Вы находитесь на странице: 1из 2

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 tw o preceding calling programs: IDENTIFICATION DIVISION. PROGRAM-ID. SUBPROG. DATA DIVISION. LINKAGE SECTION. 01 PAYREC. 10 PAY PICTURE S9(5)V99. 10 HOURLY-RATE PICTURE S9V99. 10 HOURS PICTURE S99V9. 77 PAY-CODE PICTURE 9. PROCEDURE DIVISION USING PAYREC. . . . EXIT PROGRAM. ENTRY "PAYMASTR" USING PAYREC PAY-CODE.

(2)

(6) (1) (3) (5)

(7) (1) Processing begins in the calling program. When the first CALL statement is execu ted, control is transferred to the first statement of the PROCEDURE DIVISION in SUBPROG, which is the called program. In each of the CALL statements, the operand of the first USING option is identif ied as RECORD-1. (2) When SUBPROG receives control, the values within RECORD-1 are made available to SUBPROG; however, in SUBPROG they are referred to as PAYREC. The PICTURE character-strings within PAYREC and PAY-CODE contain the same number of characters as RECORD-1 and RECORD-2, although the descriptions are not ident ical. (3) When processing within SUBPROG reaches the EXIT PROGRAM statement, control is re turned to the calling program. Processing continues in that program until the se cond CALL statement is issued. (4) In the example of a dynamically called program, because the second CALL statemen t refers to another entry point within SUBPROG, a CANCEL statement is issued bef ore the second CALL statement. (5) With the second CALL statement in the calling program, control is again transfer red to SUBPROG, but this time processing begins at the statement following the E NTRY statement in SUBPROG. (6) The values within RECORD-1 are again made available to PAYREC. In addition, the value in RECORD-2 is now made available to SUBPROG through the corresponding USI NG 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 in SUBP ROG storage were changed during the first execution, those changed values are st ill in effect). When control is transferred from the dynamically linked program, however, SUBPROG is made available in its initial state, because of the CANCEL 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 second CALL statement. In any given execution of the called program and either of the two calling progr ams, if the values within RECORD-1 are changed between the time of the first CAL L and the second, the values passed at the time of the second CALL statement wil l be the changed, not the original, values. If you want to use the original valu es, you must save them. Terms of use Feedback

. . . GOBACK.

This information center is powered by Eclipse technology. (http://www.eclipse.or g) AGOPK1503D-ASHOK KUMAR PAN ---

Вам также может понравиться