View previous topic :: View next topic |
Author |
Message |
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Thu Jan 17, 2008 6:44 pm Post subject: COBOL - move negative value into unsigned data type |
|
|
for one of the numeric item, I defined my input copybook as unsigned data field; Eg.: PIC 9(4).
If input fiel contains negative value (because my source system sends negative value), what my program receives? Will program just take the value and ignores the sign OR interpretes into some other value? _________________ Thanks |
|
Back to top |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Thu Jan 17, 2008 10:34 pm Post subject: |
|
|
It will move in the absolute value of the sending field. Also, you might get a compile time warning about dropping the sign during the move. This is in the Language Reference manual under the MOVE statement. _________________ ....Terry |
|
Back to top |
|
|
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Fri Jan 25, 2008 8:29 pm Post subject: |
|
|
I know I'm a little late with this, but for posterity's sake, here goes:
You're probably reading the field into an 01 group level field. With that said, the sign is maintained.
If you need to keep the sign for further processing, best to use a ref/moded move to a signed field to preserve the sign, then do your math. _________________ Regards, Jack.
"A problem well stated is a problem half solved" -- Charles F. Kettering |
|
Back to top |
|
|
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Fri Jan 25, 2008 10:29 pm Post subject: |
|
|
If your input field is PIC 9(4) like you say, it's not a negative number -- it's an unsigned number. See Language Reference manual and test to see your results. The LR manual contains all valid and invalid MOVEs. _________________ ....Terry |
|
Back to top |
|
|
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Sun Jan 27, 2008 11:00 am Post subject: |
|
|
My assumption was that the creating pgm used S9 to create the field.
The OP said: Quote: | ...my source system sends negative value... | In that case the the sign would be present in the field when it was read into the group that contained the 9 definition.
Since the receiving field is part of a gruop item, no conversion takes place and, in spite of the definition of the receiving field (9), it will retain the negative sign.
Then the trick is how to use the negative value instead of the absolute value. That's where the ref/moded move comes into play: Code: | MOVE ABS-VAL TO WS-WRK-SIGNED-VAL(1:) |
Then do the math w/WS-WRK-SIGNED-VAL. _________________ Regards, Jack.
"A problem well stated is a problem half solved" -- Charles F. Kettering
Last edited by slade on Sat Feb 02, 2008 1:33 pm; edited 1 time in total |
|
Back to top |
|
|
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Tue Jan 29, 2008 7:20 pm Post subject: |
|
|
Just a note to say that I was in error when I stated: Quote: |
MOVE ABS-VAL(1:) TO WS-WRK |
The receiving field s/b the ref/moded field, i.e.: Code: | MOVE ABS-VAL TO WS-WRK-SIGNED-VAL(1:) |
I also corrected the prev post. Sorry for the inconvenience. _________________ Regards, Jack.
"A problem well stated is a problem half solved" -- Charles F. Kettering |
|
Back to top |
|
|
|
|