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
 

 

Difference between a field Binary COMP and COMP-5

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
jackare

New User


Joined: 27 Aug 2008
Posts: 32
Location: Brazil

PostPosted: Tue Apr 14, 2015 3:39 am    Post subject: Difference between a field Binary COMP and COMP-5
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Tue Apr 14, 2015 5:10 am    Post subject: Reply to: COMP-5 vs COMP
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: 32
Location: Brazil

PostPosted: Tue Apr 14, 2015 5:48 am    Post subject: Re: Reply to: COMP-5 vs COMP
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: 183
Location: Toronto, ON, Canada

PostPosted: Tue Apr 14, 2015 5:58 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Tue Apr 14, 2015 6:51 pm    Post subject: Reply to: COMP-5 vs COMP
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    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 Performing arithmetic on input field zh_lad DFSORT/ICETOOL 4 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Amount field is getting corrupted whe... thesumitk SYNCSORT 5 Tue Oct 18, 2016 8:20 pm


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