-
Notifications
You must be signed in to change notification settings - Fork 0
/
05-enterfile.cob
49 lines (43 loc) · 1.53 KB
/
05-enterfile.cob
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
IDENTIFICATION DIVISION.
PROGRAM-ID. Enter_File.
****************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT data-file ASSIGN TO "records.dat".
****************************
DATA DIVISION.
FILE SECTION.
FD data-file.
01 data-set.
05 data-name PIC X(20).
05 data-age PIC 999.
WORKING-STORAGE SECTION.
01 n PIC 99.
****************************
PROCEDURE DIVISION.
DISPLAY "[+] How many records?". ACCEPT n.
DISPLAY "---".
* Read data for data-file.
OPEN OUTPUT data-file.
PERFORM TEST AFTER VARYING TALLY FROM 1 BY 1 UNTIL TALLY = n
DISPLAY "[+] Enter record #" TALLY
DISPLAY " Name : " ACCEPT data-name
DISPLAY " Age : " ACCEPT data-age
WRITE data-set
END-PERFORM.
CLOSE data-file.
DISPLAY "---".
* Display entries of data-file.
OPEN INPUT data-file.
PERFORM TEST AFTER VARYING TALLY FROM 1 BY 1 UNTIL TALLY = n
READ data-file
AT END DISPLAY "[-] Premature end of file"
NEXT SENTENCE
END-READ
DISPLAY "[+] Record #" TALLY
DISPLAY " Name : " data-name
DISPLAY " Age : " data-age
END-PERFORM.
CLOSE data-file.
STOP RUN.