Previous Topic: Passing Control LaterallyNext Topic: Retrieving Task-Related Information


Passing Control, Expecting to Return

To transfer program control to a subordinate level, expecting return of control to the instruction immediately following the request, perform the following steps:

  1. Invoke the main program specified by the task code.
  2. Perform processing, as required.
  3. Transfer control to the second program by issuing a TRANSFER CONTROL LINK statement, optionally specifying a parameter list.
  4. Perform processing in the subordinate-level program, as required. DC returns control to the next-higher-level program when the subordinate program issues a DC RETURN statement.

Example of Passing Control to a Lower Level

The program excerpt below transfers control to DEPTCHEK, a subroutine that performs error-checking.

The GETPROG program performs processing based on the status returned by the DEPTCHEK program.

 DATA DIVISION.
 WORKING-STORAGE SECTION.
 01  DEPTCHEK                   PIC X(8) VALUE 'DEPTCHEK'.
 01  ERRCHEK-INFO.
     05 CHEK-DEPT-ID            PIC 9(4).
     05 CHEK-ERRSTAT            PIC X(4).
 PROCEDURE DIVISION.
     BIND MAP SOLICIT.
     BIND MAP SOLICIT RECORD SOLICIT-REC.
     MAP IN USING SOLICIT.
     MOVE SOLICIT-DEPT-ID TO CHEK-DEPT-ID.
     MOVE 'OK' TO CHEK-ERRSTAT.
*** TRANSFER CONTROL TO ERROR CHECKING PROGRAM ***
     TRANSFER CONTROL TO DEPTCHEK LINK USING
                           CHEK-DEPT-ID
                           CHEK-ERRSTAT.
     IF CHEK-ERRSTAT NOT = 'OK'
        GO TO ERR-DEPT-ID.
     COPY IDMS SUBSCHEMA-BINDS.
     READY.
     MOVE SOLICIT-DEPT-ID TO DEPT-ID-0410.
     OBTAIN DEPARTMENT CALC
        ON DB-REC-NOT-FOUND
        PERFORM ERR-NO-DEPT.
*** FURTHER DATABASE PROCESSING ***
______________________________________________________________________________

 PROGRAM-ID.                     DEPTCHEK.
 DATA DIVISION.
 LINKAGE SECTION.
 01  CH-DEPT-INFO.
     05 CH-ID                   PIC 9(4).
     05 CH-ERRSTAT              PIC X(4).
 PROCEDURE DIVISION USING CH-DEPT-INFO.
*** PERFORM ERROR AND RANGE CHECKING ***
     IF CH-ID NOT NUMERIC
        THEN MOVE 'NNUM' TO CH-ERRSTAT
     ELSE
       IF CH-ID > 8000 OR < 1000
          MOVE 'RANG' TO CH-ERRSTAT.
*** RETURN CONTROL TO CALLING PROGRAM ***
     DC RETURN.