srinivas
28th December 2001, 13:52
HI,

I am trying to make a receipt using STPAPI call.
The message I am getting is Purchase Order not allowed.
Pls. go through the script and suggest where I am going wrong

Thanks and Regards,

Srinivas

declaration:



table ttccom950 | API test for Employee Sal Table
table ttdpur045





#pragma used dll ottstpapihand |Baan API handler

domain tcbool all.ok
long file.fp
long err.fp
long rec.read
long rec.writ
long rec.rej
long ret.code
string field(50)
string err.line(132),error.msg(132),err.subproc(132)
string data.line(2048)
string err(50)
string dat(12) | Store current date and time in format MMDDYYHHMMSS

string reno(50)
string dino(50)
string orno(50)
string pono(50)
string diqu(50)
string rrdt(50)
string dqua(50)

domain tcdate work.date

|*** choices *******************************************************************

choice.cont.process:
on.choice:
main.processing()
after.choice:
execute(end.program)

functions:

function main.processing()
{

rec.read = 0
rec.writ = 0
rec.rej = 0
file.fp = 0
err.fp = 0

|error.report.header()

file.fp = seq.open("e:\apiupload\receipts.txt" ,"r")
if file.fp < 1 then
err = "Input File e:\apiupload\receipts.txt could not be opened"
Message("Input File e:\apiupload\receipts.txt could not be opened Reason %d",file.fp)
|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()
run.main.sess()
ret.code = seq.gets(data.line, 2048, file.fp)
endwhile

ret.code = seq.close(file.fp)

|error.report.totals()

|ret.code = seq.close(err.fp)

}




function read.record()
{
|*** This function extracts the individual fields from the current record in
|*** the input ASCII file.

reno = extract.field()
dino = extract.field()
orno = extract.field()
pono = extract.field()
diqu = extract.field()
rrdt = extract.field()
dqua = extract.field()

work.date = INPUTSTR.TO.DATE(rrdt,"%D002,2")

}

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 run.main.sess()
{


stpapi.put.field("tdpur4120m000", "tccom950.reno", reno)
stpapi.put.field("tdpur4120m000", "form.dino", dino)


stpapi.handle.subproc( "tdpur4120m000", "tdpur4224s000", "add")
stpapi.put.field("tdpur4224s000", "form.orno", orno)
stpapi.continue.process("tdpur4224s000", error.msg)

stpapi.change.view("tdpur4120m000")


stpapi.put.field("tdpur4120m000", "tccom950.orno", orno)
stpapi.put.field("tdpur4120m000", "tccom950.pono", pono)
stpapi.put.field("tdpur4120m000", "tccom950.diqu", diqu)
stpapi.put.field("tdpur4120m000", "tccom950.date", str$(work.date))
stpapi.put.field("tdpur4120m000", "tccom950.dqua", dqua)

stpapi.insert("tdpur4120m000", 1, err)

Message(err)

stpapi.end.session("tdpur4120m000")

}

mark_h
28th December 2001, 16:13
Are you maintaining an existing receipt or creating a new one?

When creating a new receipt I thought the receipt number was generated? Anyway the way I would start this is:
| Start creating a receipt
stpapi.put.field("tdpur4120m000", "form.dino", dino)
stpapi.handle.subproc( "tdpur4120m000", "tdpur4224s000", "add")
| Need to start new receipt - a insert or update may also work here. This should also initiate the subsession(tdpur4224s000). It may take some playing around with the commands.
stpapi.save("tdpur4120m000", 1, err)
| Put the session in debug mode and make sure that
| when the above command is executed you
| see that subsession gets started.

stpapi.put.field("tdpur4224s000", "form.orno", orno) stpapi.continue.process("tdpur4224s000", error.msg)
| After the continue - make sure the tdpur4224s000 session disappears.
stpapi.put.field("tdpur4120m000", "tccom950.orno", orno)
stpapi.put.field("tdpur4120m000", "tccom950.pono", pono)
stpapi.put.field("tdpur4120m000", "tccom950.diqu", diqu)
stpapi.put.field("tdpur4120m000", "tccom950.date", str$(work.date))
stpapi.put.field("tdpur4120m000", "tccom950.dqua", dqua)
stpapi.insert("tdpur4120m000", 1, err)
Message(err)
| If no error you should be able to do a get on the
| receipt number.
stpapi.end.session("tdpur4120m000")

When testing FS code I always use the option dialog and start a shell. This was I can run ps and keep an eye on what starts and stops. When you step through the code make sure the first save starts tdpur4224s000 and then the continue on this session actually closes the sub process and returns control to tdpur4120m000.

If you are trying to maintain an existing receipt then you need to do a find on the receipt, PO and position. Then you can modify or insert new records. It is just a matter of playing with the commands

No access to Baan today so I am leaving and will not return until middle of next week. I will try to check in from at home.

Good Luck!


Mark

srinivas
2nd January 2002, 12:10
Hi Mark,

Thankx. I made one silly mistake. the table that i was using in the script was tccom950(my customized table where i was doing simulations earlier. I copied the script. changed the session names but not the table names) I corrected it as tdpur045.

I started with the simple case of updating a receipt. It worked fine. I will try with generating the receipt number also and update you.

Once again lot of thanx.

Regards,
Srinivas