Lesson 7 · Autumn 2026 RPG Enhancements
Let RPG Count Your Array Elements with DIM(*INZ)
Use DIM(*INZ) to size an RPG array from its initial values. Add a fourth order status without maintaining a separate element count.
When an array’s initial values already define its contents, maintaining a separate element count creates another edit to remember. DIM(*INZ) lets the initializer supply that count.
Announcement preview
This lesson uses syntax announced for IBM i 7.6 TR3 and 7.5 TR9. Compiler prerequisites remain to be confirmed as of October 28, 2026. The example has not been compiled or run on IBM i; the output shown is expected.
One change to the previous example
The INZ(*LIST) lesson used:
dcl-s statuses char(1) dim(3)
inz(*list : 'N' : 'P' : 'S');
Replace DIM(3) with DIM(*INZ):
dcl-s statuses char(1) dim(*inz)
inz(*list : 'N' : 'P' : 'S');
IBM states that DIM(*INZ) takes the dimension from the number of items in the initializer list or enumeration. This example uses a list; enumeration initialization is a separate lesson. IBM array enhancement details.
Add a fourth status
The sample business rule now includes C for cancelled:
dcl-s statuses char(1) dim(*inz)
inz(*list : 'N' : 'P' : 'S' : 'C');
That is the only declaration edit. The loop below already uses %ELEM(statuses), so the example contains no second numeric count to maintain.
Complete example
**free
ctl-opt dftactgrp(*no) actgrp(*new);
dcl-s statuses char(1) dim(*inz)
inz(*list : 'N' : 'P' : 'S' : 'C');
dcl-s idx int(10);
dcl-s message char(52);
message = 'Elements: ' + %trim(%char(%elem(statuses)));
dsply message;
for idx = 1 to %elem(statuses);
message = 'Status ' + %trim(%char(idx))
+ ': ' + statuses(idx);
dsply message;
endfor;
*inlr = *on;
return;
Expected message text:
Elements: 4
Status 1: N
Status 2: P
Status 3: S
Status 4: C
Download DIMINZ.rpgle and the compile and validation instructions.
Once the required compiler support is installed, copy the source to the indicated IFS path and run these CL commands in the same job:
CRTBNDRPG PGM(QTEMP/DIMINZ) SRCSTMF('/tmp/eraofi/DIMINZ.rpgle') DBGVIEW(*SOURCE)
CALL PGM(QTEMP/DIMINZ)
A useful validation exercise
Remove 'C', recompile, and run again. Expect Elements: 3 followed by three status messages. Put 'C' back and repeat. This checks both the inferred dimension and the loop bound using the same small fixture.
The inference happens from the source initializer when compiling. This declaration does not provide a business-maintained list or a runtime collection that grows as orders arrive. If the values need to change independently of the program, keep them in a suitable data source.
For an externally defined interface with a fixed array capacity, retain the dimension required by that interface. This lesson’s array is private to the sample program.
Before using it in an application
Check the compiler and target-release prerequisites in RPG Cafe when IBM publishes the autumn details. Do not infer compiler support from the Db2 group level alone. Record the successful compile command and PTF levels with your test output.
Read the TR3/TR9 overview or return to INZ(*LIST).
References
Documentation and references used for this lesson.

Comments
Share your thoughts, questions, or real-world IBM i experiences related to this article.