-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDETMOD.SQLRPGLE
570 lines (455 loc) · 15.6 KB
/
DETMOD.SQLRPGLE
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
**FREE
Ctl-Opt NOMAIN;
/copy qrpgleref,siscpybk
Dcl-PROC stuDets export;
Dcl-Pi stuDets zoned(3);
hname char(10);
END-PI;
//varibles
Dcl-S returnCode zoned(3);
Dcl-S tempStuID zoned(5);
Dcl-S tempStuName char(25);
Dcl-S tempStuAddr char(25);
Dcl-S tempStucourID zoned(5);
Dcl-S tempSemID zoned(2);
Dcl-S tempmarks zoned(5);
Dcl-S tempSubID zoned(5);
Dcl-S tempsubname char(25);
Dcl-S tempcoursename char(25);
Dcl-S tempsemester char(10);
Exec Sql SET OPTION COMMIT = *NONE;
cancel = *off;
exit = *off;
Husername = hname;
clear *all(stuDetCTL);
clear detmsg;
clear detmsg1;
subclear3 = *on;
Write STUDETCTL;
subclear3 = *off;
DoW (exit = *off AND cancel = *off);
Write Footer3;
Write Header;
Exfmt StuDetCTL;
clear DetMsg;
clear DetMsg1;
//Searching
//1. Declare Cursor
//2. Open Cursor
//3. Fetch First matching record
//4. Populate & Turn subfile display ind on
//5. iterate relative record number & write to subfile
//6. Fetch Next matching record
//7. Loop through 5 & 6 till complete
// Note: SubRoutine Assign - assigns all variables to corresponding display varibles
// to reduce clutter
//******Search All***********
If ((StuIDInp <> *Zero OR NameInp <> *blank)
AND (CourIDInp <> *Zero OR CourInp <> *blank)
AND (SemInp <> *BLANK));
//Clear subfile:
subclear3 = *on;
Write STUDETCTL;
subclear3 = *off;
RRN = 0;
sflDsp = *off;
// check if open cursor
Exec Sql
Declare Ultcurs CURSOR
FOR
SELECT StuID, StuName, StudAddr, StuCourID, SemID, Marks, SubName
,CourseName, Semester
FROM StuDetLOG
WHERE (StuID = :StuIDInp OR StuName = :NameInp)
AND (StuCourID = :courIDInp OR CourseName = :courInp)
AND (Semester = :SemInp);
Exec Sql Open UltCurs;
Exec Sql
FETCH FROM UltCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign; //assigns all variables to corresponding display varibles
// subroutine to reduce clutter
If (sqlCode = 0);
sflDsp = *on; //turned back on so subfile can display now
EndIf;
DoW (SqlCode = 0); //populate subfile
RRN += 1;
write StuDetSFl;
Exec Sql
FETCH NEXT FROM UltCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
ENDDO;
Exec Sql Close UltCurs;
//****Search Student and Course****
ElseIf ((StuIDInp <> *Zero OR NameInp <> *blank) AND (courIDInp <> 0 OR courInp <> *blank));
//Clear subfile:
subclear3 = *on;
Write STUDETCTL;
RRN = 0;
subclear3 = *off;
sflDsp = *off;
Exec Sql
Declare stuCorcurs CURSOR
FOR
SELECT StuID, StuName, StudAddr, StuCourID, SemID, Marks, SubName
,CourseName, Semester
FROM StuDetLOG
WHERE (StuID = :StuIDInp OR StuName = :NameInp)
AND (StuCourID = :courIDInp OR CourseName = :courInp);
Exec Sql Open StuCorCurs;
Exec Sql
FETCH FROM StuCorCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
If (sqlCode = 0);
sflDsp = *on; //turned back on so subfile can display now
EndIf;
DoW (SqlCode = 0); //populate subfile
RRN += 1;
write StuDetSFl;
Exec Sql
FETCH NEXT FROM StuCorCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
ENDDO;
Exec Sql Close StuCorCurs;
//***Search Student and Semester****
ElseIf ((StuIDInp <> *Zero OR NameInp <> *blank) AND (SemInp <> *BLANK));
//Clear subfile:
subclear3 = *on;
Write STUDETCTL;
RRN = 0;
subclear3 = *off;
sflDsp = *off;
Exec Sql
Declare StuSemcurs CURSOR
FOR
SELECT StuID, StuName, StudAddr, StuCourID, SemID, Marks, SubName
,CourseName, Semester
FROM StuDetLOG
WHERE (Semester = :SemInp)
AND (StuCourID = :courIDInp OR SemId = :semInp);
Exec Sql Open StuSemCurs;
Exec Sql
FETCH FROM StuSemCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
If (sqlCode = 0);
sflDsp = *on; //turned back on so subfile can display now
EndIf;
DoW (SqlCode = 0); //populate subfile
RRN += 1;
write StuDetSFl;
Exec Sql
FETCH NEXT FROM StuSemCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
ENDDO;
Exec Sql Close StuSemCurs;
//****Search Course and Semester*****
ElseIf ((CourIDInp <> *Zero OR CourInp <> *blank) AND (SemInp <> *BLANK));
//Clear subfile:
subclear3 = *on;
Write STUDETCTL;
RRN = 0;
subclear3 = *off;
sflDsp = *off;
Exec Sql
Declare SemCorcurs CURSOR
FOR
SELECT StuID, StuName, StudAddr, StuCourID, SemID, Marks, SubName
,CourseName, Semester
FROM StuDetLOG
WHERE (Semester = :SemInp)
AND (StuCourID = :courIDInp OR CourseName = :courInp);
Exec Sql Open SemCorCurs;
Exec Sql
FETCH FROM SemCorCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
If (sqlCode = 0);
sflDsp = *on; //turned back on so subfile can display now
EndIf;
DoW (SqlCode = 0); //populate subfile
RRN += 1;
write StuDetSFl;
Exec Sql
FETCH NEXT FROM SemCorCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
ENDDO;
Exec Sql Close SemCorCurs;
//******Search Student*********
ElseIf (StuIDInp <> *Zero OR NameInp <> *blank); //search for student via name or ID#
//Clear subfile:
subclear3 = *on;
Write STUDETCTL;
RRN = 0;
subclear3 = *off;
sflDsp = *off;
Exec Sql
Declare stuCurs CURSOR
FOR
SELECT StuID, StuName, StudAddr, StuCourID, SemID, Marks, SubName
,CourseName, Semester
FROM StuDetLOG
WHERE StuID = :StuIDInp OR StuName = :NameInp;
Exec Sql Open StuCurs;
Exec Sql
FETCH FROM StuCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
If (sqlCode = 0);
sflDsp = *on; //turned back on so subfile can display now
EndIf;
DoW (SqlCode = 0); //populate subfile
RRN += 1;
write StuDetSFl;
Exec Sql
FETCH NEXT FROM StuCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
ENDDO;
Exec Sql Close StuCurs;
//*******Search Course********
ElseIf (courIDInp <> 0 OR courInp <> *blank);
//Clear subfile:
subclear3 = *on;
Write STUDETCTL;
RRN = 0;
subclear3 = *off;
sflDsp = *off;
Exec Sql
Declare CorCurs CURSOR
FOR
SELECT StuID, StuName, StudAddr, StuCourID, SemID, Marks, SubName
,CourseName, Semester
FROM StuDetLOG
WHERE StuCourID = :courIDInp OR CourseName = :courInp;
Exec Sql Open CorCurs;
Exec Sql
FETCH FROM CorCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
If (sqlCode = 0);
sflDsp = *on; //turned back on so subfile can display now
EndIf;
DoW (SqlCode = 0); //populate subfile
RRN += 1;
write StuDetSFl;
Exec Sql
FETCH NEXT FROM CorCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
ENDDO;
Exec Sql Close CorCurs;
//******Search Semester*******
ElseIf (SemInp <> *blank);
//Clear subfile:
subclear3 = *on;
Write STUDETCTL;
RRN = 0;
subclear3 = *off;
sflDsp = *off;
Exec Sql
Declare SemCurs CURSOR
FOR
SELECT StuID, StuName, StudAddr, StuCourID, SemID, Marks, SubName
,CourseName, Semester
FROM StuDetLOG
WHERE Semester = :SemInp;
Exec Sql Open SemCurs;
Exec Sql
FETCH FROM SemCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
If (sqlCode = 0);
sflDsp = *on; //turned back on so subfile can display now
EndIf;
DoW (SqlCode = 0); //populate subfile
RRN += 1;
write StuDetSFl;
Exec Sql
FETCH NEXT FROM SemCurs INTO :tempStuID, :tempStuName, :tempstuAddr,
:tempstucourID, :tempSemID, :tempMarks, :tempsubName, :tempCourseName,
:tempsemester;
ExSr Assign;
ENDDO;
Exec Sql Close SemCurs;
//catching all blanks
Else;
DetMsg = 'Blanks are not valid';
EndIF;
//*********EndOfSearch*************
//**********Subfile Option************
If (sfldsp = *on);
ReadC StuDetSFL;
//*********************************
// Update Marks
//*********************************
If (save = *on);
Chain StuID StuDetails;
Marks = DMarks; //marks from StuDetail = Marks from Dspf
Update(E) StuDetFMT;
DMARKS = Marks;
Update(E) StuDetSFL;
DetMsg1 = 'Marks Updated';
clear DetMsg;
ENDIF;
//***************************
// Add details 'A'
// **************************
If (OptInp = 'A');
//populate window
AddStuID = Stuid;
AddStuName = StuName;
AddCorName = CourseName;
AddSem = Semester;
AddSub = Subname;
addMarks = DMarks;
DoW (Exit = *Off AND Cancel = *Off);
ExFmt AddDets;
Chain StuID StuDetails;
//selecting the subjectID from subjectmaster file
//join submaster and subcourlf, a logical that takes subcourse and joins that with
//cormaster, semmaster, and submaster to give all the IDs in subcourse a name
//then uses where clause to validate that the subject exist in the course and semester
Exec Sql
SELECT sub.SubjectID INTO :tempSubID
FROM SubMaster AS sub
JOIN SUBCOURLF AS scour
ON sub.subjectID = scour.SubjectID
WHERE scour.CourseName = :Coursename
AND scour.Semester = :Semester
AND scour.SubName = :AddSub;
If (save = *on AND AddSub <> *blank
AND addMarks <> *ZERO AND SqlCode = 0); //Update Marks and Current Subject
SubjectID = tempSubID;
Marks = AddMarks;
update(E) StuDetFMT;
AddDetMsg1 = 'Save Successful';
ElseIf (save = *on AND AddSub <> *blank AND SqlCode <> *ZERO);
AddDetMsg = ('Not a valid subject');
EndIF;
//Indicators
If (refresh = *on);
clear AddDetMsg1;
clear AddDetMsg;
AddSub = Subname;
Addmarks = Marks;
ENDIF;
ENDDO;
clear AddDetMsg;
clear AddDetMsg1;
clear DetMsg;
clear optinp;
Dmarks = Addmarks;
SubName = AddSub;
update(E) stuDetSFL;
cancel = *off; //to control flow and only back out of window
ENDIF;
//***************************
// Change Semester 'C'
// **************************
If (OptInp = 'C');
//populate window
ChgStuID = StuID;
ChgStuName = StuName;
ChgCorName = CourseName;
ChgSem = Semester;
Chain StuId StuMaster; //chain stuID from logical to stumaster to update
// semester, changes reflect in logical
DoW (Exit = *Off AND Cancel = *Off);
ExFmt ChgSemWin;
clear chgSemMsg;
chain StuID StuMaster;
Exec Sql
Select SemId INTO :tempSemID
FROM SemMaster
WHERE Semester = :ChgSem;
If (save = *on AND ChgSem <> *BLANK
AND SqlCode = 0 AND tempSemID > semID);
SemId = tempSemID;
update(E) StuMasFmt;
ChgSemMsg1 = 'Update successful';
ElseIF (save = *on AND ChgSem <> *BLANK
AND (SqlCode = 100 OR tempSemID < SemID));
ChgSemMsg = 'Not a vaild Semester';
Else;
ChgSemMsg = 'blanks not valid'; //checks for blanks
ENDIF;
//Indicators
If (refresh = *on);
clear chgSemMsg;
clear chgSemMsg1;
ChgSem = Semester;
ENDIF;
EndDo;
SemID = tempSemID;
clear optInp;
clear chgSemMsg;
clear chgSemMsg1;
clear DetMsg;
update(E) StuDetSFL;
cancel = *off; //to control flow and only back out of window
ENDIF;
//***************************
// Delete 'D'
//***************************
If (OptInp = 'D');
DoW (YORN <> 'Y' AND YORN <> 'N');
clear optInp;
Exfmt confirmWin;
If (YORN = 'Y');
Exec Sql
Delete From StuDetails
Where StuID = :StuID AND subjectID =
(SELECT subjectID
FROM SUBMaster
WHERE subname = :subname);
ENDIF;
EndDo;
clear yorn;
clear DetMsg;
update StuDetSFL;
ENDIF;
ENDIF; //sfldsp = *on
//************************************************************
//Indicators
If (exit = *on);
returncode = 222;
ElseIf (cancel = *on);
returnCode = 999;
ElseIf (refresh = *on);
clear *all(stuDetCTL);
clear detmsg;
clear detmsg1;
ENDIF; //indicators
EndDo; ///EndDo for StuDets Screen
return returnCode;
BegSr Assign;
StuID = tempStuId;
StuName = tempStuName;
StudAddr = tempStuAddr;
CourseID = tempstuCourId;
SemID = tempSemId;
DMarks = tempMarks;
SubName = tempsubName;
CourseName = tempCourseName;
Semester = tempSemester;
ENDSR;
End-Proc;