Return to the RPG Tips
Remapping Externally Described Fields to Arrays
http://systeminetwork.com/node/60402 The following RPG IV example illustrates the technique. The code is missing from the iSeries Network website so I am including it here. General ledger master file GlMst includes fields GlBal01 to GlBal12 to store the balances for each month of the year, shown below: *----------------------------------------------------------- * GlMst - General Ledger Master *----------------------------------------------------------- A UNIQUE A R GLMSTR TEXT( 'GL Master' ) A GLACT 7P 0 TEXT( 'Account' ) A GLBAL01 9P 2 TEXT( 'Balance 1' ) A GLBAL02 9P 2 TEXT( 'Balance 2' ) . . . A GLBAL11 9P 2 TEXT( 'Balance 11' ) A GLBAL12 9P 2 TEXT( 'Balance 12' ) A K GLACT The snippet of code below remaps the GlBal fields as the elements of array GlBalAry: FGlMst IP E Disk D GlBalDs Ds D GlBal01 D GlBal02 . . . D GlBal11 D GlBal12 D GlBalAry S Like( GlBal01 ) Dim( 12 ) D Based( GlBalPtr ) D GlBalPtr S * Inz( %Addr( GlBalDs ) ) The GlBal fields are redefined as subfields in the data structure GlBalDs, and array GlBalAry is defined with 12 elements like GlBal01. The array is based on the pointer GlBalPtr, which the code initializes to the address of data structure GlBalDs. As a result, the array overlays the memory address of the data structure: GlBalAry(1) overlays GlBal01, GlBalAry(2) overlays GlBal02, and so on. In your program's C-specs, you can reference the GlBal fields using the subfields in data structure GlBalDs or the elements in array GlBalAry.
[report a broken link by clicking here]