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
CALLstatement is executed, control is transferred to the first statement of thePROCEDURE DIVISIONinSUBPROG, which is the called program.In each of the
CALLstatements, the operand of the firstUSINGoption is identified asRECORD-1. - (2)
- When
SUBPROGreceives control, the values withinRECORD-1are made available toSUBPROG; however, inSUBPROGthey are referred to asPAYREC.The
PICTUREcharacter-strings withinPAYRECandPAY-CODEcontain the same number of characters asRECORD-1andRECORD-2, although the descriptions are not identical. - (3)
- When processing within
SUBPROGreaches theEXIT PROGRAMstatement, control is returned to the calling program. Processing continues in that program until the secondCALLstatement is executed. - (4)
- In the example of a dynamically called program, because the second
CALLstatement refers to another entry point withinSUBPROG, aCANCELstatement is executed before the secondCALLstatement. - (5)
- With the second
CALLstatement in the calling program, control is again transferred toSUBPROG, but this time processing begins at the statement following theENTRYstatement inSUBPROG. - (6)
- The values within
RECORD-1are again made available toPAYREC. In addition, the value inRECORD-2is now made available toSUBPROGthrough the correspondingUSINGoperand,PAY-CODE.When control is transferred the second time from the statically linked program,
SUBPROGis made available in its last-used state (that is, if any values inSUBPROGstorage were changed during the first execution, those changed values are still in effect). When control is transferred from the dynamically linked program, however,SUBPROGis made available in its initial state, because of theCANCELstatement that has been executed. - (7)
- When processing reaches the
GOBACKstatement, control is returned to the calling program at the statement immediately after the secondCALLstatement.
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.