Background

COBOL and CICS in 60 seconds

The minimum COBOL and CICS vocabulary to follow the explainers. One sentence per concept, with a short code fragment where it helps. The explainers describe cobble, a static-analysis tool that reads COBOL and CICS source without running it.

COBOL

Fields and storage

WORKING-STORAGE SECTION is where a program declares its variables. Each variable is called a field.

PICTURE clause (abbreviated PIC) says what a field holds and how wide it is.

       01  WS-NAME        PIC X(20).     20 characters of text
       01  WS-AMOUNT      PIC 9(7)V99.   9 digits; V marks an implied decimal
                                         point before the last 2 and takes
                                         no storage, so 9 bytes

VALUE clause gives a field its starting contents when the program begins: 01 WS-N PIC 9(2) VALUE 0. A field without one starts with whatever the storage held.

Group items. A field can contain sub-fields. The group occupies the concatenated bytes of its children — no extra padding, no hidden header.

       01  WS-DATE.
           05  WS-YEAR    PIC 9(4).
           05  WS-MONTH   PIC 9(2).
           05  WS-DAY     PIC 9(2).

Level numbers (01, 05, …) give the nesting: an 01 starts a new top-level item, and each higher number belongs to the nearest lower-numbered item above it.

Writing to WS-DATE writes all eight bytes. Writing to WS-MONTH writes only bytes [4, 6) — the explainers count bytes from 0 and write ranges half-open, so this is bytes 4 and 5, the fifth and sixth.

REDEFINES lets two field names describe the same physical bytes — like a C union.

       01  WS-STAMP       PIC X(8).
       01  WS-STAMP-NUM REDEFINES WS-STAMP  PIC 9(8).

Both names point at the same eight bytes. A write through one is visible through the other.

OCCURS declares a table: 05 WS-PGMS PIC X(8) OCCURS 10. is ten 8-byte elements, read as WS-PGMS(I). OCCURS DEPENDING ON makes the element count another field's runtime value, so the table's length — and the position of anything after it — is not known until the program runs.

Statements

MOVE copies data from one field to another — this is assignment.

           MOVE WS-A TO WS-B.

ADD is arithmetic in place: ADD 1 TO WS-N is WS-N = WS-N + 1.

IF / ELSE / END-IF is conditional branching, the same as in any language.

           IF WS-FLAG = 'Y'
               MOVE 1 TO WS-COUNT
           ELSE
               MOVE 0 TO WS-COUNT
           END-IF.

PERFORM calls a paragraph — think of it as a function call. PERFORM CALC-TOTAL runs the CALC-TOTAL paragraph and returns. PERFORM ... THRU runs a range of consecutive paragraphs.

           PERFORM CALC-TOTAL.
           PERFORM INIT-PARA THRU INIT-EXIT.

PERFORM … UNTIL is a loop: PERFORM LOOP-PARA UNTIL WS-N > 3 tests the condition before each run of the body (like while (!(WS-N > 3))), so the body may run zero times.

Fall-through. Paragraphs are just labels: when one ends without a jump, control runs on into the next paragraph in the source. A paragraph reached by PERFORM returns to its caller instead.

STOP RUN ends the program.

CALL runs another program. CALL 'PROGB' names it as a literal; CALL WS-PGM (a dynamic call) calls whatever name the field holds at that moment, which the source alone does not show.

CICS

CICS is IBM's transaction server. Programs don't run as standalone executables; they run as online transactions on the server.

Communication area (commarea) is a shared byte buffer passed between programs. Think of it as a flat byte array. Different programs may map the same bytes to different field names using different copybook layouts.

EXEC CICS LINK calls another program, passing the commarea. The caller waits and resumes when the called program finishes — like a subroutine call.

           EXEC CICS LINK
               PROGRAM('PROGA')
               COMMAREA(WS-COMM)
               LENGTH(WS-COMM-LEN)
           END-EXEC.

EXEC CICS XCTL transfers control to another program. The caller does not resume — like a tail call or a goto to a different program.

EXEC CICS RETURN ends the current program. Optionally starts a new transaction by specifying a TRANSID.

CSD (CICS System Definition) is configuration that maps four-character transaction codes to programs. When a user types a transaction code, the CSD tells CICS which program to start.