-
Notifications
You must be signed in to change notification settings - Fork 0
/
READIDX.cob
374 lines (307 loc) · 11.1 KB
/
READIDX.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
*=========================== READIDX ============================*
* Authors: Brian D Pead
*
* License: MIT
*
* Description: Reads the indexed file created by program BLDFILES
* in the specfied manner, and displays the records
* read.
*
* Date Version Description
* ---- ------- -----------
* 2020-02-08 1.0 First release
*================================================================*
IDENTIFICATION DIVISION.
*========================
PROGRAM-ID. READIDX.
ENVIRONMENT DIVISION.
*=====================
CONFIGURATION SECTION.
*----------------------
SOURCE-COMPUTER.
IBM-Z15.
* IBM-Z15 DEBUGGING MODE.
INPUT-OUTPUT SECTION.
*---------------------
FILE-CONTROL.
SELECT NAMADDIX ASSIGN "Data\NAMEADDR.Idx.dat"
ORGANIZATION INDEXED
ACCESS DYNAMIC
RECORD KEY NA-TAXID
ALTERNATE KEY NA-LAST-NAME
WITH DUPLICATES
FILE STATUS W-FILE-STATUS.
/
DATA DIVISION.
*==============
FILE SECTION.
*-------------
FD NAMADDIX.
01 NAMADDIX-REC. COPY NAMEADDR.
WORKING-STORAGE SECTION.
*------------------------
01 W-NAMADDIX-RECS PIC 9(09) COMP VALUE 0.
01 W-RETURN-CODE PIC S9(04) COMP.
01 W-DISP-NUM PIC ZZ,ZZ9.
01 W-ERROR-MSG PIC X(20) VALUE
'**** READIDX error: '.
01 W-READ-METHOD PIC X(01).
88 W-READ-METHOD-RANDOM VALUE 'R'.
88 W-READ-METHOD-SEQUENTIAL VALUE 'S'.
88 W-READ-METHOD-EXIT VALUE ' '.
88 W-READ-METHOD-VALID VALUE 'R'
'S'
' '.
01 W-READ-KEY-FIELD PIC X(01).
88 W-READ-KEY-FIELD-LAST-NAME VALUE 'L'.
88 W-READ-KEY-FIELD-TAXID VALUE 'T'.
88 W-READ-KEY-FIELD-EXIT VALUE ' '.
88 W-READ-KEY-FIELD-VALID VALUE 'L'
'T'
' '.
01 W-KEY-VALUE PIC X(35).
88 W-KEY-VALUE-EXIT VALUE SPACES.
01 FILLER PIC X(01).
88 W-INVALID-KEY VALUE 'Y'.
88 W-NOT-INVALID-KEY VALUE 'N'.
01 FILLER PIC X(01).
88 W-EOF VALUE 'Y'.
88 W-NOT-EOF VALUE 'N'.
01 W-FILE-STATUS PIC X(02).
88 W-FILE-STATUS-GOOD VALUE '00'.
01 W-COMPILED-DATE.
05 W-COMPILED-DATE-YYYY
PIC X(04).
05 W-COMPILED-DATE-MM PIC X(02).
05 W-COMPILED-DATE-DD PIC X(02).
05 W-COMPILED-TIME-HH PIC X(02).
05 W-COMPILED-TIME-MM PIC X(02).
05 W-COMPILED-TIME-SS PIC X(02).
05 FILLER PIC X(07).
/
PROCEDURE DIVISION.
*===================
MAIN.
*-----
PERFORM SUB-1000-START-UP THRU SUB-1000-EXIT
IF W-RETURN-CODE NOT = 0
GO TO MAIN-EXIT
END-IF
PERFORM SUB-9100-GET-READ-METHOD THRU SUB-9100-EXIT
PERFORM SUB-2000-PROCESS-READ-METHOD THRU SUB-2000-EXIT
UNTIL W-READ-METHOD-EXIT
OR W-RETURN-CODE NOT = 0
PERFORM SUB-3000-SHUT-DOWN THRU SUB-3000-EXIT
.
MAIN-EXIT.
STOP RUN.
/
SUB-1000-START-UP.
*------------------
MOVE 0 TO W-RETURN-CODE
MOVE FUNCTION WHEN-COMPILED
TO W-COMPILED-DATE
DISPLAY 'READIDX compiled on '
W-COMPILED-DATE-YYYY '/'
W-COMPILED-DATE-MM '/'
W-COMPILED-DATE-DD ' at '
W-COMPILED-TIME-HH ':'
W-COMPILED-TIME-MM ':'
W-COMPILED-TIME-SS
OPEN INPUT NAMADDIX
IF NOT W-FILE-STATUS-GOOD
DISPLAY W-ERROR-MSG
'File status '
W-FILE-STATUS
' opening NAMADDIX'
MOVE 10 TO W-RETURN-CODE
END-IF
.
SUB-1000-EXIT.
EXIT.
/
SUB-2000-PROCESS-READ-METHOD.
*-----------------------------
PERFORM SUB-9200-GET-READ-KEY-FIELD THRU SUB-9200-EXIT
IF W-READ-METHOD-RANDOM
PERFORM SUB-9300-GET-KEY-VALUE THRU SUB-9300-EXIT
PERFORM SUB-2100-READ-RANDOM THRU SUB-2100-EXIT
UNTIL W-KEY-VALUE-EXIT
ELSE
PERFORM SUB-2200-READ-SEQUENTIAL THRU SUB-2200-EXIT
UNTIL W-READ-KEY-FIELD-EXIT
OR W-RETURN-CODE NOT = 0
END-IF
IF W-RETURN-CODE NOT = 0
GO TO SUB-2000-EXIT
END-IF
PERFORM SUB-9100-GET-READ-METHOD THRU SUB-9100-EXIT
.
SUB-2000-EXIT.
EXIT.
/
SUB-2100-READ-RANDOM.
*---------------------
PERFORM SUB-9400-READ-NAMADDIX-RANDOM THRU SUB-9400-EXIT
IF W-NOT-INVALID-KEY
DISPLAY NAMADDIX-REC
END-IF
PERFORM SUB-9300-GET-KEY-VALUE THRU SUB-9300-EXIT
.
SUB-2100-EXIT.
EXIT.
/
SUB-2200-READ-SEQUENTIAL.
*-------------------------
PERFORM SUB-9500-START-NAMADDIX THRU SUB-9500-EXIT
IF W-RETURN-CODE NOT = 0
GO TO SUB-2200-EXIT
END-IF
SET W-NOT-EOF TO TRUE
PERFORM SUB-9600-READ-NAMADDIX-SEQ THRU SUB-9600-EXIT
PERFORM UNTIL W-EOF
OR W-RETURN-CODE NOT = 0
DISPLAY NAMADDIX-REC
PERFORM SUB-9600-READ-NAMADDIX-SEQ THRU SUB-9600-EXIT
END-PERFORM
IF W-RETURN-CODE NOT = 0
GO TO SUB-2200-EXIT
END-IF
PERFORM SUB-9200-GET-READ-KEY-FIELD THRU SUB-9200-EXIT
.
SUB-2200-EXIT.
EXIT.
/
SUB-3000-SHUT-DOWN.
*-------------------
CLOSE NAMADDIX
MOVE W-NAMADDIX-RECS TO W-DISP-NUM
DISPLAY 'NAMADDIX records read: '
W-DISP-NUM
DISPLAY 'READIDX Completed'
.
SUB-3000-EXIT.
EXIT.
/
SUB-9100-GET-READ-METHOD.
*-------------------------
MOVE 'X' TO W-READ-METHOD
PERFORM UNTIL W-READ-METHOD-VALID
DISPLAY 'Enter R for random reads, S for sequential, '
'space to exit: '
NO ADVANCING
ACCEPT W-READ-METHOD
MOVE FUNCTION UPPER-CASE(W-READ-METHOD)
TO W-READ-METHOD
END-PERFORM
.
SUB-9100-EXIT.
EXIT.
/
SUB-9200-GET-READ-KEY-FIELD.
*----------------------------
MOVE 'X' TO W-READ-KEY-FIELD
PERFORM UNTIL W-READ-KEY-FIELD-VALID
DISPLAY 'Enter L for last name key, T for taxid, '
'space to exit: '
NO ADVANCING
ACCEPT W-READ-KEY-FIELD
MOVE FUNCTION UPPER-CASE(W-READ-KEY-FIELD)
TO W-READ-KEY-FIELD
END-PERFORM
.
SUB-9200-EXIT.
EXIT.
/
SUB-9300-GET-KEY-VALUE.
*-----------------------
DISPLAY 'Enter key value or space to exit: '
NO ADVANCING
ACCEPT W-KEY-VALUE
.
SUB-9300-EXIT.
EXIT.
/
SUB-9400-READ-NAMADDIX-RANDOM.
*------------------------------
IF W-READ-KEY-FIELD-LAST-NAME
MOVE W-KEY-VALUE TO NA-LAST-NAME
READ NAMADDIX
KEY NA-LAST-NAME
INVALID KEY
SET W-INVALID-KEY
TO TRUE
DISPLAY 'Key not on file: '
NA-LAST-NAME
GO TO SUB-9400-EXIT
END-READ
ELSE
MOVE W-KEY-VALUE TO NA-TAXID
READ NAMADDIX
KEY NA-TAXID
INVALID KEY
SET W-INVALID-KEY
TO TRUE
DISPLAY 'Key not on file: '
NA-TAXID
GO TO SUB-9400-EXIT
END-READ
END-IF
IF W-FILE-STATUS-GOOD
SET W-NOT-INVALID-KEY
TO TRUE
ADD 1 TO W-NAMADDIX-RECS
ELSE
DISPLAY W-ERROR-MSG
'File status '
W-FILE-STATUS
' reading NAMADDIX key'
MOVE 20 TO W-RETURN-CODE
END-IF
.
SUB-9400-EXIT.
EXIT.
/
SUB-9500-START-NAMADDIX.
*------------------------
IF W-READ-KEY-FIELD-LAST-NAME
MOVE LOW-VALUES TO NA-LAST-NAME
START NAMADDIX
KEY >= NA-LAST-NAME
END-START
ELSE
MOVE LOW-VALUES TO NA-TAXID
START NAMADDIX
KEY >= NA-TAXID
END-START
END-IF
IF NOT W-FILE-STATUS-GOOD
DISPLAY W-ERROR-MSG
'File status '
W-FILE-STATUS
' starting NAMADDIX'
MOVE 40 TO W-RETURN-CODE
END-IF
.
SUB-9500-EXIT.
EXIT.
/
SUB-9600-READ-NAMADDIX-SEQ.
*---------------------------
READ NAMADDIX NEXT
AT END
SET W-EOF TO TRUE
GO TO SUB-9600-EXIT
END-READ
IF W-FILE-STATUS-GOOD
ADD 1 TO W-NAMADDIX-RECS
ELSE
DISPLAY W-ERROR-MSG
'File status '
W-FILE-STATUS
' reading NAMADDIX next record'
MOVE 50 TO W-RETURN-CODE
END-IF
.
SUB-9600-EXIT.
EXIT.