I need a way to capture the decimal value of a numeric field (i.e. 5.78). Need a way to be able to break the decimal value away to do computations on it. How do I achieve this using RPG III coding techniques?
It depends on exact circumstances, but using data structure subfields will get your exact requirement handled.
I DS
I 1 53@CVT
I 3 53@FRAC
I DS
I 1 33FRAC
C Z-ADD5.78 @CVT
C Z-ADD@FRAC FRAC
C*** DO CALCS WITH FRAC...
C SETON LR
Define the subfields to hold the largest numbers of digits, including fractional digits, that your program needs to handle. Make sure that the two intermediate subfields (@CVT and @FRAC) are defined as zoned decimal.
(We'll see how the "code" looks after it gets posted.)
Tom
Well, sorry about the formatting. This editor makes very little sense.
The @CVT field is defined over positions 1-5 with 3 decimal fraction positions. It's zoned decimal. Both @FRAC and FRAC also have 3 decimal positions and are zoned decimal. @FRAC is defined starting position 3 of the DS because that's where the fractional portion of @CVT begins. @CVT is where your numeric value will be placed for conversion to just the fractional portion.
Tom
Oh sorry ... RPG III .. why would you do that? Is this another interview question? . But if you must, check out the DIV and MVR commands. If you divide by 1 the Remainder (MVR) would be the decimal.
Discuss This Question: 4 Replies