PROCEDURE DIVISION - IBM Mainframe

In the Procedure Division, you code the executable statements that process the data you have defined in the other divisions. The Procedure Division contains the logic of your program.
The Procedure Division begins with the division header and a procedure-name header. It is divided into sections, paragraphs, sentences, and statements:

  • A section is a logical subdivision of your processing logic. A section can contain several paragraphs.
  • A paragraph subdivides a section, procedure, or program. It contains a set of related statements that provide a function and is one of the basic building blocks of a structured program. A paragraph can be the subject of the PERFORM statement.
  • A sentence is a series of one or more COBOL statements, ending with a period. Many structured programs do not have separate sentences. Each paragraph can contain one sentence. Using scope terminators instead of periods to show the logical end of the scope of a statement is preferred.
  • A statement performs a defined step of COBOL processing, such as adding two numbers. A statement is a valid combination of words, beginning with a COBOL verb.

In structured programming, the language implementation techniques in COBOL apply to the Procedure Division. In the VS COBOL II language, there are four categories of statements:

  • Imperative statements - An imperative statement specifies that an unconditional action is to be taken. The statements in the following table are imperative when they are used without any conditional phrases (such as ON EXCEPTION, NOT ON EXCEPTION, AT END, NOT AT END, and so on). Additionally, conditional statements that are terminated by their explicit scope terminators are classified as imperative. Some examples of imperative statements are:
  • Arithmetic statements (ADD, COMPUTE, DIVIDE, MULTIPLY, SUBTRACT, etc.)
  • Data-manipulation statements (ACCEPT, INITIALIZE, MOVE, SET, STRING, etc.)
  • Procedure-branching statements (CALL, EXIT, GO TO, PERFORM, STOP, etc.)
  • I/O statements (ACCEPT, CLOSE, DELETE, OPEN, DISPLAY, READ, WRITE, etc.)
  • Miscellaneous (CANCEL, CONTINUE, ENTRY, MERGE, SORT, RETURN, etc.)
  • Conditional statement - A conditional statement is either a simple conditional statement (IF, EVALUATE, SEARCH) or a conditional statement made up of an imperative statement that includes a conditional phrase or option. For example, an arithmetic statement without ON SIZE ERROR is an imperative statement. But an arithmetic statement with the conditional option ON SIZE ERROR and without a scope terminator is a conditional statement. Data-manipulation statements or CALL statements with ON OVERFLOW and I/O statements with INVALID KEY, AT END, AT END-OF-PAGE or RETURN with AT END and without a scope terminator are all conditional statements. For additional program control, the NOT phrase can also be used with conditional statements. For example, you can provide instructions to be performed when a particular exception does not occur, such as, NOT ON SIZE ERROR. The NOT phrase cannot be used with the ON OVERFLOW phrase of the CALL statement, but can be used with the ON EXCEPTION phrase.
  • Compiler-directing statements - A compiler-directing statement is not part of the program logic. Compiler-directing statements inform the compiler about the program structure, copy processing, listing control, and control flow. Some examples of compiler directing statements are BASIS, CBL, CONTROL, COPY, DELETE, EJECT, ENTER, INSERT, REPLACE, SERVICE LABEL, SKIP1, SKIP2, SKIP3, TITLE, USE, etc.
  • Delimited scope statements - In general, a delimited scope statement uses an explicit scope terminator to turn a conditional statement into an imperative statement; the resulting imperative statement can then be nested. Explicit scope terminators can also be used, however, to terminate the scope of an imperative statement and clearly <end the statement. Because a period implicitly terminates the scope of all previous statements, do not use a period within a delimited scope statement.

Scope Terminators

Unless specified otherwise, a delimited scope statement can be specified wherever an imperative statement is allowed by language rules. Use a delimited scope statement to delimit the range of operation for a COBOL conditional statement and to explicitly show the levels of nesting. For example, use an END-IF instead of a period to terminate the scope of an IF statement within a nested IF. Use a delimited scope statement if you want to code a conditional statement where the COBOL syntax calls for an imperative statement. For example, code a conditional statement as the object of an in-line PERFORM:

Scope Terminators

Scope Terminators

An explicit scope terminator is required for the in-line PERFORM statement, but is invalid for the out-of-line PERFORM statement.

Using Nested Delimited Scope Statements

When nested within another delimited scope statement with the same verb, each explicit scope terminator ends the statement begun by the most recently preceding (and as yet unpaired) occurrence of that verb. Be careful when coding an explicit scope terminator for an imperative statement that is nested within a conditional statement. You must 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 instead of the first:

Scope Terminators

To ensure that the explicit scope terminator is paired with the intended statement, the preceding example can be re-coded in one of the following ways:

scope terminator is paired with the intended statement

Explicit Scope Terminators

An explicit scope terminator marks the end of certain Procedure Division statements. Explicit scope terminators can be used with both the conditional and imperative forms of these statements. The following are explicit scope terminators:

Explicit Scope Terminators

Explicit Scope Terminators

Implicit Scope Terminators

An implicit scope terminator is a period (.) that terminates the scope of all previous statements not yet terminated. An un-terminated conditional statement cannot be contained by another statement. Except for nesting statements with IF statements nested statements must be imperative statements and must follow the rules for imperative statements. You should not nest conditional statements. An example of using implicitly terminated statement is given below:

Implicit Scope Terminators

Each of the two periods in this preceding example terminate the IF statements, making the code equivalent to the following example which has explicit scope terminators:

code equivalent to the following

Explicit scope terminators make a program easier to understand and prevent the unintentional termination of statements that an implicit terminator can cause. For instance, changing the location of the first period in the first implicit scope example changes the meaning of the code:

code equivalent to the following

In this case, the following two statements will be executed regardless of the value of ITEM, despite what the indentation indicates, because the first period terminates the IF statement.

  • MOVE ‘C’ TO ITEM
  • DISPLAY ‘VALUE OF ITEM IS NOW’ ITEM

For improved program clarity and to avoid unintentional termination of statements, you should use explicit scope terminators instead of implicit scope terminators, especially within paragraphs. You should only use implicit scope terminators at the end of a paragraph or the end of the program.
Scope of Statements

Statements that include explicit scope terminators are called delimited scope statements. When statements are nested within other statements, a separator period that terminates the sentence also terminates all nested statements. When a delimited scope statement is nested within another delimited scope statement with the same verb, each explicit scope terminator terminates the statement initiated by the most recent, and as yet un-terminated, occurrence of that verb. For statements nested within statements allowing optional conditional phrases, any optional conditional phrase encountered is considered the nearest proceeding un-terminated statement. If no phrase has been associated with it, then it can be associated with the scope terminator.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IBM Mainframe Topics