Coding Rules [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
Coding Rules
The following paragraphs state the standards that you should follow when
coding COBOL source programs. These coding rules are known in COBOL as
the reference format.
Sequence Number (Columns 1 through 6)
Sequence numbers appear in columns 1 through 6 of the source record.
They identify the order of the record with respect to other records in
your program. When you enter a program through EDIT/3000, the sequence
numbers are supplied automatically by that subsystem. When you write the
program on a coding form, however, these numbers are optional. When you
choose to use them, you enter them in columns 1 through 6 of the coding
sheet. Any character may be used in the sequence numbers, though
sequential numbers are recommended.
When you compile your program, you may request the compiler to use the
sequence numbers to check the sequence of the source statements in the
program. You may also request the compiler to renumber these statements.
You select these options with the $EDIT command (refer to Appendix B
for descriptions of the $EDIT options).
Sequence numbers are also useful if you must recompile the program. They
allow you to merge new text with the originally compiled text stored on
disk, according to sequence number. Thus, you need to enter only
additional or changed statements for this compilation.
NOTE If you intend to use this feature, increment the sequence numbers
by 10 or 100 to allow space for possible new statements.
Program Text (Columns 8 through 72)
Program text appears in columns 8 through 72. This group of columns is
divided into Areas A and B. The coding sheet provides both column and
area headings. All Area A and Area B coding conventions presented
throughout this manual represent the ANSI standard specifications for
COBOL. In many instances the HP COBOL II compiler allows variations from
these standards. In order to enhance the readability of source programs,
and ensure compatibility with standard ANSI COBOL, you are encouraged to
follow the rules presented here.
In Area A (columns 8 through 11), you begin all division headings,
section headers, paragraph headers, paragraph names, level indicators FD
and SD, and level numbers 01 and 77. These entries may, where necessary,
be continued into Area B.
In Area B (columns 12 through 72), you enter all other COBOL text. For
example, the following elements must appear in Area B: all sentences and
procedural statements; data description entries (including their names),
whether or not associated with level indicators and numbers.
Continuation Lines
Any sentence or entry that requires more than one line, must be continued
in Area B of the next line. Your program can contain any number of
continuation lines.
When a word or numeric literal is broken from one line to the next, you
must enter a hyphen (-) in column 7 of the continuation line. This
hyphen indicates that the first nonspace character in Area B is part of
the word or literal broken on the previous line.
When a nonnumeric literal is broken from one line to the next, you again
must[REV BEG] place a hyphen in column 7, and you must enter a quotation
mark or apostrophe[REV END] before the continuation of the literal. In
any case, the continuation of the word or literal can begin anywhere
within Area B of the continuation line. All spaces at the end of the
continued line are considered part of the end of the word or literal. In
any continuation line, Area A must contain spaces only.
[REV BEG]
Examples.
The following example shows a continuation line where the data item
ITEM-NUMBER-FOUR is continued onto the second line:
ADD ITEM-NUMBER-ONE, ITEM-NUMBER-TWO, ITEM-NUMBER-THREE TO IT
- EM-NUMBER-FOUR. uparrow
uparrow uparrow Column 72
Columns 7 and 14.
All characters of the first line up to column 72 are considered part of
the line. On the second line, the continuation hyphen is in column 7.
The continuation text begins in column 14.
The following example shows a nonnumeric literal continued onto a second
line. The literal is:
"Name 1A Number 1A Name 2A Number 2A Name 3A Number 3A Name 4A Number 4A"
MOVE "Name 1A Number 1A Name 2A Number 2A Name 3A Number 3A N
- "ame 4A Number 4A" TO RECORD-ITEM. uparrow
uparrow uparrow Column 72
Columns 7 and 12.
All characters of the first line up to column 72 are considered part of
the literal. Notice that there is no closing quotation mark on the first
line. Once again, the continuation hyphen is in column 7, and the
continuation text begins in column 12. The continuation of the literal
must start and end with quotation marks or apostrophes.
The following example shows that the continued line can start anywhere in
Area B. It also shows apostrophes instead of quotation marks. This
example is equivalent to the previous example:
MOVE 'Name 1A Number 1A Name 2A Number 2A Name 3A Number 3A N
- 'ame 4A Number 4A' TO RECORD-ITEM. uparrow
uparrow uparrow Column 72
Column 7. Continuation text starts in column 17.
[REV END]
[REV
BEG]
The following example shows that all characters of the first line are
used in the nonumeric literal:
Columns 68 through 72 are blank
and considered part of the literal.
downarrow downarrow
MOVE "Name 1A Number 1A Name 2A Number 2A Name 3A Number
- "3A Name 4A Number 4A" TO RECORD-ITEM. uparrow
uparrow uparrow Column 72.
Columns 7 and 12.
When the above MOVE statement is executed, the following literal is moved
to RECORD-ITEM:
"Name 1A Number 1A Name 2A Number 2A Name 3A Number 3A Name 4A Number 4A"
There are five spaces between "Number" and "3A" in the literal, which
correspond to the five spaces in columns 68 through 72 of the first line.
This literal contains a total of 75 characters.[REV END]
Debugging Lines
A debugging line is any line with a "D" in column 7. Refer to Chapter 13
, for more information on rules and use of debugging lines.
Identification Code (Columns 73-80)
An optional identification code may appear in columns 73 through 80.
This feature can be used to identify different versions of a program. It
also serves as the library name for source statements placed in a COBOL
copy library. All statements in such a library require an identification
code.
MPE/iX 5.0 Documentation