|Concepts of the COBOL Language||Introduction to Program Definition|
A COBOL source program is a syntactically correct set of COBOL statements.
A COBOL source program may contain other COBOL source programs and these contained programs may reference some of the resources of the programs within which they are contained.
With the exception of COPY
and the end program header
, the statements, entires, paragraphs and sections of a COBOL source program are grouped into four divisions that are sequenced in the following order:
The end of a COBOL source program is indicated
by either the end program header, if specified, or
by the absence of additional source program lines.
The following gives the general format and order of presentation of the entries and statements that constitute a COBOL source program. The generic terms identification-division, environment-division, data-division, procedure-division, source-program
represent a COBOL Identification Division, a COBOL Environment Division, a COBOL Data Division, a COBOL Procedure Division, a COBOL source program
and a COBOL end program header
A COBOL program can either be a program definition or a program declaration. A program definition gives details of how a program is to operate and includes a Procedure Division with a set of procedures to follow. A program declaration gives details of how a program should be called; it is referred to in this document as a call prototype and will be used to validate corresponding calls made in any program definitions occurring later in the same program source file.
The Environment, Data, and Procedure Divisions may be omitted.
The Identification Division may be omitted.
The Environment Division must be omitted. The Data and Procedure Divisions may be omitted.
Some of the "red-tape" statements required by the ANSI Standard COBOL specifications are optional when using this COBOL system. It is, however, possible to have your COBOL system output warning messages when such statements are found to be missing by use of the FLAG directive. Such statements are identified as optional in this manual by enclosing them between brackets which have boxes around them. The symbols next to these boxes indicate the dialect in which these features are optional.
The Identi fication Division must be included in every standard conforming COBOL source program. It identifies the program. The basename, derived from the filename of the file containing the program source, also identifies the first program defined in that file.
The user can also include the date the program is written, the date the compilation of the source program is accomplished, and any other information desired, under the paragraphs in the General Format shown below.
Paragraph headers identify the type of information contained in the paragraph. The name of the program must be given in the PROGRAM-ID paragraph, which is the first paragraph. The other paragraphs are optional and can be included in this division at the user's choice, in order of presentation shown by the format below.
The EXTERNAL clause in the PROGRAM-ID paragraph identifies the program as a program declaration or call prototype.
The following is the General Format of the paragraphs in the Identification Division and it defines the order of presentation in the source program.
The Environment Division specifies a standard method of expressing those aspects of a data processing problem that are dependent upon the physical characteristics of a specific computer. This division allows specification of the configuration of the source computer and the object computer. In addition, information relating to input-output control, special hardware characteristics and control techniques can be given.
The Environment Division must be included in every COBOL source program.
The Environment Division may be omitted.
The Environment Division comprises two sections:
The Configuration Section deals with the characteristics of the source computer and the object computer. This section is divided into three paragraphs:
The Input-Output Section deals with the information needed to control the transmission and handling of data between external media and the object program. This section is divided into two paragraphs:
The following is the General Format of the sections and paragraphs in the Environment Division, and defines the order of presentation in the source program.
These sections can appear in any order.
The Data Division describes the data that the object program is to accept as input, to manipulate, to create, or to produce as output.
The Data Division is subdivided into the following sections:
The File Section defines the structure of data files. Each file is defined by a file description entry and one or more record descriptions. Record descriptions are written immediately following the file description entry.
The Working-Storage Section describes records and noncontiguous data items which are not part of external data files but are developed and processed internally. It also describes data items whose values are assigned in the source program and do not change during the execution of the object program.
The Object-Storage Section describes class object data and instance object data. Its structure is the same as the Linkage and Working-Storage Sections.
The Local-Storage Section identifies a program as eligible for recursion. A separate copy of the Local-Storage Section is created each time the program is CALLed and exists only during the lifetime of that CALL.
The Linkage Section appears in the called program and describes data items that are to be referred to by the calling and the called program. Its structure is the same as the Working-Storage Section.
The Communication Section describes the data item in the source program that will serve as the interface between the Message Control System (MCS) and the program.
The Report Section contains one or more report description entries (RD entries), each of which forms the complete description of a report.
The Screen Section defines the attributes of the screens. It offers the facility to specify the exact location of fields when they are displayed on the screen as well as to control certain console features during an ACCEPT or DISPLAY operation.
Data records and items that are described in the same way have the same type. The descriptions of such items can be conveniently manipulated by declaring a type definition. A type definition can appear in the Working-Storage and Linkage Sections. A type definition in a call prototype may be referenced in a program definition.
The following is the General Format of the sections in the Data Divi sion, and defines the order of presentation in the source program.
The Procedure Division can contain declarative and non-declarative procedures
in a program definition; it must not contain any declarative or nondeclarative procedures in a call prototype.
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.)
A proced ure 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 en d of the Procedure Division and 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
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.
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 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.
The Procedure Division must conform to one of the following formats:
There are four types of statements:
There are three types of sentences:
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:
IF, SEARCH or RETURN statement
or ON EXCEPTION
A conditional sentence is a conditional statement, optionally preceded by an imperative statement, terminated by a separator period followed by a space.
A COBOL system-directing statement consists of a dire cting 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||(See the section REPLACE Statement in the chapter Compiler-Directing Statements.)|
|USE||(See the section USE Statement in the chapter Program Definition.)|
|BASIS||(See the sections BASIS Mechanism and BASIS Statement in the chapter Compiler-Directing Statements.)|
|DELETE||(See the sections BASIS Mechanism and DELETE Statement - Basis Control in the chapter Compiler-Directing Statements.)|
|INSERT||(See the section BASIS Mechanism in the chapter Compiler-Directing Statements.)|
|EJECT||(See the section EJECT Statement in the chapter Compiler-Directing Statements.)|
|SKIP1||(See the section SKIP1 Statement in the chapter Compiler-Directing Statements.)|
|SKIP2||(See the section SKIP2 Statement in the chapter Compiler-Directing Statements.)|
|SKIP3||(See the section SKIP3 Statement in the chapter Compiler-Directing Statements.)|
|TITLE||(See the section TITLE Statement in the chapter Compiler-Directing Statements.)|
|++INCLUDE||(See the section ++INCLUDE Statement in the chapter Compiler-Directing Statements.)|
|-INC||(See the section -INC Statement in the chapter Compiler-Directing Statements.)|
|$DISPLAY||(See the section $DISPLAY with Conditional Compilation Statement in the chapter Compiler-Directing Statements.)|
|$ELSE||(See the section $ELSE with Conditional Compilation Statement in the chapter Compiler-Directing Statements.)|
|$END||(See the section $END with Conditional Compilation Statement in the chapter Compiler-Directing Statements.)|
|$IF||(See the section $IF with Conditional Compilation 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.
A COBOL system-directing sentence is a single directing statement terminated by a period followed by a space.
Compiler directives give you options to control the actions of the Compiler. They allow you to enable language features, choose run-time behavior, choose compile-time options, create debugging information, control the format of data files, optimize the object code, and choose SQL options. The syntax of the directives and a description of each directive is given in your On-Line Reference.
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:
|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 EXCEPTION 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.|
The additional ANSI'85 imperative verbs are:
The additional OS/VS COBOL impera tive verbs are:
VS COBOL II imperative verb is:
The additional imperative verbs available to this COBOL system are:
When "imperati ve-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".
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.
An imperative sentence is an imperative statement terminated by a period followed by a space.
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 ter minator 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.
ADD (SIZE ERROR)
COMPUTE (SIZE ERROR)
DELETE (INVALID KEY)
DIVIDE (SIZE ERROR)
GO TO (DEPENDING)
MULTIPLY (SIZE ERROR)
READ (END or INVALID KEY)
RECEIVE (NO DATA)
REWRITE (INVALID KEY)
START (INVALID KEY)
WRITE (INVALID KEY or END-OF-PAGE)
ACCEPT (DATE, DAY or TIME)
ACCEPT MESSAGE COUNT
SET (TO TRUE)
SET (TO FALSE)
SET (ADDRESS OF)
SET (object reference)
SET (TO ON or TO OFF)
EXIT PERFORM/EXIT PARAGRAPH/EXIT SECTION
COBOL System Directing
IF and ON are verbs in the COBOL sense; it is recognized that they are not verbs in English.
The whole of this section refers to fixed format only. Your COBOL system also accepts programs written in free format. See the chapter Introduction to the COBOL Language for details of free format source.
The reference format, which provides a standard method for describing C OBOL source programs, is described in terms of character positions in a line on an input-output medium. Your COBOL system accepts source programs written in reference format and produces an output listing of the source program coded using reference format. (See the chapter Introduction for a sample source program.)
The rules for spacing given in the discussion of the reference format take precedence over all other rules for spacing.
The divisions of a source program must be ordered as follows; the Identification Division, then the Environment Division, then the Data Division, then the Procedure Division. Each division must be written according to the rules for the reference format.
See also the section Free Format in the chapter Introduction to the COBOL Language.
The reference format for a line is represented as in Figure 3-1.
Figure 3-1: Reference Format for a COBOL Source Line
The sequence number area occupies six character positions (1-6), and is between Margin L and Margin C.
The in dicator area is the 7th character position of a line.
Are a A occupies character positions 8, 9, 10 and 11, and is between margin A and margin B.
A rea B occupies character positions 12 through 72 inclusive; it begins immediately to the right of Margin B and terminates immediately to the left of Margin R.
A se quence number, normally consisting of six digits, can be placed in the sequence area and can be used to label a source program line. This sequence number is usually in ascending numeric order on each successive source statement line of the program.
This sequence number is the one used by the BASIS mechanism (see the chapter Compiler-Directing Statements) for line-editing, in which case it must be both numeric and in ascending order through the program.
The ascending order of sequence numbers can be optionally verified by your COBOL system by using the S EQCHK Compiler di rective.
There is no requirement for the content of this area to be numeric, or even unique.
If the first character position of the sequence number field contains an asterisk, or any non-printing control character (less than the character SPACE in the ASCII collating sequence), then the line is treated as co mment, and is not output to the listing file or device. This facility allows an output li sting file to be used as a source file to a subsequent compile. This support is sensitive to the MFCOMMENT Compiler directive.
Whenever a sentence, entry, phrase, or clause requires more than one line, it can be continued by starting subsequent line(s) in area B. These subsequent lines are called the continuation line(s). Any word, literal
or PICTURE character-string
can be broken in such a way that part of it appears on a continuation line.
A hyphen in the indicator area of a line indicates that the first nonblank character in area B of the current line is the successor of the last nonblank character of the preceding line
excluding intervening comment or blank lines
without any intervening space. However, if the continued line contains a nonnumeric literal without closing quotation mark, the first nonblank character in area B on the continuation line must be a quotation mark, and the continuation starts with the character immediately after that quotation mark. All spaces at the end of the continued line are considered part of the literal. Area A of a continuation line must be blank.
If there is no hyphen in the indicator area of a line, it is assumed that the last character in the preceding line is followed by a space. Both characters composing the separator "==" must be on the same line.
Characters X" and G" must be on the same line.
Characters H" must be on the same line.
Characters N" must be on the same line.
Characters *> must be on the same line.
A blank line is one that is blank from margin C to margin R, inclusive. A blank line can appear anywhere in the source program.
The text words and the separator space comprising pseudo-text can start in either area A or area B. If, however, there is a hyphen in the indicator area of a line which follows the opening pseudo-text delimiter, area A of the line must be blank; and the normal rules for continuation of lines apply to the formation of text words. (See the chapter Compiler-Directing Statements.)
The division header must start in area A. (See Figure 3-1.)
It may start in Area B.
The section header must start in area A. (See Figure 3-1.)
It may start in Area B.
A section consists of zero, one, or more paragraphs in the Environment Division or Procedure Division or zero, one or more entries in the Data Division.
A paragraph consists of a paragraph-name followed by a period and a space, and by zero, one or more sentences, or a paragraph header followed by one or more entries. Comment entries can be included within a paragraph. The paragraph header or paragraph-name starts in area A of any line following the first line of a division or a section.
The first sentence or entry in a paragraph begins either on the same line as the paragraph header or paragraph-name, or in area B of the next nonblank line that is not a comment line. Successive sentences or entries begin either in area B of the same line as the preceding sentence or entry, or in area B of the next nonblank line that is not a comment line.
Sentences can begin anywhere in area A or area B unless the AREACHECK directive is specified.
When the sentences or entries of a paragraph require more than one line, they can be continued as described in the section Continuation Of Lines earlier in this chapter.
Each Data Division entry begins with a level indicator or a level-number, followed by a space, followed by its associated name
, followed by a sequence of independent descriptive clauses. The last clause is always terminated by a period followed by a space.
There are two types of Data Division entry; those which begin with a level indicator and those which begin with a level-number.
A level indicator is any of the following:
In those Data Div ision entries that begin with a level indicator, the level indicator begins in area A followed by a space and followed in area B
or area A
with its associated name and appropriate descriptive information.
Those Data Division entries that begin with level-numbers are called data description entries.
A level-number has a value taken from the set of values 1 through 49, 66, 77
and 88. Level-numbers in the range 1 through 9 can be written either as a single digit or as a zero followed by a significant digit. At least one space must separate a level-number from the word following the level-number.
In those data description entries that begin with level-number 01 or 77, the level-number begins in area A followed by a space and followed in area B
or area A
by its associated record-name or item-name and appropriate descriptive information.
Successive data description entries can have the same format as the first and are indented according to level-number. Indentation does not affect the magnitude of a level-number.
When level-numbers are to be indented, each new level-number can begin any number of spaces to the right of margin A. The extent of indentation to the right is determined only by the width of the physical medium.
Data descriptions and level numbers other than 01 and 77 can also begin in area A.
The key word DECLARATIVES and the key words END DECLARATIVES that precede and follow, respectively, the declaratives portion of the Procedure Division must each appear on a line by themselves. Each must begin in area A and be followed by a separator period (see Figure 3-1).
A comm ent line is any line with an asterisk (*) in the continuation indicator area of the line. A comment line can appear as any line in a source program after the Identification Division header. Any combination of characters from the computer's character set can be included in area A and area B of that line (see Figure 3-1). The asterisk and the characters in area A and area B will be produced on the listing but serve as documentation only.
A comment line can appear before the Identification Division header.
A second form of comment line represented as above but with a slash (/) (instead of an asterisk) in the indicator area of the line causes page ejection prior to printing the comment.
Successive comment lines are allowed. Continuation of comment lines is permitted, except that each continuation line must contain an asterisk in the indicator area.
An in-line comment begins with the two contiguous characters "*>" preceded by a separator space, and ends with the last character position of the line. It allows free-form commentary to appear on the same line as character-strings and/or separators. An in-line comment can appear anywhere a separator space can appear in a COBOL source program or in a library text of a COBOL library. For the purpose of evaluating library text, pseudo-text and source text, an in-line comment has the value of a single space character. An in-line comment cannot be continued onto another line.
A full list of reserved words is given in the appendix Reserved Words.
Copyright © 1998 Micro Focus Limited. All rights reserved.
This document and the proprietary marks and names used herein are protected by international law.
|Concepts of the COBOL Language||Introduction to Program Definition|