HP 3000 Manuals

PROCEDURE DIVISION Syntax Rules [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

PROCEDURE DIVISION Syntax Rules 

This section discusses syntax rules for the following areas:

   *   Declarative Sections

   *   Procedures

   *   Sections and Section Headers

   *   Segmentation

Declarative Sections 

Declarative sections are optional.  If used, they may appear in COBOL
subprograms as well as main programs.

When you define declarative sections, they must be the first sections
within the PROCEDURE DIVISION, be preceded by the keyword DECLARATIVES
beginning in area A and followed by a period and a space, and be on a
line by itself.  To indicate where declarative sections end and the
remainder of the PROCEDURE DIVISION begins, you must use the keywords END
DECLARATIVES beginning in area A and followed by a period and a space,
and be on a line by itself.  USE procedures consist of a section name
followed by a space and the keyword SECTION, followed by an optional
segment number, a period and a space, a declarative sentence, and one or
more optional paragraphs.

A declarative sentence is one that contains a USE statement.  The USE
statements themselves are not executed.  They simply define the
conditions calling for the execution of the USE procedures.  The
declarative procedures are the optional paragraphs following the
declarative sentence. 

A single USE procedure is terminated in a source program by either a new
section name, which indicates the beginning of another declarative
statement, or by the keywords END DECLARATIVES, which indicate the end of
the list of declarative sections.

As the preceding paragraph implies, you must define a new section for
each USE statement entered in the source program.

Declarative procedures must not reference nondeclarative procedures,
although you may use a PERFORM statement in the nondeclarative portion of
a program to refer to procedures associated with a USE statement.

Below is an example of the declaratives portion of a COBOL program:

     PROCEDURE DIVISION.
     DECLARATIVES.
     IN-FILE-ERR SECTION.
         USE AFTER STANDARD ERROR PROCEDURE ON IN-FILE.
     REPORT-ERR-PARA.
         DISPLAY "ERROR IN IN-FILE. ".
         DISPLAY "FILE-STATUS ITEM IS  " FILE-STAT.
         DISPLAY "WHAT ACTION?".
         DISPLAY "ENTER C OR A FOR CONTINUE OR ABORT".
         ACCEPT DECISION.
         IF DECISION IS EQUAL TO "A" MOVE "ON" TO STOP-IT.
     FILE-LABEL SECTION.
         USE AFTER STANDARD BEGINNING FILE LABEL
         PROCEDURE ON OUT-FILE.
     WRITE-LABEL-PARA.
         MOVE "HP 3000" TO LABEL-REC.
     END DECLARATIVES.

In the above example, if an error occurs during execution of an OPEN,
CLOSE, READ, WRITE, REWRITE, EXCLUSIVE, or UN-EXCLUSIVE statement
referencing IN-FILE, and no AT END phrase is used in the statement, the
USE procedure, IN-FILE-ERR, is executed.

When OUTFILE is opened, the second USE procedure called FILE-LABEL, is
executed.  This procedure creates a user label, and as an implicit part
of its operation, writes the label on the file.

For more information on USE procedures, refer to "USE Statement" in
Chapter 9 .

Procedures 
[REV BEG]

A procedure consists either of one or more paragraphs or sections.  A
procedure name is a word you choose that refers to a paragraph or section
in the source program.  A procedure name consists of a section name or a
paragraph name.  A paragraph name may be qualified.[REV END]

The physical end of the PROCEDURE DIVISION is that physical position in
the source program after which no further procedures appear.

Sections and Section Headers 

A section consists of a section header followed by zero or more
successive paragraphs.  A paragraph consists of a paragraph name followed
by a period, a space, and zero or more successive sentences.
(Paragraphs, sentences, statements, and so forth are described in Chapter
2 .)

In the PROCEDURE DIVISION, a section header consists of a section name
followed by the word SECTION, an optional segment number, then a period.
For example:

     BEGIN-INITIALIZATION SECTION 05.

or:

     END-INITIALIZATION SECTION.

If no section header is specified, the entire PROCEDURE DIVISION
constitutes one section.  Section names in both main programs and
subprograms must be unique.

(For more information on section and paragraph names, refer to "MPE XL
System Dependencies" in Appendix H .)

The segment number appearing in a section header is used to segment the
PROCEDURE DIVISION. Thus, all sections with the same segment number
constitute a program segment.  If no segment number is specified, COBOL
assumes it to be 0.  Although sections with the same segment numbers are
a part of the same segment, they need not be physically contiguous in the
source program.

Segmentation 

Segmentation is an obsolete feature of the 1985 ANSI COBOL standard.
[REV BEG]

Segmentation has no effect on the physical layout of the object
program.[REV END]

Segment Numbers.   

Sections in the DECLARATIVES portion of a PROCEDURE DIVISION must have
segment numbers less than 50.

The term initial state refers to the original setting of GO TO statements
before they are modified at run time by the ALTER statement Refer to the
"ALTER Statement" in Chapter 9 .

A segment with a segment number from 0 to 49 is in its initial state only
when it is first used in a given run-unit.  Upon subsequent entries into
such a segment, its state is the same as when it was exited from a
previous usage.

There are three exceptions where a segment with a segment number from 50
to 99 is always in its initial state whenever control is transferred to
that section.  The first exception concerns the appearance of a SORT,
MERGE, or PERFORM statement, or any statement that implicitly calls a USE
procedure, in a section whose segment number is greater than 49.  When
one of these statements implicitly transfers control to a procedure
outside of the segment in which it appears, the segment is reentered in
its last used state following the execution of the procedure.

The second exception is when a subprogram is called from a section whose
segment number is greater than 49.  In this case, if the EXIT PROGRAM or
GOBACK statement is executed in the called program, the calling program
is reentered at the statement following the CALL statement.  If this
statement is within the same segment as the CALL statement, the segment
is in its last used state when it is reentered.

The third exception is when a PERFORM statement is executed.  If the
sections or paragraphs named in the PERFORM statement have segment
numbers greater than 49, then the segment of which they are a part is in
its initial state the first time it is executed.  It remains in its last
used state for all subsequent executions.  Of course, following the
completion of the PERFORM, the associated segment is again in its initial
state.

Since segment numbers greater than 49 are always (with the noted
exceptions) in their initial states when used, the compiler must
initialize each section when control is passed to it, thus lengthening
execution time.  Modifying a GO TO statement in such a section from
outside by using an ALTER statement in another section is impossible,
since all GO TO statements in that section are set to their initial state
once control is passed to that section.

(For more information on segmentation and internal naming conventions,
refer to "MPE XL System Dependencies" in Appendix H .)



MPE/iX 5.0 Documentation