100 likes | 275 Views
Calling programs. Fall 2012. Static vs Dynamic Calls. Calling Programs The program being called. Linkage Section Part of the Data Division, usually coded after the working-storage section. Defines the parameters being sent to the called program.
E N D
Calling programs Fall 2012
Calling ProgramsThe program being called • Linkage Section • Part of the Data Division, usually coded after the working-storage section. • Defines the parameters being sent to the called program. • Only needed if parameters being passed to the program
Calling ProgramsThe program being called • Procedure Division Statement • Using clause • Only needed if parameters are passed to calling program. • Example: Linkage Section. 01 PARM-Customer PIC X(10). Procedure Division using PARM-Customer.
Calling ProgramsProgram being called • Must end with EXIT PROGRAM instead of STOP RUN. • Because … STOP RUN terminates the entire application
Calling ProgramsThe program doing the calls Syntax: CALL LINKAGE TYPE IS PROCEDURE/PROGRAM ‘programname’ USING parameter list END-CALL. PROCEDURE is used if the object being called is a *MODULE. PROGRAM is used if the object being called is a *PGM. USING is used only if parameters are passed.
CALL Statement with Parameters Called Program Identification Division PROGRAM-ID. PGMB. Data Division. Linkage Section. 01 FLDX PIC X(2). 01 FLDY PIC 9(5). Procedure Division USING FLDX FLDY. Calling Program Data Division. 01 FLDA PIC X(2). 01 FLDB PIC 9(5). Procedure Division. CALL Linkage type is program PGMB USING FLDA FLDB.
CALL … BY CONTENT • Passes Parameters, but the values do not get returned to the calling program.
CALL … BY CONTENT Calling Program Called Programs Identification Division. PROGRAM-ID. SUBPGM1. Procedure Division using FLDX FLDY. COMPUTE FLDX = FLDY * 5. PROGRAM EXIT. Procedure Division. MOVE 4 to FLDA. MOVE 5 to FLDB. CALL Linkage Type is procedure ‘SUBPGM1’ USING FLDA FLDB CALL Linkage Type is program ‘SUBPGM2’ USING BY CONTENT FLDA FLDB DISPLAY FLDA. DISPLAY FLDB. Identification Division. PROGRAM-ID. SUBPGM2. Procedure Division using FLDX FLDY. COMPUTE FLDY = FLDX * 2. PROGRAM EXIT.
Combining Modules Example MODA *MODULE calls MODB *MODULE To create a program call MODCALL: CRTPGM MODCALL MODULES(MODA MODB)