ILERPG.com β€” IBM i Β· ILE RPG Β· AS400 Mastery
2 min readΒ· Admin

Choosing ILE RPG Data Types Is a Design Decision

Every DCL-S commits a field to a storage footprint, an arithmetic behavior, and a compatibility profile with everything downstream of it β€” the database, the calling program, the interface on the other end. Choosing well at declaration time prevents a whole category of problems later.

Text: CHAR or VARCHAR

CHAR(n) is fixed-length and blank-padded to its full size. It suits short, consistently sized values: codes, flags, fixed-width identifiers. VARCHAR(n) tracks its current length and suits longer text whose length varies meaningfully from record to record β€” descriptions, names, e-mail addresses. A two-character state code gains nothing from VARCHAR; an 80-character product description usually does.

Numbers: PACKED, ZONED, INT

PACKED stores two digits per byte and is the default choice for monetary amounts and business quantities. ZONED stores one digit per byte and remains correct when data originates in, or must match, an existing zoned layout. INT and UNS hold binary whole numbers and are the right choice for counters, array indexes, and API parameters, where native binary arithmetic matters.

dcl-s unitPrice   packed(9 : 2) inz(0);
dcl-s custNumber  zoned(6 : 0)  inz(0);
dcl-s loopCounter int(5)        inz(0);

Dates and times as real types

DATE, TIME, and TIMESTAMP replace six- and eight-digit numeric "dates" with values the compiler validates. They also unlock date arithmetic through built-in functions such as %DAYS and %DIFF, which handle month lengths and leap years correctly. To initialize one to the current value, use INZ(*SYS); built-in functions are called in calculations, not in the INZ keyword.

dcl-s orderDate  date inz(*sys);
dcl-s shipByDate date;

shipByDate = orderDate + %days(5);

Flags: IND

IND holds *ON or *OFF. It is the correct type for any two-state condition β€” approved, active, found β€” and it retires both numbered *INxx indicators and ad hoc 'Y'/'N' character fields in new code.

Reading a declaration

The lesson closes with an order-header data structure that mixes zoned identifiers, character text of two kinds, a packed total, an integer count, and indicator flags. Reading a structure like that and seeing immediately why each field carries its type is a skill used in every code review.

Get the lesson

Lesson 14, β€œData Types: Character, Numeric, Date, Time, and Indicator,” is part of Beginner ILE RPG in IBM i ILE RPG Mastery and is available at ILERPG.com for USD 10. The complete Beginner ILE RPG series β€” all 18 lessons β€” is USD 180, or USD 135 with coupon code RPG30, which takes 25% off when you purchase the full series.