Compaq COBOL
User Manual


Previous Contents Index

Technical Notes:

  1. If your program compile generates Errors (E-level diagnostics on OpenVMS Alpha), the link phase of the two steps taken by the compiler driver will be aborted and the object file(s) deleted. You can override this deletion by specifying the -c flag:


    % cobol -c test.cob 
    % cobol test.o 
    

    The Compaq COBOL compiler driver (see Section 1.2.2) controls a sequence of operations (as required): compiling, assembling, linking. The -c flag signals the compiler driver to break the sequence.
    (For additional information, see The COBOL Command Driver description (earlier in this chapter), Section 1.2.2.12, and the -c description under man cobol .)

  2. The -tps flag causes the Compaq COBOL compiler to use an external file handler (produced by a third party), providing increased flexibility in cross platform, transaction processing application development. See Section 1.2.2.3 for more information.
  3. The -xref and -xref_stdout flags direct the Compaq COBOL compiler to generate a data file that the Compaq FUSE Database Manager uses to create a static analysis database file. This improves the performance of the Compaq FUSE Call Graph Browser and the Compaq FUSE Cross-Referencer, which use the database file for their operations. See the Compaq FUSE documentation for more information on the Compaq FUSE static analysis database, the Compaq FUSE Cross-Referencer and Compaq FUSE Call Graph Browser.
    Specifying the -xref_stdout option directs the compiler to output the data file to standard output.
  4. Any copy file that contains a PROGRAM-ID or END PROGRAM statement for a program must contain that entire program. When compiled in the Compaq FUSE environment (using the compiler options -xref or -xref_stdout ), certain Compaq COBOL programs may fail, with this fatal diagnostic result:


    cobol: Severe: Fatal error -7 returned from a cross-referencing 
    library procedure 
    

    To avoid this error, programmers should ensure that any subroutine beginning in a given file ends in the same file.

1.2.2.3 External File Handler Support

The -tps flag allows Compaq COBOL applications to make use of ACMSxp, the Application Control and Management System/Cross-Platform Edition.

-tps specifies that files are part of a transaction processing system, and enables Encina Structured File System (SFS) record storage for applicable files. It is intended to be used in conjunction with the Transarc Encina external file handler and ACMSxp, allowing access to data in a wide variety of databases, without the need to write code in the language of the databases. This approach provides access to transaction processing technology, and incorporates industry standards for data communications and distributed computing. ACMSxp conforms to the the Multivendor Integration Architecture (MIA).

COBOL is one of the languages approved by MIA for transaction processing (TP) client programs, customer-written presentation procedures, and processing procedures. For database access, Structured Query Language (SQL) is the MIA-required access language. The SQL is embedded in COBOL and C.

See the ACMSxp documentation for full details. Additional information can also be found in published Distributed Computing Environment (DCE) documentation.

1.2.2.4 Specifying Multiple Files and Flags

The cobol command can specify multiple file names and multiple flags. Multiple file names are delimited by spaces. If appropriate, each file name can have a different suffix. The file name suffix could result in the following actions:

When a file is not in your current working directory, specify the directory path before the file name.

1.2.2.5 Compiling Multiple Files

An entire set of source files can be compiled and linked together using a single cobol command:


% cobol -o calc mainprog.cob array_calc.cob calc_aver.cob 

This cobol command:

The files can also be compiled separately, as follows:


% cobol -c array_calc.cob
% cobol -c calc_aver.cob
% cobol -o calc mainprog.cob array_calc.o calc_aver.o

In this case, the -c option prevents linking and retains the .o files. The first command creates the file array_calc.o . The second command creates the file calc_aver.o . The last command compiles the main program and links the object files into the executable program named calc .

If your path definition includes the directory containing calc , you can run the program by simply typing its name:


% calc

You can compile multiple source files by concatenating them:


% cat proga1.cob proga2.cob proga3.cob > com1.cob 
% cat progb1.cob progb2.cob > com2.cob 
% cobol -c com1.cob com2.cob 

The resulting file names are com1.o and com2.o. The OpenVMS Alpha equivalent to this is:


$ COBOL proga1+proga2+proga3,progb1+progb2 

1.2.2.6 Debugging a Program

To debug a program using the Ladebug Debugger, compile the source files with the -g flag to request additional symbol table information for source line debugging in the object and executable program files. The following cobol command also uses the -o flag to name the executable program file calc_debug :


% cobol -g -o calc_debug  mainprog.cob array_calc.cob calc_aver.cob

To debug an executable program named calc_debug, type the following command:


% ladebug calc_debug

For more information on running the program within the debugger, see the Ladebug Debugger Manual.

1.2.2.7 Output Files: Object, Executable, Listing, and Temporary Files

The output produced by the cobol command includes:

If the environment variable TMPDIR is set, the value is used as the directory for temporary files.

You control the production of these files by specifying the appropriate flags on the cobol command line. Unless you specify the -c flag, the compiler generates a single temporary object file, whether you specify one source file or multiple source files separated by blanks. The ld linker is then invoked to link the object file into one executable image file.

The object file is in Tru64 UNIX extended coff format. The object file provides the following information:

If severe errors are encountered during compilation or if you specify certain flags such as -c , linking does not occur.

1.2.2.8 Naming Output Files

To specify a file name (other than a.out ) for the executable image file, use the -o output flag, where output specifies the file name. You can also use the mv command to rename the file. The following command requests a file name of prog1.out for the source file test1.cob :


% cobol -o prog1.out test1.cob

Besides specifying the name of the executable image file, you can use the -o output flag to rename the object file if you specified the -c flag. If you specify the -c flag and omit the -o output flag, the name of the first specified file is used with a .o suffix substituted for the source file suffix.

1.2.2.9 Temporary Files

Temporary files created by the compiler or a preprocessor reside in the /tmp directory and are deleted (unless the -K flag is specified). You can set the environment variable TMPDIR to specify a directory to contain temporary files if /tmp is not acceptable.

To view the file name and directory where each temporary file is created, use the -v flag. To create object files in your current working directory, use the -c flag. Any object files ( .o files) that you specify on the cobol command line are retained.

1.2.2.10 Examples of the COBOL Command

The following examples show the use of the cobol command. Each command is followed by a description of the output files that it produces.


#1

% cobol -V aaa.cob bbb.cob ccc.cob
      

The Compaq COBOL source files aaa.cob , bbb.cob , and ccc.cob are compiled into temporary object files. The temporary object files are passed to the ld linker. The ld linker produces the executable file a.out . The -V flag causes the compiler to create the listing files aaa.lis , bbb.lis , and ccc.lis .

#2

% cobol -V *.cob
      

Compaq COBOL source files with file names that end with .cob are compiled into temporary object files, which are then passed to the ld linker. The ld linker produces the a.out file.

When the compilation completes, the cobol driver returns one of the following status values:

0---SUCCESS
1---FAILURE
2---SUBPROCESS_FAILURE ( cobol or cc )
3---SIGNAL

1.2.2.11 Other Compilers

You can compile and link multilanguage programs using a single cobol command.

The cobol command recognizes C or Assembler program files by their file suffix characters and passes them to the cc compiler for compilation. Before compilation, cc applies the cpp preprocessor to files that it recognizes, such as any file with a .c suffix.

Certain flags passed to cc are passed to the ld linker.

1.2.2.12 Interpreting Messages from the Compiler

The Compaq COBOL compiler identifies syntax errors and violations of language rules in the program. If the compiler finds any errors, it writes messages to the stderr output file and any listing file. If you enter the cobol command interactively, the messages are displayed on your terminal.

Compiler messages have the following format:


 cobol: severity: filename, line n, message-text 
 [text-in-error] 
 --------^ 

The pointer ( --^ ) indicates the exact place on the source line where the error was found. For example, the following error message shows the format and message text in a listing file when an END DO statement was omitted:


cobol: Severe: disp.cob, line 7: Missing period is assumed 
        05 VAR-1 PIC X. 
--------^ 

The severity level is one of the following:
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.

Any messages issued during the compilation are inserted in the listing file. A listing file is useful for debugging the source code. Use the -V or -list flag to produce a listing; you may also use -cross_reference , -copy_list , -flagger , -machine_code , -map , and/or -warn , all of which affect the contents of the listing file.

Diagnostic messages provide information for you to determine the cause of an error and correct it. If the compiler creates a listing file, it writes the messages to the listing file.

1.2.3 Linking a Compaq COBOL Program on Tru64 UNIX

Once your program has compiled successfully, the system passes the resulting object file (which has the suffix .o by default) to the linker to create an executable image file. By default, the executable image file has the name a.out. (To change this default, specify -o filename on the cobol command line.) This file can be run on the Tru64 UNIX system.

The ld linker provides the following primary functions:

The linker produces an executable program image with a default name of a.out.

When you enter a cobol command, the ld linker is invoked automatically unless a compilation error occurs or you specify the -c flag on the command line.

1.2.3.1 Specifying Object Libraries for Linking

You can specify object libraries on the COBOL command line by using certain flags or by providing the file name of the library. These object libraries are also searched by ld for unresolved external references.

When cobol specifies certain libraries to ld , it provides a standard list of COBOL library file names to ld . The ld linker tries to locate each of these library file names in a standard list of library directories. That is, ld attempts to locate each object library file name first in one directory, then in the second, and then in the third directory on its search list of directories.

To display a list of the compilers invoked, files processed, and libraries accessed during linking, specify the -v flag.

In addition to an object file created by the compiler, any linker flags and object files specified on the cobol command are also passed to the ld linker. The linker loads object files according to the order in which they are specified on the command line. Because of this, you must specify object libraries after all source and object files on the cobol command line.

To help identify undefined references to routines or other symbols in an object module, consider using the nm command. For instance, in the following example the nm command filtered by the grep command lists all undefined (U) symbols:


% cobol -c ex.cob
% nm -o ex.o | grep U

If the symbol is undefined, U appears in the column before the symbol name. Any symbols with a U in their names can also be displayed by this use of grep .

1.2.3.2 Specifying Additional Object Libraries

You can control the libraries as follows:

When processing a C source file ( .c suffix) using the cobol command, you may need to specify the appropriate C libraries using the -l string flag.


Previous Next Contents Index