COBOL Manual for TNS and TNS/R Programs
Program Compilation
HP COBOL Manual for TNS and TNS/R Programs—522555-006
11-5
Compilation Units
Appendix B, Data Type Correspondence, shows the correspondence between
HP COBOL data items and those of the other languages with which an HP COBOL
program can interact. HP COBOL index names are entirely internal to their own
program; they cannot be written, read, or passed as parameters. Index data items in
HP COBOL correspond to 32-bit integers.
In Example 11-2, a TNS HP COBOL program calls a FORTRAN program to get the
base-10 logarithm of a value.
Compilation Units
The source file that is input to the compiler is also called a compilation unit. A
compilation unit contains one or more “separately compiled programs.”A separately
compiled program is a program whose source text can be submitted to the compiler
independently of any other source text. Each such program can include nested
programs, and any program can call other separately compiled programs.
Submitting a sequence of separately compiled programs to the compiler as a
compilation unit (in a single compilation step) is called “stacked compilation.”
The end of each separately compiled program is ordinarily marked by an END
PROGRAM statement, although it can be marked with an ENDUNIT compiler directive
with equivalent effect. The last (or only) program in a compilation unit does not require
an END PROGRAM statement or an ENDUNIT directive. Separately compiled
programs in a compilation unit can be in any order.
Example 11-2. TNS HP COBOL Program Calling FORTRAN Program
COBOL main program fragment:
01 FTN-PARAMETERS.
* DOUBLEWORDS, SCALED UP BY 1000
03 LOGARG PICTURE S9(8) COMP.
03 LOGANS PICTURE S9(8) COMP.
01 UNSCALED PICTURE 9(5)v9(3).
...
MOVE 123.45 TO UNSCALED
MULTIPLY UNSCALED BY 1000 GIVING LOGARG
ENTER FORTRAN "LOGTEN" OF MATHS USING LOGARG
GIVING LOGANS
DIVIDE LOGANS BY 1000 GIVING UNSCALED
FORTRAN subprogram fragment:
INTEGER*4 FUNCTION LOGTEN ( IA )
INTEGER*4 IA
DOUBLE PRECISION DA
C SCALE BACK DOWN
DA = DBLE (IA) / 1000
C GET DOUBLE PRECISION LOG, RESCALE, CONVERT TO INT
LOGTEN = INT4 ( DLOG10 (DA) * 1000.D0 )
RETURN