Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 5: Data Division


LINKAGE SECTION

  • LINKAGE SECTION is used to define and declare program parameters i.e. variables whose values are passed by JCL or calling program
  • Through the data items defined in the LINKAGE SECTION, program will be able to process the data passed from JCL or from another program.
  • LINKAGE SECTION is coded in called (subroutine) program
  • LINKAGE SECTION is mostly used in sub programming which will be explained in Module 11
  • If LINKAGE SECTION is coded to receive PARM data from JCL, it should be coded with a half-word binary field ‘S9(4) COMP’ to store length prior to the actual fields. If the length field is not coded, the first two bytes of the field coded in the LINKAGE SECTION will be filled with length and the last two bytes of data will be truncated in the actual data.
  • Basic structure of LINKAGE SECTION is given below:-

    DATA DIVISION. LINKAGE SECTION. [linkage-section-entries…]

  • linkage-section-entries are the data items whose values sub program is going to receive. In addition to this, we also need to specify same in the PROCEDURE DIVISION USING clause to establish the addressability and access the data. Below example depicts use of LINKAGE SECTION, PROCEDURE DIVISION USING clause.
  • For example, you are designing a simple program ‘SUBPROG’ that will displays the sum of two values passed to it. Now, when SUBPROG is called either from JCL or from another program, two values will be passed to it. In SUBPROG these values needs to be received in order to process it, and therefore, in LINKAGE SECTION we can specify the data item declaration of the values that it will receive.
  • COBOL Sub-routine program to compute sum of values passed to it:-
    000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. SUBPROG. 000300 ENVIRONMENT DIVISION. 000400 DATA DIVISION. 000500 WORKING-STORAGE SECTION. 000600 01 OUTPUT-DATA PIC 9(4). 000700 LINKAGE SECTION. 000800 01 PARM-BUFFER. 000900 05 PARM-LENGTH PIC S9(4) COMP. 001000 05 PARM-INPUT1 PIC 9(2). 001100 05 PARM-INPUT2 PIC 9(2). 001200 PROCEDURE DIVISION USING PARM-BUFFER. 001300 MAIN-PARA. 001400 COMPUTE OUTPUT-DATA = PARM-INPUT1 + PARM-INPUT2. 001500 DISPLAY 'PARM-INPUT1: ' PARM-INPUT1. 001600 DISPLAY 'PARM-INPUT2: ' PARM-INPUT2. 001700 DISPLAY 'SUM VALUE : ' OUTPUT-DATA. 001800 GOBACK.
    Above sub routine program can be called from JCL or another COBOL Program.
    SUBPROG called from JCL:-
    //DEPTJOB JOB A123,’STEVE’ //STEP01 EXEC PGM=SUBPROG,PARM='0410' //SYSOUT DD SYSOUT=A //
    Output:-
    PARM-INPUT1: 04 PARM-INPUT2: 10 SUM VALUE : 0014
    SUBPROG called from another COBOL program ‘MAINPROG:-
    IMP Note:- When you compile the program that is calling another program, make sure to specify the load library of called program in SYSLIB DD of Link Edit step.
    000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. MAINPROG. 000300 ENVIRONMENT DIVISION. 000400 DATA DIVISION. 000500 WORKING-STORAGE SECTION. 000600 01 INPUTS. 000600 05 PRM-LENGTH PIC S9(4) COMP. 000600 05 INPUT1 PIC 9(2). 000700 05 INPUT2 PIC 9(2). 000800 PROCEDURE DIVISION. 000900 MAIN-PARA. 001000 MOVE 12 TO INPUT1. 001100 MOVE 13 TO INPUT2. 001200 CALL 'MFPROG1' USING PRM-LENGTH, INPUT1, INPUT2. 001300 STOP RUN.
    JCL used to execute MAINPROG:-
    //DEPTJOB JOB A123,’STEVE’ //STEP01 EXEC PGM=MAINPROG //SYSOUT DD SYSOUT=A //
    Output:-
    PARM-INPUT1: 12 PARM-INPUT2: 13 SUM VALUE : 0025






© copyright mainframebug.com
Privacy Policy