Compiling, Linking, and Executing Your Program [ HP COBOL II/XL Programmer's Guide ] MPE/iX 5.0 Documentation
HP COBOL II/XL Programmer's Guide
Compiling, Linking, and Executing Your Program
When you compile your program, the COBOL compiler translates your COBOL
source program to object code and resolves calls to nested programs.
When you link your program, the link editor resolves calls to subprograms
that are to be bound at link time (not all subprograms; see Chapter 4
). Your program must be linked whether it calls such subprograms or
not. The link editor uses object code to produce a program file.
When you execute your program, the loader loads the program file into
memory and the operating system executes it.
Figure 6-1 shows how a source program becomes an executing program.
Figure 6-1. How a Source Program Becomes an Executing Program
If the source program consists of a main program and one or more
subprograms, the main program and each subprogram must be compiled
separately. The resulting object files must be linked together into a
single program file. An object file cannot contain more than one
program.
Figure 6-2 shows the input to the COBOL compiler and the output from
it.[REV BEG] Note that COPYLIB and INCLUDE files can also be used for
input.[REV END] Formal file designators are in italic capital letters.
Figure 6-2. COBOL Compiler Input and Output
The rest of this section explains the following:
* The two compiler entry points and the two compiler modes.
* How to use file equations with the FILE command.
* How to run the COBOL compiler with the MPE XL RUN command.
* How to compile, link, and execute your program with Native Mode
command files.
* How to compile, link, and execute your program with Compatibility
Mode compiler UDCs or commands.
* How to use relocatable and executable libraries.
* Examples of compiling, linking, and executing programs.
Compiler Entry Points and Modes
The COBOL compiler is "two compilers in one." That is, it has two entry
points, ANSI74 and ANSI85. When you invoke it through the ANSI74 entry
point, ANSI COBOL 1974 syntax and semantics apply. When you invoke it
through the ANSI85 entry point, ANSI COBOL 1985 syntax and semantics
apply. The ANSI74 entry point is provided for compatibility with older
COBOL compilers.
The COBOL compiler also has two modes, Native Mode and Compatibility
Mode. In Native Mode, the compiler produces object code designed
especially for the MPE XL operating system. This code runs very fast on
MPE XL. In Compatibility Mode, the compiler produces object code designed
especially for the MPE V operating system. It runs on MPE XL, but not as
efficiently as Native Mode object code does, because MPE XL must simulate
the MPE V system hardware and microcode. Compatibility Mode is provided
for compatibility with the MPE V operating system.
Both entry points are available in both modes. In summary, the entry
points differ in the source code that they recognize, and the modes
differ in the object code that they generate.
Table 6-3 shows what the compiler does with each entry point in
Native Mode and Compatibility Mode.
Table 6-3. Entry Point and Mode Combination
------------------------------------------------------------------------------------------
| | | |
| Entry Point | Native Mode | Compatibility Mode |
| | | |
------------------------------------------------------------------------------------------
| | | |
| ANSI85 | Translates ANSI COBOL 1985 source | Translates ANSI COBOL 1985 source |
| | code to MPE XL object code. | code to MPE V object code. |
| | | |
------------------------------------------------------------------------------------------
| | | |
| ANSI74 | Translates ANSI COBOL 1974 source | Translates ANSI COBOL 1974 source |
| | code to MPE XL object code. | code to MPE V object code. |
| | | |
------------------------------------------------------------------------------------------
File Equations
When you use a file equation (the FILE command), its formal designator
must match the file name in the ASSIGN clause of the SELECT statement.
Example.
The following SELECT statement declares the logical file MY-FILE:
SELECT MY-FILE ASSIGN TO "MFILE".
The following file equation associates the logical file MY-FILE with the
physical file REALFILE:
:FILE MFILE=REALFILE
You can use a file equation to do the following:
* Tell your COBOL program to change the temporary file that it
creates to a permanent file. For example, the following FILE
command causes the temporary file MFILE to be made a permanent
file:
:FILE MFILE;SAVE
One alternative to the FILE command is to use the SAVE command
SAVE MFILE before the job or session ends. For example, the
following also causes the temporary file MFILE to be made a
permanent file:
:SAVE MFILE
* Override default file characteristics.
* Create a circular file.
* Create a message file.
An alternative to a file equation or the FILE command in each of the
above cases is to create the file with the BUILD command before you
execute the program. For more information on files and the FILE command,
see Chapter 5 .
[REV BEG]
Native Mode Compiler Command Files and RUN Command
You can invoke the Native Mode COBOL compiler and compile your COBOL
program in Native Mode with either the RUN command or one of the six
command files COB85XL, COB85XLK, COB85XLG, COB74XL, COB74XLK, or
COB74XLG. These command files can compile, link, and execute your
program. You can use one of the six existing command files or write your
own. For more information on compiling, linking, and executing your
program, see the appendix "MPE XL System Dependencies" in the HP COBOL
II/XL Reference Manual.[REV END]
Compatibility Mode Compiler UDCs and Commands
To compile your program in Compatibility Mode, use a UDC (User-Defined
Command) or a command to compile, link, and execute your program. Table
6-4 and Table 6-5 list each UDC and command that invokes the
Compatibility Mode COBOL compiler, the entry point through which it
invokes the compiler, and its other effects.
Table 6-4. Compatibility Mode UDCs
--------------------------------------------------------------------------------------
| | | |
| UDC | Entry Point | Invokes the compiler and: |
| | | |
--------------------------------------------------------------------------------------
| | | |
| COBOLIIX | ANSI85 | Creates an object file. |
| | | |
--------------------------------------------------------------------------------------
| | | |
| COBOLIIXPREP | | Links the object file and creates a program |
| | | file. |
| | | |
--------------------------------------------------------------------------------------
| | | |
| COBOLIIXGO | | Creates a program file in $OLDPASS and runs it. |
| | | |
--------------------------------------------------------------------------------------
Table 6-5. Compatibility Mode Commands
--------------------------------------------------------------------------------------
| | | |
| Command | Entry Point | Invokes the compiler and: |
| | | |
--------------------------------------------------------------------------------------
| | | |
| COBOLII | ANSI74 | Creates an object file. |
| | | |
--------------------------------------------------------------------------------------
| | | |
| COBOLIIPREP | | Links the object file and creates a program |
| | | file. |
| | | |
--------------------------------------------------------------------------------------
| | | |
| COBOLIIGO | | Creates a program file in $OLDPASS and runs it. |
| | | |
--------------------------------------------------------------------------------------
Syntax of UDCs.
COBOLIIX [textfile][,[uslfile[,[listfile][,[masterfile]
[,[newfile]]]]]][,info]
COBOLIIXPREP [textfile][,[progfile[,[listfile][,[masterfile]
[,[newfile]]]]]][,info]
COBOLIIXGO [textfile][,[listfile][,[masterfile] [,[newfile]]]][,info]
Syntax of Commands.
COBOLII [textfile][,[uslfile[,[listfile][,[masterfile] [,[newfile]]]]]]
[;INFO=info][;WKSP=workspacename]
COBOLIIPREP [textfile][,[progfile[,[listfile][,[masterfile]
[,[newfile]]]]]][;INFO=info][;WKSP=workspacename]
COBOLIIGO [textfile][,[listfile][,[masterfile][,[newfile]]]]
[;INFO=info][WKSP=workspacename]
Parameters.
textfile MPE or TSAM file containing your source program. This
file can be compiled. The formal designator is COBTEXT.
The default is $STDIN.
uslfile Relocatable object code file. This file can be linked.
The formal designator is COBUSL. The default is
$OLDPASS.
progfile Executable program file. This file can be executed.
The default is $NEWPASS.
listfile MPE file on which your source code will be listed. The
formal designator is COBLIST. The default is $STDLIST.
masterfile MPE or TSAM file to be merged with textfile to produce a
composite source program. The formal designator is
COBMAST. If masterfile is omitted, the entire source is
from textfile.
newfile MPE file into which the merged textfile and masterfile
is written. For details, refer to the HP COBOL II/XL
Reference Manual. The formal designator is COBNEW. The
default is that no new file is written.
info A string whose value is a command list of the form:
"$compiler_command[$compiler_command]..."
where no compiler_command contains the character $ (even
if it is within quotes). Refer to the HP COBOL II/XL
Reference Manual for more information on compiler
commands.
If the number of commands is long enough, you can use an
ampersand (&) to continue the info string. The length
limit for a compiler command is the same as the length
limit for a source program line.
In the listing file, the string "INFO=" appears where
the sequence numbers normally appear.
The info string is processed before any source,
including compiler commands in the source. Therefore,
you may not want to use the default settings of these
commands in the source file. You should only include
commands such as SUBPROGRAM, which are required for
proper compilation, in the source file. This allows you
to specify commands like NOLIST, MAP, BOUNDS, or
CROSSREF uniquely within the info string for each
compilation.
workspacename Work space in which HP TOOLSET/XL can manage versions of
the source program.
Libraries
Your program can use subprograms from relocatable libraries and
executable libraries. Relocatable and executable libraries differ in
content and in when they are referenced. The following table lists these
differences:
Table 6-6. Differences between Relocatable and Executable Libraries
---------------------------------------------------------------------
| | | |
| Library | Contents | Referenced At |
| | | |
---------------------------------------------------------------------
| | | |
| Relocatable (RL) | Relocatable object | Link time. |
| | modules. | |
| | | |
---------------------------------------------------------------------
| | | |
| Executable (XL) | Executable object | Run time. |
| | modules. | |
| | | |
---------------------------------------------------------------------
Relocatable Libraries.
A relocatable library contains relocatable object modules and is
referenced at link time.
Example.
The following shows how you can use the Link Editor to put the subprogram
SUB1 into the relocatable library RLLIB. Your input is underlined:
:LINKEDIT
LinkEd>RL RLLIB
LinkEd>ADDRL FROM=SUB1
LinkEd>EXIT
The following command links subprograms from RLLIB with the object file
of the main program, TMAIN, and creates the program file TMAINP:
:LINK TMAIN,TMAINP;RL=RLLIB
Executable Libraries.
An executable library contains executable object modules and is
referenced at run time.
The three ways to tell the operating system which executable library
contains the subprograms for your program are:
1. Specify the library in the LINK command.
The advantage of this method is that you need not remember to
specify the library in the RUN command each time you execute your
program. The only time you cannot use this method is when you
want to execute the program with different executable libraries at
different times.
The following command links subprograms from XLLIB.GROUP.ACCOUNT
with the object file of the main program, TMAIN, and creates the
program file TMAINP:
:LINK TMAIN,TMAINP;XL=XLLIB.GROUP.ACCOUNT
Either of the following commands runs the program:
:RUN TMAINP This uses the RUN command.
:TMAINP This uses the implied RUN command.
2. Specify the library in the RUN command.
The advantage of this method is that you can execute the program
with different executable libraries at different times.
The following command executes the program TMAIN, in the program
file TMAINP, with the executable library XLLIB.GROUP.ACCOUNT:
:RUN TMAINP;XL="XLLIB.GROUP.ACCOUNT"
3. Name the library XL. In the RUN command, specify LIB=G if the
library is in your group, LIB=P if the library is in your account,
or LIB=S if the library is NL.PUB.SYS or XL.PUB.SYS. LIB=S is the
default.
This is the least flexible method. It is similar to the method
used on the MPE V operating system.
Examples of Compiling, Linking, and Executing Programs
This section contains several examples of compiling, linking and
executing programs.
Example 1.
The first example compiles, links, and executes a program. Either the
program calls no subprograms, or the subprograms that it calls are in the
executable library NL.PUB.SYS or XL.PUB.SYS.
:COB85XL TPROG,,$NULL
:LINK
:RUN $OLDPASS
The first command above compiles the COBOL source program, TPROG, into
the default object file, $OLDPASS. $NULL specifies no listing.
The second command links the default object file, $OLDPASS, into the
default program file, $NEWPASS, which becomes $OLDPASS when it is closed.
The third command executes the program file, $OLDPASS.
The following single command is equivalent to the above sequence of three
commands:
:COB85XLG TPROG,$NULL
Example 2.
The second example compiles, links, and executes a main program and two
subprograms. The main program and each subprogram is in a separate
object file. The keyword RUN in the last command is optional.
:COB85XL TMAIN,TMAINO
:COB85XL SUB1,SUB1O
:COB85XL SUB2,SUB2O
:LINK FROM=TMAINO,SUB1O,SUB2O;TO=TMAINP
:RUN TMAINP
Example 3.
The third example compiles, links, and runs concatenated programs. The
first program is a main program. It uses an indirect file list of the
programs to be compiled. When programs are concatenated, the compiler is
invoked once for all of them, and the compiler output for these programs
is in a single object file, so the FROM list in the LINK command only
needs to specify one object file. The default $OLDPASS is used below.
The "indirect" file, COBSRC, contains:
$INCLUDE MAINSRC
END PROGRAM MAINSRC.
$INCLUDE SUB1SRC
END PROGRAM SUB1SRC.
$INCLUDE SUB2SRC
END PROGRAM SUB2SRC.
$INCLUDE SUB3SRC
The END PROGRAM header is not necessary for the last concatenated program
in a file. This is an easy way to migrate your current main and
subprograms to concatenated programs, and simplify your compiles and
links. The following commands compile and link the file COBSRC:
:COB85XL COBSRC
:LINK
:$OLDPASS
The defaults for the object file and program file are used above. The
RUN keyword is not necessary to run the program file, $OLDPASS.
MPE/iX 5.0 Documentation