Example 3: INDEX Data Items [ HP COBOL II/XL Migration Guide ] MPE/iX 5.0 Documentation
HP COBOL II/XL Migration Guide
Example 3: INDEX Data Items
The following program shows how to process an MPE V file (that has 16-bit
INDEX data items) on an MPE XL system (that uses 32-bit INDEX data
items). Each record is read using the $CONTROL INDEX16 option and each
record is written using the $CONTROL INDEX32 option. These options are
necessary for correct alignment of data fields.
IDENTIFICATION DIVISION.
PROGRAM-ID. INDEXEX.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT I-FILE ASSIGN TO "IFILE".
SELECT O-FILE ASSIGN TO "OFILE".
DATA DIVISION.
FILE SECTION.
FD I-FILE.
$CONTROL INDEX16
01 I-REC.
03 I-NAME PIC X(20).
03 I-ADDRESS PIC X(20).
03 I-SAL PIC S9(5).
* The following field is not usable. The control option
* tells the compiler to allocate two bytes for this
* field so I-DEPT will fall in the right place in the record.
03 I-INDEX USAGE IS INDEX.
03 I-DEPT PIC X(3).
FD O-FILE.
$CONTROL INDEX32
01 O-REC.
03 O-NAME PIC X(20).
03 O-ADDRESS PIC X(20).
03 O-SAL PIC S9(5).
* Note the following field is no longer declared as
* USAGE IS INDEX for greater portability.
* It has no value until it is recomputed.
03 O-INDEX PIC S9(9).
03 O-DEPT PIC X(3).
PROCEDURE DIVISION.
P1.
OPEN INPUT I-FILE OUTPUT O-FILE.
READ I-FILE
AT END MOVE HIGH-VALUES TO I-NAME
END-READ.
PERFORM UNTIL I-NAME = HIGH-VALUES
* Move all usable fields from input to output.
MOVE I-NAME TO O-NAME
MOVE I-ADDRESS TO O-ADDRESS
MOVE I-SAL TO O-SAL
MOVE I-DEPT TO O-DEPT
WRITE O-REC
READ I-FILE
AT END MOVE HIGH-VALUES TO I-NAME
END READ
END-PERFORM.
CLOSE I-FILE O-FILE.
STOP RUN.
MPE/iX 5.0 Documentation