Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Negative Sign display issue

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Negative Sign display issue
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7233

PostPosted: Tue Apr 19, 2011 1:28 pm    Post subject: Reply to: Sign issue
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7233

PostPosted: Tue Apr 19, 2011 1:49 pm    Post subject: Reply to: Sign issue
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7233

PostPosted: Tue Apr 19, 2011 2:27 pm    Post subject: Reply to: Sign issue
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: 7913
Location: Bellevue, IA

PostPosted: Tue Apr 19, 2011 3:54 pm    Post subject:
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7233

PostPosted: Tue Apr 19, 2011 4:32 pm    Post subject: Reply to: Sign issue
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7233

PostPosted: Tue Apr 19, 2011 5:41 pm    Post subject: Re: Reply to: Sign issue
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts DFHRESPONSE returns issue divated CICS 3 Wed Nov 02, 2016 6:32 pm
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm
No new posts How to display value of an exit param... lind sh CICS 2 Sun Oct 09, 2016 12:28 pm
This topic is locked: you cannot edit posts or make replies. DSList (3.4) cannot display Chinese c... jacobdng TSO/ISPF 4 Wed Oct 05, 2016 2:51 pm
This topic is locked: you cannot edit posts or make replies. Get and display content of an address... lind sh CICS 1 Mon Aug 08, 2016 9:18 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us