Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Compare COMP BINARY COMP4 and DISPLAY with eg sample program

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Compare COMP BINARY COMP4 and DISPLAY with eg sample program
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

Site Director


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

PostPosted: Thu Dec 16, 2010 10:23 pm    Post subject:
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

Site Director


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

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

Follow on:

We also have a separate forum for Students and Freshers that may be more appropriate:
http://www.ibmmainframeforum.com/index.php
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8121
Location: East Dubuque, Illinois, USA

PostPosted: Thu Dec 16, 2010 10:26 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Thu Dec 16, 2010 10:30 pm    Post subject: Reply to: Compare COMP BINARY COMP4 and DISPLAY with eg samp
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    Post subject: Re: Reply to: Compare COMP BINARY COMP4 and DISPLAY with eg
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Writing a file using online program grvtomar PL/I & Assembler 3 Fri Jun 30, 2017 1:06 pm
No new posts pre-compiler for program in an HFS Pedro DB2 0 Fri Jun 23, 2017 11:13 pm
No new posts Display upon console bipinpeter COBOL Programming 1 Thu Jun 22, 2017 12:35 am
No new posts compare 2 rows within the same file ram_vizag SYNCSORT 7 Wed Jun 14, 2017 12:34 am
No new posts Compiling program in endeavor for tra... RALAKKAL Compuware & Other Tools 4 Mon Jun 05, 2017 8:27 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us