Mainframe COBOL COMPUTE TRUNC Query
<p>I wonder why there is different in the result for those two cases.</p>

<p>Working Storage:</p>

<pre><code>WS-SUM-LEN PIC S9(4) COMP. 
WS-LEN-9000   PIC 9(5) VALUE 9000.
WS-TMP-LEN    PIC 9(5).
WS-FIELD-A    PIC X(2000).
</code></pre>

<p>Case 1) <code>COMPUTE WS-SUM-LEN = WS-LEN-9000 + LENGTH OF WS-FIELD-A</code></p>

<p>Result: WS-SUM-LEN = 1000</p>

<p>Case 2) </p>

<pre><code>MOVE LENGTH OF WS-FIELD-A TO WS-TMP-LEN
COMPUTE WS-SUM-LEN = WS-LEN-9000 + WS-TMP-LEN
</code></pre>

<p>Result: WS-SUM-LEN = 11000</p>

<p>The compiler option is TRUNC(OPT). Why there is no trunc occur for case 2?</p>