MainframeMaster

COBOL copybook viewer

Paste a COBOL copybook to list every field with its start position, end position, length, PICTURE, and USAGE. The viewer also reports the record length (the LRECL for a fixed-length file) and handles REDEFINES, OCCURS, OCCURS DEPENDING ON, and SYNCHRONIZED alignment.

How to use it

  1. Paste the copybook into the box, or load one of the samples.
  2. Read the table. Start and End give the byte positions, and Length gives the size of each field.
  3. Copy the table as CSV, or search for a field by name or PIC.

Runs in your browser. Nothing is uploaded.

COBOL copybook viewer

CUSTOMER-RECORD length (bytes)

109

Elementary items

13

Group items

4

REDEFINES and OCCURS

1 and 1

Redefining items and tables

LvlFieldPICUsageStartEndLengthOffsetOccurs
01
CUSTOMER-RECORD
11091090
05
CUST-IDZoned decimal
9(8)DISPLAY1880
05
CUST-NAME
944368
10
CUST-LAST-NAMECharacter
X(20)DISPLAY928208
10
CUST-FIRST-NAMECharacter
X(15)DISPLAY29431528
10
CUST-MIDDLE-INITCharacter
XDISPLAY4444143
05
CUST-STATUSCharacter88 CUST-ACTIVE: 'A'88 CUST-CLOSED: 'C'
XDISPLAY4545144
05
CUST-OPEN-DATEZoned decimal
9(8)DISPLAY4653845
05
CUST-OPEN-DATE-RRedefines CUST-OPEN-DATE.
4653845
10
CUST-OPEN-YYYYZoned decimal
9(4)DISPLAY4649445
10
CUST-OPEN-MMZoned decimal
99DISPLAY5051249
10
CUST-OPEN-DDZoned decimal
99DISPLAY5253251
05
CUST-BALANCEPacked decimal
S9(9)V99COMP-35459653
05
CUST-CREDIT-LIMITBinary
S9(7)COMP6063459
05
CUST-PHONE-TABLE
64993663
10
CUST-PHONECharacter
X(12)DISPLAY649912633
05
FILLERCharacter
X(10)DISPLAY1001091099

Start and End are 1-based byte positions, the way a record layout is usually written. Offset is the 0-based displacement. Length is the size of one entry, and End runs to the last byte of the last occurrence. Fields inside an OCCURS table show the positions of the first occurrence.

Need this at work?

Free account saves tutorial progress. The jobs board lists openings that ask for JCL.

COBOL jobs on the board

Reading the layout

In the customer sample, CUST-BALANCE is PIC S9(9)V99 COMP-3. It has 11 digits, so it takes ceil((11 + 1) / 2) = 6 bytes and occupies positions 54 to 59. CUST-CREDIT-LIMIT follows at positions 60 to 63, because S9(7) COMP has 7 digits and falls in the 4-byte band. The record is 109 bytes long. CUST-OPEN-DATE-R redefines CUST-OPEN-DATE, so it shares positions 46 to 53 and adds nothing to the total.

The SYNCHRONIZED sample shows slack bytes. COMP-PAY is a 4-byte binary item that must start on a 4-byte boundary, so the compiler adds 2 bytes before it. Each occurrence of COMP-TABLE is then padded from 14 to 16 bytes so the next occurrence stays aligned. The record is 161 bytes long, against 121 without SYNCHRONIZED.

Supported syntax

  • Level numbers 01 to 49, 66, 77, and 88, in fixed or free format, with continuation lines and *> comments.
  • PICTURE clauses with 9, X, A, S, V, P, N, and G, edited pictures (Z, *, $, comma, period, B, 0, /, +, -, CR, DB), and floating-point pictures with E. Repetition counts such as X(80) are expanded.
  • USAGE DISPLAY, DISPLAY-1, NATIONAL, BINARY, COMP, COMP-1 through COMP-5, PACKED-DECIMAL, INDEX, POINTER, POINTER-32, FUNCTION-POINTER, PROCEDURE-POINTER, and OBJECT REFERENCE. A USAGE on a group applies to the items under it.
  • OCCURS with a fixed count, OCCURS n TO m DEPENDING ON, and nested tables.
  • REDEFINES, SYNCHRONIZED, SIGN IS SEPARATE, and RENAMES.

What the viewer does not do

The viewer reads the text of the copybook only. It does not expand COPY or REPLACE, apply compiler options such as NSYMBOL or ARITH, or evaluate VALUE, JUSTIFIED, or BLANK WHEN ZERO, none of which change a field's length. It does not decode data. EXEC SQL INCLUDE members are reported and left out of the layout, and TYPE and TYPEDEF clauses are reported and not applied. For a table with OCCURS DEPENDING ON, the SYNCHRONIZED alignment of items after the table is not recalculated for smaller counts. Compare the result with the compiler storage map before you rely on it for a file layout or a data conversion.

Explain it like I'm 5

A copybook is a plan for a long row of boxes. Each box holds a set number of letters or digits, and the plan lists the boxes in order. The viewer counts along the row and tells you where each box starts, where it ends, and how wide it is. Some boxes pack their digits tightly, so a number that looks seven digits wide can fit in four bytes.

FAQ

Related Pages

Sources

The storage rules follow the IBM Enterprise COBOL for z/OS documentation: slack bytes within records, the SYNCHRONIZED clause, character-string and item size, and formats for numeric data. For the PICTURE and USAGE rules behind a single field, see the PIC storage calculator. Other calculators and checkers are on /tools.