IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Negative Sign display issue


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
PrabakarV

New User


Joined: 21 Dec 2007
Posts: 88
Location: My Desk

PostPosted: Tue Apr 19, 2011 12:53 pm
Reply with quote

Could you please tell me why i am not getting negative sign for my case 2 in the below code.

Code:
DISPLAY 'TEST 1'.                             
DISPLAY ' '.                                 
MOVE '+0005'         TO CHAR-FIELD.           
DISPLAY 'CHAR FIELD IS : ' CHAR-FIELD.       
                                             
MOVE CHAR-FIELD      TO NUM-FIELD.           
DISPLAY 'MOVING X(5) TO S9(4)'.               
DISPLAY 'NUM-FIELD-SIGNED  IS : ' NUM-FIELD. 
                                             
COMPUTE NUM-FIELD = NUM-FIELD + TEMP-VAR.     
DISPLAY 'TEMP-VAR ' TEMP-VAR.                 
DISPLAY 'ADDING 0003 TO SIGNED FIELD'.       
DISPLAY 'NUM-FIELD-SIGNED  IS : ' NUM-FIELD-N.
                                             
DISPLAY ' '.                                 
DISPLAY 'TEST 2'.                             
DISPLAY ' '.                                 
MOVE '-0005'         TO CHAR-FIELD.           
DISPLAY 'CHAR FIELD IS : ' CHAR-FIELD.       
                                             
MOVE CHAR-FIELD      TO NUM-FIELD.           
DISPLAY 'MOVING X(5) TO S9(4)'.               
DISPLAY 'NUM-FIELD-SIGNED  IS : ' NUM-FIELD. 
                                             
COMPUTE NUM-FIELD = NUM-FIELD + TEMP-VAR.     
DISPLAY 'TEMP-VAR ' TEMP-VAR.                 
DISPLAY 'ADDING 0003 TO SIGNED FIELD'.       
DISPLAY 'NUM-FIELD-SIGNED  IS : ' NUM-FIELD-N.
                                             
DISPLAY ' '.                                 
DISPLAY 'TEST 3'.                             
DISPLAY ' '.                                 
                                             
MOVE +0005 TO NUM-FIELD.                     
DISPLAY 'NUM-FIELD-SIGNED  IS : ' NUM-FIELD-N.
COMPUTE NUM-FIELD = NUM-FIELD + TEMP-VAR.     
DISPLAY 'TEMP-VAR ' TEMP-VAR.                 
DISPLAY 'ADDING 0003 TO SIGNED FIELD'.       
DISPLAY 'NUM-FIELD-SIGNED  IS : ' NUM-FIELD-N.
                                             
DISPLAY ' '.                                 
DISPLAY 'TEST 4'.                             
DISPLAY ' '.                                 
                                             
MOVE -0005 TO NUM-FIELD.                     
DISPLAY 'NUM-FIELD-SIGNED  IS : ' NUM-FIELD-N.
COMPUTE NUM-FIELD = NUM-FIELD + TEMP-VAR.     
DISPLAY 'TEMP-VAR ' TEMP-VAR.                 
DISPLAY 'ADDING 0003 TO SIGNED FIELD'.       
DISPLAY 'NUM-FIELD-SIGNED  IS : ' NUM-FIELD-N.


OUTPUT that I got after running the above:

Code:
TEST 1                     
                           
CHAR FIELD IS : +0005     
MOVING X(5) TO S9(4)       
NUM-FIELD-SIGNED  IS : 000E
TEMP-VAR 0003             
ADDING 0003 TO SIGNED FIELD
NUM-FIELD-SIGNED  IS : 000H
                           
TEST 2                     
                           
CHAR FIELD IS : -0005     
MOVING X(5) TO S9(4)       
NUM-FIELD-SIGNED  IS : 000E
TEMP-VAR 0003             
ADDING 0003 TO SIGNED FIELD
NUM-FIELD-SIGNED  IS : 000H
TEST 3                     
                           
NUM-FIELD-SIGNED  IS : 000E
TEMP-VAR 0003             
ADDING 0003 TO SIGNED FIELD
NUM-FIELD-SIGNED  IS : 000H
                           
TEST 4                     
                           
NUM-FIELD-SIGNED  IS : 000N
TEMP-VAR 0003             
ADDING 0003 TO SIGNED FIELD
NUM-FIELD-SIGNED  IS : 000K


isn't that case 2 and 4 supposed to be issuing same results. Please give me suggestions on what i am missing here.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 19, 2011 1:28 pm
Reply with quote

You are moving a literal. Something in quotes. Check in the manual what this will do, and you will have your answer, or most of it.
Back to top
View user's profile Send private message
PrabakarV

New User


Joined: 21 Dec 2007
Posts: 88
Location: My Desk

PostPosted: Tue Apr 19, 2011 1:35 pm
Reply with quote

data definition is below

Code:
01  COMP-TEST.                         
    05  CHAR-FIELD             PIC X(5).
    05  NUM-FIELD              PIC S9(4).
    05  TEMP-VAR               PIC 9(4) VALUE 0003.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 19, 2011 1:49 pm
Reply with quote

Quote:

data definition is below


OK.... but where is the result of your research in the manuals? You have two problems. Find the first, and you can get help with the second.
Back to top
View user's profile Send private message
PrabakarV

New User


Joined: 21 Dec 2007
Posts: 88
Location: My Desk

PostPosted: Tue Apr 19, 2011 2:21 pm
Reply with quote

I think you are referring to this item below; (under VS COBOL ref 3.22.1)

Quote:
If the sending item has an operational sign, the unsigned value is
used. If the operational sign occupies a separate character, that
character is not moved, and the size of the sending item is considered
to be 1 less character than the actual size.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 19, 2011 2:27 pm
Reply with quote

No, not what I was thinking of. You are moving a literal. That literal happens to contain "-", which the Cobol compiler cares about neither one way nor the other when you move that literal to a numeric field. Forget, for the moment, that there is a sign in the literal, cos, between you and the compiler, only you know that.

I'm hoping that you can locate what happens when you move a non-numeric literal to a numeric field. Because that, plus a little extra, is what is happening in your example.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Apr 19, 2011 3:54 pm
Reply with quote

Your test 2 and test 4 are very different. COBOL treats any literal -- something with quote or tic marks around it -- as an unsigned positive value. Your putting a negative sign in the literal does not change that treatment. That negative sign is completely ignored. Go back and look at your results again, considering this new information.
Back to top
View user's profile Send private message
PrabakarV

New User


Joined: 21 Dec 2007
Posts: 88
Location: My Desk

PostPosted: Tue Apr 19, 2011 4:16 pm
Reply with quote

Got answer for it.

Quote:
The following rules outline the execution of valid elementary moves. When the receiving item is:

Numeric or Numeric-edited:

° If the receiving item is signed, the sign of the sending item is placed in the receiving item, with any necessary sign conversion. If the sending item is unsigned, a positive operational sign is generated for the receiving item.

° If the receiving item is unsigned, the absolute value of the sending item is moved, and no operational sign is generated for the receiving item.

° When the sending item is alphanumeric, the data is moved as if the sending item were described as an unsigned integer.


Thanks Bill, Robert.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 19, 2011 4:32 pm
Reply with quote

Yes.

When I started out, if I had a question I resolved it by looking in manual, talking to colleagues, and if still no answer, keep at the manual until I got it workd out. Didn't have internet forums. I think you should always try the first two methods first. You'll pick up a lot mroe that way, probably.

Not quite finished yet.

You might be thinking that "alphanumeric" means a number in a PIC X(x) field. It doesn't. Try putting total rubbish in there. The compiler will still do the move. Sometimes you'll get S0C7. Sometimes you won't. If you are investigating the actions of MOVE statements, then you should know. Try changing you "-" to a "¬" (logical not) and see what happens.

Quote:

° If the receiving item is signed, the sign of the sending item is placed in the receiving item, with any necessary sign conversion. If the sending item is unsigned, a positive operational sign is generated for the receiving item.

...

° When the sending item is alphanumeric, the data is moved as if the sending item were described as an unsigned integer.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 19, 2011 5:41 pm
Reply with quote

Bill Woodger wrote:

Sometimes you'll get S0C7.


I don't mean on the MOVE. I defy anyone to get a S0C7 moving PIC X(x) to PIC 9(x). I meant on the ADD afterwards.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Issue after ISPF copy to Linklist Lib... TSO/ISPF 1
No new posts Facing ABM3 issue! CICS 3
No new posts Panvalet - 9 Character name - Issue c... CA Products 6
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top