HP 3000 Manuals

ANSI85 Features in the DATA DIVISION [ HP COBOL II/XL Programmer's Guide ] MPE/iX 5.0 Documentation


HP COBOL II/XL Programmer's Guide

ANSI85 Features in the DATA DIVISION 

This section explains the following ANSI85 features of the DATA DIVISION:

   *   EXTERNAL data items and files.
   *   The keyword FILLER is now optional.
   *   The USAGE data item formats BINARY and PACKED-DECIMAL.

The other ANSI85 feature of the DATA DIVISION, the GLOBAL clause,
supports structured programming, and is explained in Chapter 3 .

EXTERNAL Data Items and Files 

EXTERNAL data items and files can be shared by two or more programs.
They provide another way to pass information between programs.  With the
EXTERNAL clause, separately compiled programs can share files (nested
programs can share data and files using the GLOBAL clause).

Each program must declare the shared EXTERNAL items that it uses.  Shared
items are not passed through the USING phrase.  The linker matches the
EXTERNAL items by name.  Therefore, their names must be exactly the same
in each program.  For more information, see Chapter 4 .


NOTE Data items and files can be declared both EXTERNAL and GLOBAL.
FILLER The keyword FILLER can be omitted for data items that are never referenced. This saves coding time and makes the code easier to read. Example. The following shows two ways of specifying a record. One uses FILLER and the other omits it: 01 A. 05 B PIC X(5). 05 FILLER PIC X(5) VALUE "NAME:". 01 A. 05 B PIC X(5). 05 PIC X(5) VALUE "NAME:". USAGE IS BINARY and USAGE IS PACKED-DECIMAL BINARY and PACKED-DECIMAL usage are alternatives to the default, DISPLAY (one digit per byte). They are the standard for specifying radixes of two (binary) and ten (packed decimal). In the past, BINARY was expressed as the implementor-defined COMP and PACKED-DECIMAL was defined as the HP extension COMP-3. COMP and COMP-3 still work the same, but BINARY and PACKED-DECIMAL allow greater future portability between machines. When deciding whether to use DISPLAY, BINARY, or PACKED-DECIMAL for a data item, consider the following: * How the data item is used: Is it used in arithmetic or printed? If it is used in arithmetic, what are the formats of the other operands in the expressions? Avoid mixing formats, which necessitates conversion. * Storage space: A data item of the format S9(9) BINARY occupies four bytes. A data item of the format S9(9) PACKED-DECIMAL occupies (number_of_digits+1)/2 bytes (rounded up to the nearest whole number). In most cases, BINARY data items occupy less space than PACKED-DECIMAL data items. (See also "Coding Heuristics" in Chapter 3 ). Example. The following shows some example fields declared in WORKING-STORAGE: 01 VAR-FIELDS. 05 VAR1 PIC S9(5) PACKED-DECIMAL VALUE +12345. 05 VAR2 PIC S9(9) BINARY VALUE +12345. In the above example, VAR1 is stored in three bytes because PACKED-DECIMAL allows byte-alignment and allocates only the number of bytes required for the defined field. The following shows how VAR1 might be stored in memory: ---------------------------------- | | | | | 1 2 | 3 4 | 5 C | | | | | ---------------------------------- [REV BEG] VAR2 is stored in four bytes.[REV END] Binary fields are stored in the two's complement form, requiring two, four, or eight bytes each.


MPE/iX 5.0 Documentation