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

Compare COMP BINARY COMP4 and DISPLAY with eg sample program


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sureshmurali
Warnings : 1

New User


Joined: 25 Nov 2010
Posts: 70
Location: Sivakasi, India

PostPosted: Thu Dec 16, 2010 10:12 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Dec 16, 2010 10:23 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Dec 16, 2010 10:25 pm
Reply with quote

Follow on:

We also have a separate forum for Students and Freshers that may be more appropriate:
www.ibmmainframeforum.com/index.php
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: Thu Dec 16, 2010 10:26 pm
Reply with quote

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
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Dec 16, 2010 10:27 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Dec 16, 2010 10:30 pm
Reply with quote

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 icon_wink.gif

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

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Dec 17, 2010 2:55 pm
Reply with quote

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 icon_wink.gif

d

Thanks Dick,
Yes shure, it's only the 2 first bytes that gets interpreted, those that contains x'F1F2'.
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 0
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Using API Gateway from CICS program CICS 0
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts DB2 Event passed to the Application P... DB2 1
Search our Forums:

Back to Top