Compute: Warn when low-order truncation occurs

I have a result field specified as

01 MY-RESULT VALUE +0 USAGE COMP-3 PIC S9(13)V99

Imagine I multiply two factors:

COMPUTE MY-RESULT = A * B

What is the best way to detect low-order truncation in MY-RESULT? E.g. when A=B=2.01.

The ON SIZE ERRORclause is not triggered.


ANSWERS:


Something that will work with all vendors and even the oldest compilers (as you did not specified any dialect the seems to be the most important part): if it matters use an additional target field with more decimal positions and check for equality afterwards:

COMPUTE MY-RESULT RESULT-WITH-MORE-DECIMALS = A * B
IF MY-RESULT NOT = RESULT-WITH-MORE DECIMALS
   ...
END-IF

ON SIZE ERROR will only be tracked for the upper truncation.

If this 2014 feature os available for your compiler you could use the INTERMEDIATE ROUNDING IS PROHIBITED (the draft had it in as ROUNDED-MODE PROHIBITED) which will show you this problem (if EC-SIZE-TRUNCATION exception is enabled). Beware of one part: this is an exception with a "fatal" category...



 MORE:


 ? How to specify default file extension for Oracle's Pro*COBOL precompiler
 ? File status 23 on READ after START
 ? Microfocus cics xctl commarea
 ? Microfocus cics xctl commarea
 ? Microfocus cics xctl commarea
 ? How CICS shared memory works?
 ? Why 0 is being appended at the end for the values taken from cics
 ? CICS - Updates by Multiple users
 ? Pagination logic in Mainframe CICS
 ? How to reference passed record address in CICS COBOL program?