Compiler-directing statements
Several compiler-directing statements help you to direct the compilation of your program.
These are the compiler-directing statements:
BASIS
statement- This extended source program library statement provides a
complete COBOL program as the source for a compilation. For rules of formation and processing, see
the description of text-name for the
COPY
statement. *CONTROL (*CBL)
statement-
This compiler-directing statement selectively suppresses
or allows 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 thePROCEDURE DIVISION
.The syntax and usage of the
>>CALLINTERFACE
directive are similar to that of theCALLINT
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 theCALLINT
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.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 theCALLINT
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:- 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
withPICTURE X
(n) orUSAGE DISPLAY-1
withPICTURE G
(n) orN
(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
isDISPLAY
: dataType = X'02' (typeChar) - descType = X'02' and the
USAGE
isDISPLAY-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 theNATIVE
option in theUSAGE
clause: descInf2 = X'40' - Else: descInf2 = X'00'
- If the
- 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-
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 ofSYSLIB
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:
- text-name with suffix .cpy
- text-name with suffix .cbl
- text-name with suffix .cob
- text-name with no suffix
For example,
COPY MyCopy
searches in the following order:- MYCOPY.cpy (in all the specified paths, as described above)
- MYCOPY.cbl (in all the specified paths, as described above)
- MYCOPY.cob (in all the specified paths, as described above)
- 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 asMYCOPY
. If your file name is mixed case (as in MyCopy.cbl), define text-name as a literal in theCOPY
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 toCOPY A OF MYLIB
, specify-I$MYLIB
.Based on the above rules,
COPY "/X/Y"
will be searched in the root directory, andCOPY "X/Y"
will be searched in the current directory.COPY A OF SYSLIB
is equivalent toCOPY A
. The-I
option does not affectCOPY
statements that have explicit library-name qualifications besides those with the library name ofSYSLIB
.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 Linux® using NFS (Network File System), which let you access z/OS files by using a Linux 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)
DELETE
statement- This extended
source library statement removes COBOL statements from the
BASIS
source program. EJECT
statement- This compiler-directing statement specifies that the next source statement is to be printed at the top of the next page.
ENTER
statement- The statement is treated as a comment.
EVALUATE
directive- The EVALUATE directive provides a multi-branch method of choosing the source lines to include in a compilation group.
IF
directive- The IF directive provides for a one-way or two-way conditional compilation.
INSERT
statement- This library statement adds COBOL statements to the
BASIS
source program. 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. REPLACE
statement- This statement is used to replace source program text.
SKIP1/2/3
statement- These statements indicate lines to be skipped in the source listing.
TITLE
statement- This statement specifies that a title (header) should be printed at the top of each page of the source listing.
USE
statement- The
USE
statement provides declaratives to specify these elements:- Error-handling procedures:
EXCEPTION/ERROR
-
User label-handling
procedures:
LABEL
- Debugging lines and sections:
DEBUGGING
- Error-handling procedures:
Changing the header of a source listing
Compiling from the command line
Specifying compiler options in the PROCESS (CBL) statement
cob2 options
CALLINTERFACE (COBOL for Linux on x86 Language Reference)
PROCESS (CBL) statement (COBOL for Linux on x86 Language Reference)
*CONTROL (*CBL) statement (COBOL for Linux on x86 Language Reference)
COPY statement (COBOL for Linux on x86 Language Reference)
DEFINE directive (COBOL for Linux on x86 Language Reference)
EVALUATE directive (COBOL for Linux on x86 Language Reference)
IF directive (COBOL for Linux on x86 Language Reference)