A COBOL Source Program [ COBOL/HP-UX Language Reference for the Series 700 and 800 ] MPE/iX 5.0 Documentation
COBOL/HP-UX Language Reference for the Series 700 and 800
A COBOL Source Program
General Description
A COBOL source program is a syntactically correct set of COBOL
statements.
Organization.
With the exception of COPY and REPLACE statements and the END PROGRAM
header (ANS85), the statements, entries, paragraphs, and sections of a
COBOL source program are grouped into four divisions which are sequenced
in the following order:
1. The Identification Division
2. The Environment Division
3. The Data Division
4. The Procedure Division
The end of a COBOL source program is indicated by either the END PROGRAM
header, if specified, or by (ANS85) the absence of further source program
lines.
Structure
The following gives the general format and order of presentation of the
entries and statements which constitute a COBOL source program.
General Format
Syntax Rule
The generic terms Identification Division, Environment Division, Data
Division , Procedure Division and END PROGRAM header (ANS85) represent a
COBOL identification division, a COBOL environment division, a COBOL data
division, a COBOL procedure division and a COBOL END PROGRAM header
(ANS85) respectively.
General Rule
The beginning of a division in a program is indicated by the appropriate
division header. The end of a division is indicated by one of the
following:
a. The division header of a succeeding division in that program.
b. That physical position after which no more source program lines
occur.
________________________________________________________________________
| |
| c. The END PROGRAM header. (ANS85) |
| |
________________________________________________________________________
________________________________________________________________________
|Nested Source Programs |
| |
|(ANS85) |
| |
|General Description |
| |
|A COBOL source program can contain other COBOL source programs, and |
|these contained programs can reference some of the resources of the |
|programs within which they are contained. |
| |
|When a program, program B, is contained in another program, |
|program A, it can be directly contained or indirectly contained. |
|Program B is directly contained in program A if there is no |
|program contained in program A that also contains program B. |
|Program B is indirectly contained in program A if there exists |
|a program contained in program A that also contains program |
|B. |
| |
|Syntax Rules |
| |
|End-program-header must be present if: |
| |
| |
| a. The COBOL source program contains one or more nested COBOL |
| source programs, or: |
| |
| b. The COBOL source program is contained within another COBOL |
| source program. |
________________________________________________________________________
________________________________________________________________________
|(ANS85) |
| |
|General Rules |
| |
| |
| 1. The beginning of a division in a program is indicated by the |
| appropriate division header. The end of a division is |
| indicated by one of the following: |
| |
| |
| a. The division header of a succeeding division in that |
| program. |
| |
| b. An Identification Division header which indicates the |
| start of another source program. |
| |
| c. The END PROGRAM header. |
| |
| d. That physical position after which no more source |
| program lines occur. |
| |
| 2. A COBOL source program which is directly or indirectly |
| contained within another program is considered in these |
| specifications as a separate program that can additionally |
| reference certain resources defined in the containing |
| program. |
| |
| 3. The object code that results from passing a source program |
| contained within another program through your COBOL system is |
| considered to be inseparable from the object code produced from|
| the containing program. |
________________________________________________________________________
________________________________________________________________________
|END PROGRAM Header |
| |
|(ANS85) |
| |
|Function |
| |
|The END PROGRAM header indicates the end of the named COBOL source |
|program. |
| |
|General Format |
| |
| END PROGRAM program-name. |
| |
|Syntax Rules |
| |
| |
| 1. The program-name must conform to the rules for forming a |
| user-defined word. |
| |
| 2. The program-name must be identical to the program-name declared|
| in the PROGRAM-ID paragraph. (See the section The PROGRAM-ID |
| Paragraph in this chapter.) |
| |
| |
| |
|3. The program-name can be a nonnumeric literal. The content of the |
| literal must follow the rules for formation of program-names. |
| (VSC2) (MF) |
| |
|4. If a PROGRAM-ID paragraph declaring a specific program-name is |
| stated between the PROGRAM-ID paragraph and the END PROGRAM header|
| declaring and referencing, respectively, another program-name, the|
| END PROGRAM header referencing the former program-name must |
| precede that referencing the latter program-name. |
| |
| |
|General Rules |
| |
| |
| 1. The END PROGRAM header must be present in every program |
| which either contains or is contained within another |
| program. |
| |
| 2. The END PROGRAM header indicates the end of the specified COBOL|
| source program. |
| |
| 3. If the next source statement after the program terminated by |
| the END PROGRAM header is a COBOL statement, it must be the |
| Identification Division header of a program to be compiled |
| separately from that program terminated by the end program |
| header. |
________________________________________________________________________
Initial State of a Program
________________________________________________________________________
|(ANS85) |
| |
|A program is in the initial state: |
| |
| |
| 1. The first time the program is called in a run unit. |
| |
| 2. The first time the program is called after the execution of a |
| CANCEL statement referencing the program or a CANCEL |
| statement referencing a program that directly contains the |
| program. |
| |
| 3. Every time the program is called, if it possesses the initial |
| attribute. |
| |
| 4. The first time the program is called after the execution of a |
| CALL statement referencing a program that possesses the initial|
| attribute, and that directly or indirectly contains the |
| program. |
| |
|Characteristics of a Program in its Initial State |
| |
| |
| 1. The program's internal data contained in the Working-Storage |
| Section and the Communication Section is initialized. If a |
| VALUE clause is used in the description of the data item, the |
| data item is initialized to the defined value. If a VALUE |
| clause is not associated with a data item, the initial value of|
| the data item is undefined. |
| |
| All such data items are filled with the value found in the |
| DEFAULTBYTE directive. (MF) |
| |
| 2. Files with internal file connectors associated with the program|
| are not in the open mode. |
| |
| 3. The control mechanisms for all PERFORM statements contained in |
| the program are set to their initial states. |
| |
| 4. A GO TO statement referred to by an ALTER statement contained |
| in the same program is set to its initial state. |
________________________________________________________________________
MPE/iX 5.0 Documentation