[Home] [Help]
PACKAGE BODY: APPS.CSI_II_RELATIONSHIPS_PVT
Source
1 PACKAGE BODY csi_ii_relationships_pvt AS
2 /* $Header: csiviirb.pls 120.12 2008/03/08 01:08:26 fli ship $ */
3 -- start of comments
4 -- package name : csi_ii_relationships_pvt
5 -- purpose :
6 -- history :
7 -- note :
8 -- END of comments
9
10
11 g_pkg_name CONSTANT VARCHAR2(30) := 'csi_ii_relationships_pvt';
12 g_file_name CONSTANT VARCHAR2(12) := 'csiviirb.pls';
13
14 /* Cyclic Relationships */
15
16 /* TYPE instance_rec IS RECORD
17 ( instance_id NUMBER,
18 hop NUMBER );
19
20 TYPE instance_tbl IS TABLE OF instance_rec
21 INDEX BY BINARY_INTEGER ;
22 */
23 PROCEDURE get_cyclic_relationships
24 (
25 p_api_version IN NUMBER,
26 p_commit IN VARCHAR2,
27 p_init_msg_list IN VARCHAR2,
28 p_validation_level IN NUMBER,
29 p_instance_id IN NUMBER ,
30 p_depth IN NUMBER,
31 p_time_stamp IN DATE,
32 p_active_relationship_only IN VARCHAR2,
33 x_relationship_tbl OUT NOCOPY csi_datastructures_pub.ii_relationship_tbl,
34 x_return_status OUT NOCOPY VARCHAR2,
35 x_msg_count OUT NOCOPY NUMBER,
36 x_msg_data OUT NOCOPY VARCHAR2
37 )
38 IS
39 l_neighbor_inst_tbl instance_tbl;
40 l_visited_tbl instance_tbl;
41 l_visited_index INTEGER;
42 l_non_visited_tbl instance_tbl;
43 l_non_visited_index INTEGER;
44 l_cur_instance_id NUMBER;
45 l_in_visited_tbl BOOLEAN;
46 l_in_non_visited_tbl BOOLEAN;
47 l_pass_number NUMBER := 0;
48 l_first_non_vis_ind INTEGER;
49
50 l_non_visited_tbl_cnt NUMBER ;
51 l_start_time VARCHAR2(60);
52 l_end_time VARCHAR2(60);
53 l_non_vis_start NUMBER ;
54 l_api_name CONSTANT VARCHAR2(50) := 'get_cyclic_relationships';
55 l_api_version CONSTANT NUMBER := 1.0;
56 l_return_status_full VARCHAR2(1);
57 l_debug_level NUMBER;
58 l_cur_hop NUMBER;
59 BEGIN
60 -- standard start of api savepoint
61 --SAVEPOINT get_cylic_relationships_pvt;
62
63 -- standard call to check for call compatibility.
64 IF NOT fnd_api.compatible_api_call ( l_api_version,
65 p_api_version,
66 l_api_name,
67 g_pkg_name)
68 THEN
69 RAISE fnd_api.g_exc_unexpected_error;
70 END IF;
71
72 -- initialize message list if p_init_msg_list is set to true.
73 IF fnd_api.to_boolean( p_init_msg_list )
74 THEN
75 fnd_msg_pub.initialize;
76 END IF;
77
78 -- initialize api return status to success
79 x_return_status := fnd_api.g_ret_sts_success;
80 l_debug_level := fnd_profile.value('CSI_DEBUG_LEVEL');
81
82 IF (l_debug_level > 0) THEN
83 CSI_gen_utility_pvt.put_line( 'get_cyclic_relationships');
84 END IF;
85
86 IF (l_debug_level > 1) THEN
87 CSI_gen_utility_pvt.put_line(
88 p_api_version ||'-'||
89 p_commit ||'-'||
90 p_init_msg_list ||'-'||
91 p_validation_level ||'-'||
92 p_instance_id ||'-'||
93 p_time_stamp ||'-'||
94 p_active_relationship_only );
95
96 END IF;
97
98 --
99 -- API BODY
100 --
101 -- ******************************************************************
102 -- validate environment
103 -- ******************************************************************
104
105 IF p_instance_id IS NULL
106 THEN
107 fnd_message.set_name('CSI', 'CSI_INVALID_PARAMETERS');
108 fnd_msg_pub.add;
109 x_return_status := fnd_api.g_ret_sts_error;
110 RAISE fnd_api.g_exc_error;
111 END IF;
112
113 select to_char(sysdate,'YY-MON-DD HH:MI:SS')
114 into l_start_time
115 from dual ;
116
117 -- Initialize the given instance to non-visited table
118
119 l_non_visited_tbl(1).instance_id := p_instance_id ;
120 l_non_visited_tbl(1).hop := 0 ;
121 l_pass_number := 0;
122 l_non_visited_tbl_cnt := 1 ;
123 l_non_vis_start := 0 ;
124
125 WHILE l_non_visited_tbl.COUNT > 0
126 LOOP
127 -- Get the first element from Non-Visited table, Note that this may not
128 -- be having index of 1, it may have 5, 1, 10 etc.
129
130 l_non_visited_index := l_non_visited_tbl.FIRST;
131 l_cur_instance_id := l_non_visited_tbl(l_non_visited_index).instance_id ;
132 l_cur_hop := l_non_visited_tbl(l_non_visited_index).hop ;
133
134 -- Now delete this instance from Non-visited table
135
136 l_non_visited_tbl.DELETE(l_non_visited_index);
137 l_non_vis_start := l_non_vis_start + 1 ;
138
139 -- Get All the Relationships for l_cur_instance_id and populate it in x_relationship_tbl,
140 -- If that relationship does not exists. get_rel_for_instance will populate the relationship
141 -- for l_cur_instance_id only if it does not already exists in x_relationship_tbl
142
143 IF p_depth IS NOT NULL
144 THEN
145 IF l_cur_hop+1 <= p_depth
146 THEN
147 get_rel_for_instance(
148 l_cur_instance_id,
149 p_time_stamp,
150 p_active_relationship_only ,
151 x_relationship_tbl);
152 END IF ;
153 ELSE
154 -- p_depth is null so get all the relations
155 get_rel_for_instance(l_cur_instance_id,
156 p_time_stamp,
157 p_active_relationship_only,
158 x_relationship_tbl);
159 END IF ;
160
161 -- Now Push this Instance into Visited table.
162 l_visited_index := NVL(l_visited_tbl.LAST,0) + 1 ;
163 l_visited_tbl(l_visited_index).instance_id := l_cur_instance_id ;
164
165 -- Get neighbor Instances for l_cur_instance_id
166 get_neighbors_for_instance(l_cur_instance_id ,
167 l_cur_hop ,
168 p_depth ,
169 p_time_stamp ,
170 p_active_relationship_only ,
171 l_neighbor_inst_tbl);
172
173 FOR i IN 1..l_neighbor_inst_tbl.COUNT
174 LOOP
175 l_in_visited_tbl := FALSE ;
176 l_in_non_visited_tbl := FALSE ;
177
178 -- Check if this instance is in Visited Table
179 FOR j IN 1..l_visited_tbl.COUNT
180 LOOP
181 IF l_neighbor_inst_tbl(i).instance_id = l_visited_tbl(j).instance_id
182 THEN
183 l_in_visited_tbl := TRUE ;
184 EXIT ;
185 END IF ;
186 END LOOP ;
187
188 -- Check if this instance is in Non Visited Table
189 IF NOT l_in_visited_tbl
190 THEN
191 FOR k IN l_non_vis_start..l_non_visited_tbl_cnt
192 LOOP
193 BEGIN
194 IF l_neighbor_inst_tbl(i).instance_id = l_non_visited_tbl(k).instance_id
195 THEN
196 l_in_non_visited_tbl := TRUE ;
197 EXIT ;
198 END IF ;
199 EXCEPTION
200 WHEN NO_DATA_FOUND THEN
201 -- There is a gap in the range so ignore and go ahead
202 NULL ;
203 END ;
204 END LOOP ; --l_non_vis_start..l_non_visited_tbl_cnt
205 END IF ;
206
207 IF NOT (l_in_visited_tbl OR l_in_non_visited_tbl)
208 THEN
209 -- As this instance is neither in Visited Table nor in Non-Visited Table,
210 -- Push this Instance into Non Visited table.
211
212 l_non_visited_index := NVL(l_non_visited_tbl.LAST,0) + 1 ;
213 l_non_visited_tbl(l_non_visited_index).instance_id := l_neighbor_inst_tbl(i).instance_id ;
214 l_non_visited_tbl(l_non_visited_index).hop := l_neighbor_inst_tbl(i).
215 hop ;
216 l_non_visited_tbl_cnt := l_non_visited_tbl_cnt+1 ;
217
218 END IF ;
219 END LOOP ; -- l_neighbor_inst_tbl.COUNT;
220 l_pass_number := l_pass_number+1 ;
221
222 END LOOP ; -- l_non_visited_tbl.COUNT > 0
223
224 select to_char(sysdate,'YY-MON-DD HH:MI:SS')
225 into l_end_time
226 from dual ;
227
228 EXCEPTION
229 WHEN fnd_api.g_exc_unexpected_error THEN
230 --ROLLBACK TO get_cylic_relationships_pvt;
231 x_return_status := fnd_api.g_ret_sts_unexp_error ;
232 fnd_msg_pub.count_AND_get
233 (p_count => x_msg_count ,
234 p_data => x_msg_data);
235
236 WHEN OTHERS THEN
237 --ROLLBACK TO get_cylic_relationships_pvt;
238 x_return_status := fnd_api.g_ret_sts_unexp_error ;
239 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
240 THEN
241 fnd_msg_pub.add_exc_msg(g_pkg_name ,l_api_name);
242 END IF;
243 fnd_msg_pub.count_AND_get
244 (p_count => x_msg_count ,
245 p_data => x_msg_data);
246 END get_cyclic_relationships;
247
248 PROCEDURE get_rel_for_instance
249 (p_instance_id IN NUMBER,
250 p_time_stamp IN DATE,
251 p_active_relationship_only IN VARCHAR2,
252 x_relationship_tbl IN OUT NOCOPY csi_datastructures_pub.ii_relationship_tbl)
253 IS
254
255 l_cur_instance_id NUMBER;
256 i NUMBER;
257 l_relation_exists BOOLEAN;
258 l_sysdate DATE;
259 l_time_stamp DATE;
260
261
262 -- x_relationship_tbl may be already populated with instances.
263 -- This procedure gets all the relationships for the given instance and populates it in
264 -- x_relationship_tbl if it already does not exists.
265
266 CURSOR relations_cur (c_sysdate IN DATE) IS
267 SELECT relationship_id ,
268 relationship_type_code ,
269 object_id ,
270 subject_id ,
271 position_reference ,
272 active_start_date ,
273 active_end_date ,
274 display_order ,
275 mandatory_flag ,
276 context ,
277 attribute1 ,
278 attribute2 ,
279 attribute3 ,
280 attribute4 ,
281 attribute5 ,
282 attribute6 ,
283 attribute7 ,
284 attribute8 ,
285 attribute9 ,
286 attribute10,
287 attribute11,
288 attribute12,
289 attribute13,
290 attribute14,
291 attribute15,
292 object_version_number
293 FROM csi_ii_relationships
294 WHERE (subject_id = p_instance_id OR object_id = p_instance_id )
295 AND relationship_type_code = 'CONNECTED-TO'
296 AND nvl(active_start_date,creation_date) <= NVL(l_time_stamp,nvl(active_start_date,creation_date))
297 AND DECODE(p_active_relationship_only,FND_API.G_TRUE,NVL((active_end_date),c_sysdate+1),c_sysdate+1) > NVL((l_time_stamp),c_sysdate) ;
298
299 BEGIN
300 i:= 0;
301 SELECT SYSDATE
302 INTO l_sysdate
303 FROM dual;
304 --
305 -- srramakr Bug # 2882876
306 IF p_time_stamp = FND_API.G_MISS_DATE THEN
307 l_time_stamp := null;
308 ELSE
309 l_time_stamp := p_time_stamp;
310 END IF;
311 --
312 FOR relations_rec IN relations_cur(l_sysdate)
313 LOOP
314 l_relation_exists := FALSE ;
315 IF x_relationship_tbl.COUNT = 0 THEN
316 x_relationship_tbl(1).relationship_id := relations_rec.relationship_id ;
317 x_relationship_tbl(1).relationship_type_code := relations_rec.relationship_type_code ;
318 x_relationship_tbl(1).object_id := relations_rec.object_id ;
319 x_relationship_tbl(1).subject_id := relations_rec.subject_id ;
320 x_relationship_tbl(1).position_reference := relations_rec.position_reference ;
321 x_relationship_tbl(1).active_start_date := relations_rec.active_start_date ;
322 x_relationship_tbl(1).active_end_date := relations_rec.active_end_date ;
323 x_relationship_tbl(1).display_order := relations_rec.display_order;
324 x_relationship_tbl(1).mandatory_flag := relations_rec.mandatory_flag ;
325 x_relationship_tbl(1).context := relations_rec.context ;
326 x_relationship_tbl(1).attribute1 := relations_rec.attribute1 ;
327 x_relationship_tbl(1).attribute2 := relations_rec.attribute2 ;
328 x_relationship_tbl(1).attribute3 := relations_rec.attribute3 ;
329 x_relationship_tbl(1).attribute4 := relations_rec.attribute4 ;
330 x_relationship_tbl(1).attribute5 := relations_rec.attribute5 ;
331 x_relationship_tbl(1).attribute6 := relations_rec.attribute6 ;
332 x_relationship_tbl(1).attribute7 := relations_rec.attribute7 ;
333 x_relationship_tbl(1).attribute8 := relations_rec.attribute8 ;
334 x_relationship_tbl(1).attribute9 := relations_rec.attribute9 ;
335 x_relationship_tbl(1).attribute10:= relations_rec.attribute10 ;
336 x_relationship_tbl(1).attribute11:= relations_rec.attribute11;
337 x_relationship_tbl(1).attribute12:= relations_rec.attribute12;
338 x_relationship_tbl(1).attribute13:= relations_rec.attribute13;
339 x_relationship_tbl(1).attribute14:= relations_rec.attribute14 ;
340 x_relationship_tbl(1).attribute15:= relations_rec.attribute15;
341 x_relationship_tbl(1).object_version_number:= relations_rec.object_version_number; -- Porting fix for Bug 4243513
342 ELSE
343 FOR j IN 1..x_relationship_tbl.COUNT
344 LOOP
345 IF x_relationship_tbl(j).relationship_id = relations_rec.relationship_id
346 THEN
347 l_relation_exists := TRUE ;
348 EXIT ;
349 END IF ;
350 END LOOP ;
351
352 IF NOT l_relation_exists THEN
353 i := NVL(x_relationship_tbl.LAST,0) + 1 ;
354 x_relationship_tbl(i).relationship_id := relations_rec.relationship_id ;
355 x_relationship_tbl(i).relationship_type_code := relations_rec.relationship_type_code ;
356 x_relationship_tbl(i).object_id := relations_rec.object_id ;
357 x_relationship_tbl(i).subject_id := relations_rec.subject_id ;
358 x_relationship_tbl(i).position_reference := relations_rec.position_reference;
359 x_relationship_tbl(i).active_start_date := relations_rec.active_start_date;
360 x_relationship_tbl(i).active_end_date := relations_rec.active_end_date;
361 x_relationship_tbl(i).display_order := relations_rec.display_order;
362 x_relationship_tbl(i).mandatory_flag := relations_rec.mandatory_flag;
363 x_relationship_tbl(i).context := relations_rec.context ;
364 x_relationship_tbl(i).attribute1 := relations_rec.attribute1 ;
365 x_relationship_tbl(i).attribute2 := relations_rec.attribute2 ;
366 x_relationship_tbl(i).attribute3 := relations_rec.attribute3 ;
367 x_relationship_tbl(i).attribute4 := relations_rec.attribute4 ;
368 x_relationship_tbl(i).attribute5 := relations_rec.attribute5 ;
369 x_relationship_tbl(i).attribute6 := relations_rec.attribute6 ;
370 x_relationship_tbl(i).attribute7 := relations_rec.attribute7 ;
371 x_relationship_tbl(i).attribute8 := relations_rec.attribute8 ;
372 x_relationship_tbl(i).attribute9 := relations_rec.attribute9 ;
373 x_relationship_tbl(i).attribute10:= relations_rec.attribute10;
374 x_relationship_tbl(i).attribute11:= relations_rec.attribute11;
375 x_relationship_tbl(i).attribute12:= relations_rec.attribute12;
376 x_relationship_tbl(i).attribute13:= relations_rec.attribute13;
377 x_relationship_tbl(i).attribute14:= relations_rec.attribute14;
378 x_relationship_tbl(i).attribute15:= relations_rec.attribute15;
379 x_relationship_tbl(i).object_version_number:= relations_rec.object_version_number; -- Porting fix for Bug 4243513
380 END IF ;
381 END IF ;
382 END LOOP ;
383 END get_rel_for_instance ;
384
385 PROCEDURE get_neighbors_for_instance(p_instance_id IN NUMBER ,
386 p_hop IN NUMBER,
387 p_depth IN NUMBER,
388 p_time_stamp IN DATE,
389 p_active_relationship_only IN VARCHAR2,
390 x_neighbor_inst_tbl OUT NOCOPY instance_tbl )
391 IS
392
393 i NUMBER ;
394 l_sysdate DATE ;
395 l_time_stamp DATE;
396
397 CURSOR neighbor_cur (p_instance_id IN NUMBER,
398 c_sysdate IN DATE )
399 IS
400 SELECT subject_id instance_id
401 FROM csi_ii_relationships
402 WHERE (subject_id = p_instance_id OR object_id = p_instance_id)
403 AND relationship_type_code = 'CONNECTED-TO'
404 AND nvl(active_start_date,creation_date) <= NVL(l_time_stamp,nvl(active_start_date,creation_date))
405 AND DECODE(p_active_relationship_only,FND_API.G_TRUE,NVL((active_end_date),c_sysdate+1),c_sysdate+1) > NVL((l_time_stamp),c_sysdate)
406 UNION ALL
407 SELECT object_id instance_id
408 FROM csi_ii_relationships
409 WHERE (subject_id = p_instance_id OR object_id = p_instance_id)
410 AND relationship_type_code = 'CONNECTED-TO'
411 AND nvl(active_start_date,creation_date) <= NVL(l_time_stamp,nvl(active_start_date,creation_date))
412 AND DECODE(p_active_relationship_only,FND_API.G_TRUE,NVL((active_end_date),c_sysdate+1),c_sysdate+1) > NVL((l_time_stamp),c_sysdate) ;
413
414 BEGIN
415 SELECT SYSDATE
416 INTO l_sysdate
417 FROM DUAL;
418 --
419 -- srramakr Bug # 2882876
420 IF p_time_stamp = FND_API.G_MISS_DATE THEN
421 l_time_stamp := null;
422 ELSE
423 l_time_stamp := p_time_stamp;
424 END IF;
425 --
426 i:= 0;
427 x_neighbor_inst_tbl.DELETE ;
428
429 FOR neighbor_rec IN neighbor_cur (p_instance_id, l_sysdate)
430 LOOP
431 IF neighbor_rec.instance_id <> p_instance_id
432 THEN
433 i := i+1;
434 IF p_depth IS NOT NULL
435 THEN
436 IF p_hop+1 <= p_depth
437 THEN
438 x_neighbor_inst_tbl(i).instance_id := neighbor_rec.instance_id ;
439 x_neighbor_inst_tbl(i).hop := p_hop+1 ;
440 END IF ;
441 ELSE
442 x_neighbor_inst_tbl(i).instance_id := neighbor_rec.instance_id;
443 x_neighbor_inst_tbl(i).hop := p_hop+1 ;
444 END IF ; --p_depth IS NOT NULL
445 END IF ;
446 END LOOP;
447 END get_neighbors_for_instance ;
448
449 /* End of Cyclic Relationships */
450
451 PROCEDURE validate_ii_relationships(
452 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
453 p_validation_level IN NUMBER := fnd_api.g_valid_level_full,
454 p_validation_mode IN VARCHAR2,
455 p_ii_relationship_tbl IN csi_datastructures_pub.ii_relationship_tbl,
456 x_return_status OUT NOCOPY VARCHAR2,
457 x_msg_count OUT NOCOPY NUMBER,
458 x_msg_data OUT NOCOPY VARCHAR2
459 );
460
461 PROCEDURE validate_relationship_id (
462 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
463 p_validation_mode IN VARCHAR2,
464 p_relationship_id IN NUMBER,
465 x_return_status OUT NOCOPY VARCHAR2,
466 x_msg_count OUT NOCOPY NUMBER,
467 x_msg_data OUT NOCOPY VARCHAR2
468 );
469
470 PROCEDURE validate_rel_type_code (
471 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
472 p_validation_mode IN VARCHAR2,
473 p_relationship_type_code IN VARCHAR2,
474 x_return_status OUT NOCOPY VARCHAR2,
475 x_msg_count OUT NOCOPY NUMBER,
476 x_msg_data OUT NOCOPY VARCHAR2
477 );
478
479
480 PROCEDURE validate_object_id (
481 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
482 p_validation_mode IN VARCHAR2,
483 p_object_id IN NUMBER,
484 x_return_status OUT NOCOPY VARCHAR2,
485 x_msg_count OUT NOCOPY NUMBER,
486 x_msg_data OUT NOCOPY VARCHAR2
487 );
488
489
490 PROCEDURE validate_subject_id (
491 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
492 p_validation_mode IN VARCHAR2,
493 p_subject_id IN NUMBER,
494 x_return_status OUT NOCOPY VARCHAR2,
495 x_msg_count OUT NOCOPY NUMBER,
496 x_msg_data OUT NOCOPY VARCHAR2
497 );
498
499
500 PROCEDURE validate_active_end_date (
501 p_init_msg_list IN VARCHAR2 := fnd_api.g_false,
502 p_validation_mode IN VARCHAR2,
503 p_active_end_date IN DATE,
504 x_return_status OUT NOCOPY VARCHAR2,
505 x_msg_count OUT NOCOPY NUMBER,
506 x_msg_data OUT NOCOPY VARCHAR2
507 );
508
509
510 PROCEDURE define_columns(
511 p_relations_rec IN csi_datastructures_pub.ii_relationship_rec,
512 p_cur_get_relations IN NUMBER
513 )
514 IS
515 BEGIN
516
517
518 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 1, p_relations_rec.relationship_id);
519 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 2, p_relations_rec.relationship_type_code,30);
520 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 3, p_relations_rec.object_id);
521 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 4, p_relations_rec.subject_id);
522 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 5, p_relations_rec.subject_has_child,1);
523 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 6, p_relations_rec.position_reference,30);
524 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 7, p_relations_rec.active_start_date);
525 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 8, p_relations_rec.active_end_date);
526 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 9, p_relations_rec.display_order);
527 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 10, p_relations_rec.mandatory_flag,1);
528 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 11, p_relations_rec.context,30);
529 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 12, p_relations_rec.attribute1,150);
530 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 13, p_relations_rec.attribute2,150);
531 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 14, p_relations_rec.attribute3,150);
532 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 15, p_relations_rec.attribute4,150);
533 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 16, p_relations_rec.attribute5,150);
534 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 17, p_relations_rec.attribute6,150);
535 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 18, p_relations_rec.attribute7,150);
536 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 19, p_relations_rec.attribute8,150);
537 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 20, p_relations_rec.attribute9,150);
538 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 21, p_relations_rec.attribute10,150);
539 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 22, p_relations_rec.attribute11,150);
540 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 23, p_relations_rec.attribute12,150);
541 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 24, p_relations_rec.attribute13,150);
542 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 25, p_relations_rec.attribute14,150);
543 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 26, p_relations_rec.attribute15,150);
544 DBMS_SQL.DEFINE_COLUMN(p_cur_get_relations, 27, p_relations_rec.object_version_number);
545
546
547 END define_columns;
548
549
550 PROCEDURE get_column_values(
551 p_cur_get_relations IN NUMBER,
552 x_rel_rec OUT NOCOPY csi_datastructures_pub.ii_relationship_rec
553 )
554 IS
555 BEGIN
556 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 1, x_rel_rec.relationship_id);
557 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 2, x_rel_rec.relationship_type_code);
558 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 3, x_rel_rec.object_id);
559 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 4, x_rel_rec.subject_id);
560 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 5, x_rel_rec.subject_has_child);
561 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 6, x_rel_rec.position_reference);
562 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 7, x_rel_rec.active_start_date);
563 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 8, x_rel_rec.active_end_date);
564 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 9, x_rel_rec.display_order);
565 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 10, x_rel_rec.mandatory_flag);
566 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 11, x_rel_rec.context);
567 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 12, x_rel_rec.attribute1);
568 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 13, x_rel_rec.attribute2);
569 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 14, x_rel_rec.attribute3);
570 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 15, x_rel_rec.attribute4);
571 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 16, x_rel_rec.attribute5);
572 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 17, x_rel_rec.attribute6);
573 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 18, x_rel_rec.attribute7);
574 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 19, x_rel_rec.attribute8);
575 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 20, x_rel_rec.attribute9);
576 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 21, x_rel_rec.attribute10);
577 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 22, x_rel_rec.attribute11);
578 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 23, x_rel_rec.attribute12);
579 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 24, x_rel_rec.attribute13);
580 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 25, x_rel_rec.attribute14);
581 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 26, x_rel_rec.attribute15);
582 DBMS_SQL.COLUMN_VALUE(p_cur_get_relations, 27, x_rel_rec.object_version_number);
583
584 END get_column_values;
585
586
587 PROCEDURE bind(
588 p_relationship_query_rec IN csi_datastructures_pub.relationship_query_rec,
589 p_cur_get_relations IN NUMBER
590 )
591 IS
592 BEGIN
593
594 IF( (p_relationship_query_rec.relationship_id IS NOT NULL) AND (p_relationship_query_rec.relationship_id <> fnd_api.g_miss_num) )
595 THEN
596 dbms_sql.bind_variable(p_cur_get_relations, 'relationship_id', p_relationship_query_rec.relationship_id);
597 END IF;
598
599 IF( (p_relationship_query_rec.relationship_type_code IS NOT NULL) AND (p_relationship_query_rec.relationship_type_code <> fnd_api.g_miss_char) )
600 THEN
601 dbms_sql.bind_variable(p_cur_get_relations, 'relationship_type_code', p_relationship_query_rec.relationship_type_code);
602 END IF;
603
604 IF( (p_relationship_query_rec.object_id IS NOT NULL) AND (p_relationship_query_rec.object_id <> fnd_api.g_miss_num) )
605 THEN
606 dbms_sql.bind_variable(p_cur_get_relations, 'object_id', p_relationship_query_rec.object_id);
607 END IF;
608
609 IF( (p_relationship_query_rec.subject_id IS NOT NULL) AND (p_relationship_query_rec.subject_id <> fnd_api.g_miss_num) )
610 THEN
611 dbms_sql.bind_variable(p_cur_get_relations, 'subject_id', p_relationship_query_rec.subject_id);
612 END IF;
613
614
615 END bind;
616
617
618 PROCEDURE gen_select(
619 p_relship_query_rec IN csi_datastructures_pub.relationship_query_rec,
620 x_select_cl OUT NOCOPY VARCHAR2
621 )
622 IS
623 l_table_name VARCHAR2(30);
624 BEGIN
625
626 x_select_cl := 'SELECT relationship_id,relationship_type_code,object_id,subject_id'
627 ||',nvl((select '||'''Y'''|| ' from csi_ii_relationships where object_id = ciir.subject_id and relationship_type_code = ciir.relationship_type_code and rownum=1), '||'''N'''||') subject_has_child,'
628 ||'position_reference,active_start_date,active_end_date,display_order,mandatory_flag,context,attribute1,attribute2,attribute3,attribute4,attribute5,attribute6,attribute7,'
629 ||'attribute8,attribute9,attribute10,attribute11,attribute12,attribute13,attribute14'
630 ||',attribute15,object_version_number FROM csi_ii_relationships ciir';
631
632
633 END gen_select;
634
635 PROCEDURE gen_relations_where(
636 p_relship_query_rec IN csi_datastructures_pub.relationship_query_rec,
637 p_active_relationship_only IN VARCHAR2,
638 p_depth IN NUMBER,
639 x_relations_where OUT NOCOPY VARCHAR2
640 )
641 IS
642 CURSOR c_chk_str1(p_rec_item VARCHAR2) IS
643 SELECT instr(p_rec_item, '%', 1, 1)
644 FROM dual;
645 CURSOR c_chk_str2(p_rec_item VARCHAR2) IS
646 SELECT instr(p_rec_item, '_', 1, 1)
647 FROM dual;
648
649 -- return values from cursors
650 str_csr1 NUMBER;
651 str_csr2 NUMBER;
652 i NUMBER;
653 l_operator VARCHAR2(10);
654 l_cnt NUMBER :=0;
655
656 BEGIN
657
658
659 IF( (p_relship_query_rec.relationship_id IS NOT NULL) AND (p_relship_query_rec.relationship_id <> fnd_api.g_miss_num) )
660 THEN
661 l_cnt:=l_cnt+1;
662 IF(x_relations_where IS NULL) THEN
663 x_relations_where := ' WHERE ';
664 ELSE
665 x_relations_where := x_relations_where || ' AND ';
666 END IF;
667 x_relations_where := x_relations_where || 'relationship_id = :relationship_id';
668 END IF;
669
670 /*** COMMENTED IF p_active_relationship_only = 'T' THEN
671 l_cnt:=l_cnt+1;
672 IF(x_relations_where IS NULL) THEN
673 x_relations_where := ' WHERE ';
674 ELSE
675 x_relations_where := x_relations_where ||' AND ';
676 END IF;
677 x_relations_where := x_relations_where ||' ( active_end_date is null or active_end_date >= SYSDATE ) ';
678 END IF; **** END OF COMMENT ****/
679
680 IF( (p_relship_query_rec.subject_id IS NOT NULL) AND (p_relship_query_rec.subject_id <> fnd_api.g_miss_num) )
681 THEN
682 l_cnt:=l_cnt+1;
683 IF(x_relations_where IS NULL) THEN
684 x_relations_where := ' WHERE ';
685 ELSE
686 x_relations_where := x_relations_where || ' AND ';
687 END IF;
688 x_relations_where := x_relations_where || 'subject_id = :subject_id';
689 END IF;
690
691 IF( (p_relship_query_rec.relationship_type_code IS NOT NULL) AND (p_relship_query_rec.relationship_type_code <> fnd_api.g_miss_char) )
692 THEN
693 l_cnt:=l_cnt+1;
694 i:=0;
695 -- check IF item value contains '%' wildcard
696 OPEN c_chk_str1(p_relship_query_rec.relationship_type_code);
697 FETCH c_chk_str1 INTO str_csr1;
698 CLOSE c_chk_str1;
699 IF(str_csr1 <> 0) THEN
700 l_operator := ' like ';
701 i:=1;
702 ELSE
703 l_operator := ' = ';
704 END IF;
705 IF i=0 THEN
706 -- check if item value contains '_' wildcard
707 OPEN c_chk_str2(p_relship_query_rec.relationship_type_code);
708 FETCH c_chk_str2 INTO str_csr2;
709 CLOSE c_chk_str2;
710 IF(str_csr2 <> 0) THEN
711 l_operator := ' like ';
712 ELSE
713 l_operator := ' = ';
714 END IF;
715 END IF;
716 IF(x_relations_where IS NULL) THEN
717 x_relations_where := ' WHERE ';
718 ELSE
719 x_relations_where := x_relations_where || ' AND ';
720 END IF;
721 x_relations_where := x_relations_where || 'relationship_type_code ' || l_operator || ' :relationship_type_code';
722 END IF;
723
724 IF( (p_relship_query_rec.object_id IS NOT NULL) AND (p_relship_query_rec.object_id <> fnd_api.g_miss_num) )
725 THEN
726 IF(x_relations_where IS NULL) THEN
727 x_relations_where := ' WHERE ';
728 ELSE
729 IF l_cnt>1 THEN
730 x_relations_where := x_relations_where || ' AND ';
731 ELSE
732 x_relations_where := x_relations_where || ' START WITH ';
733 END IF;
734 END IF;
735 IF l_cnt>1 THEN
736 x_relations_where := x_relations_where || 'object_id = :object_id ';
737 ELSE
738 x_relations_where := x_relations_where || 'object_id = :object_id ' ||'CONNECT BY object_id = PRIOR subject_id' ;
739 IF ( (p_depth IS NOT NULL) AND (p_depth <> fnd_api.g_miss_num) ) THEN
740 x_relations_where := x_relations_where || ' AND level <= '||p_depth;
741 END IF;
742 END IF;
743 END IF;
744
745
746 END gen_relations_where;
747
748 /*--------------------------------------------------------------------------------------------------------------+
749 | <-- csi_ii_relationships_h --> |
750 |full_dump_flag |
751 | y y y y y y |
752 | c |---------------------------------------------------------------------------- c |
753 | a | | | | | | | 11-may-01 a |
754 | s 01-may-01 03-may-01 05-may-01 07-may-01 09-may-01 10-may-01 s |
755 | e e |
756 | 1 <------------------------------------case 3---------------------------------> 2 |
757 | |
758 | case 1: If the passed time stamp (p_time_stamp) falls before the first full_dump_flag(ex:30-apr-01) then |
759 | we have to skip the retreived record. |
760 | case 2: If the passed time stamp (p_time_stamp) falls after the last transaction_date(ex:12-may-01) then |
761 | we have to add the retreived record for display. |
762 | case 3: If the passed time stamp (p_time_stamp say 06-may-01)falls in between 01-may-01 and 11-may-01 then |
763 | we need to find the maximum of the minimum record where the full_dump_flag='Y' (05-may-01 in |
764 | this case) and start building the history record for display. |
765 +---------------------------------------------------------------------------------------------------------------*/
766
767 PROCEDURE from_to_tran( p_relationship_id IN NUMBER,
768 p_time_stamp IN DATE,
769 from_time_stamp OUT NOCOPY VARCHAR2,
770 to_time_stamp OUT NOCOPY VARCHAR2)
771 IS
772 l_f_date VARCHAR2(25) := fnd_api.g_miss_char;
773 l_t_date VARCHAR2(25) := fnd_api.g_miss_char;
774 BEGIN
775
776 SELECT max(min(to_char(a.transaction_date,'dd-mon-rr hh24:mi:ss')))
777 INTO l_f_date
778 FROM csi_transactions a,csi_ii_relationships b,csi_ii_relationships_h c
779 WHERE b.relationship_id = c.relationship_id
780 AND c.transaction_id = a.transaction_id
781 AND c.full_dump_flag = 'Y'
782 AND a.transaction_date <= p_time_stamp
783 AND c.relationship_id = p_relationship_id
784 GROUP BY to_char(a.transaction_date,'dd-mon-rr hh24:mi:ss');
785 IF l_f_date IS NULL THEN
786 FROM_time_stamp:=NULL;
787 to_time_stamp:=l_t_date;
788 ELSE
789 FROM_time_stamp:=l_f_date;
790 BEGIN
791 SELECT max(min(to_char(a.transaction_date,'dd-mon-rr hh24:mi:ss')))
792 INTO l_t_date
793 FROM csi_transactions a,csi_ii_relationships b,csi_ii_relationships_h c
794 WHERE b.relationship_id = c.relationship_id
795 AND c.transaction_id = a.transaction_id
796 AND a.transaction_date<= p_time_stamp
797 AND c.relationship_id = p_relationship_id
798 GROUP BY to_char(a.transaction_date,'dd-mon-rr hh24:mi:ss');
799
800 IF l_t_date IS NULL THEN
801 to_time_stamp:=NULL;
802 ELSE
803 to_time_stamp:=l_t_date;
804 END IF;
805 END;
806 END IF;
807 END;
808
809
810 PROCEDURE get_history( p_rel_rec IN csi_datastructures_pub.ii_relationship_rec
811 ,p_new_rec OUT NOCOPY csi_datastructures_pub.ii_relationship_rec
812 ,p_flag OUT NOCOPY VARCHAR2
813 ,p_time_stamp IN DATE
814 )
815 IS
816 CURSOR hist_csr (p_relationship_id IN NUMBER,
817 p_f_time_stamp IN VARCHAR2,
818 p_t_time_stamp IN VARCHAR2)
819 IS
820 SELECT c.old_subject_id
821 ,c.new_subject_id
822 ,c.old_position_reference
823 ,c.new_position_reference
824 ,c.old_active_start_date
825 ,c.new_active_start_date
826 ,c.old_active_end_date
827 ,c.new_active_end_date
828 ,c.old_mandatory_flag
829 ,c.new_mandatory_flag
830 ,c.old_context
831 ,c.new_context
832 ,c.old_attribute1
833 ,c.new_attribute1
834 ,c.old_attribute2
835 ,c.new_attribute2
836 ,c.old_attribute3
837 ,c.new_attribute3
838 ,c.old_attribute4
839 ,c.new_attribute4
840 ,c.old_attribute5
841 ,c.new_attribute5
842 ,c.old_attribute6
843 ,c.new_attribute6
844 ,c.old_attribute7
845 ,c.new_attribute7
846 ,c.old_attribute8
847 ,c.new_attribute8
848 ,c.old_attribute9
849 ,c.new_attribute9
850 ,c.old_attribute10
851 ,c.new_attribute10
852 ,c.old_attribute11
853 ,c.new_attribute11
854 ,c.old_attribute12
855 ,c.new_attribute12
856 ,c.old_attribute13
857 ,c.new_attribute13
858 ,c.old_attribute14
859 ,c.new_attribute14
860 ,c.old_attribute15
861 ,c.new_attribute15
862 ,c.full_dump_flag
863 FROM csi_transactions a,csi_ii_relationships b,csi_ii_relationships_h c
864 WHERE b.relationship_id = c.relationship_id
865 AND c.transaction_id = a.transaction_id
866 AND c.relationship_id = p_relationship_id
867 -- AND a.transaction_date BETWEEN fnd_date.canonical_to_date(p_f_time_stamp) --to_date(p_f_time_stamp,'dd-mon-rr hh24:mi:ss')
868 -- AND fnd_date.canonical_to_date(p_t_time_stamp) --to_date(p_t_time_stamp,'dd-mon-rr hh24:mi:ss')
869 AND a.transaction_date BETWEEN to_date(p_f_time_stamp,'dd/mm/rr hh24:mi:ss')
870 AND to_date(p_t_time_stamp,'dd/mm/rr hh24:mi:ss')
871 ORDER BY to_char(a.transaction_date,'dd-mon-rr hh24:mi:ss') ;
872
873 l_f_time_stamp VARCHAR2(25) :=fnd_api.g_miss_char;
874 l_t_time_stamp VARCHAR2(25) :=fnd_api.g_miss_char;
875 l_to_date VARCHAR2(25);
876 BEGIN
877 FROM_to_tran(p_relationship_id => p_rel_rec.relationship_id,
878 p_time_stamp => p_time_stamp,
879 FROM_time_stamp => l_f_time_stamp,
880 to_time_stamp => l_t_time_stamp);
881
882 SELECT max(to_char(a.transaction_date,'dd-mon-rr hh24:mi:ss'))
883 INTO l_to_date
884 FROM csi_transactions a,csi_ii_relationships_h b
885 WHERE a.transaction_id=b.transaction_id
886 AND b.relationship_id=p_rel_rec.relationship_id;
887
888 -- IF ( (l_f_time_stamp IS NOT NULL) AND (p_time_stamp>fnd_date.canonical_to_date(l_to_date) ) )-- to_date(l_to_date,'dd-mon-rr hh24:mi:ss')) ) THEN
889 IF ( (l_f_time_stamp IS NOT NULL) AND (p_time_stamp > to_date(l_to_date,'dd/mm/rr hh24:mi:ss')) )THEN
890 -- +-------------------------------------------------------------------------------------------+
891 -- | we have entered into case 2 which we just add the retreived record for display |
892 -- +-------------------------------------------------------------------------------------------+
893
894
895 p_new_rec := p_rel_rec;
896 p_flag := 'ADD';
897 ELSIF (l_f_time_stamp IS NULL) THEN
898 -- +-------------------------------------------------------------------------------------------+
899 -- | we have entered into case 1 which we have to skip the record. |
900 -- +-------------------------------------------------------------------------------------------+
901
902 p_flag := 'SKIP';
903 ELSE
904 -- +-------------------------------------------------------------------------------------------+
905 -- |we have entered into case 3 where we have to compare the record and return flag with 'add'.|
906 -- +-------------------------------------------------------------------------------------------+
907
908 FOR get_csr IN hist_csr(p_rel_rec.relationship_id,l_f_time_stamp,l_t_time_stamp) LOOP
909
910 p_new_rec.relationship_id:=p_rel_rec.relationship_id;
911 p_new_rec.relationship_type_code:=p_rel_rec.relationship_type_code;
912 p_new_rec.object_id:=p_rel_rec.object_id;
913 p_new_rec.display_order:=p_rel_rec.display_order;
914
915 IF get_csr.new_subject_id IS NOT NULL THEN
916 p_new_rec.subject_id := get_csr.new_subject_id;
917 ELSIF get_csr.full_dump_flag='Y' THEN
918 p_new_rec.subject_id := get_csr.old_subject_id;
919 END IF;
920
921 IF get_csr.new_position_reference IS NOT NULL THEN
922 p_new_rec.position_reference := get_csr.new_position_reference;
923 ELSIF get_csr.full_dump_flag='Y' THEN
924 p_new_rec.position_reference := get_csr.old_position_reference;
925 END IF;
926
927 IF get_csr.new_active_start_date IS NOT NULL THEN
928 p_new_rec.active_start_date := get_csr.new_active_start_date;
929 ELSIF get_csr.full_dump_flag='Y' THEN
930 p_new_rec.active_start_date := get_csr.old_active_start_date;
931 END IF;
932
933 IF get_csr.new_active_end_date IS NOT NULL THEN
934 p_new_rec.active_end_date := get_csr.new_active_end_date;
935 ELSIF get_csr.full_dump_flag='Y' THEN
936 p_new_rec.active_end_date := get_csr.old_active_end_date;
937 END IF;
938
939 IF get_csr.new_mandatory_flag IS NOT NULL THEN
940 p_new_rec.mandatory_flag := get_csr.new_mandatory_flag;
941 ELSIF get_csr.full_dump_flag='Y' THEN
942 p_new_rec.mandatory_flag := get_csr.old_mandatory_flag;
943 END IF;
944
945 IF get_csr.new_context IS NOT NULL THEN
946 p_new_rec.context := get_csr.new_context;
947 ELSIF get_csr.full_dump_flag='Y' THEN
948 p_new_rec.context := get_csr.old_context;
949 END IF;
950
951 IF get_csr.new_attribute1 IS NOT NULL THEN
952 p_new_rec.attribute1 := get_csr.new_attribute1;
953 ELSIF get_csr.full_dump_flag='Y' THEN
954 p_new_rec.attribute1 := get_csr.old_attribute1;
955 END IF;
956
957 IF get_csr.new_attribute2 IS NOT NULL THEN
958 p_new_rec.attribute2 := get_csr.new_attribute2;
959 ELSIF get_csr.full_dump_flag='Y' THEN
960 p_new_rec.attribute2 := get_csr.old_attribute2;
961 END IF;
962
963 IF get_csr.new_attribute3 IS NOT NULL THEN
964 p_new_rec.attribute3 := get_csr.new_attribute3;
965 ELSIF get_csr.full_dump_flag='Y' THEN
966 p_new_rec.attribute3 := get_csr.old_attribute3;
967 END IF;
968
969 IF get_csr.new_attribute4 IS NOT NULL THEN
970 p_new_rec.attribute4 := get_csr.new_attribute4;
971 ELSIF get_csr.full_dump_flag='Y' THEN
972 p_new_rec.attribute4 := get_csr.old_attribute4;
973 END IF;
974
975 IF get_csr.new_attribute5 IS NOT NULL THEN
976 p_new_rec.attribute5 := get_csr.new_attribute5;
977 ELSIF get_csr.full_dump_flag='Y' THEN
978 p_new_rec.attribute5 := get_csr.old_attribute5;
979 END IF;
980
981 IF get_csr.new_attribute6 IS NOT NULL THEN
982 p_new_rec.attribute6 := get_csr.new_attribute6;
983 ELSIF get_csr.full_dump_flag='Y' THEN
984 p_new_rec.attribute6 := get_csr.old_attribute6;
985 END IF;
986
987 IF get_csr.new_attribute7 IS NOT NULL THEN
988 p_new_rec.attribute7 := get_csr.new_attribute7;
989 ELSIF get_csr.full_dump_flag='Y' THEN
990 p_new_rec.attribute7 := get_csr.old_attribute7;
991 END IF;
992
993 IF get_csr.new_attribute8 IS NOT NULL THEN
994 p_new_rec.attribute8 := get_csr.new_attribute8;
995 ELSIF get_csr.full_dump_flag='Y' THEN
996 p_new_rec.attribute8 := get_csr.old_attribute8;
997 END IF;
998
999 IF get_csr.new_attribute9 IS NOT NULL THEN
1000 p_new_rec.attribute9 := get_csr.new_attribute9;
1001 ELSIF get_csr.full_dump_flag='Y' THEN
1002 p_new_rec.attribute9 := get_csr.old_attribute9;
1003 END IF;
1004
1005 IF get_csr.new_attribute10 IS NOT NULL THEN
1006 p_new_rec.attribute10 := get_csr.new_attribute10;
1007 ELSIF get_csr.full_dump_flag='Y' THEN
1008 p_new_rec.attribute10 := get_csr.old_attribute10;
1009 END IF;
1010
1011 IF get_csr.new_attribute11 IS NOT NULL THEN
1012 p_new_rec.attribute11 := get_csr.new_attribute11;
1013 ELSIF get_csr.full_dump_flag='Y' THEN
1014 p_new_rec.attribute11 := get_csr.old_attribute11;
1015 END IF;
1016
1017 IF get_csr.new_attribute12 IS NOT NULL THEN
1018 p_new_rec.attribute12 := get_csr.new_attribute12;
1019 ELSIF get_csr.full_dump_flag='Y' THEN
1020 p_new_rec.attribute12 := get_csr.old_attribute12;
1021 END IF;
1022
1023 IF get_csr.new_attribute13 IS NOT NULL THEN
1024 p_new_rec.attribute13 := get_csr.new_attribute13;
1025 ELSIF get_csr.full_dump_flag='Y' THEN
1026 p_new_rec.attribute13 := get_csr.old_attribute13;
1027 END IF;
1028
1029 IF get_csr.new_attribute14 IS NOT NULL THEN
1030 p_new_rec.attribute14 := get_csr.new_attribute14;
1031 ELSIF get_csr.full_dump_flag='Y' THEN
1032 p_new_rec.attribute14 := get_csr.old_attribute14;
1033 END IF;
1034
1035 IF get_csr.new_attribute15 IS NOT NULL THEN
1036 p_new_rec.attribute15 := get_csr.new_attribute15;
1037 ELSIF get_csr.full_dump_flag='Y' THEN
1038 p_new_rec.attribute15 := get_csr.old_attribute15;
1039 END IF;
1040
1041 END LOOP;
1042 IF p_new_rec.display_order = fnd_api.g_miss_num THEN
1043 p_new_rec.display_order := NULL;
1044 END IF;
1045
1046 IF p_new_rec.subject_id = fnd_api.g_miss_num THEN
1047 p_new_rec.subject_id := NULL;
1048 END IF;
1049
1050 IF p_new_rec.position_reference = fnd_api.g_miss_char THEN
1051 p_new_rec.position_reference := NULL;
1052 END IF;
1053
1054 IF p_new_rec.active_start_date = fnd_api.g_miss_date THEN
1055 p_new_rec.active_start_date := NULL;
1056 END IF;
1057
1058 IF p_new_rec.active_end_date = fnd_api.g_miss_date THEN
1059 p_new_rec.active_end_date := NULL;
1060 END IF;
1061
1062 IF p_new_rec.mandatory_flag = fnd_api.g_miss_char THEN
1063 p_new_rec.mandatory_flag := NULL;
1064 END IF;
1065
1066 IF p_new_rec.context = fnd_api.g_miss_char THEN
1067 p_new_rec.context := NULL;
1068 END IF;
1069
1070 IF p_new_rec.attribute1 = fnd_api.g_miss_char THEN
1071 p_new_rec.attribute1 := NULL;
1072 END IF;
1073
1074 IF p_new_rec.attribute2 = fnd_api.g_miss_char THEN
1075 p_new_rec.attribute2 := NULL;
1076 END IF;
1077
1078 IF p_new_rec.attribute3 = fnd_api.g_miss_char THEN
1079 p_new_rec.attribute3 := NULL;
1080 END IF;
1081
1082 IF p_new_rec.attribute4 = fnd_api.g_miss_char THEN
1083 p_new_rec.attribute4 := NULL;
1084 END IF;
1085
1086 IF p_new_rec.attribute5 = fnd_api.g_miss_char THEN
1087 p_new_rec.attribute5 := NULL;
1088 END IF;
1089
1090 IF p_new_rec.attribute6 = fnd_api.g_miss_char THEN
1091 p_new_rec.attribute6 := NULL;
1092 END IF;
1093
1094 IF p_new_rec.attribute7 =fnd_api.g_miss_char THEN
1095 p_new_rec.attribute7 := NULL;
1096 END IF;
1097
1098 IF p_new_rec.attribute8 = fnd_api.g_miss_char THEN
1099 p_new_rec.attribute8 := NULL;
1100 END IF;
1101
1102 IF p_new_rec.attribute9 = fnd_api.g_miss_char THEN
1103 p_new_rec.attribute9 := NULL;
1104 END IF;
1105
1106 IF p_new_rec.attribute10 = fnd_api.g_miss_char THEN
1107 p_new_rec.attribute10 := NULL;
1108 END IF;
1109
1110 IF p_new_rec.attribute11 = fnd_api.g_miss_char THEN
1111 p_new_rec.attribute11 := NULL;
1112 END IF;
1113
1114 IF p_new_rec.attribute12 = fnd_api.g_miss_char THEN
1115 p_new_rec.attribute12 := NULL;
1116 END IF;
1117
1118 IF p_new_rec.attribute13 = fnd_api.g_miss_char THEN
1119 p_new_rec.attribute13 := NULL;
1120 END IF;
1121
1122 IF p_new_rec.attribute14 =fnd_api.g_miss_char THEN
1123 p_new_rec.attribute14 := NULL;
1124 END IF;
1125
1126 IF p_new_rec.attribute15 = fnd_api.g_miss_char THEN
1127 p_new_rec.attribute15 := NULL;
1128 END IF;
1129
1130 p_flag :='ADD';
1131 END IF;
1132 END;
1133
1134 PROCEDURE Get_Next_Level
1135 (p_object_id IN NUMBER,
1136 p_rel_tbl OUT NOCOPY csi_datastructures_pub.ii_relationship_tbl
1137 ) IS
1138 --
1139 CURSOR REL_CUR IS
1140 select relationship_id,relationship_type_code,object_id,subject_id,position_reference,
1141 active_start_date,active_end_date,display_order,mandatory_flag,context,
1142 attribute1,attribute2,attribute3,attribute4,attribute5,attribute6,attribute7,attribute8,
1143 attribute9,attribute10,attribute11,attribute12,attribute13,attribute14,attribute15,
1144 object_version_number
1145 from CSI_II_RELATIONSHIPS cir
1146 where cir.object_id = p_object_id;
1147 --
1148 l_ctr NUMBER := 0;
1149 BEGIN
1150 FOR rel in REL_CUR LOOP
1151 l_ctr := l_ctr + 1;
1152 p_rel_tbl(l_ctr).relationship_id := rel.relationship_id;
1153 p_rel_tbl(l_ctr).relationship_type_code := rel.relationship_type_code;
1154 p_rel_tbl(l_ctr).object_id := rel.object_id;
1155 p_rel_tbl(l_ctr).subject_id := rel.subject_id;
1156 p_rel_tbl(l_ctr).position_reference := rel.position_reference;
1157 p_rel_tbl(l_ctr).active_start_date := rel.active_start_date;
1158 p_rel_tbl(l_ctr).active_end_date := rel.active_end_date;
1159 p_rel_tbl(l_ctr).display_order := rel.display_order;
1160 p_rel_tbl(l_ctr).mandatory_flag := rel.mandatory_flag;
1161 p_rel_tbl(l_ctr).context := rel.context;
1162 p_rel_tbl(l_ctr).attribute1 := rel.attribute1;
1163 p_rel_tbl(l_ctr).attribute2 := rel.attribute2;
1164 p_rel_tbl(l_ctr).attribute3 := rel.attribute3;
1165 p_rel_tbl(l_ctr).attribute4 := rel.attribute4;
1166 p_rel_tbl(l_ctr).attribute5 := rel.attribute5;
1167 p_rel_tbl(l_ctr).attribute6 := rel.attribute6;
1168 p_rel_tbl(l_ctr).attribute7 := rel.attribute7;
1169 p_rel_tbl(l_ctr).attribute8 := rel.attribute8;
1170 p_rel_tbl(l_ctr).attribute9 := rel.attribute9;
1171 p_rel_tbl(l_ctr).attribute10 := rel.attribute10;
1172 p_rel_tbl(l_ctr).attribute11 := rel.attribute11;
1173 p_rel_tbl(l_ctr).attribute12 := rel.attribute12;
1174 p_rel_tbl(l_ctr).attribute13 := rel.attribute13;
1175 p_rel_tbl(l_ctr).attribute14 := rel.attribute14;
1176 p_rel_tbl(l_ctr).attribute15 := rel.attribute15;
1177 p_rel_tbl(l_ctr).object_version_number := rel.object_version_number;
1178 END LOOP;
1179 END Get_Next_Level;
1180
1181
1182 PROCEDURE Get_Children
1183 (p_object_id IN NUMBER,
1184 p_rel_tbl OUT NOCOPY csi_datastructures_pub.ii_relationship_tbl
1185 ) IS
1186 --
1187 l_rel_tbl csi_datastructures_pub.ii_relationship_tbl;
1188 l_rel_tbl_next_lvl csi_datastructures_pub.ii_relationship_tbl;
1189 l_rel_tbl_temp csi_datastructures_pub.ii_relationship_tbl;
1190 l_rel_tbl_final csi_datastructures_pub.ii_relationship_tbl;
1191 l_next_ind NUMBER := 0;
1192 l_final_ind NUMBER := 0;
1193 l_ctr NUMBER := 0;
1194 l_found NUMBER;
1195 BEGIN
1196 Get_Next_Level
1197 ( p_object_id => p_object_id,
1198 p_rel_tbl => l_rel_tbl
1199 );
1200
1201 <<Next_Level>>
1202
1203 l_rel_tbl_next_lvl.delete;
1204 l_next_ind := 0;
1205 --
1206 IF l_rel_tbl.count > 0 THEN
1207 FOR l_ind IN l_rel_tbl.FIRST .. l_rel_tbl.LAST LOOP
1208 l_final_ind := l_final_ind + 1;
1209 l_rel_tbl_final(l_final_ind) := l_rel_tbl(l_ind);
1210 /* get the next level using this Subject ID as the parent */
1211 Get_Next_Level
1212 ( p_object_id => l_rel_tbl(l_ind).subject_id,
1213 p_rel_tbl => l_rel_tbl_temp
1214 );
1215 --
1216 IF l_rel_tbl_temp.count > 0 THEN
1217 FOR l_temp_ind IN l_rel_tbl_temp.FIRST .. l_rel_tbl_temp.LAST LOOP
1218 IF l_rel_tbl_final.count > 0 THEN
1219 l_found := 0;
1220 FOR i IN l_rel_tbl_final.FIRST .. l_rel_tbl_final.LAST LOOP
1221 IF l_rel_tbl_final(i).object_id = l_rel_tbl_temp(l_temp_ind).object_id THEN
1222 l_found := 1;
1223 exit;
1224 END IF;
1225 END LOOP;
1226 END IF;
1227 IF l_found = 0 THEN
1228 l_next_ind := l_next_ind + 1;
1229 l_rel_tbl_next_lvl(l_next_ind) := l_rel_tbl_temp(l_temp_ind);
1230 END IF;
1231 END LOOP;
1232 END IF;
1233 END LOOP;
1234 --
1235 IF l_rel_tbl_next_lvl.count > 0 THEN
1236 l_rel_tbl.DELETE;
1237 l_rel_tbl := l_rel_tbl_next_lvl;
1238 --
1239 goto Next_Level;
1240 END IF;
1241 END IF;
1242 --
1243 p_rel_tbl := l_rel_tbl_final;
1244 --
1245 -- The output of l_rel_tbl_final will be Breadth first search Order.
1246 END Get_Children;
1247 --
1248 FUNCTION Parent_of
1249 ( p_subject_id IN NUMBER,
1250 p_rel_tbl IN csi_datastructures_pub.ii_relationship_tbl
1251 ) RETURN NUMBER IS
1252 l_return_value NUMBER := -9999;
1253 BEGIN
1254 IF p_rel_tbl.count = 0 OR
1255 p_subject_id IS NULL THEN
1256 RETURN -9999;
1257 END IF;
1258 FOR i in p_rel_tbl.FIRST ..p_rel_tbl.LAST LOOP
1259 IF p_rel_tbl(i).subject_id = p_subject_id THEN
1260 l_return_value := p_rel_tbl(i).object_id;
1261 exit;
1262 END IF;
1263 END LOOP;
1264 RETURN l_return_value;
1265 END Parent_of;
1266 --
1267 PROCEDURE Get_Next_Level
1268 (p_object_id IN NUMBER,
1269 p_relationship_id IN NUMBER,
1270 p_subject_id IN NUMBER,
1271 p_rel_tbl OUT NOCOPY csi_datastructures_pub.ii_relationship_tbl,
1272 p_rel_type_code IN VARCHAR2,
1273 p_time_stamp IN DATE,
1274 p_active_relationship_only IN VARCHAR2,
1275 p_active_instances_only IN VARCHAR2,
1276 p_config_only IN VARCHAR2
1277 ) IS
1278 --
1279 l_active_relationship_only VARCHAR2(1) := p_active_relationship_only;
1280 l_active_instances_only VARCHAR2(1) := p_active_instances_only;
1281 --
1282 CURSOR OBJECT_CUR(c_sysdate IN DATE) IS -- Used when Object ID and Rel Type are passed
1283 select relationship_id,relationship_type_code,object_id,subject_id,position_reference,
1284 active_start_date,active_end_date,display_order,mandatory_flag,context,
1285 attribute1,attribute2,attribute3,attribute4,attribute5,attribute6,attribute7,attribute8,
1286 attribute9,attribute10,attribute11,attribute12,attribute13,attribute14,attribute15,
1287 object_version_number
1288 from CSI_II_RELATIONSHIPS cir
1289 where cir.object_id = p_object_id
1290 and cir.relationship_type_code = p_rel_type_code
1291 and DECODE(l_active_relationship_only,FND_API.G_TRUE,NVL((cir.active_end_date),c_sysdate+1),c_sysdate+1) > sysdate
1292 and EXISTS (select 'x'
1293 from CSI_ITEM_INSTANCES csi
1294 where csi.instance_id = cir.subject_id
1295 and DECODE(l_active_instances_only,FND_API.G_TRUE,NVL((csi.active_end_date),c_sysdate+1),c_sysdate+1) > sysdate);
1296 --
1297 CURSOR OBJECT_CUR1(c_sysdate IN DATE) IS -- Used when Object ID and Rel Type are passed
1298 select relationship_id,relationship_type_code,object_id,subject_id,position_reference,
1299 active_start_date,active_end_date,display_order,mandatory_flag,context,
1300 attribute1,attribute2,attribute3,attribute4,attribute5,attribute6,attribute7,attribute8,
1301 attribute9,attribute10,attribute11,attribute12,attribute13,attribute14,attribute15,
1302 object_version_number
1303 from CSI_II_RELATIONSHIPS cir
1304 where cir.object_id = p_object_id
1305 and cir.relationship_type_code = p_rel_type_code
1306 and DECODE(l_active_relationship_only,FND_API.G_TRUE,NVL((cir.active_end_date),c_sysdate+1),c_sysdate+1) > sysdate
1307 and EXISTS (select 'x'
1308 from CSI_ITEM_INSTANCES csi
1309 where csi.instance_id = cir.subject_id
1310 and csi.config_inst_hdr_id is not null
1311 and csi.config_inst_item_id is not null
1312 and csi.config_inst_rev_num is not null
1313 and DECODE(l_active_instances_only,FND_API.G_TRUE,NVL((csi.active_end_date),c_sysdate+1),c_sysdate+1) > sysdate);
1314 --
1315 CURSOR OBJECT_ONLY_CUR(c_sysdate IN DATE) IS -- Used when only Object ID is passed
1316 select relationship_id,relationship_type_code,object_id,subject_id,position_reference,
1317 active_start_date,active_end_date,display_order,mandatory_flag,context,
1318 attribute1,attribute2,attribute3,attribute4,attribute5,attribute6,attribute7,attribute8,
1319 attribute9,attribute10,attribute11,attribute12,attribute13,attribute14,attribute15,
1320 object_version_number
1321 from CSI_II_RELATIONSHIPS cir
1322 where cir.object_id = p_object_id
1323 and DECODE(l_active_relationship_only,FND_API.G_TRUE,NVL((cir.active_end_date),c_sysdate+1),c_sysdate+1) > sysdate
1324 and EXISTS (select 'x'
1325 from CSI_ITEM_INSTANCES csi
1326 where csi.instance_id = cir.subject_id
1327 and DECODE(l_active_instances_only,FND_API.G_TRUE,NVL((csi.active_end_date),c_sysdate+1),c_sysdate+1) > sysdate);
1328 --
1329 CURSOR SUBJECT_CUR(c_sysdate IN DATE) IS --Used when subject ID and Rel type are passed
1330 select relationship_id,relationship_type_code,object_id,subject_id,position_reference,
1331 active_start_date,active_end_date,display_order,mandatory_flag,context,
1332 attribute1,attribute2,attribute3,attribute4,attribute5,attribute6,attribute7,attribute8,
1333 attribute9,attribute10,attribute11,attribute12,attribute13,attribute14,attribute15,
1334 object_version_number
1335 from CSI_II_RELATIONSHIPS cir
1336 where cir.subject_id = p_subject_id
1337 and cir.relationship_type_code = p_rel_type_code
1338 and DECODE(l_active_relationship_only,FND_API.G_TRUE,NVL((cir.active_end_date),c_sysdate+1),c_sysdate+1) > sysdate
1339 and EXISTS (select 'x'
1340 from CSI_ITEM_INSTANCES csi
1341 where csi.instance_id = cir.subject_id
1342 and DECODE(l_active_instances_only,FND_API.G_TRUE,NVL((csi.active_end_date),c_sysdate+1),c_sysdate+1) > sysdate);
1343 --
1344 CURSOR REL_ID_CUR(c_sysdate IN DATE) IS -- Used when only relationship_id is passed
1345 select relationship_id,relationship_type_code,object_id,subject_id,position_reference,
1346 active_start_date,active_end_date,display_order,mandatory_flag,context,
1347 attribute1,attribute2,attribute3,attribute4,attribute5,attribute6,attribute7,attribute8,
1348 attribute9,attribute10,attribute11,attribute12,attribute13,attribute14,attribute15,
1349 object_version_number
1350 from CSI_II_RELATIONSHIPS cir
1351 where cir.relationship_id = p_relationship_id
1352 and DECODE(l_active_relationship_only,FND_API.G_TRUE,NVL((cir.active_end_date),c_sysdate+1),c_sysdate+1) > sysdate
1353 and EXISTS (select 'x'
1354 from CSI_ITEM_INSTANCES csi
1355 where csi.instance_id = cir.subject_id
1356 and DECODE(l_active_instances_only,FND_API.G_TRUE,NVL((csi.active_end_date),c_sysdate+1),c_sysdate+1) > sysdate);
1357 --
1358 CURSOR OTHER_PARAM_CUR(c_sysdate IN DATE) IS
1359 select relationship_id,relationship_type_code,object_id,subject_id,position_reference,
1360 active_start_date,active_end_date,display_order,mandatory_flag,context,
1361 attribute1,attribute2,attribute3,attribute4,attribute5,attribute6,attribute7,attribute8,
1362 attribute9,attribute10,attribute11,attribute12,attribute13,attribute14,attribute15,
1363 object_version_number
1364 from CSI_II_RELATIONSHIPS cir
1365 where cir.relationship_id = NVL(p_relationship_id,cir.relationship_id)
1366 and cir.object_id = NVL(p_object_id,cir.object_id)
1367 and cir.relationship_type_code = NVL(p_rel_type_code,cir.relationship_type_code)
1368 and cir.subject_id = NVL(p_subject_id,cir.subject_id)
1369 and DECODE(l_active_relationship_only,FND_API.G_TRUE,NVL((cir.active_end_date),c_sysdate+1),c_sysdate+1) > sysdate
1370 and EXISTS (select 'x'
1371 from CSI_ITEM_INSTANCES csi
1372 where csi.instance_id = cir.subject_id
1373 and DECODE(l_active_instances_only,FND_API.G_TRUE,NVL((csi.active_end_date),c_sysdate+1),c_sysdate+1) > sysdate);
1374 --
1375 l_ctr NUMBER := 0;
1376 l_sysdate DATE;
1377 COMP_EXCEP EXCEPTION;
1378 BEGIN
1379 select sysdate
1380 into l_sysdate
1381 from dual;
1382 --
1383 IF p_time_stamp IS NOT NULL THEN
1384 l_active_instances_only := FND_API.G_FALSE;
1385 l_active_relationship_only := FND_API.G_FALSE;
1386 ELSE
1387 l_active_relationship_only := p_active_relationship_only;
1388 l_active_instances_only := p_active_instances_only;
1389 END IF;
1390 --
1391 IF p_object_id IS NOT NULL AND
1392 p_rel_type_code IS NOT NULL AND
1393 p_subject_id IS NULL AND
1394 p_relationship_id IS NULL
1395 THEN
1396 IF p_config_only IS NULL OR
1397 p_config_only = fnd_api.g_false
1398 THEN
1399 FOR rel IN OBJECT_CUR(l_sysdate) LOOP
1400 l_ctr := l_ctr + 1;
1401 p_rel_tbl(l_ctr).relationship_id := rel.relationship_id;
1402 p_rel_tbl(l_ctr).relationship_type_code := rel.relationship_type_code;
1403 p_rel_tbl(l_ctr).object_id := rel.object_id;
1404 p_rel_tbl(l_ctr).subject_id := rel.subject_id;
1405 p_rel_tbl(l_ctr).position_reference := rel.position_reference;
1406 p_rel_tbl(l_ctr).active_start_date := rel.active_start_date;
1407 p_rel_tbl(l_ctr).active_end_date := rel.active_end_date;
1408 p_rel_tbl(l_ctr).display_order := rel.display_order;
1409 p_rel_tbl(l_ctr).mandatory_flag := rel.mandatory_flag;
1410 p_rel_tbl(l_ctr).context := rel.context;
1411 p_rel_tbl(l_ctr).attribute1 := rel.attribute1;
1412 p_rel_tbl(l_ctr).attribute2 := rel.attribute2;
1413 p_rel_tbl(l_ctr).attribute3 := rel.attribute3;
1414 p_rel_tbl(l_ctr).attribute4 := rel.attribute4;
1415 p_rel_tbl(l_ctr).attribute5 := rel.attribute5;
1416 p_rel_tbl(l_ctr).attribute6 := rel.attribute6;
1417 p_rel_tbl(l_ctr).attribute7 := rel.attribute7;
1418 p_rel_tbl(l_ctr).attribute8 := rel.attribute8;
1419 p_rel_tbl(l_ctr).attribute9 := rel.attribute9;
1420 p_rel_tbl(l_ctr).attribute10 := rel.attribute10;
1421 p_rel_tbl(l_ctr).attribute11 := rel.attribute11;
1422 p_rel_tbl(l_ctr).attribute12 := rel.attribute12;
1423 p_rel_tbl(l_ctr).attribute13 := rel.attribute13;
1424 p_rel_tbl(l_ctr).attribute14 := rel.attribute14;
1425 p_rel_tbl(l_ctr).attribute15 := rel.attribute15;
1426 p_rel_tbl(l_ctr).object_version_number := rel.object_version_number;
1427 --
1428 Begin
1429 select 'Y'
1430 into p_rel_tbl(l_ctr).subject_has_child
1431 from CSI_II_RELATIONSHIPS
1432 where object_id = rel.subject_id
1433 and relationship_type_code = rel.relationship_type_code
1434 and rownum = 1;
1435 Exception
1436 when no_data_found then
1437 p_rel_tbl(l_ctr).subject_has_child := 'N';
1438 End;
1439 END LOOP;
1440 ELSIF p_config_only IS NOT NULL AND
1441 p_config_only = fnd_api.g_true
1442 THEN
1443 FOR rel IN OBJECT_CUR1(l_sysdate) LOOP
1444 l_ctr := l_ctr + 1;
1445 p_rel_tbl(l_ctr).relationship_id := rel.relationship_id;
1446 p_rel_tbl(l_ctr).relationship_type_code := rel.relationship_type_code;
1447 p_rel_tbl(l_ctr).object_id := rel.object_id;
1448 p_rel_tbl(l_ctr).subject_id := rel.subject_id;
1449 p_rel_tbl(l_ctr).position_reference := rel.position_reference;
1450 p_rel_tbl(l_ctr).active_start_date := rel.active_start_date;
1451 p_rel_tbl(l_ctr).active_end_date := rel.active_end_date;
1452 p_rel_tbl(l_ctr).display_order := rel.display_order;
1453 p_rel_tbl(l_ctr).mandatory_flag := rel.mandatory_flag;
1454 p_rel_tbl(l_ctr).context := rel.context;
1455 p_rel_tbl(l_ctr).attribute1 := rel.attribute1;
1456 p_rel_tbl(l_ctr).attribute2 := rel.attribute2;
1457 p_rel_tbl(l_ctr).attribute3 := rel.attribute3;
1458 p_rel_tbl(l_ctr).attribute4 := rel.attribute4;
1459 p_rel_tbl(l_ctr).attribute5 := rel.attribute5;
1460 p_rel_tbl(l_ctr).attribute6 := rel.attribute6;
1461 p_rel_tbl(l_ctr).attribute7 := rel.attribute7;
1462 p_rel_tbl(l_ctr).attribute8 := rel.attribute8;
1463 p_rel_tbl(l_ctr).attribute9 := rel.attribute9;
1464 p_rel_tbl(l_ctr).attribute10 := rel.attribute10;
1465 p_rel_tbl(l_ctr).attribute11 := rel.attribute11;
1466 p_rel_tbl(l_ctr).attribute12 := rel.attribute12;
1467 p_rel_tbl(l_ctr).attribute13 := rel.attribute13;
1468 p_rel_tbl(l_ctr).attribute14 := rel.attribute14;
1469 p_rel_tbl(l_ctr).attribute15 := rel.attribute15;
1470 p_rel_tbl(l_ctr).object_version_number := rel.object_version_number;
1471 --
1472 Begin
1473 select 'Y'
1474 into p_rel_tbl(l_ctr).subject_has_child
1475 from CSI_II_RELATIONSHIPS
1476 where object_id = rel.subject_id
1477 and relationship_type_code = rel.relationship_type_code
1478 and rownum = 1;
1479 Exception
1480 when no_data_found then
1481 p_rel_tbl(l_ctr).subject_has_child := 'N';
1482 End;
1483 END LOOP;
1484
1485 END IF;
1486 RAISE COMP_EXCEP;
1487 END IF;
1488 --
1489 IF p_object_id IS NOT NULL AND
1490 p_rel_type_code IS NULL AND
1491 p_subject_id IS NULL AND
1492 p_relationship_id IS NULL THEN
1493 FOR rel IN OBJECT_ONLY_CUR(l_sysdate) LOOP
1494 l_ctr := l_ctr + 1;
1495 p_rel_tbl(l_ctr).relationship_id := rel.relationship_id;
1496 p_rel_tbl(l_ctr).relationship_type_code := rel.relationship_type_code;
1497 p_rel_tbl(l_ctr).object_id := rel.object_id;
1498 p_rel_tbl(l_ctr).subject_id := rel.subject_id;
1499 p_rel_tbl(l_ctr).position_reference := rel.position_reference;
1500 p_rel_tbl(l_ctr).active_start_date := rel.active_start_date;
1501 p_rel_tbl(l_ctr).active_end_date := rel.active_end_date;
1502 p_rel_tbl(l_ctr).display_order := rel.display_order;
1503 p_rel_tbl(l_ctr).mandatory_flag := rel.mandatory_flag;
1504 p_rel_tbl(l_ctr).context := rel.context;
1505 p_rel_tbl(l_ctr).attribute1 := rel.attribute1;
1506 p_rel_tbl(l_ctr).attribute2 := rel.attribute2;
1507 p_rel_tbl(l_ctr).attribute3 := rel.attribute3;
1508 p_rel_tbl(l_ctr).attribute4 := rel.attribute4;
1509 p_rel_tbl(l_ctr).attribute5 := rel.attribute5;
1510 p_rel_tbl(l_ctr).attribute6 := rel.attribute6;
1511 p_rel_tbl(l_ctr).attribute7 := rel.attribute7;
1512 p_rel_tbl(l_ctr).attribute8 := rel.attribute8;
1513 p_rel_tbl(l_ctr).attribute9 := rel.attribute9;
1514 p_rel_tbl(l_ctr).attribute10 := rel.attribute10;
1515 p_rel_tbl(l_ctr).attribute11 := rel.attribute11;
1516 p_rel_tbl(l_ctr).attribute12 := rel.attribute12;
1517 p_rel_tbl(l_ctr).attribute13 := rel.attribute13;
1518 p_rel_tbl(l_ctr).attribute14 := rel.attribute14;
1519 p_rel_tbl(l_ctr).attribute15 := rel.attribute15;
1520 p_rel_tbl(l_ctr).object_version_number := rel.object_version_number;
1521 --
1522 Begin
1523 select 'Y'
1524 into p_rel_tbl(l_ctr).subject_has_child
1525 from CSI_II_RELATIONSHIPS
1526 where object_id = rel.subject_id
1527 and relationship_type_code = rel.relationship_type_code
1528 and rownum = 1;
1529 Exception
1530 when no_data_found then
1531 p_rel_tbl(l_ctr).subject_has_child := 'N';
1532 End;
1533 END LOOP;
1534 RAISE COMP_EXCEP;
1535 END IF;
1536 --
1537 IF p_subject_id IS NOT NULL AND
1538 p_rel_type_code IS NOT NULL AND
1539 p_object_id IS NULL AND
1540 p_relationship_id IS NULL THEN
1541 FOR rel IN SUBJECT_CUR(l_sysdate) LOOP
1542 l_ctr := l_ctr + 1;
1543 p_rel_tbl(l_ctr).relationship_id := rel.relationship_id;
1544 p_rel_tbl(l_ctr).relationship_type_code := rel.relationship_type_code;
1545 p_rel_tbl(l_ctr).object_id := rel.object_id;
1546 p_rel_tbl(l_ctr).subject_id := rel.subject_id;
1547 p_rel_tbl(l_ctr).position_reference := rel.position_reference;
1548 p_rel_tbl(l_ctr).active_start_date := rel.active_start_date;
1549 p_rel_tbl(l_ctr).active_end_date := rel.active_end_date;
1550 p_rel_tbl(l_ctr).display_order := rel.display_order;
1551 p_rel_tbl(l_ctr).mandatory_flag := rel.mandatory_flag;
1552 p_rel_tbl(l_ctr).context := rel.context;
1553 p_rel_tbl(l_ctr).attribute1 := rel.attribute1;
1554 p_rel_tbl(l_ctr).attribute2 := rel.attribute2;
1555 p_rel_tbl(l_ctr).attribute3 := rel.attribute3;
1556 p_rel_tbl(l_ctr).attribute4 := rel.attribute4;
1557 p_rel_tbl(l_ctr).attribute5 := rel.attribute5;
1558 p_rel_tbl(l_ctr).attribute6 := rel.attribute6;
1559 p_rel_tbl(l_ctr).attribute7 := rel.attribute7;
1560 p_rel_tbl(l_ctr).attribute8 := rel.attribute8;
1561 p_rel_tbl(l_ctr).attribute9 := rel.attribute9;
1562 p_rel_tbl(l_ctr).attribute10 := rel.attribute10;
1563 p_rel_tbl(l_ctr).attribute11 := rel.attribute11;
1564 p_rel_tbl(l_ctr).attribute12 := rel.attribute12;
1565 p_rel_tbl(l_ctr).attribute13 := rel.attribute13;
1566 p_rel_tbl(l_ctr).attribute14 := rel.attribute14;
1567 p_rel_tbl(l_ctr).attribute15 := rel.attribute15;
1568 p_rel_tbl(l_ctr).object_version_number := rel.object_version_number;
1569 --
1570 Begin
1571 select 'Y'
1572 into p_rel_tbl(l_ctr).subject_has_child
1573 from CSI_II_RELATIONSHIPS
1574 where object_id = rel.subject_id
1575 and relationship_type_code = rel.relationship_type_code
1576 and rownum = 1;
1577 Exception
1578 when no_data_found then
1579 p_rel_tbl(l_ctr).subject_has_child := 'N';
1580 End;
1581 END LOOP;
1582 RAISE COMP_EXCEP;
1583 END IF;
1584 --
1585 IF p_relationship_id IS NOT NULL AND
1586 p_rel_type_code IS NULL AND
1587 p_subject_id IS NULL AND
1588 p_object_id IS NULL THEN
1589 FOR rel IN REL_ID_CUR(l_sysdate) LOOP
1590 l_ctr := l_ctr + 1;
1591 p_rel_tbl(l_ctr).relationship_id := rel.relationship_id;
1592 p_rel_tbl(l_ctr).relationship_type_code := rel.relationship_type_code;
1593 p_rel_tbl(l_ctr).object_id := rel.object_id;
1594 p_rel_tbl(l_ctr).subject_id := rel.subject_id;
1595 p_rel_tbl(l_ctr).position_reference := rel.position_reference;
1596 p_rel_tbl(l_ctr).active_start_date := rel.active_start_date;
1597 p_rel_tbl(l_ctr).active_end_date := rel.active_end_date;
1598 p_rel_tbl(l_ctr).display_order := rel.display_order;
1599 p_rel_tbl(l_ctr).mandatory_flag := rel.mandatory_flag;
1600 p_rel_tbl(l_ctr).context := rel.context;
1601 p_rel_tbl(l_ctr).attribute1 := rel.attribute1;
1602 p_rel_tbl(l_ctr).attribute2 := rel.attribute2;
1603 p_rel_tbl(l_ctr).attribute3 := rel.attribute3;
1604 p_rel_tbl(l_ctr).attribute4 := rel.attribute4;
1605 p_rel_tbl(l_ctr).attribute5 := rel.attribute5;
1606 p_rel_tbl(l_ctr).attribute6 := rel.attribute6;
1607 p_rel_tbl(l_ctr).attribute7 := rel.attribute7;
1608 p_rel_tbl(l_ctr).attribute8 := rel.attribute8;
1609 p_rel_tbl(l_ctr).attribute9 := rel.attribute9;
1610 p_rel_tbl(l_ctr).attribute10 := rel.attribute10;
1611 p_rel_tbl(l_ctr).attribute11 := rel.attribute11;
1612 p_rel_tbl(l_ctr).attribute12 := rel.attribute12;
1613 p_rel_tbl(l_ctr).attribute13 := rel.attribute13;
1614 p_rel_tbl(l_ctr).attribute14 := rel.attribute14;
1615 p_rel_tbl(l_ctr).attribute15 := rel.attribute15;
1616 p_rel_tbl(l_ctr).object_version_number := rel.object_version_number;
1617 --
1618 Begin
1619 select 'Y'
1620 into p_rel_tbl(l_ctr).subject_has_child
1621 from CSI_II_RELATIONSHIPS
1622 where object_id = rel.subject_id
1623 and relationship_type_code = rel.relationship_type_code
1624 and rownum = 1;
1625 Exception
1626 when no_data_found then
1627 p_rel_tbl(l_ctr).subject_has_child := 'N';
1628 End;
1629 END LOOP;
1630 RAISE COMP_EXCEP;
1631 END IF;
1632 -- If other parameters are used then following cursor will be used.
1633 FOR rel in OTHER_PARAM_CUR(l_sysdate) LOOP
1634 l_ctr := l_ctr + 1;
1635 p_rel_tbl(l_ctr).relationship_id := rel.relationship_id;
1636 p_rel_tbl(l_ctr).relationship_type_code := rel.relationship_type_code;
1637 p_rel_tbl(l_ctr).object_id := rel.object_id;
1638 p_rel_tbl(l_ctr).subject_id := rel.subject_id;
1639 p_rel_tbl(l_ctr).position_reference := rel.position_reference;
1640 p_rel_tbl(l_ctr).active_start_date := rel.active_start_date;
1641 p_rel_tbl(l_ctr).active_end_date := rel.active_end_date;
1642 p_rel_tbl(l_ctr).display_order := rel.display_order;
1643 p_rel_tbl(l_ctr).mandatory_flag := rel.mandatory_flag;
1644 p_rel_tbl(l_ctr).context := rel.context;
1645 p_rel_tbl(l_ctr).attribute1 := rel.attribute1;
1646 p_rel_tbl(l_ctr).attribute2 := rel.attribute2;
1647 p_rel_tbl(l_ctr).attribute3 := rel.attribute3;
1648 p_rel_tbl(l_ctr).attribute4 := rel.attribute4;
1649 p_rel_tbl(l_ctr).attribute5 := rel.attribute5;
1650 p_rel_tbl(l_ctr).attribute6 := rel.attribute6;
1651 p_rel_tbl(l_ctr).attribute7 := rel.attribute7;
1652 p_rel_tbl(l_ctr).attribute8 := rel.attribute8;
1653 p_rel_tbl(l_ctr).attribute9 := rel.attribute9;
1654 p_rel_tbl(l_ctr).attribute10 := rel.attribute10;
1655 p_rel_tbl(l_ctr).attribute11 := rel.attribute11;
1656 p_rel_tbl(l_ctr).attribute12 := rel.attribute12;
1657 p_rel_tbl(l_ctr).attribute13 := rel.attribute13;
1658 p_rel_tbl(l_ctr).attribute14 := rel.attribute14;
1659 p_rel_tbl(l_ctr).attribute15 := rel.attribute15;
1660 p_rel_tbl(l_ctr).object_version_number := rel.object_version_number;
1661 --
1662 Begin
1663 select 'Y'
1664 into p_rel_tbl(l_ctr).subject_has_child
1665 from CSI_II_RELATIONSHIPS
1666 where object_id = rel.subject_id
1667 and relationship_type_code = rel.relationship_type_code
1668 and rownum = 1;
1669 Exception
1670 when no_data_found then
1671 p_rel_tbl(l_ctr).subject_has_child := 'N';
1672 End;
1673 END LOOP;
1674 EXCEPTION
1675 WHEN COMP_EXCEP THEN
1676 NULL;
1677 END Get_Next_Level;
1678 --
1679 PROCEDURE Get_Children
1680 (p_relationship_query_rec IN csi_datastructures_pub.relationship_query_rec,
1681 p_rel_tbl OUT NOCOPY csi_datastructures_pub.ii_relationship_tbl,
1682 p_depth IN NUMBER,
1683 p_active_relationship_only IN VARCHAR2,
1684 p_active_instances_only IN VARCHAR2,
1685 p_config_only IN VARCHAR2, -- if true will retrieve instances with config keys
1686 p_time_stamp IN DATE,
1687 p_get_dfs IN VARCHAR2,
1688 p_ii_relationship_level_tbl OUT NOCOPY csi_ii_relationships_pvt.ii_relationship_level_tbl,
1689 x_return_status OUT NOCOPY VARCHAR2,
1690 x_msg_count OUT NOCOPY NUMBER,
1691 x_msg_data OUT NOCOPY VARCHAR2
1692 ) IS
1693 --
1694 l_api_name CONSTANT VARCHAR2(30) := 'get_children';
1695 l_api_version CONSTANT NUMBER := 1.0;
1696 l_rel_tbl csi_datastructures_pub.ii_relationship_tbl;
1697 l_rel_tbl_next_lvl csi_datastructures_pub.ii_relationship_tbl;
1698 l_rel_tbl_temp csi_datastructures_pub.ii_relationship_tbl;
1699 l_rel_tbl_final csi_datastructures_pub.ii_relationship_tbl;
1700 l_next_ind NUMBER := 0;
1701 l_final_ind NUMBER := 0;
1702 l_ctr NUMBER := 0;
1703 l_temp_id NUMBER;
1704 l_prev_id NUMBER;
1705 l_found NUMBER;
1706 l_rel_found NUMBER;
1707 l_depth NUMBER := p_depth;
1708 l_level NUMBER := 1;
1709 l_rel_type_code VARCHAR2(30);
1710 l_object_id NUMBER;
1711 l_subject_id NUMBER;
1712 l_relationship_id NUMBER;
1713 l_time_stamp DATE;
1714 l_max_count NUMBER;
1715 BEGIN
1716 x_return_status := FND_API.G_RET_STS_SUCCESS;
1717 --savepoint Get_Children;
1718 IF l_depth IS NULL OR
1719 l_depth = FND_API.G_MISS_NUM OR
1720 l_depth <= 0 THEN
1721 l_depth := 9999999;
1722 END IF;
1723 --
1724 IF p_relationship_query_rec.object_id IS NULL OR
1725 p_relationship_query_rec.object_id = FND_API.G_MISS_NUM THEN
1726 l_object_id := null;
1727 ELSE
1728 l_object_id := p_relationship_query_rec.object_id;
1729 END IF;
1730 --
1731 IF p_relationship_query_rec.subject_id IS NULL OR
1732 p_relationship_query_rec.subject_id = FND_API.G_MISS_NUM THEN
1733 l_subject_id := null;
1734 ELSE
1735 l_subject_id := p_relationship_query_rec.subject_id;
1736 END IF;
1737 --
1738 IF p_relationship_query_rec.relationship_id IS NULL OR
1739 p_relationship_query_rec.relationship_id = FND_API.G_MISS_NUM THEN
1740 l_relationship_id := null;
1741 ELSE
1742 l_relationship_id := p_relationship_query_rec.relationship_id;
1743 END IF;
1744 --
1745 IF p_relationship_query_rec.relationship_type_code IS NULL OR
1746 p_relationship_query_rec.relationship_type_code = FND_API.G_MISS_CHAR THEN
1747 l_rel_type_code := null;
1748 ELSE
1749 l_rel_type_code := p_relationship_query_rec.relationship_type_code;
1750 END IF;
1751 --
1752 IF l_object_id IS NULL AND
1753 l_subject_id IS NULL AND
1754 l_relationship_id IS NULL AND
1755 l_rel_type_code IS NULL THEN
1756 fnd_message.set_name('CSI', 'CSI_INVALID_PARAMETERS');
1757 fnd_msg_pub.add;
1758 x_return_status := fnd_api.g_ret_sts_error;
1759 RAISE fnd_api.g_exc_error;
1760 END IF;
1761 --
1762 IF p_time_stamp IS NULL OR
1763 p_time_stamp = FND_API.G_MISS_DATE THEN
1764 l_time_stamp := NULL;
1765 ELSE
1766 l_time_stamp := p_time_stamp;
1767 END IF;
1768 --
1769 Get_Next_Level
1770 ( p_object_id => l_object_id,
1771 p_relationship_id => l_relationship_id,
1772 p_subject_id => l_subject_id,
1773 p_rel_tbl => l_rel_tbl,
1774 p_rel_type_code => l_rel_type_code,
1775 p_time_stamp => l_time_stamp,
1776 p_active_relationship_only => p_active_relationship_only,
1777 p_active_instances_only => p_active_instances_only,
1778 p_config_only => p_config_only
1779 );
1780
1781 <<Next_Level>>
1782
1783 l_rel_tbl_next_lvl.delete;
1784 l_next_ind := 0;
1785 --
1786 IF l_rel_tbl.count > 0 THEN
1787 FOR l_ind IN l_rel_tbl.FIRST .. l_rel_tbl.LAST LOOP
1788 l_final_ind := l_final_ind + 1;
1789 l_rel_tbl_final(l_final_ind) := l_rel_tbl(l_ind);
1790 p_ii_relationship_level_tbl(l_final_ind).relationship_id := l_rel_tbl(l_ind).relationship_id;
1791 p_ii_relationship_level_tbl(l_final_ind).current_level := l_level;
1792 /* get the next level using this line ID as the parent */
1793 IF l_object_id IS NOT NULL AND -- Need to Explode if Object ID alone is passed
1794 l_subject_id IS NULL AND
1795 l_relationship_id IS NULL THEN
1796 Get_Next_Level
1797 ( p_object_id => l_rel_tbl(l_ind).subject_id,
1798 p_relationship_id => null,
1799 p_subject_id => null,
1800 p_rel_tbl => l_rel_tbl_temp,
1801 p_rel_type_code => l_rel_type_code,
1802 p_time_stamp => l_time_stamp,
1803 p_active_relationship_only => p_active_relationship_only,
1804 p_active_instances_only => p_active_instances_only,
1805 p_config_only => p_config_only
1806 );
1807 --
1808 IF l_rel_tbl_temp.count > 0 THEN
1809 FOR l_temp_ind IN l_rel_tbl_temp.FIRST .. l_rel_tbl_temp.LAST LOOP
1810 IF l_rel_tbl_final.count > 0 THEN
1811 l_found := 0;
1812 FOR i IN l_rel_tbl_final.FIRST .. l_rel_tbl_final.LAST LOOP
1813 IF l_rel_tbl_final(i).object_id = l_rel_tbl_temp(l_temp_ind).object_id THEN
1814 l_found := 1;
1815 exit;
1816 END IF;
1817 END LOOP;
1818 END IF;
1819 IF l_found = 0 THEN
1820 l_next_ind := l_next_ind + 1;
1821 l_rel_tbl_next_lvl(l_next_ind) := l_rel_tbl_temp(l_temp_ind);
1822 END IF;
1823 END LOOP;
1824 END IF;
1825 END IF; -- Object_id check
1826 END LOOP;
1827 --
1828 IF l_rel_tbl_next_lvl.count > 0 THEN
1829 l_rel_tbl.DELETE;
1830 l_rel_tbl := l_rel_tbl_next_lvl;
1831 --
1832 l_level := l_level + 1;
1833 IF l_level <= l_depth THEN
1834 goto Next_Level;
1835 END IF;
1836 END IF;
1837 END IF;
1838 --
1839 p_rel_tbl := l_rel_tbl_final;
1840 --
1841 -- Need to Sort if Object_id alone is passed
1842 IF nvl(p_get_dfs,FND_API.G_TRUE) = FND_API.G_TRUE AND
1843 l_object_id IS NOT NULL AND
1844 l_subject_id IS NULL AND
1845 l_relationship_id IS NULL THEN
1846 p_rel_tbl.DELETE;
1847 l_ctr := 0;
1848 --
1849 -- The output of l_rel_tbl_final will be Breadth first search Order.
1850 -- This needs to be converted to depth-first-search order.
1851 -- The following LOOP does this.
1852 --
1853 IF l_rel_tbl_final.count > 0 THEN
1854 l_max_count := l_rel_tbl_final.count;
1855 l_ctr := l_ctr + 1;
1856 p_rel_tbl(l_ctr) := l_rel_tbl_final(1);
1857 l_temp_id := l_rel_tbl_final(1).subject_id;
1858 l_rel_tbl_final.DELETE(1);
1859 LOOP
1860 IF p_rel_tbl.count = l_max_count OR
1861 l_rel_tbl_final.count = 0 THEN
1862 exit;
1863 END IF;
1864 FOR rel IN l_rel_tbl_final.FIRST .. l_rel_tbl_final.LAST LOOP
1865 l_found := 0;
1866 IF l_rel_tbl_final.EXISTS(rel) THEN
1867 IF l_rel_tbl_final(rel).object_id = l_temp_id THEN
1868 l_found := 1;
1869 l_ctr := l_ctr + 1;
1870 p_rel_tbl(l_ctr) := l_rel_tbl_final(rel);
1871 l_temp_id := l_rel_tbl_final(rel).subject_id;
1872 l_rel_tbl_final.DELETE(rel);
1873 exit;
1874 END IF;
1875 END IF;
1876 END LOOP;
1877 IF l_found = 0 THEN -- If No more component then go back
1878 -- To get the parent, do not pass l_rel_tbl_final. This may go in an infinite loop.
1879 -- Always better to pass the p_rel_tbl which is for sure has the relationship created.
1880 -- This is because, same subject can exist under two parents with different relationship_type.
1881 l_prev_id := l_temp_id;
1882 l_temp_id := Parent_of(p_subject_id => l_temp_id,
1883 p_rel_tbl => p_rel_tbl);
1884 END IF;
1885 END LOOP;
1886 END IF;
1887 END IF; -- p_get_dfs check
1888 EXCEPTION
1889 WHEN fnd_api.g_exc_error THEN
1890 -- ROLLBACK TO Get_Children;
1891 x_return_status := fnd_api.g_ret_sts_error ;
1892 fnd_msg_pub.count_AND_get
1893 (p_count => x_msg_count ,
1894 p_data => x_msg_data
1895 );
1896
1897 WHEN fnd_api.g_exc_unexpected_error THEN
1898 -- ROLLBACK TO Get_Children;
1899 x_return_status := fnd_api.g_ret_sts_unexp_error ;
1900 fnd_msg_pub.count_AND_get
1901 (p_count => x_msg_count ,
1902 p_data => x_msg_data
1903 );
1904
1905 WHEN OTHERS THEN
1906 -- ROLLBACK TO Get_Children;
1907 x_return_status := fnd_api.g_ret_sts_unexp_error ;
1908 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
1909 fnd_msg_pub.add_exc_msg('csi_relationships_pvt' ,l_api_name);
1910 END IF;
1911 fnd_msg_pub.count_AND_get
1912 (p_count => x_msg_count ,
1913 p_data => x_msg_data
1914 );
1915 END Get_Children;
1916 --
1917 PROCEDURE Get_Top_Most_Parent
1918 ( p_subject_id IN NUMBER,
1919 p_rel_type_code IN VARCHAR2,
1920 p_object_id OUT NOCOPY NUMBER
1921 ) IS
1922 l_object_id NUMBER;
1923 BEGIN
1924 IF p_rel_type_code IS NULL OR
1925 p_subject_id IS NULL THEN
1926 l_object_id := -9999;
1927 p_object_id := l_object_id;
1928 RETURN;
1929 END IF;
1930 l_object_id := p_subject_id;
1931 Begin
1932 select object_id
1933 into l_object_id
1934 from CSI_II_RELATIONSHIPS
1935 where subject_id = p_subject_id
1936 and relationship_type_code = p_rel_type_code
1937 and ((active_end_date is null) or (active_end_date > sysdate));
1938 Exception
1939 when no_data_found then
1940 p_object_id := p_subject_id;
1941 RETURN;
1942 End;
1943 -- Call Recursively for prior parent
1944 Get_Top_Most_Parent
1945 (p_subject_id => l_object_id,
1946 p_rel_type_code => p_rel_type_code,
1947 p_object_id => p_object_id
1948 );
1949 END Get_Top_Most_Parent;
1950
1951 PROCEDURE Get_Immediate_Parents
1952 ( p_subject_id IN NUMBER,
1953 p_rel_type_code IN VARCHAR2,
1954 p_rel_tbl OUT NOCOPY csi_datastructures_pub.ii_relationship_tbl
1955 ) IS
1956 l_ctr NUMBER := 0;
1957 l_object_id NUMBER;
1958 l_subject_id NUMBER;
1959 l_exists VARCHAR2(1);
1960 BEGIN
1961 IF p_subject_id IS NULL OR
1962 p_subject_id = FND_API.G_MISS_NUM THEN
1963 Return;
1964 END IF;
1965 --
1966 l_subject_id := p_subject_id;
1967 --
1968 LOOP
1969 Begin
1970 select object_id
1971 into l_object_id
1972 from CSI_II_RELATIONSHIPS
1973 where subject_id = l_subject_id
1974 and relationship_type_code = p_rel_type_code
1975 and ((active_end_date is null) or (active_end_date > sysdate));
1976 --
1977 l_ctr := l_ctr + 1;
1978 p_rel_tbl(l_ctr).subject_id := l_subject_id;
1979 p_rel_tbl(l_ctr).object_id := l_object_id;
1980 p_rel_tbl(l_ctr).relationship_type_code := p_rel_type_code;
1981 --
1982 l_exists := 'N';
1983 IF p_rel_tbl.count > 0 THEN
1984 FOR j in p_rel_tbl.FIRST .. p_rel_tbl.LAST Loop
1985 IF l_object_id = p_rel_tbl(j).subject_id THEN
1986 l_exists := 'Y';
1987 exit;
1988 END IF;
1989 End Loop;
1990 END IF;
1991 --
1992 IF l_exists = 'Y' THEN
1993 exit;
1994 END IF;
1995 --
1996 l_subject_id := l_object_id;
1997 Exception
1998 when no_data_found then
1999 exit;
2000 End;
2001 END LOOP;
2002 END Get_Immediate_Parents;
2003 --
2004
2005
2006 PROCEDURE get_relationships
2007 (
2008 p_api_version IN NUMBER,
2009 p_commit IN VARCHAR2,
2010 p_init_msg_list IN VARCHAR2,
2011 p_validation_level IN NUMBER,
2012 p_relationship_query_rec IN csi_datastructures_pub.relationship_query_rec,
2013 p_depth IN NUMBER,
2014 p_time_stamp IN DATE,
2015 p_active_relationship_only IN VARCHAR2,
2016 p_recursive_flag IN VARCHAR2,
2017 x_relationship_tbl OUT NOCOPY csi_datastructures_pub.ii_relationship_tbl,
2018 x_return_status OUT NOCOPY VARCHAR2,
2019 x_msg_count OUT NOCOPY NUMBER,
2020 x_msg_data OUT NOCOPY VARCHAR2
2021 )
2022 IS
2023 CURSOR config_csr (instance_id NUMBER) IS
2024 SELECT * FROM csi_ii_relationships
2025 WHERE object_id=instance_id;
2026
2027 l_api_name CONSTANT VARCHAR2(30) := 'get_relationships';
2028 l_api_version CONSTANT NUMBER := 1.0;
2029 l_return_status_full VARCHAR2(1);
2030 l_access_flag VARCHAR2(1);
2031 i NUMBER := 1;
2032 l_instance_id NUMBER;
2033 l_returned_rec_count NUMBER := 0;
2034 l_rel_rec csi_datastructures_pub.ii_relationship_rec;
2035 l_debug_level NUMBER;
2036 l_new_rec csi_datastructures_pub.ii_relationship_rec;
2037 l_flag VARCHAR2(4);
2038 l_active_relationship_only VARCHAR2(1) := p_active_relationship_only;
2039 l_depth NUMBER;
2040 l_found VARCHAR2(1); -- Added by sguthiva for bug 2373109
2041 xc_relationship_tbl csi_datastructures_pub.ii_relationship_tbl ;
2042 l_relationship_tbl csi_datastructures_pub.ii_relationship_tbl ;
2043 l_ins_child_tbl csi_datastructures_pub.ii_relationship_tbl ;
2044 l_rel_count NUMBER := 0;
2045 l_temp_relationship_tbl csi_datastructures_pub.ii_relationship_tbl;
2046 l_rel_tbl csi_datastructures_pub.ii_relationship_tbl;
2047 l_ctr NUMBER;
2048 l_exists VARCHAR2(1);
2049 l_exists_flag VARCHAR2(1);
2050 l_msg_index NUMBER;
2051 l_msg_count NUMBER;
2052 l_last_purge_date DATE;
2053 TYPE NUMLIST IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
2054 l_exp_inst_tbl NUMLIST;
2055 --
2056 l_instance_rec CSI_DATASTRUCTURES_PUB.INSTANCE_HEADER_REC;
2057 l_party_header_tbl CSI_DATASTRUCTURES_PUB.PARTY_HEADER_TBL;
2058 l_account_header_tbl CSI_DATASTRUCTURES_PUB.PARTY_ACCOUNT_HEADER_TBL;
2059 l_org_header_tbl CSI_DATASTRUCTURES_PUB.ORG_UNITS_HEADER_TBL;
2060 l_pricing_attrib_tbl CSI_DATASTRUCTURES_PUB.PRICING_ATTRIBS_TBL;
2061 l_ext_attrib_tbl CSI_DATASTRUCTURES_PUB.EXTEND_ATTRIB_VALUES_TBL;
2062 l_ext_attrib_def_tbl CSI_DATASTRUCTURES_PUB.EXTEND_ATTRIB_TBL;
2063 l_asset_header_tbl CSI_DATASTRUCTURES_PUB.INSTANCE_ASSET_HEADER_TBL;
2064 --
2065 /*
2066 CURSOR CHILD_CUR(p_instance_id IN NUMBER) IS
2067 SELECT subject_id
2068 from csi_ii_relationships
2069 connect by prior subject_id = object_id
2070 start with subject_id = p_instance_id;
2071 */
2072 -- Added for bug 2999353
2073 /*
2074 CURSOR expired_cur (p_object_id IN number) IS
2075 SELECT relationship_id
2076 ,active_end_date
2077 FROM csi_ii_relationships
2078 WHERE relationship_type_code='COMPONENT-OF'
2079 START WITH object_id = p_object_id
2080 CONNECT BY object_id = PRIOR subject_id;
2081 */
2082 l_fin_count NUMBER;
2083 l_fin_count1 NUMBER;
2084 l_exp_tbl csi_datastructures_pub.ii_relationship_tbl;
2085 l_temp_tbl csi_datastructures_pub.ii_relationship_tbl;
2086 l_exp_act_tbl csi_datastructures_pub.ii_relationship_tbl;
2087 l_found1 BOOLEAN;
2088 l_found2 BOOLEAN;
2089 l_expire BOOLEAN;
2090 l_exp_count NUMBER:=0;
2091 l_relationship_query_rec csi_datastructures_pub.relationship_query_rec;
2092 l_ii_relationship_level_tbl csi_ii_relationships_pvt.ii_relationship_level_tbl;
2093
2094 BEGIN
2095 -- standard start of api savepoint
2096 -- SAVEPOINT get_relationships_pvt;
2097
2098 -- standard call to check for call compatibility.
2099 IF NOT fnd_api.compatible_api_call ( l_api_version,
2100 p_api_version,
2101 l_api_name,
2102 g_pkg_name)
2103 THEN
2104 RAISE fnd_api.g_exc_unexpected_error;
2105 END IF;
2106
2107
2108 -- initialize message list if p_init_msg_list is set to true.
2109 IF fnd_api.to_boolean( p_init_msg_list )
2110 THEN
2111 fnd_msg_pub.initialize;
2112 END IF;
2113
2114
2115
2116
2117 -- initialize api return status to success
2118 x_return_status := fnd_api.g_ret_sts_success;
2119
2120
2121 l_debug_level:=fnd_profile.value('CSI_DEBUG_LEVEL');
2122 IF (l_debug_level > 0) THEN
2123 CSI_gen_utility_pvt.put_line( 'get_relationships');
2124 END IF;
2125
2126 IF (l_debug_level > 1) THEN
2127 CSI_gen_utility_pvt.put_line(
2128 p_api_version ||'-'||
2129 p_commit ||'-'||
2130 p_init_msg_list ||'-'||
2131 p_validation_level ||'-'||
2132 p_depth ||'_'||
2133 p_time_stamp );
2134
2135 csi_gen_utility_pvt.dump_rel_query_rec(p_relationship_query_rec);
2136 END IF;
2137
2138
2139 --
2140 -- API BODY
2141 --
2142 -- ******************************************************************
2143 -- validate environment
2144 -- ******************************************************************
2145
2146 IF
2147 ( ((p_relationship_query_rec.relationship_id IS NULL) OR (p_relationship_query_rec.relationship_id = fnd_api.g_miss_num))
2148 AND ((p_relationship_query_rec.relationship_type_code IS NULL) OR (p_relationship_query_rec.relationship_type_code = fnd_api.g_miss_char))
2149 AND ((p_relationship_query_rec.object_id IS NULL) OR (p_relationship_query_rec.object_id = fnd_api.g_miss_num))
2150 AND ((p_relationship_query_rec.subject_id IS NULL) OR (p_relationship_query_rec.subject_id = fnd_api.g_miss_num))
2151 )
2152 THEN
2153 fnd_message.set_name('CSI', 'CSI_INVALID_PARAMETERS');
2154 fnd_msg_pub.add;
2155 x_return_status := fnd_api.g_ret_sts_error;
2156 RAISE fnd_api.g_exc_error;
2157 END IF;
2158
2159 /* Cyclic Relationships */
2160 IF (p_relationship_query_rec.relationship_type_code = 'CONNECTED-TO')
2161 THEN
2162 IF ((p_relationship_query_rec.subject_id IS NULL
2163 AND p_relationship_query_rec.object_id IS NULL)
2164 OR ((p_relationship_query_rec.subject_id IS NOT NULL
2165 AND p_relationship_query_rec.subject_id <> fnd_api.g_miss_num)
2166 AND (p_relationship_query_rec.object_id IS NOT NULL
2167 AND p_relationship_query_rec.object_id <> fnd_api.g_miss_num)))
2168 THEN
2169 fnd_message.set_name('CSI', 'CSI_INVALID_PARAMETERS');
2170 fnd_msg_pub.add;
2171 x_return_status := fnd_api.g_ret_sts_error;
2172 RAISE fnd_api.g_exc_error;
2173 ELSIF ((p_relationship_query_rec.subject_id IS NOT NULL
2174 AND p_relationship_query_rec.subject_id <> fnd_api.g_miss_num))
2175 OR (p_relationship_query_rec.object_id IS NOT NULL
2176 AND p_relationship_query_rec.object_id <> fnd_api.g_miss_num)
2177 THEN
2178 IF p_relationship_query_rec.subject_id IS NOT NULL
2179 AND p_relationship_query_rec.subject_id <> fnd_api.g_miss_num
2180 THEN
2181 l_instance_id := p_relationship_query_rec.subject_id;
2182 ELSIF p_relationship_query_rec.object_id IS NOT NULL
2183 AND p_relationship_query_rec.object_id <> fnd_api.g_miss_num
2184 THEN
2185 l_instance_id := p_relationship_query_rec.object_id;
2186 END IF;
2187 END IF;
2188
2189 csi_ii_relationships_pvt.get_cyclic_relationships(
2190 p_api_version => p_api_version,
2191 p_commit => fnd_api.g_false,
2192 p_init_msg_list => p_init_msg_list,
2193 p_validation_level => p_validation_level,
2194 p_instance_id => l_instance_id,
2195 p_depth => p_depth ,
2196 p_time_stamp => p_time_stamp,
2197 p_active_relationship_only => p_active_relationship_only,
2198 x_relationship_tbl => xc_relationship_tbl,
2199 x_return_status => x_return_status,
2200 x_msg_count => x_msg_count,
2201 x_msg_data => x_msg_data
2202 );
2203
2204 -- x_relationship_tbl.DELETE ;
2205 --
2206 -- Get the last purge date from csi_item_instances table
2207 --
2208 BEGIN
2209 SELECT last_purge_date
2210 INTO l_last_purge_date
2211 FROM CSI_ITEM_INSTANCES
2212 WHERE rownum < 2;
2213 EXCEPTION
2214 WHEN no_data_found THEN
2215 NULL;
2216 WHEN others THEN
2217 NULL;
2218 END;
2219 --
2220 IF xc_relationship_tbl.COUNT > 0 THEN
2221 FOR i IN xc_relationship_tbl.FIRST..xc_relationship_tbl.LAST
2222 LOOP
2223 l_rel_rec := null ;
2224 l_rel_rec := xc_relationship_tbl(i);
2225
2226 IF ((p_time_stamp IS NOT NULL) AND (p_time_stamp <> FND_API.G_MISS_DATE))
2227 THEN
2228 IF ((l_last_purge_date IS NOT NULL) AND (p_time_stamp <= l_last_purge_date))
2229 THEN
2230 csi_gen_utility_pvt.put_line('Warning! History for this entity has already been purged for the datetime stamp passed. ' ||
2231 'Please provide a valid datetime stamp.');
2232 FND_MESSAGE.Set_Name('CSI', 'CSI_API_HIST_AFTER_PURGE_REQ');
2233 FND_MSG_PUB.ADD;
2234 ELSE
2235 get_history( p_rel_rec => l_rel_rec
2236 ,p_new_rec => l_new_rec
2237 ,p_flag => l_flag
2238 ,p_time_stamp => p_time_stamp);
2239
2240 IF l_flag='ADD'
2241 THEN
2242 l_relationship_tbl(i) := l_new_rec;
2243 END IF;
2244 END IF;
2245 ELSE
2246 l_relationship_tbl(i) := l_rel_rec;
2247 END IF;
2248 --
2249 IF ( (p_time_stamp IS NOT NULL) AND (p_time_stamp <> fnd_api.g_miss_date) )THEN
2250 IF l_relationship_tbl.count > 0
2251 THEN
2252 BEGIN
2253 SELECT 'Y'
2254 INTO l_relationship_tbl(i).subject_has_child
2255 FROM CSI_II_RELATIONSHIPS
2256 WHERE OBJECT_ID = l_relationship_tbl(i).subject_id
2257 AND CREATION_DATE <= p_time_stamp
2258 AND (ACTIVE_END_DATE IS NULL OR ACTIVE_END_DATE >= p_time_stamp)
2259 AND ROWNUM < 2;
2260 EXCEPTION
2261 WHEN OTHERS THEN
2262 --l_relationship_tbl(i).subject_has_child := 'N';
2263 IF (l_relationship_tbl(i).relationship_id IS NOT NULL --Added for bug 2999353
2264 AND l_relationship_tbl(i).relationship_id <> fnd_api.g_miss_num) --Added for bug 2999353
2265 THEN
2266 l_relationship_tbl(i).subject_has_child := 'N';
2267 END IF;
2268 END;
2269 END IF; -- l_relationship_tbl.count > 0
2270 END IF;
2271 END LOOP;
2272 END IF;
2273 --
2274 l_exp_inst_tbl.DELETE;
2275 IF l_relationship_tbl.count > 0 THEN
2276 FOR rel_row in l_relationship_tbl.FIRST .. l_relationship_tbl.LAST LOOP
2277 IF l_relationship_tbl.EXISTS(rel_row) THEN
2278 l_exists_flag := 'N';
2279 IF l_exp_inst_tbl.count > 0 THEN
2280 FOR exp_rec in l_exp_inst_tbl.FIRST .. l_exp_inst_tbl.LAST LOOP
2281 IF l_exp_inst_tbl(exp_rec) = l_relationship_tbl(rel_row).subject_id OR
2282 l_exp_inst_tbl(exp_rec) = l_relationship_tbl(rel_row).object_id THEN
2283 l_exists_flag := 'Y';
2284 exit;
2285 END IF;
2286 END LOOP;
2287 END IF;
2288 --
2289 IF l_exists_flag <> 'Y' THEN
2290 IF ( (p_time_stamp IS NOT NULL) AND (p_time_stamp <> fnd_api.g_miss_date)
2291 AND (l_relationship_tbl(rel_row).relationship_id IS NOT NULL --Added for bug 2999353
2292 AND l_relationship_tbl(rel_row).relationship_id <> fnd_api.g_miss_num))--Added for bug 2999353
2293 THEN
2294 l_instance_rec.instance_id := l_relationship_tbl(rel_row).subject_id;
2295 CSI_ITEM_INSTANCE_PUB.Get_item_instance_details(
2296 1.0,
2297 'F',
2298 'T',
2299 1,
2300 l_instance_rec,
2301 'F',
2302 l_party_header_tbl,
2303 'F',
2304 l_account_header_tbl,
2305 'F',
2306 l_org_header_tbl,
2307 'F',
2308 l_pricing_attrib_tbl,
2309 'F',
2310 l_ext_attrib_tbl,
2311 l_ext_attrib_def_tbl,
2312 'F',
2313 l_asset_header_tbl,
2314 'F',
2315 p_time_stamp,
2316 x_return_status,
2317 x_msg_count,
2318 x_msg_data
2319 );
2320 --
2321 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
2322 l_msg_index := 1;
2323 l_msg_count := x_msg_count;
2324 WHILE l_msg_count > 0 LOOP
2325 x_msg_data := FND_MSG_PUB.GET
2326 ( l_msg_index,
2327 FND_API.G_FALSE );
2328 csi_gen_utility_pvt.put_line( ' Error from Get_Item_Instance_Details.. ');
2329 csi_gen_utility_pvt.put_line('MESSAGE DATA = '||x_msg_data);
2330 l_msg_index := l_msg_index + 1;
2331 l_msg_count := l_msg_count - 1;
2332 END LOOP;
2333 RAISE FND_API.G_EXC_ERROR;
2334 END IF;
2335 IF nvl(l_instance_rec.active_end_date,(sysdate+1)) < sysdate THEN
2336 l_ctr := l_exp_inst_tbl.count;
2337 l_ctr := l_ctr + 1;
2338 l_exp_inst_tbl(l_ctr) := l_relationship_tbl(rel_row).subject_id;
2339 ELSE
2340 l_rel_count := l_rel_count + 1;
2341 l_temp_relationship_tbl(l_rel_count) := l_relationship_tbl(rel_row);
2342 END IF;
2343 ELSE -- p_time_stamp is not passed
2344 Begin
2345 Select 'x'
2346 into l_exists
2347 from CSI_ITEM_INSTANCES
2348 where instance_id = l_relationship_tbl(rel_row).subject_id
2349 and nvl(active_end_date,(sysdate+1)) < sysdate;
2350 l_ctr := l_exp_inst_tbl.count;
2351 l_ctr := l_ctr + 1;
2352 l_exp_inst_tbl(l_ctr) := l_relationship_tbl(rel_row).subject_id;
2353 Exception
2354 when no_data_found then -- Active Instance
2355 l_rel_count := l_rel_count + 1;
2356 l_temp_relationship_tbl(l_rel_count) := l_relationship_tbl(rel_row);
2357 End;
2358 END IF;
2359 END IF;
2360 END IF;
2361 END LOOP;
2362 END IF;
2363 -- Added by sguthiva for 2562028 fix
2364 l_rel_count := 0;
2365 IF p_active_relationship_only = 'T' THEN
2366 IF l_temp_relationship_tbl.count > 0 THEN
2367 FOR rel_row in l_temp_relationship_tbl.FIRST .. l_temp_relationship_tbl.LAST
2368 LOOP
2369 IF l_temp_relationship_tbl.EXISTS(rel_row) THEN
2370 IF l_temp_relationship_tbl(rel_row).active_end_date IS NULL OR
2371 l_temp_relationship_tbl(rel_row).active_end_date > SYSDATE THEN
2372 l_rel_count := l_rel_count + 1;
2373 x_relationship_tbl(l_rel_count) := l_temp_relationship_tbl(rel_row);
2374 END IF;
2375 END IF;
2376 END LOOP;
2377 END IF;
2378 ELSE
2379 x_relationship_tbl := l_temp_relationship_tbl;
2380 END IF;
2381
2382 -- End addition by sguthiva
2383 ELSE ---if not CONNECTED-TO
2384 --gen_select(l_crit_relations_rec,l_select_cl);
2385 IF ( ((p_relationship_query_rec.relationship_id IS NULL) OR (p_relationship_query_rec.relationship_id = fnd_api.g_miss_num))
2386 AND ((p_relationship_query_rec.subject_id IS NULL) OR (p_relationship_query_rec.subject_id = fnd_api.g_miss_num))
2387 AND ((p_relationship_query_rec.relationship_type_code IS NULL) OR (p_relationship_query_rec.relationship_type_code = fnd_api.g_miss_char)) )
2388 THEN
2389 IF( (p_relationship_query_rec.object_id IS NOT NULL) AND (p_relationship_query_rec.object_id <> fnd_api.g_miss_num) )
2390 THEN
2391 IF( (p_relationship_query_rec.relationship_type_code IS NULL) OR (p_relationship_query_rec.relationship_type_code = fnd_api.g_miss_char) )
2392 THEN
2393 fnd_message.set_name('CSI','CSI_NO_RELCODE_PASSED');
2394 fnd_msg_pub.add;
2395 RAISE fnd_api.g_exc_error;
2396 END IF;
2397 END IF;
2398 END IF;
2399 /*
2400 gen_relations_where(l_crit_relations_rec,l_active_relationship_only,l_depth,l_relations_where);
2401 IF dbms_sql.is_open(l_cur_get_relations) THEN
2402 dbms_sql.close_CURSOR(l_cur_get_relations);
2403 END IF;
2404
2405 l_cur_get_relations := dbms_sql.open_CURSOR;
2406
2407 dbms_sql.parse(l_cur_get_relations, l_select_cl||l_relations_where , dbms_sql.native);
2408
2409 bind(l_crit_relations_rec, l_cur_get_relations);
2410
2411 define_columns(l_def_relations_rec, l_cur_get_relations);
2412
2413 l_ignore := dbms_sql.execute(l_cur_get_relations);
2414 */
2415 Get_Children
2416 (p_relationship_query_rec => p_relationship_query_rec,
2417 p_rel_tbl => l_rel_tbl,
2418 p_depth => p_depth,
2419 p_active_relationship_only => p_active_relationship_only,
2420 p_time_stamp => p_time_stamp,
2421 p_get_dfs => fnd_api.g_true,
2422 p_ii_relationship_level_tbl => l_ii_relationship_level_tbl,
2423 x_return_status => x_return_status,
2424 x_msg_count => x_msg_count,
2425 x_msg_data => x_msg_data
2426 );
2427 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS)
2428 THEN
2429 l_msg_index := 1;
2430 l_msg_count := x_msg_count;
2431 WHILE l_msg_count > 0
2432 LOOP
2433 x_msg_data := FND_MSG_PUB.GET
2434 ( l_msg_index,
2435 FND_API.G_FALSE );
2436 csi_gen_utility_pvt.put_line( ' Error from Get_Chidren.. ');
2437 csi_gen_utility_pvt.put_line('MESSAGE DATA = '||x_msg_data);
2438 l_msg_index := l_msg_index + 1;
2439 l_msg_count := l_msg_count - 1;
2440 END LOOP;
2441 RAISE FND_API.G_EXC_ERROR;
2442 END IF;
2443
2444 --
2445 -- Get the last purge date from csi_item_instances table
2446 --
2447 BEGIN
2448 SELECT last_purge_date
2449 INTO l_last_purge_date
2450 FROM CSI_ITEM_INSTANCES
2451 WHERE rownum < 2;
2452 EXCEPTION
2453 WHEN no_data_found THEN
2454 NULL;
2455 WHEN others THEN
2456 NULL;
2457 END;
2458 --
2459 IF p_time_stamp IS NULL OR p_time_stamp = fnd_api.g_miss_date
2460 THEN
2461 x_relationship_tbl:=l_rel_tbl;
2462 ELSIF l_rel_tbl.COUNT >0
2463 THEN
2464 FOR p_time_csr IN l_rel_tbl.FIRST .. l_rel_tbl.LAST
2465 LOOP
2466 IF l_rel_tbl.EXISTS(p_time_csr)
2467 THEN
2468 l_new_rec:=NULL;
2469 l_returned_rec_count:=l_returned_rec_count+1;
2470
2471 IF ((l_last_purge_date IS NOT NULL) AND (p_time_stamp <= l_last_purge_date))
2472 THEN
2473 csi_gen_utility_pvt.put_line('Warning! History for this entity has already been purged for the datetime stamp passed. ' ||
2474 'Please provide a valid datetime stamp.');
2475 FND_MESSAGE.Set_Name('CSI', 'CSI_API_HIST_AFTER_PURGE_REQ');
2476 FND_MSG_PUB.ADD;
2477 ELSE
2478 get_history( p_rel_rec => l_rel_tbl(p_time_csr)
2479 ,p_new_rec => l_new_rec
2480 ,p_flag => l_flag
2481 ,p_time_stamp => p_time_stamp);
2482 END IF;
2483 -- Added by sguthiva for bug 2373109
2484 IF l_new_rec.relationship_id IS NOT NULL AND
2485 l_new_rec.relationship_id <> fnd_api.g_miss_num
2486 THEN
2487 IF l_flag='ADD' THEN
2488 l_relationship_tbl(l_returned_rec_count) :=l_new_rec;
2489 -- Added for bug 2999353
2490 IF l_relationship_tbl(l_returned_rec_count).subject_id <>l_rel_tbl(p_time_csr).subject_id
2491 THEN
2492 l_relationship_query_rec:=p_relationship_query_rec;
2493 --
2494 l_depth:=0;
2495 IF l_ii_relationship_level_tbl.COUNT > 0 AND
2496 p_depth IS NOT NULL AND
2497 p_depth <> fnd_api.g_miss_num AND
2498 p_depth >0
2499 THEN
2500 FOR l_lvl_csr IN l_ii_relationship_level_tbl.FIRST .. l_ii_relationship_level_tbl.LAST
2501 LOOP
2502 IF l_ii_relationship_level_tbl.EXISTS(l_lvl_csr)
2503 THEN
2504 IF l_ii_relationship_level_tbl(l_lvl_csr).relationship_id IS NOT NULL AND
2505 l_ii_relationship_level_tbl(l_lvl_csr).relationship_id <> fnd_api.g_miss_num AND
2506 l_ii_relationship_level_tbl(l_lvl_csr).relationship_id =l_relationship_tbl(l_returned_rec_count).relationship_id
2507 THEN
2508 l_depth:=p_depth-l_ii_relationship_level_tbl(l_lvl_csr).current_level;
2509 EXIT;
2510 END IF;
2511 END IF;
2512 END LOOP;
2513 END IF;
2514 IF l_depth>0 OR
2515 p_depth IS NULL
2516 THEN
2517 l_relationship_query_rec.object_id:=l_relationship_tbl(l_returned_rec_count).subject_id;
2518 l_relationship_query_rec.subject_id:=fnd_api.g_miss_num;
2519 csi_gen_utility_pvt.put_line('Into recurrsive call for get_relationships. ');
2520 csi_ii_relationships_pvt.get_relationships
2521 ( p_api_version => p_api_version
2522 ,p_commit => p_commit
2523 ,p_init_msg_list => p_init_msg_list
2524 ,p_validation_level => p_validation_level
2525 ,p_relationship_query_rec => l_relationship_query_rec
2526 ,p_depth => l_depth
2527 ,p_time_stamp => p_time_stamp
2528 ,p_active_relationship_only => p_active_relationship_only
2529 ,p_recursive_flag => fnd_api.g_true
2530 ,x_relationship_tbl => x_relationship_tbl
2531 ,x_return_status => x_return_status
2532 ,x_msg_count => x_msg_count
2533 ,x_msg_data => x_msg_data
2534 );
2535
2536 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS)
2537 THEN
2538 l_msg_index := 1;
2539 l_msg_count := x_msg_count;
2540 WHILE l_msg_count > 0
2541 LOOP
2542 x_msg_data := FND_MSG_PUB.GET
2543 ( l_msg_index,
2544 FND_API.G_FALSE );
2545 csi_gen_utility_pvt.put_line( ' Error from recursive Get_relationships.. ');
2546 csi_gen_utility_pvt.put_line('MESSAGE DATA = '||x_msg_data);
2547 l_msg_index := l_msg_index + 1;
2548 l_msg_count := l_msg_count - 1;
2549 END LOOP;
2550 RAISE FND_API.G_EXC_ERROR;
2551 END IF;
2552
2553 IF x_relationship_tbl.count > 0
2554 THEN
2555 FOR i IN x_relationship_tbl.FIRST .. x_relationship_tbl.LAST
2556 LOOP
2557 IF x_relationship_tbl.EXISTS(i)
2558 THEN
2559 IF x_relationship_tbl(i).relationship_id IS NOT NULL AND
2560 x_relationship_tbl(i).relationship_id <> fnd_api.g_miss_num
2561 THEN
2562 l_returned_rec_count := l_returned_rec_count + 1;
2563 l_relationship_tbl(l_returned_rec_count):=x_relationship_tbl(i);
2564 END IF;
2565 END IF;
2566 END LOOP;
2567 END IF;
2568 END IF;
2569 END IF;
2570 -- End May29 Addition
2571 END IF;
2572 ELSE
2573 -- Do not add the current record by default
2574 BEGIN
2575 SELECT 'x'
2576 INTO l_found
2577 FROM csi_ii_relationships_h
2578 WHERE relationship_id=l_rel_tbl(p_time_csr).relationship_id;
2579 EXCEPTION
2580 WHEN NO_DATA_FOUND THEN
2581 l_relationship_tbl(l_returned_rec_count) :=l_rel_tbl(p_time_csr);
2582 WHEN OTHERS THEN
2583 NULL;
2584 END;
2585 END IF;
2586 -- End addition by sguthiva for bug 2373109
2587
2588 --
2589 IF ( (p_time_stamp IS NOT NULL) AND (p_time_stamp <> fnd_api.g_miss_date) )THEN
2590 IF l_relationship_tbl.count > 0
2591 THEN
2592 BEGIN
2593 SELECT 'Y'
2594 INTO l_relationship_tbl(l_returned_rec_count).subject_has_child
2595 FROM CSI_II_RELATIONSHIPS
2596 WHERE OBJECT_ID = l_relationship_tbl(l_returned_rec_count).subject_id
2597 AND CREATION_DATE <= p_time_stamp
2598 AND (ACTIVE_END_DATE IS NULL OR ACTIVE_END_DATE >= p_time_stamp)
2599 AND ROWNUM < 2;
2600 EXCEPTION
2601 WHEN OTHERS THEN
2602 --l_relationship_tbl(l_returned_rec_count).subject_has_child := 'N';
2603 IF (l_relationship_tbl(l_returned_rec_count).relationship_id IS NOT NULL --Added for bug 2999353
2604 AND l_relationship_tbl(l_returned_rec_count).relationship_id <> fnd_api.g_miss_num) --Added for bug 2999353
2605 THEN
2606 l_relationship_tbl(l_returned_rec_count).subject_has_child := 'N';
2607 END IF;
2608 END;
2609 END IF; -- l_relationship_tbl.count > 0
2610 END IF;
2611 --END IF;
2612 ELSE
2613 EXIT;
2614 END IF;
2615 END LOOP;
2616 --
2617 l_exp_inst_tbl.DELETE;
2618 IF l_relationship_tbl.count > 0 THEN
2619 FOR rel_row in l_relationship_tbl.FIRST .. l_relationship_tbl.LAST
2620 LOOP
2621 IF l_relationship_tbl.EXISTS(rel_row) THEN
2622 l_exists_flag := 'N';
2623 IF l_exp_inst_tbl.count > 0 THEN
2624 FOR exp_rec in l_exp_inst_tbl.FIRST .. l_exp_inst_tbl.LAST LOOP
2625 IF l_exp_inst_tbl(exp_rec) = l_relationship_tbl(rel_row).subject_id THEN
2626 l_exists_flag := 'Y';
2627 exit;
2628 END IF;
2629 END LOOP;
2630 END IF;
2631 --
2632 IF l_exists_flag <> 'Y' THEN
2633 IF ( (p_time_stamp IS NOT NULL) AND (p_time_stamp <> fnd_api.g_miss_date)
2634 AND (l_relationship_tbl(rel_row).relationship_id IS NOT NULL --Added for bug 2999353
2635 AND l_relationship_tbl(rel_row).relationship_id <> fnd_api.g_miss_num))--Added for bug 2999353
2636 THEN
2637 IF p_recursive_flag=fnd_api.g_false
2638 THEN
2639 l_instance_rec.instance_id := l_relationship_tbl(rel_row).subject_id;
2640 CSI_ITEM_INSTANCE_PUB.Get_item_instance_details(
2641 1.0,
2642 'F',
2643 'T',
2644 1,
2645 l_instance_rec,
2646 'F',
2647 l_party_header_tbl,
2648 'F',
2649 l_account_header_tbl,
2650 'F',
2651 l_org_header_tbl,
2652 'F',
2653 l_pricing_attrib_tbl,
2654 'F',
2655 l_ext_attrib_tbl,
2656 l_ext_attrib_def_tbl,
2657 'F',
2658 l_asset_header_tbl,
2659 'F',
2660 p_time_stamp,
2661 x_return_status,
2662 x_msg_count,
2663 x_msg_data
2664 );
2665 ELSE
2666 l_instance_rec.instance_id := l_relationship_tbl(rel_row).subject_id;
2667 l_instance_rec.active_end_date := NULL;
2668 END IF;
2669 --
2670 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
2671 l_msg_index := 1;
2672 l_msg_count := x_msg_count;
2673 WHILE l_msg_count > 0 LOOP
2674 x_msg_data := FND_MSG_PUB.GET
2675 ( l_msg_index,
2676 FND_API.G_FALSE );
2677 csi_gen_utility_pvt.put_line( ' Error from Get_Item_Instance_Details.. ');
2678 csi_gen_utility_pvt.put_line('MESSAGE DATA = '||x_msg_data);
2679 l_msg_index := l_msg_index + 1;
2680 l_msg_count := l_msg_count - 1;
2681 END LOOP;
2682 RAISE FND_API.G_EXC_ERROR;
2683 END IF;
2684 IF nvl(l_instance_rec.active_end_date,(sysdate+1)) < sysdate THEN
2685 l_ctr := l_exp_inst_tbl.count;
2686 l_ctr := l_ctr + 1;
2687 l_exp_inst_tbl(l_ctr) := l_relationship_tbl(rel_row).subject_id;
2688 Get_Children
2689 (p_object_id => l_relationship_tbl(rel_row).subject_id,
2690 p_rel_tbl => l_ins_child_tbl
2691 );
2692 -- Modified for bug 2999353
2693 IF l_ins_child_tbl.COUNT >0
2694 THEN
2695 FOR v_rec in l_ins_child_tbl.first .. l_ins_child_tbl.last
2696 LOOP
2697 IF l_ins_child_tbl.EXISTS(v_rec)
2698 THEN
2699 l_ctr := l_ctr + 1;
2700 l_exp_inst_tbl(l_ctr) := l_ins_child_tbl(v_rec).subject_id;
2701 END IF;
2702 END LOOP;
2703 END IF;
2704 -- End modification for bug 2999353
2705 ELSE
2706 l_rel_count := l_rel_count + 1;
2707 l_temp_relationship_tbl(l_rel_count) := l_relationship_tbl(rel_row);
2708 END IF;
2709 /*
2710 ELSE -- p_time_stamp is not passed
2711 Begin
2712 Select 'x'
2713 into l_exists
2714 from CSI_ITEM_INSTANCES
2715 where instance_id = l_relationship_tbl(rel_row).subject_id
2716 and nvl(active_end_date,(sysdate+1)) < sysdate;
2717 l_ctr := l_exp_inst_tbl.count;
2718 FOR v_rec in CHILD_CUR(l_relationship_tbl(rel_row).subject_id) LOOP
2719 l_ctr := l_ctr + 1;
2720 l_exp_inst_tbl(l_ctr) := v_rec.subject_id;
2721 END LOOP;
2722 Exception
2723 when no_data_found then -- Active Instance
2724 l_rel_count := l_rel_count + 1;
2725 l_temp_relationship_tbl(l_rel_count) := l_relationship_tbl(rel_row);
2726 End;
2727 */
2728 END IF;
2729 END IF;
2730 END IF;
2731 END LOOP;
2732 END IF;
2733 --
2734 l_rel_count := 0;
2735 IF p_active_relationship_only = 'T' THEN
2736 IF l_temp_relationship_tbl.count > 0 THEN
2737 FOR rel_row in l_temp_relationship_tbl.FIRST .. l_temp_relationship_tbl.LAST
2738 LOOP
2739 IF l_temp_relationship_tbl.EXISTS(rel_row) THEN
2740 IF l_temp_relationship_tbl(rel_row).active_end_date IS NULL OR
2741 l_temp_relationship_tbl(rel_row).active_end_date > SYSDATE THEN
2742 l_rel_count := l_rel_count + 1;
2743 x_relationship_tbl(l_rel_count) := l_temp_relationship_tbl(rel_row);
2744 -- Added for bug 2999353
2745 ELSIF ( l_temp_relationship_tbl(rel_row).active_end_date IS NOT NULL AND
2746 l_temp_relationship_tbl(rel_row).active_end_date < SYSDATE ) OR
2747 ( l_temp_relationship_tbl(rel_row).relationship_type_code<>'COMPONENT-OF' )
2748 THEN
2749 -- Here we capture expired relationship records to use them later down in the program to
2750 -- eliminate all its child components.
2751 l_exp_count:=l_exp_count + 1;
2752 l_exp_tbl(l_exp_count) := l_temp_relationship_tbl(rel_row);
2753 -- End addition for bug 2999353
2754 END IF;
2755 END IF;
2756 END LOOP;
2757 END IF;
2758 ELSE
2759 -- Added for bug 2999353
2760 IF l_temp_relationship_tbl.count > 0 THEN
2761 FOR l_csr IN l_temp_relationship_tbl.FIRST .. l_temp_relationship_tbl.LAST
2762 LOOP
2763 IF l_temp_relationship_tbl.EXISTS(l_csr)
2764 THEN
2765 IF l_temp_relationship_tbl(l_csr).relationship_id IS NOT NULL AND
2766 l_temp_relationship_tbl(l_csr).relationship_id<> fnd_api.g_miss_num
2767 THEN
2768 IF l_temp_relationship_tbl(l_csr).relationship_type_code<>'COMPONENT-OF'
2769 THEN
2770 l_exp_count:=l_exp_count + 1;
2771 l_exp_tbl(l_exp_count) := l_temp_relationship_tbl(l_csr);
2772 END IF;
2773 l_found2:=FALSE;
2774 IF x_relationship_tbl.COUNT>0
2775 THEN
2776 FOR i IN x_relationship_tbl.FIRST..x_relationship_tbl.LAST
2777 LOOP
2778 IF x_relationship_tbl.EXISTS(i)
2779 THEN
2780 IF x_relationship_tbl(i).relationship_id=l_temp_relationship_tbl(l_csr).relationship_id
2781 THEN
2782 l_found2:=TRUE;
2783 EXIT;
2784 END IF;
2785 END IF;
2786 END LOOP;
2787 IF NOT(l_found2)
2788 THEN
2789 x_relationship_tbl(x_relationship_tbl.count+1) := l_temp_relationship_tbl(l_csr);
2790 END IF;
2791 ELSE
2792 x_relationship_tbl(x_relationship_tbl.count+1) := l_temp_relationship_tbl(l_csr);
2793 -- End addition bug 2999353
2794 END IF;
2795 END IF;
2796 END IF;
2797 END LOOP;
2798 END IF;
2799 END IF;
2800
2801 -- sguthiva added the following code for bug 2999353
2802 -- The following code has been added to eliminate all the child components of an expired relationship record.
2803 IF p_active_relationship_only = 'T'
2804 THEN
2805 l_fin_count:=0;
2806 l_temp_relationship_tbl.DELETE;
2807 l_temp_relationship_tbl:=x_relationship_tbl;
2808 IF l_exp_tbl.COUNT > 0
2809 THEN
2810 FOR l_exp_csr IN l_exp_tbl.FIRST .. l_exp_tbl.LAST
2811 LOOP
2812 IF l_exp_tbl.EXISTS(l_exp_csr)
2813 THEN
2814 IF l_exp_tbl(l_exp_csr).relationship_id IS NOT NULL AND
2815 l_exp_tbl(l_exp_csr).relationship_id <> fnd_api.g_miss_num AND
2816 nvl(l_exp_tbl(l_exp_csr).attribute1,'NOT-EXPIRED')<>'EXPIRED'
2817 THEN
2818 l_exp_act_tbl.delete;
2819 -- Used the following procedure instead of a cursor which use
2820 -- connect by select statement.
2821 Get_Children
2822 (p_object_id => l_exp_tbl(l_exp_csr).subject_id,
2823 p_rel_tbl => l_exp_act_tbl
2824 );
2825 IF l_exp_act_tbl.count >0 --Added for bug 3228702
2826 THEN
2827 FOR l_active_csr IN l_exp_act_tbl.first .. l_exp_act_tbl.last --expired_cur(l_exp_tbl(l_exp_csr).subject_id)
2828 LOOP
2829 IF l_exp_act_tbl.EXISTS(l_active_csr)
2830 THEN
2831 l_expire:=TRUE;
2832 l_fin_count:=l_fin_count+1;
2833 IF l_exp_act_tbl(l_active_csr).active_end_date IS NULL OR
2834 l_exp_act_tbl(l_active_csr).active_end_date > SYSDATE AND
2835 l_exp_act_tbl(l_active_csr).relationship_type_code='COMPONENT-OF'
2836 THEN
2837 l_temp_tbl(l_fin_count).relationship_id := l_exp_act_tbl(l_active_csr).relationship_id;
2838 ELSIF l_exp_act_tbl(l_active_csr).relationship_type_code='COMPONENT-OF'
2839 THEN
2840 FOR l_end_date_csr IN l_exp_tbl.FIRST .. l_exp_tbl.LAST
2841 LOOP
2842 IF l_exp_act_tbl(l_active_csr).relationship_id=l_exp_tbl(l_end_date_csr).relationship_id
2843 THEN
2844 -- Since this record is expired which is a child of an expired record and should
2845 -- not be picked while looping for active records.
2846 l_exp_tbl(l_end_date_csr).attribute1:='EXPIRED';
2847 END IF;
2848 END LOOP;
2849 END IF;
2850 END IF;
2851 END LOOP; -- End loop for expired_cur
2852 END IF;
2853
2854 END IF; -- End if for 'EXPIRED' check
2855 END IF;
2856 END LOOP; -- End loop for exprired records captured in table l_exp_tbl.
2857 END IF;
2858
2859 -- Since there are active relationship records for an expired relationship record
2860 -- so delete all the records from output table x_relationship_tbl.
2861 IF l_expire
2862 THEN
2863 x_relationship_tbl.DELETE;
2864 END IF;
2865
2866 -- Here we build x_relationship_tbl which consists of only active records.
2867
2868 l_fin_count1:=0;
2869 IF l_temp_relationship_tbl.COUNT > 0
2870 THEN
2871 FOR l_tot_csr IN l_temp_relationship_tbl.FIRST .. l_temp_relationship_tbl.LAST
2872 LOOP
2873 l_found1:=FALSE;
2874 IF l_temp_relationship_tbl.EXISTS(l_tot_csr)
2875 THEN
2876 IF l_temp_tbl.COUNT > 0
2877 THEN
2878 FOR l_exp_cld_csr IN l_temp_tbl.FIRST .. l_temp_tbl.LAST
2879 LOOP
2880 IF l_temp_tbl.EXISTS(l_exp_cld_csr)
2881 THEN
2882 IF l_temp_tbl(l_exp_cld_csr).relationship_id = l_temp_relationship_tbl(l_tot_csr).relationship_id
2883 THEN
2884 l_found1:=TRUE;
2885 END IF;
2886 END IF;
2887 END LOOP;
2888 END IF;
2889 END IF;
2890
2891 IF NOT(l_found1)
2892 THEN
2893 l_fin_count1 :=l_fin_count1+1;
2894 IF l_temp_relationship_tbl(l_tot_csr).relationship_id IS NOT NULL AND
2895 l_temp_relationship_tbl(l_tot_csr).relationship_id <> fnd_api.g_miss_num
2896 THEN
2897 x_relationship_tbl(l_fin_count1):=l_temp_relationship_tbl(l_tot_csr);
2898 END IF;
2899 END IF;
2900
2901 END LOOP;
2902 END IF;
2903
2904
2905 END IF; -- This end if is for p_active_relationship_only
2906 -- sk End addition
2907 END IF;
2908 END IF;
2909
2910 --
2911 -- end of API body
2912 --
2913 -- standard call to get message count and if count is 1, get message info.
2914 fnd_msg_pub.count_AND_get
2915 ( p_count => x_msg_count,
2916 p_data => x_msg_data
2917 );
2918 EXCEPTION
2919 WHEN fnd_api.g_exc_error THEN
2920 -- ROLLBACK TO get_relationships_pvt;
2921 x_return_status := fnd_api.g_ret_sts_error ;
2922 fnd_msg_pub.count_AND_get
2923 (p_count => x_msg_count ,
2924 p_data => x_msg_data
2925 );
2926
2927 WHEN fnd_api.g_exc_unexpected_error THEN
2928 -- ROLLBACK TO get_relationships_pvt;
2929 x_return_status := fnd_api.g_ret_sts_unexp_error ;
2930 fnd_msg_pub.count_AND_get
2931 (p_count => x_msg_count ,
2932 p_data => x_msg_data
2933 );
2934
2935 WHEN OTHERS THEN
2936 -- ROLLBACK TO get_relationships_pvt;
2937 x_return_status := fnd_api.g_ret_sts_unexp_error ;
2938 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
2939 fnd_msg_pub.add_exc_msg(g_pkg_name ,l_api_name);
2940 END IF;
2941 fnd_msg_pub.count_AND_get
2942 (p_count => x_msg_count ,
2943 p_data => x_msg_data
2944 );
2945 END get_relationships;
2946 /* End of Cyclic Relationships */
2947
2948 /* Start of Cyclic Relationships */
2949 FUNCTION valid_in_parameters
2950 ( p_relship_id IN VARCHAR2,
2951 p_object_id IN NUMBER,
2952 p_subject_id IN NUMBER
2953 ) RETURN BOOLEAN IS
2954
2955 BEGIN
2956 IF p_relship_id is not null AND P_relship_id <> fnd_api.g_miss_num
2957 THEN
2958 IF ((p_object_id is null OR p_object_id = fnd_api.g_miss_num)
2959 AND (p_subject_id is null OR p_subject_id = fnd_api.g_miss_num))
2960 THEN
2961 RETURN TRUE;
2962 ELSIF ((p_object_id is null OR p_object_id = fnd_api.g_miss_num)
2963 AND (p_subject_id is not null AND p_subject_id <> fnd_api.g_miss_num))
2964 THEN
2965 RETURN FALSE;
2966 ELSIF ((p_object_id is not null AND p_object_id <> fnd_api.g_miss_num)
2967 AND (p_subject_id is null OR p_subject_id = fnd_api.g_miss_num))
2968 THEN
2969 RETURN TRUE;
2970 ELSIF ((p_object_id is not null AND p_object_id <> fnd_api.g_miss_num)
2971 AND (p_subject_id is not null AND p_subject_id <> fnd_api.g_miss_num))
2972 THEN
2973 RETURN TRUE;
2974 END IF;
2975 END IF;
2976 EXCEPTION
2977 WHEN OTHERS THEN
2978 RETURN FALSE;
2979 END valid_in_parameters;
2980
2981 FUNCTION config_set(p_relationship_id IN NUMBER)
2982 RETURN BOOLEAN IS
2983
2984 l_configurator_id NUMBER;
2985 BEGIN
2986 /* SELECT configurator_id
2987 INTO l_configurator_id
2988 FROM csi_ii_relationships
2989 WHERE relationship_id=p_relationship_id;
2990 */
2991 IF l_configurator_id is not null
2992 THEN
2993 fnd_message.set_name('CSI','CSI_CONFIG_SET');
2994 fnd_message.set_token('relationship_id',p_relationship_id);
2995 fnd_msg_pub.add;
2996 RETURN TRUE;
2997 ELSE
2998 RETURN FALSE;
2999 END IF;
3000 EXCEPTION
3001 WHEN NO_DATA_FOUND THEN
3002 RETURN TRUE;
3003 END config_set;
3004
3005 -- This function is used for 'CONNECTED-TO' relationship type.It checks whether 'CONNECTED-TO'
3006 -- relation exists in the reverse direction for the given subject and object
3007
3008 FUNCTION relationship_not_exists
3009 ( p_subject_id IN NUMBER,
3010 p_object_id IN NUMBER,
3011 p_relship_type_code IN VARCHAR2,
3012 p_mode IN VARCHAR2,
3013 p_relationship_id IN NUMBER
3014 ) RETURN BOOLEAN IS
3015
3016 l_object_id NUMBER;
3017 l_subject_id NUMBER;
3018 l_relship_type_code VARCHAR2(30);
3019 l_dummy VARCHAR2(1) :=NULL;
3020 BEGIN
3021 IF p_mode='CREATE'
3022 THEN
3023 SELECT 'x'
3024 INTO l_dummy
3025 FROM csi_ii_relationships
3026 WHERE (( subject_id=p_object_id AND object_id=p_subject_id)
3027 OR (subject_id=p_subject_id AND object_id=p_object_id))
3028 AND relationship_type_code = p_relship_type_code
3029 AND (active_end_date IS NULL OR active_end_date > SYSDATE)
3030 AND ROWNUM = 1 ;
3031 IF SQL%FOUND THEN
3032 fnd_message.set_name('CSI','CSI_RELATIONSHIP_EXISTS');
3033 fnd_message.set_token('relationship_type',p_relship_type_code);
3034 fnd_message.set_token('subject_id',p_subject_id);
3035 fnd_message.set_token('object_id',p_object_id);
3036 fnd_msg_pub.add;
3037 RETURN FALSE;
3038 ELSE
3039 RETURN TRUE;
3040 END IF;
3041 ELSIF p_mode='UPDATE'
3042 THEN
3043 SELECT 'x'
3044 INTO l_dummy
3045 FROM csi_ii_relationships
3046 WHERE (( subject_id=p_object_id AND object_id=p_subject_id)
3047 OR (subject_id=p_subject_id AND object_id=p_object_id))
3048 AND relationship_type_code = p_relship_type_code
3049 AND (active_end_date IS NULL OR active_end_date > SYSDATE)
3050 AND relationship_id<>p_relationship_id
3051 AND ROWNUM = 1 ;
3052 IF SQL%FOUND THEN
3053 fnd_message.set_name('CSI','CSI_RELATIONSHIP_EXISTS');
3054 fnd_message.set_token('relationship_type',p_relship_type_code);
3055 fnd_message.set_token('subject_id',p_subject_id);
3056 fnd_message.set_token('object_id',p_object_id);
3057 fnd_msg_pub.add;
3058 RETURN FALSE;
3059 ELSE
3060 RETURN TRUE;
3061 END IF;
3062 END IF;
3063
3064 EXCEPTION
3065 WHEN NO_DATA_FOUND THEN
3066 RETURN TRUE;
3067 END relationship_not_exists;
3068
3069 /* End of Cyclic Relationships */
3070
3071 -- Start of att enhancements by sguthiva
3072 -- This function to make sure that an object or subject instance can participate
3073 -- atmost 2 'CONNECTED-TO' relationships.
3074
3075
3076 FUNCTION relationship_for_link
3077 ( p_instance_id IN NUMBER,
3078 p_mode IN VARCHAR2,
3079 p_relationship_id IN NUMBER
3080 ) RETURN BOOLEAN IS
3081 l_count NUMBER :=0;
3082 BEGIN
3083
3084 IF p_mode='CREATE'
3085 THEN
3086 SELECT COUNT(*)
3087 INTO l_count
3088 FROM csi_ii_relationships
3089 WHERE (subject_id=p_instance_id OR object_id=p_instance_id)
3090 AND relationship_type_code = 'CONNECTED-TO'
3091 AND (active_end_date IS NULL OR active_end_date > SYSDATE);
3092 ELSIF p_mode='UPDATE'
3093 THEN
3094 -- Code for update will check other than itself
3095 -- and during unexpiring of an expired relationship.
3096 SELECT COUNT(*)
3097 INTO l_count
3098 FROM csi_ii_relationships
3099 WHERE (subject_id=p_instance_id OR object_id=p_instance_id)
3100 AND relationship_type_code = 'CONNECTED-TO'
3101 AND relationship_id <> p_relationship_id
3102 AND (active_end_date IS NULL OR active_end_date > SYSDATE);
3103 END IF;
3104
3105
3106 IF l_count >= 2
3107 THEN
3108 RETURN TRUE;
3109 ELSE
3110 RETURN FALSE;
3111 END IF;
3112 EXCEPTION
3113 WHEN OTHERS THEN
3114 RETURN FALSE;
3115 END relationship_for_link;
3116
3117 -- This function to find it the instance is of type link
3118 FUNCTION Is_link_type
3119 ( p_instance_id IN NUMBER
3120 ) RETURN BOOLEAN IS
3121 l_link VARCHAR2(30);
3122 l_class VARCHAR2(30) := 'LINK';
3123 --
3124 BEGIN
3125 SELECT msi.ib_item_instance_class
3126 INTO l_link
3127 FROM csi_item_instances cii
3128 ,mtl_system_items_b msi
3129 WHERE cii.instance_id = p_instance_id
3130 AND msi.inventory_item_id=cii.inventory_item_id
3131 AND msi.organization_id=cii.last_vld_organization_id
3132 AND msi.ib_item_instance_class = l_class;
3133 RETURN TRUE;
3134 EXCEPTION
3135 WHEN NO_DATA_FOUND THEN
3136 RETURN FALSE;
3137 END Is_link_type;
3138
3139 -- End of att enhancements by sguthiva
3140 /* ------------------------------------------------------------------------------------------------------*/
3141 /* during creation/updation of a relationship check for a record for passed subject_id and */
3142 /* relationship_type_code */
3143 /* 1. If exists then return an error message and return false else return true */
3144 /* a sub: b ,rel code: component-of */
3145 /* / \ passed (b,component-of) --return false */
3146 /* b c passed (b,member-of) --return true */
3147 /* ------------------------------------------------------------------------------------------------------*/
3148
3149 FUNCTION subject_exists
3150 ( p_subject_id IN NUMBER,
3151 p_relship_type_code IN VARCHAR2,
3152 p_relationship_id IN NUMBER,
3153 p_mode IN VARCHAR2
3154 ) RETURN BOOLEAN IS
3155
3156 l_subject_id NUMBER;
3157 l_relship_type_code VARCHAR2(30);
3158 l_dummy VARCHAR2(1) :=NULL;
3159 l_return_value BOOLEAN := TRUE;
3160 BEGIN
3161 IF p_mode='CREATE'
3162 THEN
3163 BEGIN
3164 SELECT 'x'
3165 INTO l_dummy
3166 FROM csi_ii_relationships
3167 WHERE subject_id=p_subject_id
3168 AND relationship_type_code = p_relship_type_code
3169 AND (active_end_date IS NULL OR active_end_date > SYSDATE)
3170 --AND (SYSDATE BETWEEN NVL(active_start_date, SYSDATE) AND NVL(active_end_date, SYSDATE))
3171 AND ROWNUM=1;
3172 IF SQL%FOUND THEN
3173
3174 fnd_message.set_name('CSI','CSI_SUB_RELCODE_EXIST');
3175 fnd_message.set_token('relationship_type_code',p_relship_type_code);
3176 fnd_message.set_token('SUBJECT_ID',p_subject_id);
3177 fnd_msg_pub.add;
3178 RETURN FALSE;
3179 END IF;
3180 EXCEPTION
3181 WHEN NO_DATA_FOUND THEN
3182 RETURN TRUE;
3183 END;
3184 ELSIF p_mode='UPDATE'
3185 THEN
3186
3187 BEGIN
3188 SELECT 'x'
3189 INTO l_dummy
3190 FROM csi_ii_relationships
3191 WHERE subject_id=p_subject_id
3192 AND relationship_type_code = p_relship_type_code
3193 AND relationship_id <> p_relationship_id
3194 AND (active_end_date IS NULL OR active_end_date > SYSDATE)
3195 --AND (SYSDATE BETWEEN NVL(active_start_date, SYSDATE) AND NVL(active_end_date, SYSDATE))
3196 AND ROWNUM=1;
3197 IF SQL%FOUND THEN
3198
3199 fnd_message.set_name('CSI','CSI_SUB_RELCODE_EXIST');
3200 fnd_message.set_token('relationship_type_code',p_relship_type_code);
3201 fnd_message.set_token('SUBJECT_ID',p_subject_id);
3202 fnd_msg_pub.add;
3203 RETURN FALSE;
3204 END IF;
3205 EXCEPTION
3206 WHEN NO_DATA_FOUND THEN
3207 RETURN TRUE;
3208 END;
3209 END IF;
3210 END subject_exists;
3211
3212 /* Cyclic Relationships */
3213 /* This function checks whether the subject already exist for the relation
3214 ship */
3215 FUNCTION subject_relship_exists
3216 ( p_relationship_id IN NUMBER,
3217 p_subject_id IN NUMBER,
3218 p_relship_type_code IN VARCHAR2
3219 ) RETURN BOOLEAN IS
3220 l_subject_id NUMBER;
3221 l_relship_type_code VARCHAR2(30);
3222 l_dummy VARCHAR2(1) :=NULL;
3223 BEGIN
3224 IF p_relationship_id is not null
3225 AND(p_subject_id is null OR p_subject_id= fnd_api.g_miss_num)
3226 THEN
3227 RETURN TRUE;
3228 ELSE
3229 SELECT subject_id,relationship_type_code
3230 INTO l_subject_id,l_relship_type_code
3231 FROM csi_ii_relationships
3232 WHERE relationship_id=p_relationship_id
3233 AND subject_id =p_subject_id;
3234
3235 IF SQL%FOUND THEN
3236 RETURN TRUE;
3237 ELSE
3238 RETURN FALSE;
3239 END IF;
3240 END IF;
3241 EXCEPTION
3242 WHEN NO_DATA_FOUND THEN
3243 RETURN FALSE;
3244 END subject_relship_exists;
3245
3246 /* ---------------------------------------------------------------------------------------------- */
3247 /* during updating a relationship check for the existence of object_id or relationship_type_code */
3248 /* For the passed relationship_id */
3249 /* example - relid -reltype-object-sub-TRUE */
3250 /* 1- componentof-i10-i12-exist record */
3251 /* 1- componentof-i20-i13-FALSE */
3252 /* 1- memberof -i10-i13-FALSE */
3253 /* 1- componentof-i10-i13-TRUE */
3254 /* ---------------------------------------------------------------------------------------------- */
3255
3256 FUNCTION object_relship_exists
3257 ( p_relationship_id IN NUMBER,
3258 p_object_id IN NUMBER,
3259 p_relship_type_code IN VARCHAR2
3260 ) RETURN BOOLEAN IS
3261 l_object_id NUMBER;
3262 l_relship_type_code VARCHAR2(30);
3263 l_dummy VARCHAR2(1) :=NULL;
3264 BEGIN
3265 SELECT object_id,relationship_type_code
3266 INTO l_object_id,l_relship_type_code
3267 FROM csi_ii_relationships
3268 WHERE relationship_id=p_relationship_id;
3269
3270 IF SQL%FOUND THEN
3271 IF ( (l_object_id<>p_object_id) OR (l_relship_type_code<>p_relship_type_code) ) THEN
3272 fnd_message.set_name('CSI','CSI_CANNOT_UPDATE');
3273 fnd_message.set_token('object_id',p_object_id);
3274 fnd_message.set_token('relationship_type_code',p_relship_type_code);
3275 fnd_msg_pub.add;
3276 RETURN FALSE;
3277 ELSE
3278 RETURN TRUE;
3279 END IF;
3280 END IF;
3281 EXCEPTION
3282 WHEN NO_DATA_FOUND THEN
3283 RETURN TRUE;
3284 END object_relship_exists;
3285
3286 /* ----------------------------------------------------------------------------------------------- */
3287 /* This procedure(during creation)is used to check if the received subject is already an object */
3288 /* If found then raise error else success */
3289 /* a */
3290 /* / \ */
3291 /* b c */
3292 /* / \ */
3293 /* d a -> Not allowed */
3294 /* ----------------------------------------------------------------------------------------------- */
3295
3296 PROCEDURE check_for_object
3297 ( p_subject_id IN NUMBER,
3298 p_object_id IN NUMBER,
3299 p_relationship_type_code IN VARCHAR2,
3300 x_return_status OUT NOCOPY VARCHAR2,
3301 x_msg_count OUT NOCOPY NUMBER,
3302 x_msg_data OUT NOCOPY VARCHAR2
3303 )
3304 IS
3305 l_rel_tbl csi_datastructures_pub.ii_relationship_tbl;
3306 p_relationship_query_rec csi_datastructures_pub.relationship_query_rec;
3307 l_ii_relationship_level_tbl csi_ii_relationships_pvt.ii_relationship_level_tbl;
3308 /* CURSOR chk_obj_csr IS
3309 SELECT 'x'
3310 FROM csi_ii_relationships
3311 WHERE subject_id = p_object_id
3312 AND relationship_type_code = p_relationship_type_code
3313 START WITH object_id = p_subject_id
3314 CONNECT BY object_id = PRIOR subject_id;
3315 l_dummy VARCHAR2(1); */
3316
3317 BEGIN
3318 x_return_status := fnd_api.g_ret_sts_success;
3319 IF p_subject_id IS NULL OR
3320 p_subject_id = FND_API.G_MISS_NUM OR
3321 p_object_id IS NULL OR
3322 p_object_id = FND_API.G_MISS_NUM THEN
3323 fnd_message.set_name('CSI', 'CSI_PARENT_CHILD_INVALID');
3324 fnd_msg_pub.add;
3325 x_return_status := fnd_api.g_ret_sts_error;
3326 RETURN;
3327 END IF;
3328 --
3329 p_relationship_query_rec.object_id := p_subject_id; -- To check for Loop
3330 p_relationship_query_rec.relationship_type_code := p_relationship_type_code;
3331 --
3332 IF p_subject_id <> p_object_id THEN
3333 csi_ii_relationships_pvt.Get_Children
3334 ( p_relationship_query_rec => p_relationship_query_rec,
3335 p_rel_tbl => l_rel_tbl,
3336 p_depth => NULL,
3337 p_active_relationship_only => FND_API.G_TRUE,
3338 p_active_instances_only => FND_API.G_FALSE,
3339 p_time_stamp => FND_API.G_MISS_DATE,
3340 p_get_dfs => FND_API.G_FALSE,
3341 p_ii_relationship_level_tbl => l_ii_relationship_level_tbl,
3342 x_return_status => x_return_status,
3343 x_msg_count => x_msg_count,
3344 x_msg_data => x_msg_data
3345 );
3346 --
3347 IF x_return_status = FND_API.G_RET_STS_SUCCESS AND
3348 l_rel_tbl.count > 0 THEN
3349 FOR j in l_rel_tbl.FIRST .. l_rel_tbl.LAST LOOP
3350 IF l_rel_tbl(j).subject_id = p_object_id THEN
3351 fnd_message.set_name('CSI','CSI_CHILD_PARENT_REL_LOOP');
3352 fnd_msg_pub.add;
3353 x_return_status := fnd_api.g_ret_sts_error;
3354 exit;
3355 END IF;
3356 END LOOP;
3357 END IF;
3358 ELSE
3359 fnd_message.set_name('CSI', 'CSI_PARENT_CHILD_INVALID');
3360 fnd_msg_pub.add;
3361 x_return_status := fnd_api.g_ret_sts_error;
3362 END IF;
3363 END check_for_object;
3364
3365 PROCEDURE validate_history(p_old_relship_rec IN csi_datastructures_pub.ii_relationship_rec,
3366 p_new_relship_rec IN csi_datastructures_pub.ii_relationship_rec,
3367 p_transaction_id IN NUMBER,
3368 p_flag IN VARCHAR2,
3369 p_sysdate IN DATE,
3370 x_return_status OUT NOCOPY VARCHAR2,
3371 x_msg_count OUT NOCOPY NUMBER,
3372 x_msg_data OUT NOCOPY VARCHAR2)
3373 IS
3374 l_old_relship_rec csi_datastructures_pub.ii_relationship_rec :=p_old_relship_rec;
3375 l_new_relship_rec csi_datastructures_pub.ii_relationship_rec :=p_new_relship_rec;
3376 l_transaction_id NUMBER := p_transaction_id;
3377 l_full_dump NUMBER;
3378 l_relship_hist_rec csi_datastructures_pub.relationship_history_rec;
3379
3380 CURSOR rel_hist_csr (p_rel_hist_id NUMBER) IS
3381 SELECT relationship_history_id
3382 ,relationship_id
3383 ,transaction_id
3384 ,old_subject_id
3385 ,new_subject_id
3386 ,old_position_reference
3387 ,new_position_reference
3388 ,old_active_start_date
3389 ,new_active_start_date
3390 ,old_active_end_date
3391 ,new_active_end_date
3392 ,old_mandatory_flag
3393 ,new_mandatory_flag
3394 ,old_context
3395 ,new_context
3396 ,old_attribute1
3397 ,new_attribute1
3398 ,old_attribute2
3399 ,new_attribute2
3400 ,old_attribute3
3401 ,new_attribute3
3402 ,old_attribute4
3403 ,new_attribute4
3404 ,old_attribute5
3405 ,new_attribute5
3406 ,old_attribute6
3407 ,new_attribute6
3408 ,old_attribute7
3409 ,new_attribute7
3410 ,old_attribute8
3411 ,new_attribute8
3412 ,old_attribute9
3413 ,new_attribute9
3414 ,old_attribute10
3415 ,new_attribute10
3416 ,old_attribute11
3417 ,new_attribute11
3418 ,old_attribute12
3419 ,new_attribute12
3420 ,old_attribute13
3421 ,new_attribute13
3422 ,old_attribute14
3423 ,new_attribute14
3424 ,old_attribute15
3425 ,new_attribute15
3426 ,full_dump_flag
3427 ,object_version_number
3428 FROM csi_ii_relationships_h
3429 WHERE csi_ii_relationships_h.relationship_history_id = p_rel_hist_id
3430 FOR UPDATE OF object_version_number;
3431
3432 l_rel_hist_csr rel_hist_csr%ROWTYPE;
3433 l_rel_hist_id NUMBER;
3434
3435 BEGIN
3436
3437
3438 x_return_status := fnd_api.g_ret_sts_success;
3439 --
3440 IF csi_datastructures_pub.g_install_param_rec.fetch_flag IS NULL THEN
3441 csi_gen_utility_pvt.populate_install_param_rec;
3442 END IF;
3443 --
3444 l_full_dump := csi_datastructures_pub.g_install_param_rec.history_full_dump_frequency;
3445 --
3446 IF l_full_dump IS NULL THEN
3447 FND_MESSAGE.SET_NAME('CSI','CSI_API_GET_FULL_DUMP_FAILED');
3448 FND_MSG_PUB.ADD;
3449 RAISE FND_API.G_EXC_ERROR;
3450 END IF;
3451 --
3452 IF p_flag = 'EXPIRE' THEN
3453 l_new_relship_rec.active_end_date := p_sysdate;
3454 END IF;
3455 -- Start of modifications for Bug#2547034 on 09/20/02 - rtalluri
3456 BEGIN
3457 SELECT relationship_history_id
3458 INTO l_rel_hist_id
3459 FROM csi_ii_relationships_h h
3460 WHERE h.transaction_id = p_transaction_id
3461 AND h.relationship_id = p_old_relship_rec.relationship_id;
3462
3463 OPEN rel_hist_csr(l_rel_hist_id);
3464 FETCH rel_hist_csr INTO l_rel_hist_csr ;
3465 CLOSE rel_hist_csr;
3466
3467 IF l_rel_hist_csr.full_dump_flag = 'Y'
3468 THEN
3469 csi_ii_relationships_h_pkg.update_row(
3470 p_relationship_history_id => l_rel_hist_id ,
3471 p_relationship_id => fnd_api.g_miss_num ,
3472 p_transaction_id => fnd_api.g_miss_num ,
3473 p_old_subject_id => fnd_api.g_miss_num ,
3474 p_new_subject_id => l_new_relship_rec.subject_id ,
3475 p_old_position_reference => fnd_api.g_miss_char ,
3476 p_new_position_reference => l_new_relship_rec.position_reference,
3477 p_old_active_start_date => fnd_api.g_miss_date ,
3478 p_new_active_start_date => l_new_relship_rec.active_start_date ,
3479 p_old_active_end_date => fnd_api.g_miss_date ,
3480 p_new_active_end_date => l_new_relship_rec.active_end_date ,
3481 p_old_mandatory_flag => fnd_api.g_miss_char ,
3482 p_new_mandatory_flag => l_new_relship_rec.mandatory_flag ,
3483 p_old_context => fnd_api.g_miss_char ,
3484 p_new_context => l_new_relship_rec.context ,
3485 p_old_attribute1 => fnd_api.g_miss_char ,
3486 p_new_attribute1 => l_new_relship_rec.attribute1 ,
3487 p_old_attribute2 => fnd_api.g_miss_char ,
3488 p_new_attribute2 => l_new_relship_rec.attribute2 ,
3489 p_old_attribute3 => fnd_api.g_miss_char ,
3490 p_new_attribute3 => l_new_relship_rec.attribute3 ,
3491 p_old_attribute4 => fnd_api.g_miss_char ,
3492 p_new_attribute4 => l_new_relship_rec.attribute4 ,
3493 p_old_attribute5 => fnd_api.g_miss_char ,
3494 p_new_attribute5 => l_new_relship_rec.attribute5 ,
3495 p_old_attribute6 => fnd_api.g_miss_char ,
3496 p_new_attribute6 => l_new_relship_rec.attribute6 ,
3497 p_old_attribute7 => fnd_api.g_miss_char ,
3498 p_new_attribute7 => l_new_relship_rec.attribute7 ,
3499 p_old_attribute8 => fnd_api.g_miss_char ,
3500 p_new_attribute8 => l_new_relship_rec.attribute8 ,
3501 p_old_attribute9 => fnd_api.g_miss_char ,
3502 p_new_attribute9 => l_new_relship_rec.attribute9 ,
3503 p_old_attribute10 => fnd_api.g_miss_char ,
3504 p_new_attribute10 => l_new_relship_rec.attribute10 ,
3505 p_old_attribute11 => fnd_api.g_miss_char ,
3506 p_new_attribute11 => l_new_relship_rec.attribute11 ,
3507 p_old_attribute12 => fnd_api.g_miss_char ,
3508 p_new_attribute12 => l_new_relship_rec.attribute12 ,
3509 p_old_attribute13 => fnd_api.g_miss_char ,
3510 p_new_attribute13 => l_new_relship_rec.attribute13 ,
3511 p_old_attribute14 => fnd_api.g_miss_char ,
3512 p_new_attribute14 => l_new_relship_rec.attribute14 ,
3513 p_old_attribute15 => fnd_api.g_miss_char ,
3514 p_new_attribute15 => l_new_relship_rec.attribute15 ,
3515 p_full_dump_flag => fnd_api.g_miss_char ,
3516 p_created_by => fnd_api.g_miss_num, -- fnd_global.user_id,
3517 p_creation_date => fnd_api.g_miss_date ,
3518 p_last_updated_by => fnd_global.user_id ,
3519 p_last_update_date => SYSDATE ,
3520 p_last_update_login => fnd_global.conc_login_id ,
3521 p_object_version_number => fnd_api.g_miss_num );
3522 ELSE
3523 --
3524 IF ( l_rel_hist_csr.old_subject_id IS NULL
3525 AND l_rel_hist_csr.new_subject_id IS NULL ) THEN
3526 IF ( l_new_relship_rec.subject_id = l_old_relship_rec.subject_id )
3527 OR ( l_new_relship_rec.subject_id = fnd_api.g_miss_num ) THEN
3528 l_rel_hist_csr.old_subject_id := NULL;
3529 l_rel_hist_csr.new_subject_id := NULL;
3530 ELSE
3531 l_rel_hist_csr.old_subject_id := fnd_api.g_miss_num;
3532 l_rel_hist_csr.new_subject_id := l_new_relship_rec.subject_id;
3533 END IF;
3534 ELSE
3535 l_rel_hist_csr.old_subject_id := fnd_api.g_miss_num;
3536 l_rel_hist_csr.new_subject_id := l_new_relship_rec.subject_id;
3537 END IF;
3538 --
3539 IF ( l_rel_hist_csr.old_position_reference IS NULL
3540 AND l_rel_hist_csr.new_position_reference IS NULL ) THEN
3541 IF ( l_new_relship_rec.position_reference = l_old_relship_rec.position_reference )
3542 OR ( l_new_relship_rec.position_reference = fnd_api.g_miss_char ) THEN
3543 l_rel_hist_csr.old_position_reference := NULL;
3544 l_rel_hist_csr.new_position_reference := NULL;
3545 ELSE
3546 l_rel_hist_csr.old_position_reference := fnd_api.g_miss_char;
3547 l_rel_hist_csr.new_position_reference := l_new_relship_rec.position_reference;
3548 END IF;
3549 ELSE
3550 l_rel_hist_csr.old_position_reference := fnd_api.g_miss_char;
3551 l_rel_hist_csr.new_position_reference := l_new_relship_rec.position_reference;
3552 END IF;
3553 --
3554 IF ( l_rel_hist_csr.old_active_start_date IS NULL
3555 AND l_rel_hist_csr.new_active_start_date IS NULL ) THEN
3556 IF ( l_new_relship_rec.active_start_date = l_old_relship_rec.active_start_date )
3557 OR ( l_new_relship_rec.active_start_date = fnd_api.g_miss_date ) THEN
3558 l_rel_hist_csr.old_active_start_date := NULL;
3559 l_rel_hist_csr.new_active_start_date := NULL;
3560 ELSE
3561 l_rel_hist_csr.old_active_start_date := fnd_api.g_miss_date;
3562 l_rel_hist_csr.new_active_start_date := l_new_relship_rec.active_start_date;
3563 END IF;
3564 ELSE
3565 l_rel_hist_csr.old_active_start_date := fnd_api.g_miss_date;
3566 l_rel_hist_csr.new_active_start_date := l_new_relship_rec.active_start_date;
3567 END IF;
3568 --
3569 IF ( l_rel_hist_csr.old_active_end_date IS NULL
3570 AND l_rel_hist_csr.new_active_end_date IS NULL ) THEN
3571 IF ( l_new_relship_rec.active_end_date = l_old_relship_rec.active_end_date )
3572 OR ( l_new_relship_rec.active_end_date = fnd_api.g_miss_date ) THEN
3573 l_rel_hist_csr.old_active_end_date := NULL;
3574 l_rel_hist_csr.new_active_end_date := NULL;
3575 ELSE
3576 l_rel_hist_csr.old_active_end_date := fnd_api.g_miss_date;
3577 l_rel_hist_csr.new_active_end_date := l_new_relship_rec.active_end_date;
3578 END IF;
3579 ELSE
3580 l_rel_hist_csr.old_active_end_date := fnd_api.g_miss_date;
3581 l_rel_hist_csr.new_active_end_date := l_new_relship_rec.active_end_date;
3582 END IF;
3583 --
3584 IF ( l_rel_hist_csr.old_mandatory_flag IS NULL
3585 AND l_rel_hist_csr.new_mandatory_flag IS NULL ) THEN
3586 IF ( l_new_relship_rec.mandatory_flag = l_old_relship_rec.mandatory_flag )
3587 OR ( l_new_relship_rec.mandatory_flag = fnd_api.g_miss_char ) THEN
3588 l_rel_hist_csr.old_mandatory_flag := NULL;
3589 l_rel_hist_csr.new_mandatory_flag := NULL;
3590 ELSE
3591 l_rel_hist_csr.old_mandatory_flag := fnd_api.g_miss_char;
3592 l_rel_hist_csr.new_mandatory_flag := l_new_relship_rec.mandatory_flag;
3593 END IF;
3594 ELSE
3595 l_rel_hist_csr.old_mandatory_flag := fnd_api.g_miss_char;
3596 l_rel_hist_csr.new_mandatory_flag := l_new_relship_rec.mandatory_flag;
3597 END IF;
3598 --
3599 IF ( l_rel_hist_csr.old_context IS NULL
3600 AND l_rel_hist_csr.new_context IS NULL ) THEN
3601 IF ( l_new_relship_rec.context = l_old_relship_rec.context )
3602 OR ( l_new_relship_rec.context = fnd_api.g_miss_char ) THEN
3603 l_rel_hist_csr.old_context := NULL;
3604 l_rel_hist_csr.new_context := NULL;
3605 ELSE
3606 l_rel_hist_csr.old_context := fnd_api.g_miss_char;
3607 l_rel_hist_csr.new_context := l_new_relship_rec.context;
3608 END IF;
3609 ELSE
3610 l_rel_hist_csr.old_context := fnd_api.g_miss_char;
3611 l_rel_hist_csr.new_context := l_new_relship_rec.context;
3612 END IF;
3613 --
3614 IF ( l_rel_hist_csr.old_attribute1 IS NULL
3615 AND l_rel_hist_csr.new_attribute1 IS NULL ) THEN
3616 IF ( l_new_relship_rec.attribute1 = l_old_relship_rec.attribute1 )
3617 OR ( l_new_relship_rec.attribute1 = fnd_api.g_miss_char ) THEN
3618 l_rel_hist_csr.old_attribute1 := NULL;
3619 l_rel_hist_csr.new_attribute1 := NULL;
3620 ELSE
3621 l_rel_hist_csr.old_attribute1 := fnd_api.g_miss_char;
3622 l_rel_hist_csr.new_attribute1 := l_new_relship_rec.attribute1;
3623 END IF;
3624 ELSE
3625 l_rel_hist_csr.old_attribute1 := fnd_api.g_miss_char;
3626 l_rel_hist_csr.new_attribute1 := l_new_relship_rec.attribute1;
3627 END IF;
3628 --
3629 IF ( l_rel_hist_csr.old_attribute2 IS NULL
3630 AND l_rel_hist_csr.new_attribute2 IS NULL ) THEN
3631 IF ( l_new_relship_rec.attribute2 = l_old_relship_rec.attribute2 )
3632 OR ( l_new_relship_rec.attribute2 = fnd_api.g_miss_char ) THEN
3633 l_rel_hist_csr.old_attribute2 := NULL;
3634 l_rel_hist_csr.new_attribute2 := NULL;
3635 ELSE
3636 l_rel_hist_csr.old_attribute2 := fnd_api.g_miss_char;
3637 l_rel_hist_csr.new_attribute2 := l_new_relship_rec.attribute2;
3638 END IF;
3639 ELSE
3640 l_rel_hist_csr.old_attribute2 := fnd_api.g_miss_char;
3641 l_rel_hist_csr.new_attribute2 := l_new_relship_rec.attribute2;
3642 END IF;
3643 --
3644 IF ( l_rel_hist_csr.old_attribute3 IS NULL
3645 AND l_rel_hist_csr.new_attribute3 IS NULL ) THEN
3646 IF ( l_new_relship_rec.attribute3 = l_old_relship_rec.attribute3 )
3647 OR ( l_new_relship_rec.attribute3 = fnd_api.g_miss_char ) THEN
3648 l_rel_hist_csr.old_attribute3 := NULL;
3649 l_rel_hist_csr.new_attribute3 := NULL;
3650 ELSE
3651 l_rel_hist_csr.old_attribute3 := fnd_api.g_miss_char;
3652 l_rel_hist_csr.new_attribute3 := l_new_relship_rec.attribute3;
3653 END IF;
3654 ELSE
3655 l_rel_hist_csr.old_attribute3 := fnd_api.g_miss_char;
3656 l_rel_hist_csr.new_attribute3 := l_new_relship_rec.attribute3;
3657 END IF;
3658 --
3659 IF ( l_rel_hist_csr.old_attribute4 IS NULL
3660 AND l_rel_hist_csr.new_attribute4 IS NULL ) THEN
3661 IF ( l_new_relship_rec.attribute4 = l_old_relship_rec.attribute4 )
3662 OR ( l_new_relship_rec.attribute4 = fnd_api.g_miss_char ) THEN
3663 l_rel_hist_csr.old_attribute4 := NULL;
3664 l_rel_hist_csr.new_attribute4 := NULL;
3665 ELSE
3666 l_rel_hist_csr.old_attribute4 := fnd_api.g_miss_char;
3667 l_rel_hist_csr.new_attribute4 := l_new_relship_rec.attribute4;
3668 END IF;
3669 ELSE
3670 l_rel_hist_csr.old_attribute4 := fnd_api.g_miss_char;
3671 l_rel_hist_csr.new_attribute4 := l_new_relship_rec.attribute4;
3672 END IF;
3673 --
3674 IF ( l_rel_hist_csr.old_attribute5 IS NULL
3675 AND l_rel_hist_csr.new_attribute5 IS NULL ) THEN
3676 IF ( l_new_relship_rec.attribute5 = l_old_relship_rec.attribute5 )
3677 OR ( l_new_relship_rec.attribute5 = fnd_api.g_miss_char ) THEN
3678 l_rel_hist_csr.old_attribute5 := NULL;
3679 l_rel_hist_csr.new_attribute5 := NULL;
3680 ELSE
3681 l_rel_hist_csr.old_attribute5 := fnd_api.g_miss_char;
3682 l_rel_hist_csr.new_attribute5 := l_new_relship_rec.attribute5;
3683 END IF;
3684 ELSE
3685 l_rel_hist_csr.old_attribute5 := fnd_api.g_miss_char;
3686 l_rel_hist_csr.new_attribute5 := l_new_relship_rec.attribute5;
3687 END IF;
3688 --
3689 IF ( l_rel_hist_csr.old_attribute6 IS NULL
3690 AND l_rel_hist_csr.new_attribute6 IS NULL ) THEN
3691 IF ( l_new_relship_rec.attribute6 = l_old_relship_rec.attribute6 )
3692 OR ( l_new_relship_rec.attribute6 = fnd_api.g_miss_char ) THEN
3693 l_rel_hist_csr.old_attribute6 := NULL;
3694 l_rel_hist_csr.new_attribute6 := NULL;
3695 ELSE
3696 l_rel_hist_csr.old_attribute6 := fnd_api.g_miss_char;
3697 l_rel_hist_csr.new_attribute6 := l_new_relship_rec.attribute6;
3698 END IF;
3699 ELSE
3700 l_rel_hist_csr.old_attribute6 := fnd_api.g_miss_char;
3701 l_rel_hist_csr.new_attribute6 := l_new_relship_rec.attribute6;
3702 END IF;
3703 --
3704 IF ( l_rel_hist_csr.old_attribute7 IS NULL
3705 AND l_rel_hist_csr.new_attribute7 IS NULL ) THEN
3706 IF ( l_new_relship_rec.attribute7 = l_old_relship_rec.attribute7 )
3707 OR ( l_new_relship_rec.attribute7 = fnd_api.g_miss_char ) THEN
3708 l_rel_hist_csr.old_attribute7 := NULL;
3709 l_rel_hist_csr.new_attribute7 := NULL;
3710 ELSE
3711 l_rel_hist_csr.old_attribute7 := fnd_api.g_miss_char;
3712 l_rel_hist_csr.new_attribute7 := l_new_relship_rec.attribute7;
3713 END IF;
3714 ELSE
3715 l_rel_hist_csr.old_attribute7 := fnd_api.g_miss_char;
3716 l_rel_hist_csr.new_attribute7 := l_new_relship_rec.attribute7;
3717 END IF;
3718 --
3719 IF ( l_rel_hist_csr.old_attribute8 IS NULL
3720 AND l_rel_hist_csr.new_attribute8 IS NULL ) THEN
3721 IF ( l_new_relship_rec.attribute8 = l_old_relship_rec.attribute8 )
3722 OR ( l_new_relship_rec.attribute8 = fnd_api.g_miss_char ) THEN
3723 l_rel_hist_csr.old_attribute8 := NULL;
3724 l_rel_hist_csr.new_attribute8 := NULL;
3725 ELSE
3726 l_rel_hist_csr.old_attribute8 := fnd_api.g_miss_char;
3727 l_rel_hist_csr.new_attribute8 := l_new_relship_rec.attribute8;
3728 END IF;
3729 ELSE
3730 l_rel_hist_csr.old_attribute8 := fnd_api.g_miss_char;
3731 l_rel_hist_csr.new_attribute8 := l_new_relship_rec.attribute8;
3732 END IF;
3733 --
3734 IF ( l_rel_hist_csr.old_attribute9 IS NULL
3735 AND l_rel_hist_csr.new_attribute9 IS NULL ) THEN
3736 IF ( l_new_relship_rec.attribute9 = l_old_relship_rec.attribute9 )
3737 OR ( l_new_relship_rec.attribute9 = fnd_api.g_miss_char ) THEN
3738 l_rel_hist_csr.old_attribute9 := NULL;
3739 l_rel_hist_csr.new_attribute9 := NULL;
3740 ELSE
3741 l_rel_hist_csr.old_attribute9 := fnd_api.g_miss_char;
3742 l_rel_hist_csr.new_attribute9 := l_new_relship_rec.attribute9;
3743 END IF;
3744 ELSE
3745 l_rel_hist_csr.old_attribute9 := fnd_api.g_miss_char;
3746 l_rel_hist_csr.new_attribute9 := l_new_relship_rec.attribute9;
3747 END IF;
3748 --
3749 IF ( l_rel_hist_csr.old_attribute10 IS NULL
3750 AND l_rel_hist_csr.new_attribute10 IS NULL ) THEN
3751 IF ( l_new_relship_rec.attribute10 = l_old_relship_rec.attribute10 )
3752 OR ( l_new_relship_rec.attribute10 = fnd_api.g_miss_char ) THEN
3753 l_rel_hist_csr.old_attribute10 := NULL;
3754 l_rel_hist_csr.new_attribute10 := NULL;
3755 ELSE
3756 l_rel_hist_csr.old_attribute10 := fnd_api.g_miss_char;
3757 l_rel_hist_csr.new_attribute10 := l_new_relship_rec.attribute10;
3758 END IF;
3759 ELSE
3760 l_rel_hist_csr.old_attribute10 := fnd_api.g_miss_char;
3761 l_rel_hist_csr.new_attribute10 := l_new_relship_rec.attribute10;
3762 END IF;
3763 --
3764 IF ( l_rel_hist_csr.old_attribute11 IS NULL
3765 AND l_rel_hist_csr.new_attribute11 IS NULL ) THEN
3766 IF ( l_new_relship_rec.attribute11 = l_old_relship_rec.attribute11 )
3767 OR ( l_new_relship_rec.attribute11 = fnd_api.g_miss_char ) THEN
3768 l_rel_hist_csr.old_attribute11 := NULL;
3769 l_rel_hist_csr.new_attribute11 := NULL;
3770 ELSE
3771 l_rel_hist_csr.old_attribute11 := fnd_api.g_miss_char;
3772 l_rel_hist_csr.new_attribute11 := l_new_relship_rec.attribute11;
3773 END IF;
3774 ELSE
3775 l_rel_hist_csr.old_attribute11 := fnd_api.g_miss_char;
3776 l_rel_hist_csr.new_attribute11 := l_new_relship_rec.attribute11;
3777 END IF;
3778 --
3779 IF ( l_rel_hist_csr.old_attribute12 IS NULL
3780 AND l_rel_hist_csr.new_attribute12 IS NULL ) THEN
3781 IF ( l_new_relship_rec.attribute12 = l_old_relship_rec.attribute12 )
3782 OR ( l_new_relship_rec.attribute12 = fnd_api.g_miss_char ) THEN
3783 l_rel_hist_csr.old_attribute12 := NULL;
3784 l_rel_hist_csr.new_attribute12 := NULL;
3785 ELSE
3786 l_rel_hist_csr.old_attribute12 := fnd_api.g_miss_char;
3787 l_rel_hist_csr.new_attribute12 := l_new_relship_rec.attribute12;
3788 END IF;
3789 ELSE
3790 l_rel_hist_csr.old_attribute12 := fnd_api.g_miss_char;
3791 l_rel_hist_csr.new_attribute12 := l_new_relship_rec.attribute12;
3792 END IF;
3793 --
3794 IF ( l_rel_hist_csr.old_attribute13 IS NULL
3795 AND l_rel_hist_csr.new_attribute13 IS NULL ) THEN
3796 IF ( l_new_relship_rec.attribute13 = l_old_relship_rec.attribute13 )
3797 OR ( l_new_relship_rec.attribute13 = fnd_api.g_miss_char ) THEN
3798 l_rel_hist_csr.old_attribute13 := NULL;
3799 l_rel_hist_csr.new_attribute13 := NULL;
3800 ELSE
3801 l_rel_hist_csr.old_attribute13 := fnd_api.g_miss_char;
3802 l_rel_hist_csr.new_attribute13 := l_new_relship_rec.attribute13;
3803 END IF;
3804 ELSE
3805 l_rel_hist_csr.old_attribute13 := fnd_api.g_miss_char;
3806 l_rel_hist_csr.new_attribute13 := l_new_relship_rec.attribute13;
3807 END IF;
3808 --
3809 IF ( l_rel_hist_csr.old_attribute14 IS NULL
3810 AND l_rel_hist_csr.new_attribute14 IS NULL ) THEN
3811 IF ( l_new_relship_rec.attribute14 = l_old_relship_rec.attribute14 )
3812 OR ( l_new_relship_rec.attribute14 = fnd_api.g_miss_char ) THEN
3813 l_rel_hist_csr.old_attribute14 := NULL;
3814 l_rel_hist_csr.new_attribute14 := NULL;
3815 ELSE
3816 l_rel_hist_csr.old_attribute14 := fnd_api.g_miss_char;
3817 l_rel_hist_csr.new_attribute14 := l_new_relship_rec.attribute14;
3818 END IF;
3819 ELSE
3820 l_rel_hist_csr.old_attribute14 := fnd_api.g_miss_char;
3821 l_rel_hist_csr.new_attribute14 := l_new_relship_rec.attribute14;
3822 END IF;
3823 --
3824 IF ( l_rel_hist_csr.old_attribute15 IS NULL
3825 AND l_rel_hist_csr.new_attribute15 IS NULL ) THEN
3826 IF ( l_new_relship_rec.attribute15 = l_old_relship_rec.attribute15 )
3827 OR ( l_new_relship_rec.attribute15 = fnd_api.g_miss_char ) THEN
3828 l_rel_hist_csr.old_attribute15 := NULL;
3829 l_rel_hist_csr.new_attribute15 := NULL;
3830 ELSE
3831 l_rel_hist_csr.old_attribute15 := fnd_api.g_miss_char;
3832 l_rel_hist_csr.new_attribute15 := l_new_relship_rec.attribute15;
3833 END IF;
3834 ELSE
3835 l_rel_hist_csr.old_attribute15 := fnd_api.g_miss_char;
3836 l_rel_hist_csr.new_attribute15 := l_new_relship_rec.attribute15;
3837 END IF;
3838 --
3839
3840 csi_ii_relationships_h_pkg.update_row(
3841 p_relationship_history_id => l_rel_hist_id ,
3842 p_relationship_id => fnd_api.g_miss_num ,
3843 p_transaction_id => fnd_api.g_miss_num ,
3844 p_old_subject_id => l_rel_hist_csr.old_subject_id ,
3845 p_new_subject_id => l_rel_hist_csr.new_subject_id ,
3846 p_old_position_reference => l_rel_hist_csr.old_position_reference,
3847 p_new_position_reference => l_rel_hist_csr.new_position_reference,
3848 p_old_active_start_date => l_rel_hist_csr.old_active_start_date ,
3849 p_new_active_start_date => l_rel_hist_csr.new_active_start_date ,
3850 p_old_active_end_date => l_rel_hist_csr.old_active_end_date ,
3851 p_new_active_end_date => l_rel_hist_csr.new_active_end_date ,
3852 p_old_mandatory_flag => l_rel_hist_csr.old_mandatory_flag ,
3853 p_new_mandatory_flag => l_rel_hist_csr.new_mandatory_flag ,
3854 p_old_context => l_rel_hist_csr.old_context ,
3855 p_new_context => l_rel_hist_csr.new_context ,
3856 p_old_attribute1 => l_rel_hist_csr.old_attribute1 ,
3857 p_new_attribute1 => l_rel_hist_csr.new_attribute1 ,
3858 p_old_attribute2 => l_rel_hist_csr.old_attribute2 ,
3859 p_new_attribute2 => l_rel_hist_csr.new_attribute2 ,
3860 p_old_attribute3 => l_rel_hist_csr.old_attribute3 ,
3861 p_new_attribute3 => l_rel_hist_csr.new_attribute3 ,
3862 p_old_attribute4 => l_rel_hist_csr.old_attribute4 ,
3863 p_new_attribute4 => l_rel_hist_csr.new_attribute4 ,
3864 p_old_attribute5 => l_rel_hist_csr.old_attribute5 ,
3865 p_new_attribute5 => l_rel_hist_csr.new_attribute5 ,
3866 p_old_attribute6 => l_rel_hist_csr.old_attribute6 ,
3867 p_new_attribute6 => l_rel_hist_csr.new_attribute6 ,
3868 p_old_attribute7 => l_rel_hist_csr.old_attribute7 ,
3869 p_new_attribute7 => l_rel_hist_csr.new_attribute7 ,
3870 p_old_attribute8 => l_rel_hist_csr.old_attribute8 ,
3871 p_new_attribute8 => l_rel_hist_csr.new_attribute8 ,
3872 p_old_attribute9 => l_rel_hist_csr.old_attribute9 ,
3873 p_new_attribute9 => l_rel_hist_csr.new_attribute9 ,
3874 p_old_attribute10 => l_rel_hist_csr.old_attribute10 ,
3875 p_new_attribute10 => l_rel_hist_csr.new_attribute10 ,
3876 p_old_attribute11 => l_rel_hist_csr.old_attribute11 ,
3877 p_new_attribute11 => l_rel_hist_csr.new_attribute11 ,
3878 p_old_attribute12 => l_rel_hist_csr.old_attribute12 ,
3879 p_new_attribute12 => l_rel_hist_csr.new_attribute12 ,
3880 p_old_attribute13 => l_rel_hist_csr.old_attribute13 ,
3881 p_new_attribute13 => l_rel_hist_csr.new_attribute13 ,
3882 p_old_attribute14 => l_rel_hist_csr.old_attribute14 ,
3883 p_new_attribute14 => l_rel_hist_csr.new_attribute14 ,
3884 p_old_attribute15 => l_rel_hist_csr.old_attribute15 ,
3885 p_new_attribute15 => l_rel_hist_csr.new_attribute15 ,
3886 p_full_dump_flag => fnd_api.g_miss_char ,
3887 p_created_by => fnd_api.g_miss_num ,
3888 p_creation_date => fnd_api.g_miss_date ,
3889 p_last_updated_by => fnd_global.user_id ,
3890 p_last_update_date => SYSDATE ,
3891 p_last_update_login => fnd_global.conc_login_id ,
3892 p_object_version_number => fnd_api.g_miss_num );
3893 END IF;
3894
3895 EXCEPTION
3896 WHEN NO_DATA_FOUND THEN
3897 IF MOD(l_old_relship_rec.object_version_number+1,l_full_dump)=0 THEN
3898
3899 csi_ii_relationships_h_pkg.insert_row(
3900 px_relationship_history_id => l_relship_hist_rec.relationship_history_id,
3901 p_relationship_id => l_old_relship_rec.relationship_id,
3902 p_transaction_id => l_transaction_id,
3903 p_old_subject_id => l_old_relship_rec.subject_id,
3904 p_new_subject_id => l_new_relship_rec.subject_id,
3905 p_old_position_reference => l_old_relship_rec.position_reference,
3906 p_new_position_reference => l_new_relship_rec.position_reference,
3907 p_old_active_start_date => l_old_relship_rec.active_start_date,
3908 p_new_active_start_date => l_new_relship_rec.active_start_date,
3909 p_old_active_end_date => l_old_relship_rec.active_end_date,
3910 p_new_active_end_date => l_new_relship_rec.active_end_date,
3911 p_old_mandatory_flag => l_old_relship_rec.mandatory_flag,
3912 p_new_mandatory_flag => l_new_relship_rec.mandatory_flag,
3913 p_old_context => l_old_relship_rec.context,
3914 p_new_context => l_new_relship_rec.context,
3915 p_old_attribute1 => l_old_relship_rec.attribute1,
3916 p_new_attribute1 => l_new_relship_rec.attribute1,
3917 p_old_attribute2 => l_old_relship_rec.attribute2,
3918 p_new_attribute2 => l_new_relship_rec.attribute2,
3919 p_old_attribute3 => l_old_relship_rec.attribute3,
3920 p_new_attribute3 => l_new_relship_rec.attribute3,
3921 p_old_attribute4 => l_old_relship_rec.attribute4,
3922 p_new_attribute4 => l_new_relship_rec.attribute4,
3923 p_old_attribute5 => l_old_relship_rec.attribute5,
3924 p_new_attribute5 => l_new_relship_rec.attribute5,
3925 p_old_attribute6 => l_old_relship_rec.attribute6,
3926 p_new_attribute6 => l_new_relship_rec.attribute6,
3927 p_old_attribute7 => l_old_relship_rec.attribute7,
3928 p_new_attribute7 => l_new_relship_rec.attribute7,
3929 p_old_attribute8 => l_old_relship_rec.attribute8,
3930 p_new_attribute8 => l_new_relship_rec.attribute8,
3931 p_old_attribute9 => l_old_relship_rec.attribute9,
3932 p_new_attribute9 => l_new_relship_rec.attribute9,
3933 p_old_attribute10 => l_old_relship_rec.attribute10,
3934 p_new_attribute10 => l_new_relship_rec.attribute10,
3935 p_old_attribute11 => l_old_relship_rec.attribute11,
3936 p_new_attribute11 => l_new_relship_rec.attribute11,
3937 p_old_attribute12 => l_old_relship_rec.attribute12,
3938 p_new_attribute12 => l_new_relship_rec.attribute12,
3939 p_old_attribute13 => l_old_relship_rec.attribute13,
3940 p_new_attribute13 => l_new_relship_rec.attribute13,
3941 p_old_attribute14 => l_old_relship_rec.attribute14,
3942 p_new_attribute14 => l_new_relship_rec.attribute14,
3943 p_old_attribute15 => l_old_relship_rec.attribute15,
3944 p_new_attribute15 => l_new_relship_rec.attribute15,
3945 p_full_dump_flag => 'Y',
3946 p_created_by => fnd_global.user_id,
3947 p_creation_date => SYSDATE,
3948 p_last_updated_by => fnd_global.user_id,
3949 p_last_update_date => SYSDATE,
3950 p_last_update_login => fnd_global.conc_login_id,
3951 p_object_version_number => 1);
3952
3953 ELSE
3954
3955 IF (l_new_relship_rec.subject_id = fnd_api.g_miss_num) OR
3956 NVL(l_old_relship_rec.subject_id,fnd_api.g_miss_num) = NVL(l_new_relship_rec.subject_id,fnd_api.g_miss_num) THEN
3957 l_relship_hist_rec.old_subject_id := NULL;
3958 l_relship_hist_rec.new_subject_id := NULL;
3959 ELSIF
3960 NVL(l_old_relship_rec.subject_id,fnd_api.g_miss_num) <> NVL(l_new_relship_rec.subject_id,fnd_api.g_miss_num) THEN
3961 l_relship_hist_rec.old_subject_id := l_old_relship_rec.subject_id ;
3962 l_relship_hist_rec.new_subject_id := l_new_relship_rec.subject_id ;
3963 END IF;
3964 --
3965 IF (l_new_relship_rec.position_reference = fnd_api.g_miss_char) OR
3966 NVL(l_old_relship_rec.position_reference,fnd_api.g_miss_char) = NVL(l_new_relship_rec.position_reference,fnd_api.g_miss_char) THEN
3967 l_relship_hist_rec.old_position_reference := NULL;
3968 l_relship_hist_rec.new_position_reference := NULL;
3969 ELSIF
3970 NVL(l_old_relship_rec.position_reference,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.position_reference,fnd_api.g_miss_char) THEN
3971 l_relship_hist_rec.old_position_reference := l_old_relship_rec.position_reference ;
3972 l_relship_hist_rec.new_position_reference := l_new_relship_rec.position_reference ;
3973 END IF;
3974 --
3975 IF (l_new_relship_rec.active_start_date = fnd_api.g_miss_date) OR
3976 NVL(l_old_relship_rec.active_start_date,fnd_api.g_miss_date) = NVL(l_new_relship_rec.active_start_date,fnd_api.g_miss_date) THEN
3977 l_relship_hist_rec.old_active_start_date := NULL;
3978 l_relship_hist_rec.new_active_start_date := NULL;
3979 ELSIF
3980 NVL(l_old_relship_rec.active_start_date,fnd_api.g_miss_date) <> NVL(l_new_relship_rec.active_start_date,fnd_api.g_miss_date) THEN
3981 l_relship_hist_rec.old_active_start_date := l_old_relship_rec.active_start_date ;
3982 l_relship_hist_rec.new_active_start_date := l_new_relship_rec.active_start_date ;
3983 END IF;
3984 --
3985 IF (l_new_relship_rec.active_end_date = fnd_api.g_miss_date) OR
3986 NVL(l_old_relship_rec.active_end_date,fnd_api.g_miss_date) = NVL(l_new_relship_rec.active_end_date,fnd_api.g_miss_date) THEN
3987 l_relship_hist_rec.old_active_end_date := NULL;
3988 l_relship_hist_rec.new_active_end_date := NULL;
3989 ELSIF
3990 NVL(l_old_relship_rec.active_end_date,fnd_api.g_miss_date) <> NVL(l_new_relship_rec.active_end_date,fnd_api.g_miss_date) THEN
3991 l_relship_hist_rec.old_active_end_date := l_old_relship_rec.active_end_date ;
3992 l_relship_hist_rec.new_active_end_date := l_new_relship_rec.active_end_date ;
3993 END IF;
3994 --
3995 IF (l_new_relship_rec.mandatory_flag = fnd_api.g_miss_char) OR
3996 NVL(l_old_relship_rec.mandatory_flag,fnd_api.g_miss_char) = NVL(l_new_relship_rec.mandatory_flag,fnd_api.g_miss_char) THEN
3997 l_relship_hist_rec.old_mandatory_flag := NULL;
3998 l_relship_hist_rec.new_mandatory_flag := NULL;
3999 ELSIF
4000 NVL(l_old_relship_rec.mandatory_flag,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.mandatory_flag,fnd_api.g_miss_char) THEN
4001 l_relship_hist_rec.old_mandatory_flag := l_old_relship_rec.mandatory_flag ;
4002 l_relship_hist_rec.new_mandatory_flag := l_new_relship_rec.mandatory_flag ;
4003 END IF;
4004 --
4005 IF (l_new_relship_rec.context = fnd_api.g_miss_char) OR
4006 NVL(l_old_relship_rec.context,fnd_api.g_miss_char) = NVL(l_new_relship_rec.context,fnd_api.g_miss_char) THEN
4007 l_relship_hist_rec.old_context := NULL;
4008 l_relship_hist_rec.new_context := NULL;
4009 ELSIF
4010 NVL(l_old_relship_rec.context,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.context,fnd_api.g_miss_char) THEN
4011 l_relship_hist_rec.old_context := l_old_relship_rec.context ;
4012 l_relship_hist_rec.new_context := l_new_relship_rec.context ;
4013 END IF;
4014 --
4015 IF (l_new_relship_rec.attribute1 = fnd_api.g_miss_char) OR
4016 NVL(l_old_relship_rec.attribute1,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute1,fnd_api.g_miss_char) THEN
4017 l_relship_hist_rec.old_attribute1 := NULL;
4018 l_relship_hist_rec.new_attribute1 := NULL;
4019 ELSIF
4020 NVL(l_old_relship_rec.attribute1,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute1,fnd_api.g_miss_char) THEN
4021 l_relship_hist_rec.old_attribute1 := l_old_relship_rec.attribute1 ;
4022 l_relship_hist_rec.new_attribute1 := l_new_relship_rec.attribute1 ;
4023 END IF;
4024 --
4025 IF (l_new_relship_rec.attribute2 = fnd_api.g_miss_char) OR
4026 NVL(l_old_relship_rec.attribute2,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute2,fnd_api.g_miss_char) THEN
4027 l_relship_hist_rec.old_attribute2 := NULL;
4028 l_relship_hist_rec.new_attribute2 := NULL;
4029 ELSIF
4030 NVL(l_old_relship_rec.attribute2,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute2,fnd_api.g_miss_char) THEN
4031 l_relship_hist_rec.old_attribute2 := l_old_relship_rec.attribute2 ;
4032 l_relship_hist_rec.new_attribute2 := l_new_relship_rec.attribute2 ;
4033 END IF;
4034 --
4035 IF (l_new_relship_rec.attribute3 = fnd_api.g_miss_char) OR
4036 NVL(l_old_relship_rec.attribute3,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute3,fnd_api.g_miss_char) THEN
4037 l_relship_hist_rec.old_attribute3 := NULL;
4038 l_relship_hist_rec.new_attribute3 := NULL;
4039 ELSIF
4040 NVL(l_old_relship_rec.attribute3,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute3,fnd_api.g_miss_char) THEN
4041 l_relship_hist_rec.old_attribute3 := l_old_relship_rec.attribute3 ;
4042 l_relship_hist_rec.new_attribute3 := l_new_relship_rec.attribute3 ;
4043 END IF;
4044 --
4045 IF (l_new_relship_rec.attribute4 = fnd_api.g_miss_char) OR
4046 NVL(l_old_relship_rec.attribute4,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute4,fnd_api.g_miss_char) THEN
4047 l_relship_hist_rec.old_attribute4 := NULL;
4048 l_relship_hist_rec.new_attribute4 := NULL;
4049 ELSIF
4050 NVL(l_old_relship_rec.attribute4,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute4,fnd_api.g_miss_char) THEN
4051 l_relship_hist_rec.old_attribute4 := l_old_relship_rec.attribute4 ;
4052 l_relship_hist_rec.new_attribute4 := l_new_relship_rec.attribute4 ;
4053 END IF;
4054 --
4055 IF (l_new_relship_rec.attribute5 = fnd_api.g_miss_char) OR
4056 NVL(l_old_relship_rec.attribute5,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute5,fnd_api.g_miss_char) THEN
4057 l_relship_hist_rec.old_attribute5 := NULL;
4058 l_relship_hist_rec.new_attribute5 := NULL;
4059 ELSIF
4060 NVL(l_old_relship_rec.attribute5,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute5,fnd_api.g_miss_char) THEN
4061 l_relship_hist_rec.old_attribute5 := l_old_relship_rec.attribute5 ;
4062 l_relship_hist_rec.new_attribute5 := l_new_relship_rec.attribute5 ;
4063 END IF;
4064 --
4065 IF (l_new_relship_rec.attribute6 = fnd_api.g_miss_char) OR
4066 NVL(l_old_relship_rec.attribute6,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute6,fnd_api.g_miss_char) THEN
4067 l_relship_hist_rec.old_attribute6 := NULL;
4068 l_relship_hist_rec.new_attribute6 := NULL;
4069 ELSIF
4070 NVL(l_old_relship_rec.attribute6,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute6,fnd_api.g_miss_char) THEN
4071 l_relship_hist_rec.old_attribute6 := l_old_relship_rec.attribute6 ;
4072 l_relship_hist_rec.new_attribute6 := l_new_relship_rec.attribute6 ;
4073 END IF;
4074 --
4075 IF (l_new_relship_rec.attribute7 = fnd_api.g_miss_char) OR
4076 NVL(l_old_relship_rec.attribute7,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute7,fnd_api.g_miss_char) THEN
4077 l_relship_hist_rec.old_attribute7 := NULL;
4078 l_relship_hist_rec.new_attribute7 := NULL;
4079 ELSIF
4080 NVL(l_old_relship_rec.attribute7,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute7,fnd_api.g_miss_char) THEN
4081 l_relship_hist_rec.old_attribute7 := l_old_relship_rec.attribute7 ;
4082 l_relship_hist_rec.new_attribute7 := l_new_relship_rec.attribute7 ;
4083 END IF;
4084 --
4085 IF (l_new_relship_rec.attribute8 = fnd_api.g_miss_char) OR
4086 NVL(l_old_relship_rec.attribute8,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute8,fnd_api.g_miss_char) THEN
4087 l_relship_hist_rec.old_attribute8 := NULL;
4088 l_relship_hist_rec.new_attribute8 := NULL;
4089 ELSIF
4090 NVL(l_old_relship_rec.attribute8,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute8,fnd_api.g_miss_char) THEN
4091 l_relship_hist_rec.old_attribute8 := l_old_relship_rec.attribute8 ;
4092 l_relship_hist_rec.new_attribute8 := l_new_relship_rec.attribute8 ;
4093 END IF;
4094 --
4095 IF (l_new_relship_rec.attribute9 = fnd_api.g_miss_char) OR
4096 NVL(l_old_relship_rec.attribute9,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute9,fnd_api.g_miss_char) THEN
4097 l_relship_hist_rec.old_attribute9 := NULL;
4098 l_relship_hist_rec.new_attribute9 := NULL;
4099 ELSIF
4100 NVL(l_old_relship_rec.attribute9,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute9,fnd_api.g_miss_char) THEN
4101 l_relship_hist_rec.old_attribute9 := l_old_relship_rec.attribute9 ;
4102 l_relship_hist_rec.new_attribute9 := l_new_relship_rec.attribute9 ;
4103 END IF;
4104 --
4105 IF (l_new_relship_rec.attribute10 = fnd_api.g_miss_char) OR
4106 NVL(l_old_relship_rec.attribute10,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute10,fnd_api.g_miss_char) THEN
4107 l_relship_hist_rec.old_attribute10 := NULL;
4108 l_relship_hist_rec.new_attribute10 := NULL;
4109 ELSIF
4110 NVL(l_old_relship_rec.attribute10,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute10,fnd_api.g_miss_char) THEN
4111 l_relship_hist_rec.old_attribute10 := l_old_relship_rec.attribute10 ;
4112 l_relship_hist_rec.new_attribute10 := l_new_relship_rec.attribute10 ;
4113 END IF;
4114 --
4115 IF (l_new_relship_rec.attribute11 = fnd_api.g_miss_char) OR
4116 NVL(l_old_relship_rec.attribute11,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute11,fnd_api.g_miss_char) THEN
4117 l_relship_hist_rec.old_attribute11 := NULL;
4118 l_relship_hist_rec.new_attribute11 := NULL;
4119 ELSIF
4120 NVL(l_old_relship_rec.attribute11,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute11,fnd_api.g_miss_char) THEN
4121 l_relship_hist_rec.old_attribute11 := l_old_relship_rec.attribute11 ;
4122 l_relship_hist_rec.new_attribute11 := l_new_relship_rec.attribute11 ;
4123 END IF;
4124 --
4125 IF (l_new_relship_rec.attribute12 = fnd_api.g_miss_char) OR
4126 NVL(l_old_relship_rec.attribute12,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute12,fnd_api.g_miss_char) THEN
4127 l_relship_hist_rec.old_attribute12 := NULL;
4128 l_relship_hist_rec.new_attribute12 := NULL;
4129 ELSIF
4130 NVL(l_old_relship_rec.attribute12,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute12,fnd_api.g_miss_char) THEN
4131 l_relship_hist_rec.old_attribute12 := l_old_relship_rec.attribute12 ;
4132 l_relship_hist_rec.new_attribute12 := l_new_relship_rec.attribute12 ;
4133 END IF;
4134 --
4135 IF (l_new_relship_rec.attribute13 = fnd_api.g_miss_char) OR
4136 NVL(l_old_relship_rec.attribute13,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute13,fnd_api.g_miss_char) THEN
4137 l_relship_hist_rec.old_attribute13 := NULL;
4138 l_relship_hist_rec.new_attribute13 := NULL;
4139 ELSIF
4140 NVL(l_old_relship_rec.attribute13,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute13,fnd_api.g_miss_char) THEN
4141 l_relship_hist_rec.old_attribute13 := l_old_relship_rec.attribute13 ;
4142 l_relship_hist_rec.new_attribute13 := l_new_relship_rec.attribute13 ;
4143 END IF;
4144 --
4145 IF (l_new_relship_rec.attribute14 = fnd_api.g_miss_char) OR
4146 NVL(l_old_relship_rec.attribute14,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute14,fnd_api.g_miss_char) THEN
4147 l_relship_hist_rec.old_attribute14 := NULL;
4148 l_relship_hist_rec.new_attribute14 := NULL;
4149 ELSIF
4150 NVL(l_old_relship_rec.attribute14,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute14,fnd_api.g_miss_char) THEN
4151 l_relship_hist_rec.old_attribute14 := l_old_relship_rec.attribute14 ;
4152 l_relship_hist_rec.new_attribute14 := l_new_relship_rec.attribute14 ;
4153 END IF;
4154 --
4155 IF (l_new_relship_rec.attribute15 = fnd_api.g_miss_char) OR
4156 NVL(l_old_relship_rec.attribute15,fnd_api.g_miss_char) = NVL(l_new_relship_rec.attribute15,fnd_api.g_miss_char) THEN
4157 l_relship_hist_rec.old_attribute15 := NULL;
4158 l_relship_hist_rec.new_attribute15 := NULL;
4159 ELSIF
4160 NVL(l_old_relship_rec.attribute15,fnd_api.g_miss_char) <> NVL(l_new_relship_rec.attribute15,fnd_api.g_miss_char) THEN
4161 l_relship_hist_rec.old_attribute15 := l_old_relship_rec.attribute15 ;
4162 l_relship_hist_rec.new_attribute15 := l_new_relship_rec.attribute15 ;
4163 END IF;
4164 --
4165 IF p_flag = 'EXPIRE'
4166 THEN
4167 l_relship_hist_rec.new_active_end_date := p_sysdate;
4168 END IF;
4169
4170 csi_ii_relationships_h_pkg.insert_row(
4171 px_relationship_history_id => l_relship_hist_rec.relationship_history_id,
4172 p_relationship_id => l_old_relship_rec.relationship_id,
4173 p_transaction_id => l_transaction_id,
4174 p_old_subject_id => l_relship_hist_rec.old_subject_id,
4175 p_new_subject_id => l_relship_hist_rec.new_subject_id,
4176 p_old_position_reference => l_relship_hist_rec.old_position_reference,
4177 p_new_position_reference => l_relship_hist_rec.new_position_reference,
4178 p_old_active_start_date => l_relship_hist_rec.old_active_start_date,
4179 p_new_active_start_date => l_relship_hist_rec.new_active_start_date,
4180 p_old_active_end_date => l_relship_hist_rec.old_active_end_date,
4181 p_new_active_end_date => l_relship_hist_rec.new_active_end_date,
4182 p_old_mandatory_flag => l_relship_hist_rec.old_mandatory_flag,
4183 p_new_mandatory_flag => l_relship_hist_rec.new_mandatory_flag,
4184 p_old_context => l_relship_hist_rec.old_context,
4185 p_new_context => l_relship_hist_rec.new_context,
4186 p_old_attribute1 => l_relship_hist_rec.old_attribute1,
4187 p_new_attribute1 => l_relship_hist_rec.new_attribute1,
4188 p_old_attribute2 => l_relship_hist_rec.old_attribute2,
4189 p_new_attribute2 => l_relship_hist_rec.new_attribute2,
4190 p_old_attribute3 => l_relship_hist_rec.old_attribute3,
4191 p_new_attribute3 => l_relship_hist_rec.new_attribute3,
4192 p_old_attribute4 => l_relship_hist_rec.old_attribute4,
4193 p_new_attribute4 => l_relship_hist_rec.new_attribute4,
4194 p_old_attribute5 => l_relship_hist_rec.old_attribute5,
4195 p_new_attribute5 => l_relship_hist_rec.new_attribute5,
4196 p_old_attribute6 => l_relship_hist_rec.old_attribute6,
4197 p_new_attribute6 => l_relship_hist_rec.new_attribute6,
4198 p_old_attribute7 => l_relship_hist_rec.old_attribute7,
4199 p_new_attribute7 => l_relship_hist_rec.new_attribute7,
4200 p_old_attribute8 => l_relship_hist_rec.old_attribute8,
4201 p_new_attribute8 => l_relship_hist_rec.new_attribute8,
4202 p_old_attribute9 => l_relship_hist_rec.old_attribute9,
4203 p_new_attribute9 => l_relship_hist_rec.new_attribute9,
4204 p_old_attribute10 => l_relship_hist_rec.old_attribute10,
4205 p_new_attribute10 => l_relship_hist_rec.new_attribute10,
4206 p_old_attribute11 => l_relship_hist_rec.old_attribute11,
4207 p_new_attribute11 => l_relship_hist_rec.new_attribute11,
4208 p_old_attribute12 => l_relship_hist_rec.old_attribute12,
4209 p_new_attribute12 => l_relship_hist_rec.new_attribute12,
4210 p_old_attribute13 => l_relship_hist_rec.old_attribute13,
4211 p_new_attribute13 => l_relship_hist_rec.new_attribute13,
4212 p_old_attribute14 => l_relship_hist_rec.old_attribute14,
4213 p_new_attribute14 => l_relship_hist_rec.new_attribute14,
4214 p_old_attribute15 => l_relship_hist_rec.old_attribute15,
4215 p_new_attribute15 => l_relship_hist_rec.new_attribute15,
4216 p_full_dump_flag => NULL,
4217 p_created_by => fnd_global.user_id,
4218 p_creation_date => SYSDATE,
4219 p_last_updated_by => fnd_global.user_id,
4220 p_last_update_date => SYSDATE,
4221 p_last_update_login => fnd_global.conc_login_id,
4222 p_object_version_number => 1);
4223 END IF;
4224 END;
4225 -- End of modifications for Bug#2547034 on 09/20/02 - rtalluri
4226 EXCEPTION
4227 WHEN OTHERS THEN
4228 x_return_status := fnd_api.g_ret_sts_error;
4229 END;
4230 /* ----------------------------------------------------------------------------------------------------------+
4231 | Case1. Create/Update Relationship |
4232 | Only 'COMPONENT-OF' If subject_id not null and subject_id's creation_complete_flag |
4233 | is 'Y' and relationship is mandatory then set object_id's completeness_flag to 'Y' |
4234 | |
4235 | Case2. Location attribute inheritance property. |
4236 | Create/Update Relationship | |
4237 | Only for 'COMPONENT-OF' relationship_type_code update location of subject_id and its children in |
4238 | 'COMPONENT-OF' relationship with location of object_id. |
4239 | |
4240 | |
4241 +------------------------------------------------------------------------------------------------------------*/
4242 PROCEDURE update_instance
4243 ( p_api_version IN NUMBER,
4244 p_commit IN VARCHAR2,
4245 p_init_msg_list IN VARCHAR2,
4246 p_validation_level IN NUMBER,
4247 p_ii_relationship_rec IN csi_datastructures_pub.ii_relationship_rec,
4248 p_txn_rec IN OUT NOCOPY csi_datastructures_pub.transaction_rec,
4249 p_mode IN VARCHAR2,
4250 x_return_status OUT NOCOPY VARCHAR2,
4251 x_msg_count OUT NOCOPY NUMBER,
4252 x_msg_data OUT NOCOPY VARCHAR2)
4253 IS
4254
4255 /* CURSOR completeness_csr (p_subject_id IN NUMBER) IS
4256 SELECT object_id
4257 FROM csi_ii_relationships
4258 START WITH subject_id = p_subject_id
4259 CONNECT BY subject_id = PRIOR object_id; */
4260
4261 l_ii_relationship_rec csi_datastructures_pub.ii_relationship_rec;
4262 l_ext_attrib_values_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4263 l_party_tbl csi_datastructures_pub.party_tbl;
4264 l_account_tbl csi_datastructures_pub.party_account_tbl;
4265 l_pricing_attrib_tbl csi_datastructures_pub.pricing_attribs_tbl;
4266 l_org_assignments_tbl csi_datastructures_pub.organization_units_tbl;
4267 l_asset_assignment_tbl csi_datastructures_pub.instance_asset_tbl;
4268 l_instance_id_lst csi_datastructures_pub.id_tbl;
4269 l_instance_rec csi_datastructures_pub.instance_rec;
4270 l_instance_rec1 csi_datastructures_pub.instance_rec;
4271 l_temp_ins_rec csi_datastructures_pub.instance_rec;
4272 l_dummy NUMBER;
4273 l_object_version NUMBER;
4274 l_object_version1 NUMBER;
4275 l_subject_id NUMBER;
4276 l_item_attribute_tbl csi_item_instance_pvt.item_attribute_tbl;
4277 l_location_tbl csi_item_instance_pvt.location_tbl;
4278 l_generic_id_tbl csi_item_instance_pvt.generic_id_tbl;
4279 l_lookup_tbl csi_item_instance_pvt.lookup_tbl;
4280 l_ins_count_rec csi_item_instance_pvt.ins_count_rec;
4281 l_rel_tbl csi_datastructures_pub.ii_relationship_tbl;
4282 px_oks_txn_inst_tbl oks_ibint_pub.txn_instance_tbl;
4283 px_child_inst_tbl csi_item_instance_grp.child_inst_tbl;
4284 -- Begin Add Code for Siebel Genesis Project
4285 p_ext_attrib_values_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4286 p_party_tbl csi_datastructures_pub.party_tbl;
4287 p_account_tbl csi_datastructures_pub.party_account_tbl;
4288 p_pricing_attrib_tbl csi_datastructures_pub.pricing_attribs_tbl;
4289 p_org_assignments_tbl csi_datastructures_pub.organization_units_tbl;
4290 p_asset_assignment_tbl csi_datastructures_pub.instance_asset_tbl;
4291 -- End Add Code for Siebel Genesis Project
4292
4293 BEGIN
4294
4295 x_return_status := fnd_api.g_ret_sts_success;
4296 l_ii_relationship_rec := p_ii_relationship_rec;
4297 --
4298 IF l_ii_relationship_rec.relationship_id IS NOT NULL AND
4299 l_ii_relationship_rec.relationship_id <> FND_API.G_MISS_NUM THEN
4300 IF l_ii_relationship_rec.subject_id IS NULL OR
4301 l_ii_relationship_rec.subject_id = FND_API.G_MISS_NUM THEN
4302 Begin
4303 select subject_id
4304 into l_ii_relationship_rec.subject_id
4305 from CSI_II_RELATIONSHIPS
4306 where relationship_id = l_ii_relationship_rec.relationship_id;
4307 End;
4308 END IF;
4309 --
4310 IF l_ii_relationship_rec.object_id IS NULL OR
4311 l_ii_relationship_rec.object_id = FND_API.G_MISS_NUM THEN
4312 Begin
4313 select object_id
4314 into l_ii_relationship_rec.object_id
4315 from CSI_II_RELATIONSHIPS
4316 where relationship_id = l_ii_relationship_rec.relationship_id;
4317 End;
4318 END IF;
4319 END IF;
4320 --
4321 --To handle Case 2
4322 IF l_ii_relationship_rec.relationship_type_code='COMPONENT-OF' THEN
4323 BEGIN
4324 l_instance_rec.instance_id := l_ii_relationship_rec.subject_id;
4325 SELECT object_version_number,
4326 config_inst_hdr_id,
4327 config_inst_item_id,
4328 config_inst_rev_num
4329 INTO l_object_version1,
4330 l_instance_rec.config_inst_hdr_id, -- added
4331 l_instance_rec.config_inst_item_id, -- added
4332 l_instance_rec.config_inst_rev_num -- added
4333 FROM csi_item_instances
4334 WHERE instance_id=l_ii_relationship_rec.subject_id;
4335 l_instance_rec.object_version_number:=l_object_version1;
4336 IF p_mode='CREATE' OR p_mode='UPDATE'
4337 THEN
4338 l_instance_rec.instance_usage_code :='IN_RELATIONSHIP';
4339 END IF;
4340 SELECT active_end_date,
4341 location_type_code,
4342 location_id,
4343 inv_organization_id,
4344 inv_subinventory_name,
4345 inv_locator_id,
4346 pa_project_id,
4347 pa_project_task_id,
4348 in_transit_order_line_id,
4349 wip_job_id,
4350 po_order_line_id,
4351 operational_status_code,
4352 install_location_id,
4353 install_location_type_code
4354 INTO l_instance_rec.active_end_date,
4355 l_instance_rec.location_type_code,
4356 l_instance_rec.location_id,
4357 l_instance_rec.inv_organization_id,
4358 l_instance_rec.inv_subinventory_name,
4359 l_instance_rec.inv_locator_id,
4360 l_instance_rec.pa_project_id,
4361 l_instance_rec.pa_project_task_id,
4362 l_instance_rec.in_transit_order_line_id,
4363 l_instance_rec.wip_job_id,
4364 l_instance_rec.po_order_line_id,
4365 l_instance_rec.operational_status_code,
4366 l_instance_rec.install_location_id,
4367 l_instance_rec.install_location_type_code
4368 FROM csi_item_instances
4369 WHERE instance_id=l_ii_relationship_rec.object_id;
4370
4371 -- Begin Add Code for Siebel Genesis Project
4372 csi_item_instance_pub.update_item_instance
4373 ( p_api_version => p_api_version
4374 ,p_commit => p_commit
4375 ,p_init_msg_list => p_init_msg_list
4376 ,p_validation_level => p_validation_level
4377 ,p_instance_rec => l_instance_rec
4378 ,p_ext_attrib_values_tbl => p_ext_attrib_values_tbl
4379 ,p_party_tbl => p_party_tbl
4380 ,p_account_tbl => p_account_tbl
4381 ,p_pricing_attrib_tbl => p_pricing_attrib_tbl
4382 ,p_org_assignments_tbl => p_org_assignments_tbl
4383 ,p_asset_assignment_tbl => p_asset_assignment_tbl
4384 ,p_txn_rec => p_txn_rec
4385 ,x_instance_id_lst => l_instance_id_lst
4386 ,x_return_status => x_return_status
4387 ,x_msg_count => x_msg_count
4388 ,x_msg_data => x_msg_data
4389 );
4390 /*csi_item_instance_pvt.update_item_instance
4391 ( p_api_version => p_api_version
4392 ,p_commit => p_commit
4393 ,p_init_msg_list => p_init_msg_list
4394 ,p_validation_level => p_validation_level
4395 ,p_instance_rec => l_instance_rec
4396 ,p_txn_rec => p_txn_rec
4397 ,x_instance_id_lst => l_instance_id_lst
4398 ,x_return_status => x_return_status
4399 ,x_msg_count => x_msg_count
4400 ,x_msg_data => x_msg_data
4401 ,p_item_attribute_tbl => l_item_attribute_tbl
4402 ,p_location_tbl => l_location_tbl
4403 ,p_generic_id_tbl => l_generic_id_tbl
4404 ,p_lookup_tbl => l_lookup_tbl
4405 ,p_ins_count_rec => l_ins_count_rec
4406 ,p_oks_txn_inst_tbl => px_oks_txn_inst_tbl
4407 ,p_child_inst_tbl => px_child_inst_tbl
4408 );*/
4409 -- End Add Code for Siebel Genesis Project
4410
4411 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
4412 fnd_message.set_name('CSI','CSI_FAILED_TO_VALIDATE_INS');
4413 fnd_message.set_token('instance_id',l_instance_rec.instance_id);
4414 fnd_msg_pub.add;
4415 RAISE fnd_api.g_exc_error;
4416 END IF;
4417
4418 EXCEPTION
4419 WHEN OTHERS THEN
4420 NULL;
4421 END;
4422
4423 END IF;
4424
4425 --To handle Case 1
4426 BEGIN
4427 --FOR update_instance_csr IN completeness_csr(l_ii_relationship_rec.subject_id)
4428 csi_ii_relationships_pvt.Get_Immediate_Parents
4429 ( p_subject_id => l_ii_relationship_rec.subject_id,
4430 p_rel_type_code => 'COMPONENT-OF',
4431 p_rel_tbl => l_rel_tbl
4432 );
4433 IF l_rel_tbl.count > 0 THEN
4434 FOR j in l_rel_tbl.FIRST .. l_rel_tbl.LAST LOOP
4435 l_subject_id:=NULL;
4436 BEGIN
4437 SELECT subject_id
4438 INTO l_subject_id
4439 FROM csi_ii_relationships
4440 WHERE object_id = l_rel_tbl(j).object_id
4441 AND mandatory_flag = 'Y'
4442 AND relationship_type_code='COMPONENT-OF'
4443 AND ROWNUM=1;
4444 EXCEPTION
4445 WHEN OTHERS THEN
4446 l_subject_id:=NULL;
4447 END;
4448 --
4449 IF l_subject_id IS NOT NULL
4450 THEN
4451 SELECT COUNT(*)
4452 INTO l_dummy
4453 FROM csi_item_instances
4454 WHERE instance_id IN ( SELECT subject_id
4455 FROM csi_ii_relationships
4456 WHERE object_id = l_rel_tbl(j).object_id
4457 AND mandatory_flag = 'Y'
4458 AND relationship_type_code='COMPONENT-OF'
4459 )
4460 AND creation_complete_flag = 'N';
4461
4462 IF nvl(l_dummy,fnd_api.g_miss_num) > 0 THEN
4463 EXIT;
4464 ELSE
4465 SELECT object_version_number,
4466 config_inst_hdr_id, --added
4467 config_inst_item_id, --added
4468 config_inst_rev_num
4469 INTO l_object_version,
4470 l_instance_rec1.config_inst_hdr_id, --added
4471 l_instance_rec1.config_inst_item_id, --added
4472 l_instance_rec1.config_inst_rev_num --added
4473 FROM csi_item_instances
4474 WHERE instance_id = l_rel_tbl(j).object_id;
4475
4476 l_instance_rec1:=l_temp_ins_rec;
4477 l_instance_rec1.object_version_number:=l_object_version;
4478 l_instance_rec1.instance_id:=l_rel_tbl(j).object_id;
4479 l_instance_rec1.completeness_flag:='Y';
4480
4481 csi_item_instance_pvt.update_item_instance
4482 ( p_api_version => p_api_version
4483 ,p_commit => p_commit
4484 ,p_init_msg_list => p_init_msg_list
4485 ,p_validation_level => p_validation_level
4486 ,p_instance_rec => l_instance_rec1
4487 ,p_txn_rec => p_txn_rec
4488 ,x_instance_id_lst => l_instance_id_lst
4489 ,x_return_status => x_return_status
4490 ,x_msg_count => x_msg_count
4491 ,x_msg_data => x_msg_data
4492 ,p_item_attribute_tbl => l_item_attribute_tbl
4493 ,p_location_tbl => l_location_tbl
4494 ,p_generic_id_tbl => l_generic_id_tbl
4495 ,p_lookup_tbl => l_lookup_tbl
4496 ,p_ins_count_rec => l_ins_count_rec
4497 ,p_oks_txn_inst_tbl => px_oks_txn_inst_tbl
4498 ,p_child_inst_tbl => px_child_inst_tbl
4499 );
4500
4501 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
4502 fnd_message.set_name('CSI','CSI_FAILED_TO_VALIDATE_INS');
4503 fnd_message.set_token('instance_id',l_instance_rec1.instance_id);
4504 fnd_msg_pub.add;
4505 RAISE fnd_api.g_exc_error;
4506 END IF;
4507
4508 END IF;
4509 END IF;
4510 END LOOP;
4511 END IF; -- l_rel_tbl count check
4512 EXCEPTION
4513 WHEN OTHERS THEN
4514 NULL;
4515 END;
4516 END update_instance;
4517
4518 -- Added by sk on 9-Apr-02 for bug 2304221
4519 /* ----------------------------------------------------------------------------------------------------------+
4520 | During creation of a relationship between 2 instances then parent owner party and owner account(in |
4521 | case of external) has to inherited to the children. |
4522 | Code is applied only for 'COMPONENT-OF' relationship_type_code | |
4523 +------------------------------------------------------------------------------------------------------------*/
4524
4525 PROCEDURE update_party_account
4526 ( p_api_version IN NUMBER,
4527 p_commit IN VARCHAR2,
4528 p_init_msg_list IN VARCHAR2,
4529 p_validation_level IN NUMBER,
4530 p_ii_relationship_rec IN csi_datastructures_pub.ii_relationship_rec,
4531 p_txn_rec IN OUT NOCOPY csi_datastructures_pub.transaction_rec,
4532 x_return_status OUT NOCOPY VARCHAR2,
4533 x_msg_count OUT NOCOPY NUMBER,
4534 x_msg_data OUT NOCOPY VARCHAR2)
4535 IS
4536 l_ext_attrib_values_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4537 l_party_tbl csi_datastructures_pub.party_tbl;
4538 l_account_tbl csi_datastructures_pub.party_account_tbl;
4539 l_pricing_attrib_tbl csi_datastructures_pub.pricing_attribs_tbl;
4540 l_org_assignments_tbl csi_datastructures_pub.organization_units_tbl;
4541 l_asset_assignment_tbl csi_datastructures_pub.instance_asset_tbl;
4542 l_instance_id_lst csi_datastructures_pub.id_tbl;
4543 l_instance_rec csi_datastructures_pub.instance_rec;
4544 l_subject_id NUMBER;
4545 l_record_found VARCHAR2(1):= fnd_api.g_true;
4546 BEGIN
4547 IF p_ii_relationship_rec.relationship_type_code='COMPONENT-OF' THEN
4548
4549 BEGIN
4550 SELECT cp.party_id
4551 ,cp.party_source_table
4552 ,cp.contact_flag
4553 ,cp.relationship_type_code
4554 ,ca.party_account_id
4555 ,ca.relationship_type_code
4556 INTO l_party_tbl(1).party_id
4557 ,l_party_tbl(1).party_source_table
4558 ,l_party_tbl(1).contact_flag
4559 ,l_party_tbl(1).relationship_type_code
4560 ,l_account_tbl(1).party_account_id
4561 ,l_account_tbl(1).relationship_type_code
4562 FROM csi_i_parties cp,
4563 csi_ip_accounts ca
4564 WHERE cp.instance_id = p_ii_relationship_rec.object_id
4565 AND cp.instance_party_id = ca.instance_party_id
4566 AND cp.relationship_type_code = 'OWNER'
4567 AND cp.relationship_type_code = ca.relationship_type_code
4568 AND (cp.active_end_date IS NULL OR cp.active_end_date > SYSDATE)
4569 AND (ca.active_end_date IS NULL OR ca.active_end_date > SYSDATE);
4570 EXCEPTION
4571 WHEN OTHERS THEN
4572 l_record_found := fnd_api.g_false;
4573 END;
4574
4575 BEGIN
4576 SELECT instance_party_id
4577 ,object_version_number
4578 INTO l_party_tbl(1).instance_party_id
4579 ,l_party_tbl(1).object_version_number
4580 FROM csi_i_parties
4581 WHERE instance_id = p_ii_relationship_rec.subject_id
4582 AND relationship_type_code = 'OWNER';
4583 l_account_tbl(1).instance_party_id := l_party_tbl(1).instance_party_id;
4584 EXCEPTION
4585 WHEN OTHERS THEN
4586 NULL;
4587 END;
4588
4589 IF l_record_found = fnd_api.g_true
4590 THEN
4591 BEGIN
4592 SELECT instance_id
4593 ,object_version_number
4594 INTO l_instance_rec.instance_id
4595 ,l_instance_rec.object_version_number
4596 FROM csi_item_instances
4597 WHERE instance_id = p_ii_relationship_rec.subject_id;
4598
4599 l_party_tbl(1).instance_id := p_ii_relationship_rec.subject_id;
4600 l_account_tbl(1).parent_tbl_index := 1;
4601 EXCEPTION
4602 WHEN OTHERS THEN
4603 l_record_found := fnd_api.g_false;
4604 END;
4605 END IF;
4606
4607
4608 IF l_record_found = fnd_api.g_true
4609 THEN
4610 csi_item_instance_pub.update_item_instance
4611 ( p_api_version => p_api_version
4612 ,p_commit => p_commit
4613 ,p_init_msg_list => p_init_msg_list
4614 ,p_validation_level => p_validation_level
4615 ,p_instance_rec => l_instance_rec
4616 ,p_ext_attrib_values_tbl => l_ext_attrib_values_tbl
4617 ,p_party_tbl => l_party_tbl
4618 ,p_account_tbl => l_account_tbl
4619 ,p_pricing_attrib_tbl => l_pricing_attrib_tbl
4620 ,p_org_assignments_tbl => l_org_assignments_tbl
4621 ,p_asset_assignment_tbl => l_asset_assignment_tbl
4622 ,p_txn_rec => p_txn_rec
4623 ,x_instance_id_lst => l_instance_id_lst
4624 ,x_return_status => x_return_status
4625 ,x_msg_count => x_msg_count
4626 ,x_msg_data => x_msg_data
4627 );
4628
4629 IF NOT(x_return_status = fnd_api.g_ret_sts_success)
4630 THEN
4631 fnd_message.set_name('CSI','CSI_FAILED_TO_VALIDATE_INS');
4632 fnd_message.set_token('instance_id',l_instance_rec.instance_id);
4633 fnd_msg_pub.add;
4634 RAISE fnd_api.g_exc_error;
4635 END IF;
4636 END IF;
4637 END IF;
4638 END update_party_account;
4639
4640 -- End addition by sk on 9-Apr-02 for bug 2304221
4641
4642
4643 -- hint: primary key needs TO be returned.
4644 PROCEDURE create_relationship(
4645 p_api_version IN NUMBER,
4646 p_commit IN VARCHAR2,
4647 p_init_msg_list IN VARCHAR2,
4648 p_validation_level IN NUMBER,
4649 p_relationship_tbl IN OUT NOCOPY csi_datastructures_pub.ii_relationship_tbl,
4650 p_txn_rec IN OUT NOCOPY csi_datastructures_pub.transaction_rec,
4651 x_return_status OUT NOCOPY VARCHAR2,
4652 x_msg_count OUT NOCOPY NUMBER,
4653 x_msg_data OUT NOCOPY VARCHAR2
4654 )
4655 IS
4656
4657
4658 l_api_name CONSTANT VARCHAR2(30) := 'create_relationship';
4659 l_api_version CONSTANT NUMBER := 1.0;
4660 l_return_status_full VARCHAR2(1);
4661 l_access_flag VARCHAR2(1);
4662 l_ii_relationship_rec csi_datastructures_pub.ii_relationship_rec;
4663 l_line_count NUMBER;
4664 l_relationship_id NUMBER;
4665 l_debug_level NUMBER;
4666 l_relship_history_id NUMBER;
4667 l_msg_data VARCHAR2(2000); -- Added by sguthiva for bug 2373109
4668 l_msg_index NUMBER; -- Added by sguthiva for bug 2373109
4669 l_msg_count NUMBER; -- Added by sguthiva for bug 2373109
4670 l_exists VARCHAR2(1);
4671
4672 -- Added for cascade ownership change bug 2972082
4673 l_ext_attrib_values_tbl csi_datastructures_pub.extend_attrib_values_tbl;
4674 l_party_tbl csi_datastructures_pub.party_tbl;
4675 l_account_tbl csi_datastructures_pub.party_account_tbl;
4676 l_temp_party_tbl csi_datastructures_pub.party_tbl;
4677 l_temp_account_tbl csi_datastructures_pub.party_account_tbl;
4678 l_pricing_attrib_tbl csi_datastructures_pub.pricing_attribs_tbl;
4679 l_org_assignments_tbl csi_datastructures_pub.organization_units_tbl;
4680 l_asset_assignment_tbl csi_datastructures_pub.instance_asset_tbl;
4681 l_instance_id_lst csi_datastructures_pub.id_tbl;
4682 l_instance_rec csi_datastructures_pub.instance_rec;
4683 l_cascade_instance_rec csi_datastructures_pub.instance_rec;
4684 -- End addition for cascade ownership changes bug 2972082
4685
4686 BEGIN
4687 -- standard start of api savepoint
4688 SAVEPOINT create_relationship_pvt;
4689
4690 -- standard call to check for call compatibility.
4691 IF NOT fnd_api.compatible_api_call ( l_api_version,
4692 p_api_version,
4693 l_api_name,
4694 g_pkg_name)
4695 THEN
4696 RAISE fnd_api.g_exc_unexpected_error;
4697 END IF;
4698
4699
4700 -- initialize message list if p_init_msg_list is set to true.
4701 IF fnd_api.to_boolean( p_init_msg_list )
4702 THEN
4703 fnd_msg_pub.initialize;
4704 END IF;
4705
4706 -- initialize api return status to success
4707 x_return_status := fnd_api.g_ret_sts_success;
4708
4709 l_debug_level:=fnd_profile.value('CSI_DEBUG_LEVEL');
4710 IF (l_debug_level > 0) THEN
4711 CSI_gen_utility_pvt.put_line( 'create_relationship');
4712 END IF;
4713
4714 IF (l_debug_level > 1) THEN
4715
4716
4717 CSI_gen_utility_pvt.put_line(
4718 p_api_version ||'-'||
4719 p_commit ||'-'||
4720 p_init_msg_list ||'-'||
4721 p_validation_level );
4722
4723 csi_gen_utility_pvt.dump_rel_tbl(p_relationship_tbl);
4724 csi_gen_utility_pvt.dump_txn_rec(p_txn_rec);
4725
4726 END IF;
4727
4728 -- invoke validation procedures
4729 validate_ii_relationships(
4730 p_init_msg_list => fnd_api.g_false,
4731 p_validation_level => p_validation_level,
4732 p_validation_mode => 'CREATE',
4733 p_ii_relationship_tbl => p_relationship_tbl,
4734 x_return_status => x_return_status,
4735 x_msg_count => x_msg_count,
4736 x_msg_data => x_msg_data);
4737
4738
4739 IF x_return_status<>fnd_api.g_ret_sts_success THEN
4740 RAISE fnd_api.g_exc_error;
4741 END IF;
4742
4743
4744
4745 l_line_count := p_relationship_tbl.count;
4746
4747 FOR l_count IN 1..l_line_count LOOP
4748 IF ( (p_relationship_tbl(l_count).mandatory_flag IS NULL) OR
4749 (p_relationship_tbl(l_count).mandatory_flag = fnd_api.g_miss_char) ) THEN
4750 p_relationship_tbl(l_count).mandatory_flag:='N';
4751 END IF;
4752
4753 --Added for MACD lock functionality
4754 IF p_relationship_tbl(l_count).object_id IS NOT NULL AND
4755 p_relationship_tbl(l_count).object_id <> fnd_api.g_miss_num
4756 THEN
4757 IF csi_item_instance_pvt.check_item_instance_lock
4758 ( p_instance_id => p_relationship_tbl(l_count).object_id)
4759 THEN
4760 IF p_txn_rec.transaction_type_id NOT IN (51,53,54,401)
4761 THEN
4762 FND_MESSAGE.SET_NAME('CSI','CSI_LOCKED_INSTANCE');
4763 FND_MESSAGE.SET_TOKEN('INSTANCE_ID',p_relationship_tbl(l_count).object_id);
4764 FND_MSG_PUB.ADD;
4765 RAISE FND_API.G_EXC_ERROR;
4766 END IF;
4767 END IF;
4768 END IF;
4769 IF p_relationship_tbl(l_count).subject_id IS NOT NULL AND
4770 p_relationship_tbl(l_count).subject_id <> fnd_api.g_miss_num
4771 THEN
4772 IF csi_item_instance_pvt.check_item_instance_lock
4773 ( p_instance_id => p_relationship_tbl(l_count).subject_id)
4774 THEN
4775 IF p_txn_rec.transaction_type_id NOT IN (51,53,54,401)
4776 THEN
4777 FND_MESSAGE.SET_NAME('CSI','CSI_LOCKED_INSTANCE');
4778 FND_MESSAGE.SET_TOKEN('INSTANCE_ID',p_relationship_tbl(l_count).subject_id);
4779 FND_MSG_PUB.ADD;
4780 RAISE FND_API.G_EXC_ERROR;
4781 END IF;
4782 END IF;
4783 END IF;
4784 -- End addition for MACD lock functionality
4785
4786
4787 /* Added for cyclic relationships to skip validations for 'CONNECTED-TO' */
4788 IF p_relationship_tbl(l_count).relationship_type_code <> 'CONNECTED-TO'
4789 THEN
4790 IF subject_exists(p_subject_id => p_relationship_tbl(l_count).subject_id,
4791 p_relship_type_code => p_relationship_tbl(l_count).relationship_type_code,
4792 p_relationship_id => Null,
4793 p_mode => 'CREATE' )
4794 THEN
4795 x_return_status:=fnd_api.g_ret_sts_success;
4796 ELSE
4797 x_return_status:=fnd_api.g_ret_sts_error;
4798 RAISE fnd_api.g_exc_error;
4799 END IF;
4800
4801 IF ((x_return_status=fnd_api.g_ret_sts_success) AND
4802 (p_relationship_tbl(l_count).object_id IS NOT NULL) ) THEN
4803 csi_ii_relationships_pvt.check_for_object
4804 (p_subject_id =>p_relationship_tbl(l_count).subject_id,
4805 p_object_id =>p_relationship_tbl(l_count).object_id,
4806 p_relationship_type_code =>p_relationship_tbl(l_count).relationship_type_code,
4807 x_return_status =>x_return_status,
4808 x_msg_count =>x_msg_count,
4809 x_msg_data =>x_msg_data
4810 );
4811 IF x_return_status<>fnd_api.g_ret_sts_success THEN
4812 RAISE fnd_api.g_exc_error;
4813 END IF;
4814 END IF;
4815 END IF; /* end of additional for cyclic relationship */
4816 /* Another one for cyclic relationship */
4817 /* added this to aviod creating 'CONNECTED-TO' relationship in the reverse direction */
4818 IF p_relationship_tbl(l_count).relationship_type_code='CONNECTED-TO' THEN
4819 IF relationship_not_exists(p_relationship_tbl(l_count).subject_id,
4820 p_relationship_tbl(l_count).object_id,
4821 p_relationship_tbl(l_count).relationship_type_code,
4822 'CREATE',
4823 fnd_api.g_miss_num)
4824 THEN
4825 x_return_status:=fnd_api.g_ret_sts_success;
4826 ELSE
4827 x_return_status:=fnd_api.g_ret_sts_error;
4828 RAISE fnd_api.g_exc_error;
4829 END IF;
4830 -- Start of att enhancements by sguthiva
4831 IF csi_ii_relationships_pvt.Is_link_type (p_instance_id => p_relationship_tbl(l_count).object_id )
4832 THEN
4833 IF csi_ii_relationships_pvt.relationship_for_link
4834 ( p_instance_id => p_relationship_tbl(l_count).object_id
4835 ,p_mode => 'CREATE'
4836 ,p_relationship_id => NULL )
4837 THEN
4838 fnd_message.set_name('CSI','CSI_LINK_EXISTS');
4839 fnd_message.set_token('INSTANCE_ID',p_relationship_tbl(l_count).object_id);
4840 fnd_msg_pub.add;
4841 RAISE fnd_api.g_exc_error;
4842 END IF;
4843 END IF;
4844
4845 IF csi_ii_relationships_pvt.Is_link_type (p_instance_id => p_relationship_tbl(l_count).subject_id )
4846 THEN
4847 IF csi_ii_relationships_pvt.relationship_for_link
4848 ( p_instance_id => p_relationship_tbl(l_count).subject_id
4849 ,p_mode => 'CREATE'
4850 ,p_relationship_id => NULL )
4851 THEN
4852 fnd_message.set_name('CSI','CSI_LINK_EXISTS');
4853 fnd_message.set_token('INSTANCE_ID',p_relationship_tbl(l_count).subject_id);
4854 fnd_msg_pub.add;
4855 RAISE fnd_api.g_exc_error;
4856 END IF;
4857 END IF;
4858 -- End of att enhancements by sguthiva
4859 END IF;
4860
4861 /* end of cyclic relationship */
4862
4863 IF ((p_relationship_tbl(l_count).active_start_date IS NULL) OR
4864 (p_relationship_tbl(l_count).active_start_date = FND_API.G_MISS_DATE))
4865 THEN
4866 p_relationship_tbl(l_count).active_start_date := SYSDATE;
4867 END IF;
4868
4869 IF x_return_status=fnd_api.g_ret_sts_success THEN
4870 -- srramakr Moved the Update_instance call before the table handler Bug # 3296009
4871 update_instance
4872 ( p_api_version => p_api_version,
4873 p_commit => fnd_api.g_false,
4874 p_init_msg_list => p_init_msg_list,
4875 p_validation_level => p_validation_level,
4876 p_ii_relationship_rec => p_relationship_tbl(l_count),
4877 p_txn_rec => p_txn_rec,
4878 p_mode => 'CREATE',
4879 x_return_status => x_return_status,
4880 x_msg_count => x_msg_count,
4881 x_msg_data => x_msg_data);
4882 -- Added by sguthiva for bug 2373109
4883 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4884 l_msg_index := 1;
4885 l_msg_count := x_msg_count;
4886 WHILE l_msg_count > 0
4887 LOOP
4888 x_msg_data := FND_MSG_PUB.GET
4889 ( l_msg_index,
4890 FND_API.G_FALSE );
4891 csi_gen_utility_pvt.put_line( ' Error from CSI_II_RELATIONSHIPS_PVT.CREATE_RELATIONSHIP');
4892 csi_gen_utility_pvt.put_line( ' Call to update_instance has errored ....');
4893 csi_gen_utility_pvt.put_line('MESSAGE DATA = '||x_msg_data);
4894 l_msg_index := l_msg_index + 1;
4895 l_msg_count := l_msg_count - 1;
4896 END LOOP;
4897 RAISE FND_API.G_EXC_ERROR;
4898 END IF;
4899 -- End of addition by sguthiva for bug 2373109
4900
4901
4902
4903 -- Added by sk on 9-Apr-02 for bug 2304221
4904 -- invoke table handler(csi_ii_relationships_pkg.insert_row)
4905 csi_ii_relationships_pkg.insert_row(
4906 px_relationship_id => p_relationship_tbl(l_count).relationship_id,
4907 p_relationship_type_code => p_relationship_tbl(l_count).relationship_type_code,
4908 p_object_id => p_relationship_tbl(l_count).object_id,
4909 p_subject_id => p_relationship_tbl(l_count).subject_id,
4910 p_position_reference => p_relationship_tbl(l_count).position_reference,
4911 p_active_start_date => p_relationship_tbl(l_count).active_start_date,
4912 p_active_end_date => p_relationship_tbl(l_count).active_end_date,
4913 p_display_order => p_relationship_tbl(l_count).display_order,
4914 p_mandatory_flag => p_relationship_tbl(l_count).mandatory_flag,
4915 p_context => p_relationship_tbl(l_count).context,
4916 p_attribute1 => p_relationship_tbl(l_count).attribute1,
4917 p_attribute2 => p_relationship_tbl(l_count).attribute2,
4918 p_attribute3 => p_relationship_tbl(l_count).attribute3,
4919 p_attribute4 => p_relationship_tbl(l_count).attribute4,
4920 p_attribute5 => p_relationship_tbl(l_count).attribute5,
4921 p_attribute6 => p_relationship_tbl(l_count).attribute6,
4922 p_attribute7 => p_relationship_tbl(l_count).attribute7,
4923 p_attribute8 => p_relationship_tbl(l_count).attribute8,
4924 p_attribute9 => p_relationship_tbl(l_count).attribute9,
4925 p_attribute10 => p_relationship_tbl(l_count).attribute10,
4926 p_attribute11 => p_relationship_tbl(l_count).attribute11,
4927 p_attribute12 => p_relationship_tbl(l_count).attribute12,
4928 p_attribute13 => p_relationship_tbl(l_count).attribute13,
4929 p_attribute14 => p_relationship_tbl(l_count).attribute14,
4930 p_attribute15 => p_relationship_tbl(l_count).attribute15,
4931 p_created_by => fnd_global.user_id,
4932 p_creation_date => SYSDATE,
4933 p_last_updated_by => fnd_global.user_id,
4934 p_last_update_date => SYSDATE,
4935 p_last_update_login => fnd_global.conc_login_id,
4936 p_object_version_number => 1);
4937 -- hint: primary key should be returned.
4938 -- x_relationship_id := px_relationship_id;
4939 END IF;
4940
4941 IF x_return_status <> fnd_api.g_ret_sts_success THEN
4942 RAISE fnd_api.g_exc_error;
4943 END IF;
4944
4945 csi_transactions_pvt.create_transaction
4946 (
4947 p_api_version => p_api_version
4948 ,p_commit => p_commit
4949 ,p_init_msg_list => p_init_msg_list
4950 ,p_validation_level => p_validation_level
4951 ,p_success_if_exists_flag => 'Y'
4952 ,p_transaction_rec => p_txn_rec
4953 ,x_return_status => x_return_status
4954 ,x_msg_count => x_msg_count
4955 ,x_msg_data => x_msg_data
4956 );
4957
4958 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
4959 fnd_message.set_name('CSI','CSI_FAILED_TO_VALIDATE_TXN');
4960 fnd_message.set_token('transaction_id',p_txn_rec.transaction_id );
4961 fnd_msg_pub.add;
4962 RAISE fnd_api.g_exc_error;
4963 ROLLBACK TO create_relationship_pvt;
4964 END IF;
4965
4966 -- The following code has been commented by sguthiva
4967 -- after a discussion for bug 2373109 on 21-May-02
4968 -- During a creation of relationship there should not be
4969 -- any changes to the ownership.
4970 /*
4971 update_party_account
4972 ( p_api_version => p_api_version,
4973 p_commit => fnd_api.g_false,
4974 p_init_msg_list => p_init_msg_list,
4975 p_validation_level => p_validation_level,
4976 p_ii_relationship_rec => p_relationship_tbl(l_count),
4977 p_txn_rec => p_txn_rec,
4978 x_return_status => x_return_status,
4979 x_msg_count => x_msg_count,
4980 x_msg_data => x_msg_data);
4981 */
4982 -- End addition by sk for bug 2304221
4983
4984 IF x_return_status = fnd_api.g_ret_sts_success THEN
4985
4986 l_relship_history_id := NULL;
4987
4988 csi_ii_relationships_h_pkg.insert_row(
4989 px_relationship_history_id => l_relship_history_id,
4990 p_relationship_id => p_relationship_tbl(l_count).relationship_id,
4991 p_transaction_id => p_txn_rec.transaction_id,
4992 p_old_subject_id => NULL,
4993 p_new_subject_id => p_relationship_tbl(l_count).subject_id,
4994 p_old_position_reference => NULL,
4995 p_new_position_reference => p_relationship_tbl(l_count).position_reference,
4996 p_old_active_start_date => NULL,
4997 p_new_active_start_date => p_relationship_tbl(l_count).active_start_date,
4998 p_old_active_end_date => NULL,
4999 p_new_active_end_date => p_relationship_tbl(l_count).active_end_date,
5000 p_old_mandatory_flag => NULL,
5001 p_new_mandatory_flag => p_relationship_tbl(l_count).mandatory_flag,
5002 p_old_context => NULL,
5003 p_new_context => p_relationship_tbl(l_count).context,
5004 p_old_attribute1 => NULL,
5005 p_new_attribute1 => p_relationship_tbl(l_count).attribute1,
5006 p_old_attribute2 => NULL,
5007 p_new_attribute2 => p_relationship_tbl(l_count).attribute2,
5008 p_old_attribute3 => NULL,
5009 p_new_attribute3 => p_relationship_tbl(l_count).attribute3,
5010 p_old_attribute4 => NULL,
5011 p_new_attribute4 => p_relationship_tbl(l_count).attribute4,
5012 p_old_attribute5 => NULL,
5013 p_new_attribute5 => p_relationship_tbl(l_count).attribute5,
5014 p_old_attribute6 => NULL,
5015 p_new_attribute6 => p_relationship_tbl(l_count).attribute6,
5016 p_old_attribute7 => NULL,
5017 p_new_attribute7 => p_relationship_tbl(l_count).attribute7,
5018 p_old_attribute8 => NULL,
5019 p_new_attribute8 => p_relationship_tbl(l_count).attribute8,
5020 p_old_attribute9 => NULL,
5021 p_new_attribute9 => p_relationship_tbl(l_count).attribute9,
5022 p_old_attribute10 => NULL,
5023 p_new_attribute10 => p_relationship_tbl(l_count).attribute10,
5024 p_old_attribute11 => NULL,
5025 p_new_attribute11 => p_relationship_tbl(l_count).attribute11,
5026 p_old_attribute12 => NULL,
5027 p_new_attribute12 => p_relationship_tbl(l_count).attribute12,
5028 p_old_attribute13 => NULL,
5029 p_new_attribute13 => p_relationship_tbl(l_count).attribute13,
5030 p_old_attribute14 => NULL,
5031 p_new_attribute14 => p_relationship_tbl(l_count).attribute14,
5032 p_old_attribute15 => NULL,
5033 p_new_attribute15 => p_relationship_tbl(l_count).attribute15,
5034 p_full_dump_flag => 'Y',
5035 p_created_by => fnd_global.user_id,
5036 p_creation_date => SYSDATE,
5037 p_last_updated_by => fnd_global.user_id,
5038 p_last_update_date => SYSDATE,
5039 p_last_update_login => fnd_global.conc_login_id,
5040 p_object_version_number => 1);
5041
5042
5043 END IF;
5044
5045 -- Start of cascade ownership changes bug 2972082
5046 -- Get the parent instance owner party and owner account
5047
5048 IF nvl(p_relationship_tbl(l_count).cascade_ownership_flag,'N')='Y'
5049 THEN
5050 csi_gen_utility_pvt.put_line('Cascade_ownership_flag : '||p_relationship_tbl(l_count).cascade_ownership_flag);
5051 l_instance_rec:=l_cascade_instance_rec;
5052 l_ext_attrib_values_tbl.delete;
5053 l_party_tbl.delete;
5054 l_account_tbl.delete;
5055 l_pricing_attrib_tbl.delete;
5056 l_org_assignments_tbl.delete;
5057 l_instance_id_lst.delete;
5058
5059 IF p_relationship_tbl(l_count).object_id IS NOT NULL AND
5060 p_relationship_tbl(l_count).object_id <> fnd_api.g_miss_num
5061 THEN
5062 l_instance_rec.instance_id:=p_relationship_tbl(l_count).object_id;
5063 END IF;
5064
5065 BEGIN
5066 SELECT object_version_number,
5067 'Y'
5068 INTO l_instance_rec.object_version_number,
5069 l_instance_rec.cascade_ownership_flag
5070 FROM csi_item_instances
5071 WHERE instance_id=l_instance_rec.instance_id
5072 AND (active_end_date IS NULL OR active_end_date > sysdate);
5073 EXCEPTION
5074 WHEN OTHERS
5075 THEN
5076 csi_gen_utility_pvt.put_line( 'Error from create relationship API.');
5077 csi_gen_utility_pvt.put_line( 'The object_id, which you are trying to cascade its ownership, is not found or expired in csi_item_instances table. ');
5078 RAISE fnd_api.g_exc_error;
5079 END;
5080
5081 csi_item_instance_pub.update_item_instance
5082 ( p_api_version => p_api_version
5083 ,p_commit => p_commit
5084 ,p_init_msg_list => p_init_msg_list
5085 ,p_validation_level => p_validation_level
5086 ,p_instance_rec => l_instance_rec
5087 ,p_ext_attrib_values_tbl => l_ext_attrib_values_tbl
5088 ,p_party_tbl => l_party_tbl
5089 ,p_account_tbl => l_account_tbl
5090 ,p_pricing_attrib_tbl => l_pricing_attrib_tbl
5091 ,p_org_assignments_tbl => l_org_assignments_tbl
5092 ,p_asset_assignment_tbl => l_asset_assignment_tbl
5093 ,p_txn_rec => p_txn_rec
5094 ,x_instance_id_lst => l_instance_id_lst
5095 ,x_return_status => x_return_status
5096 ,x_msg_count => x_msg_count
5097 ,x_msg_data => x_msg_data
5098 );
5099
5100 IF NOT(x_return_status = fnd_api.g_ret_sts_success)
5101 THEN
5102 csi_gen_utility_pvt.put_line( 'Error from create relationship API.');
5103 csi_gen_utility_pvt.put_line( 'Call to update_item_instance API for cascade ownership has errored');
5104 fnd_message.set_name('CSI','CSI_FAILED_TO_VALIDATE_INS');
5105 fnd_message.set_token('instance_id',l_instance_rec.instance_id);
5106 fnd_msg_pub.add;
5107 RAISE fnd_api.g_exc_error;
5108 END IF;
5109 END IF;
5110
5111 -- End of cascade ownership changes bug 2972082
5112
5113 END LOOP;
5114 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5115 RAISE fnd_api.g_exc_error;
5116 END IF;
5117 --
5118 -- END of API BODY
5119 --
5120
5121 -- standard check for p_commit
5122 IF fnd_api.to_boolean( p_commit )
5123 THEN
5124 COMMIT WORK;
5125 END IF;
5126
5127 -- standard call to get message count and if count is 1, get message info.
5128 fnd_msg_pub.count_AND_get
5129 ( p_count => x_msg_count,
5130 p_data => x_msg_data
5131 );
5132
5133 EXCEPTION
5134 WHEN fnd_api.g_exc_error THEN
5135 ROLLBACK TO create_relationship_pvt;
5136 x_return_status := fnd_api.g_ret_sts_error ;
5137 fnd_msg_pub.count_AND_get
5138 (p_count => x_msg_count ,
5139 p_data => x_msg_data
5140 );
5141
5142 WHEN fnd_api.g_exc_unexpected_error THEN
5143 ROLLBACK TO create_relationship_pvt;
5144 x_return_status := fnd_api.g_ret_sts_unexp_error ;
5145 fnd_msg_pub.count_AND_get
5146 (p_count => x_msg_count ,
5147 p_data => x_msg_data
5148 );
5149
5150 WHEN OTHERS THEN
5151 ROLLBACK TO create_relationship_pvt;
5152 x_return_status := fnd_api.g_ret_sts_unexp_error ;
5153 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
5154 fnd_msg_pub.add_exc_msg(g_pkg_name ,l_api_name);
5155 END IF;
5156 fnd_msg_pub.count_AND_get
5157 (p_count => x_msg_count ,
5158 p_data => x_msg_data
5159 );
5160
5161 END create_relationship;
5162
5163
5164 PROCEDURE update_relationship
5165 (
5166 p_api_version IN NUMBER,
5167 p_commit IN VARCHAR2,
5168 p_init_msg_list IN VARCHAR2,
5169 p_validation_level IN NUMBER,
5170 p_relationship_tbl IN csi_datastructures_pub.ii_relationship_tbl,
5171 p_replace_flag IN VARCHAR2,
5172 p_txn_rec IN OUT NOCOPY csi_datastructures_pub.transaction_rec,
5173 x_return_status OUT NOCOPY VARCHAR2,
5174 x_msg_count OUT NOCOPY NUMBER,
5175 x_msg_data OUT NOCOPY VARCHAR2
5176 ) IS
5177
5178 CURSOR relship_csr (relship_id IN NUMBER) IS
5179 SELECT relationship_id,
5180 relationship_type_code,
5181 object_id,
5182 subject_id,
5183 position_reference,
5184 active_start_date,
5185 active_end_date,
5186 display_order,
5187 mandatory_flag,
5188 context,
5189 attribute1,
5190 attribute2,
5191 attribute3,
5192 attribute4,
5193 attribute5,
5194 attribute6,
5195 attribute7,
5196 attribute8,
5197 attribute9,
5198 attribute10,
5199 attribute11,
5200 attribute12,
5201 attribute13,
5202 attribute14,
5203 attribute15,
5204 object_version_number
5205 FROM csi_ii_relationships
5206 WHERE relationship_id=relship_id
5207 FOR UPDATE OF object_version_number ;
5208
5209
5210 l_api_name CONSTANT VARCHAR2(30) := 'update_ii_relationships';
5211 l_api_version CONSTANT NUMBER := 1.0;
5212 -- local variables
5213 --
5214 l_index NUMBER;
5215 l_count NUMBER;
5216 l_debug_level NUMBER;
5217 l_line_count NUMBER;
5218 l_relship_csr relship_csr%ROWTYPE;
5219 l_old_relship_rec csi_datastructures_pub.ii_relationship_rec;
5220 l_new_relship_rec csi_datastructures_pub.ii_relationship_rec;
5221 l_instance_rec csi_datastructures_pub.instance_rec;
5222 l_temp_ins_rec csi_datastructures_pub.instance_rec;
5223 l_object_id NUMBER;
5224 l_obv_number NUMBER;
5225 l_ins_usage_code VARCHAR2(30);
5226 l_instance_id_lst csi_datastructures_pub.id_tbl;
5227 l_item_attribute_tbl csi_item_instance_pvt.item_attribute_tbl;
5228 l_location_tbl csi_item_instance_pvt.location_tbl;
5229 l_generic_id_tbl csi_item_instance_pvt.generic_id_tbl;
5230 l_lookup_tbl csi_item_instance_pvt.lookup_tbl;
5231 l_ins_count_rec csi_item_instance_pvt.ins_count_rec;
5232 l_relationship_tbl csi_datastructures_pub.ii_relationship_tbl;
5233 l_obj_id NUMBER;
5234 l_sub_id NUMBER;
5235 l_msg_data VARCHAR2(2000);
5236 l_msg_index NUMBER;
5237 l_msg_count NUMBER;
5238 l_found BOOLEAN;
5239 l_exists VARCHAR2(1);
5240 -- Added for cascade ownership change bug 2972082
5241 l_relationship_query_rec csi_datastructures_pub.relationship_query_rec;
5242 l_rel_tbl csi_datastructures_pub.ii_relationship_tbl;
5243 l_ii_relationship_level_tbl csi_ii_relationships_pvt.ii_relationship_level_tbl;
5244 l_ext_attrib_values_tbl csi_datastructures_pub.extend_attrib_values_tbl;
5245 l_party_tbl csi_datastructures_pub.party_tbl;
5246 l_account_tbl csi_datastructures_pub.party_account_tbl;
5247 l_temp_party_tbl csi_datastructures_pub.party_tbl;
5248 l_temp_account_tbl csi_datastructures_pub.party_account_tbl;
5249 l_pricing_attrib_tbl csi_datastructures_pub.pricing_attribs_tbl;
5250 l_org_assignments_tbl csi_datastructures_pub.organization_units_tbl;
5251 l_asset_assignment_tbl csi_datastructures_pub.instance_asset_tbl;
5252 l_inst_id_lst csi_datastructures_pub.id_tbl;
5253 l_inst_rec csi_datastructures_pub.instance_rec;
5254 l_cascade_instance_rec csi_datastructures_pub.instance_rec;
5255 l_item_id NUMBER;
5256 l_srl_ctl NUMBER;
5257 l_vld_org NUMBER;
5258 l_loc_type_code VARCHAR2(30);
5259 -- End addition for cascade ownership changes bug 2972082
5260 l_subject_lock NUMBER;
5261 px_oks_txn_inst_tbl oks_ibint_pub.txn_instance_tbl;
5262 px_child_inst_tbl csi_item_instance_grp.child_inst_tbl;
5263 BEGIN
5264 -- standard start of api savepoint
5265 SAVEPOINT update_relationship_pvt;
5266 -- standard call to check for call compatibility.
5267 IF NOT fnd_api.compatible_api_call ( l_api_version,
5268 p_api_version,
5269 l_api_name,
5270 g_pkg_name)
5271 THEN
5272 RAISE fnd_api.g_exc_unexpected_error;
5273 END IF;
5274
5275
5276 -- initialize message list IF p_init_msg_list IS set TO true.
5277 IF fnd_api.to_boolean( p_init_msg_list )
5278 THEN
5279 fnd_msg_pub.initialize;
5280 END IF;
5281
5282
5283 -- initialize api return status to success
5284 x_return_status := fnd_api.g_ret_sts_success;
5285
5286
5287 l_debug_level:=fnd_profile.value('CSI_DEBUG_LEVEL');
5288 IF (l_debug_level > 0) THEN
5289 CSI_gen_utility_pvt.put_line( 'update_relationship');
5290 END IF;
5291
5292 IF (l_debug_level > 1) THEN
5293
5294
5295 CSI_gen_utility_pvt.put_line(
5296 p_api_version ||'-'||
5297 p_commit ||'-'||
5298 p_init_msg_list ||'-'||
5299 p_validation_level );
5300
5301 csi_gen_utility_pvt.dump_rel_tbl(p_relationship_tbl);
5302 csi_gen_utility_pvt.dump_txn_rec(p_txn_rec);
5303
5304 END IF;
5305
5306
5307 validate_ii_relationships(
5308 p_init_msg_list => fnd_api.g_false,
5309 p_validation_level => p_validation_level,
5310 p_validation_mode => 'UPDATE',
5311 p_ii_relationship_tbl => p_relationship_tbl,
5312 x_return_status => x_return_status,
5313 x_msg_count => x_msg_count,
5314 x_msg_data => x_msg_data);
5315
5316 IF x_return_status<>fnd_api.g_ret_sts_success THEN
5317 RAISE fnd_api.g_exc_error;
5318 END IF;
5319
5320 l_line_count := p_relationship_tbl.count;
5321
5322 FOR l_count IN 1..l_line_count LOOP
5323 l_obv_number:=NULL;
5324 /* Cyclic Relationship */
5325 /* added this to validate input parameters */
5326
5327 IF NOT valid_in_parameters
5328 (p_relship_id => p_relationship_tbl(l_count).relationship_id,
5329 p_object_id => p_relationship_tbl(l_count).object_id,
5330 p_subject_id => p_relationship_tbl(l_count).subject_id )
5331 THEN
5332 fnd_message.set_name('CSI','CSI_API_INVALID_PARAMETERS');
5333 fnd_msg_pub.add;
5334 RAISE fnd_api.g_exc_error;
5335 END IF;
5336
5337 --Added for MACD lock functionality
5338 IF p_relationship_tbl(l_count).object_id IS NOT NULL AND
5339 p_relationship_tbl(l_count).object_id <> fnd_api.g_miss_num
5340 THEN
5341 IF csi_item_instance_pvt.check_item_instance_lock
5342 ( p_instance_id => p_relationship_tbl(l_count).object_id)
5343 THEN
5344 IF p_txn_rec.transaction_type_id NOT IN (51,53,54,401)
5345 THEN
5346 FND_MESSAGE.SET_NAME('CSI','CSI_LOCKED_INSTANCE');
5347 FND_MESSAGE.SET_TOKEN('INSTANCE_ID',p_relationship_tbl(l_count).object_id);
5348 FND_MSG_PUB.ADD;
5349 RAISE FND_API.G_EXC_ERROR;
5350 END IF;
5351 END IF;
5352 END IF;
5353 IF p_relationship_tbl(l_count).subject_id IS NOT NULL AND
5354 p_relationship_tbl(l_count).subject_id <> fnd_api.g_miss_num
5355 THEN
5356 IF csi_item_instance_pvt.check_item_instance_lock
5357 ( p_instance_id => p_relationship_tbl(l_count).subject_id)
5358 THEN
5359 IF p_txn_rec.transaction_type_id NOT IN (51,53,54,401)
5360 THEN
5361 FND_MESSAGE.SET_NAME('CSI','CSI_LOCKED_INSTANCE');
5362 FND_MESSAGE.SET_TOKEN('INSTANCE_ID',p_relationship_tbl(l_count).subject_id);
5363 FND_MSG_PUB.ADD;
5364 RAISE FND_API.G_EXC_ERROR;
5365 END IF;
5366 END IF;
5367 ELSE
5368 l_subject_lock:=NULL;
5369 BEGIN
5370 SELECT subject_id
5371 INTO l_subject_lock
5372 FROM csi_ii_relationships
5373 WHERE relationship_id=p_relationship_tbl(l_count).relationship_id;
5374 IF csi_item_instance_pvt.check_item_instance_lock
5375 ( p_instance_id => l_subject_lock)
5376 THEN
5377 IF p_txn_rec.transaction_type_id NOT IN (51,53,54,401)
5378 THEN
5379 FND_MESSAGE.SET_NAME('CSI','CSI_LOCKED_INSTANCE');
5380 FND_MESSAGE.SET_TOKEN('INSTANCE_ID',l_subject_lock);
5381 FND_MSG_PUB.ADD;
5382 RAISE FND_API.G_EXC_ERROR;
5383 END IF;
5384 END IF;
5385 EXCEPTION
5386 WHEN NO_DATA_FOUND THEN
5387 NULL;
5388 END;
5389
5390 END IF;
5391 -- End addition for MACD lock functionality
5392
5393 l_new_relship_rec:=p_relationship_tbl(l_count);
5394 OPEN relship_csr (p_relationship_tbl(l_count).relationship_id);
5395 FETCH relship_csr INTO l_relship_csr;
5396 IF ( (l_relship_csr.object_version_number<>p_relationship_tbl(l_count).object_version_number)
5397 AND (p_relationship_tbl(l_count).object_version_number <> fnd_api.g_miss_num) ) THEN
5398 fnd_message.set_name('CSI', 'CSI_RECORD_CHANGED');
5399 fnd_msg_pub.add;
5400 RAISE fnd_api.g_exc_error;
5401 END IF;
5402 CLOSE relship_csr;
5403
5404 /* Cyclic relationship */
5405 /* added this call to check configurator_id */
5406 /* IF config_set
5407 (p_relationship_id=>p_relationship_tbl(l_count).relationship_id)
5408 THEN
5409 RAISE fnd_api.g_exc_error;
5410 END IF;
5411 */
5412 /* added this to skip this validation ,in case subject and object_id are null */
5413 IF ((p_relationship_tbl(l_count).relationship_id IS NOT NULL
5414 AND p_relationship_tbl(l_count).relationship_id <> fnd_api.g_miss_num)
5415 AND ( p_relationship_tbl(l_count).object_id IS NOT NULL
5416 AND p_relationship_tbl(l_count).object_id <> fnd_api.g_miss_num))
5417 THEN
5418 /* End cyclic relationship */
5419 IF object_relship_exists(p_relationship_tbl(l_count).relationship_id,
5420 p_relationship_tbl(l_count).object_id,
5421 p_relationship_tbl(l_count).relationship_type_code)
5422 THEN
5423 x_return_status := fnd_api.g_ret_sts_success;
5424 ELSE
5425 x_return_status := fnd_api.g_ret_sts_error;
5426 RAISE fnd_api.g_exc_error;
5427 END IF;
5428 END IF;
5429
5430 /* Cyclic relationship -- added the condition to skip the validation for 'CONNECTED-TO' relationship */
5431 IF p_relationship_tbl(l_count).relationship_type_code <> 'CONNECTED-TO' THEN
5432
5433 IF subject_exists(p_subject_id => p_relationship_tbl(l_count).subject_id,
5434 p_relship_type_code => p_relationship_tbl(l_count).relationship_type_code,
5435 p_relationship_id => p_relationship_tbl(l_count).relationship_id,
5436 p_mode => 'UPDATE')
5437 THEN
5438 x_return_status:=fnd_api.g_ret_sts_success;
5439 ELSE
5440 x_return_status:=fnd_api.g_ret_sts_error;
5441 RAISE fnd_api.g_exc_error;
5442 END IF;
5443 --
5444 -- check whether the Inverse Active Relationship exists
5445 Begin
5446 select 'x'
5447 into l_exists
5448 from csi_ii_relationships
5449 where object_id = decode(p_relationship_tbl(l_count).subject_id,fnd_api.g_miss_num,l_relship_csr.subject_id,
5450 p_relationship_tbl(l_count).subject_id)
5451 and subject_id = decode(p_relationship_tbl(l_count).object_id,fnd_api.g_miss_num,l_relship_csr.object_id,
5452 p_relationship_tbl(l_count).object_id)
5453 and relationship_type_code = decode(p_relationship_tbl(l_count).relationship_type_code,fnd_api.g_miss_char,
5454 l_relship_csr.relationship_type_code,
5455 p_relationship_tbl(l_count).relationship_type_code)
5456 and ((active_end_date is null) or (active_end_date > sysdate))
5457 and relationship_id <> p_relationship_tbl(l_count).relationship_id;
5458 --
5459 fnd_message.set_name('CSI','CSI_CHILD_PARENT_REL_LOOP');
5460 fnd_msg_pub.add;
5461 x_return_status := fnd_api.g_ret_sts_error;
5462 RAISE fnd_api.g_exc_error;
5463 Exception
5464 when no_data_found then
5465 null;
5466 End;
5467 --
5468 -- Start of att enhancements by sguthiva
5469 ELSIF p_relationship_tbl(l_count).relationship_type_code = 'CONNECTED-TO'
5470 THEN
5471 IF p_relationship_tbl(l_count).object_id IS NULL OR
5472 p_relationship_tbl(l_count).object_id=fnd_api.g_miss_num
5473 THEN
5474 l_obj_id:=NULL;
5475 BEGIN
5476 SELECT object_id
5477 INTO l_obj_id
5478 FROM csi_ii_relationships
5479 WHERE relationship_id=p_relationship_tbl(l_count).relationship_id;
5480 EXCEPTION
5481 WHEN OTHERS THEN
5482 NULL;
5483 END;
5484 ELSE
5485 l_obj_id := p_relationship_tbl(l_count).object_id;
5486 END IF;
5487 --
5488 IF p_relationship_tbl(l_count).subject_id IS NULL OR
5489 p_relationship_tbl(l_count).subject_id=fnd_api.g_miss_num
5490 THEN
5491 l_sub_id:=NULL;
5492 BEGIN
5493 SELECT subject_id
5494 INTO l_sub_id
5495 FROM csi_ii_relationships
5496 WHERE relationship_id=p_relationship_tbl(l_count).relationship_id;
5497 EXCEPTION
5498 WHEN OTHERS THEN
5499 NULL;
5500 END;
5501 ELSE
5502 l_sub_id := p_relationship_tbl(l_count).subject_id;
5503 END IF;
5504 --
5505 IF csi_ii_relationships_pvt.Is_link_type (p_instance_id => l_obj_id )
5506 THEN
5507 IF csi_ii_relationships_pvt.relationship_for_link
5508 ( p_instance_id => l_obj_id
5509 ,p_mode => 'UPDATE'
5510 ,p_relationship_id => p_relationship_tbl(l_count).relationship_id )
5511 THEN
5512 fnd_message.set_name('CSI','CSI_LINK_EXISTS');
5513 fnd_message.set_token('INSTANCE_ID',l_obj_id);
5514 fnd_msg_pub.add;
5515 RAISE fnd_api.g_exc_error;
5516 END IF;
5517 END IF;
5518 --
5519 IF csi_ii_relationships_pvt.Is_link_type (p_instance_id => l_sub_id )
5520 THEN
5521 IF csi_ii_relationships_pvt.relationship_for_link
5522 ( p_instance_id => l_sub_id
5523 ,p_mode => 'UPDATE'
5524 ,p_relationship_id => p_relationship_tbl(l_count).relationship_id )
5525 THEN
5526 fnd_message.set_name('CSI','CSI_LINK_EXISTS');
5527 fnd_message.set_token('INSTANCE_ID',l_sub_id);
5528 fnd_msg_pub.add;
5529 RAISE fnd_api.g_exc_error;
5530 END IF;
5531 END IF;
5532 -- End of att enhancements by sguthiva
5533 END IF;
5534 --
5535 IF (p_relationship_tbl(l_count).subject_id IS NOT NULL AND
5536 p_relationship_tbl(l_count).subject_id <> fnd_api.g_miss_num AND
5537 l_relship_csr.subject_id <> p_relationship_tbl(l_count).subject_id
5538 AND ( (p_relationship_tbl(l_count).relationship_type_code IS NOT NULL AND
5539 p_relationship_tbl(l_count).relationship_type_code <> fnd_api.g_miss_char AND
5540 p_relationship_tbl(l_count).relationship_type_code = 'COMPONENT-OF'
5541 )
5542 OR (p_relationship_tbl(l_count).relationship_type_code = fnd_api.g_miss_char AND
5543 l_relship_csr.relationship_type_code = 'COMPONENT-OF'
5544 )
5545 )
5546 )
5547 OR
5548 (l_relship_csr.relationship_type_code = 'COMPONENT-OF' AND
5549 p_relationship_tbl(l_count).ACTIVE_END_DATE <= SYSDATE AND
5550 p_relationship_tbl(l_count).ACTIVE_END_DATE <> fnd_api.g_miss_date AND
5551 p_relationship_tbl(l_count).ACTIVE_END_DATE IS NOT NULL
5552 )
5553 THEN
5554 l_object_id := NULL;
5555 l_found:=FALSE;
5556 csi_ii_relationships_pvt.Get_Top_Most_Parent
5557 ( p_subject_id => l_relship_csr.subject_id,
5558 p_rel_type_code => 'COMPONENT-OF',
5559 p_object_id => l_object_id
5560 );
5561 --
5562 IF l_object_id <> l_relship_csr.subject_id THEN
5563 BEGIN
5564 SELECT instance_usage_code
5565 INTO l_ins_usage_code
5566 FROM csi_item_instances
5567 WHERE instance_id=l_object_id;
5568 EXCEPTION
5569 WHEN NO_DATA_FOUND THEN
5570 NULL;
5571 END;
5572
5573 l_obv_number:=NULL;
5574 BEGIN
5575 SELECT object_version_number,
5576 config_inst_hdr_id, --added
5577 config_inst_item_id, --added
5578 config_inst_rev_num, --added
5579 location_type_code,
5580 inventory_item_id,
5581 last_vld_organization_id
5582 INTO l_obv_number,
5583 l_instance_rec.config_inst_hdr_id, --added
5584 l_instance_rec.config_inst_item_id, --added
5585 l_instance_rec.config_inst_rev_num, --added
5586 l_loc_type_code,
5587 l_item_id,
5588 l_vld_org
5589 FROM csi_item_instances
5590 WHERE instance_id = l_relship_csr.subject_id;
5591 --
5592 -- Bug 4232599. Serialized at SO issue items cannot have usage as IN_INVENTORY
5593 -- as taken from parent. Since relationship can be broken only thru' RMA,
5594 -- usage is set as RETURNED. Other INV/WIP txns will not let serialized at SO issue
5595 -- items to be transacted with the serial number. Hence other locations are not considered.
5596 Begin
5597 select serial_number_control_code
5598 into l_srl_ctl
5599 from MTL_SYSTEM_ITEMS_B
5600 where inventory_item_id = l_item_id
5601 and organization_id = l_vld_org;
5602 --
5603 IF l_srl_ctl = 6 THEN
5604 IF l_loc_type_code = 'INVENTORY' THEN
5605 l_ins_usage_code := 'RETURNED';
5606 END IF;
5607 END IF;
5608 Exception
5609 when no_data_found then
5610 null;
5611 End;
5612 EXCEPTION
5613 WHEN NO_DATA_FOUND THEN
5614 NULL;
5615 END;
5616 l_found:=TRUE;
5617 END IF;
5618 END IF;
5619 -- End Addition by sk for bug 2151750
5620 /* added this to aviod creating 'CONNECTED-TO' relationship in the reverse direction */
5621 IF p_relationship_tbl(l_count).relationship_type_code='CONNECTED-TO' THEN
5622 IF relationship_not_exists(p_relationship_tbl(l_count).subject_id,
5623 p_relationship_tbl(l_count).object_id,
5624 p_relationship_tbl(l_count).relationship_type_code,
5625 'UPDATE',
5626 p_relationship_tbl(l_count).relationship_id)
5627 THEN
5628 x_return_status:=fnd_api.g_ret_sts_success;
5629 ELSE
5630 x_return_status:=fnd_api.g_ret_sts_error;
5631 RAISE fnd_api.g_exc_error;
5632 END IF;
5633 END IF;
5634
5635 IF x_return_status = fnd_api.g_ret_sts_success THEN
5636 -- Update for the New subject only if the subject or relationship type is changing
5637 -- OR during Un-expiry
5638 IF (( (p_relationship_tbl(l_count).subject_id IS NOT NULL AND
5639 p_relationship_tbl(l_count).subject_id <> fnd_api.g_miss_num AND
5640 l_relship_csr.subject_id <> p_relationship_tbl(l_count).subject_id) OR
5641 ( p_relationship_tbl(l_count).relationship_type_code IS NOT NULL AND
5642 p_relationship_tbl(l_count).relationship_type_code <> fnd_api.g_miss_char AND
5643 p_relationship_tbl(l_count).relationship_type_code = 'COMPONENT-OF' AND
5644 l_relship_csr.relationship_type_code <> p_relationship_tbl(l_count).relationship_type_code) )
5645 OR
5646 ( (p_relationship_tbl(l_count).active_end_date IS NULL AND
5647 nvl(l_relship_csr.active_end_date,(sysdate+1)) <= SYSDATE) AND
5648 (p_relationship_tbl(l_count).subject_id = FND_API.G_MISS_NUM OR
5649 p_relationship_tbl(l_count).subject_id = l_relship_csr.subject_id) )
5650 )
5651 THEN
5652 csi_gen_utility_pvt.put_line('Calling Update_Instance..');
5653 update_instance
5654 ( p_api_version => p_api_version,
5655 p_commit => fnd_api.g_false,--p_commit,
5656 p_init_msg_list => p_init_msg_list,
5657 p_validation_level => p_validation_level,
5658 p_ii_relationship_rec => p_relationship_tbl(l_count),
5659 p_txn_rec => p_txn_rec,
5660 p_mode => 'UPDATE',
5661 x_return_status => x_return_status,
5662 x_msg_count => x_msg_count,
5663 x_msg_data => x_msg_data);
5664 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5665 l_msg_index := 1;
5666 l_msg_count := x_msg_count;
5667 WHILE l_msg_count > 0
5668 LOOP
5669 x_msg_data := FND_MSG_PUB.GET
5670 ( l_msg_index,
5671 FND_API.G_FALSE );
5672 csi_gen_utility_pvt.put_line( ' Error from CSI_II_RELATIONSHIPS_PVT.UPDATE_RELATIONSHIP');
5673 csi_gen_utility_pvt.put_line( ' Call to update_instance has errored ....');
5674 csi_gen_utility_pvt.put_line('MESSAGE DATA = '||x_msg_data);
5675 l_msg_index := l_msg_index + 1;
5676 l_msg_count := l_msg_count - 1;
5677 END LOOP;
5678 RAISE FND_API.G_EXC_ERROR;
5679 END IF;
5680 END IF;
5681 --
5682 csi_ii_relationships_pkg.update_row(
5683 p_relationship_id => p_relationship_tbl(l_count).relationship_id,
5684 p_relationship_type_code => p_relationship_tbl(l_count).relationship_type_code,
5685 p_object_id => p_relationship_tbl(l_count).object_id,
5686 p_subject_id => p_relationship_tbl(l_count).subject_id,
5687 p_position_reference => p_relationship_tbl(l_count).position_reference,
5688 p_active_start_date => fnd_api.g_miss_date, -- p_relationship_tbl(l_count).active_start_date,
5689 p_active_end_date => p_relationship_tbl(l_count).active_end_date,
5690 p_display_order => p_relationship_tbl(l_count).display_order,
5691 p_mandatory_flag => p_relationship_tbl(l_count).mandatory_flag,
5692 p_context => p_relationship_tbl(l_count).context,
5693 p_attribute1 => p_relationship_tbl(l_count).attribute1,
5694 p_attribute2 => p_relationship_tbl(l_count).attribute2,
5695 p_attribute3 => p_relationship_tbl(l_count).attribute3,
5696 p_attribute4 => p_relationship_tbl(l_count).attribute4,
5697 p_attribute5 => p_relationship_tbl(l_count).attribute5,
5698 p_attribute6 => p_relationship_tbl(l_count).attribute6,
5699 p_attribute7 => p_relationship_tbl(l_count).attribute7,
5700 p_attribute8 => p_relationship_tbl(l_count).attribute8,
5701 p_attribute9 => p_relationship_tbl(l_count).attribute9,
5702 p_attribute10 => p_relationship_tbl(l_count).attribute10,
5703 p_attribute11 => p_relationship_tbl(l_count).attribute11,
5704 p_attribute12 => p_relationship_tbl(l_count).attribute12,
5705 p_attribute13 => p_relationship_tbl(l_count).attribute13,
5706 p_attribute14 => p_relationship_tbl(l_count).attribute14,
5707 p_attribute15 => p_relationship_tbl(l_count).attribute15,
5708 p_created_by => fnd_api.g_miss_num,
5709 p_creation_date => fnd_api.g_miss_date,
5710 p_last_updated_by => fnd_global.user_id,
5711 p_last_update_date => SYSDATE,
5712 p_last_update_login => fnd_global.conc_login_id,
5713 p_object_version_number => p_relationship_tbl(l_count).object_version_number);
5714 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5715 RAISE fnd_api.g_exc_error;
5716 END IF;
5717
5718 /*
5719 ELSE
5720 csi_ii_relationships_pvt.expire_relationship
5721 (p_api_version => p_api_version,
5722 p_commit => fnd_api.g_false,
5723 p_init_msg_list => p_init_msg_list,
5724 p_validation_level => p_validation_level,
5725 p_relationship_rec => p_relationship_tbl(l_count),
5726 p_txn_rec => p_txn_rec,
5727 x_instance_id_lst => l_instance_id_lst,
5728 x_return_status => x_return_status,
5729 x_msg_count => x_msg_count,
5730 x_msg_data => x_msg_data);
5731
5732
5733 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5734 RAISE fnd_api.g_exc_error;
5735 END IF;
5736
5737 l_relationship_tbl(1).relationship_type_code := p_relationship_tbl(l_count).relationship_type_code; --'CONNECTED-TO' ;
5738 l_relationship_tbl(1).object_id := p_relationship_tbl(l_count).object_id;
5739 l_relationship_tbl(1).subject_id := p_relationship_tbl(l_count).subject_id ;
5740 l_relationship_tbl(1).subject_has_child := 'Y' ;
5741 l_relationship_tbl(1).active_start_date := SYSDATE ;
5742 l_relationship_tbl(1).object_version_number:=1;
5743
5744 csi_ii_relationships_pvt.create_relationship(
5745 p_api_version => p_api_version,
5746 p_commit => fnd_api.g_false,
5747 p_init_msg_list => p_init_msg_list,
5748 p_validation_level => p_validation_level,
5749 p_relationship_tbl => l_relationship_tbl,
5750 p_txn_rec => p_txn_rec,
5751 x_return_status => x_return_status,
5752 x_msg_count => x_msg_count,
5753 x_msg_data => x_msg_data);
5754
5755 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5756 RAISE fnd_api.g_exc_error;
5757 END IF;
5758 -- END IF;
5759 */
5760 -- END IF;
5761 END IF;
5762
5763 /* IF x_return_status <> fnd_api.g_ret_sts_success THEN
5764 RAISE fnd_api.g_exc_error;
5765 END IF;*/
5766 csi_transactions_pvt.create_transaction
5767 (
5768 p_api_version => p_api_version
5769 ,p_commit => p_commit
5770 ,p_init_msg_list => p_init_msg_list
5771 ,p_validation_level => p_validation_level
5772 ,p_success_if_exists_flag => 'Y'
5773 ,p_transaction_rec => p_txn_rec
5774 ,x_return_status => x_return_status
5775 ,x_msg_count => x_msg_count
5776 ,x_msg_data => x_msg_data
5777 );
5778
5779 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
5780 fnd_message.set_name('CSI','CSI_FAILED_TO_VALIDATE_TXN');
5781 fnd_message.set_token('transaction_id',p_txn_rec.transaction_id );
5782 fnd_msg_pub.add;
5783 RAISE fnd_api.g_exc_error;
5784 ROLLBACK TO create_relationship_pvt;
5785 END IF;
5786 --
5787 l_instance_rec:=l_temp_ins_rec;
5788 l_instance_rec.instance_id:= l_relship_csr.subject_id;
5789 l_instance_rec.instance_usage_code :=l_ins_usage_code;
5790 l_instance_rec.object_version_number :=l_obv_number;
5791 -- TSO with equipment changes.
5792 -- Nullify the keys when the relationship is broken
5793 l_instance_rec.config_inst_hdr_id := NULL;
5794 l_instance_rec.config_inst_rev_num := NULL;
5795 l_instance_rec.config_inst_item_id := NULL;
5796 l_instance_rec.config_valid_status := NULL;
5797 --
5798 IF l_instance_rec.instance_id IS NOT NULL AND
5799 l_instance_rec.object_version_number IS NOT NULL AND
5800 l_found
5801 THEN
5802 IF l_relship_csr.subject_id = l_instance_rec.instance_id AND
5803 nvl(p_replace_flag,fnd_api.g_false)<> fnd_api.g_true
5804 THEN
5805 csi_gen_utility_pvt.put_line('Calling update_item_instance..');
5806 csi_gen_utility_pvt.put_line('Parameter p_called_from_rel set to true..');
5807 csi_item_instance_pvt.update_item_instance
5808 (p_api_version => p_api_version
5809 ,p_commit => p_commit
5810 ,p_init_msg_list => p_init_msg_list
5811 ,p_validation_level => p_validation_level
5812 ,p_instance_rec => l_instance_rec
5813 ,p_txn_rec => p_txn_rec
5814 ,x_instance_id_lst => l_instance_id_lst
5815 ,x_return_status => x_return_status
5816 ,x_msg_count => x_msg_count
5817 ,x_msg_data => x_msg_data
5818 ,p_item_attribute_tbl => l_item_attribute_tbl
5819 ,p_location_tbl => l_location_tbl
5820 ,p_generic_id_tbl => l_generic_id_tbl
5821 ,p_lookup_tbl => l_lookup_tbl
5822 ,p_ins_count_rec => l_ins_count_rec
5823 ,p_called_from_rel => fnd_api.g_true
5824 ,p_oks_txn_inst_tbl => px_oks_txn_inst_tbl
5825 ,p_child_inst_tbl => px_child_inst_tbl
5826 );
5827 END IF;
5828
5829 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
5830 fnd_message.set_name('CSI','CSI_FAILED_TO_VALIDATE_INS');
5831 fnd_message.set_token('instance_id',l_instance_rec.instance_id);
5832 fnd_msg_pub.add;
5833 RAISE fnd_api.g_exc_error;
5834 END IF;
5835 END IF;
5836 --
5837 l_old_relship_rec.relationship_id := l_relship_csr.relationship_id;
5838 l_old_relship_rec.relationship_type_code := l_relship_csr.relationship_id;
5839 l_old_relship_rec.object_id := l_relship_csr.object_id;
5840 l_old_relship_rec.subject_id := l_relship_csr.subject_id;
5841 l_old_relship_rec.position_reference := l_relship_csr.position_reference;
5842 l_old_relship_rec.active_start_date := l_relship_csr.active_start_date;
5843 l_old_relship_rec.active_end_date := l_relship_csr.active_end_date;
5844 l_old_relship_rec.display_order := l_relship_csr.display_order;
5845 l_old_relship_rec.mandatory_flag := l_relship_csr.mandatory_flag;
5846 l_old_relship_rec.context := l_relship_csr.context;
5847 l_old_relship_rec.attribute1 := l_relship_csr.attribute1;
5848 l_old_relship_rec.attribute2 := l_relship_csr.attribute2;
5849 l_old_relship_rec.attribute3 := l_relship_csr.attribute3;
5850 l_old_relship_rec.attribute4 := l_relship_csr.attribute4;
5851 l_old_relship_rec.attribute5 := l_relship_csr.attribute5;
5852 l_old_relship_rec.attribute6 := l_relship_csr.attribute6;
5853 l_old_relship_rec.attribute7 := l_relship_csr.attribute7;
5854 l_old_relship_rec.attribute8 := l_relship_csr.attribute8;
5855 l_old_relship_rec.attribute9 := l_relship_csr.attribute9;
5856 l_old_relship_rec.attribute10 := l_relship_csr.attribute10;
5857 l_old_relship_rec.attribute11 := l_relship_csr.attribute11;
5858 l_old_relship_rec.attribute12 := l_relship_csr.attribute12;
5859 l_old_relship_rec.attribute13 := l_relship_csr.attribute13;
5860 l_old_relship_rec.attribute14 := l_relship_csr.attribute14;
5861 l_old_relship_rec.attribute15 := l_relship_csr.attribute15;
5862 l_old_relship_rec.object_version_number := l_relship_csr.object_version_number;
5863
5864
5865 validate_history(p_old_relship_rec => l_old_relship_rec,
5866 p_new_relship_rec => l_new_relship_rec,
5867 p_transaction_id => p_txn_rec.transaction_id,
5868 p_flag => NULL,
5869 p_sysdate => NULL,
5870 x_return_status => x_return_status,
5871 x_msg_count => x_msg_count,
5872 x_msg_data => x_msg_data
5873 );
5874
5875 -- Start of cascade ownership changes bug 2972082
5876 -- Get the parent instance owner party and owner account
5877
5878 IF nvl(p_relationship_tbl(l_count).cascade_ownership_flag,'N')='Y'
5879 THEN
5880 csi_gen_utility_pvt.put_line('Cascade_ownership_flag : '||p_relationship_tbl(l_count).cascade_ownership_flag);
5881 l_inst_rec:=l_cascade_instance_rec;
5882 l_ext_attrib_values_tbl.delete;
5883 l_party_tbl.delete;
5884 l_account_tbl.delete;
5885 l_pricing_attrib_tbl.delete;
5886 l_org_assignments_tbl.delete;
5887 l_inst_id_lst.delete;
5888
5889 IF p_relationship_tbl(l_count).object_id IS NOT NULL AND
5890 p_relationship_tbl(l_count).object_id <> fnd_api.g_miss_num
5891 THEN
5892 l_inst_rec.instance_id:=p_relationship_tbl(l_count).object_id;
5893 ELSE
5894 BEGIN
5895 SELECT object_id
5896 INTO l_inst_rec.instance_id
5897 FROM csi_ii_relationships
5898 WHERE relationship_id=p_relationship_tbl(l_count).relationship_id;
5899 EXCEPTION
5900 WHEN OTHERS
5901 THEN
5902 csi_gen_utility_pvt.put_line( 'Error from update relationship API.');
5903 csi_gen_utility_pvt.put_line( 'Object_id not found in csi_ii_relationships to cascade ownership');
5904 RAISE fnd_api.g_exc_error;
5905 END;
5906 END IF;
5907
5908 BEGIN
5909 SELECT object_version_number,
5910 'Y'
5911 INTO l_inst_rec.object_version_number,
5912 l_inst_rec.cascade_ownership_flag
5913 FROM csi_item_instances
5914 WHERE instance_id=l_inst_rec.instance_id
5915 AND (active_end_date IS NULL OR active_end_date > sysdate);
5916 EXCEPTION
5917 WHEN OTHERS
5918 THEN
5919 csi_gen_utility_pvt.put_line( 'Error from update relationship API.');
5920 csi_gen_utility_pvt.put_line( 'The object_id, which you are trying to cascade its ownership, is not found or expired in csi_item_instances table. ');
5921 RAISE fnd_api.g_exc_error;
5922 END;
5923
5924 csi_item_instance_pub.update_item_instance
5925 ( p_api_version => p_api_version
5926 ,p_commit => p_commit
5927 ,p_init_msg_list => p_init_msg_list
5928 ,p_validation_level => p_validation_level
5929 ,p_instance_rec => l_inst_rec
5930 ,p_ext_attrib_values_tbl => l_ext_attrib_values_tbl
5931 ,p_party_tbl => l_party_tbl
5932 ,p_account_tbl => l_account_tbl
5933 ,p_pricing_attrib_tbl => l_pricing_attrib_tbl
5934 ,p_org_assignments_tbl => l_org_assignments_tbl
5935 ,p_asset_assignment_tbl => l_asset_assignment_tbl
5936 ,p_txn_rec => p_txn_rec
5937 ,x_instance_id_lst => l_inst_id_lst
5938 ,x_return_status => x_return_status
5939 ,x_msg_count => x_msg_count
5940 ,x_msg_data => x_msg_data
5941 );
5942
5943 IF NOT(x_return_status = fnd_api.g_ret_sts_success)
5944 THEN
5945 csi_gen_utility_pvt.put_line( 'Error from update relationship API.');
5946 csi_gen_utility_pvt.put_line( 'Call to update_item_instance API for cascade ownership has errored');
5947 fnd_message.set_name('CSI','CSI_FAILED_TO_VALIDATE_INS');
5948 fnd_message.set_token('instance_id',l_instance_rec.instance_id);
5949 fnd_msg_pub.add;
5950 RAISE fnd_api.g_exc_error;
5951 END IF;
5952 END IF;
5953
5954 -- End of cascade ownership changes bug 2972082
5955
5956
5957 END LOOP;
5958 --
5959 -- END of API body.
5960 --
5961
5962 IF x_return_status <> fnd_api.g_ret_sts_success THEN
5963 RAISE fnd_api.g_exc_error;
5964 END IF;
5965
5966 -- standard check for p_commit
5967 IF fnd_api.to_boolean( p_commit )
5968 THEN
5969 COMMIT WORK;
5970 END IF;
5971
5972
5973
5974
5975 -- standard call to get message count and if count is 1, get message info.
5976 fnd_msg_pub.count_AND_get
5977 ( p_count => x_msg_count,
5978 p_data => x_msg_data
5979 );
5980
5981 EXCEPTION
5982 WHEN fnd_api.g_exc_error THEN
5983 ROLLBACK TO update_relationship_pvt;
5984 x_return_status := fnd_api.g_ret_sts_error ;
5985 fnd_msg_pub.count_AND_get
5986 (p_count => x_msg_count ,
5987 p_data => x_msg_data
5988 );
5989
5990 WHEN fnd_api.g_exc_unexpected_error THEN
5991 ROLLBACK TO update_relationship_pvt;
5992 x_return_status := fnd_api.g_ret_sts_unexp_error ;
5993 fnd_msg_pub.count_AND_get
5994 (p_count => x_msg_count ,
5995 p_data => x_msg_data
5996 );
5997
5998 WHEN OTHERS THEN
5999 ROLLBACK TO update_relationship_pvt;
6000 x_return_status := fnd_api.g_ret_sts_unexp_error ;
6001 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
6002 fnd_msg_pub.add_exc_msg(g_pkg_name ,l_api_name);
6003 END IF;
6004 fnd_msg_pub.count_AND_get
6005 (p_count => x_msg_count ,
6006 p_data => x_msg_data
6007 );
6008
6009 END update_relationship;
6010
6011
6012 PROCEDURE expire_relationship
6013 (
6014 p_api_version IN NUMBER,
6015 p_commit IN VARCHAR2,
6016 p_init_msg_list IN VARCHAR2,
6017 p_validation_level IN NUMBER,
6018 p_relationship_rec IN csi_datastructures_pub.ii_relationship_rec,
6019 p_txn_rec IN OUT NOCOPY csi_datastructures_pub.transaction_rec,
6020 x_instance_id_lst OUT NOCOPY csi_datastructures_pub.id_tbl,
6021 x_return_status OUT NOCOPY VARCHAR2,
6022 x_msg_count OUT NOCOPY NUMBER,
6023 x_msg_data OUT NOCOPY VARCHAR2
6024 ) IS
6025
6026 CURSOR relship_csr (relship_id IN NUMBER) IS
6027 SELECT relationship_id,
6028 relationship_type_code,
6029 object_id,
6030 subject_id,
6031 position_reference,
6032 active_start_date,
6033 active_end_date,
6034 display_order,
6035 mandatory_flag,
6036 context,
6037 attribute1,
6038 attribute2,
6039 attribute3,
6040 attribute4,
6041 attribute5,
6042 attribute6,
6043 attribute7,
6044 attribute8,
6045 attribute9,
6046 attribute10,
6047 attribute11,
6048 attribute12,
6049 attribute13,
6050 attribute14,
6051 attribute15,
6052 object_version_number
6053 FROM csi_ii_relationships
6054 WHERE relationship_id=relship_id
6055 FOR UPDATE OF object_version_number ;
6056
6057 l_relship_csr relship_csr%ROWTYPE;
6058 l_api_name CONSTANT VARCHAR2(30) := 'expire_relationship';
6059 l_api_version CONSTANT NUMBER := 1.0;
6060 l_debug_level NUMBER;
6061 l_old_relship_rec csi_datastructures_pub.ii_relationship_rec;
6062 l_new_relship_rec csi_datastructures_pub.ii_relationship_rec;
6063 l_ii_relationship_tbl csi_datastructures_pub.ii_relationship_tbl;
6064 l_sysdate CONSTANT DATE :=SYSDATE;
6065 l_instance_rec csi_datastructures_pub.instance_rec;
6066 l_temp_ins_rec csi_datastructures_pub.instance_rec;
6067 l_object_id NUMBER;
6068 l_obv_number NUMBER;
6069 l_ins_usage_code VARCHAR2(30);
6070 l_instance_id_lst csi_datastructures_pub.id_tbl;
6071 l_item_attribute_tbl csi_item_instance_pvt.item_attribute_tbl;
6072 l_location_tbl csi_item_instance_pvt.location_tbl;
6073 l_generic_id_tbl csi_item_instance_pvt.generic_id_tbl;
6074 l_lookup_tbl csi_item_instance_pvt.lookup_tbl;
6075 l_ins_count_rec csi_item_instance_pvt.ins_count_rec;
6076 l_found BOOLEAN;
6077 l_item_id NUMBER;
6078 l_vld_org NUMBER;
6079 l_srl_ctl NUMBER;
6080 l_loc_type_code VARCHAR2(30);
6081 px_oks_txn_inst_tbl oks_ibint_pub.txn_instance_tbl;
6082 px_child_inst_tbl csi_item_instance_grp.child_inst_tbl;
6083 BEGIN
6084 -- standard start of api savepoint
6085 SAVEPOINT expire_relationship_pvt;
6086
6087 -- standard call to check for call compatibility.
6088 IF NOT fnd_api.compatible_api_call ( l_api_version,
6089 p_api_version,
6090 l_api_name,
6091 g_pkg_name)
6092 THEN
6093 RAISE fnd_api.g_exc_unexpected_error;
6094 END IF;
6095
6096 -- initialize message list if p_init_msg_list is set to true.
6097 IF fnd_api.to_boolean( p_init_msg_list )
6098 THEN
6099 fnd_msg_pub.initialize;
6100 END IF;
6101
6102 -- initialize api return status to success
6103 x_return_status := fnd_api.g_ret_sts_success;
6104
6105 l_debug_level:=fnd_profile.value('CSI_DEBUG_LEVEL');
6106 IF (l_debug_level > 0) THEN
6107 CSI_gen_utility_pvt.put_line( 'expire_relationship');
6108 END IF;
6109
6110 IF (l_debug_level > 1) THEN
6111
6112 CSI_gen_utility_pvt.put_line(
6113 p_api_version ||'-'||
6114 p_commit ||'-'||
6115 p_init_msg_list ||'-'||
6116 p_validation_level
6117 );
6118
6119 -- dump the relationship query records
6120 csi_gen_utility_pvt.dump_txn_rec(p_txn_rec);
6121 csi_gen_utility_pvt.dump_rel_rec(p_relationship_rec);
6122
6123 END IF;
6124
6125 --
6126 -- API BODY
6127 --
6128 OPEN relship_csr (p_relationship_rec.relationship_id);
6129 FETCH relship_csr INTO l_relship_csr;
6130 IF ( (l_relship_csr.object_version_number<>p_relationship_rec.object_version_number)
6131 AND (p_relationship_rec.object_version_number <> fnd_api.g_miss_num) ) THEN
6132 fnd_message.set_name('CSI', 'CSI_RECORD_CHANGED');
6133 fnd_msg_pub.add;
6134 RAISE fnd_api.g_exc_error;
6135 END IF;
6136 CLOSE relship_csr;
6137
6138 l_ii_relationship_tbl(1) := p_relationship_rec;
6139 validate_ii_relationships(
6140 p_init_msg_list => fnd_api.g_false,
6141 p_validation_level => p_validation_level,
6142 p_validation_mode => 'EXPIRE',
6143 p_ii_relationship_tbl => l_ii_relationship_tbl,
6144 x_return_status => x_return_status,
6145 x_msg_count => x_msg_count,
6146 x_msg_data => x_msg_data);
6147
6148 IF x_return_status<>fnd_api.g_ret_sts_success THEN
6149 RAISE fnd_api.g_exc_error;
6150 END IF;
6151 IF l_relship_csr.relationship_type_code = 'COMPONENT-OF'
6152 THEN
6153 BEGIN
6154 l_object_id := NULL;
6155 l_found:=FALSE;
6156 csi_ii_relationships_pvt.Get_Top_Most_Parent
6157 ( p_subject_id => l_relship_csr.subject_id,
6158 p_rel_type_code => 'COMPONENT-OF',
6159 p_object_id => l_object_id
6160 );
6161 --
6162 IF l_object_id <> l_relship_csr.subject_id THEN
6163 BEGIN
6164 SELECT instance_usage_code
6165 INTO l_ins_usage_code
6166 FROM csi_item_instances
6167 WHERE instance_id=l_object_id;
6168 EXCEPTION
6169 WHEN NO_DATA_FOUND THEN
6170 NULL;
6171 END;
6172 l_obv_number:=NULL;
6173 BEGIN
6174 SELECT object_version_number,
6175 config_inst_hdr_id, --added
6176 config_inst_item_id, --added
6177 config_inst_rev_num,
6178 inventory_item_id,
6179 last_vld_organization_id,
6180 location_type_code
6181 INTO l_obv_number,
6182 l_instance_rec.config_inst_hdr_id, --added
6183 l_instance_rec.config_inst_item_id, --added
6184 l_instance_rec.config_inst_rev_num,
6185 l_item_id,
6186 l_vld_org,
6187 l_loc_type_code
6188 FROM csi_item_instances
6189 WHERE instance_id = l_relship_csr.subject_id;
6190 --
6191 -- Bug 4232599. Serialized at SO issue items cannot have usage as IN_INVENTORY
6192 -- as taken from parent. Since relationship can be broken only thru' RMA,
6193 -- usage is set as RETURNED. Other INV/WIP txns will not let serialized at SO issue
6194 -- items to be transacted with the serial number. Hence other locations are not considered.
6195 Begin
6196 select serial_number_control_code
6197 into l_srl_ctl
6198 from MTL_SYSTEM_ITEMS_B
6199 where inventory_item_id = l_item_id
6200 and organization_id = l_vld_org;
6201 --
6202 IF l_srl_ctl = 6 THEN
6203 IF l_loc_type_code = 'INVENTORY' THEN
6204 l_ins_usage_code := 'RETURNED';
6205 END IF;
6206 END IF;
6207 Exception
6208 when no_data_found then
6209 null;
6210 End;
6211 EXCEPTION
6212 WHEN NO_DATA_FOUND THEN
6213 NULL;
6214 END;
6215 l_found:=TRUE;
6216 END IF;
6217 END;
6218 END IF;
6219
6220
6221 --Added for MACD lock functionality
6222 IF l_relship_csr.object_id IS NOT NULL AND
6223 l_relship_csr.object_id <> fnd_api.g_miss_num
6224 THEN
6225 IF csi_item_instance_pvt.check_item_instance_lock
6226 ( p_instance_id => l_relship_csr.object_id)
6227 THEN
6228 --Added the below if condition for bug 5217556--
6229 IF p_txn_rec.transaction_type_id NOT IN (53,54)
6230 THEN
6231 FND_MESSAGE.SET_NAME('CSI','CSI_LOCKED_INSTANCE');
6232 FND_MESSAGE.SET_TOKEN('INSTANCE_ID',l_relship_csr.object_id);
6233 FND_MSG_PUB.ADD;
6234 RAISE FND_API.G_EXC_ERROR;
6235 END IF;
6236 END IF;
6237 END IF;
6238
6239 IF l_relship_csr.subject_id IS NOT NULL AND
6240 l_relship_csr.subject_id <> fnd_api.g_miss_num
6241 THEN
6242 IF csi_item_instance_pvt.check_item_instance_lock
6243 ( p_instance_id => l_relship_csr.subject_id)
6244 THEN
6245 FND_MESSAGE.SET_NAME('CSI','CSI_LOCKED_INSTANCE');
6246 FND_MESSAGE.SET_TOKEN('INSTANCE_ID',l_relship_csr.subject_id);
6247 FND_MSG_PUB.ADD;
6248 RAISE FND_API.G_EXC_ERROR;
6249 END IF;
6250 END IF;
6251 -- End addition for MACD lock functionality
6252
6253
6254
6255 csi_ii_relationships_pkg.update_row(
6256 p_relationship_id => p_relationship_rec.relationship_id,
6257 p_relationship_type_code => fnd_api.g_miss_char,
6258 p_object_id => fnd_api.g_miss_num,
6259 p_subject_id => fnd_api.g_miss_num,
6260 p_position_reference => fnd_api.g_miss_char,
6261 p_active_start_date => fnd_api.g_miss_date,
6262 p_active_end_date => l_sysdate,
6263 p_display_order => fnd_api.g_miss_num,
6264 p_mandatory_flag => fnd_api.g_miss_char,
6265 p_context => fnd_api.g_miss_char,
6266 p_attribute1 => fnd_api.g_miss_char,
6267 p_attribute2 => fnd_api.g_miss_char,
6268 p_attribute3 => fnd_api.g_miss_char,
6269 p_attribute4 => fnd_api.g_miss_char,
6270 p_attribute5 => fnd_api.g_miss_char,
6271 p_attribute6 => fnd_api.g_miss_char,
6272 p_attribute7 => fnd_api.g_miss_char,
6273 p_attribute8 => fnd_api.g_miss_char,
6274 p_attribute9 => fnd_api.g_miss_char,
6275 p_attribute10 => fnd_api.g_miss_char,
6276 p_attribute11 => fnd_api.g_miss_char,
6277 p_attribute12 => fnd_api.g_miss_char,
6278 p_attribute13 => fnd_api.g_miss_char,
6279 p_attribute14 => fnd_api.g_miss_char,
6280 p_attribute15 => fnd_api.g_miss_char,
6281 p_created_by => fnd_api.g_miss_num,
6282 p_creation_date => fnd_api.g_miss_date,
6283 p_last_updated_by => fnd_global.user_id,
6284 p_last_update_date => l_sysdate,
6285 p_last_update_login => fnd_global.conc_login_id,
6286 p_object_version_number => fnd_api.g_miss_num);
6287
6288
6289 csi_transactions_pvt.create_transaction
6290 (
6291 p_api_version => p_api_version
6292 ,p_commit => p_commit
6293 ,p_init_msg_list => p_init_msg_list
6294 ,p_validation_level => p_validation_level
6295 ,p_success_if_exists_flag => 'Y'
6296 ,p_transaction_rec => p_txn_rec
6297 ,x_return_status => x_return_status
6298 ,x_msg_count => x_msg_count
6299 ,x_msg_data => x_msg_data
6300 );
6301
6302 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6303 fnd_message.set_name('CSI','CSI_FAILED_TO_VALIDATE_TXN');
6304 fnd_message.set_token('transaction_id',p_txn_rec.transaction_id );
6305 fnd_msg_pub.add;
6306 RAISE fnd_api.g_exc_error;
6307 ROLLBACK TO create_relationship_pvt;
6308 END IF;
6309
6310 l_instance_rec:=l_temp_ins_rec;
6311 l_instance_rec.instance_id:= l_relship_csr.subject_id;
6312 l_instance_rec.instance_usage_code :=l_ins_usage_code;
6313 l_instance_rec.object_version_number :=l_obv_number;
6314 -- TSO with equipment changes.
6315 -- Nullify the keys when the relationship is broken
6316 l_instance_rec.config_inst_hdr_id := null;
6317 l_instance_rec.config_inst_rev_num := null;
6318 l_instance_rec.config_inst_item_id := null;
6319 l_instance_rec.config_valid_status := null;
6320 IF l_instance_rec.instance_id IS NOT NULL AND
6321 l_instance_rec.object_version_number IS NOT NULL AND
6322 l_found
6323 THEN
6324 csi_gen_utility_pvt.put_line('Calling Update II from Exp Rel...');
6325 csi_item_instance_pvt.update_item_instance
6326 ( p_api_version => p_api_version
6327 ,p_commit => p_commit
6328 ,p_init_msg_list => p_init_msg_list
6329 ,p_validation_level => p_validation_level
6330 ,p_instance_rec => l_instance_rec
6331 ,p_txn_rec => p_txn_rec
6332 ,x_instance_id_lst => l_instance_id_lst
6333 ,x_return_status => x_return_status
6334 ,x_msg_count => x_msg_count
6335 ,x_msg_data => x_msg_data
6336 ,p_item_attribute_tbl => l_item_attribute_tbl
6337 ,p_location_tbl => l_location_tbl
6338 ,p_generic_id_tbl => l_generic_id_tbl
6339 ,p_lookup_tbl => l_lookup_tbl
6340 ,p_ins_count_rec => l_ins_count_rec
6341 ,p_called_from_rel => fnd_api.g_true
6342 ,p_oks_txn_inst_tbl => px_oks_txn_inst_tbl
6343 ,p_child_inst_tbl => px_child_inst_tbl
6344 );
6345
6346
6347 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
6348 fnd_message.set_name('CSI','CSI_FAILED_TO_VALIDATE_INS');
6349 fnd_message.set_token('instance_id',l_instance_rec.instance_id);
6350 fnd_msg_pub.add;
6351 RAISE fnd_api.g_exc_error;
6352 END IF;
6353 END IF;
6354
6355 -- End Addition by sk for bug 2151750
6356 l_old_relship_rec.relationship_id := l_relship_csr.relationship_id;
6357 l_old_relship_rec.relationship_type_code := l_relship_csr.relationship_id;
6358 l_old_relship_rec.object_id := l_relship_csr.object_id;
6359 l_old_relship_rec.subject_id := l_relship_csr.subject_id;
6360 l_old_relship_rec.position_reference := l_relship_csr.position_reference;
6361 l_old_relship_rec.active_start_date := l_relship_csr.active_start_date;
6362 l_old_relship_rec.active_end_date := l_relship_csr.active_end_date;
6363 l_old_relship_rec.display_order := l_relship_csr.display_order;
6364 l_old_relship_rec.mandatory_flag := l_relship_csr.mandatory_flag;
6365 l_old_relship_rec.context := l_relship_csr.context;
6366 l_old_relship_rec.attribute1 := l_relship_csr.attribute1;
6367 l_old_relship_rec.attribute2 := l_relship_csr.attribute2;
6368 l_old_relship_rec.attribute3 := l_relship_csr.attribute3;
6369 l_old_relship_rec.attribute4 := l_relship_csr.attribute4;
6370 l_old_relship_rec.attribute5 := l_relship_csr.attribute5;
6371 l_old_relship_rec.attribute6 := l_relship_csr.attribute6;
6372 l_old_relship_rec.attribute7 := l_relship_csr.attribute7;
6373 l_old_relship_rec.attribute8 := l_relship_csr.attribute8;
6374 l_old_relship_rec.attribute9 := l_relship_csr.attribute9;
6375 l_old_relship_rec.attribute10 := l_relship_csr.attribute10;
6376 l_old_relship_rec.attribute11 := l_relship_csr.attribute11;
6377 l_old_relship_rec.attribute12 := l_relship_csr.attribute12;
6378 l_old_relship_rec.attribute13 := l_relship_csr.attribute13;
6379 l_old_relship_rec.attribute14 := l_relship_csr.attribute14;
6380 l_old_relship_rec.attribute15 := l_relship_csr.attribute15;
6381 l_old_relship_rec.object_version_number := l_relship_csr.object_version_number;
6382
6383
6384 validate_history(p_old_relship_rec => l_old_relship_rec,
6385 p_new_relship_rec => l_new_relship_rec,
6386 p_transaction_id => p_txn_rec.transaction_id,
6387 p_flag => 'EXPIRE',
6388 p_sysdate => l_sysdate,
6389 x_return_status => x_return_status,
6390 x_msg_count => x_msg_count,
6391 x_msg_data => x_msg_data
6392 );
6393
6394
6395
6396 IF x_return_status <> fnd_api.g_ret_sts_success THEN
6397 RAISE fnd_api.g_exc_error;
6398 END IF;
6399
6400 -- standard check for p_commit
6401 IF fnd_api.to_boolean( p_commit )
6402 THEN
6403 COMMIT WORK;
6404 END IF;
6405
6406 -- standard call to get message count and if count is 1, get message info.
6407 fnd_msg_pub.count_AND_get
6408 ( p_count => x_msg_count,
6409 p_data => x_msg_data
6410 );
6411
6412 EXCEPTION
6413 WHEN fnd_api.g_exc_error THEN
6414 ROLLBACK TO expire_relationship_pvt;
6415 x_return_status := fnd_api.g_ret_sts_error ;
6416 fnd_msg_pub.count_AND_get
6417 (p_count => x_msg_count ,
6418 p_data => x_msg_data
6419 );
6420
6421 WHEN fnd_api.g_exc_unexpected_error THEN
6422 ROLLBACK TO expire_relationship_pvt;
6423 x_return_status := fnd_api.g_ret_sts_unexp_error ;
6424 fnd_msg_pub.count_AND_get
6425 (p_count => x_msg_count ,
6426 p_data => x_msg_data
6427 );
6428
6429 WHEN OTHERS THEN
6430 ROLLBACK TO expire_relationship_pvt;
6431 x_return_status := fnd_api.g_ret_sts_unexp_error ;
6432 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
6433 fnd_msg_pub.add_exc_msg(g_pkg_name ,l_api_name);
6434 END IF;
6435 fnd_msg_pub.count_AND_get
6436 (p_count => x_msg_count ,
6437 p_data => x_msg_data
6438 );
6439 END expire_relationship;
6440
6441
6442 PROCEDURE validate_relationship_id (
6443 p_init_msg_list IN VARCHAR2,
6444 p_validation_mode IN VARCHAR2,
6445 p_relationship_id IN NUMBER,
6446 x_return_status OUT NOCOPY VARCHAR2,
6447 x_msg_count OUT NOCOPY NUMBER,
6448 x_msg_data OUT NOCOPY VARCHAR2
6449 )
6450 IS
6451 l_dummy VARCHAR2(1);
6452 BEGIN
6453
6454 -- initialize message list IF p_init_msg_list IS set TO true.
6455 IF fnd_api.to_boolean( p_init_msg_list )
6456 THEN
6457 fnd_msg_pub.initialize;
6458 END IF;
6459
6460
6461 -- initialize api return status to success
6462 x_return_status := fnd_api.g_ret_sts_success;
6463 IF(p_validation_mode ='CREATE') THEN
6464 -- validate not null column
6465 IF ( (p_relationship_id IS NOT NULL) AND (p_relationship_id <> fnd_api.g_miss_num) )
6466 /* if p_relationship_id is not null check if it already exists if found return success else error*/
6467 THEN
6468 BEGIN
6469 SELECT 'x'
6470 INTO l_dummy
6471 FROM csi_ii_relationships
6472 WHERE relationship_id=p_relationship_id
6473 AND ROWNUM=1;
6474 fnd_message.set_name('CSI','CSI_INVALID_RELSHIPID');
6475 fnd_message.set_token('relationship_id',p_relationship_id);
6476 fnd_msg_pub.add;
6477 x_return_status := fnd_api.g_ret_sts_error;
6478 EXCEPTION
6479 WHEN NO_DATA_FOUND THEN
6480 x_return_status := fnd_api.g_ret_sts_success;
6481
6482 END;
6483
6484 ELSE
6485 /* if p_relationship_id is null then return success */
6486 x_return_status := fnd_api.g_ret_sts_success;
6487 END IF;
6488 ELSIF ( (p_validation_mode = 'UPDATE') OR (p_validation_mode = 'EXPIRE') ) THEN
6489 IF ( (p_relationship_id IS NOT NULL) AND (p_relationship_id <> fnd_api.g_miss_num) ) THEN
6490 BEGIN
6491 /* Added the condition 'AND ACTIVE_END_DATE IS NULL' to avoid updating expired relationship */
6492 SELECT 'x'
6493 INTO l_dummy
6494 FROM csi_ii_relationships
6495 WHERE relationship_id=p_relationship_id;
6496 -- AND ( ACTIVE_END_DATE IS NULL
6497 -- OR ACTIVE_END_DATE >SYSDATE)
6498 -- AND ROWNUM=1;
6499 -- IF SQL%FOUND THEN
6500 x_return_status := fnd_api.g_ret_sts_success;
6501 -- END IF;
6502 EXCEPTION
6503 WHEN NO_DATA_FOUND THEN
6504 fnd_message.set_name('CSI', 'CSI_INVALID_RELSHIPID');
6505 fnd_msg_pub.add;
6506 x_return_status := fnd_api.g_ret_sts_error;
6507 END;
6508 ELSE
6509 fnd_message.set_name('CSI', 'CSI_NO_RELSHIP_ID_PASSED');
6510 fnd_msg_pub.add;
6511 x_return_status := fnd_api.g_ret_sts_error;
6512 END IF;
6513 END IF;
6514
6515
6516
6517 -- standard call to get message count and if count is 1, get message info.
6518 fnd_msg_pub.count_AND_get
6519 ( p_count => x_msg_count,
6520 p_data => x_msg_data
6521 );
6522
6523 END validate_relationship_id;
6524
6525
6526 PROCEDURE validate_rel_type_code (
6527 p_init_msg_list IN VARCHAR2,
6528 p_validation_mode IN VARCHAR2,
6529 p_relationship_type_code IN VARCHAR2,
6530 x_return_status OUT NOCOPY VARCHAR2,
6531 x_msg_count OUT NOCOPY NUMBER,
6532 x_msg_data OUT NOCOPY VARCHAR2
6533 )
6534 IS
6535 l_dummy VARCHAR2(1);
6536 BEGIN
6537 -- initialize message list if p_init_msg_list is set to true.
6538 IF fnd_api.to_boolean( p_init_msg_list )
6539 THEN
6540 fnd_msg_pub.initialize;
6541 END IF;
6542
6543 -- initialize api return status to success
6544 x_return_status := fnd_api.g_ret_sts_success;
6545 IF(p_validation_mode ='CREATE')
6546 THEN
6547 IF ((p_relationship_type_code IS NOT NULL) AND (p_relationship_type_code <> fnd_api.g_miss_char)) THEN
6548 BEGIN
6549 SELECT 'x'
6550 INTO l_dummy
6551 FROM csi_ii_relation_types
6552 WHERE relationship_type_code=p_relationship_type_code;
6553
6554 IF SQL%FOUND THEN
6555 x_return_status := fnd_api.g_ret_sts_success;
6556 END IF;
6557
6558 EXCEPTION
6559 WHEN NO_DATA_FOUND THEN
6560 fnd_message.set_name('CSI', 'CSI_INVALID_RELSHIP_CODE');
6561 fnd_message.set_token('relationship_type_code',p_relationship_type_code);
6562 fnd_msg_pub.add;
6563 x_return_status := fnd_api.g_ret_sts_error;
6564 END;
6565 ELSE
6566 fnd_message.set_name('CSI', 'CSI_NO_RELSHIP_CODE');
6567 --fnd_message.set_token('relationship_type_code',p_relationship_type_code);
6568 fnd_msg_pub.add;
6569 x_return_status := fnd_api.g_ret_sts_error;
6570
6571 END IF;
6572 ELSIF(p_validation_mode ='UPDATE')
6573 THEN
6574 IF ((p_relationship_type_code IS NOT NULL) AND (p_relationship_type_code <> fnd_api.g_miss_char)) THEN
6575 BEGIN
6576 SELECT 'x'
6577 INTO l_dummy
6578 FROM csi_ii_relation_types
6579 WHERE relationship_type_code=p_relationship_type_code;
6580 IF SQL%FOUND THEN
6581 x_return_status := fnd_api.g_ret_sts_success;
6582 END IF;
6583 EXCEPTION
6584 WHEN NO_DATA_FOUND THEN
6585 fnd_message.set_name('CSI', 'CSI_INVALID_RELSHIP_CODE');
6586 fnd_message.set_token('relationship_type_code',p_relationship_type_code);
6587 fnd_msg_pub.add;
6588 x_return_status := fnd_api.g_ret_sts_error;
6589 END;
6590 ELSIF p_relationship_type_code IS NULL -- Added for bug 2151750
6591 THEN
6592 fnd_message.set_name('CSI', 'CSI_NO_RELSHIP_CODE');
6593 fnd_msg_pub.add;
6594 x_return_status := fnd_api.g_ret_sts_error;
6595 END IF;
6596 END IF;
6597 -- standard call to get message count and if count is 1, get message info.
6598 fnd_msg_pub.count_AND_get
6599 ( p_count => x_msg_count,
6600 p_data => x_msg_data
6601 );
6602
6603 END validate_rel_type_code;
6604
6605
6606 PROCEDURE validate_object_id (
6607 p_init_msg_list IN VARCHAR2,
6608 p_validation_mode IN VARCHAR2,
6609 p_object_id IN NUMBER,
6610 x_return_status OUT NOCOPY VARCHAR2,
6611 x_msg_count OUT NOCOPY NUMBER,
6612 x_msg_data OUT NOCOPY VARCHAR2
6613 )
6614 IS
6615 l_dummy VARCHAR2(1);
6616 l_instance_id NUMBER;
6617 l_quantity NUMBER;
6618 l_location_type_code VARCHAR2(30);
6619 l_inventory_item_id NUMBER;
6620 l_serial_code NUMBER;
6621 l_item_type VARCHAR2(30);
6622 l_bom_item_type NUMBER;
6623 l_vld_org_id NUMBER;
6624 l_pick_comp_flag VARCHAR2(1);
6625 l_base_item_id NUMBER;
6626 l_repl_order_flag VARCHAR2(1);
6627 l_active VARCHAR2(1);
6628 BEGIN
6629
6630 -- initialize message list if p_init_msg_list is set to true.
6631 IF fnd_api.to_boolean( p_init_msg_list )
6632 THEN
6633 fnd_msg_pub.initialize;
6634 END IF;
6635
6636
6637 -- initialize api return status to success
6638 x_return_status := fnd_api.g_ret_sts_success;
6639
6640 -- validate not null column
6641 IF(p_validation_mode ='CREATE')
6642 THEN
6643 IF ((p_object_id IS NOT NULL) AND (p_object_id <> fnd_api.g_miss_num)) THEN
6644 -- The following code has been added by sguthiva for bug 2416144.
6645 BEGIN
6646 SELECT 'x'
6647 INTO l_active
6648 FROM csi_item_instances cii
6649 WHERE cii.instance_id=p_object_id
6650 AND (SYSDATE BETWEEN NVL(cii.active_start_date, SYSDATE) AND NVL(cii.active_end_date, SYSDATE));
6651 EXCEPTION
6652 WHEN NO_DATA_FOUND THEN
6653 fnd_message.set_name('CSI', 'CSI_EXPIRED_OBJECT');
6654 fnd_message.set_token('object_id',p_object_id);
6655 fnd_msg_pub.add;
6656 x_return_status := fnd_api.g_ret_sts_error;
6657 RAISE fnd_api.g_exc_error;
6658 END;
6659 -- End of addition for bug 2416144.
6660
6661 BEGIN
6662 -- Modified by sk for bug 2266166
6663 SELECT instance_id
6664 ,quantity
6665 ,location_type_code
6666 ,inventory_item_id
6667 ,last_vld_organization_id
6668 INTO l_instance_id
6669 ,l_quantity
6670 ,l_location_type_code
6671 ,l_inventory_item_id
6672 ,l_vld_org_id
6673 FROM csi_item_instances
6674 WHERE instance_id=p_object_id;
6675 IF l_quantity IS NOT NULL THEN
6676 IF l_quantity<>1 THEN
6677 fnd_message.set_name('CSI', 'CSI_QTY_NOTEQUAL_TO_ONE');
6678 fnd_message.set_token('object_id',p_object_id);
6679 fnd_msg_pub.add;
6680 x_return_status := fnd_api.g_ret_sts_error;
6681 END IF;
6682 END IF;
6683 /* commented by sk for bug 2151750
6684 IF l_location_type_code IS NOT NULL THEN
6685 IF UPPER(l_location_type_code) = 'INVENTORY' THEN
6686 fnd_message.set_name('CSI', 'CSI_INVALID_LOCATION_TYPE');
6687 fnd_message.set_token('object_id',p_object_id);
6688 fnd_msg_pub.add;
6689 x_return_status := fnd_api.g_ret_sts_error;
6690 END IF;
6691 END IF;
6692 */
6693 BEGIN
6694 SELECT serial_number_control_code
6695 ,item_type
6696 ,bom_item_type
6697 ,pick_components_flag
6698 ,base_item_id -- Added by rk on 9-Apr
6699 ,replenish_to_order_flag -- for bug 2304221
6700 INTO l_serial_code
6701 ,l_item_type
6702 ,l_bom_item_type
6703 ,l_pick_comp_flag
6704 ,l_base_item_id
6705 ,l_repl_order_flag
6706 FROM mtl_system_items
6707 WHERE inventory_item_id = l_inventory_item_id
6708 AND organization_id = l_vld_org_id ;
6709 -- Item is under serial control but serial_number is NULL
6710 -- '1' stands for - No serial number control
6711 -- '2' stands for - Predefined serial numbers
6712 -- '5' stands for - Dynamic entry at inventory receipt
6713 -- '6' stands for - Dynamic entry at sales order issue
6714 -- Passed object_id should be a serialized item if not it should also be an ATO/PTO item type.
6715 -- below code is commented by rtalluri on 05/20/02 for the bug 2255773
6716 /*
6717 IF NVL(l_serial_code,0) IN (2,5,6) THEN --SERIALIZED ITEM
6718 NULL;
6719 ELSIF NVL(l_serial_code,0)=1 AND
6720 ( l_bom_item_type IN (1,2)
6721 OR
6722 l_pick_comp_flag = 'Y'
6723 OR
6724 ( l_base_item_id IS NOT NULL AND l_repl_order_flag = 'Y')) -- fix for bug 2304221
6725 */
6726 IF l_quantity = 1
6727 THEN
6728 --AND NVL(l_item_type,'X') IN ('ATO','PTO') THEN --NON-SERIALIZED ITEM
6729 -- Modified by sk for bug 2266166
6730 NULL;
6731 ELSE
6732 fnd_message.set_name('CSI', 'CSI_NON_ATO_PTO_ITEM');
6733 fnd_message.set_token('object_id',p_object_id);
6734 fnd_msg_pub.add;
6735 x_return_status := fnd_api.g_ret_sts_error;
6736 END IF;
6737
6738 EXCEPTION
6739 WHEN OTHERS THEN
6740 NULL;
6741 END;
6742 EXCEPTION
6743 WHEN NO_DATA_FOUND THEN
6744 fnd_message.set_name('CSI', 'CSI_INVALID_OBJECT_ID');
6745 fnd_message.set_token('object_id',p_object_id);
6746 fnd_msg_pub.add;
6747 x_return_status := fnd_api.g_ret_sts_error;
6748 END;
6749 ELSE
6750 fnd_message.set_name('CSI', 'CSI_NO_OBJ_ID_PASSED');
6751 fnd_msg_pub.add;
6752 x_return_status := fnd_api.g_ret_sts_error;
6753 END IF;
6754
6755 ELSIF(p_validation_mode ='UPDATE')
6756 THEN
6757 IF ((p_object_id IS NOT NULL) AND (p_object_id <> fnd_api.g_miss_num)) THEN
6758 BEGIN
6759 -- Modified by sk for bug 2266166
6760 SELECT instance_id
6761 ,quantity
6762 ,location_type_code
6763 ,inventory_item_id
6764 ,last_vld_organization_id
6765 INTO l_instance_id
6766 ,l_quantity
6767 ,l_location_type_code
6768 ,l_inventory_item_id
6769 ,l_vld_org_id
6770 FROM csi_item_instances
6771 WHERE instance_id=p_object_id;
6772
6773 IF l_quantity IS NOT NULL THEN
6774 IF l_quantity<>1 THEN
6775 fnd_message.set_name('CSI', 'CSI_QTY_NOTEQUAL_TO_ONE');
6776 fnd_message.set_token('object_id',p_object_id);
6777 fnd_msg_pub.add;
6778 x_return_status := fnd_api.g_ret_sts_error;
6779 END IF;
6780 END IF;
6781 /* commented by sk for bug 2151750
6782 IF l_location_type_code IS NOT NULL THEN
6783 IF UPPER(l_location_type_code) = 'INVENTORY' THEN
6784 fnd_message.set_name('CSI', 'CSI_INVALID_LOCATION_TYPE');
6785 fnd_message.set_token('object_id',p_object_id);
6786 fnd_msg_pub.add;
6787 x_return_status := fnd_api.g_ret_sts_error;
6788 END IF;
6789 END IF;
6790 */
6791 BEGIN
6792 SELECT serial_number_control_code
6793 ,item_type
6794 ,bom_item_type
6795 ,pick_components_flag
6796 ,base_item_id
6797 ,replenish_to_order_flag
6798 INTO l_serial_code
6799 ,l_item_type
6800 ,l_bom_item_type
6801 ,l_pick_comp_flag
6802 ,l_base_item_id -- fix for bug 2304221
6803 ,l_repl_order_flag
6804 FROM mtl_system_items
6805 WHERE inventory_item_id = l_inventory_item_id
6806 AND organization_id = l_vld_org_id ;
6807 -- Item is under serial control but serial_number is NULL
6808 -- '1' stands for - No serial number control
6809 -- '2' stands for - Predefined serial numbers
6810 -- '5' stands for - Dynamic entry at inventory receipt
6811 -- '6' stands for - Dynamic entry at sales order issue
6812 -- Passed object_id should be a serialized item if not it should also be an ATO/PTO item type.
6813 -- below code is commented by rtalluri on 05/20/02 for the bug 2255773
6814 /*
6815 IF NVL(l_serial_code,0) IN (2,5,6) THEN --SERIALIZED ITEM
6816 NULL;
6817 ELSIF NVL(l_serial_code,0)=1 AND
6818 ( l_bom_item_type IN (1,2)
6819 OR
6820 l_pick_comp_flag = 'Y'
6821 OR
6822 ( l_base_item_id IS NOT NULL AND l_repl_order_flag = 'Y')) -- fix for bug 2304221
6823 */
6824 IF l_quantity = 1
6825 THEN
6826 --NVL(l_item_type,'X') IN ('ATO','PTO') THEN --NON-SERIALIZED ITEM
6827 -- Modified by sk for bug 2266166
6828 NULL;
6829 ELSE
6830 fnd_message.set_name('CSI', 'CSI_NON_ATO_PTO_ITEM');
6831 fnd_message.set_token('object_id',p_object_id);
6832 fnd_msg_pub.add;
6833 x_return_status := fnd_api.g_ret_sts_error;
6834 END IF;
6835
6836 EXCEPTION
6837 WHEN OTHERS THEN
6838 NULL;
6839 END;
6840
6841 EXCEPTION
6842 WHEN NO_DATA_FOUND THEN
6843 fnd_message.set_name('CSI', 'CSI_INVALID_OBJECT_ID');
6844 fnd_message.set_token('object_id',p_object_id);
6845 fnd_msg_pub.add;
6846 x_return_status := fnd_api.g_ret_sts_error;
6847 END;
6848 END IF;
6849 END IF;
6850
6851 -- standard call to get message count and if count is 1, get message info.
6852 fnd_msg_pub.count_and_get
6853 ( p_count => x_msg_count,
6854 p_data => x_msg_data
6855 );
6856
6857 END validate_object_id;
6858
6859
6860 PROCEDURE validate_subject_id (
6861 p_init_msg_list IN VARCHAR2,
6862 p_validation_mode IN VARCHAR2,
6863 p_subject_id IN NUMBER,
6864 x_return_status OUT NOCOPY VARCHAR2,
6865 x_msg_count OUT NOCOPY NUMBER,
6866 x_msg_data OUT NOCOPY VARCHAR2
6867 )
6868 IS
6869 l_dummy VARCHAR2(1);
6870 l_instance_id NUMBER;
6871 l_quantity NUMBER;
6872 l_location_type_code VARCHAR2(30);
6873 l_active VARCHAR2(1);
6874 BEGIN
6875
6876 -- initialize message list if p_init_msg_list is set to true.
6877 IF fnd_api.to_boolean( p_init_msg_list )
6878 THEN
6879 fnd_msg_pub.initialize;
6880 END IF;
6881
6882
6883 -- initialize API RETURN status TO success
6884 x_return_status := fnd_api.g_ret_sts_success;
6885
6886 IF ((p_subject_id IS NOT NULL) AND (p_subject_id <> fnd_api.g_miss_num)) THEN
6887 -- The following code has been added by sguthiva for bug 2416144.
6888 IF (p_validation_mode ='CREATE')
6889 THEN
6890 BEGIN
6891 SELECT 'x'
6892 INTO l_active
6893 FROM csi_item_instances cii
6894 WHERE cii.instance_id=p_subject_id
6895 AND (SYSDATE BETWEEN NVL(cii.active_start_date, SYSDATE) AND NVL(cii.active_end_date, SYSDATE));
6896 EXCEPTION
6897 WHEN NO_DATA_FOUND THEN
6898 fnd_message.set_name('CSI', 'CSI_EXPIRED_SUBJECT');
6899 fnd_message.set_token('subject_id',p_subject_id);
6900 fnd_msg_pub.add;
6901 x_return_status := fnd_api.g_ret_sts_error;
6902 RAISE fnd_api.g_exc_error;
6903 END;
6904 END IF;
6905 -- End of addition for bug 2416144.
6906 BEGIN
6907 SELECT instance_id,location_type_code
6908 INTO l_instance_id,l_location_type_code
6909 FROM csi_item_instances
6910 WHERE instance_id=p_subject_id;
6911 /* commented by sk for bug 2151750
6912 IF l_location_type_code IS NOT NULL THEN
6913 IF UPPER(l_location_type_code) = 'INVENTORY' THEN
6914 fnd_message.set_name('CSI', 'CSI_INVALID_LOCATION_TYPE');
6915 fnd_message.set_token('subject_id',p_subject_id);
6916 fnd_msg_pub.add;
6917 x_return_status := fnd_api.g_ret_sts_error;
6918 END IF;
6919 END IF;
6920 */
6921 EXCEPTION
6922 WHEN NO_DATA_FOUND THEN
6923 fnd_message.set_name('CSI', 'CSI_INVALID_SUBJECT_ID');
6924 fnd_message.set_token('subject_id',p_subject_id);
6925 fnd_msg_pub.add;
6926 x_return_status := fnd_api.g_ret_sts_error;
6927 END;
6928 END IF;
6929 -- standard call to get message count and if count is 1, get message info.
6930 fnd_msg_pub.count_AND_get
6931 ( p_count => x_msg_count,
6932 p_data => x_msg_data
6933 );
6934
6935 END validate_subject_id;
6936
6937 PROCEDURE validate_active_end_date (
6938 p_init_msg_list IN VARCHAR2,
6939 p_validation_mode IN VARCHAR2,
6940 p_active_end_date IN DATE,
6941 x_return_status OUT NOCOPY VARCHAR2,
6942 x_msg_count OUT NOCOPY NUMBER,
6943 x_msg_data OUT NOCOPY VARCHAR2
6944 )
6945 IS
6946 BEGIN
6947 -- initialize message list if p_init_msg_list is set to true.
6948 IF fnd_api.to_boolean( p_init_msg_list )
6949 THEN
6950 fnd_msg_pub.initialize;
6951 END IF;
6952
6953
6954 -- initialize api return status to success
6955 x_return_status := fnd_api.g_ret_sts_success;
6956 IF(p_validation_mode ='CREATE') THEN
6957 IF ((p_active_end_date IS NOT NULL) AND (p_active_end_date <> fnd_api.g_miss_date)) THEN
6958 fnd_message.set_name('CSI', 'CSI_ACTIVE_END_DATE');
6959 fnd_message.set_token('ACTIVE_END_DATE',p_active_end_date);
6960 fnd_msg_pub.add;
6961 x_return_status := fnd_api.g_ret_sts_error;
6962 END IF;
6963 END IF;
6964 -- standard call to get message count and if count is 1, get message info.
6965 fnd_msg_pub.count_AND_get
6966 ( p_count => x_msg_count,
6967 p_data => x_msg_data
6968 );
6969
6970 END validate_active_end_date;
6971
6972
6973 PROCEDURE validate_object_version_num (
6974 p_init_msg_list IN VARCHAR2,
6975 p_validation_mode IN VARCHAR2,
6976 p_object_version_number IN NUMBER,
6977 x_return_status OUT NOCOPY VARCHAR2,
6978 x_msg_count OUT NOCOPY NUMBER,
6979 x_msg_data OUT NOCOPY VARCHAR2
6980 )
6981 IS
6982 l_dummy VARCHAR2(1);
6983 BEGIN
6984
6985 -- initialize message list if p_init_msg_list is set to true.
6986 IF fnd_api.to_boolean( p_init_msg_list )
6987 THEN
6988 fnd_msg_pub.initialize;
6989 END IF;
6990
6991
6992 -- initialize api return status to success
6993 x_return_status := fnd_api.g_ret_sts_success;
6994
6995 -- validate not null column
6996
6997
6998 IF( (p_validation_mode = 'UPDATE') OR (p_validation_mode = 'EXPIRE') ) THEN
6999 IF ( (p_object_version_number IS NULL) OR (p_object_version_number = fnd_api.g_miss_num) ) THEN
7000 fnd_message.set_name('CSI', 'CSI_MISSING_OBJ_VER_NUM');
7001 fnd_msg_pub.add;
7002 x_return_status := fnd_api.g_ret_sts_error;
7003 ELSE
7004 x_return_status := fnd_api.g_ret_sts_success;
7005 END IF;
7006 END IF;
7007
7008 -- standard call to get message count and if count is 1, get message info.
7009 fnd_msg_pub.count_and_get
7010 ( p_count => x_msg_count,
7011 p_data => x_msg_data
7012 );
7013
7014 END validate_object_version_num;
7015
7016 PROCEDURE validate_ii_relationships(
7017 p_init_msg_list IN VARCHAR2,
7018 p_validation_level IN NUMBER,
7019 p_validation_mode IN VARCHAR2,
7020 p_ii_relationship_tbl IN csi_datastructures_pub.ii_relationship_tbl,
7021 x_return_status OUT NOCOPY VARCHAR2,
7022 x_msg_count OUT NOCOPY NUMBER,
7023 x_msg_data OUT NOCOPY VARCHAR2
7024 )
7025 IS
7026 l_api_name CONSTANT VARCHAR2(30) := 'validate_ii_relationships';
7027 l_ct NUMBER;
7028 BEGIN
7029
7030
7031
7032 -- initialize api return status to success
7033 x_return_status := fnd_api.g_ret_sts_success;
7034
7035 l_ct := p_ii_relationship_tbl.count;
7036 FOR l_count IN 1..l_ct LOOP
7037
7038 -- The following IF statement has been commented out for Bug: 3271806
7039 -- IF (p_validation_level >= fnd_api.g_valid_level_full) THEN
7040
7041 validate_relationship_id(
7042 p_init_msg_list => fnd_api.g_false,
7043 p_validation_mode => p_validation_mode,
7044 p_relationship_id => p_ii_relationship_tbl(l_count).relationship_id,
7045 x_return_status => x_return_status,
7046 x_msg_count => x_msg_count,
7047 x_msg_data => x_msg_data);
7048 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7049 RAISE fnd_api.g_exc_error;
7050 END IF;
7051
7052 validate_rel_type_code(
7053 p_init_msg_list => fnd_api.g_false,
7054 p_validation_mode => p_validation_mode,
7055 p_relationship_type_code => p_ii_relationship_tbl(l_count).relationship_type_code,
7056 x_return_status => x_return_status,
7057 x_msg_count => x_msg_count,
7058 x_msg_data => x_msg_data);
7059 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7060 RAISE fnd_api.g_exc_error;
7061 END IF;
7062
7063 validate_object_id(
7064 p_init_msg_list => fnd_api.g_false,
7065 p_validation_mode => p_validation_mode,
7066 p_object_id => p_ii_relationship_tbl(l_count).object_id,
7067 x_return_status => x_return_status,
7068 x_msg_count => x_msg_count,
7069 x_msg_data => x_msg_data);
7070 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7071 RAISE fnd_api.g_exc_error;
7072 END IF;
7073
7074 validate_subject_id(
7075 p_init_msg_list => fnd_api.g_false,
7076 p_validation_mode => p_validation_mode,
7077 p_subject_id => p_ii_relationship_tbl(l_count).subject_id,
7078 x_return_status => x_return_status,
7079 x_msg_count => x_msg_count,
7080 x_msg_data => x_msg_data);
7081 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7082 RAISE fnd_api.g_exc_error;
7083 END IF;
7084
7085 validate_active_end_date(
7086 p_init_msg_list => fnd_api.g_false,
7087 p_validation_mode => p_validation_mode,
7088 p_active_end_date => p_ii_relationship_tbl(l_count).active_end_date,
7089 x_return_status => x_return_status,
7090 x_msg_count => x_msg_count,
7091 x_msg_data => x_msg_data);
7092 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7093 RAISE fnd_api.g_exc_error;
7094 END IF;
7095
7096 validate_object_version_num (
7097 p_init_msg_list => fnd_api.g_false,
7098 p_validation_mode => p_validation_mode,
7099 p_object_version_number => p_ii_relationship_tbl(l_count).object_version_number,
7100 x_return_status => x_return_status,
7101 x_msg_count => x_msg_count,
7102 x_msg_data => x_msg_data);
7103
7104 IF x_return_status <> fnd_api.g_ret_sts_success THEN
7105 RAISE fnd_api.g_exc_error;
7106 END IF;
7107
7108 -- END IF;
7109 END LOOP;
7110
7111 END validate_ii_relationships;
7112
7113
7114 /*----------------------------------------------------------*/
7115 /* Procedure name: Resolve_id_columns */
7116 /* Description : This procudure gets the descriptions for */
7117 /* id columns */
7118 /*----------------------------------------------------------*/
7119
7120 PROCEDURE Resolve_id_columns
7121 (p_rel_history_tbl IN OUT NOCOPY csi_datastructures_pub.relationship_history_tbl)
7122 IS
7123
7124 BEGIN
7125 IF p_rel_history_tbl.count > 0 THEN
7126 FOR tab_row in p_rel_history_tbl.FIRST..p_rel_history_tbl.LAST
7127 LOOP
7128 IF p_rel_history_tbl.EXISTS(tab_row) THEN
7129 IF ( (p_rel_history_tbl(tab_row).relationship_type_code IS NOT NULL) AND
7130 (p_rel_history_tbl(tab_row).relationship_type_code <> FND_API.G_MISS_CHAR) ) THEN
7131 BEGIN
7132 SELECT name
7133 INTO p_rel_history_tbl(tab_row).relationship_type
7134 FROM csi_ii_relation_types
7135 WHERE relationship_type_code = p_rel_history_tbl(tab_row).relationship_type_code;
7136 EXCEPTION
7137 WHEN OTHERS THEN
7138 NULL;
7139 END;
7140 END IF;
7141
7142 IF ( (p_rel_history_tbl(tab_row).OLD_SUBJECT_ID IS NOT NULL) AND
7143 (p_rel_history_tbl(tab_row).OLD_SUBJECT_ID <> FND_API.G_MISS_NUM) ) THEN
7144 BEGIN
7145 SELECT instance_number
7146 INTO p_rel_history_tbl(tab_row).old_subject_number
7147 FROM csi_item_instances
7148 WHERE instance_id = p_rel_history_tbl(tab_row).old_subject_id;
7149 EXCEPTION
7150 WHEN OTHERS THEN
7151 NULL;
7152 END;
7153 END IF;
7154
7155 IF ( (p_rel_history_tbl(tab_row).NEW_SUBJECT_ID IS NOT NULL) AND
7156 (p_rel_history_tbl(tab_row).NEW_SUBJECT_ID <> FND_API.G_MISS_NUM) ) THEN
7157 BEGIN
7158 SELECT instance_number
7159 INTO p_rel_history_tbl(tab_row).new_subject_number
7160 FROM csi_item_instances
7161 WHERE instance_id = p_rel_history_tbl(tab_row).new_subject_id;
7162 EXCEPTION
7163 WHEN OTHERS THEN
7164 NULL;
7165 END;
7166 END IF;
7167 END IF;
7168 END LOOP;
7169 END IF;
7170 END Resolve_id_columns;
7171
7172
7173 /*------------------------------------------------------------*/
7174 /* Procedure name: get_inst_relationship_hist */
7175 /* Description : Procedure used to get inst relationships */
7176 /* from history for a given transaction_id */
7177 /*------------------------------------------------------------*/
7178
7179 PROCEDURE get_inst_relationship_hist
7180 ( p_api_version IN NUMBER
7181 ,p_commit IN VARCHAR2 := fnd_api.g_false
7182 ,p_init_msg_list IN VARCHAR2 := fnd_api.g_false
7183 ,p_validation_level IN NUMBER := fnd_api.g_valid_level_full
7184 ,p_transaction_id IN NUMBER
7185 ,x_rel_history_tbl OUT NOCOPY csi_datastructures_pub.relationship_history_tbl
7186 ,x_return_status OUT NOCOPY VARCHAR2
7187 ,x_msg_count OUT NOCOPY NUMBER
7188 ,x_msg_data OUT NOCOPY VARCHAR2
7189 )IS
7190
7191 l_api_name CONSTANT VARCHAR2(30) := 'get_inst_relationship_hist' ;
7192 l_api_version CONSTANT NUMBER := 1.0 ;
7193 l_csi_debug_level NUMBER ;
7194 l_flag VARCHAR2(1) :='N' ;
7195 i NUMBER :=1 ;
7196 l_relationship_query_rec csi_datastructures_pub.relationship_query_rec ;
7197 l_time_stamp DATE ;
7198 l_ii_relationship_tbl csi_datastructures_pub.ii_relationship_tbl ;
7199
7200 CURSOR get_relationship_hist(i_transaction_id NUMBER)
7201 IS
7202 SELECT
7203 cih.relationship_history_id ,
7204 cih.relationship_id ,
7205 cih.transaction_id ,
7206 cih.old_subject_id ,
7207 cih.new_subject_id ,
7208 cih.old_position_reference ,
7209 cih.new_position_reference ,
7210 cih.old_active_start_date ,
7211 cih.new_active_start_date ,
7212 cih.old_active_end_date ,
7213 cih.new_active_end_date ,
7214 cih.old_mandatory_flag ,
7215 cih.new_mandatory_flag ,
7216 cih.old_context ,
7217 cih.new_context ,
7218 cih.old_attribute1 ,
7219 cih.new_attribute1 ,
7220 cih.old_attribute2 ,
7221 cih.new_attribute2 ,
7222 cih.old_attribute3 ,
7223 cih.new_attribute3 ,
7224 cih.old_attribute4 ,
7225 cih.new_attribute4 ,
7226 cih.old_attribute5 ,
7227 cih.new_attribute5 ,
7228 cih.old_attribute6 ,
7229 cih.new_attribute6 ,
7230 cih.old_attribute7 ,
7231 cih.new_attribute7 ,
7232 cih.old_attribute8 ,
7233 cih.new_attribute8 ,
7234 cih.old_attribute9 ,
7235 cih.new_attribute9 ,
7236 cih.old_attribute10 ,
7237 cih.new_attribute10 ,
7238 cih.old_attribute11 ,
7239 cih.new_attribute11 ,
7240 cih.old_attribute12 ,
7241 cih.new_attribute12 ,
7242 cih.old_attribute13 ,
7243 cih.new_attribute13 ,
7244 cih.old_attribute14 ,
7245 cih.new_attribute14 ,
7246 cih.old_attribute15 ,
7247 cih.new_attribute15 ,
7248 cih.full_dump_flag ,
7249 cih.object_version_number ,
7250 cir.relationship_type_code ,
7251 cir.object_id ,
7252 cih.creation_date
7253 FROM csi_ii_relationships_h cih ,
7254 csi_ii_relationships cir
7255 WHERE cih.transaction_id = i_transaction_id
7256 AND cih.relationship_id = cir.relationship_id;
7257
7258 BEGIN
7259 -- Standard Start of API savepoint
7260 --SAVEPOINT get_inst_relationship_hist;
7261
7262 -- Standard call to check for call compatibility.
7263 IF NOT FND_API.Compatible_API_Call ( l_api_version ,
7264 p_api_version ,
7265 l_api_name ,
7266 g_pkg_name )
7267 THEN
7268 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7269 END IF;
7270
7271 -- Initialize message list if p_init_msg_list is set to TRUE.
7272 IF FND_API.to_Boolean( p_init_msg_list ) THEN
7273 FND_MSG_PUB.initialize;
7274 END IF;
7275
7276 -- Initialize API return status to success
7277 x_return_status := FND_API.G_RET_STS_SUCCESS;
7278
7279 -- Check the profile option CSI_DEBUG_LEVEL for debug message reporting
7280 l_csi_debug_level:=fnd_profile.value('CSI_DEBUG_LEVEL');
7281
7282 -- If CSI_DEBUG_LEVEL = 1 then dump the procedure name
7283 IF (l_csi_debug_level > 0) THEN
7284 csi_gen_utility_pvt.put_line( 'get_inst_relationship_hist');
7285 END IF;
7286
7287 -- If the debug level = 2 then dump all the parameters values.
7288 IF (l_csi_debug_level > 1) THEN
7289 csi_gen_utility_pvt.put_line( 'get_inst_relationship_hist' ||
7290 p_api_version ||'-'||
7291 p_commit ||'-'||
7292 p_init_msg_list ||'-'||
7293 p_validation_level ||'-'||
7294 p_transaction_id );
7295 END IF;
7296
7297 /***** srramakr commented for bug # 3304439
7298 -- Check for the profile option and enable trace
7299 l_flag:=csi_gen_utility_pvt.enable_trace(l_trace_flag => l_flag);
7300 -- End enable trace
7301 ****/
7302
7303 -- Start API body
7304
7305 FOR C1 IN get_relationship_hist(p_transaction_id)
7306 LOOP
7307
7308 x_rel_history_tbl(i).relationship_history_id := c1.relationship_history_id;
7309 x_rel_history_tbl(i).relationship_id := c1.relationship_id;
7310 x_rel_history_tbl(i).transaction_id := c1.transaction_id;
7311 x_rel_history_tbl(i).old_subject_id := c1.old_subject_id;
7312 x_rel_history_tbl(i).new_subject_id := c1.new_subject_id;
7313 x_rel_history_tbl(i).old_position_reference := c1.old_position_reference;
7314 x_rel_history_tbl(i).new_position_reference := c1.new_position_reference;
7315 x_rel_history_tbl(i).old_active_start_date := c1.old_active_start_date;
7316 x_rel_history_tbl(i).new_active_start_date := c1.new_active_start_date;
7317 x_rel_history_tbl(i).old_active_end_date := c1.old_active_end_date;
7318 x_rel_history_tbl(i).new_active_end_date := c1.new_active_end_date;
7319 x_rel_history_tbl(i).old_mandatory_flag := c1.old_mandatory_flag;
7320 x_rel_history_tbl(i).new_mandatory_flag := c1.new_mandatory_flag;
7321 x_rel_history_tbl(i).old_context := c1.old_context;
7322 x_rel_history_tbl(i).new_context := c1.new_context;
7323 x_rel_history_tbl(i).old_attribute1 := c1.old_attribute1;
7324 x_rel_history_tbl(i).new_attribute1 := c1.new_attribute1;
7325 x_rel_history_tbl(i).old_attribute2 := c1.old_attribute2;
7326 x_rel_history_tbl(i).new_attribute2 := c1.new_attribute2;
7327 x_rel_history_tbl(i).old_attribute3 := c1.old_attribute3;
7328 x_rel_history_tbl(i).new_attribute3 := c1.new_attribute3;
7329 x_rel_history_tbl(i).old_attribute4 := c1.old_attribute4;
7330 x_rel_history_tbl(i).new_attribute4 := c1.new_attribute4;
7331 x_rel_history_tbl(i).old_attribute5 := c1.old_attribute5;
7332 x_rel_history_tbl(i).new_attribute5 := c1.new_attribute5;
7333 x_rel_history_tbl(i).old_attribute6 := c1.old_attribute6;
7334 x_rel_history_tbl(i).new_attribute6 := c1.new_attribute6;
7335 x_rel_history_tbl(i).old_attribute7 := c1.old_attribute7;
7336 x_rel_history_tbl(i).new_attribute7 := c1.new_attribute7;
7337 x_rel_history_tbl(i).old_attribute8 := c1.old_attribute8;
7338 x_rel_history_tbl(i).new_attribute8 := c1.new_attribute8;
7339 x_rel_history_tbl(i).old_attribute9 := c1.old_attribute9;
7340 x_rel_history_tbl(i).new_attribute9 := c1.new_attribute9;
7341 x_rel_history_tbl(i).old_attribute10 := c1.old_attribute10;
7342 x_rel_history_tbl(i).new_attribute10 := c1.new_attribute10;
7343 x_rel_history_tbl(i).old_attribute11 := c1.old_attribute11;
7344 x_rel_history_tbl(i).new_attribute11 := c1.new_attribute11;
7345 x_rel_history_tbl(i).old_attribute12 := c1.old_attribute12;
7346 x_rel_history_tbl(i).new_attribute12 := c1.new_attribute12;
7347 x_rel_history_tbl(i).old_attribute13 := c1.old_attribute13;
7348 x_rel_history_tbl(i).new_attribute13 := c1.new_attribute13;
7349 x_rel_history_tbl(i).old_attribute14 := c1.old_attribute14;
7350 x_rel_history_tbl(i).new_attribute14 := c1.new_attribute14;
7351 x_rel_history_tbl(i).old_attribute15 := c1.old_attribute15;
7352 x_rel_history_tbl(i).new_attribute15 := c1.new_attribute15;
7353 x_rel_history_tbl(i).full_dump_flag := c1.full_dump_flag;
7354 x_rel_history_tbl(i).object_version_number := c1.object_version_number;
7355 x_rel_history_tbl(i).relationship_type_code := c1.relationship_type_code;
7356 x_rel_history_tbl(i).object_id := c1.object_id;
7357 x_rel_history_tbl(i).creation_date := c1.creation_date;
7358
7359
7360 IF (
7361 (x_rel_history_tbl(i).new_subject_id IS NULL)
7362 OR (x_rel_history_tbl(i).new_subject_id = FND_API.G_MISS_NUM)
7363 )
7364 THEN
7365
7366 l_relationship_query_rec.relationship_id := x_rel_history_tbl(i).relationship_id;
7367 l_time_stamp := x_rel_history_tbl(i).creation_date;
7368
7369 get_relationships
7370 (
7371 p_api_version => 1.0,
7372 p_commit => fnd_api.g_false,
7373 p_init_msg_list => fnd_api.g_false,
7374 p_validation_level => fnd_api.g_valid_level_full,
7375 p_relationship_query_rec => l_relationship_query_rec,
7376 p_depth => NULL,
7377 p_time_stamp => l_time_stamp,
7378 p_active_relationship_only => fnd_api.g_false,
7379 x_relationship_tbl => l_ii_relationship_tbl,
7380 x_return_status => x_return_status,
7381 x_msg_count => x_msg_count,
7382 x_msg_data => x_msg_data
7383 );
7384
7385 IF NOT(x_return_status = fnd_api.g_ret_sts_success) THEN
7386 RAISE fnd_api.g_exc_error;
7387 END IF;
7388 --
7389 IF l_ii_relationship_tbl.count > 0 THEN
7390 x_rel_history_tbl(i).new_subject_id := l_ii_relationship_tbl(1).subject_id;
7391 x_rel_history_tbl(i).old_subject_id := l_ii_relationship_tbl(1).subject_id;
7392 x_rel_history_tbl(i).object_id := l_ii_relationship_tbl(1).object_id;
7393 x_rel_history_tbl(i).old_active_start_date := l_ii_relationship_tbl(1).active_start_date;
7394 x_rel_history_tbl(i).new_active_start_date := l_ii_relationship_tbl(1).active_start_date;
7395 --
7396 END IF;
7397 END IF;
7398 i := i + 1;
7399 END LOOP;
7400 -- srramakr moved outside the loop
7401 -- Resolve the id columns
7402 csi_ii_relationships_pvt.Resolve_id_columns(x_rel_history_tbl);
7403
7404 -- End of API body
7405
7406 -- Standard check of p_commit.
7407 /*
7408 IF FND_API.To_Boolean( p_commit ) THEN
7409 COMMIT WORK;
7410 END IF;
7411 */
7412
7413 /***** srramakr commented for bug # 3304439
7414 -- Check for the profile option and disable the trace
7415 IF (l_flag = 'Y') THEN
7416 dbms_session.set_sql_trace(false);
7417 END IF;
7418 -- End disable trace
7419 ****/
7420
7421 -- Standard call to get message count and if count is get message info.
7422 FND_MSG_PUB.Count_And_Get
7423 (p_count => x_msg_count ,
7424 p_data => x_msg_data );
7425
7426 EXCEPTION
7427
7428 WHEN FND_API.G_EXC_ERROR THEN
7429 -- ROLLBACK TO get_inst_relationship_hist;
7430 x_return_status := FND_API.G_RET_STS_ERROR ;
7431 FND_MSG_PUB.Count_And_Get
7432 ( p_count => x_msg_count,
7433 p_data => x_msg_data );
7434 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7435 -- ROLLBACK TO get_inst_relationship_hist;
7436 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7437 FND_MSG_PUB.Count_And_Get
7438 ( p_count => x_msg_count,
7439 p_data => x_msg_data );
7440 WHEN OTHERS THEN
7441 -- ROLLBACK TO get_inst_relationship_hist;
7442 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
7443 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
7444 FND_MSG_PUB.Add_Exc_Msg
7445 ( g_pkg_name ,
7446 l_api_name );
7447 END IF;
7448 FND_MSG_PUB.Count_And_Get
7449 ( p_count => x_msg_count,
7450 p_data => x_msg_data );
7451
7452 END get_inst_relationship_hist;
7453 --
7454 /*-------------------------------------------------------------------*/
7455 /* Procedure name: Get_Cyclic_node */
7456 /* Description : Given a vertex (instance_id), it traverses thru' */
7457 /* the structure and find whether a cycle exists */
7458 /* or not. If p_stop_at_cyclic is set to false, */
7459 /* it gives the complete structure in p_rel_tbl. */
7460 /* This will be Depth-First-Search order. */
7461 /* p_cyclic_node is a vertex that participates in */
7462 /* the cycle. */
7463 /* Author : Srinivasan Ramakrishnan */
7464 /*-------------------------------------------------------------------*/
7465 PROCEDURE Get_Cyclic_Node
7466 ( p_instance_id IN NUMBER,
7467 p_cyclic_node OUT NOCOPY NUMBER,
7468 p_rel_tbl OUT NOCOPY csi_datastructures_pub.ii_relationship_tbl,
7469 p_stop_at_cyclic IN VARCHAR2,
7470 x_return_status OUT NOCOPY VARCHAR2,
7471 x_msg_count OUT NOCOPY NUMBER,
7472 x_msg_data OUT NOCOPY VARCHAR2 ) IS
7473 l_max_count NUMBER;
7474 l_ctr NUMBER;
7475 l_temp_id NUMBER;
7476 l_found NUMBER;
7477 l_node_found NUMBER;
7478 l_check_id NUMBER;
7479 l_exists NUMBER;
7480 l_cycle_exists VARCHAR2(1);
7481 l_instance_id NUMBER;
7482 l_msg_index NUMBER;
7483 l_msg_count NUMBER;
7484 l_debug_level NUMBER;
7485 l_adj_node NUMBER;
7486 l_rel_tbl_final csi_datastructures_pub.ii_relationship_tbl;
7487 l_api_name CONSTANT VARCHAR2(50) := 'get_cyclic_node';
7488 --
7489 l_rel_color_tbl csi_ii_relationships_pvt.REL_COLOR_TBL;
7490 l_rel_color_ctr NUMBER := 0;
7491 --
7492 COMP_ERROR EXCEPTION;
7493 BEGIN
7494 x_return_status := fnd_api.g_ret_sts_success;
7495 p_cyclic_node := NULL;
7496 l_instance_id := p_instance_id;
7497 --
7498 l_debug_level:=fnd_profile.value('CSI_DEBUG_LEVEL');
7499 IF (l_debug_level > 0) THEN
7500 CSI_gen_utility_pvt.put_line( 'Get_Cyclic_Node');
7501 END IF;
7502 --
7503 csi_ii_relationships_pvt.get_cyclic_relationships(
7504 p_api_version => 1.0,
7505 p_commit => fnd_api.g_false,
7506 p_init_msg_list => fnd_api.g_true,
7507 p_validation_level => fnd_api.g_valid_level_full,
7508 p_instance_id => l_instance_id,
7509 p_depth => NULL ,
7510 p_time_stamp => fnd_api.g_miss_date,
7511 p_active_relationship_only => fnd_api.g_true,
7512 x_relationship_tbl => p_rel_tbl,
7513 x_return_status => x_return_status,
7514 x_msg_count => x_msg_count,
7515 x_msg_data => x_msg_data
7516 );
7517 --
7518 IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
7519 l_msg_index := 1;
7520 l_msg_count := x_msg_count;
7521 WHILE l_msg_count > 0 LOOP
7522 x_msg_data := FND_MSG_PUB.GET
7523 ( l_msg_index,
7524 FND_API.G_FALSE );
7525 csi_gen_utility_pvt.put_line( ' Error from Get_cyclic_relationships.. ');
7526 csi_gen_utility_pvt.put_line('MESSAGE DATA = '||x_msg_data);
7527 l_msg_index := l_msg_index + 1;
7528 l_msg_count := l_msg_count - 1;
7529 END LOOP;
7530 RAISE FND_API.G_EXC_ERROR;
7531 END IF;
7532 --
7533 csi_gen_utility_pvt.put_line('p_rel_tbl count after get_cyclic_relationships is '
7534 ||to_char(p_rel_tbl.count));
7535 l_rel_tbl_final.DELETE;
7536 l_rel_tbl_final := p_rel_tbl;
7537 p_rel_tbl.DELETE;
7538 l_ctr := 0;
7539 l_rel_color_ctr := 0;
7540 --
7541 -- The output of l_rel_tbl_final will be Breadth first search Order.
7542 -- This needs to be converted to depth-first-search(DFS) order since DFS is capable of
7543 -- hitting the cyclic node.
7544 --
7545 -- There is no concept of Parent-Child in a graph structure. All we do in a DFS is, given a
7546 -- vertex, we try to get its adjacent node and walk thru' the graph.
7547 -- Since in CSI_II_RELATIONSHIPS table, they are identified as Object_id and Subject_id
7548 -- we pick up the adjacent node in whichever form it appears (object or subject).
7549 --
7550 -- The following LOOP does this.
7551 --
7552 IF l_rel_tbl_final.count > 0 THEN
7553 l_max_count := l_rel_tbl_final.count;
7554 l_temp_id := l_instance_id;
7555 LOOP
7556 IF p_rel_tbl.count = l_max_count OR
7557 l_rel_tbl_final.count = 0 THEN
7558 exit;
7559 END IF;
7560 --
7561 csi_gen_utility_pvt.put_line('Processing '||to_char(l_temp_id));
7562 --
7563 FOR rel IN l_rel_tbl_final.FIRST .. l_rel_tbl_final.LAST LOOP
7564 l_found := 0;
7565 l_adj_node := -9999;
7566 --
7567 IF l_rel_tbl_final.EXISTS(rel) THEN
7568 -- Try to get the Adjacent Node
7569 IF l_rel_tbl_final(rel).object_id = l_temp_id THEN
7570 l_adj_node := l_rel_tbl_final(rel).subject_id;
7571 l_found := 1;
7572 ELSIF l_rel_tbl_final(rel).subject_id = l_temp_id THEN
7573 l_adj_node := l_rel_tbl_final(rel).object_id;
7574 l_found := 1;
7575 END IF;
7576 --
7577 IF l_found = 1 THEN
7578 l_ctr := l_ctr + 1;
7579 p_rel_tbl(l_ctr) := l_rel_tbl_final(rel); -- Push the processed row
7580 -- Add the current node if not exists in the visited list
7581 l_exists := 0;
7582 IF l_rel_color_tbl.count > 0 THEN
7583 FOR rel_color in l_rel_color_tbl.FIRST .. l_rel_color_tbl.LAST LOOP
7584 IF l_rel_color_tbl(rel_color).node_id = l_temp_id THEN
7585 l_exists := 1;
7586 exit;
7587 END IF;
7588 END LOOP;
7589 END IF;
7590 --
7591 IF l_exists = 0 THEN
7592 l_rel_color_ctr := l_rel_color_ctr + 1;
7593 l_rel_color_tbl(l_rel_color_ctr).node_id := l_temp_id;
7594 l_rel_color_tbl(l_rel_color_ctr).color_code := 'R';
7595 END IF;
7596 --
7597 l_temp_id := l_adj_node; -- set this to the adjacent node and continue
7598 l_rel_tbl_final.DELETE(rel); -- Pop the processed row
7599 --
7600 -- Check for cycle
7601 IF l_rel_color_tbl.count > 0 THEN
7602 FOR color_rec in l_rel_color_tbl.FIRST .. l_rel_color_tbl.LAST LOOP
7603 IF l_rel_color_tbl(color_rec).node_id = l_temp_id AND -- adjacent node
7604 l_rel_color_tbl(color_rec).color_code = 'R' THEN
7605 p_cyclic_node := l_temp_id;
7606 IF nvl(p_stop_at_cyclic,fnd_api.g_true) = fnd_api.g_true THEN
7607 csi_gen_utility_pvt.put_line('Cycle exists at '||to_char(p_cyclic_node));
7608 Raise COMP_ERROR;
7609 END IF;
7610 END IF;
7611 END LOOP;
7612 END IF; -- end of check for cycle
7613 exit;
7614 END IF; -- l_found = 1
7615 END IF;
7616 END LOOP;
7617 --
7618 IF l_found = 0 THEN -- If No more components then go back
7619 -- If all the nodes under the current node are traversed then mark the node as 'B'.
7620 -- The reason for marking this to 'B' is to eliminate this node while getting
7621 -- the previous visited node
7622 l_node_found := 0;
7623 IF l_rel_color_tbl.count > 0 THEN
7624 FOR mark in l_rel_color_tbl.FIRST .. l_rel_color_tbl.LAST LOOP
7625 IF l_rel_color_tbl(mark).node_id = l_temp_id THEN
7626 l_rel_color_tbl(mark).color_code := 'B';
7627 l_node_found := 1;
7628 csi_gen_utility_pvt.put_line('Marked '||l_temp_id);
7629 exit;
7630 END IF;
7631 END LOOP;
7632 END IF;
7633 --
7634 IF l_node_found = 0 THEN
7635 l_rel_color_ctr := l_rel_color_ctr + 1;
7636 l_rel_color_tbl(l_rel_color_ctr).node_id := l_temp_id;
7637 l_rel_color_tbl(l_rel_color_ctr).color_code := 'B'; -- since l_found = 0
7638 csi_gen_utility_pvt.put_line('Marked '||l_temp_id);
7639 END IF;
7640 --
7641 -- Get the unmarked node from l_rel_color_tbl in Reverse direction
7642 -- The idea is to go back in the same path once a node is marked as 'B'.
7643 FOR adj IN REVERSE l_rel_color_tbl.FIRST .. l_rel_color_tbl.LAST LOOP
7644 IF l_rel_color_tbl(adj).color_code = 'R' THEN
7645 l_temp_id := l_rel_color_tbl(adj).node_id;
7646 exit;
7647 END IF;
7648 END LOOP;
7649 --
7650 csi_gen_utility_pvt.put_line('Adjacent Node is '||l_temp_id);
7651 IF l_temp_id = -9999 THEN
7652 csi_gen_utility_pvt.put_line('Unable to get the Adjacent Node.. Exiting...');
7653 Raise FND_API.G_EXC_UNEXPECTED_ERROR;
7654 END IF;
7655 END IF; -- l_found = 0 check
7656 END LOOP;
7657 END IF;
7658 csi_gen_utility_pvt.put_line('End of Get_Cyclic_Node...');
7659 EXCEPTION
7660 WHEN COMP_ERROR THEN
7661 null;
7662 WHEN FND_API.G_EXC_ERROR THEN
7663 x_return_status := fnd_api.g_ret_sts_error ;
7664 fnd_msg_pub.count_AND_get
7665 (p_count => x_msg_count ,
7666 p_data => x_msg_data
7667 );
7668
7669 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7670 x_return_status := fnd_api.g_ret_sts_unexp_error ;
7671 fnd_msg_pub.count_AND_get
7672 (p_count => x_msg_count ,
7673 p_data => x_msg_data
7674 );
7675
7676 WHEN OTHERS THEN
7677 x_return_status := fnd_api.g_ret_sts_unexp_error ;
7678 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
7679 fnd_msg_pub.add_exc_msg(g_pkg_name,l_api_name);
7680 END IF;
7681 fnd_msg_pub.count_AND_get
7682 (p_count => x_msg_count ,
7683 p_data => x_msg_data
7684 );
7685 END Get_Cyclic_Node;
7686
7687 -- Begin Add Code for Siebel Genesis Project
7688 FUNCTION Get_Root_Parent
7689 (
7690 p_subject_id IN NUMBER,
7691 p_rel_type_code IN VARCHAR2,
7692 p_object_id IN NUMBER
7693 ) RETURN NUMBER
7694 IS
7695 l_object_id NUMBER;
7696 l_root_object_id NUMBER;
7697 BEGIN
7698 IF p_rel_type_code IS NULL OR
7699 p_subject_id IS NULL THEN
7700 l_object_id := p_object_id;
7701 RETURN l_object_id;
7702 END IF;
7703
7704 l_object_id := p_subject_id;
7705
7706 Begin
7707 select object_id
7708 into l_object_id
7709 from CSI_II_RELATIONSHIPS
7710 where subject_id = p_subject_id
7711 and relationship_type_code = p_rel_type_code
7712 and ((active_end_date is null) or (active_end_date > sysdate));
7713 Exception
7714 when no_data_found then
7715 l_object_id := p_subject_id;
7716 RETURN l_object_id;
7717 End;
7718 -- Call Recursively for prior parent
7719 Get_Top_Most_Parent
7720 (p_subject_id => l_object_id,
7721 p_rel_type_code => p_rel_type_code,
7722 p_object_id => l_root_object_id
7723 );
7724 return l_root_object_id;
7725 END Get_Root_Parent;
7726 -- End Add Code for Siebel Genesis Project
7727
7728 END csi_ii_relationships_pvt;