I don't have much knowledge in RPGLE. I am trying to solve this small exercise given to me. I never worked or seen exercises using decimals. I want to get percentage of 7 values. So, I want to do the following calculation.
For example in RPGLE.
DTotal S 3P 0
DPercnt S 2P 2
/Free
Total = 589;
Percnt = (Total/700)100;
Dsply Percnt;
*Inlr = *On;
/End-Free
Expected output is 84.142857143
or round off decimal places to two (84.14)
or four (84.1430)
places.
- Which Data type I should use for
Total
andPercent
Variables? - How can I declare
Percent
variable (Packed or Zoned) to hold two or four or N decimal places? - Can anyone please type the declaration part and the calculation part in "RPG IV" or in Fixed-format please?
Errors I got and corrections I carried-out:
The end of the expression is expected.
(with in SEU)For the above error, I added
*
and it solvedPercnt = (Total/700) * 100;
Below is the second error.
The target for a numeric operation is too small to hold the result (C G D F)
For above error, I increased
Percnt
variable length to4P 2
.But this time answer was wrong,
DSPLY 8414
. Not as expected.So, I used
Eval
as suggested below.Eval(H) Percnt = (Total/700) * 100;
Still same output:
DSPLY 8414
.Thanks @Barbara. I noticed this tip late.
DSPLY (%CHAR(Percnt))
gave me the desired output84.14
.