×

Good News Everybody!

The new search engine is LIVE!

Please report any problems to david (at) midrange.com.




I'm pretty sure you're being bit by eval's handling of intermediate results...

Since PositiveValue is an unsigned integer, and 21 is a constant that
could also be considered an unsigned integer, eval is treating the
results as an unsigned integer which obviously won't hold a negative
value.

Solution:
1) redefine PositiveValue as a signed integer
2) let eval know you're dealing with signed values
a) NegativeValue = %int(PositiveValue) - 21;
b) NegativeValue = PositiveValue + (-21);

note that 2a) would blow up given a PositiveValue greater than 127.

I'd go with option 1) myself....

HTH,
Charles



On Mon, Sep 27, 2010 at 4:04 PM, Koester, Michael
<mkoester@xxxxxxxxxxxxx> wrote:
I have a variable defined "3i 0", local to a subprocedure that I expect
could be any whole number value from -128 to +127, per my understanding
of a signed integer.  When my subprocedure puts what I expect to be a
minus 18 into the field, I get the dreaded "MCH1216 -  too small to hold
result" crash & burn.

I'm sure I can fix it instantly by defining packed numerics, but I need
to understand the rules.

D PositiveValue            3u  0
D NegativeValue            3i  0
 /free
 PositiveValue = 3;
 NegativeValue = PositiveValue - 21;
  [down in flames we go]
 /end-free

What could be so tough about subtracting 3 from 21 and expecting -18?
Please set me straight here.  It's an SQLRPGLE program on a 6.1 box.

Many thanks.
Michael Koester

--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2026 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.