View previous topic :: View next topic |
Author |
Message |
dhruva Beginner
Joined: 15 Sep 2004 Posts: 4 Topics: 2
|
Posted: Wed Sep 15, 2004 2:14 pm Post subject: Cobol Binary to Numeric Conversion |
|
|
Hi ,
In many of our production programs display of variables are in Binary format, so always we need to interpret 68J as +681. To have it on everyone desk, I just wrote small program to get all values for +0 to +9 and -0 to -9. But surprisingly I got some different results than expected (Am I Expecting wrong ?)
Please see the below program:
Code: |
WORKING-STORAGE SECTION.
**************************
01 WS-FLAG-VARIABLES.
05 WS-BINARY-NUM PIC S9(05) COMP-3 VALUE +0.
05 WS-DISPLAY-NUM PIC S9(05) VALUE +0.
05 WS-EDITED-NUM PIC +9(05) .
.
********************
PROCEDURE DIVISION.
**********************
0000-MAINLINE.
MOVE +100 TO WS-BINARY-NUM.
MOVE WS-BINARY-NUM TO WS-DISPLAY-NUM.
MOVE WS-BINARY-NUM TO WS-EDITED-NUM.
DISPLAY 'WS-EDITED-NUM= ' WS-EDITED-NUM.
DISPLAY 'WS-DISPLAY-NUM = ' WS-DISPLAY-NUM.
DISPLAY 'WS-BINARY-NUM = ' WS-BINARY-NUM.
DISPLAY '********************************'.
'.
|
This way I moved and Displayed till +109.
Then I started with Negative numbers
Code: |
MOVE -100 TO WS-BINARY-NUM.
MOVE WS-BINARY-NUM TO WS-DISPLAY-NUM.
MOVE WS-BINARY-NUM TO WS-EDITED-NUM.
DISPLAY 'WS-EDITED-NUM= ' WS-EDITED-NUM.
DISPLAY 'WS-DISPLAY-NUM = ' WS-DISPLAY-NUM.
DISPLAY 'WS-BINARY-NUM = ' WS-BINARY-NUM.
DISPLAY '********************************'.
|
This Continued till -109.
Code: |
======================================
The sysout is as follows:
====================
WS-EDITED-NUM= +00100
WS-DISPLAY-NUM = 0010{
WS-BINARY-NUM = 00100
********************************
WS-EDITED-NUM= +00101
WS-DISPLAY-NUM = 0010A
WS-BINARY-NUM = 00101
********************************
It continued in the same way till 109..
Then for the negative numbers ..
WS-EDITED-NUM= -00100
WS-DISPLAY-NUM = 0010}
WS-BINARY-NUM = 0010}
********************************
WS-EDITED-NUM= -00101
WS-DISPLAY-NUM = 0010J
WS-BINARY-NUM = 0010J
********************************
|
Now the Questions are :
1. For the Edited Variables the Displays are okay
2. For the Display variable for the positive numbers why the displays are in Symbols and letters ? I am expecting that kind for the Binary variable but that didn't not happen ? Is it the way it is supposed to be displayed?
Now for the Negative numbers:
Both the Display and the Binary displays are in same format ? Why like that. If we need to know the actual value we always have to move this to edited variable and display it ?
Can some one let us know about this ?
Thanks.
Dhruva. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Wed Sep 15, 2004 2:47 pm Post subject: |
|
|
Dhruva,
A variable defined as pic S9(05) has a sign over punch. The over punch in hex format looks like this
Code: |
{ABCDEFGHI}JKLMNOPQR
CCCCCCCCCCDDDDDDDDDD
01234567890123456789
|
Hex C0 thru C9 are positive numbers and D0 thru D9 are negative numbers.
If you want the actual number to be displayed then you need to move the Numeric edited field and display it.
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
dhruva Beginner
Joined: 15 Sep 2004 Posts: 4 Topics: 2
|
Posted: Wed Sep 15, 2004 5:30 pm Post subject: |
|
|
Hi Kolusu,
{ABCDEFGHI}JKLMNOPQR
CCCCCCCCCCDDDDDDDDDD
01234567890123456789
Thanks for the Explanation. Then what about the binary variable display for the positive numbers ? Why they are displaying actual numbers for the Positive numbers and the same is not for the negative numbers ?
Can you please explain this also ?
[ |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Thu Sep 16, 2004 11:37 am Post subject: |
|
|
dhruva,
Binary(comp) or internal decimal(comp-3) items are converted to external decimal. Negative signed values cause a low-order sign overpunch
Internal floating-point numbers are converted to external floating-point numbers for display, such that:
A COMP-1 item will display as if it had an external floating-point PICTURE clause of -.9(8 )E-99
A COMP-2 item will display as if it had an external floating-point PICTURE clause of -.9(17)E-99
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
|
|