I got the inspiration to convert all the subroutines in a RPG program
I'm working on to procedures, in order to get rid of some global data,
but now I'm having a problem with ending the program in a procedure.
The only thing I could find on Google (so far) was a suggestion on
sending an Escape message from the procedure to end the program.
2K4S3.48$AM2....@news.rdc1.ne.home.com
I'll use the Escape message method ITMT, but isn't there an easier way
to accomplish this?
Regards,
Miguel
--
miguel DOT vrolijk AT setarnet DOT aw
<snip>
>I'll use the Escape message method ITMT, but isn't there an easier way
>to accomplish this?
</snip>
I found it myself: the C library function exit(). Duh.
H binddir('QC2LE') dftactgrp(*no) actgrp('QILE')
...
* void exit(int status)
D Exit pr extproc('exit')
D 10i 0 value
...
C CALLP Exit(0)
Regards,
Miguel
One way could be to use the CEETREK Api.. This API when called, will
return to the nearest control boundary. Whoa, you say, whats a control
boundary?
If you have created an RPG program with procedures, you will have had
to specify an activation group that the program is run in, either
*NEW, *CALLER, or you specify a name. Now lets say you had four
programs. PGM1, PGM2, PGM3,PGM4 compiled with actgrps
ACTA,ACTB,ACTA,*CALLER
Lets also say, that pgm1 has called pgm2 that called pgm3 which called
pgm4.the call stack might look something like this..
Program Activation group
pgm1 (ACTA)
pgm2 (ACTB)
pgm3 (ACTA)
pgm4 (ACTA)
A control boundary is that boundary between differing activation
groups. Ie, in our example, a boundary exists between pgm1, and pgm2,
as we are going from activation group ACTA to ACTB, and another
between pgm2 and pgm3, as we go from ACTB back to ACTA again.
Now. Lets say pgm4 had a procedure in which you called CEETREK. When
called, pgm4 would 'end', pgm3 would also 'end', and control would be
returned to the statement after the CALL 'PGM3' line in pgm2. The
call stack would now look like this...
Program Activation group
pgm1 (ACTA)
pgm2 (ACTB)
I say end in quotes, because, programs pgm3 and pgm4 would still
remain active..... Sorta like if you use RETURN instead of SETON
LR.... All global fields would retain their values, I think, also,
that files would remain open. This is because pgm1 is compiled with
the same activation group as pgm3 and pgm4, and as pgm1 is still in
the call stack, Activation group ACTA cannot at this point be ended
(or RECLAIMED). If pgm1 was compiled with activation group as ACTB,
then calling CEETREK would have resulted in pgm3 and pgm4 been removed
from memory, as ACTA would no longer be in the call stack.
One final note, If you compile with activation group *CALLER, and this
program is called from the command line/menu/cl then your program will
be run in the 'Default activation group' - This group cannot be ended,
unless you signoff. Therefor, you program once called will remain
active for the life of the job.... SETON LR will in this instance, not
close your program down. Also, CEETREK, Will not work.
So, to finalise and return to your original question,
If you compile your program with actgrp(*NEW) then calling CEETREK at
any point within your program (including the procedures) will end your
program at that point.... And control will be returned to the previous
program.
If you compile with actgrp(*CALLER), calling CEETREK will not only end
your program, but end the calling program also, and so on until you
get to a program running in a differing activation group.
If you compile with actgrp('AnythingElse') then control will return to
the previous program, so long as this program is not running in the
same activation as your program, otherwise, behaviour would be similar
to actgrp(*Caller)
Cheers.
<snip>
...
>One way could be to use the CEETREK Api.. This API when called, will
>return to the nearest control boundary. Whoa, you say, whats a control
>boundary?
...
</snip>
Thank you for taking the time to answer my question. I've been using
APIs for a few months now, but my knowledge of ILE is still lacking.
I'll stick with the C library function exit() FTTB (it seems to work
OK), until I learn more about ILE and activation groups.
Regards,
Miguel