Wednesday, December 30, 2015

Passing Data from JCL to COBOL program

We pass data from JCL to cobol program in two ways:
1. Using the PARM keyword 
2. Using SYSIN DD in JCL
The basic difference between these two ways of passing are as follows:
A. Using 'PARM=' on the exec keyword, we can pass only 100 characters of data. Also in cobol we need linkage section to take the values in.
B. When we pass data through SYSIN, we need to have the accept keyword in COBOL. For each row in SYSIN, we need to have corresponding ACCEPT verb in cobol.

Sample cobol program accepting PARM value through linkage
...
......
LINKAGE SECTION.
01 LS-TEST-PARM.
    05 LS-TEST-LENGTH PIC S9(04) USAGE COMP.
    05 LS-VAR1 PIC 9(02).
    05 LS-VAR2 PIC 9(02).

PROCEDURE DIVISION USING LS-TEST-PARM.
DISPLAY LS-VAR1.
DISPLAY LS-VAR2.
DISPLAY LS-TEST-LENGTH.
STOP RUN.

Have a look into the corresponding JCL.
//TTYYTST  JOB(TEST),CLASS=I,MSGCLASS=X,MSGLEVEL=(1,1)
//                NOTIFY=&SYSUID
//*
//JSTEP01  EXEC PGM=SAMPLE3,PARM='1211212'
//STEPLIB  DD DSN=TEST.LOAD.LIB1,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSOUT   DD SYSOUT=*

RESULT:
12
11
007

Sample program accepting data from SYSIN .
...
....
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-TOTAL
    05  WS-VAR1  PIC X(02).
    05  WS-VAR2  PIC X(02).
PROCEDURE DIVISION.
INITIALIZE WS-TOTAL.
ACCEPT WS-VAR1.
ACCEPT WS-VAR2.
DISPLAY WS-VAR1.
DISPLAY WS-VA22 .

Corresponding JCL:
//TTYAATST  JOB(TEST),CLASS=I,MSGCLASS=X,MSGLEVEL=(1,1)
//                NOTIFY=&SYSUID
//*
//JSTEP01  EXEC PGM=SAMPLE1
//STEPLIB  DD DSN=TEST.LOAD.LIB1,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSOUT   DD SYSOUT=
//sysin dd*
12
31
/*
//*
Result:
12
31

If we do not have any data to be passed we can make SYSIN DD DUMMY. I tried passing blank values via SYSIN. Was Expecting an abend, but it did not. It displayed spaces in SYSOUT.