C H A P T E R  5

Compiling COBOL and PL/I Programs and Assembling Maps

You can use the Development System Compilation Menu to compile COBOL and PL/I programs and to assemble BMS maps.

This chapter contains the following topics:


Compilation Menu Functions

On the Development System Compilation Menu, you can select files to edit or compile or set Copylib directories. FIGURE 5-1 shows the functions available from the Compilation Menu.

  FIGURE 5-1 Compilation Menu Map

Diagram showing the actions performed when you make a selection on the Compilation Menu.


Displaying the Compilation Menu

The Compilation menu shown in FIGURE 5-2 is similar to the standard file selection screen in Sun MTP.


procedure icon  To Display the Compilation Menu

single-step bulletPress PF4 on the Development System main menu.

  FIGURE 5-2 Compilation Menu

Screen shot showing the Compilation Menu.

The two display criteria fields at the top of the screen are:

Directory

Complete path name of the directory containing the programs to be compiled. The first element can be an environment variable.

Extensions

Specify up to eight file extensions. The extensions indicate the file type:

.clt: Adheres to IBM OS/VS COBOL compiler standards; assumed to be CICS programs.

.cl2: Adheres to IBM COBOL2 compiler standards; assumed to be CICS programs.

.cbl: Batch programs.

.bms: BMS maps. This file is assembled.

.pl1: Adheres to Liant Open PL/I standards.

.pli: Adheres to Liant Open PL/I standards.

.plt: Adheres to Liant Open PL/I standards; assumed to contain EXEC CICS statements.

.ppl: Adheres to Liant Open PL/I standards; assumed to be database programs.


Descriptions of the file information fields are located in TABLE 2-2.


procedure icon  To Select Files

1. Move the cursor to the selection field to the left of the file name and type an uppercase or lowercase S beside the file name.

2. Press the function key for the action you want to perform.

The following table describes the function keys on the Compilation Menu.

TABLE 5-1 Compilation Menu Function Keys

Function Key

Action

PF2

Executes the kixed shell script, which opens the selected file, by default, in the vi editor. If you select multiple files, the last file selected is edited first and the first file selected is edited last. The kixed script is invoked automatically for each file.

PF3

Closes the Compilation Menu and returns to the Development System main menu.

PF4

Refreshes the data in the file list portion of the screen. After you modify a file's attributes, press PF4 to update the screen.

PF5

Displays the Copylib Settings screen. See COBOL Copylib Settings.

PF6

Displays an options screen, depending on the file selected:

.clt, .cbl or .cl2 files: Displays the Set Compiler Options screen for COBOL. See Compiling COBOL Programs.

pl2, .pl1, .pli or .ppl files: Displays the Set Compiler Options screen for PL/I. See Compiling Online PL/I Programs.

.bms files: Displays the Set Assembler Options Screen. See Assembling BMS Maps.

PF7

Displays the previous page of files. If the top of the file list is displayed, this message is displayed:

Beginning of data reached

PF8

Displays the next page of files. If the bottom of the file list is displayed, this message is displayed:

End of data reached

PF9

Redisplays the contents of the directory, sorted by file name.

PF10

Redisplays the contents of the directory, sorted in descending sequence by the file modification date.

PF11

Redisplays the contents of the directory, sorted in descending sequence by the file size.

Enter

No action takes place unless a file is selected. If a file is selected, either the Compiler or the Assembler screen is displayed, depending on the file extension.

If a directory is selected, the directory changes to the selected directory and the files in that directory are displayed.



COBOL Copylib Settings

The Copylib Settings screen enables you to set a maximum of eight directories that are searched for copybooks referenced in the COBOL source code. Directories are searched in the following order:

1. Current directory

2. Directories defined on the Copylib Settings screen

3. Directories defined by the COBCPY environment variable

Refer to the COBOL documentation for information about the COBCPY environment variable.


procedure icon  To Display the Copylib Settings Screen

single-step bulletPress PF5 on the Compilation menu.

The screen (FIGURE 5-3) contains eight fields to enter directories that contain the copybooks. The first element in the directory name can be an environment variable, designated with a dollar sign ($). The environment variable can be followed by other subdirectories separated by slashes (/).

  FIGURE 5-3 Copylib Settings Screen

Screen shot showing the Copylib Settings screen.[ D ]

The Copylib settings, as well as other user-specific options, are maintained in the file $KIXSYS/user-name.tbl, where user-name is the user's login name. The options are saved from session to session.


Compiling COBOL Programs

You can set COBOL compiler options and compile your programs either from the Compilation Menu or from the command line.

To compile batch programs using the command line interface, see Chapter 15.

Using the Compilation Menu

The Set Compiler Options screen for COBOL enables you to customize the actions of the compiler.


procedure icon  To Display the Set Compiler Options Screen

1. Select a COBOL program file on the Compilation menu (FIGURE 5-2).

2. Press PF6 to display the Set Compiler Options screen.

  FIGURE 5-4 Set Compiler Options Screen for COBOL

Screen shot of the Set Compiler Options Screen after selecting a COBOL program.[ D ]

COBOL Compiler Options

Modify the screen values if you need to.

Output filename

Name of the currently selected file displays as the default. You can change the file name. A file name can be up to 14 characters.

Output environment

Defaults to the directory name on the Compilation menu screen. You can change this value. The first element in this field can be an environment variable, which can be followed by other subdirectories separated by slashes.


Some compiler options and directives are set automatically based on the extension of the selected file. You set others by modifying the default values on the screen.

The following options and directives for online programs are set based on the file extension:

.clt: -v ibmcomp perform-type=osvs defaultbyte=0 cics

.cl2: -v ibmcomp perform-type=osvs defaultbyte=0

The following options and directives for batch programs are set based on the file extension:

.cbl: -v ibmcomp perform-type=osvs defaultbyte=32

where:

-v

Sets the verbose option, which displays information about the compile.

ibmcomp

Allocates data in sizes that are compatible with the mainframe.

perform-type=osvs

The compiler treats PERFORM statements similar to those used by mainframes.

defaultbyte

Controls how storage is initialized. This storage is declared in a COBOL program and does not have a value statement associated with it. For online programs, this directive is set to zero to ensure that storage is set to low values. For batch programs, this option is set to 32 to ensure that storage is set to spaces.

cics

For OS/VS COBOL programs, allows the use of BLL cells.




Note - Do not try to compile translated online programs with .cbl extensions.



The options and directives on the Set Compiler Options screen for COBOL are listed in the following table with the corresponding COBOL directive. Refer to your COBOL documentation for more information about using COBOL directives.

TABLE 5-2 COBOL Compiler Options

Screen Option

COBOL Directive/Option

Listing

[NO]LIST

Bounds

[NO]BOUND

Alter

[NO]ALTER

Animator

-a

Output

-i (intermediate code) /-u (native code)

Xref

[NO]XREF

Optimize

[NO]CICSOPT

ANSI 85

[NO]ANS85

Err List

[NO]ERRLIST

Trunc

[NO]TRUNC

VS COBOL2

[NO]VSC2


The options and directives you set on the Set Compiler Options screen, as well as other user-specific directives, are saved in a file called $KIXSYS/user-name.tbl, where user-name is the user's login name. These directives are saved from session to session.

You can set other directives in the $COBDIR/cobopt file. You can also change the default COBOL directives by modifying the $UNIKIX/bin/kixcob shell script.


procedure icon  To Compile the Program

single-step bulletPress PF4 on the Set Compiler Options screen to execute the kixcob shell script, which calls the COBOL compiler.

If .clt or .cl2 programs are selected, they are translated and compiled. If .cbl programs are selected, they are compiled, but not translated. If multiple files were selected, the files are compiled in reverse order; the last file selected is compiled first.

When compiling is complete, the editor displays the results of the compile and translation in the default editor (vi).

Using the Command-Line Interface

Before you can compile an online program using the command-line interface, you must process it using the kixclt translator. After the program is translated successfully, you can compile it. When compiling programs, you usually use a set of directives on a regular basis. These directives vary according to the type of COBOL (OS/VS, COBOL2) programs being compiled. Some of these directives are required by Sun MTP to ensure that the programs compile properly. Refer to your COBOL documentation for a description of the compiler options and directives.

Translating Programs

kixclt is the Sun MTP Common Language Translator. It locates and includes all copy files before translating CICS COBOL statements to COBOL statements. Therefore, you must set the COBCPY environment variable before running kixclt. $COBCPY points to the location of your COBOL copybooks, mapset copybooks (if any), and to the Sun MTP copybook directory. For example:

export COBCPY=path-name/copy:path-name/maps:$UNIKIX/copy

To translate an OS/VS COBOL program named myprog.clt and produce an output file named myprog.cbl, type the following command:

$ kixclt myprog.clt

If errors occur during translation, you must correct the program and translate it again.

Refer to the Sun Mainframe Transaction Processing Software Reference Guide for a description of kixclt and its options.

Compiler Directives

Use the following directives to compile online COBOL2 programs. Refer to the COBOL documentation for other compiler options you might require.

Use the following directives to compile online OS/VS COBOL programs. Refer to the COBOL documentation for other compiler options you might require.

Using Scripts and Makefiles to Compile

You can type directives on the command line or you can specify the name of a file containing a list of directives.

Example: The following command to compile a COBOL2 program contains all its directives and four options (-iaPV) on the command line.

$ cob -C 'arithmetic"osvs"' -C 'defaultbyte"0"' -C ibmcomp -C nocics -C notrunc 	-C vsc2 -iaPV myprog.cbl

Example: The following command to compile an OS/VS COBOL program contains its directives in a file named cobopts, and four options (-iaPV) on the command line.

$ cob -C "directives=/path-name/cobopts" -iaPV myprog.cbl

You can also create shell scripts to compile a single program or all the programs in one directory.

The following example illustrates a script for compiling one program. The COBOPT environment variable must be set to the appropriate directives file.

CODE EXAMPLE 5-1 Script to Compile One Online COBOL Program
for source
	do
	echo ---$source
	cob  -iaPV $source
	if [ $? -ne 0 ]
	then
		echo "Error in compilation of: " $source
		exit
	fi
done

CODE EXAMPLE 5-2 illustrates a script that translates and compiles all online programs in a directory. The script also captures log files indicating an error or successful completion. Programs are compiled only after successful translation.

CODE EXAMPLE 5-2 Script to Compile All Online COBOL Programs in a Directory
for i in `ls *.cl2`
do
    echo about to kixclt `basename $i .cl2`.cl2
    echo about to kixclt `basename $i .cl2`.cl2 >> COMPALL.err
    echo about to kixclt `basename $i .cl2`.cl2 >> COMPALL.log
    kixclt options `basename $i .cl2`.cl2
  ReturnCode=$?
  if [ $ReturnCode -ne 0 ]
    then
        echo "Error detected during kixclt of `basename $i .cl2`" >> COMPALL.err
  else
    echo about to compile `basename $i .cl2`.cbl
    echo about to compile `basename $i .cl2`.cbl >> COMPALL.err
    cob options and directives `basename $i .cl2`.cbl
    ReturnCode=$?
    if [ $ReturnCode -ne 0 ]
      then
          echo "Error detected during cob of `basename $i .cbl`" >> COMPALL.err
    else
        echo "Compile completed for `basename $i .cl2`" >> COMPALL.err
        rm `basename $i .cl2`.cbl
    fi
  fi
done

The $UNIKIX/test/primer/cobol directory contains a shell script build_ACCT.sh, which builds the sample accounting application. You can use it as a model to build your own scripts.

As an alternative to using script files, you can use a makefile to compile COBOL programs. The advantage of using a makefile is that it can selectively compile only those programs whose source has changed.



Note - Before using a makefile, you must understand the concepts of the make function.



The following code example illustrates a makefile that translates and compiles COBOL programs whose source code has changed since the last time the makefile was executed.

CODE EXAMPLE 5-3 makefile to Compile COBOL Programs (1 of 3)
# ***********************************************
# CICS Application Programming Primer
# Enter into Catalog:
# dataset     reclen    keylen   type
# ACCTFIL     383       5        KSDS
# ACCTIX	      63        17       KSDS
# ***********************************************
 
# ***********************************************
# rules
# ***********************************************
 
.SUFFIXES: .clt .cbl .int .gnt .bms .map 
 
.clt.cbl:
	rm -f $*.cbl
	( kixclt $*.clt )
 
.cbl.int:
	rm -f $*.int $*.idy
	cob -ia $(COBFLAGS) $<
 
.cbl.gnt:
	rm -f $*.gnt
	cob -u $(COBFLAGS) $<
 
.bms.map:
	rm -f $*.map $*.err $*.lst
	kixbms  -a $<
 
# ***********************************************
# variables to rules
# ***********************************************
 
# Cobflags for CLT modules
COBFLAGS=-C "ibmcomp cics noalter osvs defaultbyte=0"
 
# Cobflags for CL2 modules
COBFLAGS1=-C "ibmcomp noalter osvs defaultbyte=0"
 
# ***********************************************
# standard variables
# ***********************************************
 
# ***********************************************
# standard targets
# ***********************************************
 
all:        $(INTTARGETS)
 
INTTARGETS: ACCT00.int ACCT01.int ACCT02.int ACCT03.int \ 
            ACCT04.int
 
GNTTARGETS: ACCT00.gnt ACCT01.gnt ACCT02.gnt ACCT03.gnt \
            ACCT04.gnt
 
clean:
	rm -f *.gnt
	rm -f *.int
	rm -f *.idy
 
# ***********************************************
# Targets with dependencies
# ***********************************************
ACCT00.int:   ACCT00.clt     ACCT00.cbl
 
ACCT01.int:   ACCT01.clt     ACCT01.cbl
 
ACCT02.int:   ACCT02.clt     ACCT02.cbl
 
ACCT03.int:   ACCT03.clt     ACCT03.cbl
 
ACCT04.int:   ACCT04.clt     ACCT04.cbl
 
ACCT00.gnt:   ACCT00.clt     ACCT00.cbl
 
ACCT01.gnt:   ACCT01.clt     ACCT01.cbl
 
ACCT02.gnt:   ACCT02.clt     ACCT02.cbl
 
ACCT03.gnt:   ACCT03.clt     ACCT03.cbl
 
ACCT04.gnt:   ACCT04.clt     ACCT04.cbl

Compiling COBOL Programs to .gnt for Production Systems

You must compile your COBOL programs for execution in .gnt mode for a production system. The .gnt files are native code and execute faster than .int code.

In a test environment, if you want to use Micro Focus Animator, refer to the Micro Focus documentation for the appropriate options.


Compiling Online PL/I Programs

The Set Compiler Options screen for PL/I shown in FIGURE 5-5 enables you to customize the actions of the Open PL/I compiler.


procedure icon  To Display the Set PL/I Compiler Options Screen

1. Select a PL/I program file on the Compilation menu (FIGURE 5-2).

2. Press PF6.

  FIGURE 5-5 Set Compiler Options Screen for PL/I

Screen shot showing the Set Compiler Options Screen after selecting a PL/I program.[ D ]

Output filename

Name of the currently selected file displays as the default. You can change the file name; up to 14 characters.

Output environment

Defaults to the directory name entered on the Compilation menu. The environment can be any directory. You can use an environment variable as the first element in the output environment field, followed by other subdirectories separated by slashes.


PL/I Compiler Options

The following compiler options are set automatically based on the extension of the selected file.

.pli, .pl1

Open PL/I commands only.

.plt

Open PL/I with EXEC CICS commands.

.ppl

Open PL/I with EXEC CICS commands and database (Oracle) commands.




Note - Do not mix Liant Open PL/I filename extensions with COBOL filename extensions in a single set of selections. If you do, the error message Illegal file extension for compile is displayed.



Other options are set by modifying the default values on the screen. The options on the Set Compiler Options screen for PL/I are listed in the following table with the corresponding Liant Open PL/I options. Refer to the Open PL/I User's Guide for more information.

TABLE 5-3 PL/I Compiler Options

Screen Option

Open PL/I Option

nodebuginfo

Used for debugging with CodeWatch

Expnded List

Produces expanded listing

Alloc Map

Produces storage allocation map in listing

PIC

Position-Independent-Code

Unaligned

Unaligned PL/I structures at level 1

Optimize 2

Level of optimization

Debug (CW)

Specifies to use CodeWatch

CICS dbg CW

Allows CodeWatch to debug EXEC CICS precompiler-generated code


These options plus other user-specific options are maintained in a file called $KIXSYS/user-name.tbl, where user-name is the user's login name. The options are saved from session to session.


procedure icon  To Compile the Program

single-step bulletPress PF4 on the Set Compiler Options screen.

This executes the kixpl1 shell script, which calls the Liant Open PL/I compiler, the Oracle pre-compiler (.ppl extension), or the preprocessing translator, depending on the filename extension of the source file. If multiple files are selected, the files are compiled in reverse order; the last file selected is compiled first.

When the compilation completes, the results of the compile and translation are displayed in the default editor (vi).


Assembling BMS Maps

You can set BMS Assembler options and assemble your BMS maps either from the Compilation Menu or from the command line.

Using the Compilation Menu

The Set Assembler Options screen enables you to customize the BMS assembler's actions.


procedure icon  To Display the Set Assembler Options Screen

1. Select a file with a .bms extension on the Compilation menu (FIGURE 5-2).

2. Press PF6.

  FIGURE 5-6 Set Assembler Options Screen

Screen shot showing the Set Assembler Options Screen after selecting a .bms file.[ D ]

Edit the following values on the screen:

Output filename

Name of the currently selected file displays by default. You can change the filename; up to 14 characters.

Output Environment

Defaults to the directory name on the Compilation menu. The environment can be any directory in which any element can be an environment variable designated with a leading dollar sign. The environment variable can be preceded or followed by other subdirectories delimited with slashes.

Generate Language copy member

Create a COBOL copybook, PL/I include file, or C header file. The type of copy member created depends on the value of LANG in the .bms file.

Y: Create the copy member

N: Do not create the copy member

Generate List file output

Create a list file showing the results of the assembly.

Y: Creates a temporary file in the vi editor and displays it on your screen.

  • To save the file, type :wq filename
  • The file is saved to the directory specified in Output Environment, unless you specify a different directory when saving the file.

N: Do not create a listing file.



procedure icon  To Assemble the Map

single-step bulletPress PF4 on the Set Assembler Options screen.

This executes the kixasm shell script, which calls the BMS assembler, kixbms. If multiple files are selected, the files are assembled in reverse order; the last file selected is assembled first.

After each file is assembled, the default editor (vi) displays the results of the assembly.

Using the Command Line-Interface to Assemble Maps

Use the kixbms command to assemble BMS maps. You can specify one or more files with .bms extensions to assemble; kixbms creates map files with .map extensions.

Example: Type the following command at the command prompt to assemble a BMS map named mymap.bms and produce a copy member for inclusion in the programs. The output is a file named mymap.map.

$ kixbms -c mymap.bms

See Chapter 9 for more information about managing maps and refer to the Sun Mainframe Transaction Processing Software Reference Guide for a description of all the kixbms options.