skip to main content

Procedure Division Statements : EXIT

EXIT
General Format
Format 1
Format 2
EXIT PROGRAM [ {RETURNING} {Literal-1   } ] 
               {GIVING   } {Identifier-1}
Format 3
EXIT PERFORM [CYCLE]
Format 4
EXIT {PARAGRAPH}
     {SECTION  }
Format 5
EXIT METHOD
Syntax rules
Format 1
1.
Format 2
2.
3.
4.
GIVING and RETURNING are synonymous.
5.
Format 3
6.
Format 4
7.
Format 5
8.
General Rules
Format 1
1.
Format 2
2.
3.
 
If the calling runtime element is a COBOL element, execution continues in the calling element as specified in the rules for the CALL statement. The state of the calling runtime element is not altered and is identical to that which existed at the time it executed the CALL statement except that the contents of data items and the contents of files shared between the calling runtime element and the called program may have been changed.
 
If the program in which the EXIT PROGRAM statement is specified is an initial program, an implicit CANCEL statement referencing that program is executed upon return to the calling runtime element.
Format 3
4.
5.
Format 4
6.
 
NOTE - The return mechanisms mentioned in the rules for EXIT PARAGRAPH and EXIT SECTION are those associated with language elements such as PERFORM, SORT and USE.
7.
Format 5
8.
Examples
Format 1 - Exit placed at the end of a paragraphs block
procedure division.
     perform elab-1 thru elab-1-exit.
     goback.
     add 1 to w-item.
Format 2 - Exit the program
exit program
Format 3 - Exit a perform loop
perform until 1 = 1 *> Would be infinite loop
  read customers next 
       at end exit perform *> Loop is ended here
  end-read
  display cust-code cust-name 
Format 4 - Exit a paragraph
  if ws-amount not > 0
     exit paragraph
  end-if
  compute ws-interest = ws-amount * ws-rate / 100 / 12
  move ws-interest to loan-interest
Format 5 - Exit a method at the first valid condition
method-id. check-age as "checkAge".
working-storage section.
77 age-range pic 9.
88 invalid-age value 0.
88 is-child    value 1.
88 is-teen     value 2.
88 is-adult    value 3.
linkage section.
77 age pic 9(3).
procedure division using age returning age-range.
   if age = 0
      set invalid-age to true
      exit method
   end-if
   if age > 0 and age < 14
      set is-child to true
      exit method
   end-if
   if age > 13 and age < 20
      set is-teen to true
      exit method
   end-if
   if age > 19 
      set is-adult to true
   end-if
   goback.
 end method.

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left