baan2tm0
24th January 2005, 10:19
:cool: Hello peeps,

I am trying to retrieve sales order lines by AFS written in vb.net. I checked in the debug mode and found out that the code hangs whenever the first stpapi.end.session is executed. below is the code:

Dim parentsession, sessionname, fieldname, fieldvalue, retval As String

ParentSession = "tdsls4101m000"
SessionName = "tdsls4102s000"
FieldName = "tdsls040.orno"
fieldvalue = "602169"

BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & parentsession & Chr(34) & "," & Chr(34) & fieldname & Chr(34) & "," & Chr(34) & fieldvalue & Chr(34) & ")")
BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.handle.subproc( " & Chr(34) & parentsession & Chr(34) & "," & Chr(34) & sessionname & Chr(34) & "," & Chr(34) & "add" & Chr(34) & ")")
BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.continue.process( " & Chr(34) & parentsession & Chr(34) & "," & Chr(34) & Space(10) & Chr(34) & ")")

BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.browse.set(" & Chr(34) & "tdsls4102s000" & Chr(34) & "," & Chr(34) & "first.set" & Chr(34) & "," & Chr(34) & errMessage1 & Chr(34) & ")")

If BaaNObj.ReturnValue = 1 Then
Do While BaaNObj.ReturnValue = 1
Dim NewRow As DataRow = dtOrder.NewRow
NewRow("orno") = fieldvalue
NewRow("pono") = GetFieldValue("tdsls041.pono", "tdsls4102s000", 2)
NewRow("cprj") = GetFieldValue("tdsls041.cprj", "tdsls4102s000", 6)
NewRow("qono") = GetFieldValue("tdsls041.qono", "tdsls4102s000", 6)
NewRow("qpon") = GetFieldValue("tdsls041.qpon", "tdsls4102s000", 2)
If Trim(NewRow("cprj")) <> "" Then dtOrder.Rows.Add(NewRow)
BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.browse.set(" & Chr(34) & "tdsls4102s000" & Chr(34) & "," & Chr(34) & "next.set" & Chr(34) & "," & Chr(34) & errMessage1 & Chr(34) & ")")
retval = BaaNObj.FunctionCall
Loop
End If

'This is where it hangs
BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.end.session(" & Chr(34) & sessionname & Chr(34) & "," & Chr(34) & errMessage1 & Chr(34) & ")")
BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.handle.subproc( " & Chr(34) & parentsession & Chr(34) & "," & Chr(34) & sessionname & Chr(34) & "," & Chr(34) & "kill" & Chr(34) & ")")
BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.end.session(" & Chr(34) & parentsession & Chr(34) & "," & Chr(34) & errMessage1 & Chr(34) & ")")

dgProjectParts.DataSource = dtOrder

whenever i remove all the stpapi.end.session the programs works fine.. but i am not able to quit the BaanObj.

please help me.. and thanks in advance.

richard
24th January 2005, 11:42
Hello,

I don't know VB.Net.
In our API's, we never put an end.session before subproc.
At the end, we have two end.sessions (main and sub).

Regards

baan2tm0
24th January 2005, 14:36
:cool: hello,

the handle.subproc after the end.session is a "kill" action..
anyway, i already removed that but it still hangs.

thanks and regards

mark_h
24th January 2005, 15:51
When you execute the stpapi.end.session on tdsls4102s000 it returns to the main session. Does it start another sub-session? Otherwise the stpapi.end.session on the main session will cause it to hang. You can debug your code and when you hit the stpapi.end.session for tdsls4102s000 make sure it really ends the session. If that works then check to see if the main session ends. It sounds like you just need to get the end sessions in the correct order.

I do not know anything about vb.net, but usually you have a option dialog box running to where you can start a shell. Then do ps to see what is happening.

baan2tm0
25th January 2005, 07:15
:cool: hello sirs,
this is the AFS code that i wanted to happen in vb.net:
stpapi.put.field("tdsls4101m000","tdsls040.orno","602169")
stpapi.handle.subproc("tdsls4101m000","tdsls4102s000","add")
stpapi.continue.process("tdsls4101m000",error.msg)
stpapi.browse.set("tdsls4102s000","first.set",error.msg)

|this is where it hangs up in vb.net
|when i remove all the following lines the code seems to work
|but i cant properly quit baan
stpapi.end.session("tdsls4102s000",error.msg)
|i tried removing the next line but nothing happens
stpapi.handle.subproc("tdsls4101m000","tdsls4102s000","kill")
stpapi.end.session("tdsls4101m000",error.msg)

thanks once again sirs.. hope to hear more from you.

best regards

baan2tm0
25th January 2005, 07:20
:cool: sir mark,

i didn't understand the last part from your last post about doing a ps to see what is happening. i'm really sorry, i'm just a beginner in BaaN.

thanks and regards

mark_h
25th January 2005, 14:33
Usually when making a connection do baan you get an option dialog box on the task bar. Click on this. One of the options is "start shell" - click on this. This starts up a shell that can show information on your processes. Usually I get a prompt like bshell>. At this prompt type ps and hit return. This will show you the processes you have running. By watching this as you step thru your code you can see what starts when. When debugging you code for example you will see that the first stpapi.put.field on the main session starts that session in the background. Then when you do a continue on the tdsls4101m000, session it starts tdsls4102s000. From this you can tell what order you need to end the sessions. For example tdsls4101m000 will have PID of 24, tdsls4102s000 will have PID(Process id) of 25 with PPID (Parent Process ID) of 24. This means 25 must be ended before you end 24.

Mark

baan2tm0
25th January 2005, 17:40
:cool: sir,

that was pretty neat.. didn't know you could do that in baan..

it seems there is a tdsls1509s000 running which i didn't open. maybe i have to do an end session on that?

thanks once again sir and regards,

mark_h
25th January 2005, 17:54
I am not familiar with tdsls at all, so I can only guess at what needs to be done. You might need to find which session is starting the tdsls1509s000 session and add a stpapi.handle.subproc for it - this should give control of the session to your program code. Then you can end the session, maybe there is something that needs to happen in it. Just my guess.

Mark

baan2tm0
26th January 2005, 09:22
it seems i got rid of the tdsls1509s000.. something wrong with my code.. i dont see the tdsls150s000 anymore. i created a new one again but it still hangs.. during the hanging, when i ps i see:

ottstpoledaem
ottstpstdlib
tdsls4101m000
tdsls4102s000
ottstpshell

mark_h
26th January 2005, 15:05
Sorry, but I really do not know the tdsls sessions. Maybe if you post your code again someone will see something that is causing it to hang. Also you may want to make sure you have the latest stapi objects from Baan - and even maybe the latest session object.

From just glancing at the sessions I would expect something that looks like this:

stpapi.handle.subproc("tdsls4101m000","tdsls4102s000","add")
stpapi.put.field("tdsls4101m000","tdsls040.orno","602169")
stpapi.put.field("tdsls4101m000","tdsls040.cotp","XXX")
.....
stpapi.continue.process("tdsls4101m000",error.msg)
stpapi.put.field("tdsls4102s0000","tdsls041.item","Some-item")
stpapi.put.field("tdsls4102s000","tdsls041.cwar","XXX")
stpapi.insert("tdsls4102s000",true,error.msg)
stpapi.end.session("tdsls4102s000")
stpapi.end.session("tdsls4101m000")


This code is assuming this works like purchase order lines. From just running the sessions(individually, since sls is not setup) it looks the same.

Mark

baan2tm0
26th January 2005, 17:39
here is my code:

stpapi.put.field("tdsls4101m000","tdsls040.orno","602169")
stpapi.find("tdsls4101m000",error.msg)
stpapi.handle.subproc("tdsls4101m000","tdsls4102s000","add")
stpapi.continue.process("tdsls4101m000",error.msg)

stpapi.put.field("tdsls4102s000","tdsls041.oqua","10")
stpapi.put.field("tdsls4102s000","tdsls041.cprj","702159")
stpapi.insert("tdsls4102s000",true,error.msg)

stpapi.end.session("tdsls4102s000",error.msg)
stpapi.end.session("tdsls4101m000",error.msg)



We don't have the Solution 10923.. If i download this Solution... will this solution fix the problem? i noticed that only when i open any sub sessions.. that is the time when it hangs the end.session.

mark_h
26th January 2005, 18:01
I am not sure about 10923 fixing your problem - I do recommend giving Baan a call. Since I am not an admin I do not know how hard it is to install solution 10923 and then un-install it.

Does this actually do the insert? Are there any error messages on any of the commands?

Mark

baan2tm0
1st February 2005, 17:51
nope.. sorry.. but i have made changes to the code again.. and this inserted a sales order line:




stpapi.put.field("tdsls4101m000","tdsls040.orno","602169")
stpapi.find("tdsls4101m000",error.msg)
stpapi.handle.subproc("tdsls4101m000","tdsls4102s000","add")
stpapi.continue.process("tdsls4101m000",error.msg)

stpapi.put.field("tdsls4102s000","tdsls041.orno","602169")
stpapi.put.field("tdsls4102s000","tdsls041.cprj","702159")
stpapi.put.field("tdsls4102s000","tdsls041.cprj","FFPLDSHT305000")
stpapi.put.field("tdsls4102s000","tdsls041.cuqs","kgs")
stpapi.put.field("tdsls4102s000","tdsls041.oqua","10")
stpapi.put.field("tdsls4102s000","tdsls041.pric","100")
stpapi.put.field("tdsls4102s000","tdsls041.opol","2")
stpapi.insert("tdsls4102s000",true,error.msg)

stpapi.end.session("tdsls4102s000",error.msg)
stpapi.end.session("tdsls4101m000",error.msg)



.... :( but it still hangs when i do an end session :( .. help.. please.. help!!

mark_h
1st February 2005, 18:33
Check this post (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=14201&highlight=kill) out. I hesitate to recommend this method, but I have had to use it myself to kill unruly sub-sessions. The only reason why I am posting this is because the insert worked. I have no idea what may be causing this to hand.

Mark

kbartelds
2nd February 2005, 11:01
Just some remarks:

* if a header is present, at line level you should not give orno a value before the insert, you can give it a value to execute a find and get to check if you have found the right orno
* do not use quotemarks to indicate a number, use str$(...) or edit$
* you use cprj twice, I think the second time it should be item?
* always check the return values of the insert and find actions, if necessary including the message queue, if insert fails, use recover option.

I think the combination of using cpr twice (so skipping item) and not checking the return value of the afs insert action with recover in case of error will result in hanging on end.session. Not using recover will result in unpredictable situations (at least: that is how it is documented).

Regards,
Klaas

baan2tm0
2nd February 2005, 12:42
hey thanks man..

sorry my mistake... :confused: one more question.. what does "recover" do? and how do i use it.. and suppose i want to use a "recover" in vb.. what should i do?

kbartelds
2nd February 2005, 13:20
In general:

stpapi.put.field("tdsls4101m000","tdsls040.orno", str$(orno))
if not stpapi.find("tdsls4101m000",find.mess) then
stpapi.recover("tdsls4101m000",recover.mess)
else
..........
endif

If the find action did not succeed, there is either no current record, or the current record is not the expected one. Any following transaction (insert orderlines or change) will definitely fail or have unwanted results (insert line to wrong order). The recover command, you might look at it as the ESCape key, transaction will be undone.

The recover option should always be used in case of find/insert/delete/update (these api functions return a value which can be checked). It is even a good idea to always check the result of a find api call: use the get.field api to the current keys and check it with value used in put.field.

Never did try afs in vb, sorry can't help you with that. If you want to have a working example for entering sales orders for testing purposes, just give me a PM.

Good Luck,
Klaas

mark_h
2nd February 2005, 14:58
Klaas said:

* do not use quotemarks to indicate a number, use str$(...) or edit$

Good catch on the coding - I just glanced right past that version of code. As for the quote, I have never had a problem with this while testing a function server. Is there a problem with this I have never run into? I almost always test first with hard coded vaules. Of course the full-up version of my function servers use variables with str$, but I have never seen a problem with this.

As for stpapi.recover in should work in VB, never tested it but it should work. As for how I use stpapi.recover - I only use this when I have to do something else in the session. Typically I check the results for each command, if one command fails I exit the session and give error messages. I seldom use stpapi.recover and have not run into a problem so far. I do recommend doing it just to make the session running in the background a little cleaner.

Mark

kbartelds
2nd February 2005, 15:40
I always use recover option, so I'm sure to be in control of the flow (clean programming). If necessary, I will end the session (or use alternative flows to get the work done), but the program will continue to process all the records that can be processed. The result will be shown on the report.

As for the quotes: there might not even be a problem using it, but why use fixed values this way if after testing, it will be changed to variables. It would not always matter very much, but think about date formats, formats of negative values etc.

Regards,
Klaas

mark_h
2nd February 2005, 16:24
It sounds like you open a session then insert mutliple records then close the session. In that case stpapi.recover would be necessary. When I first started programming using the API code I had problems with doing this - sounds like I need to try this again.

As for the test code - I keep a test program that I drop all kinds of code it (board, mine, others) to test things. I usually hard code the minimum needed to test or to try to solve problems with other scripts. Never had a problem with negative numbers, and dates are always str$(date.num()). Just depends on what I am testing. This script is scary to the un-initiated. :)

Mark

baan2tm0
14th February 2005, 14:33
even if i don't use find/insert/update/delete it still hangs. i removed the find and theoretically this vb code should work right?

Public Sub Foo()
'test procedure
Dim errMessage1 As String = Space(30)
BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.put.field(" & Chr(34) & "tdsls4101m000" & Chr(34) & "," & Chr(34) & "tdsls040.orno" & Chr(34) & "," & Chr(34) & "330057" & Chr(34) & ")")
BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.handle.subproc( " & Chr(34) & "tdsls4101m000" & Chr(34) & "," & Chr(34) & "tdsls4102s000" & Chr(34) & "," & Chr(34) & "add" & Chr(34) & ")")
BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.continue.process( " & Chr(34) & "tdsls4101m000" & Chr(34) & "," & Chr(34) & errMessage1 & Chr(34) & ")")
BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.handle.subproc( " & Chr(34) & "tdsls4101m000" & Chr(34) & "," & Chr(34) & "tdsls4102s000" & Chr(34) & "," & Chr(34) & "kill" & Chr(34) & ")")
errMessage1 = BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.end.session(" & Chr(34) & "tdsls4102s000" & Chr(34) & "," & Chr(34) & errMessage1 & Chr(34) & ")")
errMessage1 = BaaNObj.ParseExecFunction("ottstpapihand", "stpapi.end.session(" & Chr(34) & "tdsls4101m000" & Chr(34) & "," & Chr(34) & errMessage1 & Chr(34) & ")")
End Sub

but when i debug the code.. it still hangs at the first end session with no error message.. is there any other way i can close the two sub sessions? how do i kill a baan session from vb? do i also use ottstpapihand or something else?

rock on and god bless you dudes!!

mark_h
14th February 2005, 16:12
Well - if you remove the subproc with the "kill" command. The stpapi.handle.subproc should always come before the command that starts the sub-session - in this case the continue. What the "kill" command does is say - next time the tdsls4101m00 session starts tdsls4201s000 then do a kill on the session. So without that I would say the code should work. If it doesn't then I would contact Baan - you may need new tools patches, a porting set or session objects. I would be interested to see if they even support the ole connection. I would try testing it on our machines but we do not use the sls module.

As for the post I did on using kill - you could always write a DLL in Baan and call this from VB. Then it could do the kill for you.

Mark

baan2tm0
26th March 2005, 10:32
sir mark,

right now i believe that we donot have the capability to write our own DLLs.. am i right in saying that we donot own code??

is there a work around in killing those sessions?? sorry for the trouble! :o

mark_h
29th March 2005, 16:56
Missed this post. You do not need to own source to develope your own Baan libraries and code. You may need a developers license, but I am not even sure about that. Anyway that is the only thing I can think of at this time. I do not know how to kill the sessions from VB. Sorry I can not help.

Mark