From my understanding when using UNSTRING, the use of ON OVERFLOW [INSTRUCTION] will be useful if there would be an overflow in the use of the UNSTRING.
But if there is no overflow, why would you use NOT ON OVERFLOW [INSTRUCTION] ?
The only possible utility to the NOT ON OVERFLOW [INSTRUCTION] would be to pass an instruction if there is no overflow but what would be the use of that if you already had the expected result from the UNSTRING ?
Is there any concrete example of how this could be useful in this example :
IDENTIFICATION DIVISION.
PROGRAM-ID. YOUR-PROGRAM-NAME.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 WS-VAR1 PIC A(11) VALUE "Hello World".
01 WS-VAR2 PIC A(5).
01 WS-VAR3 PIC A(5).
01 WS-COMPTEUR PIC 9 VALUE 2.
PROCEDURE DIVISION.
MAIN-PROCEDURE.
INTO WS-VAR2 WS-VAR3
WITH POINTER WS-COMPTEUR
ON OVERFLOW DISPLAY "This string is too large"
END-UNSTRING.
DISPLAY WS-VAR2
DISPLAY WS-VAR3.
STOP RUN.
END PROGRAM YOUR-PROGRAM-NAME.
Even when I read IBM documentation, it doesn't give me much explanation as to what could be used in this instance but to display a message ?
IBM Documentation : link
In COBOL 74 there was no
NOT ON OVERFLOWphrase. Therefore, it was necessary to use either aGO TOstatement or set a flag for testing in an immediately followingIFstatement. TheNOT ON OVERFLOWphrase andEND-UNSTRINGwere added in COBOL 85 to to improve program structure.For your example, I made some changes to first display
WS-VAR1then the result of theUNSTRING. Note that theOVERFLOWcondition concerns the number of items and not the length of the text. I ran three tests to show the resultsResults:
As may be seen in the code,
ON OVERFLOWis used for error processing;NOT ON OVERFLOWis used for normal processing. Without the improved structure fromNOT ON OVERFLOW, normal processing would immediately follow the error processing, unless one used the previously mentioned COBOL 74 type processing.Note that
DELIMITED ALL SPACEgives a different result than that shown for one case, above. [Ignore the--]