View previous topic :: View next topic
|
Author |
Message |
sureshmurali Warnings : 1 New User
Joined: 25 Nov 2010 Posts: 70 Location: Sivakasi, India
|
|
|
|
Hi
I have tried the following program to test for BINARY, COMP, COMP-4 and COMP-5.
IDENTIFICATION DIVISION.
PROGRAM-ID. PRGM1.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 GRP10.
05 VAR1 PIC 9(4).
05 VAR2 REDEFINES VAR1 PIC 9(4) BINARY.
05 VAR3 REDEFINES VAR1 PIC 9(4) COMP.
05 VAR4 REDEFINES VAR1 PIC 9(4) COMP-4.
05 VAR5 REDEFINES VAR1 PIC 9(4) COMP-5.
PROCEDURE DIVISION.
MOVE 1234 TO VAR1.
DISPLAY VAR1 " " VAR2 " " VAR3 " " VAR4 " " VAR5.
STOP RUN.
Output I got is :
VAR1 " " VAR2 " " VAR3 " " VAR4 " " VAR5.
1234 1938 1938 1938 61938
From this BINARY, COMP and COMP-4 are same.
Why the values are changing between the binary types and DISPLAY type eventhough the organization of data is different in the memory?
For DISPLAY Usage , the value is 1234
For Binary types(BINARY, COMP, COMP4), the value becomes 1938.
Why 1234 is different in the binary type?
Please clarify. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello and welcome to the forum,
Suggest you look at the length of each variable in the compiler output.
Even though you specified "redefines", the result is not a complete redefinition. . .
You need to spend some time in the cobol manual reading about how numeric fields are defined. There is a link to "IBM Manuals" at the top of the page and the COBOL manuals are the first group. . . |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
Why 1234 is different in the binary type? |
Because of the way you defined your variables, and the way COBOL stores data internally. If you want to know more details, they are all completely explained in the COBOL manuals as Dick mentioned. This topic also comes up quite frequently on this forum, so searching the forum would also provide you with many good answers. |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
Internal representation of VAR1 is x'F1F2F3F4'
When you display VAR1 you get the character representation of the four digits, as expected.
The other variables are displaying the same storage, but represented as the decimal equivalent of the bitpattern. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Kjeld,
Quote: |
The other variables are displaying the same storage, but represented as the decimal equivalent of the bitpattern. |
A bit of qualification:
The other variables are displaying only the first part of the same storage
d |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
dick scherrer wrote: |
Hi Kjeld,
Quote: |
The other variables are displaying the same storage, but represented as the decimal equivalent of the bitpattern. |
A bit of qualification:
The other variables are displaying part of the same storage
d |
Thanks Dick,
Yes shure, it's only the 2 first bytes that gets interpreted, those that contains x'F1F2'. |
|
Back to top |
|
|
|