Microsoft KB Archive/32955

Declaring Files with Variable-Length Records in COBOL 3.x, 4.x

PSS ID Number: Q32955 Article last modified on 04-21-1993

3.00 3.00a 4.00 4.50 | 3.00 3.00a 4.00 4.50 MS-DOS | OS/2

Summary: There are three ways to declare files with variable-length records in Microsoft COBOL Versions 3.0, 3.0a, 4.0, and 4.5: 1. FD (file-name) RECORD IS VARYING IN SIZE FROM 20 TO 100 CHARACTERS DEPENDING ON WS-REC-LENGTH. 01 (rec-name). 05 fixed-portion PIC x(20). 05 var-portion PIC x(80). WORKING-STORAGE SECTION. 01 WS-REC-LENGTH PIC 9(3). PROCEDURE DIVISION. OPEN OUTPUT (file-name). MOVE ALL “A” TO fixed-portion. MOVE “ABCD” TO var-portion. MOVE 24 TO ws-rec-length. WRITE (rec-name). Please note that you must initialize the “DEPENDING ON” variable (which lets you vary the length of the record) prior to a WRITE. If the file is opened for input, the system moves the length of the record read into the “DEPENDING ON” variable. 2. FD (file) RECORDING MODE IS VARIABLE. 01 rec-1 PIC X(20). 01 rec-2 PIC X(50). PROCEDURE DIVISION. MOVE ALL “A” TO rec-1. WRITE rec-1. MOVE ALL “B” TO rec-2. WRITE rec-2. 3. Compiling with the “RECMODE (V)” eliminates the need for the “RECORDING MODE IS VARIABLE” clause in the FD.

Additional reference words: 3.00 3.00a 4.00 4.50 Copyright Microsoft Corporation 1993.