Procedure Division [ Micro Focus COBOL Language Reference ] MPE/iX 5.0 Documentation
Micro Focus COBOL Language Reference
Procedure Division
The Procedure Division can contain declarative and non-declarative
procedures in a program defintion; it must not contian any declarative or
nondeclarative procedures in a call prototype (MF only).
Organization
Declarative sections must be grouped at the beginning of the Procedure
Division preceded by the key word DECLARATIVES and followed by the key
words END DECLARATIVES. (See the section The USE Statement in the
chapters Program Definition, and Debug Module in your Language Reference
- Additional Topics.)
Structure
A procedure is composed of a paragraph, a group of successive paragraphs,
a section, or a group of successive sections within the Procedure
Division. A procedure-name is a word used to refer to a paragraph or
section in the source program in which it occurs. It consists of a
paragraph-name (which can be qualified) or a section-name.
The end of the Procedure Divisionand the physical end of the program is
that physical position in a COBOL source program after which no further
procedures appear , or the occurrence of the END PROGRAM header,
whichever occurs first, (ANS85 only)
A section consists of a section header followed by zero, one, or more
successive paragraphs. A section ends immediately before the next
section, at the end of the Procedure Division or at the key words END
DECLARATIVES in the declaratives portion of the Procedure Division.
For MF, OSVS and VSC2 only: A section can consist of sentences that
are not in paragraphs.
A paragraph consists of a paragraph-name followed by a period and a
space, and by zero, one, or more successive sentences. A paragraph ends
immediately before the next paragraph-name or section-name, at the end of
the Procedure Division or at the key words END DECLARATIVES in the
declaratives portion of the Procedure Division.
A sentence consists of one or more statements and is terminated by a
period followed by a space.
A statement is a syntactically valid combination of words and symbols
beginning with a COBOL verb.
The term "identifier" is defined as the word or words necessary to make
unique reference to a data item.
Execution
Execution begins with the first statement of the Procedure Division,
excluding declaratives. Statements are then executed in the order in
which they occur in the source program, except where the rules indicate
some other order.
General Formats.
PROCEDURE DIVISION Header.
The Procedure Divisionis identified by and must or may (MF only) begin
with one of the following headers:
Format 1.
Format 2 (MF).
Procedure Division Body.
The Procedure Division must conform to one of the following formats:
Format 1.
Format 2.
Statements and Sentences
There are four types of statements:
1. Conditional statements.
2. COBOL system directing statements.
3. Imperative statements.
4. For ANS85 only: Delimited scope statements.
There are three types of sentences:
1. Conditional sentences.
2. COBOL system directing sentences.
3. Imperative sentences.
Conditional Statement.
A conditional statement specifies that the truth value of a condition is
to be determined and that the subsequent action of the object program is
dependent on this truth value. A conditional statement is one of the
following:
* An EVALUATE (ANS85), IF, SEARCH or RETURN statement
* A READ statement that specifies the AT END or INVALID KEY phrase
* For OSVS only: An ON statement.
* A WRITE statement that specifies the INVALID KEY or END-OF-PAGE
phrase
* A START, REWRITE or DELETE statement that specifies the INVALID
KEY phrase
* An arithmetic statement (ADD, COMPUTE, DIVIDE, MULTIPLY, SUBTRACT)
that specifies the SIZE ERROR phrase
* A RECEIVE statement that specifies a NO DATA phrase
* A STRING or UNSTRING statement that specifies the ON OVERFLOW
phrase
* A CALL statement that specifies the ON OVERFLOW or ON EXCEPTION
(ANS85) phrase
* For MF and XOPEN only: An ACCEPT or DISPLAY statement that
specifies the ON EXCEPTION phrase.
Conditional Sentence.
A conditional sentence is a conditional statement, optionally preceded by
an imperative statement, terminated by a period followed by a space.
The COBOL System-Directing Statement.
A COBOL system-directing statement consists of a directing verb and its
operands. The directing verbs are:
COPY (See the section COPY Statement in the chapter
Compiler-Directing Statements.)
ENTER (See the section ENTER Statement in the chapter Program
Definition.)
REPLACE For ANS85 only: (See the section REPLACE Statement in the
Compiler-Directing Statements.)
USE (See the section USE Statement in the chapter Program
Definition.)
BASIS For OSVS and VSC2 only: (See the section BASIS Mechanism
in the chapter Compiler-Directing Statements
DELETE For OSVS and VSC2 only: (See the section BASIS Mechanism
in the chapter Compiler-Directing Statements
INSERT For OSVS and VSC2 only: (See the section BASIS Mechanism
in the chapter Compiler-Directing Statements
EJECT For MF, OSVS and VSC2 only: (See the section EJECT
Statement in the chapter Compiler-Directing Statements.)
SKIP1 For MF, OSVS and VSC2 only: (See the section SKIP1
Statement in the chapter Compiler-Directing Statements.)
SKIP2 For MF, OSVS and VSC2 only: (See the section SKIP2
Statement in the chapter Compiler-Directing Statements.)
SKIP3 For MF, OSVS and VSC2 only: (See the section SKIP3
Statement in the Compiler-Directing Statements.)
TITLE For MF and VSC2 only: (See the section TITLE Statement in
the chapter Compiler-Directing Statements.)
++INCLUDE For OSVS and VSC2 only: (See the section ++INCLUDE
Statement in the chapter Compiler-Directing Statements.)
-INC For OSVS and VSC2 only: (See the section -INC Statement in
the chapter Compiler-Directing Statements.)
$DISPLAY For MF only: (See the section $DISPLAY with Conditional
Compliation Statement in the chapter Compiler-Directing
Statements.
$ELSE For MF only: (See the section $ELSE with Conditional
Compliation Statement in the chapter Compiler-Directing
Statements.
$END For MF only: (See the section $END with Conditional
Compliation Statement in the chapter Compiler-Directing
Statements.
$IF For MF only: (See the section $IF with Conditional
Compliation Statement in the chapter Compiler-Directing
Statements.
A COBOL system directing statement causes your COBOL system to take a
specified action during creation of the object code.
The COBOL System-Directing Sentence.
A COBOL system-directing sentence is a single directing statement
terminated by a period followed by a space.
Imperative Statement.
An imperative statement indicates a specific unconditional action to be
taken by the object program. An imperative statement is any statement
that is neither a conditional statement nor a COBOL system directing
statement. An imperative statement can consist of a sequence of
imperative statements, each possibly separated from the next by a
separator.
The imperative verbs are:
ACCEPT(1) ENABLE RELEASE
ADD(2) EXIT REWRITE(3)
ALTER GO TO SEND
CALL(4) INSPECT SET
CANCEL MERGE SORT
CLOSE MOVE START(3)
COMPUTE(2) MULTIPLY(2) STOP
DELETE(3) OPEN STRING(4)
DISABLE PERORM SUBTRACT(2)
DISPLAY(1) READ(5) UNSTRING(4)
DIVIDE(2) RECEIVE(6) WRITE(7)
(1) Without the optional ON EXCEPTION phrase
(2) Without the optional SIZE ERROR phrase
(3) Without the optional INVALID KEY phrase
(4) Without the optional ON OVERFLOW or ON EXCECPTION phrase.
(5) Without the optional AT END phrase or INVALID KEY phrase.
(6) Without the optional NO DATA phrase.
(7) Without the optional INVALID KEY phrase or END-OF-PAGE phrase.
For ANS85 only: The ANSI'85 inperative verbs are:
CONTINUE INITIALIZE PURGE
For OSVS only: The OS/VS imperative verbs are:
EXAMINE GOBACK TRANSFORM
EXHIBIT
For VSC2 only: The VS COBOL II imperative verb is:
GOBACK
For MF only: The additional imperative verbs available to this COBOL
system are:
CHAIN EXHIBIT GOBACK
NEXT SENTENCE
When "imperative-statement" appears in the general format of statements,
"imperative-statement" refers to that sequence of consecutive imperative
statements that must be ended by a period or by any phrase associated
with a statement containing that "imperative-statement".
For OSVS only: Either the connective word "THEN" or the connective word
"AND" can optionally be placed between any two imperative statements
which appear in a single sequence of imperative statements.
Imperative Sentence.
An imperative sentence is an imperative statement terminated by a period
followed by a space.
For ANS85 only: Delimited Scope Statements.
A delimited scope statement is a statement (for example, an IF statement)
which is terminated by (that is, has its end-point determined by) a
matching explicit scope terminator (in this case END-IF). Thus, all the
statements between a delimited scope statement and its paired explicit
scope terminator are deemed to be contained within that delimited scope
statement.
Delimited scope statements can be nested, in which case each explicit
scope terminator encountered in the program is considered to pair with
the nearest preceding unpaired matching delimited scope statement.
Scope delimited statements can also be implicitly terminated, either at
the end of a procedural sentence (where all unterminated statements are
terminated by the separator period), or by the termination of any
containing delimited scope statement.
NOTE Not all statements are scope delimitable in this fashion; those
statements that are scope delimitable are termed delimited scope
statements only if they are explicitly terminated by an explicit
scope delimiter. See the section Explicit And Implicit Scope
Terminators in the chapter Concepts of the COBOL Language for
further information.
Categories of Statements.
---------------------------------------------------------
| | |
| Category | Verbs |
| | |
---------------------------------------------------------
| | |
| Arithmetic | ADD |
| | COMPUTE |
| | DIVIDE |
| | INSPECT~(TALLYING) |
| | MULTIPLY |
| | SUBTRACT |
| | EXAMINE~(TALLYING) (OSVS) |
| | |
---------------------------------------------------------
| | |
| Conditional | ADD (SIZE ERROR) |
| | CALL (OVERFLOW) |
| | COMPUTE (SIZE ERROR) |
| | DELETE (INVALID KEY) |
| | DIVIDE (SIZE ERROR) |
| | GO TO (DEPENDING) |
| | IF |
| | MULTIPLY (SIZE ERROR) |
| | READ (END or INVALID KEY) |
| | RECEIVE (NO DATA) |
| | RETURN (END) |
| | REWRITE (INVALID KEY) |
| | SEARCH |
| | START (INVALID KEY) |
| | STRING (OVERFLOW) |
| | SUBTRACT (SIZE ERROR) |
| | UNSTRING (OVERFLOW) |
| | WRITE (INVALID KEY or END-OF-PAGE) |
| | EVALUATE (ANS85) |
| | ON (OSVS) |
| | |
---------------------------------------------------------
---------------------------------------------------------
| | |
| Category | Verbs |
| | |
---------------------------------------------------------
| | |
| Data Movement | ACCEPT (DATE, DAY or TIME) |
| | ACCEPT MESSAGE COUNT |
| | INSPECT (REPLACING) |
| | MOVE |
| | STRING |
| | UNSTRING |
| | EXAMINE (OSVS) |
| | TRANSFORM (OSVS) |
| | INITIALIZE (ANS85) |
| | INSPECT (CONVERTING) (ANS85) |
| | SET (TO TRUE) (ANS85) |
| | SET (TO FALSE) (MF) |
| | SET (ADDRESS OF) (MF)(VSC2) |
| | SET (POINTER) (MF)(VSC2) |
| | |
---------------------------------------------------------
| | |
| Ending | EXIT PROGRAM |
| | GOBACK (MF)(OSVS)(VSC2) |
| | STOP |
| | |
---------------------------------------------------------
| | |
| Input-Output | ACCEPT ( identifier ) |
| | CLOSE |
| | DELETE |
| | DISABLE |
| | DISPLAY |
| | ENABLE |
| | OPEN |
| | READ |
| | RECEIVE |
| | REWRITE |
| | SEND |
| | START |
| | STOP ( literal ) |
| | WRITE |
| | EXHIBIT (MF)(OSVS) |
| | PURGE (ANS85) |
| | SET ( TO ON or TO OFF ) (ANS85) |
| | |
---------------------------------------------------------
| | |
| Inter-Program | CALL above |
| | CANCEL |
| | CHAIN (MF) |
| | EXEC |
| | |
---------------------------------------------------------
| | |
| Null Operation | EXIT CONTINUE(ANS85) |
| | |
---------------------------------------------------------
---------------------------------------------------------
| | |
| Category | Verbs |
| | |
---------------------------------------------------------
| | |
| Ordering | MERGE |
| | RELEASE |
| | RETURN |
| | SORT |
| | |
---------------------------------------------------------
| | |
| Procedure | ALTER |
| | CALL |
| | EXIT PERFORM / EXIT PARAGRAPH / EXIT |
| | SECTION (MF) |
| | GO TO |
| | NEXT SENTENCE (MF) |
| | PERFORM |
| | |
---------------------------------------------------------
| | |
| Scope | END-ACCEPT (MF)(XOPEN) |
| Delimiting | END-ADD |
| (ANS85) | END-CALL |
| | END-DELETE |
| | END-DISPLAY (MF)(XOPEN) |
| | END-DIVIDE |
| | END-EVALUATE |
| | END-IF |
| | END-MULTIPLY |
| | END-PERFORM |
| | END-READ |
| | END-RECEIVE |
| | END-RETURN |
| | END-REWRITE |
| | END-SEARCH |
| | END-START |
| | END-STRING |
| | END-SUBTRACT |
| | END-UNSTRING |
| | END-WRITE |
| | |
---------------------------------------------------------
---------------------------------------------------------
| | |
| Category | Verbs |
| | |
---------------------------------------------------------
| | |
| COBOL System | BASIS (OSVS, VSC2) |
| Directing | DELETE (OSVS, VSC2) |
| | INSERT(OSVS, VSC2) |
| | $DISPLAY(MF) |
| | $ELSE(MF) |
| | $END(MF) |
| | $IF(MF) |
| | COPY |
| | ENTER |
| | USE |
| | REPLACE (ANS85) |
| | ENTRY (OSVS)(VSC2)(MF) |
| | EJECT (OSVS)(VSC2)(MF) |
| | SKIP1 (OSVS)(VSC2)(MF) |
| | SKIP2 (OSVS)(VSC2)(MF) |
| | SKIP3 (OSVS)(VSC2)(MF) |
| | TITLE (OSVS)(MF) |
| | NOTE (OSVS) |
| | ++INCLUDE (MF) |
| | -INC (MF) |
| | |
---------------------------------------------------------
| | |
| Table Handling | SEARCH |
| | SET |
| | |
---------------------------------------------------------
IF and ON are verbs in the COBOL sense; it is recognized that they are
not verbs in English.
MPE/iX 5.0 Documentation