A scope terminator ends a verb or statement. Scope terminators can be explicit or implicit.
Explicit scope terminators:
Explicit scope terminators end a verb without ending a sentence. They consist of END followed by a hyphen and the name of the verb being terminated, such as END-IF.
Listed below some of the important explicit scope terminators.
END-ADD END-PERFORM END-ACCEPT END-CALL END-COMPUTE END-DELETE END-DISPLAY END-DIVIDE END-EVALUATE END-IF END-MULTIPLY END-READ END-RETURN END-REWRITE END-SEARCH END-START END-STRING END-SUBTRACT END-UNSTRING END-WRITE |
Implicit scope terminator:
An implicit scope terminator is a period (.) that ends the scope of all previous statements not yet ended.
Example:
Let see example below with both implicit and explicit scope terminators.
Implicit scope terminator:
IF ITEM = "A" DISPLAY "THE VALUE OF ITEM IS " ITEM ADD 1 TO TOTAL MOVE "C" TO ITEM DISPLAY "THE VALUE OF ITEM IS NOW " ITEM. ---> IF statement end here IF ITEM = "B" ADD 2 TO TOTAL. ---> IF statement end here |
Explicit scope terminator:
IF ITEM = "A" DISPLAY "THE VALUE OF ITEM IS " ITEM ADD 1 TO TOTAL MOVE "C" TO ITEM DISPLAY "THE VALUE OF ITEM IS NOW " ITEM END-IF ---> IF statement end here IF ITEM = "B" ADD 2 TO TOTAL END-IF ---> IF statement end here |
For improved program clarity and to avoid unintentional ending of statements, use explicit scope terminators, especially within paragraphs. Use implicit scope terminators only at the end of a paragraph or the end of a program.
Tips:
Be careful when coding an explicit scope terminator for an imperative statement that is nested within a conditional statement. Ensure that the scope terminator is paired with the statement for which it was intended. In the following example, the scope terminator will be paired with the second READ statement, though the programmer intended it to be paired with the first.
READ FILE1 AT END MOVE A TO B READ FILE2 END-READ |
To ensure that the explicit scope terminator is paired with the intended statement, the preceding example can be recoded in this way.
READ FILE1 AT END MOVE A TO B READ FILE2 END-READ END-READ |
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!