Is there any way to specify for a program source, what options for the activation group should be used during compilation?
In most of our programs on the as/400 we need to change the handling of the activation group (since the default behaviour is not at all useful...). Everytime I compile one of those programs, I have to remember to set the compiler options (that's in PDM: enter 14
, hit F4
, change DFTACTGRP
from *YES
to *NO
, hit enter
, change ACTGRP
to *NEW
or *CALLER
, depending on the program). So we have a lot of programs with comments at the beginning, having tons of exclamation marks, reminding the programmer to do so. And yes, sometimes you forget.
Is there any trick, so you don't have to remember yourself?
You can set these compiler options in your RPGLE or your CLLE program sources.
In RPG you would use H-Specs at the top of your source to set compiler options. Like this:
HDFTACTGRP(*NO) ACTGRP(*CALLER)
Just add it to whatever else you have there, e.g.:
H DEBUG DATEDIT(*YMD)
H DFTACTGRP(*NO) ACTGRP(*CALLER)
H BNDDIR('SRVBNDDIR')
H MAIN(main)
F OUTPUT O F 3000 DISK USROPN
D ...
* procedures, etc.
In CL, there is a special command DCLPRCOPT
which is not actually a command (as it is not executed during runtime), but a way to set compiler options.
DCLPRCOPT DFTACTGRP(*NO) ACTGRP(*CALLER)
Just put it at the top of your program. I normally put it behind the declaration of variables and before any real command. I also add a short comment, since I don't think everyone who might right my code might understand what is done there:
PGM PARM(&SOMEPARM)
DCL VAR(&SOMEPARM) TYPE(*CHAR) LEN(*64)
DCL VAR(&COUNTER) TYPE(*DEC) LEN(5 0)
/* Setting options for compilation of this program */
/* This is a permanent job, so we want a *NEW activation group. */
DCLPRCOPT DFTACTGRP(*NO) ACTGRP(*NEW)
/* do actual work here in a loop */
/* ..... */
ENDPGM
Now, when you compile the program (just enter 14
in PDM and hit enter) it ends up with the activation group behaviour you specified in the source. Nothing left to remember yourself there.