Compaq COBOL
Reference Manual
In this example:
- The relative locations of records (01-level items) in the
Working-Storage and Linkage Sections are neither defined nor
predictable.
- The structures of ITEM-J (a record) and ITEM-C (a group item within
a record) are identical.
Example 2
WORKING-STORAGE SECTION.
01 ITEM-A.
03 ITEM-B PIC X.
03 ITEM-C.
05 ITEM-D OCCURS 3 TIMES.
07 ITEM-E PIC X.
07 ITEM-F PIC 9999 COMP SYNC.
07 ITEM-G PIC X.
03 ITEM-H PIC X.
|
In this example:
- A fill byte is added after each occurrence of ITEM-D to maintain
2-byte boundary alignment of the next occurrence.
- ITEM-D is 5 bytes long. The fill byte following ITEM-D is not
included in its length.
- ITEM-C is 18 bytes long. Its length includes the fill bytes
associated with its subordinate items.
- The record ITEM-A is 21 bytes long.
Example 3
WORKING-STORAGE SECTION.
01 ITEM-A.
03 ITEM-B PIC X.
03 ITEM-C.
05 ITEM-D OCCURS 3 TIMES.
07 ITEM-E PIC X.
07 ITEM-F PIC 9999 COMP SYNC.
03 ITEM-H PIC X.
|
In this example:
- ITEM-G is omitted.
- ITEM-D is 4 bytes long. No fill bytes are added, since the next
occurrence is already aligned on a 2-byte boundary.
- ITEM-C is 12 bytes long.
- The record ITEM-A is 15 bytes long.
5.2.4 Alpha Alignment and Padding
The Compaq Alpha Calling Standards for the Tru64 UNIX,
OpenVMS Alpha, and Windows NT systems specify Alpha natural data
alignment and padding. You invoke this alignment by adding the
alignment padding
compiler option to the compile command line, or by using
pad align
directives in your source code. (See the Compaq COBOL User Manual for additional
information on the command.)
The natural Alpha alignments and field sizes that apply to
elementary COBOL data fields are shown in Table 5-4.
Table 5-4 Alpha Alignment and Padding
Data Types |
Alignment Starting Position |
Pictures |
Usages |
8-bit character string
|
Byte boundary
|
A, X, 9, Edited
|
Display
|
16-bit integer
|
Word boundary, multiple of 2
|
9(4)
|
COMP
|
32-bit integer
|
Longword boundary, multiple of 4
|
9(8)
|
COMP
|
Single-precision real
|
|
|
COMP-1
|
64-bit integer
|
Quadword boundary, multiple of 8
|
9(16)
|
COMP
|
Double-precision real
|
|
|
COMP-2
|
These alignments and field sizes apply to elementary data items.
However, they are extended to group data items at all level numbers by
requiring that the alignment of the group data item conforms to the
alignment of the largest natural alignment of any elementary data item
that is subordinate to the group-item. Every intermediate group data
item in Compaq COBOL is a candidate for natural Alpha
alignment and padding. Every higher-level data item is padded to be the
smallest multiple of the largest natural alignment of any of its
subordinate elementary data items that contains the data structure. The
alignment and padding can be determined in all cases by following the
tree structure through as many levels as required until the elementary
data item with the largest natural alignment is found. All elementary
data items are aligned and sized within their data structures according
to Table 5-4.
5.3 DATA DIVISION General Format and Rules
Function
The Data Division describes data the program creates, receives as
input, manipulates, and produces as output.
Syntax Rules
- The Data Division follows the Environment Division.
- The reserved words DATA DIVISION, followed by a period (.)
separator character identify and begin the Data Division.
General Rules
- The Data Division is subdivided into sections. These sections must
be in the following order:
FILE SECTION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
REPORT SECTION.
SCREEN SECTION.
File Section
- The File Section defines the structure of data files. It begins
with the File Section header containing the reserved words FILE
SECTION, followed by a period (.) separator character.
- File description entries and sort-merge file description entries
follow the File Section header. They can be in any order.
- The file description entry consists of a level indicator (FD), a
file-name, and a series of independent clauses.
- The FD clause specifies the following:
- How the file records data
- The sizes of logical and physical records
- The names of data records (except for report files)
- The number of lines on a logical printer page
- An FD entry, followed by one or more record description entries,
defines a sequential, relative, or indexed file. Record description
entries must immediately follow the associated FD entry.
- No record description entries may follow the report file
description entry.
- The sort-merge file description entry consists of a level indicator
(SD), a file-name, and a series of independent clauses.
- An SD clause specifies the following:
- How the file records data
- The sizes of logical and physical records
- The names of data records
- An SD entry specifies the sizes and names of data records for a
sort-merge file referred to by SORT and MERGE statements.
- An SD entry, followed by one or more record description entries,
defines a file. record description entries must immediately follow the
associated SD entry.
Working-Storage Section
- The Working-Storage Section describes records and subordinate data
items. These records are not parts of files; rather, the program
develops and processes them internally.
- The Working-Storage Section also describes data items assigned
values by the source program.
- The Working-Storage Section consists of a section header, followed
by record description entries.
- The section header consists of the reserved words WORKING-STORAGE
SECTION, followed by a period (.) separator character.
- A record description entry groups data items that bear a
hierarchical relationship to each other. Unrelated data items in the
Working-Storage Section can be described as records that are individual
elementary items.
- Record description clauses can be used in the File Section, the
Working-Storage Section, or the Linkage Section.
- The VALUE IS clause can specify the initial value of any item in
the Working-Storage Section except index data items (described by the
USAGE IS INDEX clause) and index-names (described by the INDEXED BY
phrase of the OCCURS clause).
- If the VALUE IS clause does not specify an initial value, the
default initial value for an item depends on the type of data item:
Data Item Type |
Default Initial Value |
Numeric
|
Zero
|
Index-name
|
Occurrence number one
|
Index data item
|
Undefined
|
Tables
|
Undefined
|
All others
|
Spaces
|
Linkage Section
- The Linkage Section is used only in a called program.
- The Linkage Section describes data available through the calling
program; both the calling and called programs can access this data.
- To access calling program data items through the Linkage Section,
the called program must have a Procedure Division header USING phrase.
- The structure of the Linkage Section is the same as that of the
Working-Storage Section. It consists of a section header followed by
record description entries. The section header consists of the reserved
words LINKAGE SECTION followed by a period (.) separator character.
Report Section
- The Report Section defines report files. It begins with the Report
Section header: the reserved words REPORT SECTION, followed by a period
(.) separator character.
- Report description entries follow the Report Section header.
- The report description entry consists of a level indicator (RD), a
report name, and a series of independent clauses.
- An RD clause specifies the following:
- Identifying characters to be prefixed to each print line in a report
- The physical structure and organization of a report
- The name of the report
- An RD entry, followed by one or more report group description
entries, defines a report. Report group description entries must
immediately follow the associated report description entry.
- A report group description entry defines a report group. It
specifies the characteristics of a report group and the individual
items within a report group.
Screen Section
- The Screen Section describes a video form and specifies the
attributes, behavior, size, and location of each screen item within the
video form. The Screen Section is for use with ACCEPT and DISPLAY
statements.
Additional References
5.3.1 FD (File Description) Sequential, Line Sequential, Relative, Indexed, and Report File Descriptions
Function
A file description entry describes the physical structure,
identification, record names, and names for sequential, line
sequential, relative, indexed, and report files. It also specifies the
internal or external attributes of a file connector and the local or
global attributes of a file-name.
*Clauses marked with an asterisk (*) can be in either the SELECT clause
of the Environment Division or the file description entry of the Data
Division. They cannot be in both places for the same file.
Syntax Rules
Formats 1, 2, 3, and 4---All Files
- The level indicator FD identifies the start of a file description
entry. It must precede file-name.
- The clauses following file-name can appear in any order.
- A period (.) separator character must terminate a file description
entry.
- On OpenVMS, the file name written to disk (see the ASSIGN clause
in Chapter 4) has the file type .DAT added if no other file type is
specified in the corresponding file specification. <>
Format 1---Sequential or Line Sequential Files
- file-name can refer only to a sequential file.
- One or more record description entries must follow the file
description entry.
Format 2---Relative Files
- file-name can refer only to a relative file.
- If a START statement refers to file-name, the file
description must include the RELATIVE KEY phrase within the ACCESS MODE
clause.
- One or more record description entries must follow the file
description entry.
Format 3---Indexed Files
- file-name can refer only to an indexed file.
- On Tru64 UNIX and Windows NT, for information on
file-names for indexed files, see the ASSIGN clause in
Chapter 4.<>
- alt-key cannot have the same leftmost character position
as that of rec-key or any other alt-key for the same
file.
- One or more record description entries must follow the file
description entry.
Format 4---Report Files
- file-name can refer only to a report file.
- No record description entries may follow the file description entry
for a report file.
- Only the CLOSE statement and the OPEN statement with the OUTPUT or
EXTEND phrase may reference this file description entry.
General Rules
Formats 1, 2, 3, and 4---All Files
- A file description entry associates file-name with a file
connector.
- On OpenVMS, if the file description entry contains the EXTERNAL
clause, the RMS special registers RMS-STS, RMS-STV, and RMS-FILENAME
are external registers.
- If the file description entry contains the GLOBAL clause, the RMS
special registers RMS-STS, RMS-STV, and RMS-FILENAME are global
registers. <>
Format 1---Sequential and Line Sequential Files
- If the file description entry contains the LINAGE clause and the
EXTERNAL clause, the LINAGE-COUNTER special register is an external
data item.
- If the file description entry contains the LINAGE clause and the
GLOBAL clause, the special register LINAGE-COUNTER is a global name.
Format 3---Indexed Files
- If the file description entry contains the EXTERNAL clause, the
segmented key seg-key has the external attribute.
- If the file description entry contains the GLOBAL clause, the
segmented key seg-key is a global name.
See the Compaq COBOL User Manual for examples of the file description entry
formats.
5.3.2 SD (Sort-Merge File Description)
Function
A sort-merge file description entry describes a sort or merge file's
physical structure, identification, and record names.
Syntax Rules
- The level indicator SD identifies the start of a sort-merge file
description. It must precede file-name.
- The clauses following file-name can appear in any order.
- A period (.) separator character must terminate a sort-merge file
description entry.
- One or more record description entries must follow the sort-merge
file description entry.
General Rule
No input-output statements can refer to a file-name in a
sort-merge file description.
Examples
See the Compaq COBOL User Manual for examples of the sort-merge file description
entry.
5.3.3 RD (Report Description)
Function
The Report Description names a report, specifies any identifying
characters to be prefixed to each print line in the report, and
describes the physical structure and organization of that report. It
also determines whether a report-name is a local name or
global name.
Syntax Rules
- report-name must appear in one and only one REPORT clause.
- The clauses following report-name may appear in any order.
report-name is the highest permissible qualifier that can be
specified for LINE-COUNTER, PAGE-COUNTER, and all data-names in the
Report Section.
General Rules
- If the Report Description entry contains the GLOBAL clause,
report-name and the special registers LINE-COUNTER and
PAGE-COUNTER are global names.
- The reserved word PAGE-COUNTER references a special register that
the compiler creates for each report in the Report Section.
- In the Report Section, a reference to PAGE-COUNTER can appear only
in a SOURCE clause. In the Procedure Division, PAGE-COUNTER can be used
anywhere an integer data item can appear.
- If more than one PAGE-COUNTER exists in a program, PAGE-COUNTER
must be qualified by a report-name wherever it is referenced
in the Procedure Division.
In the Report Section, an unqualified
reference to PAGE-COUNTER is qualified implicitly by the name of the
report containing the reference. Whenever the PAGE-COUNTER of a
different report is referenced, PAGE-COUNTER must be explicitly
qualified by the other report's report-name.
- The INITIATE statement causes the Report Writer Control System to
set the PAGE-COUNTER of the referenced report to one.
- PAGE-COUNTER is automatically incremented by one each time the
Report Writer Control System executes a page advance.
- Procedure Division statements may alter the contents of
PAGE-COUNTER.
- The reserved word LINE-COUNTER references a special register that
the compiler creates for each report in the Report Section.
- In the Report Section, a reference to LINE-COUNTER can appear only
in a SOURCE clause. In the Procedure Division, LINE-COUNTER can be used
anywhere a data item with an integer value can appear. However, only
the Report Writer Control System can change the contents of
LINE-COUNTER.
- If there is more than one LINE-COUNTER in a program, Procedure
Division references to LINE-COUNTER must be qualified by a
report-name.
In the Report Section, an unqualified
reference to LINE-COUNTER is qualified implicitly by the name of the
report containing the reference. Whenever the LINE-COUNTER of a
different report is referenced, LINE-COUNTER must be explicitly
qualified by the other report's report-name.
- The INITIATE statement causes the Report Writer Control System to
set the LINE-COUNTER of the referenced report to zero. The Report
Writer Control System also automatically resets LINE-COUNTER to zero
each time it executes a page advance.
- The execution of SUPPRESS statements and the processing of
nonprintable report groups do not change the value of LINE-COUNTER.
- At the time each print line is presented, the value of LINE-COUNTER
represents the line number on which the print line is presented. After
the presentation of the report group, the value of LINE-COUNTER is
governed by the Report Writer Presentation Rules and Tables.
Additional References
Example
The following is an example of a global Report Description entry:
FILE SECTION.
FD WEEKLY-REPORTS...
REPORTS ARE PAYROLL-REPORT
PAYROLL-IRS.
REPORT SECTION.
RD PAYROLL-REPORT
IS GLOBAL
CODE "AA"
CONTROL GRAND-TOT
SITE-TOT
DEPT-TOT
GROUP-TOT
PAGE LIMITS ARE 60 LINES
HEADING 2
FIRST DETAIL 9
LAST DETAIL 55
FOOTING 58.
RD PAYROLL-IRS
CODE "BB"...
|
The previous example uses the CODE clause to flag PAYROLL-REPORT
records from other records (see PAYROLL-IRS) included in the same file
(WEEKLY-REPORTS). The entry defines four control totals. GRAND-TOT is
the most major control total; it will be printed only at the end of the
report. SITE-TOT, DEPT-TOT, and GROUP-TOT are major, intermediate, and
minor control totals, respectively. These totals are printed whenever
the Report Writer Control System (RWCS) processes a control break. The
entry also defines a report page with 60 lines. On each page the RWCS
is to print PAYROLL-REPORT headings beginning on line 2, detail lines
from lines 9 to 55, and footings beginning on line 58.
5.3.4 Data Description
Function
A data description entry specifies the characteristics of a data item.
Syntax Rules
- level-number in Format 1 can be any number from 01 to 49,
or 77.
- Data description clauses can appear in any order, with two
exceptions:
- The optional data-name or FILLER clause must immediately
follow level-number.
- The optional REDEFINES clause must immediately follow the optional
data-name or FILLER clause.
- The EXTERNAL clause can appear in a level 01 or 77 data description
entry in the Working-Storage Section.
- The GLOBAL clause can appear in a level 01 or 77 data description
entry in the Working-Storage Section, or in a level 01 data description
entry in the File Section.
- The EXTERNAL and REDEFINES clauses cannot be in the same data
description entry.
- data-name must appear in any Format 1 entry that contains
the EXTERNAL clause or GLOBAL clause, or in the record descriptions of
a file description entry that contains the EXTERNAL or GLOBAL clause.
- There must be a PICTURE clause for all elementary items except the
following:
- An index data item
- A COMP-1 or COMP-2 data item
- The subject of a RENAMES clause
- A POINTER data item
In these cases, there must be no PICTURE clause.
- The words THRU and THROUGH are equivalent.
- The SYNCHRONIZED, PICTURE, JUSTIFIED, and BLANK WHEN ZERO clauses
can appear only in Data Description entries for elementary items.
General Rules
- Each condition-name requires a separate Format 3 entry.
The level 88 entry associates one or more values, or ranges of values,
with condition-name.
All condition-name entries
for an associated data item (the conditional variable) must immediately
follow that item's data description entry.
Any
condition-name associated with a global conditional variable
is global.
A condition-name can be associated with a data
item at any level except:
- Another condition-name
- A level 66 item
- A group that contains items with JUSTIFIED, SYNCHRONIZED, or USAGE
(other than USAGE IS DISPLAY) clauses
- An index data item
- Multiple level 01 data description entries subordinate to an FD or
SD entry implicitly redefine the same area.