Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 38 ยท Modern COBOL and Mainframes

The Mainframe Environment

Understand where most COBOL runs - IBM z/OS, TSO and ISPF, datasets and record formats, EBCDIC, packed decimal COMP-3 storage, batch versus online work, and how a COBOL program becomes a job.

Most of the world's production COBOL runs on mainframes, in particular IBM Z systems with the z/OS operating system. Banks, insurers, airlines and governments use them for work where an hour of downtime costs a fortune and a wrong digit costs more. If you want a COBOL job, you will meet this environment, and even if you only use GnuCOBOL on a laptop, knowing how the mainframe thinks explains many odd corners of the language: why records have fixed lengths, why numbers can be "packed", why the sort order of letters is unusual.

This lesson is a guided tour. The next lesson, JCL for COBOL jobs, shows how to actually run a program.

The big picture

flowchart LR
    U["Developer<br/>TSO / ISPF or VS Code"] --> S["Source<br/>PDS member"]
    S --> C["Compile<br/>Enterprise COBOL"]
    C --> L["Link-edit<br/>load module"]
    L --> R["Run<br/>batch job or CICS"]
    R --> D[("Datasets<br/>VSAM, sequential, DB2")]

Source code becomes a load module in a library; a job or a transaction runs it against datasets and databases.

Two worlds coexist on z/OS:

  • Batch: jobs started by a scheduler or a person, running without a user at a terminal. Reads files, updates masters, prints reports. Typical for nightly processing.
  • Online: transactions entered at terminals or from web services, answered in a fraction of a second, managed by CICS or IMS (CICS basics).

Talking to the system: TSO and ISPF

Developers traditionally log on to TSO (Time Sharing Option) and work with ISPF, a menu-driven full-screen editor and file manager. You browse datasets, edit source in a text editor with line commands (I to insert, D to delete, C and M to copy and move), submit jobs with the SUB command, and read the results in SDSF (System Display and Search Facility). Today many teams use VS Code with IBM's Z Open Editor extension and Zowe, an open-source CLI and API for z/OS, but the underlying objects are the same.

Datasets, not files

On z/OS a file is a dataset with a dotted, upper-case name of up to 44 characters, for example PROD.PAYROLL.MASTER. Each dot-separated part is a qualifier of up to 8 characters. The first qualifier is usually the owner or the system. The main kinds:

Kind What it is COBOL view
Sequential (PS) One stream of records ORGANIZATION IS SEQUENTIAL
Partitioned (PDS, PDSE) A "folder" of members, used for source, copybooks, load modules COPY libraries, program libraries
VSAM KSDS, ESDS, RRDS, LDS Indexed, sequential, relative (indexed files)
GDG Generation Data Group: versions .G0001V00, .G0002V00, relative names (0) and (-1) Dataset chosen in the JCL
Temporary &&TEMP, deleted at job end Passing data between steps

Record formats appear in the dataset description and must match the program's FD:

  • RECFM=FB: fixed length records, blocked. LRECL=80 means every record has 80 bytes; BLKSIZE (for example 27920) is the physical block size, usually chosen by the system.
  • RECFM=VB: variable length, blocked. Each record has a 4-byte length prefix, so LRECL is the maximum record length plus 4 (variable records).
  • RECFM=FBA or VBA: has an ANSI carriage-control character in column 1, used for printed output.

EBCDIC

Mainframes use EBCDIC, an 8-bit character code from the 1960s, not ASCII. Letters are stored in two non-contiguous runs (A to I, J to R, S to Z) and the sort order is different: lowercase letters sort before uppercase and both sort before digits. This is why the same SORT on a mainframe and on a PC can order mixed data differently (sorting). When files move between systems the transfer program converts text fields; binary and packed fields must not be converted, which is a classic source of garbage. The Python block later converts a name with code page 037, one of the common EBCDIC variants.

How numbers are stored: USAGE

The USAGE clause chooses the internal format of a numeric item, and on the mainframe it matters for both space and speed:

Usage Storage Example PIC S9(5) takes
DISPLAY (default) One character per digit; sign overpunched in the last digit 5 bytes
COMP-3 / PACKED-DECIMAL Two digits per byte, sign in the last nibble 3 bytes
COMP / BINARY Binary integer, 2, 4 or 8 bytes depending on digits 4 bytes
COMP-1, COMP-2 Single and double floating point 4 / 8 bytes

Packed decimal is the mainframe's money format: exact decimal arithmetic, compact, and supported directly by hardware instructions. A value of +12345 in PIC S9(5) COMP-3 is the three bytes 12 34 5C; C marks positive and D negative (F for unsigned). This also explains a common abend: S0C7, the "data exception", happens when a packed or zoned field contains bytes that are not valid digits, for example uninitialized storage or a field overwritten by a text move.

Python Stand-in: EBCDIC (code page 037) bytes versus ASCII

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The output shows the ASCII bytes 48 65 ... against EBCDIC c8 85 ... (H is c8, e is 85), and that a is 81, A is c1, 1 is f1: in EBCDIC a < A < 1, in ASCII 1 < A < a.

Python Stand-in: COMP-3 packed decimal encoding and decoding

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You see 12345 stored as 12 34 5c in three bytes, -12345 as 12 34 5d, and the nine-digit amount fitting in five bytes (12 34 56 78 9c).

On z/OS the compiler (IBM Enterprise COBOL, currently version 6.x) reads source, copybooks and compiler options and produces an object module. The binder (link-editor) combines it with subprograms and runtime routines into a load module stored in a program library. A job then names that library and the program to run. Options you will see: LIST, MAP, XREF (listings), SSRANGE (subscript checking, tables), OPT(1) or OPT(2) (optimization), ARITH(EXTEND) (31-digit arithmetic), TEST (debugging information).

Return codes and abends

A step ends either with a return code (RETURN-CODE, 0 to 4095; 0 clean, 4 warning, 8 error, 12 severe) or with an abend (abnormal end). Abends have codes you will quickly recognize:

  • S0C7: data exception (bad packed or zoned data).
  • S0C4: protection exception (bad address, often a table subscript far out of range or a bad CALL).
  • S806: load module not found, often a missing library in the JCL.
  • S013: open error, such as a mismatch between the record format in the program and the dataset.
  • U4038, U1000...: user abend codes from the language runtime or your own program.

The program's file status codes and RETURN-CODE convention are what turn these into readable messages.

Why it lasts

Mainframe COBOL systems survive because they are reliable, fast at high volume, and hold decades of business rules. Billions of lines still run daily. The work today is as much about maintaining and modernizing them (APIs, JSON, cloud connections, testing, modern practices) as writing new batch jobs.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does RECFM=FB, LRECL=80 describe?

    FB means fixed blocked, and LRECL is the logical record length.
  2. 2. How many bytes does PIC S9(5) COMP-3 occupy?

    Five digits plus a sign nibble make six nibbles, which is three bytes.
  3. 3. What usually causes an S0C7 abend?

    S0C7 is a data exception: the arithmetic hardware found a nibble that is not a valid digit or sign.
  4. 4. In EBCDIC, how does the letter 'a' compare with 'A'?

    EBCDIC puts lowercase before uppercase (a is 81, A is C1), the opposite of ASCII.

Summary

  • Most production COBOL runs on z/OS in batch jobs and online transactions.
  • Data lives in datasets with record formats (FB, VB) that must match the program.
  • EBCDIC and packed decimal (COMP-3) are mainframe norms; invalid numeric data causes S0C7.
  • Source is compiled, link-edited into a load module and run by JCL or CICS; return codes and abend codes report the outcome.

Next: JCL for COBOL jobs