Compiler-directing statements

Several compiler-directing statements and one compiler directive help you to direct the compilation of your program.

These are the compiler-directing statements and directive:

*CONTROL (*CBL) statement
This compiler-directing statement selectively suppresses output or causes output to be produced. The keywords *CONTROL and *CBL are synonymous.
>>CALLINTERFACE directive
This compiler directive specifies the interface convention for calls, and indicates whether argument descriptors are to be generated. The convention specified with >>CALLINTERFACE is in effect until another >>CALLINTERFACE specification is made. >>CALLINT is an abbreviation for >>CALLINTERFACE.

>>CALLINTERFACE can be used only in the PROCEDURE DIVISION.

The syntax and usage of the >>CALLINTERFACE directive are similar to that of the CALLINT compiler option. Exceptions are:

  • The directive syntax does not include parentheses.
  • The directive can be applied to selected calls as described below.
  • The directive syntax includes the keyword DESCRIPTOR and its variants.

If you specify >>CALLINT with no suboptions, the call convention used is determined by the CALLINT compiler option.

DESCRIPTOR only: The >>CALLINT directive is treated as a comment except for these forms:

  • >>CALLINT SYSTEM DESCRIPTOR, or equivalently >>CALLINT DESCRIPTOR
  • >>CALLINT SYSTEM NODESCRIPTOR, or equivalently >>CALLINT NODESCRIPTOR

These directives turn DESCRIPTOR on or off; SYSTEM is ignored.

If you code OPTLINK or CDECL (valid COBOL for Windows values) instead of SYSTEM, the compiler generates an I-level diagnostic, and the entire directive (not just the first keyword) is ignored.

The >>CALLINT directive can be specified anywhere that a COBOL procedure statement can be specified. For example, this is valid syntax:

MOVE 3 TO
>>CALLINTERFACE SYSTEM
RETURN-CODE.

The effect of >>CALLINT is limited to the current program. A nested program or a program compiled in the same batch inherits the calling convention specified in the CALLINT compiler option, but not a convention specified by the >>CALLINT compiler directive.

If you are writing a routine that is to be called with >>CALLINT SYSTEM DESCRIPTOR, this is the argument-passing mechanism:

This image shows the CALLINT SYSTEM DESC argument-passing mechanism. Link to detail.

pointer to descr-n
Points to the descriptor for the specific argument; 0 if no descriptor exists for the argument.
descriptor-ID
Set to COBDESC0 to identify this version of the descriptor, allowing for a possible change to the descriptor entry format in the future.
descType
Set to X'02' (descElmt) for an elementary data item of USAGE DISPLAY with PICTURE X(n) or USAGE DISPLAY-1 with PICTURE G(n) or N(n). For all others (numeric fields, structures, tables), set to X'00'.
dataType
Set as follows:
  • descType = X'00': dataType = X'00'
  • descType = X'02' and the USAGE is DISPLAY: dataType = X'02' (typeChar)
  • descType = X'02' and the USAGE is DISPLAY-1: dataType = X'09' (typeGChar)
descInf1
Always set to X'00'.
descInf2
Set as follows:
  • If descType = X'00'; descInf2 = X'00'
  • If descType = X'02':
    • If the CHAR(EBCDIC) option is in effect and the argument is not defined with the NATIVE option in the USAGE clause: descInf2 = X'40'
    • Else: descInf2 = X'00'
length-1
In the argument descriptor is the length of the argument for a fixed-length argument or the current length for a variable-length item.
length-2
The maximum length of the argument if the argument is a variable-length item. For a fixed-length argument, length-2 is equal to length-1.
COPY statement
Read syntax diagramSkip visual syntax diagram
COPY statement syntax

>>-COPY-+-text-name-+-+--------------------------+-------------->
        '-literal-1-' '-+-OF-+--+-library-name-+-'   
                        '-IN-'  '-literal-2----'     

>--+----------+--+-----------------------------------------+---><
   '-SUPPRESS-'  |            .--------------------------. |   
                 |            V                          | |   
                 '-REPLACING----operand-1--BY--operand-2-+-'   

This compiler-directing statement places prewritten text into a COBOL program.

Neither text-name nor library-name need to be unique within a program. They can be identical to other user-defined words in the program.

You must specify a text-name (the name of a copybook) that contains the prewritten text; for example, COPY my-text. You can qualify text-name with a library-name; for example, COPY my-text of inventory-lib. If text-name is not qualified, a library-name of SYSLIB is assumed.

library-name

If you specify library-name as a literal, the content of the literal is treated as the actual path. If you specify library-name as a user-defined word, the name is used as an environment variable and the value of the environment variable is used for the path to locate the copybook. To specify multiple path names, delimit them with a colon (:).

If you do not specify library-name, the path used is as described under text-name.

text-name

If you specify text-name as a literal, the content of the literal is treated as the actual path. If you specify text-name as a user-defined word, processing depends on whether the environment variable that corresponds to text-name is set. If the environment variable is set, the value of the environment variable is used as the file name, and possibly the path name, for the copybook.

A text-name is treated as an absolute path if all three of these conditions are met:

  • library-name is not used.
  • text-name is a literal or an environment variable.
  • The first character is '/'.

For example, this is treated as an absolute path:

COPY "/mycpylib/mytext.cpy"

If the environment variable that corresponds to text-name is not set, the search for the copybook uses the following names:

  1. text-name with suffix .cpy
  2. text-name with suffix .cbl
  3. text-name with suffix .cob
  4. text-name with no suffix

For example, COPY MyCopy searches in the following order:

  1. MYCOPY.cpy (in all the specified paths, as described above)
  2. MYCOPY.cbl (in all the specified paths, as described above)
  3. MYCOPY.cob (in all the specified paths, as described above)
  4. MYCOPY (in all the specified paths, as described above)

COBOL defaults library-name and text-name to uppercase unless the name is contained in a literal ("MyCopy"). In this example, MyCopy is not the same as MYCOPY. If your file name is mixed case (as in MyCopy.cbl), define text-name as a literal in the COPY statement.

-I option

For other cases (when neither a library-name nor text-name indicates the path), the search path is dependent on the -I option.

To have COPY A be equivalent to COPY A OF MYLIB, specify -I$MYLIB.

Based on the above rules, COPY "/X/Y" will be searched in the root directory, and COPY "X/Y" will be searched in the current directory.

COPY A OF SYSLIB is equivalent to COPY A. The -I option does not affect COPY statements that have explicit library-name qualifications besides those with the library name of SYSLIB.

If both library-name and text-name are specified, the compiler inserts a path separator (/) between the two values if library-name does not end in /. For example, COPY MYCOPY OF MYLIB with these settings:

export MYCOPY=MYPDS(MYMEMBER)
export MYLIB=MYFILE

results in MYFILE/MYPDS(MYMEMBER).

If you specify text-name as a user-defined word, you can access local files and also access PDS members on z/OS without changing your mainframe source. For example:

COPY mycopybook

In this example, if the environment variable mycopybook is set to h/mypds(mycopy):

  • h is assigned to the specific host.
  • mypds is the z/OS PDS name.
  • mycopy is the PDS member name.

You can access z/OS files from AIX using NFS (Network File System), which let you access z/OS files by using an AIX path name. However, note that NFS converts the path separator to "." to follow z/OS naming conventions. To ensure proper name formation, keep this in mind when assigning values to your environment variables. For example, these settings:

export MYCOPY=(MYMEMBER)
export MYLIB=M/MYFILE/MYPDS

do not work because the resulting path is:

M/MYFILE/MYPDS/(MYMEMBER)

which after conversion of the path separator becomes:

M.MYFILE.MYPDS.(MYMEMBER)
PROCESS (CBL) statement
This compiler-directing statement, which you can place before the IDENTIFICATION DIVISION header of an outermost program, specifies compiler options that are to be used during compilation of the program.

related references   
cob2, cob2_j, and cob2_r options
  
CALLINTERFACE directive (COBOL for AIX Language Reference)  
CBL (PROCESS) statement (COBOL for AIX Language Reference)  
*CONTROL (*CBL) statement (COBOL for AIX Language Reference)  
COPY statement (COBOL for AIX Language Reference)