Variables and PICTURE clauses

Level numbers

Every data item starts with a level number from 01 to 49. Level 01 is a record or group, and deeper numbers nest inside it. Level 77 declares a standalone item, and 88 declares a condition name.

01 WS-EMPLOYEE. 05 WS-FIRST-NAME PIC X(20). 05 WS-LAST-NAME PIC X(20). 05 WS-SALARY PIC 9(6)V99.

PICTURE clauses

PICTURE (or PIC) defines the shape of a field. X is an alphanumeric character, 9 is a digit, V is an implied decimal point, and S adds a sign:

01 WS-CODE PIC XX. 01 WS-COUNT PIC 9(4). 01 WS-RATE PIC S9(5)V99.

VALUE and INITIALIZE

VALUE sets a starting value at declaration time. INITIALIZE resets fields to their default values, spaces for X fields and zeros for 9 fields:

01 WS-COUNT PIC 9(4) VALUE 0. INITIALIZE WS-EMPLOYEE.

The code on this page was run with GnuCOBOL 3.2.0 on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev