in RPG III I need to store an huge array in a file. The maximum fieldlength is 256, thus I defined the file with 16 fields of 250 chars long each. Is there a way to put the 1000 values of the array into the 16 fields without moving? Just like the REDEFINES in COBOL?
array in the program:
E MPDV 1000 4
Specicifation of the file:
D000001 1 4 WRPMOD
D000002 5 254 W01PDV
... etc. until
D000017 37554004 W16PDV
In Cobol I would write:
01 MPDV-TOP.
03 MPDV-ARR OCCURS 1000.
05 MPDV PIC X(4).
01 WRPREC REDEFINES MPDV-TOP.
03 W01PDV PIC X(250).
.... ETC. UNTIL
03 W16PDV PIC X(250).
Reading the file I get the array MPDV with it's values and with values in MPDV I can write the file.
my solution looks like this: an extra array
E MPX 16250 MPDV REDEF
and lots of moves:
C MOVELMMEMOD WRPMOD
C MOVEAMPDV MPX
C MOVELMPX,1 W01PDV
C MOVELMPX,2 W02PDV
.... etc until
C MOVELMPX,16 W16PDV
C WRITEWRPASM
and reverse for reading.
Use a Data Structure to overlay the individual fields into the main field:
IMPDV DS
I 1 250 W01PDV
I 251 500 W02PDV
I 501 750 W03PDV
. . .
I 37514000 W16PDV
For more information I recommend the following resources:
IBM i information center
ILE RPG Programmers Guide
ILE RPG Language Reference
Safari Books Online
The Modern RPG IV Language