MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

COBOL - move negative value into unsigned data type

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
Sarangadhar
Beginner


Joined: 14 Oct 2004
Posts: 130
Topics: 43
Location: virtual village

PostPosted: Thu Jan 17, 2008 6:44 pm    Post subject: COBOL - move negative value into unsigned data type Reply with quote

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
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Thu Jan 17, 2008 10:34 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Fri Jan 25, 2008 8:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Fri Jan 25, 2008 10:29 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Sun Jan 27, 2008 11:00 am    Post subject: Reply with quote

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
View user's profile Send private message
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Tue Jan 29, 2008 7:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group