2000-PROCESS-ORDER-HEADER SECTION. STRT-PROCESS-ORDER-HEADER. PERFORM 4100-READ-SAINHDR03. IF WS-SAINHDR03-IS-AT-END GO TO EXIT-PROCESS-ORDER-HEADER END-IF. IF SIH3-INVOICE-DATE > WS-ENDING-DATE GO TO EXIT-PROCESS-ORDER-HEADER END-IF. IF NOT SIH3-INVOICE-ITEM GO TO STRT-PROCESS-ORDER-HEADER END-IF. MOVE SIH3-INVOICE-NUMBER TO SDR2-INVOICE-NUMBER. MOVE ZERO TO SDR2-ITEM-NUMBER. PERFORM 4200-START-SADTL02. IF WS-SADTL02-IS-AT-END GO TO STRT-PROCESS-ORDER-HEADER END-IF. PERFORM 2100-PROCESS-ORDER-DETAIL. GO TO STRT-PROCESS-ORDER-HEADER. EXIT-PROCESS-ORDER-HEADER. EXIT.
This section of code processes a file, and contains 5 GO TO statements. The first two GOTO's direct program flow to quit processing the file. The 3rd and 4th GOTO's Continue processing the file, but just skip the current record, and the last GOTO is what makes this block of code a loop.
The GOTO is mainly used to control looping. With that said I don't use GOTO's in Java, C++, etc... I think they are a bad habit for most new programmers to develop, and are not needed in most languages.