Examples: static and dynamic CALL statements
This example shows how you can code static and dynamic calls.
The example has three parts:
- Code that uses a static call to call a subprogram
- Code that uses a dynamic call to call the same subprogram
- The subprogram that is called by the two types of calls
The following example shows how you would code static calls:
PROCESS NODYNAM NODLL
IDENTIFICATION DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RECORD-2 PIC X. (6)
01 RECORD-1. (2)
05 PAY PICTURE S9(5)V99.
05 HOURLY-RATE PICTURE S9V99.
05 HOURS PICTURE S99V9.
. . .
PROCEDURE DIVISION.
CALL "SUBPROG" USING RECORD-1. (1)
CALL "PAYMASTR" USING RECORD-1 RECORD-2. (5)
STOP RUN.
The following example shows how you would code dynamic calls:
DATA DIVISION.
WORKING-STORAGE SECTION.
77 PGM-NAME PICTURE X(8).
01 RECORD-2 PIC x. (6)
01 RECORD-1. (2)
05 PAY PICTURE S9(5)V99.
05 HOURLY-RATE PICTURE S9V99.
05 HOURS PICTURE S99V9.
. . .
PROCEDURE DIVISION.
. . .
MOVE "SUBPROG" TO PGM-NAME.
CALL PGM-NAME USING RECORD-1. (1)
CANCEL PGM-NAME.
MOVE "PAYMASTR" TO PGM-NAME. (4)
CALL PGM-NAME USING RECORD-1 RECORD-2. (5)
STOP RUN.
The following example shows a called subprogram that is called by each of the two preceding calling programs:
IDENTIFICATION DIVISION.
PROGRAM-ID. SUBPROG.
DATA DIVISION.
LINKAGE SECTION.
01 PAYREC. (2)
10 PAY PICTURE S9(5)V99.
10 HOURLY-RATE PICTURE S9V99.
10 HOURS PICTURE S99V9.
77 PAY-CODE PICTURE 9. (6)
PROCEDURE DIVISION USING PAYREC. (1)
. . .
EXIT PROGRAM. (3)
ENTRY "PAYMASTR" USING PAYREC PAY-CODE. (5)
. . .
GOBACK. (7)
- (1)
- Processing begins in the calling program. When the first
CALL
statement is executed, control is transferred to the first statement of thePROCEDURE DIVISION
inSUBPROG
, which is the called program.In each of the
CALL
statements, the operand of the firstUSING
option is identified asRECORD-1
. - (2)
- When
SUBPROG
receives control, the values withinRECORD-1
are made available toSUBPROG
; however, inSUBPROG
they are referred to asPAYREC
.The
PICTURE
character-strings withinPAYREC
andPAY-CODE
contain the same number of characters asRECORD-1
andRECORD-2
, although the descriptions are not identical. - (3)
- When processing within
SUBPROG
reaches theEXIT PROGRAM
statement, control is returned to the calling program. Processing continues in that program until the secondCALL
statement is executed. - (4)
- In the example of a dynamically called program, because the second
CALL
statement refers to another entry point withinSUBPROG
, aCANCEL
statement is executed before the secondCALL
statement. - (5)
- With the second
CALL
statement in the calling program, control is again transferred toSUBPROG
, but this time processing begins at the statement following theENTRY
statement inSUBPROG
. - (6)
- The values within
RECORD-1
are again made available toPAYREC
. In addition, the value inRECORD-2
is now made available toSUBPROG
through the correspondingUSING
operand,PAY-CODE
.When control is transferred the second time from the statically linked program,
SUBPROG
is made available in its last-used state (that is, if any values inSUBPROG
storage were changed during the first execution, those changed values are still in effect). When control is transferred from the dynamically linked program, however,SUBPROG
is made available in its initial state, because of theCANCEL
statement that has been executed. - (7)
- When processing reaches the
GOBACK
statement, control is returned to the calling program at the statement immediately after the secondCALL
statement.
In any given execution of the called program and
either of the two calling programs, if the values within RECORD-1
are
changed between the time of the first CALL
and the
second, the values passed at the time of the second CALL
statement
will be the changed, not the original, values. If you want to use
the original values, you must save them.