DIRECTIVES


Directives are controls that are placed into a source program. Two types of directives exist: compiler directives and preprocessor directives. All directives begin in position 7 of the RPG statement.

Compiler directives control various functions of the compile process, such as page printing and inclusion of external source code.

Preprocessors analyze and run directives. A preprocessor is a program that reads the RPG source code and performs some work, possibly altering the RPG source code, before calling the RPG compiler. The RPG compiler and SQL preprocessor directives provide functions to alter the RPG program listing and to include the SQL database manager. Table 1.16 lists these directives. Figure 1.11 illustrates the use of several RPG compiler directives as well as SQL preprocessor directives.

click to expand
Figure 1.11: Example of RPG directives.

Table 1.16: Preprocessor/Compiler Directives

Directive

Description

/COPY [[library/]file,]member

Causes the compiler to include source code contained in a separate source member. Any RPG source code can be included using the /COPY directive, including another /COPY directive.

/COPY 'ifs-file/folder-name'

Same function as /COPY except supports including source code from the integrated hierarchical file system (IFS). The IFS file name must be enclosed in single quotes.

/INCLUDE [[library/]file,]member

Same function as /COPY except avoids being processed by the SQL preprocessor.

/INCLUDE 'ifs-title/folder-name'

Same function as /INCLUDE except supports including source code from the integrated hierarchical file system (IFS). The IFS file name must be enclosed in single quotes.

/EJECT

Causes the compiler to skip to the top of the next page when the compiled program is printed.

/TITLE TEXT

Causes the compiler to print the text on the top of each page of the printed compiler list. Subsequent /TITLE directives override previous /TITLE.

/SPACE [n]

Causes the compiler to print n blank lines. If no n value is specified, 1 is assumed. Up to 255 can be specified. This directive is a legacy feature. Previous versions of RPG didn't allow blank lines to be embedded in the actual source itself. This directive allowed blank lines to be printed on compiler listings. This directive has been deprecated with the support in RPG for blank lines.

/EXEC SQL [SQL statement]

This SQL preprocessor directive starts an SQL statement. The SQL statement can begin on this line or on a subsequent line.

+ continued-SQL statement

This SQL preprocessor directive indicates the continuation of the SQL statement that began with /EXEC SQL.

/END-EXEC

This SQL preprocessor directive ends the SQL statement that followed the previous /EXEC SQL.

With the exception of the /COPY compiler directive, most compiler directives offer little additional function. The /COPY compiler directive allows external source members to be included at compile time.

Conditional Compiler Preprocessor Source Directives

To condition the inclusion of source, RPG IV supports several compiler directives. These directives are interpreted prior to compiling. They control which sections of source are included when the source is compiled. Compiler directives must be specified starting in position 7 of the RPG source statement. Directives that require a parameter must be by one or more blanks and then the parameter. Table 1.17 lists the directives.

Table 1.17: Conditional Preprocessor Source Directives

Preprocessor Directive

Description

/DEFINE identifier

Defines an identifier. An identifier is similar to a variable in a program, except it is not available to the program. Subsequent directives that determine if the identifier has been defined use the identifier. The DEFINE parameter of the CRTBNDRPG and CRTRPGMOD commands also allows an identifier to be defined to the preprocessor.

/UNDEFINE

Removes an identifier. The identifier no longer exists and causes a subsequent /IF DEFINED for that identifier to fail.

/IF DEFINED(identifier)

Returns a true condition if the identifier has previously been defined with a /DEFINE directive. If the condition is true, the source following the directive is included.

/IF NOT DEFINED(identifier)

Returns a true condition if the identifier is not defined. If the condition is true, the source following the directive is included.

/ELSEIF DEFINED(identifier)

Returns true if the identifier has previously been defined. Use this directive to test for an identifier within another /IF or /ELSEIF directive. If the condition is true, the source following the directive is included.

/ELSEIF NOT DEFINED(identifier)

Returns true if the identifier is not defined. Use this directive to test for an identifier within another /IF or /ELSEIF directive. If the condition is true, the source following the directive is included.

/ELSE

Unconditionally includes the source code that follows the directive. Functions as the "else" condition for a corresponding /IF or /ELSEIF directive.

/EOF

Causes the compiler to stop processing the source code following this statement. Use this directive in conjunction with /IF to cause termination of source that is being included with the /COPY directive.

/ENDIF

Ends the previous /IF or /ELSEIF directive.




The Modern RPG IV Language
The Modern RPG IV Language
ISBN: 1583470646
EAN: 2147483647
Year: 2003
Pages: 156
Authors: Robert Cozzi

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net