## EVAL Math Problem

605 pts.
Tags:
iSeries development
RPGLE
Bruce, can you figure out this piece of code? I don't understand the result I get. Before code is executed: XXAVAL = 0, LTSTHQ = 30, LTCUSQ = 30, LTPICQ = 0, XPQTY = 30, OLOLQT = 30
```EVAL      XXAVAL= LTSTHQ-(LTCUSQ+LTPICQ+XPQTY)+OLOLQT
```
After code is executed: XXAVAL = 0. I figured XXAVAL should be 60?

Thanks. We'll let you know when a new response is added.

The hierarchy of the EVAL states that all calculations within parentheses are done first. Your eval would translate to:

```XXAVAL = 30 - (30 + 0 + 30) + 30 which would then become
XXAVAL = 30 - 60 + 30 whci would give a value of 0.```

—————————————————————-

Parenthesis are indeed done first. For the “rest of the story” see Operation Precedence in the ILE RPG Reference.

Bruce Vining

Thanks, guys!
Well, my brain doesn’t always see what the my eyes show it. I copied that line of code direct from the source member. What I didn’t see was that the minus sign is abutted against the paren.

That changes the operation from a binary operation (subtract) to a unary operation (ie. like z-sub).

That’s the real problem/answer, not Operation Precedence, but Expression Operators!

So, the real formula is:

`XXAVAL= 30 + (60-) + 30 making XXAVAL = zero.`

I’ll remember to check for spaces in a formula, ’cause it changes + and -.
Kevin