Reference Format

132 Views


COBOL programs must be written in the COBOL reference format. Figure 1 shows the reference format for a COBOL 80-character source line.

Sequence Number Area (Columns 1 through 6)

A sequence number identifies each statement to be compiled by the COBOL compiler. The use of sequence numbers is optional, and may consist of any character in the character set of the computer. Sequence numbers may be in any order, and they need not be unique.

Indicator Area (Column 7)

Use the indicator area to specify:

  • The continuation of lines from the previous line onto the current line (see the information on continuation lines on page.
  • The treatment of text as documentation or comments
  • Debugging lines

Area A (Columns 8 through 11)

The following items must begin in Area A:

  • Division header
  • Section header
  • Paragraph header or paragraph name
  • Level indicator (FD and SD) or level-number (01 and 77)
  • DECLARATIVES and END DECLARATIVES
  • END PROGRAM header

Division Header

A division header is a combination of words, followed by a separator period, that indicates the beginning of a division:

  • IDENTIFICATION DIVISION.
  • ENVIRONMENT DIVISION.
  • DATA DIVISION.
  • PROCEDURE DIVISION.

A division header (except when a USING phrase is specified with a Procedure Division header) must be immediately followed by a separator period. Except for the USING phrase, no text may appear on the same line.

Section Header

A section header indicates either the beginning of a series of paragraphs (in the Environment and Procedure Divisions), or the beginning of an entry (in the Data Division). For example, FILE-CONTROL in the former case, and FILE SECTION in the latter.

A section header must be immediately followed by a period except when Procedure Division segment numbers are specified.

Paragraph Header or Paragraph Name

A paragraph header or paragraph name indicates the beginning of a paragraph. In the Environment Division, a paragraph consists of a paragraph header followed by one or more entries. In the Procedure Division, a paragraph consists of a paragraph-name followed by one or more sentences.

Level Indicator (FD and SD) or Level-Number (01 and 77)

A level indicator can be either FD or SD. It must begin in Area A and be followed by a space. (See “File Section” on page 145.) A level-number that must begin in Area A is a 1- or 2-digit integer with a value of 01 or 77.

DECLARATIVES and END DECLARATIVES

DECLARATIVES and END DECLARATIVES are keywords that begin and end the declaratives part of the source program. In the Procedure Division, each of these words must begin in Area A and be followed immediately by a separator period; no other text may appear on the same line. After END DECLARATIVES, no text may appear before the following section header.

END PROGRAM Header

The END PROGRAM header, followed by program-name and a separator period, indicates the end of a COBOL program. Program-name must be identical to that of the corresponding PROGRAM-ID paragraph. Every COBOL program (except an outermost program that contains no nested programs and is not followed by another COBOL program in a sequence of COBOL programs) must end with this header.

 

Area B (Columns 12 through 72)

The following items must begin in Area B:

  • Entries
  • Sentences
  • Statements
  • Clauses
  • Continuation lines

Entries, Sentences, Statements, Clauses

The first entry, sentence, statement, or clause begins on either the same line as the header or paragraph-name it follows, or in Area B of the next nonblank line that is not a comment line. Successive sentences or entries either begin 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.

Within an entry or sentence, successive lines in Area B may have the same format, or may be indented to clarify program logic. The output listing is indented only if the input statements are indented. Indentation does not affect the meaning of the program, and the amount is limited to the width of Area B.

Continuation Lines

Any sentence, entry, clause, or phrase that requires more than one line can be continued in Area B of the next line that is neither a comment line nor a blank line. The line being continued is a continued line; the succeeding lines are continuation lines. Area A of a continuation line must be blank, though the indicator area must contain a hyphen. If there is no hyphen the last character of the preceding line is assumed to be followed by a space.

If there is a hyphen in the indicator area of a line, the first nonblank character of this continuation line immediately follows the last nonblank character of the continued line without an intervening space.

 

Area A or Area B

The following items may begin in either Area A or Area B:

  • Comment lines
  • Debugging lines
  • Blank lines
  • Pseudo-text
  • Compiler-directing statements other than the USE statement.

Comment Lines

A comment line is any line with an asterisk (*) or slash (/) in the indicator area (column 7) of the line. The comment may be written anywhere in Area A and Area B of that line, and may consist of any combination of characters from the EBCDIC character set. A comment line may be placed anywhere in the program following the Identification Division header.

Multiple comment lines are allowed. Each must begin with either an asterisk (*) or a slash (/) in the indicator area. An asterisk (*) comment line is printed in the output listing, immediately following the last preceding line. A slash (/) comment line is printed on the first line of the next page, and the current page of the output listing is ejected.

The compiler treats a comment line as documentation, and does not check it syntactically.

Debugging Lines

A debugging line is any line with a 'D' in the indicator area of the line. Debugging lines can be written in the Environment Division (after the OBJECT-COMPUTER paragraph), the Data Division, and the Procedure Division. If a debugging line contains only spaces in Area A and Area B, it is considered a blank line.

Blank Lines

A blank line contains nothing but spaces from column 7 through column 72. A blank line may appear anywhere in a program.

Pseudo-Text

The character-strings and separators comprising pseudo-text may start in either Area A or Area B. If, however, there is a hyphen in the indicator area (column 7) of a line which follows the opening pseudo-text delimiter, Area A of the line must be blank, and the rules for continuation lines apply to the formation of text words.

Compiler-Directing Statements

The following compiler-directing statements may start in Area A or Area B:

Comment Area (Columns 73 through 80)

The comment area is available for your own use; for example, to identify your program.

Post Comments