JCL, CICS and Db2
Most COBOL in the world runs on a machine this container is not. The numbers in the job, the transaction and the database of a bank are on z/OS, started by JCL, entered through CICS and stored in Db2 or VSAM, and none of those three is available here. A course that taught them by pretending would teach a fiction, so this lesson does the opposite: it says what each one is, shows the code a COBOL programmer writes for it, and marks every part that was not run here.
What a mainframe is
z/OS is an operating system for IBM mainframes, and a mainframe is a machine built for throughput and for running many jobs at once against one large store of data. COBOL arrived there in 1964 and never left: the batch report that closes the day, the transaction that moves money between accounts and the extract that feeds the reporting system are still, in most large organisations, COBOL programs.
Four names come up with it. JCL is the job control language: the file of statements that says which program to run, which files it gets and what to do with its status. CICS is the transaction monitor: it starts a program for one request and holds the screen and the state between requests. Db2 is the relational database, and VSAM is the older indexed file system whose records a COBOL program reads and writes directly. The COBOL language is the same language this course teaches; the four names are the machinery around it.
A JCL step
A JCL job is a stack of steps, and each step runs one program. The statements below are the shape of it, not a listing from a real machine:
//NIGHTJOB JOB (ACCT),'NIGHT BATCH',CLASS=A,MSGCLASS=X
//STEP1 EXEC PGM=TAXCALC,PARM='RECORDS=500'
//STEPLIB DD DSN=PROD.LOADLIB,DISP=SHR
//SYSIN DD DSN=PROD.TXN.INPUT,DISP=SHR
//SYSOUT DD SYSOUT=*
//STEP2 EXEC PGM=REPORT,COND=(4,LT)
//INFILE DD DSN=PROD.TXN.OUTPUT,DISP=SHR
EXEC PGM= names the program, PARM= passes the string the program reads with ACCEPT FROM COMMAND-LINE or a LINKAGE parameter, and each DD names a file that the program\'s SELECT ... ASSIGN TO will use. COND=(4,LT) on the second step means "skip this step if an earlier step ended with a status less than 4", which is the scheduler\'s version of the rule that a batch chain stops on failure.
A COBOL program does not see JCL. It sees a program name, a parameter string and a set of files, which is exactly what a command line and a folder of files give it on any other system. That is why the language survived the move: the same program runs under JCL on z/OS and under a shell script on Linux, with the surroundings changed and the source kept.
The part of a step that runs here
The parameter, the record count and the status can be reproduced without z/OS, and the program below is the piece of a step worth understanding first. It takes a count, warns when the count is larger than a hundred and returns the status a scheduler would branch on:
IDENTIFICATION DIVISION.
PROGRAM-ID. STEP.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-COUNT PIC 9(3).
01 WS-PARM PIC X(10).
01 WS-RECORDS PIC 9(5) VALUE 0.
PROCEDURE DIVISION.
ACCEPT WS-COUNT FROM ARGUMENT-NUMBER
IF WS-COUNT NOT = 1
DISPLAY "PARM RECORDS missing" UPON STDERR
MOVE 8 TO RETURN-CODE
STOP RUN
END-IF.
ACCEPT WS-PARM FROM ARGUMENT-VALUE
IF FUNCTION TEST-NUMVAL(WS-PARM) NOT = 0
DISPLAY "PARM RECORDS is not a number: " FUNCTION TRIM(WS-PARM) UPON STDERR
MOVE 8 TO RETURN-CODE
STOP RUN
END-IF.
MOVE FUNCTION NUMVAL(WS-PARM) TO WS-RECORDS
IF WS-RECORDS IS GREATER THAN 100
DISPLAY "step warning: " WS-RECORDS " records selected"
MOVE 4 TO RETURN-CODE
ELSE
DISPLAY "step ok: " WS-RECORDS " records selected"
END-IF.
STOP RUN.
Three runs, with a count, with a large count and with no parameter at all:
cobc -x -free -Wall -o step step.cob
./step 50
echo $?
./step 500
echo $?
./step
echo $?
step ok: 00050 records selected
0
step warning: 00500 records selected
4
PARM RECORDS missing
8
COND=(4,LT) is a shell test with the same two numbers in it. A step whose status is 4 lets the next one run, because four is a warning; a step whose status is 8 stops the chain:
./step 50; if [ $? -le 4 ]; then echo "next step runs"; fi
./step; if [ $? -le 4 ]; then echo "next step runs"; else echo "next step skipped"; fi
step ok: 00050 records selected
next step runs
PARM RECORDS missing
next step skipped
That is the whole of the scheduler concept, and it is the reason the last two lessons spent their time on RETURN-CODE and on statuses that mean different things. The JCL around it names the program and the files; the rule above the program decides what runs next.
CICS
A CICS transaction is one request from one screen or terminal. The monitor starts the program, the program reads the screen, does its work, sends an answer and returns, and the state that has to survive until the next request travels in a COMMAREA: a byte area whose layout both the program and the monitor know. This fragment is the part a COBOL programmer writes:
PROCEDURE DIVISION.
EXEC CICS RECEIVE MAP('ACCTMAP') MAPSET('ACCTSET')
INTO(ACCT-SCREEN) END-EXEC
MOVE ACCT-NUMBER OF ACCT-SCREEN TO WS-ACCOUNT
PERFORM READ-ACCOUNT
IF WS-STATUS = "00"
MOVE ACCT-BALANCE TO BALANCE-OUT OF ACCT-SCREEN
ELSE
MOVE "ACCOUNT NOT FOUND" TO MESSAGE-OUT OF ACCT-SCREEN
END-IF
EXEC CICS SEND MAP('ACCTMAP') MAPSET('ACCTSET')
FROM(ACCT-SCREEN) ERASE END-EXEC
EXEC CICS RETURN TRANSID('ACCT')
COMMAREA(WS-COMMAREA) END-EXEC.
EXEC CICS ... END-EXEC is not COBOL: it is a language of its own that a translator turns into COBOL calls before the compiler sees the source. GnuCOBOL 3.2 has no CICS translator, this container has no CICS region, and so the fragment above is the only form in which it appears in this course: it is not compiled and not run here. The COBOL around it, the MOVE, the PERFORM and the IF, is the same code as in every other lesson.
Db2
Db2 statements sit in COBOL source in an EXEC SQL block, with host variables written as COBOL names with a colon:
EXEC SQL
SELECT ACCT_NO, BALANCE, STATUS
INTO :WS-ACCOUNT, :WS-BALANCE, :WS-STATUS
FROM ACCOUNTS
WHERE ACCT_NO = :WS-KEY
END-EXEC
An EXEC SQL block is not compiled by cobc either. A precompiler reads the source, turns each block into calls to the database runtime, and hands the result to the COBOL compiler; the SQLCODE that the statement leaves behind is then a special register the program tests like any other status. This image has no Db2 client, no precompiler and no server, so the block above is shown and not run.
The patterns the precompiler output follows are the ones this course teaches: a status checked after every statement, a message for the user, a cursor for a multi-row read, and a transaction boundary the program decides. A programmer who knows FILE STATUS and the status table already knows how the database half of the program will look.
What is not run here
One table, so the boundary of this course is written down instead of implied:
concept runs in this container what the course does
COBOL source yes, cobc 3.2.0 builds and runs every lesson
batch status yes, a shell and $? lessons 120 to 122
indexed files yes, GnuCOBOL indexed lessons 075 to 078
JCL no shown in this lesson, not run
CICS no, no translator shown in this lesson, not run
Db2 no, no client shown in this lesson, not run
EBCDIC data partly, ASCII is native lesson 043
The install pages of this course and the mainframe page carry the longer version of the same story. What matters for a reader is that the language is one language: a program that reads an indexed file, checks a status and returns a code is the same program on z/OS and here, and the difference is the JCL, the monitor and the database around it.
Exercises
- Write the JCL for a job of three steps where the second may warn and the third must not run after an error. Which COND value does each step carry?
- Change STEP to return 0 for a count of exactly 100 and 4 for anything above it. Which line of the shell test changes?
- Explain in one sentence why a CICS program needs a COMMAREA and a batch program does not.
- Name the two statuses a Db2 program checks after a SELECT, and say what each one means.
Questions
A new set of questions in a new order every time. Choose one answer for each, then check.
-
What does JCL do?
Answer
It names the program, its files and its parameter, and decides what runs next
EXEC PGM, DD and COND are the three parts the lesson shows.
-
What does COND=(4,LT) on a step mean?
Answer
Skip the step when an earlier step ended with a status less than 4
The shell test if [ $? -le 4 ] shows the same rule.
-
What is a COMMAREA in CICS?
Answer
A byte area that carries state between two transactions
The pseudo-conversational program passes it on RETURN TRANSID.
-
Why is the EXEC CICS fragment not compiled here?
Answer
EXEC CICS is translated by a CICS translator, and this image has none
GnuCOBOL 3.2 has no CICS translator and there is no CICS region here.
-
What does this program print?
IDENTIFICATION DIVISION. PROGRAM-ID. Q5. DATA DIVISION. WORKING-STORAGE SECTION. 01 N PIC 9(2) VALUE 0. PROCEDURE DIVISION. IF N = 0 DISPLAY "zero" ELSE DISPLAY "other" END-IF. STOP RUN.Answer
zero
N was initialized to zero.
-
What does this program print?
IDENTIFICATION DIVISION. PROGRAM-ID. Q6. DATA DIVISION. WORKING-STORAGE SECTION. 01 W PIC X(5) VALUE "ABCDE". PROCEDURE DIVISION. DISPLAY W(1:1) W(5:1). STOP RUN.Answer
AE
The first character is A and the fifth is E.
-
What does this program print?
IDENTIFICATION DIVISION. PROGRAM-ID. Q7. DATA DIVISION. WORKING-STORAGE SECTION. 01 A PIC 9(3) VALUE 100. 01 B PIC 9(2) VALUE 5. 01 C PIC 9(3). PROCEDURE DIVISION. COMPUTE C = A / B DISPLAY C. STOP RUN.Answer
020
A hundred divided by five is twenty, printed with three digits.
-
What does this program print?
IDENTIFICATION DIVISION. PROGRAM-ID. Q8. DATA DIVISION. WORKING-STORAGE SECTION. 01 T. 05 T-N PIC 9(2) OCCURS 3 TIMES. 01 I PIC 9(2). PROCEDURE DIVISION. PERFORM VARYING I FROM 1 BY 1 UNTIL I IS GREATER THAN 3 MOVE I TO T-N(I) END-PERFORM. DISPLAY T-N(2). STOP RUN.Answer
02
The second entry was set to the second value of the loop.
-
Which part of a mainframe job has a direct equivalent in this course?
Answer
The step status and the branch on it
RETURN-CODE and a shell test reproduce COND.
-
Why does this lesson show no invented output for JCL, CICS or Db2?
Answer
None of the three runs here, and output that was never produced would be a lie
The lesson marks every part that was not run.
The COBOL on this page was built with cobc (GnuCOBOL) 3.2.0 and run on Alpine Linux 3.24.3 (x86_64) in a Docker container. The JCL, CICS and Db2 listings were not run: no z/OS, no CICS translator and no Db2 client exist in this image.
Article author: Arthur Isaev