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

Variables, Constants, and Named Indicators: Three Declarations, Three Jobs

DCL-S and DCL-C look almost identical on the page, and a named indicator is simply a variable with a two-state type. Each still does distinct work, and treating them as interchangeable is where fragile code begins.

Variables: give them the narrowest scope

A variable exists to change. Declared at the top of a module, outside any procedure, it is global and visible to every procedure. Declared inside a subprocedure, it is local, visible only there, and re-initialized on every call. The working rule is to default to local and reach for global only when several procedures genuinely share the same storage.

STATIC is the exception to re-initialization. A static local keeps its value between calls without becoming visible to the rest of the program β€” the right tool for a running count or a small cache, and the wrong tool as a substitute for a parameter or a return value.

dcl-proc evaluateClaim;
  dcl-pi *n char(1);
    claimAmount packed(9 : 2) const;
  end-pi;
  dcl-s claimsProcessed int(10) static inz(0);
  claimsProcessed += 1;
  // ...
end-proc;

Constants: one definition, referenced everywhere

A named constant holds a value fixed at compile time; any attempt to change it is a compile error. Status codes, business thresholds, and structural limits all belong here. if orderStatus = ORD_STATUS_OPEN; documents itself in a way if orderStatus = 'O'; never will, and when a threshold changes, it changes in one place.

Named indicators: meaning in the name

*IN35 = *ON; is functionally complete and conveys nothing. creditHoldActive = *on; explains itself. Named indicators are ordinary IND variables; the discipline lies in naming them so the *ON state reads as true in plain English and initializing each one explicitly.

Lesson 15 brings all three tools together in a claim-evaluation routine where every declaration does exactly one job, visible before a single executable line is read.

Get the lesson

Lesson 15, β€œVariables, Constants, and Named Indicators,” 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.