DBA Data[Home] [Help]

PACKAGE BODY: APPS.GR_HAZARD_GROUPS_PKG

Source


1 PACKAGE BODY GR_HAZARD_GROUPS_PKG AS
2 /*$Header: GRHIHGB.pls 115.6 2002/10/25 19:51:34 methomas ship $*/
3 PROCEDURE Insert_Row
4 	   			 (p_commit IN VARCHAR2,
5 				  p_called_by_form IN VARCHAR2,
6 				  p_hazard_group_code IN VARCHAR2,
7 				  p_hazard_group_description IN VARCHAR2,
8 				  p_created_by IN NUMBER,
9 				  p_creation_date IN DATE,
10 				  p_last_updated_by IN NUMBER,
11 				  p_last_update_date IN DATE,
12 				  p_last_update_login IN NUMBER,
13 				  x_rowid OUT NOCOPY VARCHAR2,
14 				  x_return_status OUT NOCOPY VARCHAR2,
15 				  x_oracle_error OUT NOCOPY NUMBER,
16 				  x_msg_data OUT NOCOPY VARCHAR2)
17 	IS
18 /*   Alpha Variables */
19 
20 L_RETURN_STATUS VARCHAR2(1) := 'S';
21 L_KEY_EXISTS VARCHAR2(1);
22 L_MSG_DATA VARCHAR2(2000);
23 L_ROWID VARCHAR2(18);
24 
25 /*   Number Variables */
26 
27 L_ORACLE_ERROR	  NUMBER;
28 
29 /*   Exceptions */
30 
31 FOREIGN_KEY_ERROR EXCEPTION;
32 ITEM_EXISTS_ERROR EXCEPTION;
33 ROW_MISSING_ERROR EXCEPTION;
34 
35 /* Declare cursors */
36 
37 
38 BEGIN
39 
40 /*     Initialization Routine */
41 
42    SAVEPOINT Insert_Row;
43    x_return_status := 'S';
44    x_oracle_error := 0;
45    x_msg_data := NULL;
46 
47 /*	  Now call the check foreign key procedure */
48 
49    Check_Foreign_Keys
50 			     (p_hazard_group_code,
51 			      p_hazard_group_description,
52 				  l_return_status,
53 				  l_oracle_error,
54 				  l_msg_data);
55    IF l_return_status <> 'S' THEN
56       RAISE Foreign_Key_Error;
57    END IF;
58 
59 /* 	   Now check the primary key doesn't already exist */
60 
61    Check_Primary_Key
62    	   	   		 (p_hazard_group_code,
63 				  'F',
64 				  l_rowid,
65 				  l_key_exists);
66 
67    IF FND_API.To_Boolean(l_key_exists) THEN
68    	  RAISE Item_Exists_Error;
69    END IF;
70 
71    INSERT INTO gr_hazard_groups
72    		  	     (hazard_group_code,
73    		  	      hazard_group_description,
74 				  created_by,
75 				  creation_date,
76 				  last_updated_by,
77 				  last_update_date,
78 				  last_update_login)
79           VALUES
80 		         (p_hazard_group_code,
81 				  p_hazard_group_description,
82 				  p_created_by,
83 				  p_creation_date,
84 				  p_last_updated_by,
85 				  p_last_update_date,
86 				  p_last_update_login);
87 
88 /*   Now get the row id of the inserted record */
89 
90    Check_Primary_Key
91    	   	   		 (p_hazard_group_code,
92 				  'F',
93 				  l_rowid,
94 				  l_key_exists);
95 
96    IF FND_API.To_Boolean(l_key_exists) THEN
97    	  x_rowid := l_rowid;
98    ELSE
99    	  RAISE Row_Missing_Error;
100    END IF;
101 
102 /*   Check the commit flag and if set, then commit the work. */
103 
104    IF FND_API.To_Boolean(p_commit) THEN
105       COMMIT WORK;
106    END IF;
107 
108 EXCEPTION
109 
110    WHEN Foreign_Key_Error THEN
111       ROLLBACK TO SAVEPOINT Insert_Row;
112 	  x_return_status := l_return_status;
113 	  x_oracle_error := l_oracle_error;
114       FND_MESSAGE.SET_NAME('GR',
115                            'GR_FOREIGN_KEY_ERROR');
116       FND_MESSAGE.SET_TOKEN('TEXT',
117          		            l_msg_data,
118             			    FALSE);
119       IF FND_API.To_Boolean(p_called_by_form) THEN
120 	     APP_EXCEPTION.Raise_Exception;
121 	  ELSE
122          x_msg_data := FND_MESSAGE.Get;
123 	  END IF;
124 
125    WHEN Item_Exists_Error THEN
126       ROLLBACK TO SAVEPOINT Insert_Row;
127 	  x_return_status := 'E';
128 	  x_oracle_error := APP_EXCEPTION.Get_Code;
129       FND_MESSAGE.SET_NAME('GR',
130                            'GR_RECORD_EXISTS');
131       FND_MESSAGE.SET_TOKEN('CODE',
132          		            p_hazard_group_code,
133             			    FALSE);
134       IF FND_API.To_Boolean(p_called_by_form) THEN
135 	     APP_EXCEPTION.Raise_Exception;
136 	  ELSE
137          x_msg_data := FND_MESSAGE.Get;
138 	  END IF;
139 
140    WHEN Row_Missing_Error THEN
141       ROLLBACK TO SAVEPOINT Insert_Row;
142 	  x_return_status := 'E';
143 	  x_oracle_error := APP_EXCEPTION.Get_Code;
144       FND_MESSAGE.SET_NAME('GR',
145                            'GR_NO_RECORD_INSERTED');
146       FND_MESSAGE.SET_TOKEN('CODE',
147          		            p_hazard_group_code,
148             			    FALSE);
149       IF FND_API.To_Boolean(p_called_by_form) THEN
150 	     APP_EXCEPTION.Raise_Exception;
151 	  ELSE
152          x_msg_data := FND_MESSAGE.Get;
153 	  END IF;
154 
155    WHEN OTHERS THEN
156       ROLLBACK TO SAVEPOINT Insert_Row;
157 	  x_return_status := 'U';
158 	  x_oracle_error := APP_EXCEPTION.Get_Code;
159 	  l_msg_data := APP_EXCEPTION.Get_Text;
160 	  FND_MESSAGE.SET_NAME('GR',
161 	                       'GR_UNEXPECTED_ERROR');
162 	  FND_MESSAGE.SET_TOKEN('TEXT',
163 	                        l_msg_data,
164 	                        FALSE);
165       IF FND_API.To_Boolean(p_called_by_form) THEN
166 	     APP_EXCEPTION.Raise_Exception;
167 	  ELSE
168          x_msg_data := FND_MESSAGE.Get;
169 	  END IF;
170 
171 END Insert_Row;
172 
173 PROCEDURE Update_Row
174 	   			 (p_commit IN VARCHAR2,
175 				  p_called_by_form IN VARCHAR2,
176 				  p_rowid IN VARCHAR2,
177 				  p_hazard_group_code IN VARCHAR2,
178 				  p_hazard_group_description IN VARCHAR2,
179 				  p_created_by IN NUMBER,
180 				  p_creation_date IN DATE,
181 				  p_last_updated_by IN NUMBER,
182 				  p_last_update_date IN DATE,
183 				  p_last_update_login IN NUMBER,
184 				  x_return_status OUT NOCOPY VARCHAR2,
185 				  x_oracle_error OUT NOCOPY NUMBER,
186 				  x_msg_data OUT NOCOPY VARCHAR2)
187    IS
188 
189 /*   Alpha Variables */
190 
191 L_RETURN_STATUS	  VARCHAR2(1) := 'S';
192 L_MSG_DATA		  VARCHAR2(2000);
193 
194 /*   Number Variables */
195 
196 L_ORACLE_ERROR	  NUMBER;
197 
198 /*   Exceptions */
199 
200 FOREIGN_KEY_ERROR EXCEPTION;
201 ROW_MISSING_ERROR EXCEPTION;
202 
203 BEGIN
204 
205 /*       Initialization Routine */
206 
207    SAVEPOINT Update_Row;
208    x_return_status := 'S';
209    x_oracle_error := 0;
210    x_msg_data := NULL;
211 
212 /*	  Now call the check foreign key procedure */
213 
214    Check_Foreign_Keys
215 			     (p_hazard_group_code,
216 			      p_hazard_group_description,
217 				  l_return_status,
218 				  l_oracle_error,
219 				  l_msg_data);
220 
221    IF l_return_status <> 'S' THEN
222       RAISE Foreign_Key_Error;
223    ELSE
224       UPDATE gr_hazard_groups
225 	  SET	 hazard_group_code	 			 = p_hazard_group_code,
226 	         hazard_group_description 	 	 = p_hazard_group_description,
227 			 created_by						 = p_created_by,
228 			 creation_date					 = p_creation_date,
229 			 last_updated_by				 = p_last_updated_by,
230 			 last_update_date				 = p_last_update_date,
231 			 last_update_login				 = p_last_update_login
232 	  WHERE  rowid = p_rowid;
233 	  IF SQL%NOTFOUND THEN
234 	     RAISE Row_Missing_Error;
235 	  END IF;
236    END IF;
237 
238 /*   Check the commit flag and if set, then commit the work. */
239 
240    IF FND_API.To_Boolean(p_commit) THEN
241       COMMIT WORK;
242    END IF;
243 
244 EXCEPTION
245 
246    WHEN Foreign_Key_Error THEN
247       ROLLBACK TO SAVEPOINT Update_Row;
248 	  x_return_status := l_return_status;
249 	  x_oracle_error := l_oracle_error;
250       FND_MESSAGE.SET_NAME('GR',
251                            'GR_FOREIGN_KEY_ERROR');
252       FND_MESSAGE.SET_TOKEN('TEXT',
253          		            l_msg_data,
254             			    FALSE);
255       IF FND_API.To_Boolean(p_called_by_form) THEN
256 	     APP_EXCEPTION.Raise_Exception;
257 	  ELSE
258          x_msg_data := FND_MESSAGE.Get;
259 	  END IF;
260 
261    WHEN Row_Missing_Error THEN
262       ROLLBACK TO SAVEPOINT Update_Row;
263 	  x_return_status := 'E';
264 	  x_oracle_error := APP_EXCEPTION.Get_Code;
265       FND_MESSAGE.SET_NAME('GR',
266                            'GR_NO_RECORD_INSERTED');
267       FND_MESSAGE.SET_TOKEN('CODE',
268          		            p_hazard_group_code,
269             			    FALSE);
270       IF FND_API.To_Boolean(p_called_by_form) THEN
271 	     APP_EXCEPTION.Raise_Exception;
272 	  ELSE
273          x_msg_data := FND_MESSAGE.Get;
274 	  END IF;
275 
276    WHEN OTHERS THEN
277       ROLLBACK TO SAVEPOINT Update_Row;
278 	  x_return_status := 'U';
279 	  x_oracle_error := APP_EXCEPTION.Get_Code;
280 	  l_msg_data := APP_EXCEPTION.Get_Text;
281 	  FND_MESSAGE.SET_NAME('GR',
282 	                       'GR_UNEXPECTED_ERROR');
283 	  FND_MESSAGE.SET_TOKEN('TEXT',
284 	                        l_msg_data,
285 	                        FALSE);
286       IF FND_API.To_Boolean(p_called_by_form) THEN
287 	     APP_EXCEPTION.Raise_Exception;
288 	  ELSE
289          x_msg_data := FND_MESSAGE.Get;
290 	  END IF;
291 
292 END Update_Row;
293 
294 PROCEDURE Lock_Row
295 	   			 (p_commit IN VARCHAR2,
296 				  p_called_by_form IN VARCHAR2,
297 				  p_rowid IN VARCHAR2,
298 				  p_hazard_group_code IN VARCHAR2,
299 				  p_hazard_group_description IN VARCHAR2,
300 				  p_created_by IN NUMBER,
301 				  p_creation_date IN DATE,
302 				  p_last_updated_by IN NUMBER,
303 				  p_last_update_date IN DATE,
304 				  p_last_update_login IN NUMBER,
305 				  x_return_status OUT NOCOPY VARCHAR2,
306 				  x_oracle_error OUT NOCOPY NUMBER,
307 				  x_msg_data OUT NOCOPY VARCHAR2)
308    IS
309 
310 /*  Alpha Variables */
311 
312 L_RETURN_STATUS	  VARCHAR2(1) := 'S';
313 L_MSG_DATA		  VARCHAR2(2000);
314 
315 /*  Number Variables */
316 
317 L_ORACLE_ERROR	  NUMBER;
318 
319 /*   Exceptions */
320 
321 NO_DATA_FOUND_ERROR 		EXCEPTION;
322 ROW_ALREADY_LOCKED_ERROR 	EXCEPTION;
323 PRAGMA EXCEPTION_INIT(ROW_ALREADY_LOCKED_ERROR,-54);
324 
325 /*   Define the cursors */
326 
327 CURSOR c_lock_hazard_groups
328  IS
329    SELECT	*
330    FROM		gr_hazard_groups
331    WHERE	rowid = p_rowid
332    FOR UPDATE NOWAIT;
333 LockHazGrpRcd	  c_lock_hazard_groups%ROWTYPE;
334 BEGIN
335 
336 /*      Initialization Routine */
337 
338    SAVEPOINT Lock_Row;
339    x_return_status := 'S';
340    x_oracle_error := 0;
341    x_msg_data := NULL;
342 
343 /*	   Now lock the record */
344 
345    OPEN c_lock_hazard_groups;
346    FETCH c_lock_hazard_groups INTO LockHazGrpRcd;
347    IF c_lock_hazard_groups%NOTFOUND THEN
348 	  CLOSE c_lock_hazard_groups;
349 	  RAISE No_Data_Found_Error;
350    END IF;
351    CLOSE c_lock_hazard_groups;
352 
353    IF FND_API.To_Boolean(p_commit) THEN
354       COMMIT WORK;
355    END IF;
356 
357 EXCEPTION
358 
359    WHEN No_Data_Found_Error THEN
360       ROLLBACK TO SAVEPOINT Lock_Row;
361 	  x_return_status := 'E';
362 	  FND_MESSAGE.SET_NAME('GR',
363 	                       'GR_RECORD_NOT_FOUND');
364 	  FND_MESSAGE.SET_TOKEN('CODE',
365 	                        p_hazard_group_code,
366 							FALSE);
367       IF FND_API.To_Boolean(p_called_by_form) THEN
368 	     APP_EXCEPTION.Raise_Exception;
369 	  ELSE
370          x_msg_data := FND_MESSAGE.Get;
371 	  END IF;
372 
373    WHEN Row_Already_Locked_Error THEN
374       ROLLBACK TO SAVEPOINT Lock_Row;
375 	  x_return_status := 'E';
376 	  x_oracle_error := APP_EXCEPTION.Get_Code;
377 	  FND_MESSAGE.SET_NAME('GR',
378 	                       'GR_ROW_IS_LOCKED');
379       IF FND_API.To_Boolean(p_called_by_form) THEN
380 	     APP_EXCEPTION.Raise_Exception;
381 	  ELSE
382          x_msg_data := FND_MESSAGE.Get;
383 	  END IF;
384 
385    WHEN OTHERS THEN
386       ROLLBACK TO SAVEPOINT Lock_Row;
387 	  x_return_status := 'U';
388 	  x_oracle_error := APP_EXCEPTION.Get_Code;
389 	  l_msg_data := APP_EXCEPTION.Get_Text;
390 	  FND_MESSAGE.SET_NAME('GR',
391 	                       'GR_UNEXPECTED_ERROR');
392 	  FND_MESSAGE.SET_TOKEN('TEXT',
393 	                        l_msg_data,
394 	                        FALSE);
395       IF FND_API.To_Boolean(p_called_by_form) THEN
396 	     APP_EXCEPTION.Raise_Exception;
397 	  ELSE
398          x_msg_data := FND_MESSAGE.Get;
399 	  END IF;
400 
401 END Lock_Row;
402 
403 PROCEDURE Delete_Row
404 	   			 (p_commit IN VARCHAR2,
405 				  p_called_by_form IN VARCHAR2,
406 				  p_rowid IN VARCHAR2,
407 				  p_hazard_group_code IN VARCHAR2,
408 				  p_hazard_group_description IN VARCHAR2,
409 				  p_created_by IN NUMBER,
410 				  p_creation_date IN DATE,
411 				  p_last_updated_by IN NUMBER,
412 				  p_last_update_date IN DATE,
413 				  p_last_update_login IN NUMBER,
414 				  x_return_status OUT NOCOPY VARCHAR2,
415 				  x_oracle_error OUT NOCOPY NUMBER,
416 				  x_msg_data OUT NOCOPY VARCHAR2)
417    IS
418 
419 /*   Alpha Variables */
420 
421 L_RETURN_STATUS	  VARCHAR2(1) := 'S';
422 L_MSG_DATA		  VARCHAR2(2000);
423 L_CALLED_BY_FORM  VARCHAR2(1);
424 
425 /*   Number Variables */
426 
427 L_ORACLE_ERROR	  NUMBER;
428 
429 /*   Exceptions */
430 
431 CHECK_INTEGRITY_ERROR EXCEPTION;
432 ROW_MISSING_ERROR	  EXCEPTION;
433 PRAGMA EXCEPTION_INIT(Row_Missing_Error,100);
434 BEGIN
435 
436 /*   Initialization Routine */
437 
438    SAVEPOINT Delete_Row;
439    x_return_status := 'S';
440    l_called_by_form := 'F';
441    x_oracle_error := 0;
442    x_msg_data := NULL;
443 
444 /*  Now call the check integrity procedure */
445 
446    Check_Integrity
447 			     (l_called_by_form,
448 			      p_hazard_group_code,
449 			      p_hazard_group_description,
450 				  l_return_status,
451 				  l_oracle_error,
452 				  l_msg_data);
453 
454    IF l_return_status <> 'S' THEN
455       RAISE Check_Integrity_Error;
456    END IF;
457 
458    DELETE FROM gr_hazard_groups
459    WHERE  	   rowid = p_rowid;
460 
461 /*   Check the commit flag and if set, then commit the work. */
462 
463    IF FND_API.TO_Boolean(p_commit) THEN
464       COMMIT WORK;
465    END IF;
466 
467 EXCEPTION
468 
469    WHEN Check_Integrity_Error THEN
470       ROLLBACK TO SAVEPOINT Delete_Row;
471 	  x_return_status := l_return_status;
472 	  x_oracle_error := l_oracle_error;
473       IF FND_API.To_Boolean(p_called_by_form) THEN
474 	     APP_EXCEPTION.Raise_Exception;
475 	  ELSE
476          x_msg_data := FND_MESSAGE.Get;
477 	  END IF;
478 
479    WHEN Row_Missing_Error THEN
480       ROLLBACK TO SAVEPOINT Delete_Row;
481 	  x_return_status := 'E';
482 	  x_oracle_error := APP_EXCEPTION.Get_Code;
483       FND_MESSAGE.SET_NAME('GR',
484                            'GR_RECORD_NOT_FOUND');
485       FND_MESSAGE.SET_TOKEN('CODE',
486          		            p_hazard_group_code,
487             			    FALSE);
488       IF FND_API.To_Boolean(p_called_by_form) THEN
489 	     APP_EXCEPTION.Raise_Exception;
490 	  ELSE
491          x_msg_data := FND_MESSAGE.Get;
492 	  END IF;
493 
494    WHEN OTHERS THEN
495       ROLLBACK TO SAVEPOINT Delete_Row;
496 	  x_return_status := 'U';
497 	  x_oracle_error := APP_EXCEPTION.Get_Code;
498 	  l_msg_data := APP_EXCEPTION.Get_Text;
499 	  l_msg_data := APP_EXCEPTION.Get_Text;
500 	  FND_MESSAGE.SET_NAME('GR',
501 	                       'GR_UNEXPECTED_ERROR');
502 	  FND_MESSAGE.SET_TOKEN('TEXT',
503 	                        l_msg_data,
504 	                        FALSE);
505       IF FND_API.To_Boolean(p_called_by_form) THEN
506 	     APP_EXCEPTION.Raise_Exception;
507 	  ELSE
508          x_msg_data := FND_MESSAGE.Get;
509 	  END IF;
510 
511 END Delete_Row;
512 
513 PROCEDURE Check_Foreign_Keys
514 	   			 (p_hazard_group_code IN VARCHAR2,
515 	   			  p_hazard_group_description IN VARCHAR2,
516 				  x_return_status OUT NOCOPY VARCHAR2,
517 				  x_oracle_error OUT NOCOPY NUMBER,
518 				  x_msg_data OUT NOCOPY VARCHAR2)
519    IS
520 
521 /*   Alpha Variables */
522 
523 L_RETURN_STATUS	  VARCHAR2(1) := 'S';
524 L_MSG_DATA		  VARCHAR2(2000);
525 L_KEY_EXISTS	  VARCHAR2(1);
526 
527 /*   Number Variables */
528 
529 L_ORACLE_ERROR	  NUMBER;
530 L_ROWID			  NUMBER;
531 
532 /*   Define the cursors */
533 
534 BEGIN
535 
536 /*   Initialization Routine */
537 
538    SAVEPOINT Check_Foreign_Keys;
539    x_return_status := 'S';
540    x_oracle_error := 0;
541    l_msg_data := NULL;
542    x_msg_data := NULL;
543 
544 /*   No foreign key checking needed. */
545 
546    IF x_return_status <> 'S' THEN
547       x_msg_data := l_msg_data;
548    END IF;
549 
550 EXCEPTION
551 
552    WHEN OTHERS THEN
553       ROLLBACK TO SAVEPOINT Check_Foreign_Keys;
554 	  x_return_status := 'U';
555 	  x_oracle_error := APP_EXCEPTION.Get_Code;
556 	  l_msg_data := APP_EXCEPTION.Get_Text;
557 	  FND_MESSAGE.SET_NAME('GR',
558 	                       'GR_UNEXPECTED_ERROR');
559 	  FND_MESSAGE.SET_TOKEN('TEXT',
560 	                        l_msg_data,
561 	                        FALSE);
562 	  x_msg_data := FND_MESSAGE.Get;
563 
564 END Check_Foreign_Keys;
565 
566 PROCEDURE Check_Integrity
567 	   			 (p_called_by_form IN VARCHAR2,
568 	   			  p_hazard_group_code IN VARCHAR2,
569 	   			  p_hazard_group_description IN VARCHAR2,
570 				  x_return_status OUT NOCOPY VARCHAR2,
571 				  x_oracle_error OUT NOCOPY NUMBER,
572 				  x_msg_data OUT NOCOPY VARCHAR2)
573    IS
574 
575 /*   Alpha Variables */
576 
577 L_RETURN_STATUS	  VARCHAR2(1) := 'S';
578 L_MSG_DATA	  VARCHAR2(2000);
579 L_CODE_BLOCK	  VARCHAR2(30);
580 
581 /*   Number Variables */
582 
583 L_ORACLE_ERROR	  NUMBER;
584 L_RECORD_COUNT	  NUMBER;
585 
586 /*  Exception   */
587 INTEGRITY_ERROR		EXCEPTION;
588 
589 /*	 Define the Cursors */
590 /*   European Hazards Table */
591 
592 CURSOR c_get_eurohazards
593  IS
594    SELECT	COUNT(*)
595    FROM		gr_eurohazards_b
596    WHERE	hazard_group_code = p_hazard_group_code;
597 
598 BEGIN
599 
600 /*     Initialization Routine */
601 
602    SAVEPOINT Check_Integrity;
603    x_return_status := 'S';
604    x_oracle_error := 0;
605    x_msg_data := NULL;
606    l_msg_data := NULL;
607 
608 /*   Start with the European Hazards table */
609 
610    l_record_count := 0;
611    l_code_block := 'c_get_eurohazards';
612    OPEN c_get_eurohazards;
613    FETCH c_get_eurohazards INTO l_record_count;
614    IF l_record_count <> 0 THEN
615       l_return_status := 'E';
616       l_msg_data := l_msg_data || 'gr_eurohazards_b ';
617    END IF;
618    CLOSE c_get_eurohazards;
619 
620 /*	 Now sort out the error messaging */
621 
622    IF l_return_status <> 'S' THEN
623      RAISE INTEGRITY_ERROR;
624    END IF;
625 
626 EXCEPTION
627 
628    WHEN INTEGRITY_ERROR THEN
629       x_return_status := 'E';
630       FND_MESSAGE.SET_NAME('GR',
631                            'GR_INTEGRITY_HEADER');
632       FND_MESSAGE.SET_TOKEN('CODE',
633 	                    p_hazard_group_code,
634 	                    FALSE);
635       FND_MESSAGE.SET_TOKEN('TABLES',
636 	                    l_msg_data,
637 	                    FALSE);
638       IF FND_API.To_Boolean(p_called_by_form) THEN
639          APP_EXCEPTION.Raise_Exception;
640       ELSE
641         x_msg_data := FND_MESSAGE.Get;
642       END IF;
643    WHEN OTHERS THEN
644       ROLLBACK TO SAVEPOINT Check_Integrity;
645       x_return_status := 'U';
646       x_oracle_error := APP_EXCEPTION.Get_Code;
647       l_msg_data := APP_EXCEPTION.Get_Text;
648       FND_MESSAGE.SET_NAME('GR',
649                           'GR_UNEXPECTED_ERROR');
650       FND_MESSAGE.SET_TOKEN('TEXT',
651                             l_msg_data,
652                             FALSE);
653       IF FND_API.To_Boolean(p_called_by_form) THEN
654         APP_EXCEPTION.Raise_Exception;
655       ELSE
656         x_msg_data := FND_MESSAGE.Get;
657       END IF;
658 
659 END Check_Integrity;
660 
661 PROCEDURE Check_Primary_Key
662 /*		  p_hazard_group_code is the hazard_group code to check.
663 **		  p_called_by_form is 'T' if called by a form or 'F' if not.
664 **		  x_rowid is the row id of the record if found.
665 **		  x_key_exists is 'T' is the record is found, 'F' if not.
666 */
667 		  		 	(p_hazard_group_code IN VARCHAR2,
668 					 p_called_by_form IN VARCHAR2,
669 					 x_rowid OUT NOCOPY VARCHAR2,
670 					 x_key_exists OUT NOCOPY VARCHAR2)
671   IS
672 /*	Alphanumeric variables	 */
673 
674 L_MSG_DATA VARCHAR2(80);
675 
676 /*		Declare any variables and the cursor */
677 
678 
679 CURSOR c_get_hazard_group_rowid
680  IS
681    SELECT hg.rowid
682    FROM	  gr_hazard_groups hg
683    WHERE  hg.hazard_group_code = p_hazard_group_code;
684 HazGrpRecord			   c_get_hazard_group_rowid%ROWTYPE;
685 
686 BEGIN
687 
688    x_key_exists := 'F';
689    OPEN c_get_hazard_group_rowid;
690    FETCH c_get_hazard_group_rowid INTO HazGrpRecord;
691    IF c_get_hazard_group_rowid%FOUND THEN
692       x_key_exists := 'T';
693 	  x_rowid := HazGrpRecord.rowid;
694    ELSE
695       x_key_exists := 'F';
696    END IF;
697    CLOSE c_get_hazard_group_rowid;
698 
699 EXCEPTION
700 
701 	WHEN Others THEN
702 	  l_msg_data := APP_EXCEPTION.Get_Text;
703 	  FND_MESSAGE.SET_NAME('GR',
704 	                       'GR_UNEXPECTED_ERROR');
705 	  FND_MESSAGE.SET_TOKEN('TEXT',
706 	                        l_msg_data,
707 	                        FALSE);
708       IF FND_API.To_Boolean(p_called_by_form) THEN
709 	     APP_EXCEPTION.Raise_Exception;
710 	  END IF;
711 
712 END Check_Primary_Key;
713 
714 END GR_HAZARD_GROUPS_PKG;