CICS Sample Program Explains How to use Link Command

Two sample programs given below. Those are main program and sub-program.

Link Command

  1. Main program with Link command to call sub-program
  2. Logic in Sub-program
  3. How to add logic for function keys
  4. Add a program to MAP in CICS
  5. The logic for MAP definition

1# Main Program

 ID DIVISION.
PROGRAM-ID. HAS.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 TID PIC X(4).
77 MSG PIC X(50) VALUE 'IMPORTANT OF LINK PROGRAM'.
77 A PIC X(35) VALUE 'THIS IS MAIN PROGRAM'.
77 B PIC X(35) VALUE 'NOW CONTROL MOVE TO SUB'.
77 C PIC X(40) VALUE 'THANK U BYE'.
PROCEDURE DIVISION.
EXEC CICS RECEIVE INTO (TID)
LENGTH(LENGTH OF TID)
END-EXEC.
EXEC CICS SEND
FROM(MSG)
END-EXEC.
EXEC CICS RECEIVE END-EXEC.
EXEC CICS SEND
FROM(A)
ERASE
END-EXEC.
EXEC CICS RECEIVE END-EXEC.
EXEC CICS SEND FROM(B) END-EXEC.
EXEC CICS RECEIVE END-EXEC.
EXEC CICS LINK
PROGRAM('SUB')
END-EXEC.
EXEC CICS SEND FROM(C) ERASE END-EXEC.
EXEC CICS RECEIVE END-EXEC.
EXEC CICS RETURN END-EXEC.

The logic for Sub program when you use LINK in main program.

2# Sub Program for LINK

 ID DIVISION.
PROGRAM-ID. SEN.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 D PIC X(35) VALUE 'THIS IS SUB PROGRAM'.
77 E PIC X(50) VALUE 'NOW CONTROL TO MAIN'.
PROCEDURE DIVISION.
EXEC CICS SEND FROM(D) END-EXEC.
EXEC CICS RECEIVE END-EXEC.
EXEC CICS SEND FROM(E) END-EXEC.
EXEC CICS RECEIVE END-EXEC.
EXEC CICS RETURN END-EXEC.

3# CICS Function Key(EIBAID)

 ID DIVISION.
PROGRAM-ID. AD12GM.
DATA DIVISION.
WORKING-STORAGE SECTION.
COPY ADD001.
01 RES.
02 A PIC 9(3).
02 B PIC 9(3).
02 C PIC 9(4).
77 Z PIC X(80).
PROCEDURE DIVISION.
MOVE LOW-VALUES TO ADD1I.
MOVE LOW-VALUES TO ADD1O.
EXEC CICS
SEND MAP('ADD1') MAPSET('ADD001')
END-EXEC.
MAIN-PARA.
EXEC CICS HANDLE AID
PF1(ADD-PARA)
PF2(SUB-PARA)
ANYKEY(E-PARA)
END-EXEC.
EXEC CICS
RECEIVE MAP('ADD1') MAPSET('ADD001')
END-EXEC.
ADD-PARA.
MOVE NO1I TO A.
MOVE NO2I TO B.
COMPUTE C = A + B.
MOVE C TO RESO.
MOVE 'ADD SUCCESSFUL' TO MSGO.
EXEC CICS
SEND MAP('ADD1') MAPSET('ADD001')
ERASE
END-EXEC.
EXEC CICS RETURN END-EXEC.
SUB-PARA.
MOVE NO1I TO A.
MOVE NO2I TO B.
COMPUTE C = A - B.
MOVE C TO RESO.
MOVE 'SUB SUCCESSFUL' TO MSGO.
EXEC CICS
SEND MAP('ADD1') MAPSET('ADD001')
ERASE
END-EXEC.
EXEC CICS RETURN END-EXEC.
E-PARA.
MOVE 'PRESS F1 AND F2' TO MSGO.
EXEC CICS SEND
SEND MAP('ADD1') MAPSET('ADD001')
ERASE
END-EXEC.
go to main-para.

How to write a piece of code to add logic for function keys in CICS.

4# ADD Program in CICS-COBOL

 PROGRAM-ID. AD12GM.
DATA DIVISION.
WORKING-STORAGE SECTION.
COPY ADD001.
01 RES.
02 A PIC 9(3).
02 B PIC 9(3).
02 C PIC 9(4).
77 Z PIC X(80).
PROCEDURE DIVISION.
MOVE LOW-VALUES TO ADD1I.
MOVE LOW-VALUES TO ADD1O.
EXEC CICS
SEND MAP('ADD1') MAPSET('ADD001')
END-EXEC.
EXEC CICS
RECEIVE MAP('ADD1') MAPSET('ADD001')
END-EXEC.
MOVE NO1I TO A.
MOVE NO2I TO B.
COMPUTE C = A + B.
MOVE C TO RESO.
EXEC CICS
SEND MAP('ADD1') MAPSET('ADD001')
ERASE
END-EXEC.
EXEC CICS RETURN END-EXEC.

5# Map for Addition

 DFHMSD TYPE=&SYSPARM,                                         X
 MODE=INOUT,                                                   X
 TIOAPFX=YES,                                                  X
 STORAGE=AUTO,                                                 X
 LANG=COBOL,                                                   X
 CTRL=FREEKB
 ADD01   DFHMDI SIZE=(24,80),LINE=1,COLUMN=1
 DFHMDF INITIAL='ADD    PGM',POS=(1,38),LENGTH=10,ATTRB=PROT
 DFHMDF INITIAL='ENTER NO1:',POS=(05,11),LENGTH=10,ATTRB=PROT
 NO1        DFHMDF POS=(05,22),LENGTH=3,ATTRB=(UNPROT,IC),PICIN='999',         X
 INITIAL=''
 DFHMDF POS=(05,26),LENGTH=1,ATTRB=ASKIP
 DFHMDF INITIAL='ENTER NO2:',POS=(06,11),LENGTH=10,
ATTRB=ASKIP
 NO2       
DFHMDF POS=(06,22),LENGTH=03,ATTRB=UNPROT,PICIN='999',              X
 INITIAL=''
 DFHMDF INITIAL='RESULT  :',POS=(08,11),                        X
 LENGTH=09,ATTRB=PROT
 RES       DFHMDF POS=(08,22),ATTRB=UNPROT,                                    X
 LENGTH=04,PICOUT='9999',                                       X
 INITIAL='____'

Also, read

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.