yurong
14th August 2007, 04:22
Hello All,

I met a problem with AFS need your help.
I wrote a library to handle purchase order.
source code like following:

#pragma used dll ottstpapihand

function long Date2Number(const long input.date)
{
long input.year
long input.month
long input.day
input.year = input.date/10000
input.month = (input.date - input.year*10000) / 100
input.day = (input.date - input.year*10000 - input.month*100)
return(date.to.num(input.year, input.month, input.day))
}

function extern string New_PurchaseOrder_Head(const long CompanyCode, const long Order_Number, const string Supplier,
const string Order_Type, const string Postal_Address, const string Delivery_Address,
const long Order_Date)
{
string orno(6)
string error.message(250)
long do.update
do.update = 1
error.message = ""

switch.to.company(CompanyCode)

stpapi.put.field("tdpur4101m000", "tdpur040.orno", Str$(Order_Number))
stpapi.put.field("tdpur4101m000", "tdpur040.suno", Supplier)
stpapi.put.field("tdpur4101m000", "tdpur040.cotp", Order_Type)
stpapi.put.field("tdpur4101m000", "tdpur040.odat", Str$(Date2Number(Order_Date)))
stpapi.insert("tdpur4101m000", do.update, error.message)
stpapi.save("tdpur4101m000", error.message)

stpapi.get.field("tdpur4101m000", "tdpur040.orno", orno)
stpapi.end.session("tdpur4101m000")

return(orno)
}

function extern string New_PurchaseOrder_Line(const long CompanyCode, const long Order_Number,
const string Item_Code, const double Quantity)
{
string error.message(250)
long do.update
do.update = 1
error.message = ""
long position

string pono(2)
string amta(10)

switch.to.company(CompanyCode)

stpapi.put.field("tdpur4101m000", "tdpur040.orno", Str$(Order_Number))
stpapi.find("tdpur4101m000")
stpapi.continue.process("tdpur4101m000", error.message)

| select max(tdpur041.pono) :position
| from tdpur041
| where tdpur041.orno = :Order_Number
| selectdo
| position = position + 1
| selectempty
| position = 1
| endselect

| stpapi.put.field("tdpur4102s000", "tdpur041.pono", Str$(position))
| stpapi.put.field("tdpur4102s000", "tdpur041.item", Str$(Item_Code))
| stpapi.put.field("tdpur4102s000", "tdpur041.oqua", Str$(Quantity))
| stpapi.insert("tdpur4102s000", do.update, error.message)
| stpapi.save("tdpur4102s000", error.message)

| stpapi.get.field("tdpur4102s000", "tdpur041.pono", pono)
| stpapi.get.field("tdpur4102s000", "tdpur041.amta", amta)

stpapi.end.session("tdpur4102s000", error.message) |HANGS HERE
| stpapi.handle.subproc("tdpur4101m000", "tdpur4102s000", "kill")
| string err(255)
| err = stpapi.get.mess.code("tdpur4101m000")
| err = stpapi.get.mess.code("tdpur4102s000")
stpapi.end.session("tdpur4101m000")

return(pono&"/"&amta)
}

But after I insert and save a record in 'tdpur4102s000' session, I can't end this session. Even if I cancel all transaction in this session, just start 'tdpur4102s000' with stpapi.continue.process, I still can't not end the 'tdpur4102s000' session.


Anyone can help me?
Thanks a lot!!!

yurong
14th August 2007, 09:53
Hello all,

I have modified my source code, I use 'stpapi.zoom.option' instead of 'stpapi.continue.process', now the subsession can be closed properly.

I have looked into the bshell, when I start the 'stpapi.continue.process', 2 subsession will be opened: 'tdpur4102s000' and 'tdpur4503s000'.
Then I try to close anyone but I failed, the session just hang on.
But when I change to use the 'stpapi.zoom.option' to zoom to the 'tdpur4102s000', still 2 subsession opened, and I can close it with 'stpapi.end.session'

Anyone have clue about this?
Tks!

mark_h
14th August 2007, 15:37
Well before the stpapi.zoom you should have a stpapi.handle.subproc("tdpur4101m000", "tdpur4102s000", "add"). You have to be able to control the sub-sessions.

my code:

ret.code = stpapi.find( "tdpur4101m000" )
if(ret.code <> 1) then
message("Find PO err: %s",fserr)
stpapi.end.session( "tdpur4101m000" )
return
endif

| Now startup the maintain PO Lines Subsession.
stpapi.handle.subproc( "tdpur4101m000", "tdpur4107s000", "add" )
stpapi.continue.process( "tdpur4101m000", fserr )
if(strip$(fserr)<>"") then
message("Error activate maintain PO: %s",fserr)
stpapi.end.session( "tdpur4101m000" )
return
endif

On my system tdpur4107s000(and tdpur4503s000) starts with the lines button. In my case I no longer worry about the 4503 session. I remember I used to have to end it before or after the 4107s000 session - but not now. So you just need to play with it. You can also search on the sessions in this forum - you might find better examples.

yurong
14th August 2007, 15:57
Hi Mark, I have tried to add the 'stpapi.handle.subproc' to control the tdpur4503s000 and tdpur4102s000 session, but after I use the 'stpapi.continue.process', I still can't end the subsession with 'stpapi.session'
It's very strange for me why the subsession can be closed when I use the 'stpapi.zoom.option'.
Is there any difference between this two mode?

I have also made a test with the sales order, the interesting result is I can end subsession with the 'stpapi.continue.process', but with the 'stpapi.zoom.option', it did not work.

I have checked the source code, I saw some condition in the code, "if api.mode", does this make the different result?

mark_h
14th August 2007, 16:47
Stpapi.continue executes the choice.continue and stpapi.zoom is like doing application and zoom. If you have source code I would put it in debug mode and see what is happening. I think in the case the correct call is stpapi.continue. Make sure you get the stpapi.handle before the stpapi.continue for tdpur4101m000. The code you posted above the first thing I noticed was that the stpapi.handle.subproc was after the continue - it must be before the continue. Also keep in mind you MAY have to control the tdpur4503s000 session - I don't have to.

And yes those if api.mode will impact what happens with the session. So run it both manually and in api mode with debug. Watch what happens and then try to figure out how to work around issues. You may also want to contact infor for the last stpapi and session objects - that sometimes solves issues.

Over the years I have found a variety of issues with this session - the most problems I have is with the pegging sessions and reason codes(we are on A&D). It seems like every service pack I have to make a little change.

yurong
15th August 2007, 03:01
Hi Mark,

Yes I have tried times, it just did not work where ever the stpapi.handle.subproc was put, before of after.
I only have the souce code of the session script, but I can't compile it, still some included function souce code were missed.

I will try to contact Infor to get some information.
Tks!

Thomasm
16th August 2007, 08:34
Yurong

I find it is always a problem when a subsession calls other sessions, but in the case of the PO session I have managed to come round it. I found that calling the stpapi.handle with the action 'ignore' did the trick for me. What you see below is a code snipet from my function to create a PO with one line. This is where I move intot he subsession ans start filling the field in.



/Thomas


sess = "tdpur4101m000"
line.sess = "tdpur4102s000"
...
...
| now move to the lines to start processing
stpapi.handle.subproc(sess, line.sess, "add")
stpapi.handle.subproc(sess, "tdpur4503s000", "ignore")
stpapi.continue.process(sess, continue.msg) | go to sub session
if not ( continue.msg = "" ) then
recov = stpapi.recover( line.sess, recover.msg)
err.id = ERR.COULD.NOT.CONTINUE
err.msg = "Continue.msg: " & continue.msg & " Recov.msg: " & recover.msg
return(false)
endif

stpapi.put.field(line.sess,"tdpur041.item", str$(item))

yurong
16th August 2007, 10:49
Hi Thomas,
tks for your reply, I just made a test, but it did not solve my problem :-)
But I found some difference, without the "ignore", when I try to end the session, it hangs, and I look into system with ps, the subsession 'tdsls4102s000' and 'tdsls4503s000' still exist.
with 'ignore', the subsessions can be closed when I try to end the session, but the session 'tdpur4101m000' still hangs.