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

Difference between a field Binary COMP and COMP-5


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

New User


Joined: 27 Aug 2008
Posts: 35
Location: Brazil

PostPosted: Tue Apr 14, 2015 3:39 am
Reply with quote

Hi guys,
What's the difference between a field Binary COMP and COMP-5 in COBOL?
Thanks!
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7311
Location: Inside the Matrix

PostPosted: Tue Apr 14, 2015 5:10 am
Reply with quote

COMP, or COMP-4 or BINARY (they are all the same, COMP-4 and BINARY are just aliases of COMP) has maximum values limited by the PICture.

COMP PIC 9 has a value 0-9, COMP PIC S9(4) has a value -9999-+9999.

The PICture also defines the amount of storage occupied. 0-4 digits, a halfword, 5-9 digits a fullword, any bigger a doubleword.

COMP, COMP-4 and BINARY do truncation to PICture, decimal truncation.

COMP-5 is "native binary". What this means is that the number of digits in the PICture define the amount of storage, but the value which can be contained is limited only by the bit-settings of the field (and whether signed or not), not by the PICture.

COMP-5 PIC 9 can hold a value 0-65535. COMP-5 PIC S99 can hold a value -32768-+32767.

COMP-5 does truncation to field-size, binary truncation.

Compiler option TRUNC with (BIN) will treat all binary fields (COMP, COMP-4, BINARY) as "native binary" (COMP-5).

Generally more instructions are generated for COMP-5 than for the others.

Use COMP-5 if the field can contain values beyond the PICture (CICS or SQL or JAVA fields).

Don't mess with the compiler option TRUNC, as it can change program behaviour. A change to that option has to be analysed and tested, just like any program change.
Back to top
View user's profile Send private message
jackare

New User


Joined: 27 Aug 2008
Posts: 35
Location: Brazil

PostPosted: Tue Apr 14, 2015 5:48 am
Reply with quote

Bill Woodger wrote:
COMP, or COMP-4 or BINARY (they are all the same, COMP-4 and BINARY are just aliases of COMP) has maximum values limited by the PICture.

COMP PIC 9 has a value 0-9, COMP PIC S9(4) has a value -9999-+9999.

The PICture also defines the amount of storage occupied. 0-4 digits, a halfword, 5-9 digits a fullword, any bigger a doubleword.

COMP, COMP-4 and BINARY do truncation to PICture, decimal truncation.

COMP-5 is "native binary". What this means is that the number of digits in the PICture define the amount of storage, but the value which can be contained is limited only by the bit-settings of the field (and whether signed or not), not by the PICture.

COMP-5 PIC 9 can hold a value 0-65535. COMP-5 PIC S99 can hold a value -32768-+32767.

COMP-5 does truncation to field-size, binary truncation.

Compiler option TRUNC with (BIN) will treat all binary fields (COMP, COMP-4, BINARY) as "native binary" (COMP-5).

Generally more instructions are generated for COMP-5 than for the others.

Use COMP-5 if the field can contain values beyond the PICture (CICS or SQL or JAVA fields).

Don't mess with the compiler option TRUNC, as it can change program behaviour. A change to that option has to be analysed and tested, just like any program change.



Thanks, Woodger
Back to top
View user's profile Send private message
jerryte

Active User


Joined: 29 Oct 2010
Posts: 195
Location: Toronto, ON, Canada

PostPosted: Tue Apr 14, 2015 5:58 pm
Reply with quote

I always use COMP-5 for binary fields. The compile will generate it as a 2 byte halfword or 4 byte fullword and treat it as native binary. Also this option is not affected by the TRUNC compiler option. I see no practical reason to use COMP or BINARY.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7311
Location: Inside the Matrix

PostPosted: Tue Apr 14, 2015 6:51 pm
Reply with quote

I only use COMP-5 when necessary :-)

The important thing is that one definition is not used in one place, and another definition in another place, whether within a program, across programs, across systems, or on files or other means of data transfer.

TRUNC(BIN) is a way to get everything treated as COMP-5. Generally, there is a performance degradation with COMP-5. The larger the field (half- faster than full- faster than double-word), the bigger the hit.

Remember that COMP-5 will do no decimal truncation:

Code:
01  a-field PIC 9(5).
01  a-native-binary COMP-5 PIC 99.
01  a-decimal-binary COMP PIC 99.


With TRUNC(STD)

Code:
MOVE a-field TO a-native-binary
              a-decimal-binary


Will get you different results if the value of a-field is greater than 99.

With TRUNC(OPT) don't ever code to do truncation like that.
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
This topic is locked: you cannot edit posts or make replies. Passing a field name to COBOL program COBOL Programming 10
No new posts BMS map length field greater than zero CICS 3
No new posts Break a record into fields, each fiel... SYNCSORT 2
No new posts SYNCSORT Error - CONTROL FIELD BEYOND... SYNCSORT 10
No new posts Unable to display comp variable COBOL Programming 4
Search our Forums:

Back to Top