Data Alignment [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
Data Alignment
In a COBOL program, data is moved from one area of storage (sending data
item) to another (receiving data item) through use of the MOVE, ACCEPT,
STRING, UNSTRING, arithmetic, or other statements in the PROCEDURE
DIVISION. When aligning data within the receiving item, the compiler
follows specific rules. These rules depend upon the category of that
item, as noted below. Table 4-2 contains some examples.
* For data items in the numeric category, the compiler aligns the
data by the decimal point and places it in the receiving data
item. The compiler also truncates excess characters on either end
of the sending data item, and fills unused positions in the
receiving data item with zeros.
NOTE The decimal point is never actually stored in a numeric data item;
instead, the compiler defines and keeps track of an assumed decimal
point that appears in the data item only when it is read or written
or output. Any stored data item that contains a combination of
digits and editing characters such as the decimal point, comma, and
so forth, does not belong to the numeric category and cannot be
used in arithmetic operations except as a receiving field.
When your program does not explicitly specify a decimal point for a
numeric data item, the compiler defines an assumed decimal point
immediately after the rightmost digit and aligns the item as
described above.
* For data items in the numeric-edited category, the compiler aligns
the data by decimal point with zero-fill or truncation at either
end (as with numeric data items), except where editing replaces
leading zeros with another character.
NOTE The decimal point in a numeric-edited data item, unlike that in a
numeric data item, is actually stored in the item.
* For data items in the alphabetic, alphanumeric, and
alphanumeric-edited categories, the compiler aligns the data at
the leftmost character position. It also truncates excess
characters to the right of the sending item and fills unused
positions to the right of the receiving item with spaces.
NOTE If your program specifies the JUSTIFIED clause for the receiving
data item in the DATA DIVISION, the above rules are modified as
directed by that clause.
Level-01 (record) and level-77 data items are always aligned on word
boundaries unless they are in the LINKAGE SECTION. Refer to "System
Dependencies" in Appendix H for more information. In Table 4-2 ,
a space character is represented by the symbol _, and an assumed decimal
point position is represented by the symbol ^. The receiving data items
for alphabetic and alphanumeric data items are each 11 positions long.
The receiving data item for the alphanumeric-edited data item is six
positions long. The receiving data items for numeric and numeric-edited
data items may each contain up to 18 digits. The specifications for the
PICTURE format are explained in Chapter 7 .
Table 4-2. Data Alignment
-----------------------------------------------------------------------------------------------------
| | | | Receiving Field after Transfer |
| | | Receiving Item | |
| Category | Data to be Stored | before Transfer | |
-----------------------------------------------------------------------------------------------------
| | | | PICTURE | Content |
| | | | Clause | |
- Alphabetic - ABC - PQRSTUVWXYZ - A(11) - ABC -
- - ABCDEFGHIJK - PQRSTUVWXYZ - A(11) - ABCDEFGHIJK -
- - ABCDEFGHIJKLMN - PQRSTUVWXYZ - A(11) - ABCDEFGHIJK -
-----------------------------------------------------------------------------------------------------
- Numeric - 1^2 - 987654 - 9(3)V9(3) - 001^200 -
- - 123^456 - 987654 - 9(3)V9(3) - 123^456 -
- - 12345^67890 - 987654 - 9(3)V9(3) - 345^678 -
-----------------------------------------------------------------------------------------------------
- Numeric Edited - 1.2 - 987.654 - 9(3).9(3) - 001.200 -
- - 123.456 - 987.654 - 9(3).9(3) - 123.456 -
- - 12345.67890 - 987.654 - 9(3).9(3) - 345.678 -
-----------------------------------------------------------------------------------------------------
| Alphanumeric | ABCDE | ZZZ/ZZZ | XXX/XXX | ABC/DE_ |
| Edited | | | | |
-----------------------------------------------------------------------------------------------------
- Alphanumeric - A2C - PQRSTUVW123 - X(11) - A2C________ -
- - A2C?E!G*I5K - PQRSTUVW123 - X(11) - A2C?E!G*I5K -
- - A2C?E!G*I5K@M7 - PQRSTUVW123 - X(11) - A2C?E!G*I5K -
-----------------------------------------------------------------------------------------------------
MPE/iX 5.0 Documentation