OK, "native binary" first.
The "problem" with native-binary is the performance. The performance is improved with V5+, as the dread divide (and associated code) is only done now when needed. It still "looks" like a lot of code, but some of the code will only be executed when needed, and assuming that no actual overflow occurs, will never be executed. So that's very good.
There's a very useful discussion of this in Chapter 8. Coding techniques to get the most out of V6 in the V6 Performance Tuning Guide, although I'm wondering if there is a typo in and other references to COMP-5.
COMP-5 is not always slower than STD/OPT:
Although TRUNC(BIN) enables more efficient code when storing out a COMPUTE or MOVE result it continues to significantly harm the performance when these data items are used as input to arithmetic statements (as the compiler must assume the max 2,4,8 byte size). V6 optimizes the correction code for TRUNC(STD) so the performance benefit of TRUNC(BIN) has been reduced slightly.
In specific cases where data naturally exceeds the PICture (CICS, DB2, "integer" data from programming languages with that) then use COMP-5 for the relevant fields. Specifying TRUNC(BIN) just applies COMP-5 to all BINARY types, and whilst you have all the digits you may need, you have also affected the performance of everything which doesn't need the extra digits (beyond the PICture).
Neither TRUNC(OPT) not TRUNC(STD) affect COMP-5 fields.
This:
TRUNC(STD) instructs the compiler to always correct back to the specified PICTURE clause and allows the compiler to assume that loaded values only have the specified number of PICTURE clause digits.
Indicates the importance of knowing that you source field conforms to PICture unless using COMP-5. As with USAGE DISPLAY and PACKED-DECIMAL the compiler does not generate code to truncate the source, only the target/receiving field. The compiler assumes that COBOL code generated by the compiler has created all source fields that it uses. If an original source value does not conform to PICture, whether using OPT or STD, then "interesting" things will/may occur.
So, no, except for "moves" (there may be other exceptions, I don't know, but maths is bad and ADD 1 is maths) the generated code for COMP-5/TRUNC(BIN)/native-binary is not optimal.
When I say "use COMP-5 when needed" I mean "use COMP-5 when that source value can, by design, exceed the PICture of a COBOL binary field of that byte-size".
Of course, you are free to use COMP-5 for everything, or to use TRUNC(BIN). You just have to accept the performance hit. I know of two sites who changed from TRUNC(BIN) to TRUNC(OPT) and were very happy with the results (in terms of reduced running costs). That is not an easy change to make either. It needs care. Anything that requires the BIN must be changed to COMP-5.
With your TRUNC(OPT) example, you just can't do that. It immediately breaks the contract with the compiler, and the results are all your own fault. You can't promise not to exceed the bits set for the maximum value represented by the PICture, and then complain when you do that :-)
With the new names, it multiplies the issue with native-binary. On the positive side, it would allow access to a one-byte binary, but since there's no machine instruction that does direct maths on a one-byte binary, the compiler would end up doing what we do already ("pretend" it is a half-word and put the one byte in the first or second byte, ensuring the other is zero).
Would it make the code more portable? Not really, since it is down to the implementor to define how those descriptions are stored.
Yes, the ON SIZE ERROR is an issue. I can't recommend using it with COMP-5 at all :-)
However, if IBM were to "fix" it, how many programs would "break"? We can't even begin to guess.
I always make sure my fields are big enough, and don't use ON SIZE ERROR (subject to site standards, of course...).
BillWoodger