View previous topic :: View next topic
|
Author |
Message |
PrabakarV
New User
Joined: 21 Dec 2007 Posts: 88 Location: My Desk
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
PrabakarV
New User
Joined: 21 Dec 2007 Posts: 88 Location: My Desk
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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. . .
Yeeesh. . .
d |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Follow on. . .
Maybe i shouldn't work on things that dispense medicine or write checks today. . .
d |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Hey, if you're writing checks can I get in line? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Sure - maybe we can share the same jail cell. . .
d |
|
Back to top |
|
|
|