HP 3000 Manuals

Compiling Your Program [ Micro Focus COBOL for UNIX COBOL User Guide ] MPE/iX 5.0 Documentation


Micro Focus COBOL for UNIX COBOL User Guide

Compiling Your Program 

Having created your COBOL source code, you must compile it with the COBOL
Compiler.  The Compiler checks the COBOL syntax of your source code and
then creates intermediate object code.

The Compiler is described in detail in your COBOL System Reference.

Using the Compiler Command Line 

Initially your program is likely to contain syntax errors.  To find
these, compile your program.  If your program is in a source file called
myprog.cbl, enter the command:

     cob myprog.cbl

(Don't forget to press Enter to cause the command to be processed.)

Any errors are displayed on the screen.  If there are a lot of errors
then you can direct the errors to a listing file so you can refer to them
while applying the corrections.  The following command creates a listing
file, myprog.lst:

     cob -P myprog.cbl

Following the compilation, the file myprog.lst contains a listing of the
program complete with error messages.  If you just want to place the
error messages in the listing file, you also need the directive, ERRLIST:

     cob -P myprog.cbl -C errlist

In both cases, the error messages also appear on your screen. 
The Error Messages manual contains a list of errors which might occur
during compilation.  If you are in doubt as to the cause of an error,
refer to your 

Language Reference or your On-line Reference for the exact COBOL syntax.

Compiling for Animation 

When you have corrected all your syntax errors, your program is ready for
animation.  You have already used the cob command to compile your
program.  By default this compiles ready for animation, creating an
intermediate code file (.int) and an .idy file which is an information
file required by Animator.

Your program is now ready for debugging using Animator.  See the section
Animating Your Program later in this chapter.

Compiling for Production 

Once you have cleared all your syntax and logic errors, you can create a
program that you can run directly.  To get the best speed you should
create native object code.  To do this, generate your program using:

     cob -uO myprog.int

This creates a native object code file myprog.gnt.  You run this using
the cobrun command.

You can use the intermediate code file, created when compiling for
animation.  Using this file results in a smaller program in most cases,
but one which runs more slowly.

Using Directives 

There are a large number of options available for controlling the way
your program is compiled.  These options are specified using directives
when you invoke the Compiler.  You can enter directives individually on
the command line, or you can create default directives which are then
invoked as a group either automatically or from the command line or from
within the source code.

For normal operation you need to know about and use very few directives.
In the majority of cases you use the default values.  If you do need to
use other directives you can find details of every directive in the COBOL 
System Reference.  The directives are listed there both alphabetically
and by category.

Many directives can be supplied to the Compiler to create code which is
compatible with other COBOL compilers.

A number of directives define the output produced by the Compiler.  You
are likely to use these directives more frequently.

There are several ways of specifying directives.

   *   In the $COBDIR/cobopt file 

   *   In the cobol.dir file

   *   Using the COBOPT environment variable

You can also group directives in a directives file and specify the group
as a single directive in the above places.

In many cases you will use a combination of ways, depending on what you
want to achieve.

cobol.dir.   

If you want to permanently override the default value of a directive,
then place the directive in the file cobol.dir in the directory pointed
to by the COBDIR environment variable.

COBOPT.   

The cobopt file and the COBOPT environment variable provide similar
mechanisms for supplying options to the cob command.  These cob options
can include directives to be passed to the compiler.  However, we
recommend that you use cobol.dir instead, and use these mechanisms only
for specifying options to cob.

Command line.   

When you are controlling the Compiler temporarily to run in a particular
way, use the command line.  For example, to pass the directives NOALTER
and NOQUAL to the Compiler, use:

     cob -C "noalter noqual" myprog.cbl

$SET statement.   

If your program is always affected by particular circumstances then place
the controlling directive on a $SET line in your program.  For example,
your program might require a specific currency sign that none of your
other programs need.  To get this, use the following as the first line of
your program source:

     $SET CURRENCY-SIGN"157"

Directive file.   

If you have a set of directives that you always want to use together,
then use a directives file.  This can be thought of as a macro directive.
For example, you might be migrating some programs from a different
dialect.  Place the directives needed to get compatibility with this
dialect into an ASCII text file, say dialect.dir.  To use this when
compiling a program, place the directive USE"dialect.dir" on the command
line or a $SET line in your program.

The Compiler processes these ways of supplying directives in the order
they are described, above.  If a directive is specified in more than one
place, the Compiler will use the last reference it processes to determine
the value to use.

Obtaining the Fastest Compilation Time 

This section shows you the best way to use the Compiler to keep your
compilation time to a minimum.

Using the Development Cycle Procedure.   

As shown earlier, when you are developing your program, you only need to
compile to intermediate object code while you are debugging.  You do not
need to generate native object code until your program is free of bugs
and ready for production.

Using Directives for Fast Compilation.   

There are several directives that affect the speed of a compilation.
They are:

   *   ALTER

   *   COMS85

   *   COPYLIST

   *   LIST or PRINT

   *   QUAL

These directives are described briefly below.  For more information on
all directives, refer to your COBOL System Reference.

ALTER Directive.   

The ALTER directive enables the use of ALTER statements in your program.
If you know there are no ALTER statements in your source code, specifying
NOALTER enables the Compiler to produce slightly more efficient code as
well as produce it more quickly.  The Compiler assumes ALTER as the
default.

COMS85 Directive.   

This directive allows syntax checking for the ANSI'85 standard in the
Communications Module (COMMUNICATION SECTION, SEND, RECEIVE, and so on).

To prevent this (otherwise unnecessary) syntax checking, and thus speed
up compilation time, do not change the default setting of this directive
(NOCOMS85) unless your program uses the COBOL Message Control System.

COPYLIST Directive.   

COPYLIST tells the Compiler to list the contents of all COPY and INCLUDE
files.

If you are creating a listing file, specifying NOCOPYLIST results in
faster compilation time, as COBOL COPY-files are not expanded in the
listing.  The Compiler assumes COPYLIST as the default.

LIST Directive.   

LIST specifies that you want a listing file to be created.

If you do not need to create a listing file, specifying NOLIST (the
default) speeds up the compilation process.

QUAL Directive.   

QUAL is only required if you are using 
qualified data-names; for example:

     elementary-item-a of group-item-1

If you are not using qualified data-names, you can speed up the
compilation process by using NOQUAL. The Compiler assumes QUAL as the
default.



MPE/iX 5.0 Documentation