[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

The descriptions of ITEM-B and ITEM-F are equivalent. Therefore, you would not expect the following sentence to change the values of ITEM-C and ITEM-D:


MOVE ITEM-B TO ITEM-F
MOVE ITEM-F TO ITEM-B.

Figure 5-6 shows how storage for the record would be allocated without and with boundary equivalence. A hyphen (-) indicates fill bytes caused by the SYNCHRONIZED clause. A plus sign (+) represents fill bytes resulting from boundary equivalence.

Figure 5-6 Storage Allocation Without and With Boundary Equivalence


Without boundary equivalence, ITEM-B occupies 8 bytes, and ITEM-F occupies 7 bytes. Moving the contents of ITEM-B to ITEM-F truncates the last byte of ITEM-D. Moving the contents of ITEM-F to ITEM-B pads the last byte of ITEM-D with a space character.

In contrast, boundary equivalence eliminates this unforeseen result. The elementary items occupy the same relative positions in each group. Therefore, the structures of ITEM-B and ITEM-F are the same, and the results of both group and elementary moves are predictable.

Examples

The following series of examples show major-minor storage allocation. The notes after each example indicate its significant features. A hyphen (-) represents fill bytes.

Example 1


 WORKING-STORAGE SECTION.
01    ITEM-A.
    03    ITEM-B    PIC X.
    03    ITEM-C.
        05    ITEM-D.
            07    ITEM-E    PIC 999 COMP SYNC.
            07    ITEM-F    PIC X(10).
        05    ITEM-G REDEFINES ITEM-D.
            07    ITEM-H    PIC 9(14) COMP SYNC.
            07    ITEM-I    PIC XXXX.
01    ITEM-J.
    03    ITEM-K.
        05    ITEM-L    PIC 999 COMP SYNC.
        05    ITEM-M    PIC X(10).
    03    ITEM-N REDEFINES ITEM-K.
        05    ITEM-O    PIC 9(14) COMP SYNC.
        05    ITEM-P    PIC XXXX.

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 and I64 Alignment and Padding

The Hewlett-Packard OpenVMS Calling Standard for the Tru64 UNIX, OpenVMS Alpha, and OpenVMS I64 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. (Refer to the HP COBOL User Manual for additional information on the command.)

The Alpha natural 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 HP COBOL is a candidate for Alpha natural 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

  1. The Data Division follows the Environment Division.
  2. The reserved words DATA DIVISION, followed by a period (.) separator character identify and begin the Data Division.

General Rules

  1. 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. (Alpha, I64)

File Section

  1. 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.
  2. File description entries and sort-merge file description entries follow the File Section header. They can be in any order.
  3. The file description entry consists of a level indicator (FD), a file-name, and a series of independent clauses.
  4. 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
  5. 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.
  6. No record description entries may follow the report file description entry.
  7. The sort-merge file description entry consists of a level indicator (SD), a file-name, and a series of independent clauses.
  8. An SD clause specifies the following:
    • How the file records data
    • The sizes of logical and physical records
    • The names of data records
  9. An SD entry specifies the sizes and names of data records for a sort-merge file referred to by SORT and MERGE statements.
  10. 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

  1. 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.
  2. The Working-Storage Section also describes data items assigned values by the source program.
  3. The Working-Storage Section consists of a section header, followed by record description entries.
  4. The section header consists of the reserved words WORKING-STORAGE SECTION, followed by a period (.) separator character.
  5. 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.
  6. Record description clauses can be used in the File Section, the Working-Storage Section, or the Linkage Section.
  7. 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).
  8. 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

  1. The Linkage Section is used only in a called program.
  2. The Linkage Section describes data available through the calling program; both the calling and called programs can access this data.
  3. To access calling program data items through the Linkage Section, the called program must have a Procedure Division header USING phrase.
  4. 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.


Previous Next Contents Index