RPGLE Convert negative number into decimal

145 pts.
Tags:
RPGLE
RPGLE negative zoned decimal
Input field (CHGAMT) is defined as 17S 2 but has a negative value     (-14.00)  viewed as '0000000000000140}'

I have to first move this value into a character field and get it into a decimal format again (17S 2) so I can use the value to compare to another field defined the same way.  Ultimately, I will need it to have the negative sign print in a field in an output file as 14.00- or -14.00. 

I tried to move this value into a field defined as 17S 2 - but it drops the negative sign. 

Any suggestions? 

Thank you.

 

 

 



Software/Hardware used:
RPGLE iseries AS400

Answer Wiki

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

When you say that the field is defined as 17 s 2, are you talking about the program or your print file? If you are not seeing the negative sign when it prints, what edit code are you using in your print file?

I put together the following little down and dirty program.

<pre>

d neg_number_1 s 17s 2 inz(0)

/Free

neg_number_1 = -14.00;

/End-Free

</pre>

When I run it in debug, I get:

NEG_NUMBER_1 = -000000000000014.00.

I’m not sure why you are getting ’0000000000000140}’ unless this is the value of a character field. I don’t understand why you think you need to move the field to a character field to get it back into a decimal format. Can you post some of your code, especially your D specs?

Discuss This Question: 6  Replies

 
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
  • TomLiotta
    I tried to move this value into a field defined as 17S 2 - but it drops the negative sign. Please clarify -- did you MOVE the value or EVAL the value? What version/release? And please verify that this is ILE RPG and not RPG/400. There is no problem with setting a 17s 2 variable to the value -14.00, so there is clearly some other issue that isn't being included. What does "drops the negative sign" mean? How did you determine it was 'dropped'? By printing it? By displaying it in one of your display files? By viewing the memory in a debug session? Tom
    125,585 pointsBadges:
    report
  • CharlieBrowne
    Are you losing the sign while printing or calculating. If it while printing, you either have the wrong edit code or you have another output overlaying the sign field. If this is the case, simply change the order of the fields in your O specs. By habit we usually have them from low to high ending position. If you switch to High to Low ending positiion, you can solve this problem if fields are too large.
    41,370 pointsBadges:
    report
  • TomLiotta
    When I run it in debug, I get: NEG_NUMBER_1 = -000000000000014.00. That's exactly how it should look. It's correct. But it doesn't illustrate the "problem" which still isn't clear. Why do you say it “drops the negative sign”? What is dropping the sign? Your report? Or something else? Tom
    125,585 pointsBadges:
    report
  • Pt0505
    I am not printing anything. I am using RPGLE. I am reading an input file that has the neg value in the field defined as 17 S 2 '0000000000000140}'. I pass it to another field in my program that is defined as 80 char (it has to be this way - another software that we use where I can pass data between external files and this software - I have parms I can use, but are 80 char). I then use that value to do other functions and eventually write out the value into an output file/field. But to do that other function, I need to have this other field have my value as a negative. When the value is passed to the 80 char field, the sign is no longer there. When I did a dump, the negative was not there. I did finally solve this - I did a MOVEL of my initial value to the 80 char field, then to a char field defined as 17A and another field defined as 17S 2. I then check the 17th position of the char field for a value less than 0. If it is, I multiply my numeric field by -1.
    145 pointsBadges:
    report
  • CharlieBrowne
    For future reference: Since you are moving from numeric to alpha, you do lose the sign. Next time, use Eval Axx = %editc(Nxx : '?' where Axx is your alpha field Nxx is your numeric field and ? is an RPG Edit Code
    41,370 pointsBadges:
    report
  • WoodEngineer
    The iSeries uses the zone area of the right-most digit (packed) to carry the sign. This can yield odd results when just viewing the field in its raw form. The } character indicates a zero with the negative bit set. A negative one will show as J. Try the %editc techinque that CharlieBrown recommends and you'll be good to go. No need to move the data from field to field to field.
    6,305 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