-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcob-simpleinventory.cob
504 lines (441 loc) · 17.2 KB
/
cob-simpleinventory.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
000000* MIT License
* Copyright (c) 2018 Christer Stig Åke Landstedt
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
IDENTIFICATION DIVISION.
PROGRAM-ID. cob-simpleinventory.
AUTHOR. "Christer Stig Åke Landstedt".
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT DATAFILE ASSIGN TO "cob-simpleinventory.dat"
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS IKEY.
DATA DIVISION.
FILE SECTION.
FD DATAFILE
RECORD CONTAINS 100 CHARACTERS.
01 DATAFILEFD.
05 IKEY PIC 9(4).
05 MN PIC X(9).
05 NAME PIC X(16).
05 DES PIC X(40).
05 INS PIC 9(4)V9(2).
05 COST PIC 9(5)V9(2).
05 ICURRENCY PIC X(3).
WORKING-STORAGE SECTION.
01 WS-ENDOFFILE PIC 9 VALUE ZERO.
01 WS-DATAFILEFD.
05 WS-IKEY PIC 9(4).
05 WS-MN PIC X(9).
05 WS-NAME PIC X(16).
05 WS-DES PIC X(40).
05 WS-INS PIC 9(4)V9(2).
05 WS-COST PIC 9(5)V9(2).
05 WS-ICURRENCY PIC X(3).
01 DATEANDTIME.
05 CURRENTDATE.
10 YY PIC 99.
10 MM PIC 99.
10 DD PIC 99.
05 CURRENTTIME.
10 TIMEHH PIC 99.
10 TIMEMM PIC 99.
10 TIMESS PIC 99.
01 CURRENTDATE2.
05 YY2 PIC 9999.
05 MM2 PIC 99.
05 DD2 PIC 99.
LOCAL-STORAGE SECTION.
01 USER-SELECTION PIC 9 VALUE ZERO.
01 IID-SELECTION PIC 9(4) VALUE ZERO.
01 LS-DATAFILE.
05 LS-IKEY PIC X(12) VALUE "Part Number".
05 LS-MN PIC X(15) VALUE "| Model Number".
05 LS-NAME PIC X(19) VALUE "| Name".
05 LS-DES PIC X(43) VALUE "| Description".
05 LS-INS PIC X(11) VALUE "| In Stock".
05 LS-COST PIC X(6) VALUE "| Cost".
PROCEDURE DIVISION.
MAIN-PROGRAM.
0000SELECTIONSTART.
MOVE 0 TO USER-SELECTION.
ACCEPT CURRENTDATE2 FROM DATE yyyymmdd.
DISPLAY "-----------------------------------------------------"
"-----------------------------------------------------"
"-----------".
DISPLAY "Cobol Simple Inventory 0.1 "YY2"-"MM2"-"DD2.
DISPLAY "-----------------------------------------------------"
"-----------------------------------------------------"
"-----------".
PERFORM UNTIL USER-SELECTION>0
DISPLAY "MENU"
DISPLAY "---------------------------------------------------"
"---------------------------------------------------"
"---------------"
DISPLAY " 1 : Inventory"
DISPLAY " 2 : Information"
DISPLAY " 3 : Exit application"
DISPLAY "Select number and press Enter: "
ACCEPT USER-SELECTION
EVALUATE USER-SELECTION
WHEN 1 GO TO 0000SELECTIONINVENTORY
WHEN 2 GO TO 0000SELECTIONINFO
WHEN 3 GO TO 0000SELECTIONQUIT
WHEN OTHER PERFORM 0000SELECTIONSTARTERROR
END-EVALUATE
END-PERFORM.
0000SELECTIONSTARTERROR.
DISPLAY " ".
DISPLAY "!ERROR WRONG INPUT!".
GO TO 0000SELECTIONSTART.
0000SELECTIONINVENTORY.
ACCEPT CURRENTDATE2 FROM DATE yyyymmdd.
MOVE 0 TO USER-SELECTION.
DISPLAY " ".
DISPLAY "-----------------------------------------------------"
"-----------------------------------------------------"
"-----------".
DISPLAY "Inventory "YY2"-"MM2"-"DD2.
DISPLAY "-----------------------------------------------------"
"-----------------------------------------------------"
"-----------".
DISPLAY LS-DATAFILE
DISPLAY "-----------------------------------------------------"
"-----------------------------------------------------"
"-----------".
OPEN I-O DATAFILE.
PERFORM UNTIL WS-ENDOFFILE = 1
READ DATAFILE INTO WS-DATAFILEFD
AT END MOVE 1 TO WS-ENDOFFILE
NOT AT END
DISPLAY IKEY " | " MN " | "
NAME " | " DES " | " INS " | " COST " " ICURRENCY
END-READ
END-PERFORM.
CLOSE DATAFILE.
MOVE 0 TO WS-ENDOFFILE.
PERFORM UNTIL USER-SELECTION>0
DISPLAY " "
DISPLAY "---------------------------------------------------"
"---------------------------------------------------"
"---------------"
DISPLAY "MENU"
DISPLAY "---------------------------------------------------"
"---------------------------------------------------"
"---------------"
DISPLAY " 1 : Add Item to Inventory"
DISPLAY " 2 : Edit Inventory Item"
DISPLAY " 3 : Delete Item In Inventory"
DISPLAY " 4 : Delete ALL Inventory"
DISPLAY " 5 : Go To Main Menu"
DISPLAY " 6 : Exit Application"
DISPLAY "Select number and press Enter: "
ACCEPT USER-SELECTION
EVALUATE USER-SELECTION
WHEN 1 PERFORM 0000SELECTIONADD
WHEN 2 PERFORM 0000SELECTIONEDIT
WHEN 3 PERFORM 0000SELECTIONDELETE
WHEN 4 PERFORM 0000SELECTIONDELETEALL
WHEN 5 PERFORM 0000SELECTIONSTART
WHEN 6 GO TO 0000SELECTIONQUIT
WHEN OTHER PERFORM 0000SELECTIONCONTACTSERROR
END-EVALUATE
END-PERFORM.
0000SELECTIONCONTACTSERROR.
DISPLAY " ".
DISPLAY "!ERROR WRONG INPUT!".
GO TO 0000SELECTIONINVENTORY.
0000SELECTIONADD.
MOVE 0 TO USER-SELECTION.
DISPLAY " ".
DISPLAY "Enter Part Number (4 digets):".
ACCEPT WS-IKEY.
IF WS-IKEY IS NUMERIC
ELSE
DISPLAY "!!!ERROR WRONG INPUT"
GO TO 0000SELECTIONINVENTORY
END-IF.
DISPLAY "Enter Model Number (max 9 characters):"
ACCEPT WS-MN
DISPLAY "Enter Name (max 16 characters):"
ACCEPT WS-NAME
DISPLAY "Enter Description (max 40 characters):"
ACCEPT WS-DES
DISPLAY "Enter In Stock:"
ACCEPT WS-INS
DISPLAY "Enter Cost Per Unit:"
ACCEPT WS-COST
DISPLAY "Enter Currency (max 3 characters):"
ACCEPT WS-ICURRENCY
MOVE WS-IKEY TO IKEY.
MOVE WS-MN TO MN.
MOVE WS-NAME TO NAME.
MOVE WS-DES TO DES.
MOVE WS-INS TO INS.
MOVE WS-COST TO COST.
MOVE WS-ICURRENCY TO ICURRENCY.
MOVE WS-DATAFILEFD TO DATAFILEFD.
OPEN I-O DATAFILE.
WRITE DATAFILEFD
INVALID KEY DISPLAY"!ERROR RECORD ALREADY EXIST!"
NOT INVALID KEY DISPLAY "Item Added."
END-WRITE.
CLOSE DATAFILE.
GO TO 0000SELECTIONINVENTORY.
0000SELECTIONEDIT.
MOVE 0 TO USER-SELECTION.
DISPLAY " ".
DISPLAY "Enter Part Number To Edit:".
ACCEPT WS-IKEY.
MOVE WS-IKEY TO IKEY.
OPEN I-O DATAFILE.
READ DATAFILE INTO WS-DATAFILEFD
KEY IS IKEY
INVALID KEY
DISPLAY "!ERROR PART NUMBER DOSE NOT EXIST!"
PERFORM 0000SELECTIONEDITERROR2
NOT INVALID KEY
IF WS-IKEY IS NUMERIC
DISPLAY " "
ELSE
DISPLAY "!!!ERROR WRONG INPUT"
PERFORM 0000SELECTIONEDITERROR2
END-IF
END-READ.
CLOSE DATAFILE.
PERFORM UNTIL USER-SELECTION>0
DISPLAY " "
DISPLAY "---------------------------------------------------"
"---------------------------------------------------"
"-----------"
DISPLAY "MENU"
DISPLAY "---------------------------------------------------"
"---------------------------------------------------"
"-----------"
DISPLAY " 1 : Edit Model Number"
DISPLAY " 2 : Edit Name"
DISPLAY " 3 : Edit Description"
DISPLAY " 4 : Edit Stock"
DISPLAY " 5 : Edit Cost"
DISPLAY " 6 : Edit Currency"
DISPLAY " 7 : Cancel Edit"
DISPLAY "Select number and press Enter: "
ACCEPT USER-SELECTION
EVALUATE USER-SELECTION
WHEN 1 PERFORM 0000SELECTIONEDITMODEL
WHEN 2 PERFORM 0000SELECTIONEDITNAME
WHEN 3 PERFORM 0000SELECTIONEDITDESCRIPTION
WHEN 4 PERFORM 0000SELECTIONEDITSTOCK
WHEN 5 PERFORM 0000SELECTIONEDITCOST
WHEN 6 PERFORM 0000SELECTIONEDITCURRENCY
WHEN 7 GO TO 0000SELECTIONINVENTORY
WHEN OTHER PERFORM 0000SELECTIONEDITERROR
END-EVALUATE
END-PERFORM.
0000SELECTIONEDITMODEL.
DISPLAY " ".
DISPLAY "New Model Number:"
ACCEPT WS-MN.
GO TO 0000CONTINUEEDIT.
0000SELECTIONEDITNAME.
DISPLAY " ".
DISPLAY "New Name:"
ACCEPT WS-NAME.
GO TO 0000CONTINUEEDIT.
0000SELECTIONEDITDESCRIPTION.
DISPLAY " ".
DISPLAY "New Description:"
ACCEPT WS-DES.
GO TO 0000CONTINUEEDIT.
0000SELECTIONEDITSTOCK.
DISPLAY " ".
DISPLAY "New Stock:"
ACCEPT WS-INS.
GO TO 0000CONTINUEEDIT.
0000SELECTIONEDITCOST.
DISPLAY " ".
DISPLAY "New Cost:"
ACCEPT WS-COST.
GO TO 0000CONTINUEEDIT.
0000SELECTIONEDITCURRENCY.
DISPLAY " ".
DISPLAY "New Currency:"
ACCEPT WS-ICURRENCY.
GO TO 0000CONTINUEEDIT.
0000CONTINUEEDIT.
OPEN I-O DATAFILE.
MOVE WS-IKEY TO IKEY.
MOVE WS-MN TO MN.
MOVE WS-NAME TO NAME.
MOVE WS-DES TO DES.
MOVE WS-INS TO INS.
MOVE WS-COST TO COST.
MOVE WS-ICURRENCY TO ICURRENCY.
REWRITE DATAFILEFD
INVALID KEY DISPLAY"!ERROR CONTACT DOSE NOT EXIST!"
NOT INVALID KEY DISPLAY "Item Updated."
END-REWRITE.
CLOSE DATAFILE.
GO TO 0000SELECTIONINVENTORY.
0000SELECTIONEDITERROR.
DISPLAY " ".
DISPLAY "!ERROR WRONG INPUT!".
GO TO 0000SELECTIONEDIT.
0000SELECTIONEDITERROR2.
CLOSE DATAFILE.
GO TO 0000SELECTIONINVENTORY.
0000SELECTIONDELETE.
MOVE 0 TO USER-SELECTION.
DISPLAY " ".
DISPLAY "---------------------------------------------------"
"---------------------------------------------------"
"---------------".
DISPLAY "Enter Part Number Of Item To Be Deleted:".
ACCEPT WS-IKEY.
MOVE WS-IKEY TO IKEY.
OPEN I-O DATAFILE.
READ DATAFILE INTO WS-DATAFILEFD
KEY IS IKEY
INVALID KEY
DISPLAY "!ERROR PART NUMBER DOSE NOT EXIST!"
PERFORM 0000SELECTIONDELETEERROR2
NOT INVALID KEY
IF WS-IKEY IS NUMERIC
MOVE WS-IKEY TO IKEY
ELSE
DISPLAY "!ERROR WRONG INPUT!"
PERFORM 0000SELECTIONDELETEERROR2
END-IF
END-READ.
CLOSE DATAFILE.
PERFORM UNTIL USER-SELECTION>0
DISPLAY "Are you sure that you want to delete this item?"
DISPLAY " 1 : Yes I want to delete this item"
DISPLAY " 2 : No!"
DISPLAY "Select number and press Enter: "
ACCEPT USER-SELECTION
EVALUATE USER-SELECTION
WHEN 1 PERFORM 0000CONTINUEDELETE
WHEN 2 PERFORM 0000SELECTIONINVENTORY
WHEN OTHER PERFORM 0000SELECTIONDELETEERROR
END-EVALUATE
END-PERFORM.
0000CONTINUEDELETE.
OPEN I-O DATAFILE.
DELETE DATAFILE
INVALID KEY DISPLAY "!ERROR CONTACT DOSE NOT EXIST!"
NOT INVALID KEY DISPLAY "Item Deleted."
END-DELETE.
CLOSE DATAFILE.
GO TO 0000SELECTIONINVENTORY.
0000SELECTIONDELETEERROR.
DISPLAY " ".
DISPLAY "!ERROR WRONG INPUT!".
GO TO 0000SELECTIONDELETE.
0000SELECTIONDELETEERROR2.
CLOSE DATAFILE.
GO TO 0000SELECTIONDELETE.
0000SELECTIONDELETEALL.
MOVE 0 TO USER-SELECTION.
DISPLAY " ".
DISPLAY "---------------------------------------------------"
"---------------------------------------------------"
"---------------".
PERFORM UNTIL USER-SELECTION>0
DISPLAY "Are you sure that you want to DELETE ALL items?"
DISPLAY " 1 : Yes I want to DELETE ALL item."
DISPLAY " 2 : No!"
DISPLAY "Select number and press Enter: "
ACCEPT USER-SELECTION
EVALUATE USER-SELECTION
WHEN 1 PERFORM 0000CONTINUEDELETEALL
WHEN 2 PERFORM 0000SELECTIONINVENTORY
WHEN OTHER PERFORM 0000SELECTIONDELETEALLERROR
END-EVALUATE
END-PERFORM.
0000CONTINUEDELETEALL.
DELETE FILE
DATAFILE
END-DELETE.
OPEN OUTPUT DATAFILE.
MOVE 0001 TO IKEY.
MOVE "0002-0003" TO MN.
MOVE "Product X" TO NAME
MOVE "Dose this thing." TO DES
MOVE 1 TO INS
MOVE 1 TO COST
MOVE "SEK" TO ICURRENCY
WRITE DATAFILEFD
END-WRITE.
CLOSE DATAFILE.
GO TO 0000SELECTIONINVENTORY.
0000SELECTIONDELETEALLERROR.
DISPLAY " ".
DISPLAY "!ERROR WRONG INPUT!".
GO TO 0000SELECTIONDELETEALL.
0000SELECTIONINFO.
MOVE 0 TO USER-SELECTION.
DISPLAY " ".
DISPLAY "---------------------------------------------------"
"---------------------------------------------------"
"---------------".
DISPLAY "Application information".
DISPLAY "---------------------------------------------------".
DISPLAY "Application: Cobol Simple Inventory 0.1".
DISPLAY "Made with: ".
DISPLAY "* Ubuntu 16.04".
DISPLAY "* Gedit 3.18.3".
DISPLAY "* GnuCobol(OpenCobol) 2.2".
DISPLAY "---------------------------------------------------".
DISPLAY "MIT License".
DISPLAY "Copyright (c) 2018 Christer Stig Åke Landstedt".
DISPLAY " ".
DISPLAY
"Permission is hereby granted, free of charge, to any "
"person obtaining a copy of this software and "
"associated documentation files (the ""Software""), "
"to deal in the Software without restriction, "
"including without limitation the rights "
"to use, copy, modify, merge, publish, distribute, "
"sublicense, and/or sell copies of the Software,"
"and to permit persons to whom the Software is "
"furnished to do so, subject to the following "
"conditions:".
DISPLAY " ".
DISPLAY
"The above copyright notice and this permission notice "
"shall be included in all copies or substantial "
"portions of the Software.".
DISPLAY " ".
DISPLAY
"THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY "
"OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT "
"LIMITED TO THE WARRANTIES OF MERCHANTABILITY, "
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. "
"IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS "
"BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR "
"OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION "
"WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE "
"SOFTWARE.".
GO TO 0000SELECTIONSTART.
0000SELECTIONQUIT.
STOP-RUN.