HP OpenVMS Systemsask the wizard |
The Question is: i want to create a file in cobol prog but as extend The Answer is :
The COBOL User Manual includes an example of using OPEN EXTEND.
Extending a Sequential File
To position a file to its current end, and to allow the program
to write new records beyond the last record in the file, use both:
The EXTEND phrase of the OPEN statement
The WRITE statement
Example 6-37 shows how to extend a sequential file.
IDENTIFICATION DIVISION.
PROGRAM-ID. SEQ04.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT TRANS-FILE ASSIGN TO "TRANS".
DATA DIVISION.
FILE SECTION.
FD TRANS-FILE.
01 TRANSACTION-RECORD PIC X(25).
PROCEDURE DIVISION.
A000-BEGIN.
OPEN EXTEND TRANS-FILE.
PERFORM A100-WRITE-RECORD
UNTIL TRANSACTION-RECORD = "END".
CLOSE TRANS-FILE.
STOP RUN.
A100-WRITE-RECORD.
DISPLAY "Enter next record - X(25)".
DISPLAY "Enter END to terminate the session".
DISPLAY "-------------------------".
ACCEPT TRANSACTION-RECORD.
IF TRANSACTION-RECORD NOT = "END"
WRITE TRANSACTION-RECORD.
Without the EXTEND mode, a Compaq COBOL program would have to open
the input file, copy the contents to an output file, and add records
to the output file. (An interesting parallel to the requirements
of file updates within the since-retired Spiralog file system, the
OpenVMS Wizard might add.)
|