-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPHONEBOOK.CBL
81 lines (79 loc) · 2.75 KB
/
PHONEBOOK.CBL
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
******************************************************************
* Author: Clair Marchesani
* Date: 22 May 2016
* Purpose: Self-Study / Demonstration
* Tectonics: cobc
******************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. PHONEBOOK.
AUTHOR CLAIR MARCHESANI
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT BOOK ASSIGN TO "PHONEBOOK.DAT"
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS FS.
DATA DIVISION.
FILE SECTION.
FD BOOK.
01 BOOKENTRY.
88 ENDOFFILE VALUE HIGH-VALUES.
02 NAME.
03 FIRSTNAME PIC X(10).
03 LASTNAME PIC X(10).
02 PHONENUMBER.
03 PREFIX PIC 9(5).
03 RESTOFNUMBER PIC 9(7).
WORKING-STORAGE SECTION.
01 FS PIC 99.
01 YESNOANSWER PIC X.
01 WS-BOOKENTRY.
02 WS-NAME.
03 WS-FIRSTNAME PIC X(10).
03 WS-LASTNAME PIC X(10).
02 WS-PHONENUMBER.
03 WS-PREFIX PIC 9(5).
03 WS-RESTOFNUMBER PIC 9(12).
PROCEDURE DIVISION.
MAIN-PROCEDURE.
DISPLAY "Enter Surname."
ACCEPT WS-LASTNAME
OPEN INPUT BOOK
IF FS(1:1) IS NOT ZERO THEN
CLOSE BOOK
IF WS-LASTNAME EQUALS SPACES THEN STOP RUN END-IF
DISPLAY "Adding a new entry"
PERFORM ADD-ENTRY-PROCEDURE
END-IF
READ BOOK
AT END SET ENDOFFILE TO TRUE
END-READ
PERFORM UNTIL ENDOFFILE
IF LASTNAME EQUALS WS-LASTNAME THEN
DISPLAY SPACE
DISPLAY FIRSTNAME SPACE LASTNAME
DISPLAY "Number" SPACE PREFIX SPACE RESTOFNUMBER
END-IF
READ BOOK
AT END SET ENDOFFILE TO TRUE
END-READ
END-PERFORM
CLOSE BOOK
DISPLAY "Add new entry?"
ACCEPT YESNOANSWER
IF YESNOANSWER EQUALS 'Y' THEN PERFORM ADD-ENTRY-PROCEDURE.
CLOSE BOOK
STOP RUN.
ADD-ENTRY-PROCEDURE.
OPEN EXTEND BOOK
MOVE WS-LASTNAME TO LASTNAME
DISPLAY "Enter first name for person " WS-LASTNAME
ACCEPT FIRSTNAME
DISPLAY "Enter Phone Number Prefix"
ACCEPT PREFIX
DISPLAY "Enter rest of phone number"
ACCEPT RESTOFNUMBER
WRITE BOOKENTRY
CLOSE BOOK
STOP RUN.
END PROGRAM PHONEBOOK.