-
Notifications
You must be signed in to change notification settings - Fork 4
/
ImportAttendees.cbl
127 lines (116 loc) · 4.35 KB
/
ImportAttendees.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
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
identification division.
program-id. ImportAttendees.
environment division.
configuration section.
repository.
function all intrinsic.
input-output section.
file-control.
select CSVSourceFile assign to CSVSourceFileName
organization is line sequential.
select optional AttendeesFile assign to AttendeesFileName
organization is indexed
access mode is dynamic
record key is AuthCode
file status is RecordWriteStatus.
data division.
file section.
fd CSVSourceFile.
01 CSVFileInputLine pic x(255).
88 EndOfCSVFile value high-values.
fd AttendeesFile is global.
copy DD-Attendee replacing Attendee by
==AttendeeRecord is global.
88 EndOfAttendeesFile value high-values==.
working-storage section.
01 CountOfLinesProcessed pic 999 value zero.
01 CountOfLinesImported pic 999 value zero.
copy DD-Attendee.
01 TempAttendeeData.
02 PaidDateFromWeb pic x(10).
02 ArrivalDayFromWeb pic x(10).
02 StayingLateFromWeb pic x(5).
01 AttendeesFileName pic x(20) value spaces.
01 CSVSourceFileName pic x(30) value spaces.
01 CommandLineArgumentCount pic 9 value zero.
01 RecordWriteStatus pic xx.
88 Successful value "00".
88 RecordExists value "22".
88 NoSuchRecord value "23".
procedure division.
accept CommandLineArgumentCount from argument-number
if CommandLineArgumentCount equal to 2 then
accept CSVSourceFileName from argument-value
accept AttendeesFileName from argument-value
else
move "barncamp-attendees.csv" to CSVSourceFileName
move "attendees.dat" to AttendeesFileName
end-if
display "Reading from " trim(CSVSourceFileName) " and writing to " trim(AttendeesFileName)
open input CSVSourceFile
open i-o AttendeesFile
read CSVSourceFile
at end set EndOfCSVFile to true
end-read
perform until EndOfCSVFile
initialize Attendee
unstring CSVFileInputLine
delimited by ","
into
AttendeeName of Attendee,
Email of Attendee,
AuthCode of Attendee,
AmountToPay of Attendee,
AmountPaid of Attendee,
PaidDateFromWeb,
Telephone of Attendee,
ArrivalDayFromWeb,
Diet of Attendee,
StayingLateFromWeb,
NumberOfKids of Attendee
end-unstring
if AuthCode of Attendee not equal to 'Code' and AuthCode of Attendee is not equal to spaces then
add 1 to CountOfLinesProcessed
move ArrivalDayFromWeb(1:3) to ArrivalDay of Attendee
if PaidDateFromWeb is not equal to spaces then
move PaidDateFromWeb(1:2) to CentuaryPaid of Attendee
move PaidDateFromWeb(3:2) to YearPaid of Attendee
move PaidDateFromWeb(6:2) to MonthPaid of Attendee
move PaidDateFromWeb(9:2) to DayPaid of Attendee
end-if
evaluate AmountPaid of Attendee
when greater than zero set AttendeePaid of Attendee to true
when less than or equal to zero set AttendeeNotPaid of Attendee to true
end-evaluate
if NumberOfKids of Attendee is less than zero or greater than 5 then
move zero to NumberOfKids of Attendee
end-if
set AttendeeComing of Attendee to true
if trim(StayingLateFromWeb) is equal to "true" then
set CanStayTillMonday of Attendee to true
else
set CanStayTillMonday of Attendee to false
end-if
write AttendeeRecord from Attendee
invalid key
if RecordExists
display "Record for " AuthCode of Attendee " already exists"
else
display "Error - status is " RecordWriteStatus
end-if
not invalid key
display "Imported record with authcode of " AuthCode of Attendee
add 1 to CountOfLinesImported
end-write
end-if
read CSVSourceFile
at end set EndOfCSVFile to true
end-read
end-perform
close AttendeesFile
close CSVSourceFile
display "Total attendees imported is " CountOfLinesImported
display "Total attendees processed is " CountOfLinesProcessed
stop run
.
end program ImportAttendees.