Skip to content

STOP Statement

The STOP statement terminates the current program.

Format 1

       STOP RUN [ {RETURNING} numeric-1 ] 
                  {GIVING }

Syntax:

numeric-n is a literal or data item that is numeric.

General Rules:

  1. A Format 1 STOP RUN statement terminates the program, optionally returning a return code to the operating system. Any OPEN files are CLOSE'd.
  2. In the Format 1 STOP RUN statement, the RETURNING/GIVING clause returns the value of numeric-1 to the operating system through the special return-code register.
  3. RETURNING and GIVING are synonyms.

Code Sample:

       IDENTIFICATION DIVISION. 
       PROGRAM-ID. STOP-1. 
       ENVIRONMENT DIVISION. 
       DATA DIVISION. 
       WORKING-STORAGE SECTION. 
       77 NUMERIC-1 PIC 9 VALUE 1. 
       77 DUMMY PIC X. 
       PROCEDURE DIVISION. 
       MAIN. 
      *FORMAT 1 
      *STOP RUN [ {RETURNING} NUMERIC ] 
      *           {GIVING } 
              EVALUATE DUMMY 
                     WHEN "A" 
                            STOP RUN 
                     WHEN "B" 
                            STOP RUN RETURNING NUMERIC-1 
                     WHEN "C" 
                            STOP RUN GIVING NUMERIC-1 
                     WHEN "D" 
                            STOP RUN RETURNING 1 
                     WHEN "E" 
                            STOP RUN GIVING 1 
                     WHEN OTHER 
                            CONTINUE 
              END-EVALUATE. 

              DISPLAY "STOP-1 FINISHED!" LINE 15 COL 10. 
              ACCEPT DUMMY LINE 15 COL 30. 
              STOP RUN.
Back to top