Compaq COBOL
User Manual


Previous Contents Index

1.1.2.3 Improving Compile Performance with Separate Compilation (OpenVMS)

The /SEPARATE_COMPILATION qualifier can improve compile-time performance for large source files that are made up of multiple separately compiled programs (SCPs). For programs compiled without this qualifier, the compiler engine parses the entire compilation unit and uses system resources (sized for the total job) for the duration of this compilation. When you use the /SEPARATE_COMPILATION qualifier, the compilation is replaced by a smaller series of operations, and memory structures that are needed for individual procedures are reclaimed and recycled. See Section 1.3.2.4 for additional information. <>

1.1.3 Choosing a Reference Format

You need to choose a reference format before you set out to write a Compaq COBOL program, and you must be aware of the format at compile time. The Compaq COBOL compiler accepts source code written in either terminal or ANSI reference format. You cannot mix reference formats in the same source file.

On OpenVMS, when copying text from Oracle CDD/Repository, the Compaq COBOL compiler translates the record descriptions into the reference format of the source program. <>

1.1.3.1 Terminal Reference Format

Compaq recommends using terminal format, a Compaq optional format, when you create source files from interactive terminals. The compiler accepts terminal format as the default reference format.

Terminal format eliminates the line number and identification fields of ANSI format and allows horizontal tab characters and short lines. Terminal format saves disk space and decreases compile time. It is easier to edit source code written in terminal format.

The following table shows the structure and content of a terminal reference source line: To select ANSI format, specify the -ansi flag (on Tru64 UNIX systems) or the /ANSI_FORMAT qualifier (on OpenVMS Alpha systems) at compile time. You can choose this format if your COBOL program is written for a compiler that uses ANSI format.

For ANSI format, the compiler expects 80-character program lines. The following table shows the structure and content of an ANSI reference source line:
Character Positions Contents
1 to 6 Optional sequence numbers
7 Indicators
8 to 11 Area A
12 to 72 Area B
73 to 80 Optional Area

For more information about the two reference formats, see the Compaq COBOL Reference Manual.

1.1.3.2 Converting Between Reference Formats

The REFORMAT utility allows you to convert a terminal format program to ANSI format and vice versa. You can also use REFORMAT to match the formats of Compaq COBOL source files and library files when their formats are not the same. See Chapter 14 for a description of the REFORMAT utility.

1.2 Developing Programs on Tru64 UNIX

This section briefly describes the Tru64 UNIX commands (commands used at the operating system prompt) that you use to create, compile, link, and run Compaq COBOL programs on Tru64 UNIX systems.

1.2.1 Creating a Compaq COBOL Program on Tru64 UNIX

Use a text editor, such as vi or emacs , to create and revise your source files. For instance, to edit the file prog1.cob using the vi editor, type:


% vi prog1.cob

Figure 1-1 shows the basic steps in Compaq COBOL program development on Tru64 UNIX systems.

Figure 1-1 Commands for Developing Compaq COBOL Programs on Tru64 UNIX


When naming a source file, choose one of the four file name extensions that the cobol compiler recognizes as COBOL file suffixes. These suffixes are:

.cob
.COB
.cbl
.CBL

Table 1-1 shows other file name suffixes.

Table 1-1 Other File Name Suffixes
Suffix Description
.c Identifies C language files passed to the C compiler driver cc , which performs additional command line parsing before invoking the C language compiler.
.s Identifies assembler files passed to cc . Compaq COBOL does not generate .s files.
.o Identifies object files passed to cc , which are in turn passed to ld .
.a Identifies archive object libraries passed to cc , which are in turn passed to ld . All routines in the specified object library will be searched during linking to resolve external references. This is one method of specifying special libraries for which the cobol command does not automatically search.
.so Identifies shared object libraries passed to cc , which are in turn passed to ld . All routines in the specified object library will be searched during linking to resolve external references. This is one method of specifying special libraries for which the cobol command does not automatically search.

The following cobol command compiles the program named prog1.cob and automatically uses the linker ld to link the main program into an executable program file named a.out (the name used if you do not specify a name):


% cobol prog1.cob

The cobol command automatically passes a standard default list of Tru64 UNIX and Compaq COBOL libraries to the ld linker. If all external routines used by a program reside in these standard libraries, additional libraries or object files are not specified on the cobol command line.

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


% a.out

If the executable image is not in your current directory path, specify the directory path in addition to the file name.

The COPY Statement and Libraries

As you write a program, you can use the COPY statement in your source program to include text from another file. With the COPY statement, separate programs can share common source text kept in libraries, reducing development and testing time as well as storage. The Compaq COBOL Reference Manual explains how to use the COPY statement.

Special Considerations for Routines Named "main"

If you have a program or routine named "main," declared either in a Compaq COBOL or other module, your application may not work correctly. The Compaq COBOL library contains a routine named "main," which initializes the run-time environment for the CALL by data name statements, extended ACCEPT and DISPLAY statements, and some error handling. When your application also declares a "main," your routine preempts the Compaq COBOL routine, and the run-time initialization is not performed.

Compaq recommends that you not name a Compaq COBOL program "main."

If you have a C routine named "main," you can work around this problem by having the "main" routine directly call the Compaq COBOL initialization routine, cob_init. The cob_init routine interface (in C) is as follows:


   void cob_init (         /* init the RTL */ 
       int argc,           /* argument count */ 
       char **argv,        /* arguments */ 
       char **envp         /* environment variable pointers */ )  

1.2.2 Compiling a Compaq COBOL Program on Tru64 UNIX

Compilation does the following for you:

To compile your program, use the cobol command.

The COBOL Command Driver

The cobol command invokes a compiler driver that is the actual user interface to the Compaq COBOL compiler. It accepts a list of command flags and file names and causes one or more processors (compiler, assembler, or linker) to process each file.

After the Compaq COBOL compiler processes the appropriate files to create one or more object files, the compiler driver passes a list of files, certain flags, and other information to the cc compiler. After the cc compiler (the default C compiler on your system) processes relevant files and information, it passes certain information (such as .o object files) to the ld linker. The cobol command executes each processor; if any processor returns other than normal status, further processing is discontinued and the Compaq COBOL compiler displays a message identifying the processor (and its returned status, in hexadecimal) before terminating its own execution.

1.2.2.1 Format of the COBOL Command on Tru64 UNIX

The cobol command has the following format:

cobol [--flags [options]]... filename[.suffix] [filename[.suffix]]... [--flags [options]]...

--flags [options]

Indicates either special actions to be performed by the compiler or linker, or special properties of input or output files. For details about command-line flags, see Section 1.2.2.2. If you specify the -l string flag (which indicates libraries to be searched by the linker) or an object library file name, place it after the file names and after other flags.

filename.suffix

Specifies the source files containing the program units to be compiled, where the file name has a suffix that indicates the type of file used. The recognized COBOL suffix characters are .cob , .COB , .cbl , and .CBL .

Note that the compiler driver checks for a valid suffix on filename. If you omit suffix, or if it is not one of the types recognized by the cobol command, the file is assumed to be an object file and is passed directly to the linker.

An example cobol command line would be:


% cobol -v test.cob pas.o

This command specifies the following:

As an additional example, you might find that your compiler command lines are getting rather long, as shown in the following example:


% cobol -rsv foreign_extensions -flagger high_fips -warn information zeroes.cob

To work around this, you may truncate compiler flag options (arguments) to their shortest unambiguous form, as follows:


% cobol -rsv for -flagger high -warn info zeroes.cob

1.2.2.2 COBOL Command Flags

Flags to the cobol command affect how the compiler processes a file. The simplest form of the cobol command is often sufficient.

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

For a complete list of Compaq COBOL flags, see Table 1-2. For more information about the Compaq COBOL flags, access the reference (man) page for COBOL at the Tru64 UNIX system prompt. For example:


%  man cobol

Table 1-2 Compaq COBOL Command Flags on Tru64 UNIX
Flag Default
-align [padding] off
-ansi off
-arch -arch generic
-arithmetic native -arithmetic native
-arithmetic standard -arithmetic native
-C off
-c on
-call_shared on
-check all off
-check [no]bounds -check nobounds
-check [no]decimal -check nodecimal
-check [no]perform -check noperform
-check none on
-conditionals [selector] off
-convert [no]leading_blanks -convert noleading_blanks
-copy off
-copy_list off
-cord off
-cross_reference off
-cross_reference alphabetical off
-cross_reference declared off
-D num off
-display_formatted off
-feedback file off
-fips 74 off
-flagger [option] off
-granularity byte ,
-granularity long ,
-granularity quad
-granularity quad
-g0 off
-g1 on
-g2 or -g off
-g3 off
-include off
-K off
-L off
-L dir off
-list off
-l string off
-mach or -machine_code off
-map off
-map alphabetical off
-map declared off
-math_intermediate cit3 ,
-math_intermediate cit4 ,
-math_intermediate float
-math_intermediate float
-names as_is ,
-names lower ,
-names lowercase ,
-names upper ,
-names uppercase
-names lowercase
-nationality japan ,
-nationality us
-nationality us
-nolocking off
-noobject off
-non_shared -call_shared
-nowarn off
-O0 off
-O1 off
-O2 off
-O3 off
-O4 or -O on
-o output a.out
-p0 on
-p1 or -p off
-relax_key_checking or -rkc off
-rsv [no]200x -rsv no200x
-rsv [no]foreign_extensions -rsv noforeign_extensions
-rsv [no]xopen -rsv xopen
-seq or -sequence_check off
-shared -call_shared
-show code off
-show copy off
-show xref off
-std or -std 85 on
-std [no]mia -std nomia
-std [no]syntax -std nosyntax
-std [no]v3 -std nov3
-std [no]xopen -std xopen
-T num off
-taso off
-tps off
-trunc off
-tune -tune generic
-V off
-v off
-w off
-warn -warn other
-warn all off
-warn [no]information -warn noinformation
-warn [no]other -warn other
-warn none off
-xref, -xref_stdout off


Previous Next Contents Index