negative numeric values

1150 pts.
Tags:
PF
RPG
RPG/400
How to retrieve the negative numeric values stored in packed fields of a PF into a RPG program and process them?

Answer Wiki

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

All numeric field types are basically handled the same way.

Your F spec should define the file as E (externally) defined.
The field can be used by field name, say QtyOnHnd (of course that field should never be negative)
in rpg – rpgle

If QtyOnHnd < *zero
eval errQty = *on
else
eval errQty = *off
endif.

To put a negative value in the field
Eval QtyOnHnd = -1

Phil
///////////////////////////////////////////////////////////////////////////////////////
Wilson, you’re absolutely right.
There is 0% chance of getting the record structure wrong when using the external description but there are times when other strategies do apply. In this case, it didn’t appear that the question required an answer quite so complex.

Phil

- – - – - – - – -

In the RPG languages, you don’t even need to think about it. That’s why we have a compiler!

The opcodes ADD, SUB, Z-ADD, Z-SUB, EVAL – all the arithmetic, in fact, just ‘does it’

You may wish to look at edit codes for final output, though, in order to represent the negative value in human readable form, either with a negative sign, or brackets.

IF you’re really interested, the sign is stored in the high order half byte of the rightmost byte of the field. You may interrogate this, and used to have access with opcodes MVHLZ (sic) and its friends. Or you could just check the bits.

Binary negative fields?? – another question.

Yorkshireman

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • WilsonAlano
    Phil, Why did you say "Your F spec should define the file as E (externally) defined."? Internal described files allows negative packed fields just like externals. Just the way to describe the file/field to the program changes. Wilson
    2,485 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following