8.2 Technique 1 - Virtual Fields and a Working List
Note: This technique is considered redundant. Refer to 8.4 Technique 3 - Using the DEF_ARRAY Command for the best solution.
Set up virtual fields (CYR01, CYR02, ..... CYR12) and virtual code to return the separate fields from field CYR to the program after reading a record from the file, and to "re-build" the field CYR from the separate fields when writing a record to the file.
Define some virtual code for Data structure specifications ("I" specs).
I DS
I 1 84 WRK
I 1 72WRK01
I 8 142WRK02
" " " " "
" " " " "
I 78 842WRK12
Derive some virtual code for Calculations after input from file ("C" specs).
C*
C* VC_USING FIELDS(CYR01 CYR02 ...... CYR12 CYR)
C*
C MOVELCYR WRK
C Z-ADDWRK01 CYR01
C Z-ADDWRK02 CYR02
C " " "
C " " "
C Z-ADDWRK12 CYR12
C*
Derive some virtual code for Calculations before output to file ("C" specs).
C*
C* VC_USING FIELDS(CYR01 CYR02 ...... CYR12 CYR)
C*
C Z-ADDCYR01 WRK01
C Z-ADDCYR02 WRK02
C Z-ADD " "
C Z-ADDCYR12 WRK12
C MOVELWRK CYR
C*
After reading a record from the file, an RDML subroutine can be executed to place the separate values retrieved in the virtual fields (loaded from field CYR by the virtual code) into a working list, which can then be indexed like an array.
This example is working with an "array" of 12 virtual fields called CYR01 -> CYR12.
FETCH FIELDS(#CYR01 ..... #CYR12) FROM_FILE(.....)
EXECUTE LOAD
SUBROUTINE LOAD
DEF_LIST NAME(#LIST) FIELDS(#CYRXX) TYPE(*WORKING)
NBR_ENTRYS(12)
CLR_LIST #LIST
CHANGE #CYRXX #CYR01
ADD_ENTRY #LIST
CHANGE #CYRXX #CYR02
ADD_ENTRY #LIST
" " "
CHANGE #CYRXX #CYR12
ADD_ENTRY #LIST
ENDROUTINE
Before writing a record to the file, an RDML subroutine can be executed to place the 12 values in the working list back into the 12 individual virtual fields (which will subsequently be loaded back into the field CYR by the virtual code) that will actually be used to update the database.
EXECUTE ULOAD
UPDATE FIELDS(#CYR01 .... #CYR12) IN_FILE(.....)
SUBROUTINE ULOAD
GET_ENTRY 1 #LIST
CHANGE #CYR01 #CYRXX
GET_ENTRY 2 #LIST
CHANGE #CYR02 #CYRXX
" " "
GET_ENTRY 12 #LIST
CHANGE #CYR12 #CYRXX
ENDROUTINE
If the file contains more than 1 array, the LOAD and ULOAD routines can be extended to include more fields in working list #LIST. Thus only 1 working list and 1 pair of subroutines are required.
Once these routines are used to place the 12 fields into a working list you can manipulate the values just like an array.
For example, to calculate total of all 12 fields:
CHANGE #TOT 0
BEGIN_LOOP FROM(1) TO(12) USING(#I)
GET_ENTRY #I #LIST
CHANGE #TOT (#TOT + #CYRXX)
END_LOOP
to increment all 12 values in list by 10 percent:
BEGIN_LOOP FROM(1) TO(12) USING(#I)
GET_ENTRY #I #LIST
CHANGE #CYRXX (#CYRXX * 1.1)
UPD_ENTRY #LIST
END_LOOP