COBOL Manual for TNS and TNS/R Programs

Migrating TNS Programs to Native Programs
HP COBOL Manual for TNS and TNS/R Programs522555-006
33-11
Causes of Misalignment in HP COBOL Programs
Using an explicit number for the offset of a record or for the size of a record
This practice can cause misaligned addresses by overlooking the “implicit” filler
bytes that the COBOL85 compiler adds to records:
°
Within records, to ensure that every BINARY or COMPUTATIONAL field begins
at an even-byte offset from the beginning of the structure
°
At the end of any record that has an odd number of bytes, to give it an even
number of bytes
Example 33-1. Misalignment (page 1 of 2)
Separately Compiled Main Program:
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-1.
DATA DIVISION.
EXTENDED-STORAGE SECTION.
01 aligned-group.
* 7-word (14 byte) word-aligned group containing
* 1-word, 2-word, and 4-word binary numeric items:
05 v16 PIC S9(4) COMP.
05 v32 PIC s9(9) COMP.
05 v64 PIC S9(18) COMP.
01 group-2.
05 aligned-buff PIC X(14).
05 big-buff PIC X(100).
* aligned-buff and big-buff happen to start at even byte
05 pad PIC X.
05 unaligned-buff PIC X(14).
* unaligned-buff starts at odd byte
PROCEDURE DIVISION.
main.
legal-ways-always-work.
CALL "PROG-2" USING aligned-group.
wrong-type-works-when-even.
MOVE aligned-group TO aligned-buff.
CALL "PROG-2" USING aligned-buff.
MOVE aligned-group TO big-buff(21:14).
CALL "PROG-2" USING big-buff(21:14).
wrong-type-fails-when-odd.
MOVE aligned-group TO unaligned-buff.
CALL "PROG-2" USING unaligned-buff.
MOVE aligned-group TO big-buff(22:14).
CALL "PROG-2" USING big-buff(22:14).
END PROGRAM PROG-1.