8.3 Technique 2 - Using the SUBSTRING Command
Note: This technique is considered redundant. Refer to 8.4 Technique 3 - Using the DEF_ARRAY Command for the best solution.
Note that this method will not work for arrays that contain negative values. Refer to the SUBSTRING command in the .
In the RDML program use a "get" subroutine to retrieve a value imbedded within field CYR.
SUBROUTINE NAME(GET_FLD)
PARMS((#INP *RECEIVED)(#VALUE *RETURNED))
DEFINE #INP *DEC 3 0 (always use odd length packed)
DEFINE #VALUE *DEC 7 2
DEFINE #POS *DEC 7 0
CHANGE FIELD(#POS) TO('(#INP * 7) - 6')
SUBSTRING FIELD(#CYR #POS 7) INTO(#VALUE 1 7)
ENDROUTINE
In the RDML program use a "put" subroutine to place a value back into field FLD.
SUBROUTINE NAME(PUT_FLD)
PARMS((#INP *RECEIVED)(#VALUE *RECEIVED))
CHANGE FIELD(#POS) TO('(#INP * 7) - 6')
SUBSTRING FIELD(#VALUE 1 7) INTO(#CYR #POS 7)
ENDROUTINE
By using these routines you can "index" the field CYR like this, to calculate totals of all 12 fields:
CHANGE FIELD(#TOT) TO(0)
BEGIN_LOOP FROM(1) TO(12) USING(#I)
EXECUTE GET_FLD (#I #CYRXX)
CHANGE FIELD(#TOT) TO('#TOT + #CYRXX')
END_LOOP
to increment all values in list by 10 percent:
BEGIN_LOOP FROM(1) TO(12) USING(#J)
EXECUTE GET_FLD (#J #INCR)
CHANGE FIELD(#NVAL) TO('#INCR * 1.1')
EXECUTE PUT_FLD (#J #NVAL)
END_LOOP