Hi, everyone. I may have a "can't get there from here" problem with the way %EDITC works using edit code 'X' with negative values.
I'm converting old code with LOTS of (dreaded) MOVE, MOVEL, and MOVEA instructions. We have ARCAD-Transformer RPG (with which I'm pretty happy) to aid in conversion to Free-format ... but it's only human. ;-) The program contains three fields:
Our old code looks like this (and you gotta love those effortless character-numeric conversions):
... and the free-format conversion looks like this:
... which seems to me a pretty decent and safe code conversion.
However, in testing, RPAG receives the negative value -46100. This causes no problem with the compiled fixed-format code, but in free-format code, "%EDITC(RPAG:'X')" produces "00000000004610}", as the negative sign is indicated by a 'D' in the high-order bits of the last digit (X'D0"="}"). Then when the %DEC is encountered, expecting a character string that can be interpreted as numbers, the last character of SH#HGA causes runtime error RNX0105 (A character representation of a numeric value is in error).
Without going in to too much gory detail about how MOVE works, the use of %EDITC(xxx:'X'), rather than %CHAR(xxx), is almost mandatory, since %CHAR (as well as edit codes other than 'X') truncates leading zeroes and therefore produces strings of different lengths, depending upon content. OTOH, %EDITC( :'X') produces a character string of a consistent length.
So while %CHAR and %DEC seem to be inverse functions, %EDITC( :'X') and %DEC are not. (To be fair, I'm not sure what %EDITC( :'X'') could/should do with a negative value other than what it's doing now.)
To avoid the problem, we may do something like this:
... or a similar workaround, which is simple enough but requires manually seeking out, analyzing, and fixing every numeric-to-character MOVE statement. 
Can anyone suggest how to mitigate the problem? :-) Any magical compiler settings, CTL-specs, ARCAD parameter settings, anything?
I'm converting old code with LOTS of (dreaded) MOVE, MOVEL, and MOVEA instructions. We have ARCAD-Transformer RPG (with which I'm pretty happy) to aid in conversion to Free-format ... but it's only human. ;-) The program contains three fields:
Code:
RPAG : PACKED(15: 0) SH#HGA : CHAR(15) $H2 : PACKED(15: 0)
Code:
C MOVE RPAG SH#HGA ... C MOVE SH#HGA $H2 15 0
Code:
SH#HGA = %EDITC(RPAG:'X');
...
$H2 = %DEC(%XLATE(' ':'0':SH#HGA):15:0);
However, in testing, RPAG receives the negative value -46100. This causes no problem with the compiled fixed-format code, but in free-format code, "%EDITC(RPAG:'X')" produces "00000000004610}", as the negative sign is indicated by a 'D' in the high-order bits of the last digit (X'D0"="}"). Then when the %DEC is encountered, expecting a character string that can be interpreted as numbers, the last character of SH#HGA causes runtime error RNX0105 (A character representation of a numeric value is in error).
Without going in to too much gory detail about how MOVE works, the use of %EDITC(xxx:'X'), rather than %CHAR(xxx), is almost mandatory, since %CHAR (as well as edit codes other than 'X') truncates leading zeroes and therefore produces strings of different lengths, depending upon content. OTOH, %EDITC( :'X') produces a character string of a consistent length.
So while %CHAR and %DEC seem to be inverse functions, %EDITC( :'X') and %DEC are not. (To be fair, I'm not sure what %EDITC( :'X'') could/should do with a negative value other than what it's doing now.)
To avoid the problem, we may do something like this:
Code:
IF RPAG >= 0; SH#HGA = %EDITC(RPAG:'X'); ELSE; SH#HGA = '-' + %SUBST(%EDITC(- RPAG:'X'):2); // at the risk of losing a high-order non-zero digit. ENDIF;

Can anyone suggest how to mitigate the problem? :-) Any magical compiler settings, CTL-specs, ARCAD parameter settings, anything?






Comment