Skip to content

Data Structures

Daniel Long edited this page Sep 29, 2026 · 2 revisions

Data Structures

Basic Data Structure

DCL-DS employee QUALIFIED;
  id INT(10);
  name VARCHAR(50);
  salary PACKED(9:2);
END-DS;

employee.id = 1;
employee.name = 'Alice';
employee.salary = 75000.00;
DSPLY employee.name;

Array of Data Structures

DCL-DS item QUALIFIED DIM(10);
  code CHAR(5);
  description VARCHAR(50);
  price PACKED(7:2);
END-DS;

item(1).code = 'A001';
item(1).description = 'Widget';
item(1).price = 9.99;

LIKEDS

DCL-DS address QUALIFIED;
  street VARCHAR(100);
  city VARCHAR(50);
  state CHAR(2);
END-DS;

DCL-DS shipping LIKEDS(address);
shipping.city = 'Springfield';

Initial Values: INZ

As on IBM i, a data structure without INZ starts as blanks, not zeros. A character subfield is blank, an integer subfield reads as what blank bytes decode to (INT(10) is 1077952576, INT(5) 16448), and a packed or zoned subfield holds no decimal data at all: using it before assigning it is a decimal data error (status 907).

DCL-DS totals QUALIFIED INZ;      // every subfield starts at its type's default
  count INT(10);
  amount PACKED(9:2);
  label CHAR(10) INZ('TOTAL');    // a subfield INZ sets that subfield alone
END-DS;

DCL-DS work QUALIFIED;            // no INZ: blanks until assigned
  qty PACKED(5:0) INZ(1);         // ...except this subfield
  price PACKED(7:2);
END-DS;

LIKEDS copies the layout, not the initialization: DCL-DS a LIKEDS(b) starts blank, INZ gives it type defaults, and INZ(*LIKEDS) initializes it as b is. CLEAR sets every subfield to its type's default; RESET restores the state the data structure was declared with.

Clone this wiki locally