DBA Data[Home] [Help]

PACKAGE BODY: APPS.IGS_HE_EN_SUSA_CC_PKG

Source


1 PACKAGE BODY igs_he_en_susa_cc_pkg AS
2 /* $Header: IGSWI44B.pls 120.2 2005/07/03 18:46:50 appldev ship $ */
3 
4   l_rowid VARCHAR2(25);
5   old_references igs_he_en_susa_cc%ROWTYPE;
6   new_references igs_he_en_susa_cc%ROWTYPE;
7 
8   PROCEDURE set_column_values (
9     p_action                            IN     VARCHAR2,
10     x_rowid                             IN     VARCHAR2,
11     x_he_susa_cc_id                     IN     NUMBER,
12     x_person_id                         IN     NUMBER,
13     x_course_cd                         IN     VARCHAR2,
14     x_unit_set_cd                       IN     VARCHAR2,
15     x_sequence_number                   IN     NUMBER,
16     x_cost_centre                       IN     VARCHAR2,
17     x_subject                           IN     VARCHAR2,
18     x_proportion                        IN     NUMBER,
19     x_creation_date                     IN     DATE,
20     x_created_by                        IN     NUMBER,
21     x_last_update_date                  IN     DATE,
22     x_last_updated_by                   IN     NUMBER,
23     x_last_update_login                 IN     NUMBER
24   ) AS
25   /*
26   ||  Created By : [email protected]
27   ||  Created On : 02-SEP-2003
28   ||  Purpose : Initialises the Old and New references for the columns of the table.
29   ||  Known limitations, enhancements or remarks :
30   ||  Change History :
31   ||  Who             When            What
32   ||  (reverse chronological order - newest change first)
33   */
34 
35     CURSOR cur_old_ref_values IS
36       SELECT   *
37       FROM     igs_he_en_susa_cc
38       WHERE    rowid = x_rowid;
39 
40   BEGIN
41 
42     l_rowid := x_rowid;
43 
44     -- Code for setting the Old and New Reference Values.
45     -- Populate Old Values.
46     OPEN cur_old_ref_values;
47     FETCH cur_old_ref_values INTO old_references;
48     IF ((cur_old_ref_values%NOTFOUND) AND (p_action NOT IN ('INSERT', 'VALIDATE_INSERT'))) THEN
49       CLOSE cur_old_ref_values;
50       fnd_message.set_name ('FND', 'FORM_RECORD_DELETED');
51       igs_ge_msg_stack.add;
52       app_exception.raise_exception;
53       RETURN;
54     END IF;
55     CLOSE cur_old_ref_values;
56 
57     -- Populate New Values.
58     new_references.he_susa_cc_id                     := x_he_susa_cc_id;
59     new_references.person_id                         := x_person_id;
60     new_references.course_cd                         := x_course_cd;
61     new_references.unit_set_cd                       := x_unit_set_cd;
62     new_references.sequence_number                   := x_sequence_number;
63     new_references.cost_centre                       := x_cost_centre;
64     new_references.subject                           := x_subject;
65     new_references.proportion                        := x_proportion;
66 
67     IF (p_action = 'UPDATE') THEN
68       new_references.creation_date                   := old_references.creation_date;
69       new_references.created_by                      := old_references.created_by;
70     ELSE
71       new_references.creation_date                   := x_creation_date;
72       new_references.created_by                      := x_created_by;
73     END IF;
74 
75     new_references.last_update_date                  := x_last_update_date;
76     new_references.last_updated_by                   := x_last_updated_by;
77     new_references.last_update_login                 := x_last_update_login;
78 
79   END set_column_values;
80 
81 
82   PROCEDURE check_uniqueness AS
83   /*
84   ||  Created By : [email protected]
85   ||  Created On : 02-SEP-2003
86   ||  Purpose : Handles the Unique Constraint logic defined for the columns.
87   ||  Known limitations, enhancements or remarks :
88   ||  Change History :
89   ||  Who             When            What
90   ||  (reverse chronological order - newest change first)
91   */
92   BEGIN
93 
94     IF ( get_uk_for_validation (
95            new_references.person_id,
96            new_references.course_cd,
97            new_references.unit_set_cd,
98            new_references.sequence_number,
99            new_references.cost_centre,
100            new_references.subject
101          )
102        ) THEN
103       fnd_message.set_name ('IGS', 'IGS_GE_RECORD_ALREADY_EXISTS');
104       igs_ge_msg_stack.add;
105       app_exception.raise_exception;
106     END IF;
107 
108   END check_uniqueness;
109 
110 
111   FUNCTION get_pk_for_validation (
112     x_he_susa_cc_id                     IN     NUMBER
113   ) RETURN BOOLEAN AS
114   /*
115   ||  Created By : [email protected]
116   ||  Created On : 02-SEP-2003
117   ||  Purpose : Validates the Primary Key of the table.
118   ||  Known limitations, enhancements or remarks :
119   ||  Change History :
120   ||  Who             When            What
121   ||  (reverse chronological order - newest change first)
122   */
123     CURSOR cur_rowid IS
124       SELECT   rowid
125       FROM     igs_he_en_susa_cc
126       WHERE    he_susa_cc_id = x_he_susa_cc_id
127       FOR UPDATE NOWAIT;
128 
129     lv_rowid cur_rowid%RowType;
130 
131   BEGIN
132 
133     OPEN cur_rowid;
134     FETCH cur_rowid INTO lv_rowid;
135     IF (cur_rowid%FOUND) THEN
136       CLOSE cur_rowid;
137       RETURN(TRUE);
138     ELSE
139       CLOSE cur_rowid;
140       RETURN(FALSE);
141     END IF;
142 
143   END get_pk_for_validation;
144 
145 
146   FUNCTION get_uk_for_validation (
147     x_person_id                         IN     NUMBER,
148     x_course_cd                         IN     VARCHAR2,
149     x_unit_set_cd                       IN     VARCHAR2,
150     x_sequence_number                   IN     NUMBER,
151     x_cost_centre                       IN     VARCHAR2,
152     x_subject                           IN     VARCHAR2
153   ) RETURN BOOLEAN AS
154   /*
155   ||  Created By : [email protected]
156   ||  Created On : 02-SEP-2003
157   ||  Purpose : Validates the Unique Keys of the table.
158   ||  Known limitations, enhancements or remarks :
159   ||  Change History :
160   ||  Who             When            What
161   ||  (reverse chronological order - newest change first)
162   */
163     CURSOR cur_rowid IS
164       SELECT   rowid
165       FROM     igs_he_en_susa_cc
166       WHERE    person_id = x_person_id
167       AND      course_cd = x_course_cd
168       AND      unit_set_cd = x_unit_set_cd
169       AND      sequence_number = x_sequence_number
170       AND      cost_centre = x_cost_centre
171       AND      subject = x_subject
172       AND      ((l_rowid IS NULL) OR (rowid <> l_rowid));
173 
174     lv_rowid cur_rowid%RowType;
175 
176   BEGIN
177 
178     OPEN cur_rowid;
179     FETCH cur_rowid INTO lv_rowid;
180     IF (cur_rowid%FOUND) THEN
181       CLOSE cur_rowid;
182         RETURN (true);
183         ELSE
184        CLOSE cur_rowid;
185       RETURN(FALSE);
186     END IF;
187 
188   END get_uk_for_validation ;
189 
190 
191   PROCEDURE before_dml (
192     p_action                            IN     VARCHAR2,
193     x_rowid                             IN     VARCHAR2,
194     x_he_susa_cc_id                     IN     NUMBER,
195     x_person_id                         IN     NUMBER,
196     x_course_cd                         IN     VARCHAR2,
197     x_unit_set_cd                       IN     VARCHAR2,
198     x_sequence_number                   IN     NUMBER,
199     x_cost_centre                       IN     VARCHAR2,
200     x_subject                           IN     VARCHAR2,
201     x_proportion                        IN     NUMBER,
202     x_creation_date                     IN     DATE,
203     x_created_by                        IN     NUMBER,
204     x_last_update_date                  IN     DATE,
205     x_last_updated_by                   IN     NUMBER,
206     x_last_update_login                 IN     NUMBER
207   ) AS
208   /*
209   ||  Created By : [email protected]
210   ||  Created On : 02-SEP-2003
211   ||  Purpose : Initialises the columns, Checks Constraints, Calls the
212   ||            Trigger Handlers for the table, before any DML operation.
213   ||  Known limitations, enhancements or remarks :
214   ||  Change History :
215   ||  Who             When            What
216   ||  (reverse chronological order - newest change first)
217   */
218   BEGIN
219 
220     set_column_values (
221       p_action,
222       x_rowid,
223       x_he_susa_cc_id,
224       x_person_id,
225       x_course_cd,
226       x_unit_set_cd,
227       x_sequence_number,
228       x_cost_centre,
229       x_subject,
230       x_proportion,
231       x_creation_date,
232       x_created_by,
233       x_last_update_date,
234       x_last_updated_by,
235       x_last_update_login
236     );
237 
238     IF (p_action = 'INSERT') THEN
239       -- Call all the procedures related to Before Insert.
240       IF ( get_pk_for_validation(
241              new_references.he_susa_cc_id
242            )
243          ) THEN
244         fnd_message.set_name('IGS','IGS_GE_RECORD_ALREADY_EXISTS');
245         igs_ge_msg_stack.add;
246         app_exception.raise_exception;
247       END IF;
248       check_uniqueness;
249     ELSIF (p_action = 'UPDATE') THEN
250       -- Call all the procedures related to Before Update.
251       check_uniqueness;
252     ELSIF (p_action = 'VALIDATE_INSERT') THEN
253       -- Call all the procedures related to Before Insert.
254       IF ( get_pk_for_validation (
255              new_references.he_susa_cc_id
256            )
257          ) THEN
258         fnd_message.set_name('IGS','IGS_GE_RECORD_ALREADY_EXISTS');
259         igs_ge_msg_stack.add;
260         app_exception.raise_exception;
261       END IF;
262       check_uniqueness;
263     ELSIF (p_action = 'VALIDATE_UPDATE') THEN
264       check_uniqueness;
265     END IF;
266 
267     IF (p_action IN ('VALIDATE_INSERT', 'VALIDATE_UPDATE', 'VALIDATE_DELETE')) THEN
268       l_rowid := NULL;
269     END IF;
270 
271   END before_dml;
272 
273 
274   PROCEDURE insert_row (
275     x_rowid                             IN OUT NOCOPY VARCHAR2,
276     x_he_susa_cc_id                     IN OUT NOCOPY NUMBER,
277     x_person_id                         IN     NUMBER,
278     x_course_cd                         IN     VARCHAR2,
279     x_unit_set_cd                       IN     VARCHAR2,
280     x_sequence_number                   IN     NUMBER,
281     x_cost_centre                       IN     VARCHAR2,
282     x_subject                           IN     VARCHAR2,
283     x_proportion                        IN     NUMBER,
284     x_mode                              IN     VARCHAR2
285   ) AS
286   /*
287   ||  Created By : [email protected]
288   ||  Created On : 02-SEP-2003
289   ||  Purpose : Handles the INSERT DML logic for the table.
290   ||  Known limitations, enhancements or remarks :
291   ||  Change History :
292   ||  Who             When            What
293   ||  (reverse chronological order - newest change first)
294   */
295 
296     x_last_update_date           DATE;
297     x_last_updated_by            NUMBER;
298     x_last_update_login          NUMBER;
299 
300   BEGIN
301 
302     x_last_update_date := SYSDATE;
303     IF (x_mode = 'I') THEN
304       x_last_updated_by := 1;
305       x_last_update_login := 0;
306     ELSIF (X_MODE IN ('R', 'S')) THEN
307       x_last_updated_by := fnd_global.user_id;
308       IF (x_last_updated_by IS NULL) THEN
309         x_last_updated_by := -1;
310       END IF;
311       x_last_update_login := fnd_global.login_id;
312       IF (x_last_update_login IS NULL) THEN
313         x_last_update_login := -1;
314       END IF;
315     ELSE
316       fnd_message.set_name ('FND', 'SYSTEM-INVALID ARGS');
317       fnd_message.set_token ('ROUTINE', 'IGS_HE_EN_SUSA_CC_PKG.INSERT_ROW');
318       igs_ge_msg_stack.add;
319       app_exception.raise_exception;
320     END IF;
321 
322     x_he_susa_cc_id := NULL;
323 
324     before_dml(
325       p_action                            => 'INSERT',
326       x_rowid                             => x_rowid,
327       x_he_susa_cc_id                     => x_he_susa_cc_id,
328       x_person_id                         => x_person_id,
329       x_course_cd                         => x_course_cd,
330       x_unit_set_cd                       => x_unit_set_cd,
331       x_sequence_number                   => x_sequence_number,
332       x_cost_centre                       => x_cost_centre,
333       x_subject                           => x_subject,
334       x_proportion                        => x_proportion,
335       x_creation_date                     => x_last_update_date,
336       x_created_by                        => x_last_updated_by,
337       x_last_update_date                  => x_last_update_date,
338       x_last_updated_by                   => x_last_updated_by,
339       x_last_update_login                 => x_last_update_login
340     );
341 
342      IF (x_mode = 'S') THEN
343     igs_sc_gen_001.set_ctx('R');
344   END IF;
345  INSERT INTO igs_he_en_susa_cc (
346       he_susa_cc_id,
347       person_id,
348       course_cd,
349       unit_set_cd,
350       sequence_number,
351       cost_centre,
352       subject,
353       proportion,
354       creation_date,
355       created_by,
356       last_update_date,
357       last_updated_by,
358       last_update_login
359     ) VALUES (
360       igs_he_en_susa_cc_s.NEXTVAL,
361       new_references.person_id,
362       new_references.course_cd,
363       new_references.unit_set_cd,
364       new_references.sequence_number,
365       new_references.cost_centre,
366       new_references.subject,
367       new_references.proportion,
368       x_last_update_date,
369       x_last_updated_by,
370       x_last_update_date,
371       x_last_updated_by,
372       x_last_update_login
373     ) RETURNING ROWID, he_susa_cc_id INTO x_rowid, x_he_susa_cc_id;
374  IF (x_mode = 'S') THEN
375     igs_sc_gen_001.unset_ctx('R');
376   END IF;
377 
378 
379     l_rowid := NULL;
380 
381 
382 EXCEPTION
383   WHEN OTHERS THEN
384     IF (SQLCODE IN (-28115, -28113, -28111)) THEN
385       fnd_message.set_name ('IGS', 'IGS_SC_POLICY_EXCEPTION');
386       fnd_message.set_token ('ERR_CD', SQLCODE);
387       igs_ge_msg_stack.add;
388       igs_sc_gen_001.unset_ctx('R');
389       app_exception.raise_exception;
390     ELSE
391       igs_sc_gen_001.unset_ctx('R');
392       RAISE;
393     END IF;
394  END insert_row;
395 
396 
397   PROCEDURE lock_row (
398     x_rowid                             IN     VARCHAR2,
399     x_he_susa_cc_id                     IN     NUMBER,
400     x_person_id                         IN     NUMBER,
401     x_course_cd                         IN     VARCHAR2,
402     x_unit_set_cd                       IN     VARCHAR2,
403     x_sequence_number                   IN     NUMBER,
404     x_cost_centre                       IN     VARCHAR2,
405     x_subject                           IN     VARCHAR2,
406     x_proportion                        IN     NUMBER
407   ) AS
408   /*
409   ||  Created By : [email protected]
410   ||  Created On : 02-SEP-2003
411   ||  Purpose : Handles the LOCK mechanism for the table.
412   ||  Known limitations, enhancements or remarks :
413   ||  Change History :
414   ||  Who             When            What
415   ||  (reverse chronological order - newest change first)
416   */
417     CURSOR c1 IS
418       SELECT
419         person_id,
420         course_cd,
421         unit_set_cd,
422         sequence_number,
423         cost_centre,
424         subject,
425         proportion
426       FROM  igs_he_en_susa_cc
427       WHERE rowid = x_rowid
428       FOR UPDATE NOWAIT;
429 
430     tlinfo c1%ROWTYPE;
431 
432   BEGIN
433 
434     OPEN c1;
435     FETCH c1 INTO tlinfo;
436     IF (c1%notfound) THEN
437       fnd_message.set_name('FND', 'FORM_RECORD_DELETED');
438       igs_ge_msg_stack.add;
439       CLOSE c1;
440       app_exception.raise_exception;
441       RETURN;
442     END IF;
443     CLOSE c1;
444 
445     IF (
446         (tlinfo.person_id = x_person_id)
447         AND (tlinfo.course_cd = x_course_cd)
448         AND (tlinfo.unit_set_cd = x_unit_set_cd)
449         AND (tlinfo.sequence_number = x_sequence_number)
450         AND (tlinfo.cost_centre = x_cost_centre)
451         AND (tlinfo.subject = x_subject)
452         AND (tlinfo.proportion = x_proportion)
453        ) THEN
454       NULL;
455     ELSE
456       fnd_message.set_name('FND', 'FORM_RECORD_CHANGED');
457       igs_ge_msg_stack.add;
458       app_exception.raise_exception;
459     END IF;
460 
461     RETURN;
462 
463   END lock_row;
464 
465 
466   PROCEDURE update_row (
467     x_rowid                             IN     VARCHAR2,
468     x_he_susa_cc_id                     IN     NUMBER,
469     x_person_id                         IN     NUMBER,
470     x_course_cd                         IN     VARCHAR2,
471     x_unit_set_cd                       IN     VARCHAR2,
472     x_sequence_number                   IN     NUMBER,
473     x_cost_centre                       IN     VARCHAR2,
474     x_subject                           IN     VARCHAR2,
475     x_proportion                        IN     NUMBER,
476     x_mode                              IN     VARCHAR2
477   ) AS
478   /*
479   ||  Created By : [email protected]
480   ||  Created On : 02-SEP-2003
481   ||  Purpose : Handles the UPDATE DML logic for the table.
482   ||  Known limitations, enhancements or remarks :
483   ||  Change History :
484   ||  Who             When            What
485   ||  (reverse chronological order - newest change first)
486   */
487     x_last_update_date           DATE ;
488     x_last_updated_by            NUMBER;
489     x_last_update_login          NUMBER;
490 
491   BEGIN
492 
493     x_last_update_date := SYSDATE;
494     IF (X_MODE = 'I') THEN
495       x_last_updated_by := 1;
496       x_last_update_login := 0;
497     ELSIF (X_MODE IN ('R', 'S')) THEN
498       x_last_updated_by := fnd_global.user_id;
499       IF x_last_updated_by IS NULL THEN
500         x_last_updated_by := -1;
501       END IF;
502       x_last_update_login := fnd_global.login_id;
503       IF (x_last_update_login IS NULL) THEN
504         x_last_update_login := -1;
505       END IF;
506     ELSE
507       fnd_message.set_name( 'FND', 'SYSTEM-INVALID ARGS');
508       fnd_message.set_token ('ROUTINE', 'IGS_HE_EN_SUSA_CC_PKG.UPDATE_ROW');
509       igs_ge_msg_stack.add;
510       app_exception.raise_exception;
511     END IF;
512 
513     before_dml(
514       p_action                            => 'UPDATE',
515       x_rowid                             => x_rowid,
516       x_he_susa_cc_id                     => x_he_susa_cc_id,
517       x_person_id                         => x_person_id,
518       x_course_cd                         => x_course_cd,
519       x_unit_set_cd                       => x_unit_set_cd,
520       x_sequence_number                   => x_sequence_number,
521       x_cost_centre                       => x_cost_centre,
522       x_subject                           => x_subject,
523       x_proportion                        => x_proportion,
524       x_creation_date                     => x_last_update_date,
525       x_created_by                        => x_last_updated_by,
526       x_last_update_date                  => x_last_update_date,
527       x_last_updated_by                   => x_last_updated_by,
528       x_last_update_login                 => x_last_update_login
529     );
530 
531      IF (x_mode = 'S') THEN
532     igs_sc_gen_001.set_ctx('R');
533   END IF;
534  UPDATE igs_he_en_susa_cc
535       SET
536         person_id                         = new_references.person_id,
537         course_cd                         = new_references.course_cd,
538         unit_set_cd                       = new_references.unit_set_cd,
539         sequence_number                   = new_references.sequence_number,
540         cost_centre                       = new_references.cost_centre,
541         subject                           = new_references.subject,
542         proportion                        = new_references.proportion,
543         last_update_date                  = x_last_update_date,
544         last_updated_by                   = x_last_updated_by,
545         last_update_login                 = x_last_update_login
546       WHERE rowid = x_rowid;
547 
548     IF (SQL%NOTFOUND) THEN
549      fnd_message.set_name ('IGS', 'IGS_SC_POLICY_UPD_DEL_EXCEP');
550      igs_ge_msg_stack.add;
551      igs_sc_gen_001.unset_ctx('R');
552      app_exception.raise_exception;
553  END IF;
554  IF (x_mode = 'S') THEN
555     igs_sc_gen_001.unset_ctx('R');
556   END IF;
557 
558 
559     l_rowid := NULL;
560 
561   EXCEPTION
562     WHEN OTHERS THEN
563       IF (SQLCODE = (-28115)) THEN
564         fnd_message.set_name ('IGS', 'IGS_SC_UPD_POLICY_EXCP');
565         fnd_message.set_token ('ERR_CD', SQLCODE);
566         igs_ge_msg_stack.add;
567         igs_sc_gen_001.unset_ctx('R');
568         app_exception.raise_exception;
569       ELSE
570         igs_sc_gen_001.unset_ctx('R');
571         RAISE;
572       END IF;
573 
574   END update_row;
575 
576 
577   PROCEDURE add_row (
578     x_rowid                             IN OUT NOCOPY VARCHAR2,
579     x_he_susa_cc_id                     IN OUT NOCOPY NUMBER,
580     x_person_id                         IN     NUMBER,
581     x_course_cd                         IN     VARCHAR2,
582     x_unit_set_cd                       IN     VARCHAR2,
583     x_sequence_number                   IN     NUMBER,
584     x_cost_centre                       IN     VARCHAR2,
585     x_subject                           IN     VARCHAR2,
586     x_proportion                        IN     NUMBER,
587     x_mode                              IN     VARCHAR2
588   ) AS
589   /*
590   ||  Created By : [email protected]
591   ||  Created On : 02-SEP-2003
592   ||  Purpose : Adds a row if there is no existing row, otherwise updates existing row in the table.
593   ||  Known limitations, enhancements or remarks :
594   ||  Change History :
595   ||  Who             When            What
596   ||  (reverse chronological order - newest change first)
597   */
598     CURSOR c1 IS
599       SELECT   rowid
600       FROM     igs_he_en_susa_cc
601       WHERE    he_susa_cc_id                     = x_he_susa_cc_id;
602 
603   BEGIN
604 
605     OPEN c1;
606     FETCH c1 INTO x_rowid;
607     IF (c1%NOTFOUND) THEN
608       CLOSE c1;
609 
610       insert_row (
611         x_rowid,
612         x_he_susa_cc_id,
613         x_person_id,
614         x_course_cd,
615         x_unit_set_cd,
616         x_sequence_number,
617         x_cost_centre,
618         x_subject,
619         x_proportion,
620         x_mode
621       );
622       RETURN;
623     END IF;
624     CLOSE c1;
625 
626     update_row (
627       x_rowid,
628       x_he_susa_cc_id,
629       x_person_id,
630       x_course_cd,
631       x_unit_set_cd,
632       x_sequence_number,
633       x_cost_centre,
634       x_subject,
635       x_proportion,
636       x_mode
637     );
638 
639   END add_row;
640 
641 
642   PROCEDURE delete_row (
643     x_rowid IN VARCHAR2,
644   x_mode IN VARCHAR2
645   ) AS
646   /*
647   ||  Created By : [email protected]
648   ||  Created On : 02-SEP-2003
649   ||  Purpose : Handles the DELETE DML logic for the table.
650   ||  Known limitations, enhancements or remarks :
651   ||  Change History :
652   ||  Who             When            What
653   ||  (reverse chronological order - newest change first)
654   */
655   BEGIN
656 
657     before_dml (
658       p_action => 'DELETE',
659       x_rowid => x_rowid
660     );
661 
662      IF (x_mode = 'S') THEN
663     igs_sc_gen_001.set_ctx('R');
664   END IF;
665  DELETE FROM igs_he_en_susa_cc
666     WHERE rowid = x_rowid;
667 
668     IF (SQL%NOTFOUND) THEN
669      fnd_message.set_name ('IGS', 'IGS_SC_POLICY_UPD_DEL_EXCEP');
670      igs_ge_msg_stack.add;
671      igs_sc_gen_001.unset_ctx('R');
672      app_exception.raise_exception;
673  END IF;
674  IF (x_mode = 'S') THEN
675     igs_sc_gen_001.unset_ctx('R');
676   END IF;
677 
678 
679     l_rowid := NULL;
680 
681   END delete_row;
682 
683 
684 END igs_he_en_susa_cc_pkg;