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
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
| Lvl | Field | PIC | Usage | Start | End | Length | Offset | Occurs |
|---|---|---|---|---|---|---|---|---|
| 01 | CUSTOMER-RECORD | 1 | 109 | 109 | 0 | |||
| 05 | CUST-IDZoned decimal | 9(8) | DISPLAY | 1 | 8 | 8 | 0 | |
| 05 | CUST-NAME | 9 | 44 | 36 | 8 | |||
| 10 | CUST-LAST-NAMECharacter | X(20) | DISPLAY | 9 | 28 | 20 | 8 | |
| 10 | CUST-FIRST-NAMECharacter | X(15) | DISPLAY | 29 | 43 | 15 | 28 | |
| 10 | CUST-MIDDLE-INITCharacter | X | DISPLAY | 44 | 44 | 1 | 43 | |
| 05 | CUST-STATUSCharacter88 CUST-ACTIVE: 'A'88 CUST-CLOSED: 'C' | X | DISPLAY | 45 | 45 | 1 | 44 | |
| 05 | CUST-OPEN-DATEZoned decimal | 9(8) | DISPLAY | 46 | 53 | 8 | 45 | |
| 05 | CUST-OPEN-DATE-RRedefines CUST-OPEN-DATE. | 46 | 53 | 8 | 45 | |||
| 10 | CUST-OPEN-YYYYZoned decimal | 9(4) | DISPLAY | 46 | 49 | 4 | 45 | |
| 10 | CUST-OPEN-MMZoned decimal | 99 | DISPLAY | 50 | 51 | 2 | 49 | |
| 10 | CUST-OPEN-DDZoned decimal | 99 | DISPLAY | 52 | 53 | 2 | 51 | |
| 05 | CUST-BALANCEPacked decimal | S9(9)V99 | COMP-3 | 54 | 59 | 6 | 53 | |
| 05 | CUST-CREDIT-LIMITBinary | S9(7) | COMP | 60 | 63 | 4 | 59 | |
| 05 | CUST-PHONE-TABLE | 64 | 99 | 36 | 63 | |||
| 10 | CUST-PHONECharacter | X(12) | DISPLAY | 64 | 99 | 12 | 63 | 3 |
| 05 | FILLERCharacter | X(10) | DISPLAY | 100 | 109 | 10 | 99 |
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.
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.
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.
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.
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.