Example: dynamic call using CALL identifier
The
following example shows how you might make dynamic calls
that use CALL
identifier.
The
first program, dl1.cbl, uses CALL
identifier to
call the second program, dl1a.cbl.
dl1.cbl
* Simple dynamic call to dl1a
Identification Division.
Program-id. dl1.
*
Environment Division.
Configuration Section.
Input-Output Section.
File-control.
*
Data Division.
File Section.
Working-storage Section.
01 var pic x(10).
Linkage Section.
*
Procedure Division.
move "Dl1A" to var.
display "Calling " var.
call var.
move "dl1a " to var.
display "Calling " var.
call var.
stop run.
End program dl1.
dlla.cbl
* Called by dl1.cbl using CALL identifier.
IDENTIFICATION DIVISION.
PROGRAM-ID. dl1a.
*
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
OBJECT-COMPUTER. ANY-THING.
*
DATA DIVISION.
WORKING-STORAGE SECTION.
77 num pic 9(4) binary value is zero.
*
PROCEDURE DIVISION.
LA-START.
display "COBOL DL1A function." upon console.
add 11 to num.
display "num = " num
goback.
Procedure
To create and run the example above, do these steps:
- Enter
cob2 dl1.cbl -o dl1
to generate executable moduledl1
. - Enter
cob2 dl1a.cbl -dll -o DL1A
to generate executable moduleDL1A
.Unless you compile using the
PGMNAME(MIXED)
option, executable program-names are changed to uppercase.-dll
,-dso
, and-shared
are three equivalent options, and any one can be specified here. See -dll | -dso | -shared to learn more about these options. - Enter the command
export COBPATH=.
to cause the current directory to be searched for the targets of dynamic calls. - Enter
dl1
to run the program.
Because the CALL
identifier target
must match the name of the called program, the executable module in
the above example is generated as DL1A
, not as dl1a
.