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: 7279

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: 7279

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 2 byte YEAR from Y'DATE2' field tecnokrat DFSORT/ICETOOL 2 Tue Feb 07, 2017 12:05 pm
No new posts Sort two file having same field, one ... himanshu malik DFSORT/ICETOOL 7 Thu Feb 02, 2017 10:09 am
No new posts resume binary ftp in z/os meykh2014 All Other Mainframe Topics 6 Sun Jan 22, 2017 10:01 am
No new posts INVALID FIELD OR CONSTANT IN SORTOF ?? Ron Klop DFSORT/ICETOOL 8 Wed Jan 11, 2017 3:44 pm
No new posts Difference between TWALENG and TWASIZE Arunkumar Chandrasekaran CICS 3 Tue Jan 03, 2017 12:57 pm


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