Thomasm
8th February 2011, 20:33
I have created a simple session (session A) and then a second session (session B) that calls the first session.

I have both sessions in debug and I see that for each call from session B with stpapi.put.field ("session A", ...) session A comes up in debugger at before.program and then goes directly to after.program and then dies. This happens at each call. Remvoving before.program only means it goes directly to after.program.

What am I missing? :confused:

Greatful for help.
/Thomas

mark_h
8th February 2011, 20:57
Post the API code. And how does session b call the first session.

Thomasm
8th February 2011, 21:24
Thanks for your time Mark. Here is a simplified example of my two sessions.

Session A, the session that is called via afs

|******************************************************************************
|* Thomas MÃ¥rtensson
|* 2010-11-12
|******************************************************************************
|* Main table tipcs020 Projects, Form Type 4
|******************************************************************************

|****************************** declaration section ***************************
declaration:
#pragma used dll ottstpapihand

#include <bic_tt> |include tools functions

table ttipcs020 | Projects

extern domain tccprj cprj.f fixed
extern domain tccprj cprj.t fixed
extern domain tcpsta psta.f
extern domain tcpsta psta.t
extern domain tcmcs.str14 f.device


| Script
extern domain tcmcs.str132 boi.call
long dummy
long err.id
string err.msg(500)



#include "itssma0003" | Generate Area from Postcode


|****************************** program section ********************************
before.program:
_p.desc = sattr.descr$ | entry point when called via afs

| and then it goes directly to here
after.program:
stpapi.end.session( "tssma3101m000", err.msg )

|****************************** ZOOM FROM SECTION ***************************
zoom.from.all:
on.entry:
get.screen.defaults()

cprj.f = ""
cprj.t = ""
import("cprj.f", cprj.f)
import("cprj.t", cprj.t)

|****************************** form section **********************************
form.1:
init.form:
get.screen.defaults()


|****************************** choice section ********************************
choice.cont.process:
on.choice:
execute(print.data)

choice.print.data:
on.choice:
if rprt_open() then
read.main.table()
rprt_close()
else
choice.again()
endif


choice.end.program:
before.choice:
stpapi.end.session( "tssma3101m000", err.msg )

choice.abort.program:
before.choice:
stpapi.end.session( "tssma3101m000", err.msg )



|****************************** field section *********************************

field.cprj.f:
when.field.changes:
cprj.t = cprj.f

field.psta.f:
when.field.changes:
psta.t = psta.f

field.f.device:
check.input:
if not ( deviceExists( f.device ) ) then
set.input.error("tcedis3012")
endif


|****************************** function section ******************************

functions:

function read.main.table()
{

select
*
from
tipcs020
where
tipcs020._index1 inrange {:cprj.f} and {:cprj.t}
and tipcs020.psta inrange :psta.f and :psta.t
order by
tipcs020._index1
selectdo
createServiceOrders(tipcs020.cprj)
endselect
}

function long createServiceOrders( domain tccprj cprj )
{
| create a service order via tssma3101m000
}

Then the session that is calling the above session via afs:

|******************************************************************************
|* bxbmsb604m333 0 VRC B40O DV bsm1
|* Process 1-Sales
|* Thomas MÃ¥rtensson
|* 2011-02-08
|******************************************************************************
|* Main table bxbms603 1-Sales Process Settings, Form Type 4
|******************************************************************************

|****************************** declaration section ***************************
declaration:

#pragma used dll ottstpapihand

table tbxbms603 | 1-Sales Process Settings
table ttipcs020 | Projects
table ttdsls041 | Sales Order Lines


extern domain tcorno orno.f
extern domain tcorno orno.t
extern domain tcpsta psta.f fixed
extern domain tcpsta psta.t fixed

domain tccprj hold.cprj
long more.to.process


extern domain tcmcs.str132 boi.call
string active.sessions.array( 13, 100 )
long num.active.sessions

|****************************** PROGRAM SECTION ***************************
before.program:
num.active.sessions = 0

after.program:
closeAllSessions()

|****************************** ZOOM FROM SECTION ***************************


|****************************** form section **********************************

form.1:
init.form:
get.screen.defaults()

|****************************** choice section ********************************


choice.cont.process:
on.choice:
execute(print.data)

choice.print.data:
on.choice:
if rprt_open() then

more.to.process = true

while more.to.process
processAll()
endwhile

rprt_close()
else
choice.again()
endif


choice.end.program:
before.choice:
closeAllSessions()

choice.abort.program:
before.choice:
closeAllSessions()


|****************************** field section *********************************

field.orno.f:
when.field.changes:
orno.t = orno.f

field.psta.f:
when.field.changes:
psta.t = psta.f


|****************************** function section ******************************

functions:

function processAll()
{
more.to.process = false

db.retry.point()

select
*
from
tipcs020 for update,
bxbms603,
tdsls041
where
bxbms603._index1 inrange {:psta.f} and {:psta.t}
and tdsls041._index1 inrange {:orno.f} and {:orno.t}
and tipcs020.psta = bxbms603.psta
and tipcs020.cprj = tdsls041.cprj
order by
bxbms603._index1
selectdo
if ( tdsls041.cprj <> "" and tdsls041.cprj <> hold.cprj ) then
message( bxbms603.sess & " " & str$(tdsls041.cprj) )
if ( processOneProject(tipcs020.cprj, bxbms603.sess) ) then
tipcs020.psta = bxbms603.pstb
db.update(ttipcs020, db.retry)
commit.transaction()
else
break | error is NOT handled
endif

hold.cprj = tdsls041.cprj

more.to.process = true
endif
endselect
}


function long processOneProject( domain tccprj cprj, domain tcmcs.st13 sess )
{
domain tcmcs.str50 set.report.msg
domain tcmcs.s256 err.msg
domain tcmcs.s256 end.msg
domain tcmcs.s256 continue.msg
domain tcmcs.s256 recover.msg
long recov

registerSession( sess )
err.msg = ""
set.report.msg = ""

stpapi.put.field( sess, "cprj.f", cprj )
stpapi.put.field( sess, "cprj.t", cprj )
stpapi.put.field( sess, "psta.f", "" )
stpapi.put.field( sess, "psta.t", "zzz" )
stpapi.put.field( sess, "f.device", "NULL" )

| set the report hard, there is only one
stpapi.set.report( sess, "rbxcomb99011333", spool.device, set.report.msg)
if isspace(set.report.msg) then
stpapi.continue.process(sess, continue.msg)
else
err.msg = "Could not set report: set.report.msg: " & set.report.msg
return( false )
endif

| Manage errors in case of not continued
if not (isspace(continue.msg) ) then
recov = stpapi.recover( sess, recover.msg)
err.msg = "Continue.msg: " & continue.msg & " Recov.msg: " & recover.msg
stpapi.end.session( sess, end.msg )
if not ( isspace( end.msg ) or end.msg = "Process is gone" ) then
err.msg = err.msg & " End.msg: " & end.msg
return( false )
endif
return(false)
endif

return(true)
}


| *********** session handling




function extern closeAllSessions()
{
string dummy
long enum.answer

endAllRegisteredSessions()

| make sure we allways can exit without processing on the below session
| answer no to question 'Process warehouse cycle counting data immediately?'
enum.answer = stpapi.enum.answer( "tdinv1120m000", "tdinv11202", tcyesno.no )
stpapi.end.session( "tdinv1120m000", dummy )
}

function registerSession( const string session )
{
if not ( sessionExistsInArray(session) ) then
num.active.sessions = num.active.sessions + 1
active.sessions.array(1,num.active.sessions) = session
endif
}
function long sessionExistsInArray( const string session )
{
long i

for i = 1 to num.active.sessions
if ( active.sessions.array(1, i) = session ) then
return(true)
endif
endfor

return(false)
}
function endAllRegisteredSessions()
{
long i
string dummy

i = 1
while (i <= num.active.sessions)
stpapi.end.session( active.sessions.array(1,i), dummy )
i = i + 1
endwhile

num.active.sessions = 0
}

Thomasm
8th February 2011, 22:22
Baah, silly... By mistake I had removed the form from the session that is called via afs, so that is why it did not initialise the form but instead went directly out again.

Mark, first of all thank you for your time. Your advice are always valuable. Would it be clearer for the case if your comment and my second posting with the code was removed from this thread (along with this comment...)?

Thx,
/Thomas

mark_h
8th February 2011, 22:39
What is the session name for session A started by session b? What is the start option and what is flag for main session is it checked? What happens if you start session A normally - not thru afs?

I do not think I have written an AFS session that calls a session that uses ASF. I pretty much keep all my routines in Libraries and call them one at a time. Don't see why it wouldn't work just never done it myself.

mark_h
8th February 2011, 22:41
Baah, silly... By mistake I had removed the form from the session that is called via afs, so that is why it did not initialise the form but instead went directly out again.

Mark, first of all thank you for your time. Your advice are always valuable. Would it be clearer for the case if your comment and my second posting with the code was removed from this thread (along with this comment...)?

Thx,
/Thomas

Nahhh - if someone would just read the whole thread they will see the solution. I got distracted in the middle of the post and did not see your post. This should be fine.