[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
User Manual


Previous Contents Index

16.4 Using Alignment Directives, Qualifiers, and Flags (Alpha, I64)

Alignment directives offer flexibility and selectivity: they alter the current alignment by specifying new alignment information from within the source program.

The forms of the alignment directives are as follows:


    *DC SET ALIGNMENT
    *DC SET NOALIGNMENT
    *DC END-SET ALIGNMENT

    *DC SET PADALIGN
    *DC SET NOPADALIGN
    *DC END-SET PADALIGN

The *DC SET ALIGNMENT directive and the *DC SET PADALIGN directive function independently of each other, except when their scopes overlap in the program source. In case of overlapping scope, the effect of the *DC SET PADALIGN directive prevails.

The *DC SET ALIGNMENT directive specifies natural Alpha alignment of elementary data items. The *DC SET PADALIGN specifies Alpha natural alignment and padding.

The *DC SET NOALIGNMENT directive specifies OpenVMS VAX compatible alignment.

The optional *DC END-SET ALIGNMENT directive terminates the current *DC SET ALIGNMENT or *DC SET NOALIGNMENT directive that is currently in effect.

The alignment of binary data that has been specified with the SYNCHRONIZED clause is unaffected by the *DC SET ALIGNMENT and *DC SET PADALIGN directives.

When you use an alignment directive or qualifier to align data in records, you should consider whether the data will be written to a file to be accessed by applications written in HP COBOL for OpenVMS VAX.

Note

These directives are not allowed in the PROCEDURE DIVISION of a program source.

16.4.1 Order of Alignment Operations (Alpha, I64)

Table 16-2 shows the order of precedence of the primary alignment qualifiers and directives in HP COBOL.

Table 16-2 Alignment and Padding Order of Precedence (Alpha, I64)
  Compiler Directives
Command line
Qualifier and Option
No Directive
in Effect
*DC SET
ALIGNMENT
*DC SET
PADALIGN
*DC SET
NOALIGN
(none) None Align
elementary
data items.
Align and pad elementary data items and structures. None
/ALIGNMENT
-align
Align
elementary
data items.
Align
elementary
data items.
Align and pad elementary data items and structures. None
/ALIGN=PAD
-align pad
Align and pad elementary data items and structures. Align elementary data items and structures. Align and pad elementary data items. None

16.4.2 Nesting Alignment Directives (Alpha, I64)

Alignment directives located within the source program alter the current alignment by specifying a new alignment, which remains in effect (except for data specified with SYNCHRONIZED, which remains unchanged) until changed precedence, or until the beginning of the next file specified in a comma list. You can nest alignment directives within a program to specify different alignments for selected sets of data. Alignment directives do the following:

  • A SET ALIGNMENT (or SET NOALIGNMENT) directive. At this point in the program source the alignment specified by this directive becomes the current alignment.
  • An END-SET ALIGNMENT directive. At this point, the immediately preceding SET ALIGNMENT (or SET NOALIGNMENT) directive is closed. The current alignment now becomes one of the following:
    • The alignment specified by the closest previous unclosed alignment directive
    • The alignment specified by the command-line option if no previous alignment directive exists
  • The beginning of the next file specified in a comma list (on the HP COBOL command line). This event closes all of the preceding alignment directives. The alignment specified with the command-line option becomes the current alignment.

Example 16-1 shows an example of nested alignment directives in source code.

Example 16-1 Using*DC SET ALIGNMENT Directives

   .
   .                                 (1)
   .

        *DC SET ALIGNMENT            (2)

        01 comp-group.
            02 cg-x1   pic x.
            02 cg-c1   pic 9(1) comp.

        *DC SET NOALIGNMENT          (3)

        01 comp-group-2.
            02 cg-x2   pic x.
            02 cg-c2   pic 9(1) comp.

        *DC END-SET ALIGNMENT        (4)

        01 comp-group-3.
            02 cg-x3   pic x.
            02 cg-c3   pic 9(1) comp.

        *DC END-SET ALIGNMENT        (5)

        01 comp-group-4.
            02 cg-x4   pic x.
            02 cg-c4   pic 9(1) comp.

  1. Initially, OpenVMS VAX compatible alignment is specified either by NOALIGNMENT or the absence of ALIGN on the compile command.
  2. The SET ALIGNMENT directive specifies alignment along natural boundaries, superseding the initial OpenVMS VAX compatible alignment.
  3. The SET NOALIGNMENT directive specifies VAX compatible alignment; data is now byte-aligned.
  4. The END-SET ALIGNMENT directive terminates the alignment specified with the previous SET directive ((3) SET NOALIGNMENT). Alignment is once again along the natural boundaries as specified by (2), the SET ALIGNMENT directive.
  5. This END-SET ALIGNMENT directive terminates the alignment specified with the original directive ((2) SET ALIGNMENT). Alignment is now OpenVMS VAX compatible as specified by the default command-line option. <>

16.4.2.1 SYNCHRONIZED Clause

The SYNCHRONIZED clause, which aligns binary data on natural boundaries, is included in both HP COBOL and HP COBOL for OpenVMS VAX. Refer to the HP COBOL Reference Manual for complete information on the SYNCHRONIZED clause.

16.4.3 Comparing Alignment Directive Effects

The alignment examples that follow illustrate the following important points:

  • HP COBOL for OpenVMS VAX and HP COBOL align 01 (and 77) data items along different boundaries, as follows:
    • HP COBOL for OpenVMS VAX aligns 01 data records and items along longword boundaries. It byte-aligns all other fields unless SYNC has been specified.
    • HP COBOL aligns 01 records and items along quadword boundaries. It byte-aligns all other fields unless SYNC or the alignment option has been specified.
  • On Alpha and I64, the effects of the SYNCHRONIZED clause, the alignment command-line option, and the SET ALIGNMENT directive on elementary data alignment are identical.

Example 16-2 through Example 16-6 show a comparison of the use and results of several alignment cases. They are applicable to Tru64 UNIX, OpenVMS I64 and OpenVMS Alpha; and Example 16-2 is additionally applicable to OpenVMS VAX (except for the information on the /ALIGNMENT qualifier, which is Alpha- and I64- specific). Example 16-2 shows the effects of the SYNCHRONIZED clause in program source, as compared with the /ALIGNMENT qualifier on the command line.

Example 16-2 Using /ALIGNMENT with SYNCHRONIZED

01 comp-group.
    02 cg-x1   pic x.                                  (1)
    02 cg-c1   pic 9(1) comp.                          (2)
    02 cg-c3   pic 9(3) comp.                          (3)
    02 cg-c7   pic 9(7) comp.                          (4)
    02 cg-c12  pic 9(12) comp.                         (5)
01 comp-group-synch.
    02 cg-x1-synch   pic x.                            (6)
    02 cg-c1-synch   pic 9(1) comp synchronized.       (7)
    02 cg-c3-synch   pic 9(3) comp synchronized.       (8)
    02 cg-c7-synch   pic 9(7) comp synchronized.       (9)
    02 cg-c12-synch  pic 9(12) comp synchronized.      (10)

The data is aligned as shown in the following examples using different alignment configurations. In the accompanying data diagrams, a number (n) indicates that that byte is occupied by the nth field of the record, and a dash (---) indicates a filler byte. The fields are indicated by the callouts in the right column of Example 16-2.

HP COBOL for OpenVMS VAX would align the data as follows:



|             |             |             |             |        1111 | 1111       |
| 1223 | 3444 | 4555 | 5555 | 5    | 6-77 | 88-- | 9999 | ---- | 0000 | 0000 |     |


Previous Next Contents Index