Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with RPG arithmethic

Status
Not open for further replies.

Ju5

Programmer
May 25, 2007
85
PH
I need to add a condition to an RPG program that compares a variable to a negative value.

The current code:
A SUB B Diff
Diff ifle 5
.
.
.
endif
where A is larger than B and Diff is a 2 length 0 Decimal variable.

Need to change it so that the statement comes out as:
A - B = Diff
if Diff is less than -15(diff is -14 to 0)... endif

Is this formula correct for calculating rate?
x Div y quot
MVR remain
remain MULT 100 rate

where
length dec
quot 3 3
remain 3 3
rate 3 3

The code is in RPG so I'm not sure if I can use %REM instead of MVR and I can't use /Free either.
 
Well,,, I sure my cohorts on this site will give you a better way. But you could always do this.
diff ifle 0
diff ifge -14
.
.
.
endif
endif
that way the ... gets preformed if diff is between -14 and 0

Now what rate are you trying to calculate? Are you calculating the % diff between 2 numbers.

Say 10 and 6,, the diff would be 4, and 10 / 4 * 100 = 40%

Is this what you are trying to do??
 
Apparently you're using RPG IV so I don't see any reason you don't use /free code.

As for the comparison, you could code the following.
/free
if (A - B) < -15;
...;
endif;
 
The file type for the code is RPG not RPGLE. What effect would it have on the code if I changed it from RPG to RPGLE?

I'm trying to calculate the rate of completion(i.e. Actual vs. Estimated)
 
How should I catch the decimal result of Qty1 / Qty2 for the rate computation? DIV only catches the whole number, right?

Here's what I am using:
actual DIV estimate result 42
MVR QRATE 42
QRATE MULT 100 QPCT 42
QPCT IFGE 90
...
END

Is this correct?
 
The computation is ok but you should lengthen the variables up to 5.2 because of the sign.
Code:
actual    DIV  estimate  result  52
          MVR            QRATE   52
QRATE     MULT 100       QPCT    52

Or, in RPG IV (RPGLE source member type)
Code:
D ActualNoDec     s             11p 0 Inz(0)        
D EstimateNoDec   s             11p 0 Inz(0)         
D QRateNoDec      s              5p 0 Inz(0) 
D QPct            s              5p 2 Inz(0)    

 /free
  ActualNoDec = Actual * 100;
  EstimateNoDec = Estimate * 100;

  // Developed coding example
  QrateNoDec = %REM( ActualNoDec : EstimateNoDec );   
  QPct = QrateNoDec / 100;

  // Or, direct coding example
  Eval (h) QPct = %REM( ActualNoDec : EstimateNoDec ) / 100;
Note. %REM function supports only numeric values with zero decimal positions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top