Q. I just can't figure this one out. I need to place a numeric field into a numeric array in an RPG/400 program, so that each digit of the original field goes into separate elements of the numeric array. The field I'm trying to move is named MSTDLR and is defined as packed decimal, 7 digits, 2 decimals. 3 shows what I'm trying to do.
Q. I just can't figure this one out. I need to place a numeric field into a numeric array in an RPG/400 program, so that each digit of the original field goes into separate elements of the numeric array. The field I'm trying to move is named MSTDLR and is defined as packed decimal, 7 digits, 2 decimals. Figure 3 shows what I'm trying to do.
The MOVEL operation is there to turn MSTDLR into a whole number. The MOVEA operation moves the whole number into array ARD. When I try to compile this, however, the compiler produces error message QRG7105 ("DOLAR and ARD are not the same type and length"). Am I doing something wrong? Please help!
A. The MOVEA operation has some restrictions when the data being moved is numeric. One such restriction is that both Factor 2 and the Result field must have the same length. Since DOLAR has five digits and each element of ARD has only one, the compiler chokes on this MOVEA and flags it as illegal.
To accomplish what you're attempting to do, convert the numeric data temporarily to character, MOVEA it into a character array, then MOVE this array into ARD, as shown in 4. Then it will work as you wanted. In particular, notice the MOVEL operation, which both truncates MSTDLR to a whole number and converts it to character in a single stroke.
To accomplish what you're attempting to do, convert the numeric data temporarily to character, MOVEA it into a character array, then MOVE this array into ARD, as shown in Figure 4. Then it will work as you wanted. In particular, notice the MOVEL operation, which both truncates MSTDLR to a whole number and converts it to character in a single stroke.
TechTalk: Not All MOVEs Are Valid
Figure 3 Incorrect code
Figure 3: Incorrect Code ... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 E ARD 5 1 0 * C MOVELMSTDLR DOLAR 50 C MOVEADOLAR ARD
TechTalk: Not All MOVEs Are Valid
Figure 4 Corrected code
Figure 4: Corrected Code ... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 E ARD 5 1 0 E ARDC 5 1 * C MOVELMSTDLR DOLARC 5 C MOVEADOLARC ARDC C MOVE ARDC ARD
LATEST COMMENTS
MC Press Online