-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCORMOD.SQLRPGLE
159 lines (132 loc) · 3.9 KB
/
CORMOD.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
**FREE
Ctl-Opt NOMAIN;
/copy qrpgleref,siscpybk
Dcl-PROC Courser export;
Dcl-Pi Courser zoned(3);
hname char(10);
END-PI;
//Varibles
Dcl-S returnCode zoned(3);
Dcl-s courid zoned(5);
Dcl-s semesiD zoned(2);
Dcl-s sidesubID zoned(5);
Exec Sql SET OPTION COMMIT = *NONE;
cancel = *off;
exit = *off;
Husername = hname;
clear *all(newcourctl);
clear courmsg;
clear courmsg1;
//Clearing subfile
subclear = *off;
Write NewCourCtl;
RRN = 0;
subclear = *on;
//Loading Subfile
SetLL *start subMaster;
Read subMaster;
DoU (%EOF(subMaster));
RRN += 1;
Write NewCourSFL;
Read subMaster;
ENDDO;
//Writing Subfile: adding course and subjects
DoW (Exit = *Off AND Cancel = *Off);
write header;
write footerCour;
ExFmt NewCourCtl;
clear courmsg;
clear courmsg1;
ReadC NewCourSFL;
If (NewCourInp <> *BLANK AND SemInp <> *BLANK AND NwCourOpt = '1' AND save = *on);
//validating course exist or adding it
Exec Sql
Select courseID INTO :courID
FROM CorMaster
WHERE courseName = :NewCourInp;
If (SqlCode = 100); //autogenerates a new course if it doesn't already exist
SetGT *hival CorMaster;
ReadP(N) CorMaster;
CourseID = (CourseId + 10);
CourseName = %TRIM(NewCourInp);
write(E) cormasfmt;
ENDIF;
//validating semester exist
Exec Sql
Select SemID INTO :SemesID
FROM semmaster
WHERE Semester = :SemInp;
If (SqlCode = 100);
courMsg = 'Invalid Semester';
ENDIF;
//adding subjects if valid semester exists
If (SqlCode = 0);
ExSr AddSubject;
EndIf;
//throw error for blank input(s)
Else;
courMsg = 'Blanks not valid';
ENDIF; // saving
//Indicators
If (exit = *on);
Returncode = 222;
ElseIf (cancel = *on);
ReturnCode = 999;
ElseIf (refresh = *on);
clear *all(newcourctl);
clear courmsg;
clear courmsg1;
ENDIF;
ENDDO;
return returnCode;
//------------------------------------------------
// Adding several subjects to subcourse subroutine
// ------------------------------------------------
BegSR AddSubject;
//Writing first changed record
RRN = 0;
SUBJECTID = SUBJECTID;
If (CourId <> *ZERO); //If preexisting course is entered
CourseID = CourId;
Else; //If new courseId is entered
CourseID = CourseID;
EndIf;
SemID = SemesId;
Exec Sql
Select SubjectID INTO :sidesubID //validate that a subid semid and corid
FROM SubCourLF
WHERE CourseName = :NewCourInp
AND Semester = :semInp AND subjectID = :subjectID;
If (SqlCode = 100);
Write(e) SUBCORFMT; // Write to SubCourse File
EndIf;
clear nwCourOpt; // Clear first changed record
Update(E) NEWCOURSFL;
NxtChange = *On;
ReadC NEWCOURSFL;
//Writing all other changed records after first change
DoW Not %EoF();
SUBJECTID = SUBJECTID;
If (CourId <> *ZERO);
CourseID = CourId;
Else;
CourseID = CourseID;
EndIf;
SemID = SemesId;
Exec Sql
Select SubjectID INTO :sidesubID //validate that a subid semid and corid
FROM SubCourLF
WHERE CourseName = :NewCourInp
AND Semester = :semInp AND subjectID = :subjectID;
If (SqlCode = 100);
Write(e) SUBCORFMT;
EndIf;
clear nwCourOpt;
Update(E) NEWCOURSFL;
ReadC NEWCOURSFL;
EndDo;
NxtChange = *off;
CourMsg1 = ('Subjects added to courseID: ' + %CHAR(CourseID));
clear *all(NEWCOURCTL);
EndSr;
END-PROC;