[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

1.3 Source Reference Format

The HP COBOL compiler recognizes two source program formats: ANSI and terminal.

  • ANSI format conforms to the American National Standard COBOL reference format.
  • Terminal format is a concise Hewlett-Packard specified format. It shortens source program lines by allowing horizontal tab characters and carriage returns. In terminal format, you do not use the ANSI format sequence numbers or identification area.

By default, the compiler expects terminal-format source lines. The compiler expects ANSI format only when the command line includes the ansi compiler option.

The reference format rules for spacing take precedence over all other spacing rules.

1.3.1 ANSI Format

The ANSI source reference format describes COBOL programs in terms of character positions on an input line. A source program line has 80 character positions as shown in Figure 1-1.

Figure 1-1 Source Program Line


Margin L

Immediately to the left of the leftmost character position.

Margin C

Between character positions 6 and 7.

Margin A

Between character positions 7 and 8.

Margin B

Between character positions 11 and 12.

Margin R

Between character positions 72 and 73.

Sequence Number Area

The six character positions between Margin L and Margin C. The contents can be any characters from the computer character set.

The compiler does not check the uniqueness of the contents. However, the compiler does check for the ascending sequence of the contents if the compiler command line includes the sequence compiler option.

Indicator Area

The seventh character position. The character in this position directs the compiler to interpret the source line in one of the following ways:

Character Source Line Interpretation
space ( ) Default. The compiler processes the line as normal COBOL text.
hyphen (-) Continuation line. The compiler processes the line as a continuation of the previous source line.
asterisk (*) Comment line. The compiler ignores the contents of the line. However, the source line appears on the program listing.
slash (/) New listing page. The compiler treats the line as a comment line. However, it advances the program listing to the top of the next page before printing the line.
A-Z, a-z Conditional compilation lines. The compiler processes the line as normal COBOL text if you specify the DEBUGGING MODE clause in the SOURCE-COMPUTER paragraph, or if you specify the conditionals compiler option in the command line. If you do not specify either, the compiler processes this line as a comment line.

Area A

The four character positions between Margin A and Margin B. Area A contains division headers, section headers, paragraph headers, paragraph-names, level indicators, and certain level-numbers.

Area B

The 61 character positions between Margin B and Margin R. Area B contains all other COBOL text.

Identification Area

The eight character positions immediately following Margin R. The compiler ignores the contents of the identification area. However, the contents appear on the source program listing.

Line Continuation

Sentences, entries, phrases, and clauses that continue in Area B of subsequent lines are called continuation lines. The line being continued is called the continued line.

A hyphen in a line's indicator area causes its first nonblank character in Area B to be the immediate successor of the last nonblank character of the preceding line. This continuation excludes intervening comment lines and blank lines.

However, if the continued line ends with a nonnumeric literal without a closing quotation mark, the first nonblank character in Area B of the continuation line must be a quotation mark. The continuation starts with the character immediately after the quotation mark. All spaces at the end of the continued line are part of the literal. Area A of the continuation line must be blank.

If the indicator area is blank:

  • The compiler treats the first nonblank character on the line as if it followed a space.
  • The compiler treats the last nonblank character on the preceding line as if it preceded a space.

ANSI Format Example


001010 01  NUMERIC-CONTINUATION.
001020     03  NUMERIC-LITERAL          PIC  9(16) VALUE IS 123
001030-    4567890123456.
001040 01  NONNUMERIC-CONTINUATION.
001050     03  NONNUMERIC-LITERAL       PIC  X(40) VALUE IS "AB
001060-    "CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn".
001070 PROCEDURE DIVISION.
001080 SENTENCE-CONTINUATION.
001090     IF NUMERIC-LITERAL NOT = SPACES
001100         DISPLAY "NUMERIC-LITERAL NOT = SPACES"
001110     ELSE
001120         DISPLAY NUMERIC-LITERAL.

Lines 001020 and 001030 show continuation of a numeric literal. Lines 001050 and 001060 continue a nonnumeric literal. A sentence that spans four lines begins on line 001090.

Blank Lines

A blank line contains no characters other than spaces between Margin C and Margin R. Blank lines can be anywhere in a source program or library text.

Comment Lines

A comment line is any source line with an asterisk (*) or slash (/) in its indicator area. Area A and Area B can contain any characters from the computer character set. Comment lines can be anywhere in a source program or library text.

Conditional Compilation Lines

A conditional compilation line is any source line after the OBJECT COMPUTER paragraph that includes one of these uppercase or lowercase alphabetic characters in its indicator area: A to Z, a to z. The compiler processes the line as normal COBOL text if you specify the DEBUGGING MODE clause in the SOURCE COMPUTER paragraph.

The compiler processes the line as normal COBOL text if you include the appropriate conditionals compiler option in the command line.

If you specify neither, the compiler processes this line as a comment line.

Lines conditioned by one letter can be compiled or treated as comments independently of other conditional compilation lines. On OpenVMS systems, for instance, if you compile with /CONDITIONALS=(A,B), lines conditioned with A and B compile while those conditioned by other letters are treated as comments.

See Chapter 8 for additional information on the interaction between conditional compilation lines and the COPY statement.

Pseudo-Text

Pseudo-text character-strings and separators can start in either Area A or Area B. However, if there is a hyphen in the indicator area of a line that follows the opening pseudo-text delimiter, Area A of the line must be blank.

The normal rules for line continuation apply to the formation of text-words.

Pseudo-text is described in Chapter 8.

Short Lines and Tab Characters

If the source program input medium is not punched cards, carriage return and horizontal tab characters can shorten source lines.

The compiler recognizes the end of the input line as Margin R. Tab characters, other than those in nonnumeric literals, cause the compiler to generate enough space characters to position the next character at the next tab stop. The compiler's tab stops are at character positions 8, 12, 20, 28, 36, 44, 52, 60, 68, and 76.

The following example shows how the compiler interprets carriage return and horizontal tab characters in a source program:

Shortened ANSI Format Source Line


000100*The following record description shows the source line format[Return]
000110 01[Tab]RECORD-A.[Return]
000120[Tab][Tab]03  GROUP-A.[Return]
000130[Tab][Tab][Tab]05  ITEM-A[Tab]PIC X(10).[Return]
000140*[Tab]The tab character in the nonnumeric literal[Return]
000150*[Tab]on the next line is stored as one character[Return]
000160[Tab][Tab][Tab]05
ITEM-B[Tab]PIC X VALUE IS "[Tab]".[Return]
000170[Tab][Tab]03  ITEM-C[Tab][Tab]PIC X(10).[Return]
000180D01[Tab]RECB REDEFINES RECORD-A[Tab]PIC X(21).[Return]

Source Line as Interpreted by the Compiler


000100*The following record description shows the source line format
000110 01  RECORD-A.
000120     03  GROUP-A.
000130             05  ITEM-A      PIC X(10).
000140*    The tab character in the nonnumeric literal
000150*    on the next line is stored as one character
000160             05  ITEM-B      PIC X VALUE IS "[Tab]".
000170     03  ITEM-C              PIC X(10).
000180D01  RECB REDEFINES RECORD-A PIC X(21).


Previous Next Contents Index