Compiler Directive in RPGLE AS400 |
Compiler Directive
/TITLE
Use this /TITLE compiler directive to specify heading information for the compiler listing that would be displayed at the top of every page. The /TITLE compiler directive must be followed by the blank and the text after the blank would be printed on the compiler listing page. An RPG program can have more than one /TITLE compiler directive defined.
/TITLE Test title 1
/EJECT
Use this /EJECT compiler directive to specify that print the next lines of specifications on the new page of the compiler listing. /EJECT compiler directive must be followed by at least 2 blanks. This compiler directive cannot be coded in a free-form RPG.
C EVAL VAR1 = 'TEST' /EJECT C SETON LR
/SPACE
Use this /SPACE compiler directive to control the line spacing within the source section of the compiler listing. The /SPACE compiler directive must be followed by 1 space and then followed by a value between 1 to 112 that tells the number of lines to be spaces in the compiler listing. This compiler directive cannot be coded in Free-form RPG.
C EVAL VAR1 = 'TEST' /SPACE 5 C SETON LR
/SET
Use this /SET compiler directive to temporarily change values for keywords in control specs. We can specify the following keywords with the /SET directive.
Specify the default CCSID for character fields that are defined without the CCSID keyword. Here CCSID would be *JOBRUN or *JOBRUNMIX or *UTF8 or *HEX or number.
Specify the default CCSID for graphic fields that are defined without the CCSID keyword. Here CCSID would be *JOBRUN or *JOBRUN or *SRC or *HEX or *IGNORE or number.
Specify the default CCSID for UCS-2 fields that are defined without the CCSID keyword. Here CCSID would be *UTF16 or number.
Specify the default format and separators for date fields that are specified without the date format.
Specify the default format and separators for time fields that are specified without the time format.
Example of using /SET compiler directive
In this example, we will see how /SET compiler directive will affect the CCSID for the FLD2 variable.
CTL-OPT CCSID(*CHAR : 37) DCL-S FLD1 char(10); /SET CCSID(*CHAR : 273) DCL-S FLD2 char(10);
/RESTORE
Use this /RESTORE compiler directive to restore values previously set by /SET directive in the same source member or undoes the effect of the previous /SET compiler directive.
Example of using /RESTORE compiler directive
Here we use the above example used with /SET compiler directive, we will see how /RESTORE compiler directive will affect the CCSID for the FLD3 variable.
CTL-OPT CCSID(*CHAR : 37) DCL-S FLD1 char(10); /SET CCSID(*CHAR : 273) DCL-S FLD2 char(10); /RESTORE CCSID(*CHAR) DCL-S FLD3 char(10);
/OVERLOAD
The /OVERLOAD compiler directive has parameters DETAIL or NODETAIL. Specify DETAIL if we want to see detailed information of the calls to the overloaded prototypes in statements following the compiler directive in the compiler listing.
/COPY or /INCLUDE
Both the compiler directives /COPY or /INCLUDE have the same purpose and the same syntax but are handled differently by the SQL precompiler and it depends upon the RPG preprocessor options parameter (RPGPPOPT) specified on the CRTSQLRPGI command.
When *NONE is specified for the RPGPPOPT parameter on the CRTSQLRPGI command, then the compiler is not called for preprocessing.
When *NONE is specified for the RPGPPOPT parameter on the CRTSQLRPGI command, then the compiler is not called for preprocessing.
When *LVL1 is specified for the RPGPPOPT parameter on the CRTSQLRPGI command, then the compiler is called for preprocessing to expand /COPY and handle the conditional compilation directives.
When *LVL2 is specified for RPGPPOPT parameter on CRTSQLRPGI command, then the compiler is called for preprocessing to expand /COPY and /INCLUDE and handle the conditional compilation directives except for the /INCLUDE compiler directive.
Using physical files with /COPY and /INCLUDE
/COPY and /INCLUDE followed by 1 space followed by file name or path. The format can be as follows:
Libraryname/Filename,Membername
Or
Filename,Membername
Or
Membername
Using IFS file with /COPY and /INCLUDE
/COPY /EASYCLASS1/PGM1.rpgle
/COPY /EASYCLASS1/PGM1
/COPY EASYCLASS1/PGM1.rpgle
/COPY "IFS file having blanks" /COPY 'IFS file having blanks'
Nested /COPY or /INCLUDE
Nesting of /COPY and /INCLUDE compiler directives is allowed.
Conditional Compiler Directive
The conditional compiler directive allows us to include or exclude sections of source code from the program compilation.
Define the condition name and remove the condition using the /DEFINE compiler directive and /UNDEFINE compiler directive
/DEFINE
The /DEFINE conditional directive defines conditions for conditional program compilation. /DEFINE must be followed by at least one space and then the condition name should also be specified on the same line. The /DEFINE compiler directive cannot be specified within the free-format RPG and it adds the condition name to the currently defined conditions list. Therefore, /IF DEFINED(condition_name) is TRUE and /IF NOT DEFINED(condition_name) is FALSE. There can be a maximum of up to 320 conditions that can be added using the DEFINE directive on the CRTBNDRPG and CRTRPGMOD commands.
/UNDEFINE
The /UNDEFINE compiler directive tells that the condition is no longer defined or exists. The /UNDEFINE compiler directive must be followed by one space and then the condition name should also be specified on the same line./UNDEFINE cannot be used with free-format RPG. The /UNDEFINE compiler directive removes the condition name from the currently defined conditions list.
Predefined Conditions
Conditions that are defined by the compiler for us are predefined conditions. These conditions cannot be used with /DEFINE and /UNDEFINE compiler directives. The predefined conditions can only be used with /IF and /ELSEIF.
/IF DEFINED(*ILERPG) H BNDDIR('QC2LE') /ENDIF
/IF DEFINED(*CRTBNDRPG) H DFTACTGRP(*NO) /ENDIF
/IF DEFINED(*CRTRPGMOD) H /ENDIF
/IF DEFINED(*V6R1M0) // specify the code valid on V6R1M0 /ENDIF
Testing Conditions
Conditions are tested using /IF directive groups. The /IF directive can be followed by zero or more /ELSEIF directive and optionally followed by /ELSE directive and finally followed by and /ENDIF directive. All the source lines except compile-time data are valid inside the /IF directive groups.
/EOF
/EOF compiler directive tells the compiler to ignore the rest of the source lines in the compiled source member.