Compaq COBOL
User Manual


Previous Contents Index

1.3.2 Compiling a Compaq COBOL Program on OpenVMS Alpha

To compile your program, use the COBOL command. The Compaq COBOL compiler performs these primary functions:

The compiler outputs an object module that provides the following information:

To invoke the Compaq COBOL compiler, use the COBOL command (explained in Section 1.3.2.1). You can specify qualifiers with the COBOL command. The following sections discuss the COBOL command and its qualifiers.

1.3.2.1 Format of the COBOL Command on OpenVMS Alpha

The COBOL command has the following format:

COBOL [/qualifier] ... {file-spec [/qualifier] ...} ...

/qualifier

Specifies an action to be performed by the compiler on all files or specific files listed. When a qualifier appears directly after the COBOL command, it affects all the files listed. By contrast, when a qualifier appears after a file specification, it affects only the file that immediately precedes it. However, when files are concatenated, these rules do not apply.

file-spec

Specifies an input source file that contains the program or module to be compiled. You are not required to specify a file type; the Compaq COBOL compiler assumes the default file type COB. If you do not provide a file specification with the COBOL command, the system prompts you for one.

1.3.2.2 Compiling Multiple Files

You can include more than one file specification on the same command line by separating the file specifications with either a comma (,) or a plus sign (+). If you separate the file specifications with commas, you can control which source files are affected by each qualifier. In the following example, the Compaq COBOL compiler creates an object file for each source file but creates only a listing file for the source files entitled PROG_1 and PROG_3:


$ COBOL/LIST PROG_1, PROG_2/NOLIST, PROG_3

If you separate file specifications with plus signs, the Compaq COBOL compiler concatenates each of the specified source files and creates one object file and one listing file. In the following example, only one object file, PROG_1.OBJ, and one listing file, PROG_1.LIS, are created. Both of these files are named after the first source file in the list, but contain all three modules.


$ COBOL PROG_1 + PROG_2/LIST + PROG_3

Any qualifiers specified for a single file within a list of files separated with plus signs affect all files in the list.

1.3.2.3 Debugging a Program

To effectively debug a Compaq COBOL program, you must first make symbol and traceback information available by adding the DEBUG option to the compile command line. You specify the /DEBUG option as follows:


$ COBOL/DEBUG myprog 
$ LINK/DEBUG myprog 
$ RUN/DEBUG myprog 

This enables you to examine and modify variables, monitor flow of control, and perform various other debugging techniques. See HELP COBOL/DEBUG, HELP DEBUG, and Section C.4,OpenVMS Debugger (OpenVMS) for additional information.

When you compile a program with /DEBUG, you should also specify /NOOPTIMIZE (-O0) to expedite your debugging session. (The default is /OPTIMIZE (-O).) Optimization often changes the order of execution of the object code generated for statements in a program, and it might keep values in registers and deallocate user variables. These effects can be confusing when you use the debugger. (A diagnostic message warns you if you compile a Compaq COBOL program with /DEBUG without specifying anything about optimization on the command line.)

1.3.2.4 Separately Compiled Programs

If a compilation unit consists of multiple separately compiled programs (SCPs), by default the Compaq COBOL compiler produces a single object file that consists of a single module with multiple embedded procedures. This object file can be inserted into an object library. If your build procedure requires that the linker extract any part of the module, the linker must extract the entire object.

If you use /SEPARATE_COMPILATION on the compile command line Compaq COBOL will compile multiple SCPs into a single object file that consists of a concatenation of modules, each containing a single procedure. This object may then be inserted into an object library from which the linker can extract just the procedures that are specifically needed.

1.3.2.5 COBOL Qualifiers

COBOL options (also known as qualifiers or flags) control the way in which the compiler processes a file. You can process your file with the COBOL command alone or you can select options that offer you alternatives for developing, debugging, and documenting programs.

If you compile parts of your program (compilation units) using multiple COBOL commands, options that affect the execution of the program should be used consistently for all compilations, especially if data will be shared or passed between procedures.

Table 1-4 lists the COBOL command options and their defaults. For more information about COBOL options, invoke online help for COBOL at the system prompt.

Note

Brackets ([]) indicate that the enclosed item is optional. If you specify more than one option for a single qualifier, you must separate each option with a comma and enclose the list of options in parentheses.

Table 1-4 COBOL Command Qualifiers
   


1.3.2.6 Common Command-Line Errors to Avoid

The following are some common errors to avoid when entering COBOL command lines:

1.3.2.7 Compiling Programs with Conditional Compilation

To debug source code that contains conditional compilation lines, you can use either the /CONDITIONALS qualifier or the WITH DEBUGGING MODE clause. The /CONDITIONALS qualifier is listed in Table 1-4. For more information about the /CONDITIONALS qualifier, invoke the online Help facility for Compaq COBOL at the system prompt. For more information about the WITH DEBUGGING MODE clause, refer to the Compaq COBOL Reference Manual.

Using the WITH DEBUGGING MODE clause as part of the SOURCE-COMPUTER paragraph causes the compiler to process all conditional compilation lines in your program as COBOL text. If you do not specify the WITH DEBUGGING MODE clause, and if the /CONDITIONALS qualifier is not in effect, all conditional compilation lines in your program are treated as comments.

The WITH DEBUGGING MODE clause applies to: (1) the program that specifies it, and (2) any contained program within a program that specifies the clause.

1.3.2.8 Interpreting Messages from the Compiler

If there are errors in your source file when you compile your program, the Compaq COBOL compiler flags these errors and displays helpful messages. You can reference the message, locate the error, and, if necessary, correct the error in your program.

The general format of compiler messages shown on your screen is shown in the following example:

..........................^
%COBOL-s-ident, message-text
At line number n in name

%COBOL

The facility or program name of the Compaq COBOL compiler. This prefix indicates that the Compaq COBOL compiler issued the message.

s

The severity of the error, represented in the following way:
F Fatal error. The compiler does not produce an object module. You must correct the error before you can compile the program to produce an object module.
E Error. The compiler makes an assumption about what you intended and continues. However, the compiler's assumption may not relate to your intention. Correct the error.
W Warning. The compiler attempts to correct the error in the statement, but you should verify that the compiler's action is acceptable. Otherwise, your program may produce unexpected results.
I Informational. This message usually appears with other messages to inform you of specific actions taken by the compiler. No action is necessary on your part. Note that these messages are suppressed by default. You must invoke /WARN=ALL or /WARN=INFO to enable them.

ident

The message identification. This is a descriptive abbreviation of the message text.

message-text

The compiler's message. In many cases, it consists of no more than one line of output. A message generally provides you with enough information to determine the cause of the error so that you can correct it.

At line number n in name

The integer n is the number of the line where the diagnostic occurs. The number is relative to the beginning of the file or text library module specified by name.

A sample compiler message with two diagnostics looks like this in the listing file:


   12          PROCEDURE DIVISION. 
   13          P-NAME 
   14              MOVE ABC TO XYZ. 
   ................^ 
%COBOL-E-NODOT, Missing period is assumed 
 
 
   14              MOVE ABC TO XYZ. 
   ............................^ 
%COBOL-F-UNDEFSYM, Undefined name 

In the sample, the first diagnostic pointer (^) points to the MOVE statement in source line number 14, which is the closest approximation to where the error (P-NAME is not followed by a period) occurred. The second diagnostic pointer points to XYZ, an undefined name in source line number 14. Each diagnostic pointer is followed by a message line that identifies, in this order:

Although most compiler messages are self-explanatory, some require additional explanation. The online HELP facility for Compaq COBOL contains a list and descriptions of these Compaq COBOL compiler messages. Use the HELP COBOL Compiler Messages command to access this list.

To examine messages that occurred during compilation, you can search for each occurrence of %COBOL in the compiler listing file. Section 1.3.2.9 describes listing files.

The severity levels, and what you should do next, are as follows:
Severe The compiler does not produce an object module. You must correct the error before you can compile the program to produce an object module.
Error The compiler makes an assumption about what you intended and continues. However, the compiler's assumption may not relate to your intention. Correct the error.
Warning The compiler attempts to correct the error in the statement, but you should verify that the compiler's action is acceptable. Otherwise, your program may produce unexpected results.
Informational This message usually appears with other messages to inform you of specific actions taken by the compiler. No action is necessary on your part.

1.3.2.9 Using Compiler Listing Files

A compiler listing file provides information that can help you debug or document your Compaq COBOL program. It consists of the following sections:

To generate a listing file, specify the /LIST qualifier when you compile your Compaq COBOL program interactively as in the following example for PROG_1.COB:


$  COBOL/LIST PROG_1.COB 

If you compile your program as a batch job, the compiler creates a listing file by default. You can specify the /NOLIST qualifier to suppress creation of the listing file, if that suits your purposes. (In either case, however, the listing file is not automatically printed.) By default, the name of the listing file is the name of your source file followed by the file type .LIS. You can include a file specification with the /LIST qualifier to override this default.

When used with the /LIST qualifier, the following COBOL command qualifiers supply additional information in the compiler listing file:

For a description of each qualifier's function, invoke the online HELP facility for COBOL at the system prompt as follows:


$ HELP COBOL 

Compiler Listing File for a Contained Program

A contained COBOL program listing file includes two additional program elements that provide nesting level information about the main program and the contained program. For additional information about contained programs, see Chapter 12, Interprogram Communication.

1.3.3 Linking a Compaq COBOL Program

After you compile a Compaq COBOL source program or module, use the LINK command to combine your object modules into one executable image that the OpenVMS Alpha operating system can execute. A source program or module cannot run until it is linked.

When you execute the LINK command, the OpenVMS Alpha Linker performs the following functions:

The LINK command produces an executable image by default. However, you can specify qualifiers and qualifier options with the LINK command to obtain shareable images and system images.

See Table 1-5 for a list of commonly used LINK command qualifiers. For a complete list and for more information about the LINK qualifiers, invoke the online HELP facility for the LINK command at the system prompt.

For a complete discussion of linker capabilities and for detailed descriptions of LINK qualifiers and qualifier options, see the OpenVMS Linker Utility Manual.

1.3.3.1 The LINK Command

The format of the LINK command is as follows:

LINK[/qualifier] ... {file-spec[/qualifier] ...} ...

/qualifier...

Specifies output file options when it is positioned after the LINK command. Specifies input file options when it is positioned after file-spec.

file-spec...

Specifies the input files to be linked.

If you specify more than one input file, you must separate the input file specifications with a plus sign (+) or a comma (,).

By default, the linker creates an output file with the name of the first input file specified and the file type EXE. If you link multiple files, specify the file containing the main program first. Then the name of your output file will have the same name as your main program module.

The following command line links the object files MAINPROG.OBJ, SUBPROG1.OBJ, and SUBPROG2.OBJ to produce one executable image called MAINPROG.EXE:


$ LINK MAINPROG, SUBPROG1, SUBPROG2
 

1.3.3.2 LINK Qualifiers

LINK qualifiers allow you to control various aspects of the link operation such as modifying linker input and output and invoking the debugging and traceback facilities.

Table 1-5 summarizes some of the more commonly used LINK qualifiers. Refer to the OpenVMS Linker Utility Manual for a complete list and explanations of the LINK qualifiers or invoke the online HELP facility for the LINK command at the OpenVMS Alpha prompt.

Note

Brackets ([]) indicate that the enclosed item is optional. If you specify more than one option for a single qualifier, you must separate each option with a comma and enclose the list of options in parentheses.

Table 1-5 Commonly Used LINK Qualifiers
Function Qualifier Default
Indicate that an input file
is a library file.
/LIBRARY Not applicable.
 
Indicate that an input file
is a linker options file.
/OPTIONS Not applicable.
 
Request output file,
define a file specification,
and specify whether the
image is shareable.
/EXECUTABLE[=file-spec]
/SHAREABLE[=file-spec]
/EXECUTABLE=
name.EXE

where name is the name of the first input file.
/NOSHAREABLE
 
Request and specify the
contents of an image map
(memory allocation) listing.
/BRIEF
/[NO]CROSS_REFERENCE
/FULL
/MAP[=file-spec] or /NOMAP
/NOCROSS_REFERENCE
/NOMAP (interactive)
/MAP=name.MAP (batch)

where name is the name of the first input file.
 
Specify the amount of
debugging information.
/DEBUG[=file-spec] or /NODEBUG
/[NO]TRACEBACK
/NODEBUG
/TRACEBACK


Previous Next Contents Index