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

Displaying a COMP field in sysoud


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: Wed Mar 09, 2011 7:42 pm
Reply with quote

I have a comp variable S9(5) and i am displaying this in job output. do that display sign also ?

Code:
CHAR-FIELD             PIC X(8).     
NUM-FIELD              PIC S9(5).     
NUM-COMP-FIELD         PIC S9(5) COMP.
END-COMP-FIELD         PIC S9(5) COMP.

MOVE '-0025874'         TO CHAR-FIELD.       
DISPLAY 'CHAR FIELD IS : ' CHAR-FIELD.       
                                             
MOVE CHAR-FIELD      TO NUM-FIELD.           
DISPLAY 'NUM-FIELD  IS : ' NUM-FIELD.         
                                             
MOVE NUM-FIELD       TO NUM-COMP-FIELD.       
DISPLAY 'NUM-COMP-FIELD IS : ' NUM-COMP-FIELD.
                                             
MOVE NUM-COMP-FIELD  TO END-COMP-FIELD.       
DISPLAY 'END-COMP-FIELD IS : ' END-COMP-FIELD.


I tried this but it is displaying the below.

Code:
CHAR FIELD IS : -0025874     
NUM-FIELD  IS : 25874         
NUM-COMP-FIELD IS : 0000025874
END-COMP-FIELD IS : 0000025874


could you please anyone explain this. or any link is appreciated.

Thanks
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: Wed Mar 09, 2011 8:17 pm
Reply with quote

The MOVE CHAR-FIELD TO NUM-FIELD is where your difference comes from. The decimal point of a PIC X variable is to the right of the last digit. Hence, 25874 is moved to NUM-FIELD and your sign is lost.

This is all clearly and completely explained in the manuals (link at the top of the page), specifically section 6.2.24.2 of the COBOL Language Reference manual.
Back to top
View user's profile Send private message
PrabakarV

New User


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

PostPosted: Wed Mar 09, 2011 9:04 pm
Reply with quote

sorry i got this.

Code:
CHAR FIELD IS : -0025874       
NUM-FIELD  IS : 2587D         
NUM-COMP-FIELD IS : 0000025874
END-COMP-FIELD IS : 0000025874
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: Wed Mar 09, 2011 9:33 pm
Reply with quote

Code:
       77  CHAR-FIELD                  PIC X(8).
       77  CHAR-FIELD-N                REDEFINES CHAR-FIELD
                                       PIC S9(07) SIGN LEADING SEPARATE.
       77  NUM-FIELD                   PIC S9(5).
       77  NUM-COMP-FIELD              PIC S9(5) COMP.
       77  END-COMP-FIELD              PIC S9(5) COMP.

       PROCEDURE DIVISION.
           MOVE '-0025874'             TO  CHAR-FIELD.
           DISPLAY 'CHAR FIELD IS : ' CHAR-FIELD.

           MOVE CHAR-FIELD-N           TO  NUM-FIELD.
           DISPLAY 'NUM-FIELD  IS : ' NUM-FIELD.

           MOVE NUM-FIELD              TO  NUM-COMP-FIELD.
           DISPLAY 'NUM-COMP-FIELD IS : ' NUM-COMP-FIELD.

           MOVE NUM-COMP-FIELD         TO  END-COMP-FIELD.
           DISPLAY 'END-COMP-FIELD IS : ' END-COMP-FIELD.
produces results, as expected, of
Code:
 CHAR FIELD IS : -0025874
 NUM-FIELD  IS : 2587M
 NUM-COMP-FIELD IS : 000002587M
 END-COMP-FIELD IS : 000002587M
I'm not sure if you deliberately ignored my earlier post, or if you don't understand the manual, or what.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Mar 09, 2011 10:10 pm
Reply with quote

Hi Robert,

Interestingly, i get the "positive" nibble on the zoned-decimal field:
Code:
CHAR FIELD IS : -0025874 
NUM-FIELD  IS : 2587D     
NUM-COMP-FIELD IS : 25874
END-COMP-FIELD IS : 25874
Also, i do not have leading zeros on the COMP fields displays. . .

The difference between what you posted and what i used is that my ws-fields are level 01 rather than 77 . . .

d
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Wed Mar 09, 2011 10:19 pm
Reply with quote

Dick,
Out of Curiousity, did you specify SIGN LEADING SEPARATE on your redefines?
If you DID, then I will be forced to try both Robert's code and your code on my system to see whether the results differ.
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: Wed Mar 09, 2011 10:26 pm
Reply with quote

I tired 01 instead of 77 and got the same results.

My site standard compile process sets TRUNC(BIN). When I recompile with TRUNC(STD), I don't get the leading zeroes on the COMP variables, either.

I redefined the PIC X to numeric SIGN LEADING SEPARATE to pick up the sign -- hence the code post. With just the MOVE the O/P has, I get the same results you do (using TRUNC(STD) of course).
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Mar 09, 2011 10:27 pm
Reply with quote

Hi Ronald,

Actually, i used the code initially posted by the TS - i don't have a redefines. And having said that i realize i forgot Robert's original reply. . . Agreed with this 2 hours ago and lost it . . . Dain Brammage. . . icon_redface.gif

Yeeesh. . .

d
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Mar 09, 2011 10:28 pm
Reply with quote

Follow on. . .

Maybe i shouldn't work on things that dispense medicine or write checks today. . . icon_lol.gif

d
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: Wed Mar 09, 2011 10:37 pm
Reply with quote

Hey, if you're writing checks can I get in line? icon_biggrin.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Mar 10, 2011 1:45 am
Reply with quote

Sure - maybe we can share the same jail cell. . . icon_cool.gif

d
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 Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts IBM OnDemand Folders displaying to al... IBM Tools 6
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
Search our Forums:

Back to Top