vsevilla
26th June 2002, 19:44
Hi All
I was reading a samples about Maintain Receipts whit stpapi, and i was testing the sample code attached, but i only can use with a purchase orden with one line, because the command stpapi.continue.process("tdpur4224s000", err) automatically create the records in table tpur045 for all lines of the order with the field srnb=1, so when i update the record with ret.code = stpapi.update("tdpur4120m020", true, err) for the second line in the order i receive the error "The order is linked to other Receipt Number".
Could you help me please
vsevilla
|******************************************************************************
|* tdpur4120m021 0 VRC B40c c2 mcr2
|* Recepciones de O/C desde archivo ASCII
|* Vinicio Sevilla Quevedo
|* 2002-04-08
|******************************************************************************
|* Main table tdpur045 Recepciones de O/C
|******************************************************************************
|****************************** declaration section ***************************
declaration:
#pragma used dll ottstpapihand |Baan API handler
table ttdpur980 | Archivos procesados en Interface
table ttdinv981 | Parámetros Interface
table ttcmcs001
table ttdpur041
table ttdpur045
extern domain tcdate m.fecha | Fecha de procesamiento
extern domain tclogn m.user | Usuario
extern domain tcsrnb m.srnb
extern domain tcmcs.str60 m.plog | Path de Archivos Logs
extern domain tcmcs.str60 m.prec | Path de Archivos Recibidos
extern domain tcmcs.str60 m.pgen | Path de Archivos Procesados
extern string m.file1(100)
extern string m.file2(100)
extern string m.file3(100)
extern string m.guia(50)
string reno(50) |* Receipt Serie
string dino(50) |* Nota de Entrega
string orno(50) |* Order No
string pono(50) |* Pono No
string qstr(50) |* Quantity
extern domain tcmcs.str60 que.accion
domain tcbool all.ok
long file.fp
long err.fp
long rec.read
long rec.writ
long rec.rej
long ret.code
long r
string err.line(132)
string data.line(2048)
string err(50)
string dat(12) | Store current date and time in format MMDDYYHHMMSS
domain tcorno m.orno
domain tcpono m.pono
|****************************** form section **********************************
before.program:
que.accion = "Iniciando Proceso"
|Carga Parámetros de la Interface
carga.param()
form.1:
init.form:
get.screen.defaults()
genera.nombres()
|****************************** choice section ********************************
choice.cont.process:
on.choice:
main.processing()
genera.nombres() | Genera el nombre del archivo a leer
after.choice:
execute(end.program)
|****************************** field section *********************************
field.m.user:
before.input:
attr.input = false
field.m.fecha:
before.input:
attr.input = false
|field.m.guia:
|check.input:
| genera.nombres() | Genera el nombre del archivo a leer
|****************************** function section ******************************
functions:
function main.processing()
{
rec.read = 0
rec.writ = 0
rec.rej = 0
file.fp = 0
err.fp = 0
dino = ""
error.report.header()
| Inicializar variables
que.accion="Verificando....." & m.file1
display("que.accion")
refresh()
| Aun no sube este archivo
que.accion="Buscando....." & m.file1
display("que.accion")
refresh()
file.fp = seq.open( m.file1 ,"r")
if file.fp < 1 then
err = "El archivo " & m.file1 & "nopuede ser abierto"
write.err.record()
return
endif
ret.code = seq.gets(data.line, 2048, file.fp)
while seq.eof(file.fp) = 0
rec.read = rec.read + 1
all.ok = true
read.record()
if check.consistencia()>0 then
run.main.sess()
endif
seq.gets(data.line, 2048, file.fp)
endwhile
ret.code = seq.close(file.fp)
actualiza.generado()
error.report.totals()
que.accion ="Finalizado Proceso de Carga de Archivos"
display("que.accion")
refresh()
ret.code = seq.close(err.fp)
| Muevo los archivos
r = shell("cp " & m.file1 & " " & m.file2, 0)
r = shell("rm " & m.file1, 0)
}
function run.main.sess()
{
|*** This function invokes session tdrpl0122m000
que.accion="Procesando....." & sprintf$("O/C: %s Pos.: %s ",orno,pono)
display("que.accion")
refresh()
stpapi.put.field("tdpur4120m020", "tdpur045.reno", reno)
stpapi.put.field("tdpur4120m020", "form.dino", dino)
stpapi.handle.subproc( "tdpur4120m020", "tdpur4224s000", "add")
ret.code = stpapi.change.view("tdpur4120m020")
if ret.code > 0 then
stpapi.put.field("tdpur4224s000", "form.orno", orno)
stpapi.continue.process("tdpur4224s000", err)
if(strip$(err)<>"" and strip$(err)<>"Process is gone") then
Message("Child process error = %s",err)
else
| No matter what kill the session.
stpapi.end.session("tdpur4224s000")
| Now get the receipt number just created.
stpapi.get.field("tdpur4120m020","tdpur045.reno",reno)
| At this point you could update receipt fields.
stpapi.put.field("tdpur4120m020", "tdpur045.orno", orno)
stpapi.put.field("tdpur4120m020", "tdpur045.pono", pono)
stpapi.put.field("tdpur4120m020", "tdpur045.diqu", qstr)
stpapi.put.field("tdpur4120m020", "tdpur045.date", str$(m.fecha))
stpapi.put.field("tdpur4120m020", "tdpur045.dqua", qstr)
ret.code = stpapi.update("tdpur4120m020", true, err)
if ret.code <> 1 then
err = "La Orden de Compra no encontrada para la Orden No "
err = err & orno
write.err.record()
endif
endif
endif
stpapi.end.session("tdpur4120m020")
if all.ok then
rec.writ = rec.writ + 1
else
rec.rej = rec.rej + 1
endif
}
function read.record()
{
|*** This function extracts the individual fields from the current record in
|*** the input ASCII file.
reno = extract.field()
orno = extract.field()
pono = extract.field()
qstr = extract.field()
m.orno = lval(orno)
m.pono = lval(pono)
}
function string extract.field()
{
|*** This function searches for the 'pipe' delimiter and extracts the next
|*** field in the current record in the input ASCII file
string extracted.field(50)
long pointer
long flag
string character(1)
pointer = 0
flag = FALSE
while flag = FALSE
pointer = pointer + 1
character = data.line(pointer; 1)
if data.line(pointer;1) = "|" or data.line(pointer;1) = "" then
flag = TRUE
endif
endwhile
extracted.field = data.line(1;pointer - 1)
data.line = data.line(pointer+1; 2048)
return(extracted.field)
}
function write.err.record()
{
|*** This function writes an error message to the error ASCII file
all.ok = false
err.line = "Registro Número " & str$(rec.read) & " Error: "
err.line = err.line & err
ret.code = seq.puts(err.line, err.fp)
}
function error.report.header()
{
|*** This function writes the current date and time into the start of the
|*** error ASCII file
err.fp = seq.open(m.file3 ,"w+")
dat = dte$()
err.line = "Reporte de Control: Fecha "
err.line = err.line & dat(3;2) & "/" & dat(1;2) & "/" & dat(5;2)
err.line = err.line & " Time "
err.line = err.line & dat(7;2) & ":" & dat(9;2) & ":" & dat(11;2)
ret.code = seq.puts(err.line, err.fp)
}
function error.report.totals()
{
|*** This function writes the control totals (number of records read, rejected
|*** and written) at the end of the error ASCII file.
err.line = "Registros Leídos: " & str$(rec.read)
ret.code = seq.puts(err.line, err.fp)
err.line = "Registros Procesados: " & str$(rec.writ)
ret.code = seq.puts(err.line, err.fp)
err.line = "Registros Rechazados: " & str$(rec.rej)
ret.code = seq.puts(err.line, err.fp)
}
| Funcion que chequea la consistencia de los datos almacenados en
| las tablas temporales.
function extern long check.consistencia()
{
long ret
long m.ed
ret=1
m.ed = 0
if lval(qstr) <= 0 then
err = sprintf$("O/C: %s Pos: %s Cantidad a recepcionar negativa",orno,pono)
write.err.record()
ret=-1
endif
select tdpur045.*
from tdpur045
where tdpur045._index1 = {:m.orno, :m.pono}
order by tdpur045._index1 DESC
as set with 1 rows
selectdo
if tdpur045.pmsk(3;1) = "y" then
select tdpur041.*
from tdpur041
where tdpur041._index1 = {:m.orno, :m.pono}
selectdo
if tdpur041.sorn <> 0 and tdpur041.cwar = " " then
m.ed = 1
endif
endselect
else
err = sprintf$("O/C: %s Pos: %s Orden entregada",orno,pono)
write.err.record()
ret = -1
endif
selectempty
err = sprintf$("O/C: %s Pos: %s No hay orden por entregar",orno,pono)
write.err.record()
ret = -1
endselect
return(ret)
}
function genera.nombres()
{
long que.anio, que.mes, que.dia
num.to.date(m.fecha,que.anio,que.mes,que.dia)
|Archivo que se recibe
m.file1 = sprintf$("%s",m.prec)
m.file1 = m.file1 & sprintf$("/RC%@99@",que.dia)
m.file1 = m.file1 & sprintf$("%@99@",que.mes)
m.file1 = m.file1 & sprintf$("%@9999@",que.anio)
m.file1 = m.file1 & ".TXT"
m.file1 = tolower$(m.file1)
|Archivo que se procesa
m.file2 = sprintf$("%s",m.pgen)
m.file2 = m.file2 & sprintf$("/RC%@99@",que.dia)
m.file2 = m.file2 & sprintf$("%@99@",que.mes)
m.file2 = m.file2 & sprintf$("%@9999@",que.anio)
m.file2 = m.file2 & ".TXT"
m.file2 = tolower$(m.file2)
|Archivo de Log
m.file3 = sprintf$("%s",m.plog)
m.file3 = m.file3 & sprintf$("/RC%@99@",que.dia)
m.file3 = m.file3 & sprintf$("%@99@",que.mes)
m.file3 = m.file3 & sprintf$("%@9999@",que.anio)
m.file3 = m.file3 & ".ERR"
m.file3 = tolower$(m.file3)
display("m.file1")
refresh()
}
function actualiza.generado()
{
db.retry.point()
tdpur980.nfil = m.file1
tdpur980.pdat = m.fecha
tdpur980.usua = logname$
tdpur980.ohor = time.num()
tdpur980.nreg = rec.read
db.insert(ttdpur980,db.retry)
commit.transaction()
}
| Función que carga los parámetros de la Interface a variables globales
function carga.param()
{
m.fecha = date.num()
m.user = logname$
| Busca los parémtros de la Interface
select tdinv981.*
from tdinv981
selectdo
m.plog = shiftl$(shiftr$(tdinv981.plog))
m.prec = shiftl$(shiftr$(tdinv981.prec))
m.pgen = shiftl$(shiftr$(tdinv981.pgen))
endselect
}
I was reading a samples about Maintain Receipts whit stpapi, and i was testing the sample code attached, but i only can use with a purchase orden with one line, because the command stpapi.continue.process("tdpur4224s000", err) automatically create the records in table tpur045 for all lines of the order with the field srnb=1, so when i update the record with ret.code = stpapi.update("tdpur4120m020", true, err) for the second line in the order i receive the error "The order is linked to other Receipt Number".
Could you help me please
vsevilla
|******************************************************************************
|* tdpur4120m021 0 VRC B40c c2 mcr2
|* Recepciones de O/C desde archivo ASCII
|* Vinicio Sevilla Quevedo
|* 2002-04-08
|******************************************************************************
|* Main table tdpur045 Recepciones de O/C
|******************************************************************************
|****************************** declaration section ***************************
declaration:
#pragma used dll ottstpapihand |Baan API handler
table ttdpur980 | Archivos procesados en Interface
table ttdinv981 | Parámetros Interface
table ttcmcs001
table ttdpur041
table ttdpur045
extern domain tcdate m.fecha | Fecha de procesamiento
extern domain tclogn m.user | Usuario
extern domain tcsrnb m.srnb
extern domain tcmcs.str60 m.plog | Path de Archivos Logs
extern domain tcmcs.str60 m.prec | Path de Archivos Recibidos
extern domain tcmcs.str60 m.pgen | Path de Archivos Procesados
extern string m.file1(100)
extern string m.file2(100)
extern string m.file3(100)
extern string m.guia(50)
string reno(50) |* Receipt Serie
string dino(50) |* Nota de Entrega
string orno(50) |* Order No
string pono(50) |* Pono No
string qstr(50) |* Quantity
extern domain tcmcs.str60 que.accion
domain tcbool all.ok
long file.fp
long err.fp
long rec.read
long rec.writ
long rec.rej
long ret.code
long r
string err.line(132)
string data.line(2048)
string err(50)
string dat(12) | Store current date and time in format MMDDYYHHMMSS
domain tcorno m.orno
domain tcpono m.pono
|****************************** form section **********************************
before.program:
que.accion = "Iniciando Proceso"
|Carga Parámetros de la Interface
carga.param()
form.1:
init.form:
get.screen.defaults()
genera.nombres()
|****************************** choice section ********************************
choice.cont.process:
on.choice:
main.processing()
genera.nombres() | Genera el nombre del archivo a leer
after.choice:
execute(end.program)
|****************************** field section *********************************
field.m.user:
before.input:
attr.input = false
field.m.fecha:
before.input:
attr.input = false
|field.m.guia:
|check.input:
| genera.nombres() | Genera el nombre del archivo a leer
|****************************** function section ******************************
functions:
function main.processing()
{
rec.read = 0
rec.writ = 0
rec.rej = 0
file.fp = 0
err.fp = 0
dino = ""
error.report.header()
| Inicializar variables
que.accion="Verificando....." & m.file1
display("que.accion")
refresh()
| Aun no sube este archivo
que.accion="Buscando....." & m.file1
display("que.accion")
refresh()
file.fp = seq.open( m.file1 ,"r")
if file.fp < 1 then
err = "El archivo " & m.file1 & "nopuede ser abierto"
write.err.record()
return
endif
ret.code = seq.gets(data.line, 2048, file.fp)
while seq.eof(file.fp) = 0
rec.read = rec.read + 1
all.ok = true
read.record()
if check.consistencia()>0 then
run.main.sess()
endif
seq.gets(data.line, 2048, file.fp)
endwhile
ret.code = seq.close(file.fp)
actualiza.generado()
error.report.totals()
que.accion ="Finalizado Proceso de Carga de Archivos"
display("que.accion")
refresh()
ret.code = seq.close(err.fp)
| Muevo los archivos
r = shell("cp " & m.file1 & " " & m.file2, 0)
r = shell("rm " & m.file1, 0)
}
function run.main.sess()
{
|*** This function invokes session tdrpl0122m000
que.accion="Procesando....." & sprintf$("O/C: %s Pos.: %s ",orno,pono)
display("que.accion")
refresh()
stpapi.put.field("tdpur4120m020", "tdpur045.reno", reno)
stpapi.put.field("tdpur4120m020", "form.dino", dino)
stpapi.handle.subproc( "tdpur4120m020", "tdpur4224s000", "add")
ret.code = stpapi.change.view("tdpur4120m020")
if ret.code > 0 then
stpapi.put.field("tdpur4224s000", "form.orno", orno)
stpapi.continue.process("tdpur4224s000", err)
if(strip$(err)<>"" and strip$(err)<>"Process is gone") then
Message("Child process error = %s",err)
else
| No matter what kill the session.
stpapi.end.session("tdpur4224s000")
| Now get the receipt number just created.
stpapi.get.field("tdpur4120m020","tdpur045.reno",reno)
| At this point you could update receipt fields.
stpapi.put.field("tdpur4120m020", "tdpur045.orno", orno)
stpapi.put.field("tdpur4120m020", "tdpur045.pono", pono)
stpapi.put.field("tdpur4120m020", "tdpur045.diqu", qstr)
stpapi.put.field("tdpur4120m020", "tdpur045.date", str$(m.fecha))
stpapi.put.field("tdpur4120m020", "tdpur045.dqua", qstr)
ret.code = stpapi.update("tdpur4120m020", true, err)
if ret.code <> 1 then
err = "La Orden de Compra no encontrada para la Orden No "
err = err & orno
write.err.record()
endif
endif
endif
stpapi.end.session("tdpur4120m020")
if all.ok then
rec.writ = rec.writ + 1
else
rec.rej = rec.rej + 1
endif
}
function read.record()
{
|*** This function extracts the individual fields from the current record in
|*** the input ASCII file.
reno = extract.field()
orno = extract.field()
pono = extract.field()
qstr = extract.field()
m.orno = lval(orno)
m.pono = lval(pono)
}
function string extract.field()
{
|*** This function searches for the 'pipe' delimiter and extracts the next
|*** field in the current record in the input ASCII file
string extracted.field(50)
long pointer
long flag
string character(1)
pointer = 0
flag = FALSE
while flag = FALSE
pointer = pointer + 1
character = data.line(pointer; 1)
if data.line(pointer;1) = "|" or data.line(pointer;1) = "" then
flag = TRUE
endif
endwhile
extracted.field = data.line(1;pointer - 1)
data.line = data.line(pointer+1; 2048)
return(extracted.field)
}
function write.err.record()
{
|*** This function writes an error message to the error ASCII file
all.ok = false
err.line = "Registro Número " & str$(rec.read) & " Error: "
err.line = err.line & err
ret.code = seq.puts(err.line, err.fp)
}
function error.report.header()
{
|*** This function writes the current date and time into the start of the
|*** error ASCII file
err.fp = seq.open(m.file3 ,"w+")
dat = dte$()
err.line = "Reporte de Control: Fecha "
err.line = err.line & dat(3;2) & "/" & dat(1;2) & "/" & dat(5;2)
err.line = err.line & " Time "
err.line = err.line & dat(7;2) & ":" & dat(9;2) & ":" & dat(11;2)
ret.code = seq.puts(err.line, err.fp)
}
function error.report.totals()
{
|*** This function writes the control totals (number of records read, rejected
|*** and written) at the end of the error ASCII file.
err.line = "Registros Leídos: " & str$(rec.read)
ret.code = seq.puts(err.line, err.fp)
err.line = "Registros Procesados: " & str$(rec.writ)
ret.code = seq.puts(err.line, err.fp)
err.line = "Registros Rechazados: " & str$(rec.rej)
ret.code = seq.puts(err.line, err.fp)
}
| Funcion que chequea la consistencia de los datos almacenados en
| las tablas temporales.
function extern long check.consistencia()
{
long ret
long m.ed
ret=1
m.ed = 0
if lval(qstr) <= 0 then
err = sprintf$("O/C: %s Pos: %s Cantidad a recepcionar negativa",orno,pono)
write.err.record()
ret=-1
endif
select tdpur045.*
from tdpur045
where tdpur045._index1 = {:m.orno, :m.pono}
order by tdpur045._index1 DESC
as set with 1 rows
selectdo
if tdpur045.pmsk(3;1) = "y" then
select tdpur041.*
from tdpur041
where tdpur041._index1 = {:m.orno, :m.pono}
selectdo
if tdpur041.sorn <> 0 and tdpur041.cwar = " " then
m.ed = 1
endif
endselect
else
err = sprintf$("O/C: %s Pos: %s Orden entregada",orno,pono)
write.err.record()
ret = -1
endif
selectempty
err = sprintf$("O/C: %s Pos: %s No hay orden por entregar",orno,pono)
write.err.record()
ret = -1
endselect
return(ret)
}
function genera.nombres()
{
long que.anio, que.mes, que.dia
num.to.date(m.fecha,que.anio,que.mes,que.dia)
|Archivo que se recibe
m.file1 = sprintf$("%s",m.prec)
m.file1 = m.file1 & sprintf$("/RC%@99@",que.dia)
m.file1 = m.file1 & sprintf$("%@99@",que.mes)
m.file1 = m.file1 & sprintf$("%@9999@",que.anio)
m.file1 = m.file1 & ".TXT"
m.file1 = tolower$(m.file1)
|Archivo que se procesa
m.file2 = sprintf$("%s",m.pgen)
m.file2 = m.file2 & sprintf$("/RC%@99@",que.dia)
m.file2 = m.file2 & sprintf$("%@99@",que.mes)
m.file2 = m.file2 & sprintf$("%@9999@",que.anio)
m.file2 = m.file2 & ".TXT"
m.file2 = tolower$(m.file2)
|Archivo de Log
m.file3 = sprintf$("%s",m.plog)
m.file3 = m.file3 & sprintf$("/RC%@99@",que.dia)
m.file3 = m.file3 & sprintf$("%@99@",que.mes)
m.file3 = m.file3 & sprintf$("%@9999@",que.anio)
m.file3 = m.file3 & ".ERR"
m.file3 = tolower$(m.file3)
display("m.file1")
refresh()
}
function actualiza.generado()
{
db.retry.point()
tdpur980.nfil = m.file1
tdpur980.pdat = m.fecha
tdpur980.usua = logname$
tdpur980.ohor = time.num()
tdpur980.nreg = rec.read
db.insert(ttdpur980,db.retry)
commit.transaction()
}
| Función que carga los parámetros de la Interface a variables globales
function carga.param()
{
m.fecha = date.num()
m.user = logname$
| Busca los parémtros de la Interface
select tdinv981.*
from tdinv981
selectdo
m.plog = shiftl$(shiftr$(tdinv981.plog))
m.prec = shiftl$(shiftr$(tdinv981.prec))
m.pgen = shiftl$(shiftr$(tdinv981.pgen))
endselect
}