Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

Another approach beside @kratenko suggestion.If you have default company settings, you could just change the command default value using CHGCMDDFT . e.g. CHGCMDDFT CRTBNDRPG 'DFTACTGRP(*NO)' and so on.. Our practice here is to always put settings at H-spec, especially for some special, non-standard settings. If someone forgot, default company settings will be used. One problem with this approach is your updated command probably will be reset back after OS update. You could use one of 2 approach

  1. Put all your CHGCMDDFT in CL code and re-run after every OS upgrade
  2. Duplicate,CHGCMDDFT required commands to a library and put this library in system library list

We change quite few of other command default and i prefer approach 1 above. Hope this helps

H specs are definitely the way forward in 99% of programs but occasionally you'll find a compiler option that can't be set in an h spec. I've used source control software in the past which added these options as a comment in the source header and automatically applied it when compiling. To solve the problem of compiling on different machines we wrote our own compile utility that could read these comments. It's a fairly simple CL program, you just have to decide on a format for the comments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top