|
6.9 WRITE
To output data to the printer or to a file, the verb WRITE is used. It would be of the form:
|
WRITE {level 01 name of file/printer FD}
|
For example:
000100 ENVIRONMENT DIVISION.
000200 INPUT-OUTPUT SECTION.
000300 FILE-CONTROL.
000400 ASSIGN PRINT-FILE TO PRINTER.
:
000500 DATA DIVISION.
000600 FILE SECTION.
000700 FD PRINT-FILE.
000800 01 P-DATA PIC X(80).
:
000900 WORKING-STORAGE SECTION.
001000 01 DATA-NUMBER PIC 9(6) VALUE 123456.
001100 01 PRINT-NUMBER PIC X(6).
:
010900*in procedure division
011100 MOVE DATA-NUMBER TO PRINT-NUMBER
011200 MOVE PRINT-NUMBER TO P-DATA
011300 WRITE P-DATA
To simplify things the word FROM can be used to save always having to first MOVE
the data (PRINT-NUMBER) into the printing item (P-DATA above).
So, line 011200 and 011300 can simply be written as:
011100 WRITE P-DATA FROM PRINT-NUMBER
In addition to WRITE, the is also REWRITE and DELETE which are used to update records
within files that have been opened in I-O mode (see the following section). When using DELETE you must first read
the record that is to be deleted. Also, when deleting a record you refer to the FILE NAME
rather than the record name:
000300 FD IN-FILE.
000400 01 CUST-RECORD.
000500 03 C-NAME PIC X(20).
000600 03 C-NUMBER PIC 9(6).
:
001000* in procedure division
001100 READ IN-FILE
001200 NOT AT END
001300 IF C-NUMBER = 123456 THEN
001400 DELETE IN-FILE
001500 ELSE MOVE C-NUMBER TO W-DATA-STORE
001600 END-IF
001700 END-READ
For details on the READ statement, see the following section
|