HP OpenVMS Systems Documentation

Content starts here

HP COBOL
User Manual


Previous Contents Index

16.3 Aligning Data for Performance and Compatibility (Alpha, I64)

Proper alignment is important for HP COBOL applications on Tru64 UNIX, OpenVMS Alpha, and OpenVMS I64 platforms. Manipulation of binary data (that is, COMP, COMP-1, COMP-2, INDEX, and POINTER data items) is significantly faster if alignment is on natural boundaries. A natural boundary is the smallest boundary at which data can be aligned without crossing the next boundary for that type. (For example, longword is the natural boundary for four-byte integers.)

Two forms of alignment are available in HP COBOL. The basic form of alignment allows you to align only elementary data items without padding the record structures and substructures within which they reside. The alternate form, which is Alpha alignment and padding, aligns both the elementary data items and the structures and substructures in which they are found. It also pads out those structures and substructures to lengths which are multiples of their alignments. This form of alignment and padding conforms to the HP OpenVMS Calling Standard.

OpenVMS VAX compatible record layouts are available for compatibility with applications running on OpenVMS VAX platforms, including HP COBOL for OpenVMS VAX.

16.3.1 Data Boundaries (Alpha, I64)

Natural alignment for binary data is detailed in Table 16-1. The boundaries described in Table 16-1 are specified in the HP OpenVMS Calling Standard. The table generally applies both to Tru64 UNIX and to OpenVMS Alpha, with the exception that IEEE is the only floating point data type on the Tru64 UNIX operating system.

Table 16-1 Boundaries for Naturally Aligned Binary Data (Alpha, I64)
COBOL
USAGE
PICTURE
Declaration
Alpha, I64
Standard Data Type
Natural
Alignment
Allocated
Storage
DISPLAY PIC A
PIC X
PIC 9
PIC EDITED
8-bit character string BYTE 1 byte
COMP PIC [S]9(1-4) 16-bit word integer WORD 2 bytes
  PIC [S]9(5-9) 32-bit longword integer LONGWORD 4 bytes
  PIC [S]9(10-18) 64-bit quadword integer QUADWORD 8 bytes
  PIC [S]9(19-31) 128-bit octaword integer QUADWORD 16 bytes
COMP-1 Not applicable 32-bit F-floating LONGWORD 4 bytes
    32-bit IEEE S-floating LONGWORD 4 bytes
COMP-2 Not applicable 64-bit D-floating QUADWORD 8 bytes
    64-bit G-floating QUADWORD 8 bytes
    64-bit IEEE T-floating QUADWORD 8 bytes
INDEX Not applicable 32-bit longword integer LONGWORD 4 bytes 1
POINTER Not applicable 32-bit longword integer LONGWORD 4 bytes 2

1 On the Alpha and I64 systems, USAGE IS INDEX is allocated as a longword integer for OpenVMS VAX compatibility. On the Tru64 UNIX system, it is allocated as a 64-bit quadword integer, with 8 bytes of storage.
2 On Alpha and I64 systems, HP COBOL allocates 4 bytes for POINTER data to maintain HP COBOL for OpenVMS VAX compatibility. On the Tru64 UNIX system, it allocates 8 bytes for POINTER data (a 64-bit quadword integer).

16.3.2 Data Field Padding (Alpha, I64)

In HP COBOL, all 01 and 77-level data items are always aligned on quadword boundaries. With Alpha natural alignment and padding invoked, the lengths of all data-items are compiled to be multiples of the greatest alignment of any subordinate elementary field.

The compiler will flag (with an Informational diagnostic) all fields that might incur side effects when compiled with alignment and padding enabled.

16.3.3 Alignment Directives, Qualifiers, and Flags (Alpha, I64)

Within your program, you can specify alignment with the alignment directives, which consist of structured comments embedded within the DATA DIVISION of the program source.

When you compile a COBOL program, you can use the /ALIGNMENT qualifier or the /ALIGNMENT=PADDING qualifier on Alpha and I64 systems and -align or -align pad on Tru64 UNIX systems to specify aligned elementary data items or naturally aligned and padded record layouts for optimal performance. If you do not specify this option, the default alignment is used, which is OpenVMS VAX compatible record layouts for compatibility with HP COBOL for OpenVMS VAX and other OpenVMS VAX languages.

In addition to the primary goal of optimum performance, specifying data alignment offers the following advantages:

  • Ease of use and conversion---You might need to make a minimal number of changes to existing source files before compiling them with the HP COBOL compiler. In some cases, all you need to do is specify the -align flag or the /ALIGNMENT qualifier with or without the padding option when you compile.
  • Flexibility---You can specify VAX compatible alignment (byte alignment) or natural alignment on a record-by-record basis. For example, you can specify VAX compatible alignment for files shared by both compilers and natural alignment for HP COBOL-only files and records.

Note

The two types of padding (use of alignment with the PADDING option, or use of *DC SET PADALIGN) are not recommended in a COBOL program that contains the REDEFINES or RENAMES syntax.

16.3.4 Specifying Alignment at Compile Time (Alpha, I64)

The result of the alignment command-line option is identical on the OpenVMS Alpha, OpenVMS I64 and the Tru64 UNIX operating systems.

On Alpha and I64 systems, the /ALIGNMENT qualifier used with the COBOL command aligns data on Alpha natural boundaries and optionally pads data structures that contain them, in conformity with the HP OpenVMS Calling Standard. The format of the /ALIGNMENT qualifier is as follows:


/ALIGNMENT[=[NO]PADDING] or /NOALIGNMENT   <>

On Tru64 UNIX systems, you use the -align flag with the cobol command to align elementary data items on Alpha natural boundaries and optionally to pad data structures which contain them, in conformity with the HP OpenVMS Calling Standard. The format of the -align flag is as follows:


-align [padding] <>

On all three patforms, the default is alignment on Alpha natural boundaries and no padding of interior or terminal fields (for 01-level data items and data structures).

The alignment command-line qualifier or flag specifies the minimum alignment for data items specified within the program source when no additional alignment information has been specified. You can specify the minimum alignment of specific data items within your program by including compiler directives in the program source.

The -align flag or the /ALIGNMENT qualifier aligns all COMP, COMP-1, COMP-2, INDEX, and POINTER data along natural boundaries. (See Table 16-1.)

By default, alignment is turned off and data is aligned on byte boundaries.

The alignment specified in the compile command is in force throughout a given compilation, except as modified by any compiler directives. In addition, the alignment of elementary binary data that has been specified with the SYNCHRONIZED clause is unchanged.


Previous Next Contents Index