DBA Data[Home] [Help]

PACKAGE BODY: APPS.EGO_ICC_BULKLOAD_PVT

Source


1 PACKAGE BODY EGO_ICC_BULKLOAD_PVT AS
2 /* $Header: EGOVICCB.pls 120.22.12020000.2 2012/07/13 02:03:57 mshirkol ship $ */
3 
4 
5      g_icc_rec_count      NUMBER := 0;
6      g_ag_assoc_rec_count NUMBER := 0;
7      g_fn_param_map_count NUMBER := 0;
8      g_icc_vers_rec_count NUMBER := 0;
9      g_item_obj_id        NUMBER := NULL;
10      g_old_icc_rec       mtl_item_catalog_groups_b%rowtype;
11 
12 
13     CURSOR cur_get_obj_id
14     IS
15     SELECT object_id
16     FROM   fnd_objects
17     WHERE obj_name = G_ITEM_OBJ_NAME;
18 
19     TYPE number_tbl_type IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;  --- added bug 9701271
20 
21     --
22     -- Bug 12394675. Issue #2. New version should be created only if
23     -- there are changes in TAs. Added below TYPE which will
24     -- be used in TA comparison.
25     -- sreharih. Mon Apr 25 16:27:38 PDT 2011
26     --
27     TYPE t_ta_records      IS TABLE OF ego_trans_attr_vers_b%ROWTYPE INDEX BY BINARY_INTEGER;
28     TYPE t_ta_intf_records IS TABLE OF ego_trans_attrs_vers_intf%ROWTYPE INDEX BY BINARY_INTEGER;
29 
30     -----------------------------------------------
31     ---   This procedure prints the debugging information to a file or
32     ---   to the concurrent program output
33     ---
34     -----------------------------------------------
35     PROCEDURE write_debug( p_proc_name in VARCHAR2, p_message in VARCHAR2)
36     IS
37      -- PRAGMA AUTONOMOUS_TRANSACTION;
38     BEGIN
39 
40 
41      --- logging logic here  using G_PKG_NAME and p_PROC_NAME ---
42      --dbms_output.put_line(' start insert=>'||p_proc_name||'**'||P_MESSAGE);
43      --INSERT INTO TEMP_VJ VALUES (  xx_temp_vj.nextval||'-'||p_proc_name , p_message);
44      --COMMIT;
45 
46       EGO_METADATA_BULKLOAD_PVT.write_debug(G_PKG_NAME||'.'||p_proc_name||'->'||p_message);
47 
48 
49     EXCEPTION
50     WHEN OTHERS THEN
51       --dbms_output.put_line(SQLERRM);
52       null;
53     END write_debug;
54 
55    -----------------------------------------------
56    --- Log the message in the interface errors table
57    ---
58    -----------------------------------------------
59 
60    PROCEDURE log_error ( p_transaction_id IN NUMBER
61                         ,p_entity         IN VARCHAR2
62                         ,p_message        IN VARCHAR2
63                         ,p_proc_name      IN VARCHAR2
64                        )
65     IS
66 
67     BEGIN
68 
69       null;
70 
71     EXCEPTION
72     WHEN OTHERS THEN
73       null;
74     END log_error;
75 
76 
77 
78     -----------------------------------------------
79     ---  This procedure is used to validate the transaction type in the
80     ---   interface tables
81     ---
82     -----------------------------------------------
83     PROCEDURE Validate_Trans_Type ( p_entity         IN VARCHAR2
84                                    ,x_return_status   OUT NOCOPY VARCHAR2
85                                    ,x_return_msg  OUT NOCOPY VARCHAR2
86                                   )
87 
88     IS
89       L_proc_name VARCHAR2(30) :=  'Validate_Trans_Type';
90       l_msg_name   fnd_new_messages.message_name%type;
91       l_msg_text   fnd_new_messages.message_text%type;
92       l_sysdate     DATE       := SYSDATE;
93 
94     BEGIN
95           write_debug (l_proc_name, 'Start of  '||l_proc_name);
96           x_return_status := G_RET_STS_SUCCESS;
97           ---
98           --- Validating if the transaction type is being passed
99           ---
100 
101           IF p_entity = G_ENTITY_ICC_HEADER THEN
102 
103                 l_msg_name := 'EGO_TRANS_TYPE_INVALID';
104                 FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
105                 l_msg_text := FND_MESSAGE.GET;
106 
107                 INSERT INTO MTL_INTERFACE_ERRORS
108                  (
109                     TRANSACTION_ID
110                     ,UNIQUE_ID
111                     ,ORGANIZATION_ID
112                     ,COLUMN_NAME
113                     ,TABLE_NAME
114                     ,MESSAGE_NAME
115                     ,ERROR_MESSAGE
116                     ,bo_identifier
117                     ,ENTITY_IDENTIFIER
118                     ,LAST_UPDATE_DATE
119                     ,LAST_UPDATED_BY
120                     ,CREATION_DATE
121                     ,CREATED_BY
122                     ,LAST_UPDATE_LOGIN
123                     ,REQUEST_ID
124                     ,PROGRAM_APPLICATION_ID
125                     ,PROGRAM_ID
126                     ,PROGRAM_UPDATE_DATE
127                  )
128                  SELECT transaction_id
129                        ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
130                        ,null
131                        ,null
132                        ,G_ENTITY_ICC_HEADER_TAB
133                        ,l_msg_name
134                        ,l_msg_text
135                        ,G_BO_IDENTIFIER_ICC
136                        ,G_ENTITY_ICC_HEADER
137                        ,l_sysdate
138                        ,G_USER_ID
139                        ,l_sysdate
140                        ,G_USER_ID
141                        ,G_LOGIN_ID
142                        ,G_CONC_REQUEST_ID
143                        ,G_PROG_APPL_ID
144                        ,G_PROGRAM_ID
145                        ,l_sysdate
146                 FROM   MTL_ITEM_CAT_GRPS_INTERFACE MICGI
147                 WHERE  ( (MICGI.transaction_type IS NULL )
148                              OR
149                          (MICGI.transaction_type NOT IN ( G_TTYPE_CREATE , G_TTYPE_UPDATE
150                                                        ,G_TTYPE_SYNC)
151                          )
152                        )
153                 AND  (
154                          ( G_SET_PROCESS_ID IS NULL )
155                           OR
156                          ( MICGI.set_process_id =  G_SET_PROCESS_ID)
157                      )
158                 AND process_status = G_PROCESS_STATUS_INITIAL
159                 ;
160 
161                 --write_debug ( l_proc_name, 'rows inserted=>'||SQL%ROWCOUNT);
162 
163                 ---
164                 --- mark the respective records as errors
165                 ---
166                 UPDATE MTL_ITEM_CAT_GRPS_INTERFACE MICGI
167                 SET micgi.process_status = G_PROCESS_STATUS_ERROR
168                 WHERE  ( micgi.transaction_type IS NULL OR
169                          micgi.transaction_type NOT IN ( G_TTYPE_CREATE , G_TTYPE_UPDATE
170                                                        ,G_TTYPE_SYNC)
171                        )
172                 AND  (
173                          ( G_SET_PROCESS_ID IS NULL )
174                           OR
175                          ( MICGI.set_process_id =  G_SET_PROCESS_ID)
176                      )
177                 AND MICGI.process_status = G_PROCESS_STATUS_INITIAL
178                 ;
179 
180 
181           END IF; -- entity  Header
182 
183 
184           IF p_entity = G_ENTITY_ICC_AG_ASSOC THEN
185 
186                 l_msg_name := 'EGO_TRANS_TYPE_INVALID';
187                 FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
188                 l_msg_text := FND_MESSAGE.GET;
189 
190 
191                 INSERT INTO MTL_INTERFACE_ERRORS
192                  (
193                     TRANSACTION_ID
194                     ,UNIQUE_ID
195                     ,ORGANIZATION_ID
196                     ,COLUMN_NAME
197                     ,TABLE_NAME
198                     ,MESSAGE_NAME
199                     ,ERROR_MESSAGE
200                     ,bo_identifier
201                     ,ENTITY_IDENTIFIER
202                     ,LAST_UPDATE_DATE
203                     ,LAST_UPDATED_BY
204                     ,CREATION_DATE
205                     ,CREATED_BY
206                     ,LAST_UPDATE_LOGIN
207                     ,REQUEST_ID
208                     ,PROGRAM_APPLICATION_ID
209                     ,PROGRAM_ID
210                     ,PROGRAM_UPDATE_DATE
211                  )
212                  SELECT transaction_id
213                        ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
214                        ,null
215                        ,null
216                        ,G_ENTITY_ICC_HEADER_TAB
217                        ,l_msg_name
218                        ,l_msg_text
219                        ,G_BO_IDENTIFIER_ICC
220                        ,G_ENTITY_ICC_AG_ASSOC
221                        ,l_sysdate
222                        ,G_USER_ID
223                        ,l_sysdate
224                        ,G_USER_ID
225                        ,G_LOGIN_ID
226                        ,G_CONC_REQUEST_ID
227                        ,G_PROG_APPL_ID
228                        ,G_PROGRAM_ID
229                        ,l_sysdate
230                 FROM   EGO_ATTR_GRPS_ASSOC_INTERFACE eagai
231                 WHERE  ( eagai.transaction_type IS NULL OR
232                          eagai.transaction_type NOT IN ( G_TTYPE_CREATE
233                                                         ,G_TTYPE_DELETE)
234                        )
235                 AND  (
236                          ( G_SET_PROCESS_ID IS NULL )
237                           OR
238                          ( EAGAI.set_process_id =  G_SET_PROCESS_ID)
239                      )
240                 AND process_status = G_PROCESS_STATUS_INITIAL
241                 ;
242 
243 
244                 UPDATE EGO_ATTR_GRPS_ASSOC_INTERFACE eagai
245                 SET eagai.process_status = G_PROCESS_STATUS_ERROR
246                 WHERE  ( eagai.transaction_type IS NULL OR
247                          eagai.transaction_type NOT IN ( G_TTYPE_CREATE
248                                                        , G_TTYPE_DELETE)
249                        )
250                 AND  (
251                          ( G_SET_PROCESS_ID IS NULL )
252                           OR
253                          ( eagai.set_process_id =  G_SET_PROCESS_ID)
254                      )
255                 AND eagai.process_status = G_PROCESS_STATUS_INITIAL
256                 ;
257 
258           end if;
259 
260           IF p_entity = G_ENTITY_ICC_FN_PARAM_MAP THEN
261 
262                 l_msg_name := 'EGO_TRANS_TYPE_INVALID';
263                 FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
264                 l_msg_text := FND_MESSAGE.GET;
265 
266 
267                 INSERT INTO MTL_INTERFACE_ERRORS
268                  (
269                     TRANSACTION_ID
270                     ,UNIQUE_ID
271                     ,ORGANIZATION_ID
272                     ,COLUMN_NAME
273                     ,TABLE_NAME
274                     ,MESSAGE_NAME
275                     ,ERROR_MESSAGE
276                     ,bo_identifier
277                     ,ENTITY_IDENTIFIER
278                     ,LAST_UPDATE_DATE
279                     ,LAST_UPDATED_BY
280                     ,CREATION_DATE
281                     ,CREATED_BY
282                     ,LAST_UPDATE_LOGIN
283                     ,REQUEST_ID
284                     ,PROGRAM_APPLICATION_ID
285                     ,PROGRAM_ID
286                     ,PROGRAM_UPDATE_DATE
287                  )
288                  SELECT transaction_id
289                        ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
290                        ,null
291                        ,null
292                        ,G_ENTITY_FUNC_PARAM_MAP_TAB
293                        ,l_msg_name
294                        ,l_msg_text
295                        ,G_BO_IDENTIFIER_ICC
296                        ,G_ENTITY_ICC_FN_PARAM_MAP
297                        ,l_sysdate
298                        ,G_USER_ID
299                        ,l_sysdate
300                        ,G_USER_ID
301                        ,G_LOGIN_ID
302                        ,G_CONC_REQUEST_ID
303                        ,G_PROG_APPL_ID
304                        ,G_PROGRAM_ID
305                        ,l_sysdate
306                FROM   EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
307                WHERE  ( efpmi.transaction_type IS NULL OR
308                  efpmi.transaction_type NOT IN ( G_TTYPE_CREATE , G_TTYPE_UPDATE ,
309                                               G_TTYPE_SYNC , G_TTYPE_DELETE)
310                        )
311                 AND  (
312                          ( G_SET_PROCESS_ID IS NULL )
313                           OR
314                          ( EFPMI.set_process_id =  G_SET_PROCESS_ID)
315                      )
316                AND process_status = G_PROCESS_STATUS_INITIAL
317                ;
318 
319 
320 
321                 UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
322                 SET efpmi.process_status = G_PROCESS_STATUS_ERROR
323                 WHERE  ( efpmi.transaction_type IS NULL OR
324                          efpmi.transaction_type NOT IN ( G_TTYPE_CREATE , G_TTYPE_UPDATE
325                                                        ,G_TTYPE_SYNC, G_TTYPE_DELETE)
326                        )
327                 AND  (
328                          ( G_SET_PROCESS_ID IS NULL )
329                           OR
330                          ( efpmi.set_process_id =  G_SET_PROCESS_ID)
331                      )
332                 AND efpmi.process_status = G_PROCESS_STATUS_INITIAL
333                 ;
334 
335 
336           END IF;
337 
338 
339           if p_entity = G_ENTITY_ICC_VERSION THEN
340 
341                 l_msg_name := 'EGO_TRANS_TYPE_ICC_VER_INVALID';
342                 FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
343                 l_msg_text := FND_MESSAGE.GET;
344 
345                ---
346                --- Insert for versioning interface table
347                ---
348 
349                 INSERT INTO MTL_INTERFACE_ERRORS
350                  (
351                     TRANSACTION_ID
352                     ,UNIQUE_ID
353                     ,ORGANIZATION_ID
354                     ,COLUMN_NAME
355                     ,TABLE_NAME
356                     ,MESSAGE_NAME
357                     ,ERROR_MESSAGE
358                     ,bo_identifier
359                     ,ENTITY_IDENTIFIER
360                     ,LAST_UPDATE_DATE
361                     ,LAST_UPDATED_BY
362                     ,CREATION_DATE
363                     ,CREATED_BY
364                     ,LAST_UPDATE_LOGIN
365                     ,REQUEST_ID
366                     ,PROGRAM_APPLICATION_ID
367                     ,PROGRAM_ID
368                     ,PROGRAM_UPDATE_DATE
369                  )
370                  SELECT transaction_id
371                        ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
372                        ,null
373                        ,null
374                        ,G_ENTITY_ICC_VERS_TAB
375                        ,l_msg_name
376                        ,l_msg_text
377                        ,G_BO_IDENTIFIER_ICC
378                        ,G_ENTITY_ICC_VERSION
379                        ,l_sysdate
380                        ,G_USER_ID
381                        ,l_sysdate
382                        ,G_USER_ID
383                        ,G_LOGIN_ID
384                        ,G_CONC_REQUEST_ID
385                        ,G_PROG_APPL_ID
386                        ,G_PROGRAM_ID
387                        ,l_sysdate
388                 FROM   EGO_ICC_VERS_INTERFACE EIVI
389                 WHERE  ( EIVI.transaction_type IS NULL OR
390                          EIVI.transaction_type NOT IN ( G_TTYPE_CREATE )
391                        )
392                 AND  (
393                          ( G_SET_PROCESS_ID IS NULL )
394                           OR
395                          ( EIVI.set_process_id =  G_SET_PROCESS_ID)
396                      )
397                 AND EIVI.process_status = G_PROCESS_STATUS_INITIAL
398                 ;
399 
400                 UPDATE EGO_ICC_VERS_INTERFACE EIVI
401                 SET EIVI.process_status = G_PROCESS_STATUS_ERROR
402                 WHERE  ( EIVI.transaction_type IS NULL OR
403                          EIVI.transaction_type  <> G_TTYPE_CREATE
404                        )
405                 AND  (
406                          ( G_SET_PROCESS_ID IS NULL )
407                           OR
408                          ( EIVI.set_process_id =  G_SET_PROCESS_ID)
409                      )
410                 AND EIVI.process_status = G_PROCESS_STATUS_INITIAL
411                 ;
412 
413         END IF;
414 
415 
416       write_debug (l_proc_name, 'End of  '||l_proc_name);
417     EXCEPTION
418     WHEN OTHERS THEN
419       x_return_status := G_RET_STS_UNEXP_ERROR;
420       x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
421       return;
422     END Validate_Trans_Type;
423 
424 
425     -----------------------------------------------
426     ---  This procedure is used to validate the Entity cols in the
427     ---   interface tables eg. ag_name and ag_id in attr assoc interface table
428     ---
429     -----------------------------------------------
430     PROCEDURE Validate_Entity_Cols (  p_entity         IN VARCHAR2
431                                      ,x_return_status  OUT NOCOPY VARCHAR2
432                                      ,x_return_msg  OUT NOCOPY VARCHAR2
433                                              )
434 
435     IS
436       L_proc_name VARCHAR2(30) :=  'Validate_Entity_Cols';
437       l_msg_name   fnd_new_messages.message_name%type;
438       l_msg_text   fnd_new_messages.message_text%type;
439       l_sysdate     DATE       := SYSDATE;
440 
441     BEGIN
442           write_debug (l_proc_name, 'Start of  '||l_proc_name);
443           x_return_status := G_RET_STS_SUCCESS;
444 
445           l_msg_name := 'EGO_REQ_COLNS_MISSING';
446           FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
447           l_msg_text := FND_MESSAGE.GET;
448 
449 
450           IF p_entity = G_ENTITY_ICC_HEADER THEN
451                 ---- Validate some of the bare essential columns for
452                 ---- every interface table
453 
454 
455                 INSERT INTO MTL_INTERFACE_ERRORS
456                  (
457                     TRANSACTION_ID
458                     ,UNIQUE_ID
459                     ,ORGANIZATION_ID
460                     ,COLUMN_NAME
461                     ,TABLE_NAME
462                     ,MESSAGE_NAME
463                     ,ERROR_MESSAGE
464                     ,bo_identifier
465                     ,ENTITY_IDENTIFIER
466                     ,LAST_UPDATE_DATE
467                     ,LAST_UPDATED_BY
468                     ,CREATION_DATE
469                     ,CREATED_BY
470                     ,LAST_UPDATE_LOGIN
471                     ,REQUEST_ID
472                     ,PROGRAM_APPLICATION_ID
473                     ,PROGRAM_ID
474                     ,PROGRAM_UPDATE_DATE
475                  )
476                  SELECT transaction_id
477                        ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
478                        ,null
479                        ,null
480                        ,G_ENTITY_ICC_HEADER_TAB
481                        ,l_msg_name
482                        ,l_msg_text
483                        ,G_BO_IDENTIFIER_ICC
484                        ,G_ENTITY_ICC_HEADER
485                        ,l_sysdate
486                        ,G_USER_ID
487                        ,l_sysdate
488                        ,G_USER_ID
489                        ,G_LOGIN_ID
490                        ,G_CONC_REQUEST_ID
491                        ,G_PROG_APPL_ID
492                        ,G_PROGRAM_ID
493                        ,l_sysdate
494                 FROM MTL_ITEM_CAT_GRPS_INTERFACE MICGI
495                 WHERE
496                       (   micgi.item_catalog_name is NULL  AND
497                           micgi.item_catalog_group_id   is NULL  AND
498                           micgi.segment1 is NULL  AND micgi.segment14 is NULL AND
499                           micgi.segment2 is NULL  AND micgi.segment15 is NULL AND
500                           micgi.segment3 is NULL  AND micgi.segment16 is NULL AND
501                           micgi.segment4 is NULL  AND micgi.segment17 is NULL AND
502                           micgi.segment5 is NULL  AND micgi.segment18 is NULL AND
503                           micgi.segment6 is NULL  AND micgi.segment19 is NULL AND
504                           micgi.segment7 is NULL  AND micgi.segment20 is NULL AND
505                           micgi.segment8 is NULL  AND
506                           micgi.segment9 is NULL  AND
507                           micgi.segment10 is NULL AND
508                           micgi.segment11 is NULL AND
509                           micgi.segment12 is NULL AND
510                           micgi.segment13 is NULL
511                       )
512                 AND  micgi.process_status = G_PROCESS_STATUS_INITIAL
513                 AND  (
514                          ( G_SET_PROCESS_ID IS NULL )
515                           OR
516                          ( MICGI.set_process_id =  G_SET_PROCESS_ID)
517                      )
518                 ;
519                 write_debug ( l_proc_name, 'rows inserted=>'||SQL%ROWCOUNT);
520 
521                 ---
522                 --- mark the respective records as errors
523                 ---
524                 UPDATE MTL_ITEM_CAT_GRPS_INTERFACE micgi
525                 SET micgi.process_status = G_PROCESS_STATUS_ERROR
526                 WHERE  (   micgi.item_catalog_name is NULL  AND
527                           micgi.item_catalog_group_id   is NULL  AND
528                           micgi.segment1 is NULL  AND micgi.segment14 is NULL AND
529                           micgi.segment2 is NULL  AND micgi.segment15 is NULL AND
530                           micgi.segment3 is NULL  AND micgi.segment16 is NULL AND
531                           micgi.segment4 is NULL  AND micgi.segment17 is NULL AND
532                           micgi.segment5 is NULL  AND micgi.segment18 is NULL AND
533                           micgi.segment6 is NULL  AND micgi.segment19 is NULL AND
534                           micgi.segment7 is NULL  AND micgi.segment20 is NULL AND
535                           micgi.segment8 is NULL  AND
536                           micgi.segment9 is NULL  AND
537                           micgi.segment10 is NULL AND
538                           micgi.segment11 is NULL AND
539                           micgi.segment12 is NULL AND
540                           micgi.segment13 is NULL
541                       )
542                 AND  (
543                          ( G_SET_PROCESS_ID IS NULL )
544                           OR
545                          ( MICGI.set_process_id =  G_SET_PROCESS_ID)
546                      )
547                 AND  micgi.process_status = G_PROCESS_STATUS_INITIAL
548                 ;
549 
550        END IF; --- header
551 
552 
553        IF p_entity = G_ENTITY_ICC_AG_ASSOC THEN
554 
555                     INSERT INTO MTL_INTERFACE_ERRORS
556                      (
557                         TRANSACTION_ID
558                         ,UNIQUE_ID
559                         ,ORGANIZATION_ID
560                         ,COLUMN_NAME
561                         ,TABLE_NAME
562                         ,MESSAGE_NAME
563                         ,ERROR_MESSAGE
564                         ,bo_identifier
565                         ,ENTITY_IDENTIFIER
566                         ,LAST_UPDATE_DATE
567                         ,LAST_UPDATED_BY
568                         ,CREATION_DATE
569                         ,CREATED_BY
570                         ,LAST_UPDATE_LOGIN
571                         ,REQUEST_ID
572                         ,PROGRAM_APPLICATION_ID
573                         ,PROGRAM_ID
574                         ,PROGRAM_UPDATE_DATE
575                  )
576                  SELECT transaction_id
577                        ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
578                        ,null
579                        ,null
580                        ,G_ENTITY_ICC_HEADER_TAB
581                        ,l_msg_name
582                        ,l_msg_text
583                        ,G_BO_IDENTIFIER_ICC
584                        ,G_ENTITY_ICC_AG_ASSOC
585                        ,l_sysdate
586                        ,G_USER_ID
587                        ,l_sysdate
588                        ,G_USER_ID
589                        ,G_LOGIN_ID
590                        ,G_CONC_REQUEST_ID
591                        ,G_PROG_APPL_ID
592                        ,G_PROGRAM_ID
593                        ,l_sysdate
594                  FROM   EGO_ATTR_GRPS_ASSOC_INTERFACE eagai
595                  WHERE  ( (eagai.item_catalog_group_id IS NULL AND
596                           eagai.item_catalog_name IS NULL )
597                            OR
598                           ( eagai.attr_group_name IS NULL AND
599                             eagai.attr_group_id IS NULL )
600                         )
601                 AND  (
602                          ( G_SET_PROCESS_ID IS NULL )
603                           OR
604                          ( eagai.set_process_id =  G_SET_PROCESS_ID)
605                      )
606                  AND  eagai.process_status = G_PROCESS_STATUS_INITIAL
607                 ;
608 
609                 UPDATE EGO_ATTR_GRPS_ASSOC_INTERFACE eagai
610                 SET eagai.process_status = G_PROCESS_STATUS_ERROR
611                 WHERE  ( (eagai.item_catalog_group_id IS NULL AND
612                          eagai.item_catalog_name IS NULL )
613                           OR
614                          ( eagai.attr_group_name IS NULL AND
615                            eagai.attr_group_id IS NULL )
616                        )
617                 AND  (
618                          ( G_SET_PROCESS_ID IS NULL )
619                           OR
620                          ( eagai.set_process_id =  G_SET_PROCESS_ID)
621                      )
622                 AND  eagai.process_status = G_PROCESS_STATUS_INITIAL
623                 ;
624 
625 
626        END IF ; -- ag assoc
627 
628        IF p_entity = G_ENTITY_ICC_FN_PARAM_MAP THEN
629 
630                   INSERT INTO MTL_INTERFACE_ERRORS
631                                  (
632                                     TRANSACTION_ID
633                                     ,UNIQUE_ID
634                                     ,ORGANIZATION_ID
635                                     ,COLUMN_NAME
636                                     ,TABLE_NAME
637                                     ,MESSAGE_NAME
638                                     ,ERROR_MESSAGE
639                                     ,bo_identifier
640                                     ,ENTITY_IDENTIFIER
641                                     ,LAST_UPDATE_DATE
642                                     ,LAST_UPDATED_BY
643                                     ,CREATION_DATE
644                                     ,CREATED_BY
645                                     ,LAST_UPDATE_LOGIN
646                                     ,REQUEST_ID
647                                     ,PROGRAM_APPLICATION_ID
648                                     ,PROGRAM_ID
649                                     ,PROGRAM_UPDATE_DATE
650                                   )
651                  SELECT transaction_id
652                        ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
653                        ,null
654                        ,null
655                        ,G_ENTITY_FUNC_PARAM_MAP_TAB
656                        ,l_msg_name
657                        ,l_msg_text
658                        ,G_BO_IDENTIFIER_ICC
659                        ,G_ENTITY_ICC_FN_PARAM_MAP
660                        ,l_sysdate
661                        ,G_USER_ID
662                        ,l_sysdate
663                        ,G_USER_ID
664                        ,G_LOGIN_ID
665                        ,G_CONC_REQUEST_ID
666                        ,G_PROG_APPL_ID
667                        ,G_PROGRAM_ID
668                        ,l_sysdate
669                  FROM   EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
670                  WHERE  ( (efpmi.item_catalog_group_id IS NULL AND
671                            efpmi.item_catalog_name IS NULL)
672                            OR
673                            (
674                             efpmi.function_name IS NULL AND
675                             efpmi.function_id   IS NULL )
676                             OR
677                            (
678                             efpmi.parameter_name IS NULL AND
679                             efpmi.parameter_id IS NULL )
680                          )
681                 AND  (
682                          ( G_SET_PROCESS_ID IS NULL )
683                           OR
684                          ( efpmi.set_process_id =  G_SET_PROCESS_ID)
685                      )
686                  AND  efpmi.process_status = G_PROCESS_STATUS_INITIAL
687                  ;
688 
689                 UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
690                 SET efpmi.process_status = G_PROCESS_STATUS_ERROR
691                 WHERE  ( (efpmi.item_catalog_group_id IS NULL AND
692                           efpmi.item_catalog_name IS NULL)
693                           OR
694                           (
695                            efpmi.function_name IS NULL AND
696                            efpmi.function_id   IS NULL )
697                            OR
698                           (
699                            efpmi.parameter_name IS NULL AND
700                            efpmi.parameter_id IS NULL )
701                         )
702                 AND  (
703                          ( G_SET_PROCESS_ID IS NULL )
704                           OR
705                          ( efpmi.set_process_id =  G_SET_PROCESS_ID)
706                      )
707                 AND  efpmi.process_status = G_PROCESS_STATUS_INITIAL
708                 ;
709 
710        END IF;
711 
712        IF p_entity = G_ENTITY_ICC_VERSION THEN
713 
714                 ---
715                 --- Added if condition bug 9791391
716                 ---  if the P4T profile is not enabled , error out the version records
717                 ---
718 
719                 IF NOT G_P4TP_PROFILE_ENABLED THEN
720 
721                     l_msg_name := 'EGO_P4T_PROFILE_DISABLED_ERROR';
722                     FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
723                     fnd_message.set_token('ENTITY_NAME' , G_ENTITY_ICC_VERSION);
724                     l_msg_text := FND_MESSAGE.GET;
725 
726 
727                     --- Versioning interface columns
728                     ---
729                     INSERT INTO MTL_INTERFACE_ERRORS
730                      (
731                         TRANSACTION_ID
732                         ,UNIQUE_ID
733                         ,ORGANIZATION_ID
734                         ,COLUMN_NAME
735                         ,TABLE_NAME
736                         ,MESSAGE_NAME
737                         ,ERROR_MESSAGE
738                         ,bo_identifier
739                         ,ENTITY_IDENTIFIER
740                         ,LAST_UPDATE_DATE
741                         ,LAST_UPDATED_BY
742                         ,CREATION_DATE
743                         ,CREATED_BY
744                         ,LAST_UPDATE_LOGIN
745                         ,REQUEST_ID
746                         ,PROGRAM_APPLICATION_ID
747                         ,PROGRAM_ID
748                         ,PROGRAM_UPDATE_DATE
749                      )
750                      SELECT transaction_id
751                            ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
752                            ,null
753                            ,null
754                            ,G_ENTITY_ICC_VERS_TAB
755                            ,l_msg_name
756                            ,l_msg_text
757                            ,G_BO_IDENTIFIER_ICC
758                            ,G_ENTITY_ICC_VERSION
759                            ,l_sysdate
760                            ,G_USER_ID
761                            ,l_sysdate
762                            ,G_USER_ID
763                            ,G_LOGIN_ID
764                            ,G_CONC_REQUEST_ID
765                            ,G_PROG_APPL_ID
766                            ,G_PROGRAM_ID
767                            ,l_sysdate
768                     FROM EGO_ICC_VERS_INTERFACE eivi
769                     where (
770                              ( G_SET_PROCESS_ID IS NULL )
771                               OR
772                              ( eivi.set_process_id =  G_SET_PROCESS_ID)
773                          )
774                      AND  eivi.process_status = G_PROCESS_STATUS_INITIAL
775                      ;
776 
777                     UPDATE EGO_ICC_VERS_INTERFACE eivi
778                     SET eivi.process_status = G_PROCESS_STATUS_ERROR
779                     where (
780                              ( G_SET_PROCESS_ID IS NULL )
781                               OR
782                              ( eivi.set_process_id =  G_SET_PROCESS_ID)
783                          )
784                      AND  eivi.process_status = G_PROCESS_STATUS_INITIAL
785                      ;
786                 END IF;
787                 --- end bug 9791391
788 
789 
790 
791 
792 
793                 l_msg_name := 'EGO_REQ_COLNS_MISSING';
794                 FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
795                 l_msg_text := FND_MESSAGE.GET;
796 
797 
798                 --- Versioning interface columns
799                 ---
800                 INSERT INTO MTL_INTERFACE_ERRORS
801                  (
802                     TRANSACTION_ID
803                     ,UNIQUE_ID
804                     ,ORGANIZATION_ID
805                     ,COLUMN_NAME
806                     ,TABLE_NAME
807                     ,MESSAGE_NAME
808                     ,ERROR_MESSAGE
809                     ,bo_identifier
810                     ,ENTITY_IDENTIFIER
811                     ,LAST_UPDATE_DATE
812                     ,LAST_UPDATED_BY
813                     ,CREATION_DATE
814                     ,CREATED_BY
815                     ,LAST_UPDATE_LOGIN
816                     ,REQUEST_ID
817                     ,PROGRAM_APPLICATION_ID
818                     ,PROGRAM_ID
819                     ,PROGRAM_UPDATE_DATE
820                  )
821                  SELECT transaction_id
822                        ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
823                        ,null
824                        ,null
825                        ,G_ENTITY_ICC_VERS_TAB
826                        ,l_msg_name
827                        ,l_msg_text
828                        ,G_BO_IDENTIFIER_ICC
829                        ,G_ENTITY_ICC_VERSION
830                        ,l_sysdate
831                        ,G_USER_ID
832                        ,l_sysdate
833                        ,G_USER_ID
834                        ,G_LOGIN_ID
835                        ,G_CONC_REQUEST_ID
836                        ,G_PROG_APPL_ID
837                        ,G_PROGRAM_ID
838                        ,l_sysdate
839                 FROM EGO_ICC_VERS_INTERFACE eivi
840                 where (
841                           ( eivi.item_catalog_name IS NULL AND
842                             eivi.item_catalog_group_id  IS NULL
843                           )
844                       )
845                 AND  (
846                          ( G_SET_PROCESS_ID IS NULL )
847                           OR
848                          ( eivi.set_process_id =  G_SET_PROCESS_ID)
849                      )
850                  AND  eivi.process_status = G_PROCESS_STATUS_INITIAL
851                  ;
852 
853                 UPDATE EGO_ICC_VERS_INTERFACE eivi
854                 SET eivi.process_status = G_PROCESS_STATUS_ERROR
855                 where (
856                           ( eivi.item_catalog_name IS NULL AND
857                             eivi.item_catalog_group_id  IS NULL
858                           )
859                       )
860                 AND  (
861                          ( G_SET_PROCESS_ID IS NULL )
862                           OR
863                          ( eivi.set_process_id =  G_SET_PROCESS_ID)
864                      )
865                  AND  eivi.process_status = G_PROCESS_STATUS_INITIAL
866                  ;
867 
868 
869           l_msg_name := 'EGO_ICC_VER_SEQ_NO_INVALID';
870           FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
871           l_msg_text := FND_MESSAGE.GET;
872 
873 
874           --- Insert errors for ICC Name
875           ---
876           INSERT INTO MTL_INTERFACE_ERRORS
877            (
878               TRANSACTION_ID
879               ,UNIQUE_ID
880               ,ORGANIZATION_ID
881               ,COLUMN_NAME
882               ,TABLE_NAME
883               ,MESSAGE_NAME
884               ,ERROR_MESSAGE
885               ,BO_IDENTIFIER
886               ,ENTITY_IDENTIFIER
887               ,LAST_UPDATE_DATE
888               ,LAST_UPDATED_BY
889               ,CREATION_DATE
890               ,CREATED_BY
891               ,LAST_UPDATE_LOGIN
892               ,REQUEST_ID
893               ,PROGRAM_APPLICATION_ID
894               ,PROGRAM_ID
895               ,PROGRAM_UPDATE_DATE
896            )
897             SELECT transaction_id
898                   ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
899                   ,null
900                   ,null
901                   ,G_ENTITY_ICC_VERS_TAB
902                   ,l_msg_name
903                   ,l_msg_text
904                   ,G_BO_IDENTIFIER_ICC
905                   ,G_ENTITY_ICC_VERSION
906                   ,l_sysdate
907                   ,G_USER_ID
908                   ,l_sysdate
909                   ,G_USER_ID
910                   ,G_LOGIN_ID
911                   ,G_CONC_REQUEST_ID
912                   ,G_PROG_APPL_ID
913                   ,G_PROGRAM_ID
914                   ,l_sysdate
915              FROM  ego_icc_vers_interface eivi
916              WHERE 1=1
917              AND   ---( eivi.ver_seq_no <= 0      ---- commented bug 9752139, moved to row by row
918                    ---   OR
919                      eivi.ver_seq_no IS NULL
920                    ---)
921              AND   eivi.transaction_id IS NOT NULL
922              AND   eivi.process_status = G_PROCESS_STATUS_INITIAL
923              AND  (
924                    ( G_SET_PROCESS_ID IS NULL )
925                    OR
926                    ( eivi.set_process_id =  G_SET_PROCESS_ID)
927                   );
928 
929 
930             UPDATE EGO_ICC_VERS_INTERFACE eivi
931             SET eivi.process_status = G_PROCESS_STATUS_ERROR
932            WHERE 1=1
933              AND   ---( eivi.ver_seq_no <= 0      ---- commented bug 9752139, moved to row by row
934                    ---   OR
935                      eivi.ver_seq_no IS NULL
936                    ---)
937              AND   eivi.transaction_id IS NOT NULL
938              AND   eivi.process_status = G_PROCESS_STATUS_INITIAL
939              AND  (
940                    ( G_SET_PROCESS_ID IS NULL )
941                    OR
942                    ( eivi.set_process_id =  G_SET_PROCESS_ID)
943               );
944 
945 
946        END IF; --- versioning interface
947 
948       write_debug (l_proc_name, 'End of  '||l_proc_name);
949     EXCEPTION
950     WHEN OTHERS THEN
951       x_return_status := G_RET_STS_UNEXP_ERROR;
952       x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
953     END Validate_Entity_Cols;
954 
955 
956     -----------------------------------------------
957     --- This procedure is used to validate the required columns
958     --- or bare essential meta data informaiton in the
959     --- interface tables
960     -----------------------------------------------
961 
962 
963 
964 
965     PROCEDURE Validate_Name_ID_Cols ( p_entity         IN VARCHAR2
966                                      ,x_return_status  OUT NOCOPY VARCHAR2
967                                      ,x_return_msg     OUT NOCOPY VARCHAR2
968                                      )
969 
970     IS
971       l_proc_name   varchar2(30) :=  'Validate_Name_ID_Cols';
972       l_msg_name    fnd_new_messages.message_name%type;
973       l_msg_text    fnd_new_messages.message_text%type;
974       l_msg_name2   fnd_new_messages.message_name%type;
975       l_msg_text2   fnd_new_messages.message_text%type;
976       l_msg_name3   fnd_new_messages.message_name%type;
977       l_msg_text3   fnd_new_messages.message_text%type;
978       l_msg_name4   fnd_new_messages.message_name%type;
979       l_msg_text4   fnd_new_messages.message_text%type;
980       l_msg_name5   fnd_new_messages.message_name%type;
981       l_msg_text5   fnd_new_messages.message_text%type;
982 
983 
984       l_sysdate     DATE       := SYSDATE;
985       l_item_data_level VARCHAR2(50) := 'ITEM_LEVEL';
986 
987 
988     BEGIN
989       write_debug (l_proc_name, 'Start of  '||l_proc_name);
990       write_debug (l_proc_name, 'p_entity=>'||p_entity);
991 
992       x_return_status := G_RET_STS_SUCCESS;
993 
994        IF p_entity = G_ENTITY_ICC_HEADER THEN
995            --- ICC table , ICC Name
996 
997            UPDATE mtl_item_cat_grps_interface micgi
998            SET    item_catalog_name = ( select icc_kfv.concatenated_segments
999                                         from   mtl_item_catalog_groups_kfv icc_kfv
1000                                         where icc_kfv.item_catalog_group_id = micgi.item_catalog_group_id
1001                                       )
1002            WHERE micgi.item_catalog_group_id IS NOT NULL
1003            AND   micgi.process_status = G_PROCESS_STATUS_INITIAL
1004            AND  (
1005                   ( G_SET_PROCESS_ID IS NULL )
1006                     OR
1007                   ( MICGI.set_process_id =  G_SET_PROCESS_ID)
1008                )
1009            ;
1010 
1011            write_debug (l_proc_name, '1');
1012 
1013 
1014 
1015            UPDATE mtl_item_cat_grps_interface micgi
1016            SET    micgi.item_catalog_group_id = ( select icc_kfv.item_catalog_group_id
1017                                                   from   mtl_item_catalog_groups_kfv icc_kfv
1018                                                   where icc_kfv.concatenated_segments = micgi.item_catalog_name
1019                                                 )
1020            WHERE micgi.item_catalog_name IS NOT NULL
1021            AND   micgi.item_catalog_group_id IS NULL
1022            AND   micgi.process_status = G_PROCESS_STATUS_INITIAL
1023            AND  (
1024                   ( G_SET_PROCESS_ID IS NULL )
1025                     OR
1026                   ( MICGI.set_process_id =  G_SET_PROCESS_ID)
1027                )
1028            ;
1029 
1030            write_debug (l_proc_name, '2');
1031 
1032           --- insert into mtl_interface_errors
1033           ---
1034 
1035           l_msg_name := 'EGO_ITEMCATALOG_INVALID';
1036           FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
1037           l_msg_text := FND_MESSAGE.GET;
1038 
1039           write_debug (l_proc_name, '3');
1040 
1041           --- Insert errors for ICC Name
1042           ---
1043           INSERT INTO MTL_INTERFACE_ERRORS
1044            (
1045               TRANSACTION_ID
1046               ,UNIQUE_ID
1047               ,ORGANIZATION_ID
1048               ,COLUMN_NAME
1049               ,TABLE_NAME
1050               ,MESSAGE_NAME
1051               ,ERROR_MESSAGE
1052               ,BO_IDENTIFIER
1053               ,ENTITY_IDENTIFIER
1054               ,LAST_UPDATE_DATE
1055               ,LAST_UPDATED_BY
1056               ,CREATION_DATE
1057               ,CREATED_BY
1058               ,LAST_UPDATE_LOGIN
1059               ,REQUEST_ID
1060               ,PROGRAM_APPLICATION_ID
1061               ,PROGRAM_ID
1062               ,PROGRAM_UPDATE_DATE
1063            )
1064             SELECT transaction_id
1065                   ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
1066                   ,null
1067                   ,null
1068                   ,G_ENTITY_ICC_HEADER_TAB
1069                   ,l_msg_name
1070                   ,l_msg_text
1071                   ,G_BO_IDENTIFIER_ICC
1072                   ,G_ENTITY_ICC_HEADER
1073                   ,l_sysdate
1074                   ,G_USER_ID
1075                   ,l_sysdate
1076                   ,G_USER_ID
1077                   ,G_LOGIN_ID
1078                   ,G_CONC_REQUEST_ID
1079                   ,G_PROG_APPL_ID
1080                   ,G_PROGRAM_ID
1081                   ,l_sysdate
1082              FROM  mtl_item_cat_grps_interface micgi
1083              WHERE micgi.item_catalog_name IS NULL
1084              AND   micgi.item_catalog_group_id IS NOT NULL
1085              AND   micgi.transaction_id IS NOT NULL
1086              AND   micgi.process_status = G_PROCESS_STATUS_INITIAL
1087              AND  (
1088                    ( G_SET_PROCESS_ID IS NULL )
1089                    OR
1090                    ( micgi.set_process_id =  G_SET_PROCESS_ID)
1091                   ) ;
1092 
1093            write_debug (l_proc_name, '4');
1094            --- update status flag in ICC interface table
1095 
1096            UPDATE MTL_ITEM_CAT_GRPS_INTERFACE micgi
1097             set process_status = G_PROCESS_STATUS_ERROR
1098            WHERE micgi.item_catalog_group_id is NOT NULL
1099            AND   micgi.item_catalog_name IS NULL
1100            and   micgi.transaction_id IS NOT NULL
1101            AND   micgi.process_status = G_PROCESS_STATUS_INITIAL
1102            AND  (
1103                    ( G_SET_PROCESS_ID IS NULL )
1104                    OR
1105                    ( MICGI.set_process_id =  G_SET_PROCESS_ID)
1106                 )
1107               ;
1108 
1109             write_debug (l_proc_name, '5');
1110            /*****************************************
1111            --- ICC Parent id , ICC Parent Name
1112            ---
1113            /*****************************************/
1114 
1115            UPDATE mtl_item_cat_grps_interface micgi
1116            SET    parent_catalog_group_name = ( select icc_kfv.concatenated_segments
1117                                                 from   mtl_item_catalog_groups_kfv icc_kfv
1118                                                 where icc_kfv.item_catalog_group_id = micgi.parent_catalog_group_id
1119                                                )
1120            WHERE micgi.parent_catalog_group_id IS NOT NULL
1121            AND   micgi.process_status = G_PROCESS_STATUS_INITIAL
1122            AND  (
1123                   ( G_SET_PROCESS_ID IS NULL )
1124                     OR
1125                   ( MICGI.set_process_id =  G_SET_PROCESS_ID)
1126                )
1127            ;
1128 
1129            write_debug (l_proc_name, '6');
1130 
1131            UPDATE mtl_item_cat_grps_interface micgi
1132            SET    micgi.parent_catalog_group_id = ( select icc_kfv.item_catalog_group_id
1133                                                   from   mtl_item_catalog_groups_kfv icc_kfv
1134                                                   where icc_kfv.concatenated_segments = micgi.parent_catalog_group_name
1135                                                 )
1136            WHERE micgi.parent_catalog_group_name IS NOT NULL
1137            AND   micgi.parent_catalog_group_id IS NULL
1138            AND   micgi.process_status = G_PROCESS_STATUS_INITIAL
1139            AND  (
1140                   ( G_SET_PROCESS_ID IS NULL )
1141                     OR
1142                   ( MICGI.set_process_id =  G_SET_PROCESS_ID)
1143                )
1144            ;
1145 
1146            write_debug (l_proc_name, '7');
1147 
1148           --- insert into mtl_interface_errors
1149           ---
1150 
1151           l_msg_name := 'EGO_ICC_PARENT_INVALID';
1152           FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
1153           l_msg_text := FND_MESSAGE.GET;
1154 
1155           write_debug (l_proc_name, '8');
1156           --- Insert errors for ICC Name
1157           ---
1158           INSERT INTO MTL_INTERFACE_ERRORS
1159            (
1160               TRANSACTION_ID
1161               ,UNIQUE_ID
1162               ,ORGANIZATION_ID
1163               ,COLUMN_NAME
1164               ,TABLE_NAME
1165               ,MESSAGE_NAME
1166               ,ERROR_MESSAGE
1167               ,BO_IDENTIFIER
1168               ,ENTITY_IDENTIFIER
1169               ,LAST_UPDATE_DATE
1170               ,LAST_UPDATED_BY
1171               ,CREATION_DATE
1172               ,CREATED_BY
1173               ,LAST_UPDATE_LOGIN
1174               ,REQUEST_ID
1175               ,PROGRAM_APPLICATION_ID
1176               ,PROGRAM_ID
1177               ,PROGRAM_UPDATE_DATE
1178            )
1179             SELECT transaction_id
1180                   ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
1181                   ,null
1182                   ,null
1183                   ,G_ENTITY_ICC_HEADER_TAB
1184                   ,l_msg_name
1185                   ,l_msg_text
1186                   ,G_BO_IDENTIFIER_ICC
1187                   ,G_ENTITY_ICC_HEADER
1188                   ,l_sysdate
1189                   ,G_USER_ID
1190                   ,l_sysdate
1191                   ,G_USER_ID
1192                   ,G_LOGIN_ID
1193                   ,G_CONC_REQUEST_ID
1194                   ,G_PROG_APPL_ID
1195                   ,G_PROGRAM_ID
1196                   ,l_sysdate
1197              FROM  mtl_item_cat_grps_interface micgi
1198              WHERE micgi.parent_catalog_group_name IS NULL
1199              AND   micgi.parent_catalog_group_id IS NOT NULL
1200              AND   micgi.transaction_id IS NOT NULL
1201              AND   micgi.process_status = G_PROCESS_STATUS_INITIAL
1202              AND  (
1203                    ( G_SET_PROCESS_ID IS NULL )
1204                    OR
1205                    ( micgi.set_process_id =  G_SET_PROCESS_ID)
1206                   ) ;
1207 
1208            write_debug (l_proc_name, '9');
1209            --- update status flag in ICC interface table for invalid parent ICC  names
1210 
1211            UPDATE MTL_ITEM_CAT_GRPS_INTERFACE micgi
1212             set process_status = G_PROCESS_STATUS_ERROR
1213            WHERE micgi.parent_catalog_group_name IS NULL
1214            AND   micgi.parent_catalog_group_id is NOT NULL
1215            and   micgi.transaction_id IS NOT NULL
1216            AND   micgi.process_status = G_PROCESS_STATUS_INITIAL
1217            AND  (
1218                    ( G_SET_PROCESS_ID IS NULL )
1219                    OR
1220                    ( MICGI.set_process_id =  G_SET_PROCESS_ID)
1221                 )
1222               ;
1223 
1224            write_debug (l_proc_name, '10');
1225 
1226        END IF;     -- entity = header
1227 
1228 
1229 
1230        IF p_entity = G_ENTITY_ICC_AG_ASSOC THEN
1231            --- Update the AG Table, attr_group_name
1232            ---
1233 
1234            UPDATE EGO_ATTR_GRPS_ASSOC_INTERFACE EAGAI
1235            SET attr_group_name = ( select eagv.attr_group_name
1236                                  from ego_attr_groups_v EAGv
1237                                  where EAGv.attr_group_id = EAGAI.attr_group_id
1238                                )
1239            WHERE eagai.attr_group_id IS NOT NULL
1240            AND   eagai.process_status = G_PROCESS_STATUS_INITIAL
1241            AND  (
1242                   ( G_SET_PROCESS_ID IS NULL )
1243                     OR
1244                   ( eagai.set_process_id =  G_SET_PROCESS_ID)
1245                )
1246            ;
1247            write_debug (l_proc_name, '11');
1248 
1249            --- Update the AG Table , attr_group_id
1250            ---
1251 
1252            UPDATE EGO_ATTR_GRPS_ASSOC_INTERFACE EAGAI
1253            SET attr_group_id = ( select eagv.attr_group_id
1254                                  from ego_attr_groups_v EAGv
1255                                  where EAGv.attr_group_name = EAGAI.attr_group_name
1256                                )
1257            WHERE eagai.attr_group_id IS NULL
1258            AND   eagai.attr_group_name IS NOT NULL
1259            AND   eagai.process_status = G_PROCESS_STATUS_INITIAL
1260            AND  (
1261                   ( G_SET_PROCESS_ID IS NULL )
1262                     OR
1263                   ( eagai.set_process_id =  G_SET_PROCESS_ID)
1264                )
1265            ;
1266 
1267            write_debug (l_proc_name, '12');
1268            --- Update AG table, ICC Name
1269            ---
1270            UPDATE EGO_ATTR_GRPS_ASSOC_INTERFACE EAGAI
1271            SET  eagai.item_catalog_name = ( select icc_kfv.concatenated_segments
1272                                                   from   mtl_item_catalog_groups_kfv icc_kfv
1273                                                   where icc_kfv.item_catalog_group_id = eagai.item_catalog_group_id
1274                                                 )
1275            WHERE eagai.item_catalog_group_id IS NOT NULL
1276            AND   eagai.process_status = G_PROCESS_STATUS_INITIAL
1277            AND  (
1278                   ( G_SET_PROCESS_ID IS NULL )
1279                     OR
1280                   ( eagai.set_process_id =  G_SET_PROCESS_ID)
1281                )
1282            ;
1283 
1284            write_debug (l_proc_name, '13');
1285 
1286            ---Update AG table, ICC id
1287            UPDATE EGO_ATTR_GRPS_ASSOC_INTERFACE EAGAI
1288            SET  eagai.item_catalog_group_id = ( select icc_kfv.item_catalog_group_id
1289                                                   from   mtl_item_catalog_groups_kfv icc_kfv
1290                                                   where icc_kfv.concatenated_segments = eagai.item_catalog_name
1291                                                 )
1292            WHERE eagai.item_catalog_name IS NOT NULL
1293            AND   eagai.item_catalog_group_id IS NULL
1294            AND   eagai.process_status = G_PROCESS_STATUS_INITIAL
1295            AND  (
1296                   ( G_SET_PROCESS_ID IS NULL )
1297                     OR
1298                   ( eagai.set_process_id =  G_SET_PROCESS_ID)
1299                )
1300            ;
1301 
1302            write_debug (l_proc_name, '14');
1303 
1304           --- insert into mtl_interface_errors
1305           ---
1306 
1307           l_msg_name := 'EGO_ITEMCATALOG_INVALID';
1308           FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
1309           l_msg_text := FND_MESSAGE.GET;
1310 
1311           INSERT INTO MTL_INTERFACE_ERRORS
1312            (
1313               TRANSACTION_ID
1314               ,UNIQUE_ID
1315               ,ORGANIZATION_ID
1316               ,COLUMN_NAME
1317               ,TABLE_NAME
1318               ,MESSAGE_NAME
1319               ,ERROR_MESSAGE
1320               ,BO_IDENTIFIER
1321               ,ENTITY_IDENTIFIER
1322               ,LAST_UPDATE_DATE
1323               ,LAST_UPDATED_BY
1324               ,CREATION_DATE
1325               ,CREATED_BY
1326               ,LAST_UPDATE_LOGIN
1327               ,REQUEST_ID
1328               ,PROGRAM_APPLICATION_ID
1329               ,PROGRAM_ID
1330               ,PROGRAM_UPDATE_DATE
1331            )
1332            SELECT transaction_id
1333                  ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
1334                  ,null
1335                  ,null
1336                  ,G_ENTITY_ICC_AG_ASSOC_TAB
1337                  ,l_msg_name
1338                  ,l_msg_text
1339                  ,G_BO_IDENTIFIER_ICC
1340                  ,G_ENTITY_ICC_AG_ASSOC
1341                  ,l_sysdate
1342                  ,G_USER_ID
1343                  ,l_sysdate
1344                  ,G_USER_ID
1345                  ,G_LOGIN_ID
1346                  ,G_CONC_REQUEST_ID
1347                  ,G_PROG_APPL_ID
1348                  ,G_PROGRAM_ID
1349                  ,l_sysdate
1350           FROM  EGO_ATTR_GRPS_ASSOC_INTERFACE eagai
1351           WHERE eagai.item_catalog_name IS NULL
1352           OR    eagai.item_catalog_group_id IS NULL
1353           AND   eagai.transaction_id IS NOT NULL
1354           AND   eagai.process_status = G_PROCESS_STATUS_INITIAL
1355           AND  (
1356                   ( G_SET_PROCESS_ID IS NULL )
1357                   OR
1358                   ( eagai.set_process_id =  G_SET_PROCESS_ID)
1359                );
1360 
1361          write_debug (l_proc_name, '15');
1362            l_msg_name2 := 'EGO_AG_NAME_MISSING';
1363            FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name2 );
1364            l_msg_text2 := FND_MESSAGE.GET;
1365 
1366          write_debug (l_proc_name, '16');
1367 
1368           INSERT INTO MTL_INTERFACE_ERRORS
1369            (
1370               TRANSACTION_ID
1371               ,UNIQUE_ID
1372               ,ORGANIZATION_ID
1373               ,COLUMN_NAME
1374               ,TABLE_NAME
1375               ,MESSAGE_NAME
1376               ,ERROR_MESSAGE
1377               ,bo_identifier
1378               ,ENTITY_IDENTIFIER
1379               ,LAST_UPDATE_DATE
1380               ,LAST_UPDATED_BY
1381               ,CREATION_DATE
1382               ,CREATED_BY
1383               ,LAST_UPDATE_LOGIN
1384               ,REQUEST_ID
1385               ,PROGRAM_APPLICATION_ID
1386               ,PROGRAM_ID
1387               ,PROGRAM_UPDATE_DATE
1388            )
1389            SELECT transaction_id
1390                  ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
1391                  ,null
1392                  ,null
1393                  ,G_ENTITY_ICC_AG_ASSOC_TAB
1394                  ,l_msg_name2
1395                  ,l_msg_text2
1396                  ,G_BO_IDENTIFIER_ICC
1397                  ,G_ENTITY_ICC_AG_ASSOC
1398                  ,l_sysdate
1399                  ,G_USER_ID
1400                  ,l_sysdate
1401                  ,G_USER_ID
1402                  ,G_LOGIN_ID
1403                  ,G_CONC_REQUEST_ID
1404                  ,G_PROG_APPL_ID
1405                  ,G_PROGRAM_ID
1406                  ,l_sysdate
1407           FROM  EGO_ATTR_GRPS_ASSOC_INTERFACE eagai
1408           WHERE ( eagai.attr_group_name IS NULL
1409                     OR
1410                   eagai.attr_group_id IS NULL
1411                 )
1412           AND   eagai.transaction_id IS NOT NULL
1413           AND   eagai.process_status = G_PROCESS_STATUS_INITIAL
1414           AND  (
1415                   ( G_SET_PROCESS_ID IS NULL )
1416                   OR
1417                   ( eagai.set_process_id =  G_SET_PROCESS_ID)
1418                )
1419               ;
1420 
1421           write_debug (l_proc_name, '17');
1422           --- update status flag in interface table
1423           ---
1424           UPDATE EGO_ATTR_GRPS_ASSOC_INTERFACE eagai
1425           set process_status = G_PROCESS_STATUS_ERROR
1426           WHERE eagai.item_catalog_name IS NULL
1427           OR    eagai.item_catalog_group_id IS NULL
1428           OR    eagai.attr_group_name IS NULL
1429           OR    eagai.attr_group_id IS NULL
1430           AND   eagai.transaction_id IS NOT NULL
1431           AND   eagai.process_status = G_PROCESS_STATUS_INITIAL
1432           AND  (
1433                   ( G_SET_PROCESS_ID IS NULL )
1434                   OR
1435                   ( eagai.set_process_id =  G_SET_PROCESS_ID)
1436                )
1437                ;
1438          write_debug (l_proc_name, '18');
1439        END IF; --- entity = AG Association
1440 
1441 
1442        IF p_entity = G_ENTITY_ICC_FN_PARAM_MAP THEN
1443            ---- Validation for the func_param_interface
1444            ----
1445 
1446 
1447            --- ICC Name
1448            UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1449            SET  efpmi.item_catalog_name = ( select icc_kfv.concatenated_segments
1450                                             from   mtl_item_catalog_groups_kfv icc_kfv
1451                                              where icc_kfv.item_catalog_group_id = efpmi.item_catalog_group_id
1452                                           )
1453            WHERE efpmi.item_catalog_group_id IS NOT NULL
1454            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1455            AND  (
1456                    ( G_SET_PROCESS_ID IS NULL )
1457                    OR
1458                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1459                 )
1460                 ;
1461 
1462 
1463            write_debug (l_proc_name, '19');
1464            -- ICC id
1465 
1466            UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1467            SET  efpmi.item_catalog_group_id = ( select icc_kfv.item_catalog_group_id
1468                                                from   mtl_item_catalog_groups_kfv icc_kfv
1469                                                where icc_kfv.concatenated_segments = efpmi.item_catalog_name
1470                                              )
1471            WHERE efpmi.item_catalog_name IS NOT NULL
1472            AND   efpmi.item_catalog_group_id IS NULL
1473            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1474            AND  (
1475                    ( G_SET_PROCESS_ID IS NULL )
1476                    OR
1477                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1478                 )
1479                 ;
1480           write_debug (l_proc_name, '20');
1481 
1482 
1483 
1484            --- Get the Attr group name
1485            ---
1486            UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1487            set    efpmi.attr_group_name =(  SELECT agv.attr_group_id
1488                                            FROM ego_attr_groups_v agv,
1489                                                    ego_obj_attr_grp_assocs_v oagv,
1490                                                    ego_catalog_groups_v cg
1491                                              WHERE oagv.attr_group_id = agv.attr_group_id
1492                                                AND agv.attr_group_id = EFPMI.ATTR_GROUP_ID
1493                                                AND cg.catalog_group_id = oagv.classification_code
1494                                                AND oagv.object_id = g_item_obj_id
1495                                                and oagv.data_level_int_name = l_item_data_level
1496                                                AND oagv.classification_code
1497                                                IN (
1498                                                    SELECT TO_CHAR (item_catalog_group_id)
1499                                                    FROM mtl_item_catalog_groups_b
1500                                                    CONNECT BY PRIOR parent_catalog_group_id =
1501                                                                        item_catalog_group_id
1502                                                    START WITH item_catalog_group_id = EFPMI.ITEM_CATALOG_GROUP_ID
1503                                                   )
1504                                           )
1505            WHERE efpmi.attr_group_id IS NOT NULL
1506            AND   efpmi.item_catalog_group_id is not null
1507            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1508            AND  (
1509                    ( G_SET_PROCESS_ID IS NULL )
1510                    OR
1511                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1512                 )
1513                 ;
1514 
1515            write_debug (l_proc_name, '21');
1516            -- Attr Group id
1517 
1518            UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1519            set    efpmi.attr_group_id = (  SELECT agv.attr_group_id
1520                                            FROM ego_attr_groups_v agv,
1521                                                    ego_obj_attr_grp_assocs_v oagv,
1522                                                    ego_catalog_groups_v cg
1523                                              WHERE oagv.attr_group_id = agv.attr_group_id
1524                                                AND agv.attr_group_name = EFPMI.ATTR_GROUP_NAME
1525                                                AND cg.catalog_group_id = oagv.classification_code
1526                                                AND oagv.object_id = g_item_obj_id
1527                                                and oagv.data_level_int_name = l_item_data_level
1528                                                AND oagv.classification_code
1529                                                IN (
1530                                                    SELECT TO_CHAR (item_catalog_group_id)
1531                                                    FROM mtl_item_catalog_groups_b
1532                                                    CONNECT BY PRIOR parent_catalog_group_id =
1533                                                                        item_catalog_group_id
1534                                                    START WITH item_catalog_group_id = EFPMI.ITEM_CATALOG_GROUP_ID
1535                                                   )
1536                                           )
1537            WHERE efpmi.attr_group_name IS NOT NULL
1538            AND   efpmi.attr_group_id IS NULL
1539            AND   efpmi.item_catalog_group_id IS NOT NULL
1540            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1541            AND  (
1542                    ( G_SET_PROCESS_ID IS NULL )
1543                    OR
1544                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1545                 )
1546                 ;
1547 
1548 
1549            write_debug (l_proc_name, '22');
1550            -- Attribute  name
1551 
1552            UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1553            set    efpmi.attr_name = (  SELECT eav.attr_name
1554                                        FROM ego_attrs_v eav
1555                                        WHERE eav.attr_id = efpmi.attr_id
1556                                        AND   eav.attr_group_name = efpmi.attr_group_name
1557                                     )
1558            WHERE efpmi.attr_name IS NULL
1559            AND   efpmi.attr_id IS NOT NULL
1560            AND   efpmi.attr_group_name IS NOT NULL
1561            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1562            AND  (
1563                    ( G_SET_PROCESS_ID IS NULL )
1564                    OR
1565                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1566                 )
1567                 ;
1568 
1569            write_debug (l_proc_name, '23');
1570            --- Attr ID
1571            ---
1572            UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1573            set    efpmi.attr_id = ( select eav.attr_id
1574                                     from ego_attrs_v eav
1575                                     where eav.attr_name = efpmi.attr_name
1576                                     and   eav.attr_group_name = efpmi.attr_group_name
1577                                   )
1578            WHERE efpmi.attr_id is null
1579            AND   efpmi.attr_name IS NOT NULL
1580            AND   efpmi.attr_group_name IS NOT NULL
1581            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1582            AND  (
1583                    ( G_SET_PROCESS_ID IS NULL )
1584                    OR
1585                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1586                 )
1587                 ;
1588 
1589            write_debug (l_proc_name, '24');
1590            --- Function name
1591            ---
1592            UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1593            set    efpmi.function_name = (  select efv.internal_name
1594                                        from ego_functions_v efv
1595                                        where efv.function_id = efv.function_id
1596                                     )
1597            WHERE efpmi.function_name IS NULL
1598            AND   efpmi.function_id IS NOT NULL
1599            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1600            AND  (
1601                    ( G_SET_PROCESS_ID IS NULL )
1602                    OR
1603                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1604                 )
1605                 ;
1606 
1607            write_debug (l_proc_name, '25');
1608            --- Function id
1609            ---
1610            UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1611            set    efpmi.function_id = ( select efv.function_id
1612                                         from ego_functions_v efv
1613                                         where efv.internal_name = efpmi.function_name
1614                                        )
1615            WHERE efpmi.function_id IS NULL
1616            AND   efpmi.function_name IS NOT NULL
1617            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1618            AND  (
1619                    ( G_SET_PROCESS_ID IS NULL )
1620                    OR
1621                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1622                 )
1623                 ;
1624 
1625            write_debug (l_proc_name, '26');
1626 
1627            UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1628            set    efpmi.parameter_id = ( select efpb.func_param_id
1629                                         from ego_func_params_b efpb
1630                                         where efpb.internal_name = efpmi.parameter_name
1631                                         and   efpb.function_id = efpmi.function_id
1632                                        )
1633            WHERE efpmi.parameter_id IS NULL
1634            AND   efpmi.parameter_name IS NOT NULL
1635            AND   efpmi.function_id IS NOT NULL
1636            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1637            AND  (
1638                    ( G_SET_PROCESS_ID IS NULL )
1639                    OR
1640                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1641                 )
1642                 ;
1643 
1644            write_debug (l_proc_name, '27');
1645 
1646            UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1647            set    efpmi.parameter_name = ( select efpb.internal_name
1648                                         from ego_func_params_b efpb
1649                                         where efpb.func_param_id = efpmi.parameter_id
1650                                         and   efpb.function_id = efpmi.function_id
1651                                        )
1652            WHERE efpmi.parameter_name IS NULL
1653            AND   efpmi.parameter_id IS NOT NULL
1654            AND   efpmi.function_id IS NOT NULL
1655            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1656            AND  (
1657                    ( G_SET_PROCESS_ID IS NULL )
1658                    OR
1659                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1660                 )
1661                 ;
1662 
1663 
1664            write_debug (l_proc_name, '28');
1665            --- insert into mtl_interface_errors
1666            ---
1667 
1668            l_msg_name := 'EGO_ITEMCATALOG_INVALID';
1669            FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
1670            l_msg_text := FND_MESSAGE.GET;
1671 
1672            write_debug (l_proc_name, '29');
1673            l_msg_name2 := 'EGO_AG_NAME_MISSING';
1674            FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name2 );
1675            l_msg_text2 := FND_MESSAGE.GET;
1676 
1677 
1678            l_msg_name3 := 'EGO_ATTR_NAME_MISSING';
1679            FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name3 );
1680            l_msg_text3 := FND_MESSAGE.GET;
1681 
1682 
1683            l_msg_name4 := 'EGO_ICC_FUNCTION_INVALID';
1684            FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name4 );
1685            l_msg_text4 := FND_MESSAGE.GET;
1686 
1687 
1688            l_msg_name5 := 'EGO_ICC_FUNC_PARAM_INVALID';
1689            FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name5 );
1690            l_msg_text5 := FND_MESSAGE.GET;
1691 
1692 
1693            write_debug (l_proc_name, '30');
1694            --- Insert errors for ICC Name
1695            ---
1696            INSERT INTO MTL_INTERFACE_ERRORS
1697             (
1698                TRANSACTION_ID
1699                ,UNIQUE_ID
1700                ,ORGANIZATION_ID
1701                ,COLUMN_NAME
1702                ,TABLE_NAME
1703                ,MESSAGE_NAME
1704                ,ERROR_MESSAGE
1705                ,bo_identifier
1706                ,ENTITY_IDENTIFIER
1707                ,LAST_UPDATE_DATE
1708                ,LAST_UPDATED_BY
1709                ,CREATION_DATE
1710                ,CREATED_BY
1711                ,LAST_UPDATE_LOGIN
1712                ,REQUEST_ID
1713                ,PROGRAM_APPLICATION_ID
1714                ,PROGRAM_ID
1715                ,PROGRAM_UPDATE_DATE
1716             )
1717             SELECT transaction_id
1718                   ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
1719                   ,null
1720                   ,null
1721                   ,G_ENTITY_FUNC_PARAM_MAP_TAB
1722                   ,l_msg_name
1723                   ,l_msg_text
1724                   ,G_BO_IDENTIFIER_ICC
1725                   ,G_ENTITY_ICC_FN_PARAM_MAP
1726                   ,l_sysdate
1727                   ,G_USER_ID
1728                   ,l_sysdate
1729                   ,G_USER_ID
1730                   ,G_LOGIN_ID
1731                   ,G_CONC_REQUEST_ID
1732                   ,G_PROG_APPL_ID
1733                   ,G_PROGRAM_ID
1734                   ,l_sysdate
1735            FROM  EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1736            WHERE efpmi.item_catalog_name IS NULL
1737            OR    efpmi.item_catalog_group_id IS NULL
1738            AND   efpmi.transaction_id IS NOT NULL
1739            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1740            AND  (
1741                    ( G_SET_PROCESS_ID IS NULL )
1742                    OR
1743                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1744                 );
1745 
1746            write_debug (l_proc_name, '31');
1747            INSERT INTO MTL_INTERFACE_ERRORS
1748             (
1749                TRANSACTION_ID
1750                ,UNIQUE_ID
1751                ,ORGANIZATION_ID
1752                ,COLUMN_NAME
1753                ,TABLE_NAME
1754                ,MESSAGE_NAME
1755                ,ERROR_MESSAGE
1756                ,bo_identifier
1757                ,ENTITY_IDENTIFIER
1758                ,LAST_UPDATE_DATE
1759                ,LAST_UPDATED_BY
1760                ,CREATION_DATE
1761                ,CREATED_BY
1762                ,LAST_UPDATE_LOGIN
1763                ,REQUEST_ID
1764                ,PROGRAM_APPLICATION_ID
1765                ,PROGRAM_ID
1766                ,PROGRAM_UPDATE_DATE
1767             )
1768             SELECT transaction_id
1769                   ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
1770                   ,null
1771                   ,null
1772                   ,G_ENTITY_FUNC_PARAM_MAP_TAB
1773                   ,l_msg_name2
1774                   ,l_msg_text2
1775                   ,G_BO_IDENTIFIER_ICC
1776                   ,G_ENTITY_ICC_FN_PARAM_MAP
1777                   ,l_sysdate
1778                   ,G_USER_ID
1779                   ,l_sysdate
1780                   ,G_USER_ID
1781                   ,G_LOGIN_ID
1782                   ,G_CONC_REQUEST_ID
1783                   ,G_PROG_APPL_ID
1784                   ,G_PROGRAM_ID
1785                   ,l_sysdate
1786            FROM  EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1787            WHERE efpmi.attr_group_name IS NULL
1788            OR    efpmi.attr_group_id IS NULL
1789            AND   efpmi.transaction_id IS NOT NULL
1790            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1791            AND  (
1792                    ( G_SET_PROCESS_ID IS NULL )
1793                    OR
1794                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1795                 );
1796 
1797            write_debug (l_proc_name, '32');
1798            INSERT INTO MTL_INTERFACE_ERRORS
1799             (
1800                TRANSACTION_ID
1801                ,UNIQUE_ID
1802                ,ORGANIZATION_ID
1803                ,COLUMN_NAME
1804                ,TABLE_NAME
1805                ,MESSAGE_NAME
1806                ,ERROR_MESSAGE
1807                ,bo_identifier
1808                ,ENTITY_IDENTIFIER
1809                ,LAST_UPDATE_DATE
1810                ,LAST_UPDATED_BY
1811                ,CREATION_DATE
1812                ,CREATED_BY
1813                ,LAST_UPDATE_LOGIN
1814                ,REQUEST_ID
1815                ,PROGRAM_APPLICATION_ID
1816                ,PROGRAM_ID
1817                ,PROGRAM_UPDATE_DATE
1818             )
1819             SELECT transaction_id
1820                   ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
1821                   ,null
1822                   ,null
1823                   ,G_ENTITY_FUNC_PARAM_MAP_TAB
1824                   ,l_msg_name3
1825                   ,l_msg_text3
1826                   ,G_BO_IDENTIFIER_ICC
1827                   ,G_ENTITY_ICC_FN_PARAM_MAP
1828                   ,l_sysdate
1829                   ,G_USER_ID
1830                   ,l_sysdate
1831                   ,G_USER_ID
1832                   ,G_LOGIN_ID
1833                   ,G_CONC_REQUEST_ID
1834                   ,G_PROG_APPL_ID
1835                   ,G_PROGRAM_ID
1836                   ,l_sysdate
1837            FROM  EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1838            WHERE efpmi.attr_name IS NULL
1839            OR    efpmi.attr_id IS NULL
1840            AND   efpmi.transaction_id IS NOT NULL
1841            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1842            AND  (
1843                    ( G_SET_PROCESS_ID IS NULL )
1844                    OR
1845                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1846                 )
1847                 ;
1848 
1849            write_debug (l_proc_name, '33');
1850            ---
1851            --- Function name errors
1852            ---
1853            INSERT INTO MTL_INTERFACE_ERRORS
1854             (
1855                TRANSACTION_ID
1856                ,UNIQUE_ID
1857                ,ORGANIZATION_ID
1858                ,COLUMN_NAME
1859                ,TABLE_NAME
1860                ,MESSAGE_NAME
1861                ,ERROR_MESSAGE
1862                ,bo_identifier
1863                ,ENTITY_IDENTIFIER
1864                ,LAST_UPDATE_DATE
1865                ,LAST_UPDATED_BY
1866                ,CREATION_DATE
1867                ,CREATED_BY
1868                ,LAST_UPDATE_LOGIN
1869                ,REQUEST_ID
1870                ,PROGRAM_APPLICATION_ID
1871                ,PROGRAM_ID
1872                ,PROGRAM_UPDATE_DATE
1873             )
1874             SELECT transaction_id
1875                   ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
1876                   ,null
1877                   ,null
1878                   ,G_ENTITY_FUNC_PARAM_MAP_TAB
1879                   ,l_msg_name3
1880                   ,l_msg_text3
1881                   ,G_BO_IDENTIFIER_ICC
1882                   ,G_ENTITY_ICC_FN_PARAM_MAP
1883                   ,l_sysdate
1884                   ,G_USER_ID
1885                   ,l_sysdate
1886                   ,G_USER_ID
1887                   ,G_LOGIN_ID
1888                   ,G_CONC_REQUEST_ID
1889                   ,G_PROG_APPL_ID
1890                   ,G_PROGRAM_ID
1891                   ,l_sysdate
1892            FROM  EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1893            WHERE efpmi.function_name IS NULL
1894            OR    efpmi.function_id IS NULL
1895            AND   efpmi.transaction_id IS NOT NULL
1896            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1897            AND  (
1898                    ( G_SET_PROCESS_ID IS NULL )
1899                    OR
1900                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1901                 )
1902                 ;
1903 
1904            write_debug (l_proc_name, '34');
1905            INSERT INTO MTL_INTERFACE_ERRORS
1906             (
1907                TRANSACTION_ID
1908                ,UNIQUE_ID
1909                ,ORGANIZATION_ID
1910                ,COLUMN_NAME
1911                ,TABLE_NAME
1912                ,MESSAGE_NAME
1913                ,ERROR_MESSAGE
1914                ,bo_identifier
1915                ,ENTITY_IDENTIFIER
1916                ,LAST_UPDATE_DATE
1917                ,LAST_UPDATED_BY
1918                ,CREATION_DATE
1919                ,CREATED_BY
1920                ,LAST_UPDATE_LOGIN
1921                ,REQUEST_ID
1922                ,PROGRAM_APPLICATION_ID
1923                ,PROGRAM_ID
1924                ,PROGRAM_UPDATE_DATE
1925             )
1926             SELECT transaction_id
1927                   ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
1928                   ,null
1929                   ,null
1930                   ,G_ENTITY_FUNC_PARAM_MAP_TAB
1931                   ,l_msg_name5
1932                   ,l_msg_text5
1933                   ,G_BO_IDENTIFIER_ICC
1934                   ,G_ENTITY_ICC_FN_PARAM_MAP
1935                   ,l_sysdate
1936                   ,G_USER_ID
1937                   ,l_sysdate
1938                   ,G_USER_ID
1939                   ,G_LOGIN_ID
1940                   ,G_CONC_REQUEST_ID
1941                   ,G_PROG_APPL_ID
1942                   ,G_PROGRAM_ID
1943                   ,l_sysdate
1944            FROM  EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1945            WHERE efpmi.parameter_name IS NULL
1946            OR    efpmi.parameter_id IS NULL
1947            AND   efpmi.transaction_id IS NOT NULL
1948            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1949            AND  (
1950                    ( G_SET_PROCESS_ID IS NULL )
1951                    OR
1952                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1953                 );
1954 
1955            write_debug (l_proc_name, '35');
1956 
1957            --- update the interface table records to Error
1958            ---
1959            UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE efpmi
1960            SET efpmi.process_status = G_PROCESS_STATUS_ERROR
1961            WHERE  efpmi.attr_name IS NULL
1962            OR     efpmi.attr_group_name IS NULL
1963            OR     efpmi.item_catalog_name IS NULL
1964            OR     efpmi.attr_id IS NULL
1965            OR     efpmi.attr_group_id IS NULL
1966            OR     efpmi.item_catalog_group_ID IS NULL
1967            OR     efpmi.function_id IS NULL
1968            OR     efpmi.function_name IS NULL
1969            OR     efpmi.parameter_id IS NULL
1970            OR     efpmi.parameter_name IS NULL
1971            AND   efpmi.transaction_id IS NOT NULL
1972            AND   efpmi.process_status = G_PROCESS_STATUS_INITIAL
1973            AND  (
1974                    ( G_SET_PROCESS_ID IS NULL )
1975                    OR
1976                    ( efpmi.set_process_id =  G_SET_PROCESS_ID)
1977                 )
1978               ;
1979 
1980          write_debug (l_proc_name, '36');
1981        end if ; -- entity = func params
1982 
1983        /*
1984           --- Moved to rwo by row processing
1985           ---
1986        If p_entity = G_ENTITY_ICC_VERSION THEN
1987            --- ICC versions table , ICC Name
1988 
1989            UPDATE EGO_ICC_VERS_INTERFACE  eivi
1990            SET    eivi.item_catalog_name = ( select icc_kfv.concatenated_segments
1991                                         from   mtl_item_catalog_groups_kfv icc_kfv
1992                                         where icc_kfv.item_catalog_group_id = eivi.item_catalog_group_id
1993                                       )
1994            WHERE eivi.item_catalog_group_id IS NOT NULL
1995            AND   eivi.process_status = G_PROCESS_STATUS_INITIAL
1996            AND  (
1997                   ( G_SET_PROCESS_ID IS NULL )
1998                     OR
1999                   ( eivi.set_process_id =  G_SET_PROCESS_ID)
2000                )
2001            ;
2002 
2003            write_debug(l_proc_name, 'updated name');
2004 
2005            UPDATE ego_icc_vers_interface eivi
2006            SET    eivi.item_catalog_group_id = ( select icc_kfv.item_catalog_group_id
2007                                                   from   mtl_item_catalog_groups_kfv icc_kfv
2008                                                   where icc_kfv.concatenated_segments = eivi.item_catalog_name
2009                                                 )
2010            WHERE eivi.item_catalog_name IS NOT NULL
2011            AND   eivi.item_catalog_group_id IS NULL
2012            AND   eivi.process_status = G_PROCESS_STATUS_INITIAL
2013            AND  (
2014                   ( G_SET_PROCESS_ID IS NULL )
2015                     OR
2016                   ( eivi.set_process_id =  G_SET_PROCESS_ID)
2017                )
2018            ;
2019 
2020            write_debug(l_proc_name, 'updated id');
2021             --commit;
2022           --- insert into mtl_interface_errors
2023           ---
2024 
2025           l_msg_name := 'EGO_ICC_ID_INVALID';
2026           FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
2027           l_msg_text := FND_MESSAGE.GET;
2028 
2029 
2030           --- Insert errors for ICC Name
2031           ---
2032           INSERT INTO MTL_INTERFACE_ERRORS
2033            (
2034               TRANSACTION_ID
2035               ,UNIQUE_ID
2036               ,ORGANIZATION_ID
2037               ,COLUMN_NAME
2038               ,TABLE_NAME
2039               ,MESSAGE_NAME
2040               ,ERROR_MESSAGE
2041               ,BO_IDENTIFIER
2042               ,ENTITY_IDENTIFIER
2043               ,LAST_UPDATE_DATE
2044               ,LAST_UPDATED_BY
2045               ,CREATION_DATE
2046               ,CREATED_BY
2047               ,LAST_UPDATE_LOGIN
2048               ,REQUEST_ID
2049               ,PROGRAM_APPLICATION_ID
2050               ,PROGRAM_ID
2051               ,PROGRAM_UPDATE_DATE
2052            )
2053             SELECT transaction_id
2054                   ,MTL_SYSTEM_ITEMS_INTERFACE_S.nextval
2055                   ,null
2056                   ,null
2057                   ,G_ENTITY_ICC_VERS_TAB
2058                   ,l_msg_name
2059                   ,l_msg_text
2060                   ,G_BO_IDENTIFIER_ICC
2061                   ,G_ENTITY_ICC_VERSION
2062                   ,l_sysdate
2063                   ,G_USER_ID
2064                   ,l_sysdate
2065                   ,G_USER_ID
2066                   ,G_LOGIN_ID
2067                   ,G_CONC_REQUEST_ID
2068                   ,G_PROG_APPL_ID
2069                   ,G_PROGRAM_ID
2070                   ,l_sysdate
2071              FROM  ego_icc_vers_interface eivi
2072              WHERE ( eivi.item_catalog_group_id IS NULL
2073                      OR
2074                      eivi.item_catalog_name IS NULL
2075                    )
2076              AND   eivi.transaction_id IS NOT NULL
2077              AND   eivi.process_status = G_PROCESS_STATUS_INITIAL
2078              AND  (
2079                    ( G_SET_PROCESS_ID IS NULL )
2080                    OR
2081                    ( eivi.set_process_id =  G_SET_PROCESS_ID)
2082                   ) ;
2083 
2084            write_debug(l_proc_name, 'inserted into errors=>'||SQL%ROWCOUNT);
2085 
2086            --- update status flag in ICC interface table
2087 
2088            UPDATE ego_icc_vers_interface eivi
2089             set process_status = G_PROCESS_STATUS_ERROR
2090            WHERE ( eivi.item_catalog_group_id IS NULL
2091                      OR
2092                      eivi.item_catalog_name IS NULL
2093                    )
2094            AND   eivi.transaction_id IS NOT NULL
2095            AND   eivi.process_status = G_PROCESS_STATUS_INITIAL
2096            AND  (
2097                    ( G_SET_PROCESS_ID IS NULL )
2098                    OR
2099                    ( eivi.set_process_id =  G_SET_PROCESS_ID)
2100                 )
2101               ;
2102            write_debug(l_proc_name, 'updated error to intf rows affected=>'||SQL%ROWCOUNT);
2103 
2104 
2105        END IF;  --- versions
2106 
2107        */
2108 
2109     write_debug (l_proc_name, 'End of  '||l_proc_name);
2110 
2111     EXCEPTION
2112     WHEN OTHERS THEN
2113       x_return_status := G_RET_STS_UNEXP_ERROR;
2114       x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
2115     END Validate_Name_ID_Cols;
2116 
2117 
2118     -----------------------------------------------
2119     --- This procedure , marks the records for processing based on set_process_id passed
2120     ---   , sets the request_id column
2121     ---   , also does other bulk validations
2122     ---
2123     -----------------------------------------------
2124 
2125     PROCEDURE Bulk_Validate ( p_entity         IN VARCHAR2
2126                              ,x_return_status  OUT NOCOPY VARCHAR2
2127                              ,x_return_msg  OUT NOCOPY VARCHAR2
2128                             )
2129     IS
2130 
2131       L_proc_name VARCHAR2(30) :=  'Bulk_Validate';
2132       e_stop_process     EXCEPTION;
2133       l_sysdate    DATE := SYSDATE;
2134 
2135 
2136     BEGIN
2137       write_debug(l_proc_name,'Start of '||l_proc_name);
2138 
2139       x_return_status := G_RET_STS_SUCCESS;
2140 
2141       ---- update the transction_id in the interace table
2142       ---- update the transaction_type to UPPER
2143       ----
2144       IF p_entity = G_ENTITY_ICC_HEADER THEN
2145 
2146 
2147           Validate_Trans_Type (  G_ENTITY_ICC_HEADER, x_return_status ,x_return_msg);
2148 
2149               IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
2150                  RETURN;
2151               END IF;
2152 
2153           Validate_Entity_Cols ( G_ENTITY_ICC_HEADER, x_return_status ,x_return_msg);
2154 
2155               IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
2156                  RETURN;
2157               END IF;
2158 
2159           Validate_Name_ID_Cols ( G_ENTITY_ICC_HEADER, x_return_status ,x_return_msg);
2160 
2161               IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
2162                  RETURN;
2163               END IF;
2164 
2165       END IF;  --- END ICC
2166 
2167 
2168       --- AG Assoc
2169       ----
2170       IF p_entity = G_ENTITY_ICC_AG_ASSOC THEN
2171 
2172           Validate_Trans_Type (  G_ENTITY_ICC_AG_ASSOC, x_return_status ,x_return_msg);
2173 
2174               IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
2175                  RETURN;
2176               END IF;
2177 
2178           Validate_Entity_Cols ( G_ENTITY_ICC_AG_ASSOC, x_return_status ,x_return_msg);
2179 
2180               IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
2181                  RETURN;
2182               END IF;
2183 
2184           Validate_Name_ID_Cols ( G_ENTITY_ICC_AG_ASSOC, x_return_status ,x_return_msg);
2185 
2186               IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
2187                  RETURN;
2188               END IF;
2189 
2190 
2191       END IF;  -- END  AG Assoc
2192 
2193 
2194       --- Func Params
2195       ----
2196       IF p_entity = G_ENTITY_ICC_FN_PARAM_MAP THEN
2197 
2198            Validate_Trans_Type (  G_ENTITY_ICC_FN_PARAM_MAP, x_return_status ,x_return_msg);
2199 
2200               IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
2201                  RETURN;
2202               END IF;
2203 
2204            Validate_Entity_Cols ( G_ENTITY_ICC_FN_PARAM_MAP, x_return_status ,x_return_msg);
2205               IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
2206                  RETURN;
2207               END IF;
2208 
2209            Validate_Name_ID_Cols ( G_ENTITY_ICC_FN_PARAM_MAP, x_return_status ,x_return_msg);
2210 
2211               IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
2212                  RETURN;
2213               END IF;
2214       END IF;  -- END  Func Params
2215 
2216 
2217 
2218          --- corresponding TA records have to marked as Error
2219          ---
2220       IF p_entity = G_ENTITY_ICC_VERSION THEN
2221 
2222 
2223            --- moved to row by row bug 9752139
2224            ---
2225            /*
2226            Validate_Trans_Type (  G_ENTITY_ICC_VERSION, x_return_status ,x_return_msg);
2227 
2228               IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
2229                  RETURN;
2230               END IF;
2231            */
2232 
2233            Validate_Entity_Cols ( G_ENTITY_ICC_VERSION, x_return_status ,x_return_msg);
2234 
2235               IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
2236                  RETURN;
2237               END IF;
2238 
2239            --- Moved to row by row , since ICC may not be
2240            --- processed at the point this is called
2241            ---
2242            ---
2243            ---Validate_Name_ID_Cols ( G_ENTITY_ICC_VERSION, x_return_status ,x_return_msg);
2244            ---
2245            ---   IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
2246            ---      RETURN;
2247            ---   END IF;
2248            ---
2249 
2250 
2251       END IF;
2252 
2253 
2254     write_debug(l_proc_name,'End');
2255     EXCEPTION
2256     WHEN OTHERS THEN
2257       x_return_status := G_RET_STS_UNEXP_ERROR;
2258       x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
2259       write_debug( l_proc_name ,x_return_msg);
2260       RETURN;
2261     END Bulk_Validate;
2262 
2263 
2264 /********************************************************************
2265 --- This procedure does thebulk validations as present in Bulk_Validate
2266 --- when the public API for ICC processing is invoked
2267 ---
2268 ********************************************************************/
2269 
2270 
2271     PROCEDURE   Bulk_Validate_For_API (    p_entity         IN varchar2
2272                                          , p_icc_rec        IN OUT NOCOPY ego_icc_rec_type
2273                                          , p_ag_assoc_rec   IN OUT NOCOPY ego_ag_assoc_rec_type
2274                                          , p_func_param_assoc_rec IN OUT NOCOPY ego_func_param_map_rec_type
2275                                          , x_return_status    OUT NOCOPY VARCHAR2
2276                                          , x_return_msg  OUT NOCOPY VARCHAR2
2277                                      )
2278     IS
2279       l_proc_name  CONSTANT VARCHAR2(30) := 'Bulk_Validate_For_API';
2280     BEGIN
2281 
2282       write_debug(l_proc_name,'Start');
2283 
2284       NULL;
2285       write_debug(l_proc_name,'End');
2286 
2287     EXCEPTION
2288     WHEN OTHERS THEN
2289       x_return_status := G_RET_STS_UNEXP_ERROR;
2290       x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
2291       RETURN;
2292     END Bulk_Validate_For_API;
2293 
2294 
2295    /********************************************************************
2296     ** Procedure: Check_Catalog_CCID (Unexposed)
2297     ** Purpose  : Checks the existence of catalog group id
2298     ** Returns  : TRUE if CCID exists and FALSE if not
2299     **********************************************************************/
2300 
2301 
2302     FUNCTION Check_Catalog_CCID ( p_catalog_grp_id IN NUMBER)
2303     RETURN BOOLEAN
2304     IS
2305       l_ccid NUMBER;
2306     BEGIN
2307 
2308       SELECT item_catalog_group_id
2309         INTO l_ccid
2310       FROM mtl_Item_Catalog_Groups_b
2311       WHERE  item_catalog_group_id = p_catalog_grp_id;
2312 
2313     Return TRUE;
2314 
2315     EXCEPTION WHEN OTHERS
2316     THEN
2317       Return FALSE;
2318     END Check_Catalog_CCID;
2319 
2320 
2321 /********************************************************************
2322 ---   Function to check if the code passed exists in lookups
2323 ---   for given lookup type
2324 ---
2325 ********************************************************************/
2326 
2327 
2328 FUNCTION Check_Lookup_value  ( p_code  IN VARCHAR2
2329                               ,p_lookup IN VARCHAR2
2330                               )
2331 RETURN boolean
2332 IS
2333 
2334   l_return boolean := false;
2335 
2336   CURSOR cur_lkup
2337   IS
2338   SELECT 1
2339   FROM FND_LOOKUP_VALUES
2340   WHERE LOOKUP_CODE = p_code
2341   AND   LOOKUP_TYPE = p_lookup
2342   AND   LANGUAGE = USERENV('LANG');
2343 
2344 
2345   l_proc_name    VARCHAR2(30) := 'Check_Lookup_value';
2346 BEGIN
2347   write_debug(l_proc_name,'Start');
2348 
2349   FOR rec_lkup IN cur_lkup
2350   LOOP
2351     l_return := TRUE;
2352     write_debug(l_proc_name,' Code =>'||p_code||' exists in lookup=>'||p_lookup);
2353     EXIT;
2354   END LOOP;
2355 
2356 write_debug(l_proc_name,'End ');
2357 RETURN l_return;
2358 
2359 END Check_Lookup_value;
2360 
2361 
2362 /********************************************************************
2363 --  API Name:       Generate_Seq_For_Item_Catalog
2364 --
2365 --  Description:
2366 --  Generates the Item Sequence For Number Generation
2367 ********************************************************************/
2368 PROCEDURE Generate_Seq_For_Item_Catalog (
2369         p_icc_id                        IN  NUMBER
2370        ,p_seq_start_num                 IN  NUMBER
2371        ,p_seq_increment_by              IN  NUMBER
2372        ,x_seq_name                      OUT nocopy VARCHAR2
2373        ,x_return_status                 OUT nocopy VARCHAR2
2374        ,x_return_msg                    OUT NOCOPY VARCHAR2
2375 )IS
2376     l_proc_name              CONSTANT VARCHAR2(50) := 'Generate_Sequence_For_Item_Catalog';
2377     l_seq_name               VARCHAR2(100);
2378     l_ret_seq_name           VARCHAR2(100);
2379     l_syn_name               VARCHAR2(100);
2380     l_seq_name_prefix        VARCHAR2(70) ;
2381     l_syn_name_prefix        CONSTANT VARCHAR2(70) := 'ITEM_NUM_SEQ_';
2382     l_seq_name_suffix        CONSTANT VARCHAR2(10) := '_S' ;
2383     l_dyn_sql                VARCHAR2(100);
2384 
2385     l_status                 VARCHAR2(1);
2386     l_industry               VARCHAR2(1);
2387     l_schema                 VARCHAR2(30);
2388 
2389     fnd_apps_schema      VARCHAR2(30) := NULL;
2390     h_status             VARCHAR2(2000);
2391     h_industry           VARCHAR2(2000);
2392     h_x                  BOOLEAN;
2393 
2394 BEGIN
2395     x_return_status := G_RET_STS_SUCCESS;
2396 
2397     --start ad_dll fix 12.2
2398     h_x := FND_INSTALLATION.Get_App_Info('FND', h_status, h_industry, fnd_apps_schema);
2399 
2400     IF FND_INSTALLATION.GET_APP_INFO('INV', l_status, l_industry, l_schema) THEN
2401        IF l_schema IS NULL    THEN
2402           x_return_msg := 'INV Schema could not be located.';
2403           write_debug (l_proc_name,x_return_msg );
2404           x_return_status  :=  G_RET_STS_ERROR;
2405        END IF;
2406     ELSE
2407           x_return_msg := 'INV Schema could not be located.';
2408           write_debug (l_proc_name,x_return_msg );
2409           x_return_status  :=  G_RET_STS_ERROR;
2410     END IF;
2411 
2412    -- l_seq_name_prefix := l_schema ||'.'||'ITEM_NUM_SEQ_';
2413     l_seq_name_prefix := 'ITEM_NUM_SEQ_';
2414     l_ret_seq_name := 'ITEM_NUM_SEQ_'|| p_icc_id || l_seq_name_suffix;
2415     l_seq_name  := l_seq_name_prefix || p_icc_id || l_seq_name_suffix;
2416     l_dyn_sql   := 'CREATE SEQUENCE '||l_seq_name||' INCREMENT BY '||p_seq_increment_by||' START WITH '||p_seq_start_num || ' NOCACHE';
2417 
2418     --bugfix 11907422 for 12.2 AD_DDL changes
2419     --EXECUTE IMMEDIATE l_dyn_sql;
2420 
2421     AD_DDL.DO_DDL(fnd_apps_schema, l_schema, AD_DDL.CREATE_SEQUENCE,l_dyn_sql, l_seq_name);
2422 
2423     l_syn_name  := l_syn_name_prefix || p_icc_id || l_seq_name_suffix;
2424     l_dyn_sql   := 'CREATE SYNONYM '||l_syn_name||' FOR '||l_seq_name;
2425 
2426      --bugfix 11907422 for 12.2 AD_DDL changes
2427     --EXECUTE IMMEDIATE l_dyn_sql;
2428 
2429     --comment this line since AD_DDL.DO_DDL will create synonym for us
2430 
2431     --AD_DDL.DO_DDL(fnd_apps_schema, fnd_apps_schema, ad_ddl.create_synonym,l_dyn_sql, l_syn_name);
2432 
2433 
2434     x_seq_name := l_ret_seq_name;
2435 EXCEPTION
2436    WHEN others THEN
2437       x_return_status  :=  G_RET_STS_UNEXP_ERROR;
2438       x_return_msg := G_PKG_NAME||'.'||l_proc_name||' '||SQLERRM;
2439 END Generate_Seq_For_Item_Catalog;
2440 
2441 /********************************************************************
2442 
2443 --  API Name:       Drop_Sequence_For_Item_Catalog
2444 --
2445 --  Description:
2446 --  Drops the Item Sequence For Number Generation
2447 ********************************************************************/
2448 
2449 PROCEDURE Drop_Sequence_For_Item_Catalog (
2450        p_item_catalog_seq_name         IN  VARCHAR2
2451        ,x_return_status                 OUT NOCOPY VARCHAR2
2452        ,x_return_msg                    OUT NOCOPY VARCHAR2
2453        )
2454 IS
2455     l_proc_name              CONSTANT VARCHAR2(50) := 'Drop_Sequence_For_Item_Catalog';
2456     l_dyn_sql                VARCHAR2(100);
2457     l_status                 VARCHAR2(1);
2458     l_industry               VARCHAR2(1);
2459     l_schema                 VARCHAR2(30);
2460 
2461     fnd_apps_schema      VARCHAR2(30) := NULL;
2462     h_status             VARCHAR2(2000);
2463     h_industry           VARCHAR2(2000);
2464     h_x                  BOOLEAN;
2465 
2466 BEGIN
2467     x_return_status := G_RET_STS_SUCCESS;
2468 
2469     h_x := FND_INSTALLATION.Get_App_Info('FND', h_status, h_industry, fnd_apps_schema);
2470 
2471     IF FND_INSTALLATION.GET_APP_INFO('INV', l_status, l_industry, l_schema) THEN
2472        IF l_schema IS NULL    THEN
2473           x_return_msg := 'INV Schema could not be located.';
2474           write_debug (l_proc_name,x_return_msg );
2475           x_return_status  :=  G_RET_STS_ERROR;
2476        END IF;
2477     ELSE
2478           x_return_msg := 'INV Schema could not be located.';
2479           write_debug (l_proc_name,x_return_msg );
2480           x_return_status  :=  G_RET_STS_ERROR;
2481     END IF;
2482 
2483     l_dyn_sql   := 'DROP SYNONYM '||p_item_catalog_seq_name;
2484 
2485      --bugfix 11907422 for 12.2 AD_DDL changes
2486    -- EXECUTE IMMEDIATE l_dyn_sql;
2487    --comment this line since AD_DDL.DO_DDL will drop synonym for us,
2488    --AD_DDL.DO_DDL(fnd_apps_schema,fnd_apps_schema, ad_ddl.drop_synonym,l_dyn_sql, p_item_catalog_seq_name);
2489 
2490     --l_dyn_sql   := 'DROP SEQUENCE '||l_schema||'.'||p_item_catalog_seq_name;
2491     l_dyn_sql   := 'DROP SEQUENCE '||p_item_catalog_seq_name;
2492      --bugfix 11907422 for 12.2 AD_DDL changes
2493     --EXECUTE IMMEDIATE l_dyn_sql;
2494 
2495      AD_DDL.DO_DDL(fnd_apps_schema,l_schema, ad_ddl.drop_sequence,l_dyn_sql, p_item_catalog_seq_name);
2496 EXCEPTION
2497    WHEN others THEN
2498       x_return_status  :=  G_RET_STS_UNEXP_ERROR;
2499       x_return_msg := G_PKG_NAME||'.'||l_proc_name||' '||SQLERRM;
2500 END Drop_Sequence_For_Item_Catalog;
2501 
2502 
2503 
2504 --
2505 -- Bug 9953881. Function mappings are not happening correctly
2506 -- Added new method to get object id.
2507 -- sreharih. Fri Apr 15 16:53:09 PDT 2011
2508 --
2509 
2510 FUNCTION get_object_id RETURN NUMBER IS
2511 
2512  l_ret fnd_objects.object_id%TYPE;
2513 
2514 BEGIN
2515 
2516   OPEN cur_get_obj_id;
2517   FETCH cur_get_obj_id INTO l_ret;
2518   CLOSE cur_get_obj_id;
2519 
2520   RETURN l_ret;
2521 END get_object_id;
2522 
2523 --
2524 -- Bug 9953881. Function mappings are not happening correctly
2525 -- Added new method to fetch num/desc action id from ICC.
2526 -- sreharih. Fri Apr 15 16:53:09 PDT 2011
2527 --
2528 
2529 PROCEDURE get_item_action_ids(p_item_catalog_group_id IN NUMBER,
2530                               x_num_action_id         OUT NOCOPY NUMBER,
2531                               x_desc_action_id        OUT NOCOPY NUMBER) IS
2532 
2533 
2534 
2535   CURSOR c IS
2536    SELECT cat.item_num_action_id, cat.item_desc_action_id
2537      FROM mtl_item_catalog_groups_b cat
2538     WHERE cat.item_catalog_group_id = p_item_catalog_group_id;
2539 
2540 BEGIN
2541  OPEN c;
2542  FETCH c INTO x_num_action_id, x_desc_action_id;
2543  CLOSE c;
2544 
2545 END get_item_action_ids;
2546 
2547 --
2548 -- Bug 9953881. Function mappings are not happening correctly
2549 -- Added new method to get function associated to action.
2550 -- sreharih. Fri Apr 15 16:53:09 PDT 2011
2551 --
2552 
2553 FUNCTION get_action_function_id (p_object_id           IN NUMBER,
2554                                  p_classification_code IN VARCHAR2,
2555                                  p_action_id           IN NUMBER ) RETURN NUMBER IS
2556 
2557  CURSOR c IS
2558  SELECT act.function_id
2559    FROM ego_actions_b act
2560   WHERE act.object_id = p_object_id
2561     AND act.classification_code = p_classification_code
2562     AND act.action_id = p_action_id;
2563 
2564   l_ret ego_actions_b.function_id%TYPE;
2565   l_proc_name       CONSTANT VARCHAR2(30) := 'GET_ACTION_FUNCTION_ID';
2566 
2567 BEGIN
2568   write_debug(l_proc_name,'Entering method with params icc id = ' || p_classification_code ||
2569                                                   ' action_id = ' || p_action_id ||
2570                                                   ' object_id = ' || p_object_id);
2571 
2572   OPEN c;
2573   FETCH c INTO l_ret;
2574   CLOSE c;
2575 
2576   write_debug(l_proc_name,'Returning ' || l_ret);
2577   RETURN l_ret;
2578 
2579 END get_action_function_id;
2580 
2581 --
2582 -- Bug 9953881. Function mappings are not happening correctly
2583 -- Added new method to get action id based on the item num/desc
2584 -- generated action id in ICC. We have to do this way until
2585 -- we fix the interface table to take in action name.
2586 -- sreharih. Fri Apr 15 16:53:09 PDT 2011
2587 --
2588 
2589 FUNCTION get_action_id (p_item_catalog_group_id IN NUMBER,
2590                         p_function_id           IN NUMBER,
2591                         p_object_id             IN NUMBER) RETURN NUMBER IS
2592 
2593   l_num_action_id   mtl_item_catalog_groups_b.item_num_action_id%TYPE;
2594   l_desc_action_id  mtl_item_catalog_groups_b.item_desc_action_id%TYPE;
2595   l_proc_name       CONSTANT VARCHAR2(30) := 'GET_ACTION_ID';
2596 BEGIN
2597   write_debug(l_proc_name,'Entering method with params icc id = ' || p_item_catalog_group_id ||
2598                                                 ' function_id = ' || p_function_id ||
2599                                                   ' object_id = ' || p_object_id);
2600 
2601   get_item_action_ids(p_item_catalog_group_id  => p_item_catalog_group_id,
2602                       x_num_action_id          => l_num_action_id,
2603                       x_desc_action_id         => l_desc_action_id);
2604 
2605   write_debug(l_proc_name,'ICC Num Action ID is  : ' || l_num_action_id);
2606   write_debug(l_proc_name,'ICC Desc Action ID is : ' || l_desc_action_id);
2607 
2608   IF l_num_action_id IS NOT NULL THEN
2609     -- Check if user is updating the num gen action.
2610     IF p_function_id = get_action_function_id(p_object_id,
2611                                               to_char(p_item_catalog_group_id),
2612                                               l_num_action_id)  THEN
2613        write_debug(l_proc_name,'Returning icc num action id');
2614        RETURN l_num_action_id;
2615     END IF;
2616   END IF;
2617 
2618   IF l_desc_action_id IS NOT NULL THEN
2619     -- Check if user is updating the desc gen action.
2620     IF p_function_id = get_action_function_id(p_object_id,
2621                                               to_char(p_item_catalog_group_id),
2622                                               l_desc_action_id)  THEN
2623        write_debug(l_proc_name,'Returning icc desc action id');
2624        RETURN l_desc_action_id;
2625     END IF;
2626   END IF;
2627 
2628   write_debug(l_proc_name,'Returning null');
2629   RETURN NULL;
2630 
2631 END get_action_id;
2632 
2633 
2634 FUNCTION mapping_exists (p_action_id     IN NUMBER,
2635                          p_function_id   IN NUMBER,
2636                          p_func_param_id IN NUMBER ) RETURN BOOLEAN IS
2637 
2638   CURSOR c
2639   IS
2640   SELECT 1
2641   FROM   ego_mappings_b b
2642   WHERE  b.mapped_obj_pk1_val = to_char(p_action_id)
2643     AND  b.function_id        = p_function_id
2644     AND  b.func_param_id      = p_func_param_id;
2645 
2646  l_ret INTEGER;
2647  l_proc_name CONSTANT VARCHAR2(30) := 'MAPPING_EXISTS';
2648 
2649 BEGIN
2650 
2651   write_debug(l_proc_name,'Entering method with params action id = ' || p_action_id ||
2652                                                    ' function_id = ' || p_function_id ||
2653                                                  ' func_param_id = ' || p_func_param_id);
2654 
2655   OPEN c;
2656   FETCH c INTO l_ret;
2657   CLOSE c;
2658 
2659   write_debug(l_proc_name,'Return ' || l_ret);
2660 
2661   IF l_ret = 1 THEN
2662     RETURN true;
2663   ELSE
2664     RETURN false;
2665   END IF;
2666 
2667 END mapping_exists;
2668 
2669 
2670 
2671 --
2672 -- Bug 9953881. Function mappings are not happening correctly
2673 -- Modified the method below to
2674 --  a. Get action id from ICC num or desc generate action col-
2675 --     umns. The value would have been updated correctly before
2676 --     the code flows here. There is a fundamental design issue
2677 --     where map_interface table dont have the action column.So
2678 --     if user is passing same function for both num/desc gener-
2679 --     ate action columns, then the code will misbehave.
2680 --  b. Removed some commented code for better readability.
2681 --  c. Added correct logic to check whether mapping already exists
2682 --     or not.
2683 --  d. Make transaction type as update if user is trying to create the map again.
2684 --  sreharih. Fri Apr 15 16:53:09 PDT 2011
2685 --
2686 
2687 /********************************************************************
2688 ---
2689 --- This procedure validates the paramter mappings associatiation
2690 --- between function and ICC
2691 ---
2692 /********************************************************************/
2693  PROCEDURE Validate_Func_Param_Mappings    ( p_func_param_assoc_rec IN OUT NOCOPY ego_func_param_map_rec_type
2694                                             ,x_return_status      OUT NOCOPY VARCHAR2
2695                                             ,x_return_msg  OUT NOCOPY VARCHAR2
2696                                            )
2697 IS
2698 
2699   l_proc_name  CONSTANT VARCHAR2(30) := 'Validate_Func_Param_Mappings';
2700   -- for error logging
2701   --
2702   l_entity_code     VARCHAR2(30) := G_ENTITY_ICC_FN_PARAM_MAP;
2703   l_token_table     ERROR_HANDLER.Token_Tbl_Type;
2704 
2705   l_function_id     ego_func_params_b.function_id%TYPE;
2706   l_func_param_id   ego_func_params_b.func_param_id%TYPE;
2707   l_func_params_tbl ego_func_param_map_tbl_type;
2708   l_object_id       fnd_objects.object_id%TYPE := null;
2709   l_action_id       ego_actions_b.action_id%TYPE := null;
2710   l_mapping_found  BOOLEAN := FALSE;
2711 
2712 
2713   cursor cur_func_param (  p_param_name  VARCHAR2 default null
2714                           ,p_param_id    NUMBER default null
2715                           ,p_function_id NUMBER
2716                         )
2717   IS
2718   select FUNC_PARAM_ID, internal_name
2719   from   ego_func_params_b efpb
2720   where  efpb.function_id = p_function_id
2721   and    efpb.internal_name = nvl(p_param_name, efpb.internal_name)
2722   and    efpb.func_param_id = nvl(p_param_id ,efpb.func_param_id)
2723   ;
2724 
2725 BEGIN
2726   write_debug(l_proc_name,'Start');
2727   x_return_status := G_RET_STS_SUCCESS;
2728 
2729 
2730   --
2731   -- Bug 9953881. Function mappings are not happening correctly
2732   -- Modified the method below to
2733   --  a. Get action id from ICC num or desc generate action col-
2734   --     umns. The value would have been updated correctly before
2735   --     the code flows here.
2736   --  sreharih. Fri Apr 15 16:53:09 PDT 2011
2737   --
2738 
2739 
2740   l_object_id  := get_object_id;
2741   l_action_id  := get_action_id (p_item_catalog_group_id => p_func_param_assoc_rec.item_catalog_group_id,
2742                                  p_function_id           => p_func_param_assoc_rec.function_id,
2743                                  p_object_id             => l_object_id);
2744 
2745   write_debug(l_proc_name,'Action ID is ' || l_action_id);
2746 
2747   --- If function is not associated to ICC , log error and return
2748   ---
2749   IF l_action_id IS NULL THEN
2750 
2751      x_return_status := G_RET_STS_ERROR;
2752      l_token_table(1).token_name := 'FUNC_NAME';
2753      l_token_table(1).token_value :=  p_func_param_assoc_rec.function_name;
2754 
2755      l_token_table(2).token_name := 'ICC_NAME';
2756      l_token_table(2).token_value :=  p_func_param_assoc_rec.item_catalog_name;
2757 
2758      ERROR_HANDLER.Add_Error_Message(
2759         p_message_name                  => 'EGO_FUNC_NOT_ASSOC_ICC'
2760        ,p_application_id                => G_APPL_NAME
2761        ,p_row_identifier                => p_func_param_assoc_rec.transaction_id
2762        ,p_token_tbl                     => l_token_table
2763        ,p_entity_code                   => l_entity_code
2764        ,p_table_name                    => G_ENTITY_FUNC_PARAM_MAP_TAB
2765      );
2766      l_token_table.delete;
2767      p_func_param_assoc_rec.process_status := G_PROCESS_STATUS_ERROR;
2768      RETURN;
2769 
2770   END IF;
2771 
2772 
2773            --
2774            -- Bug 9953881. Function mappings are not happening correctly
2775            -- Modified the method below to
2776            --  c. Added correct logic to check whether mapping already exists
2777            --     or not.
2778            --  d. Make transaction type as update if user is trying to create the map again.
2779            --  sreharih. Fri Apr 15 16:53:09 PDT 2011
2780            --
2781 
2782 
2783        l_mapping_found := FALSE;
2784 
2785        l_mapping_found := mapping_exists(p_action_id         => l_action_id,
2786                                          p_function_id       => p_func_param_assoc_rec.function_id,
2787                                          p_func_param_id     => p_func_param_assoc_rec.parameter_id);
2788 
2789 
2790        IF p_func_param_assoc_rec.transaction_type = G_TTYPE_CREATE AND l_mapping_found THEN
2791           p_func_param_assoc_rec.transaction_type := G_TTYPE_UPDATE;
2792        END IF;
2793 
2794        IF p_func_param_assoc_rec.transaction_type = G_TTYPE_UPDATE AND (NOT l_mapping_found) THEN
2795 
2796            x_return_status := G_RET_STS_ERROR;
2797            l_token_table(1).token_name := 'PARAM_NAME';
2798            l_token_table(1).token_value := p_func_param_assoc_rec.parameter_name;
2799          ERROR_HANDLER.Add_Error_Message(
2800             p_message_name                  => 'EGO_MAPPING_DOES_NOT_EXIST'
2801            ,p_application_id                => G_APPL_NAME
2802            ,p_token_tbl                     => l_token_table
2803            ,p_row_identifier                => p_func_param_assoc_rec.transaction_id
2804            ,p_entity_code                   => l_entity_code
2805            ,p_table_name                    => G_ENTITY_FUNC_PARAM_MAP_TAB
2806          );
2807          l_token_table.DELETE;
2808          p_func_param_assoc_rec.process_status := G_PROCESS_STATUS_ERROR;
2809          RETURN;
2810 
2811        END IF;
2812 
2813       ---- Resolve the SYNC transaction type
2814       ---- if the paramter being mapped is already associated for the same function , against the ICC
2815       ---- then it is UPDATE
2816       ----
2817       IF p_func_param_assoc_rec.transaction_type = G_TTYPE_SYNC THEN
2818 
2819         IF l_mapping_found THEN
2820             p_func_param_assoc_rec.transaction_type := G_TTYPE_UPDATE;
2821         ELSE
2822             p_func_param_assoc_rec.transaction_type := G_TTYPE_CREATE;
2823         END IF;
2824 
2825       END IF;
2826 
2827 
2828 
2829       ---
2830       --- Checking the UOM Parameter name against the FUNCTION
2831       ---
2832       IF p_func_param_assoc_rec.mapped_uom_parameter IS NOT NULL AND p_func_param_assoc_rec.mapped_uom_parameter <> G_MISS_NUM THEN
2833 
2834         for  rec_param_chk in cur_func_param ( p_param_id =>  p_func_param_assoc_rec.mapped_uom_parameter
2835                                               ,p_function_id => p_func_param_assoc_rec.function_id
2836                                              )
2837         loop
2838 
2839           l_func_param_id := rec_param_chk.func_param_id;
2840           p_func_param_assoc_rec.uom_parameter := rec_param_chk.internal_name;
2841         end loop;
2842 
2843         IF l_func_param_id IS NULL THEN
2844 
2845              x_return_status := G_RET_STS_ERROR;
2846              ERROR_HANDLER.Add_Error_Message(
2847                 p_message_name                  => 'EGO_ICC_FUNC_UOM_PARAM_INVALID'
2848                ,p_application_id                => G_APPL_NAME
2849                ,p_row_identifier                => p_func_param_assoc_rec.transaction_id
2850                ,p_entity_code                   => l_entity_code
2851                ,p_table_name                    => G_ENTITY_FUNC_PARAM_MAP_TAB
2852              );
2853              p_func_param_assoc_rec.process_status := G_PROCESS_STATUS_ERROR;
2854 
2855         END IF;
2856 
2857       ELSIF p_func_param_assoc_rec.uom_parameter IS NOT NULL AND p_func_param_assoc_rec.uom_parameter <> G_MISS_CHAR THEN
2858         for  rec_param_chk in cur_func_param ( p_param_name =>  p_func_param_assoc_rec.uom_parameter
2859                                               ,p_function_id => p_func_param_assoc_rec.function_id
2860                                              )
2861         loop
2862           l_func_param_id := rec_param_chk.func_param_id;
2863           p_func_param_assoc_rec.mapped_uom_parameter := l_func_param_id;
2864         end loop;
2865 
2866         IF l_func_param_id IS NULL THEN
2867 
2868                x_return_status := G_RET_STS_ERROR;
2869                l_token_table(1).token_name := 'UOM_PARAM';
2870                l_token_table(1).token_value := p_func_param_assoc_rec.uom_parameter;
2871              ERROR_HANDLER.Add_Error_Message(
2872                 p_message_name                  => 'EGO_ICC_FUNC_UOM_PARAM_INVALID'
2873                ,p_application_id                => G_APPL_NAME
2874                ,p_token_tbl                     => l_token_table
2875                ,p_row_identifier                => p_func_param_assoc_rec.transaction_id
2876                ,p_entity_code                   => l_entity_code
2877                ,p_table_name                    => G_ENTITY_FUNC_PARAM_MAP_TAB
2878              );
2879              l_token_table.DELETE;
2880              p_func_param_assoc_rec.process_status := G_PROCESS_STATUS_ERROR;
2881 
2882         END IF;
2883       END IF;
2884 
2885        IF p_func_param_assoc_rec.UOM_PARAM_VALUE_TYPE IS NOT NULL AND p_func_param_assoc_rec.UOM_PARAM_VALUE_TYPE <> G_MISS_CHAR THEN
2886 
2887          IF NOT Check_Lookup_value ( p_code => p_func_param_assoc_rec.UOM_PARAM_VALUE_TYPE
2888                                ,p_lookup => 'EGO_PARAM_MAP_UOM_SOURCE'
2889                               ) THEN
2890 
2891                x_return_status := G_RET_STS_ERROR;
2892                l_token_table(1).token_name := 'COL_NAME';
2893                l_token_table(1).token_value := 'UOM_PARAM_VALUE_TYPE';
2894 
2895                ERROR_HANDLER.Add_Error_Message(
2896                 p_message_name                  => 'EGO_INVALID_VALUE_FOR_COL'
2897                ,p_application_id                => G_APPL_NAME
2898                ,p_row_identifier                => p_func_param_assoc_rec.transaction_id
2899                ,p_entity_code                   => l_entity_code
2900                ,p_table_name                    => G_ENTITY_FUNC_PARAM_MAP_TAB
2901                );
2902              l_token_table.DELETE;
2903              p_func_param_assoc_rec.process_status := G_PROCESS_STATUS_ERROR;
2904 
2905          ELSIF p_func_param_assoc_rec.UOM_PARAM_VALUE_TYPE = 'F' -- fixed
2906                 AND ( p_func_param_assoc_rec.FIXED_UOM_VALUE IS NULL OR p_func_param_assoc_rec.FIXED_UOM_VALUE = G_MISS_CHAR)
2907                 THEN
2908 
2909                  x_return_status := G_RET_STS_ERROR;
2910                  l_token_table(1).token_name := 'MAPPED_ATTR';
2911                  l_token_table(1).token_value := p_func_param_assoc_rec.uom_parameter;
2912 
2913                   ERROR_HANDLER.Add_Error_Message(
2914                    p_message_name                  => 'EGO_FIXED_UOM_REQUIRED'
2915                   ,p_application_id                => G_APPL_NAME
2916 
2917                   ,p_row_identifier                => p_func_param_assoc_rec.transaction_id
2918                   ,p_entity_code                   => l_entity_code
2919                   ,p_table_name                    => G_ENTITY_FUNC_PARAM_MAP_TAB
2920                   );
2921                  p_func_param_assoc_rec.process_status := G_PROCESS_STATUS_ERROR;
2922          END IF;
2923        END IF;
2924   write_debug(l_proc_name,'End ');
2925 EXCEPTION
2926 WHEN OTHERS THEN
2927   x_return_status := G_RET_STS_UNEXP_ERROR;
2928   x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
2929 END Validate_Func_Param_Mappings;
2930 
2931 
2932 /******************************************
2933 ---- Function to check the function name
2934 ---- or ID provided against EGO_FUNCTIONS_V
2935 *****************************************/
2936 
2937 FUNCTION Check_Function ( p_func_id  IN NUMBER DEFAULT NULL
2938                          ,p_func_name IN VARCHAR2 DEFAULT NULL
2939                         )
2940 RETURN NUMBER
2941 IS
2942   l_temp_id    NUMBER := NULL;
2943   l_func_id    NUMBER := NULL;
2944   l_proc_name  VARCHAR2(30) := 'Check_Function';
2945 
2946   CURSOR cur_func
2947   IS
2948   SELECT function_id
2949   FROM ego_functions_v
2950   where  ( function_id = nvl(p_func_id, function_id)
2951            AND
2952            internal_name = nvl(p_func_name, internal_name)
2953         ) ;
2954 
2955   CURSOR cur_func_check ( p_cur_func_id  NUMBER)
2956   IS
2957   SELECT 1
2958   FROM EGO_FUNC_PARAMS_B
2959   WHERE function_id = p_cur_func_id
2960   AND   param_type = 'R'
2961   AND data_type IN ('O', 'N', 'V', 'I', 'L', 'S')
2962   ;
2963 
2964 
2965 BEGIN
2966 
2967   for rec_func IN cur_func
2968   loop
2969       l_temp_id := rec_func.function_id;
2970   end loop;
2971 
2972   write_debug(l_proc_name, 'l_temp_id =>'||l_temp_id);
2973 
2974   ---
2975   --- Function should have a return value for it to be associated to the ICC
2976   --- number generation and desc generation
2977   for rec_func_check_func IN cur_func_check ( l_temp_id)
2978   LOOP
2979     l_func_id := l_temp_id;
2980   END LOOP;
2981  write_debug(l_proc_name, 'l_func_id =>'||l_func_id);
2982 
2983   return l_func_id;
2984 EXCEPTION
2985 WHEN OTHERS THEN
2986   return null;
2987 END ;
2988 
2989 
2990 /********************************************************************
2991 ---   This procedure accepts a icc intf. record type , does value to id
2992 ---   conversion and other validations for function related columns
2993 ---   bug 9737833
2994 ********************************************************************/
2995 PROCEDURE Validate_YesNo_Cols ( p_icc_rec       IN OUT NOCOPY ego_icc_rec_type
2996                                ,x_return_status OUT NOCOPY VARCHAR2
2997                                ,x_return_msg    OUT NOCOPY VARCHAR2
2998                               )
2999 IS
3000   l_proc_name  CONSTANT VARCHAR2(30) := 'Validate_YesNo_Cols';
3001   -- for error logging
3002   --
3003   l_entity_code     VARCHAR2(30) := G_ENTITY_ICC_HEADER;
3004   l_token_table     ERROR_HANDLER.Token_Tbl_Type;
3005 
3006   l_return_msg      VARCHAR2(4000);
3007   l_return_status   VARCHAR2(1);
3008 
3009 
3010 
3011 BEGIN
3012   write_debug(l_proc_name,'Start');
3013   X_return_status := G_RET_STS_SUCCESS;
3014 
3015 
3016   IF p_icc_rec.enabled_flag IS NOT NULL
3017         AND p_icc_rec.enabled_flag <> G_MISS_CHAR THEN
3018 
3019     IF p_icc_rec.enabled_flag NOT IN ( 'Y', 'N') THEN
3020 
3021            x_return_status := G_RET_STS_ERROR;
3022            l_token_table(1).token_name := 'COL_NAME';
3023            l_token_table(1).token_value := 'ENABLED_FLAG';
3024 
3025           ERROR_HANDLER.Add_Error_Message(
3026             p_message_name                  => 'EGO_INVALID_VALUE_FOR_COL'
3027            ,p_application_id                => G_APPL_NAME
3028            ,p_token_tbl                     => l_token_table
3029            ,p_row_identifier                => p_icc_rec.transaction_id
3030            ,p_entity_code                   => l_entity_code
3031            ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3032          );
3033          l_token_table.DELETE;
3034            write_debug(l_proc_name, 'Err_Msg-TID='
3035                    ||p_icc_rec.transaction_id||'-(ICC)=('
3036                    ||p_icc_rec.item_catalog_name
3037                    ||') invalid value for col ENABLED_FLAG'
3038                  );
3039 
3040 
3041     END IF;
3042   END IF;
3043 
3044   IF p_icc_rec.ITEM_CREATION_ALLOWED_FLAG IS NOT NULL
3045         AND p_icc_rec.ITEM_CREATION_ALLOWED_FLAG <> G_MISS_CHAR THEN
3046 
3047     IF p_icc_rec.ITEM_CREATION_ALLOWED_FLAG NOT IN ( 'Y', 'N') THEN
3048 
3049            x_return_status := G_RET_STS_ERROR;
3050            l_token_table(1).token_name := 'COL_NAME';
3051            l_token_table(1).token_value := 'ITEM_CREATION_ALLOWED_FLAG';
3052 
3053           ERROR_HANDLER.Add_Error_Message(
3054             p_message_name                  => 'EGO_INVALID_VALUE_FOR_COL'
3055            ,p_application_id                => G_APPL_NAME
3056            ,p_token_tbl                     => l_token_table
3057            ,p_row_identifier                => p_icc_rec.transaction_id
3058            ,p_entity_code                   => l_entity_code
3059            ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3060          );
3061          l_token_table.DELETE;
3062            write_debug(l_proc_name, 'Err_Msg-TID='
3063                    ||p_icc_rec.transaction_id||'-(ICC)=('
3064                    ||p_icc_rec.item_catalog_name
3065                    ||') invalid value for col ITEM_CREATION_ALLOWED_FLAG'
3066                  );
3067 
3068 
3069     END IF;
3070   END IF;
3071 
3072 
3073   IF p_icc_rec.ENABLE_KEY_ATTRS_DESC IS NOT NULL
3074         AND p_icc_rec.ENABLE_KEY_ATTRS_DESC <> G_MISS_CHAR THEN
3075 
3076     IF p_icc_rec.ENABLE_KEY_ATTRS_DESC NOT IN ( 'Y', 'N') THEN
3077 
3078            x_return_status := G_RET_STS_ERROR;
3079            l_token_table(1).token_name := 'COL_NAME';
3080            l_token_table(1).token_value := 'ENABLE_KEY_ATTRS_DESC';
3081 
3082           ERROR_HANDLER.Add_Error_Message(
3083             p_message_name                  => 'EGO_INVALID_VALUE_FOR_COL'
3084            ,p_application_id                => G_APPL_NAME
3085            ,p_token_tbl                     => l_token_table
3086            ,p_row_identifier                => p_icc_rec.transaction_id
3087            ,p_entity_code                   => l_entity_code
3088            ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3089          );
3090          l_token_table.DELETE;
3091          write_debug(l_proc_name, 'Err_Msg-TID='
3092                ||p_icc_rec.transaction_id||'-(ICC)=('
3093                ||p_icc_rec.item_catalog_name
3094                ||') invalid value for col ENABLE_KEY_ATTRS_DESC'
3095              );
3096 
3097     END IF;
3098   END IF;
3099 
3100   IF p_icc_rec.ENABLE_KEY_ATTRS_NUM IS NOT NULL
3101         AND p_icc_rec.ENABLE_KEY_ATTRS_NUM <> G_MISS_CHAR THEN
3102 
3103     IF p_icc_rec.ENABLE_KEY_ATTRS_NUM NOT IN ( 'Y', 'N') THEN
3104 
3105            x_return_status := G_RET_STS_ERROR;
3106            l_token_table(1).token_name := 'COL_NAME';
3107            l_token_table(1).token_value := 'ENABLE_KEY_ATTRS_NUM';
3108 
3109           ERROR_HANDLER.Add_Error_Message(
3110             p_message_name                  => 'EGO_INVALID_VALUE_FOR_COL'
3111            ,p_application_id                => G_APPL_NAME
3112            ,p_token_tbl                     => l_token_table
3113            ,p_row_identifier                => p_icc_rec.transaction_id
3114            ,p_entity_code                   => l_entity_code
3115            ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3116          );
3117          l_token_table.DELETE;
3118          write_debug(l_proc_name, 'Err_Msg-TID='
3119                ||p_icc_rec.transaction_id||'-(ICC)=('
3120                ||p_icc_rec.item_catalog_name
3121                ||') invalid value for col ENABLE_KEY_ATTRS_NUM'
3122              );
3123 
3124     END IF;
3125   END IF;
3126 
3127   write_debug(l_proc_name,'End');
3128 
3129 EXCEPTION
3130 WHEN OTHERS THEN
3131   x_return_status := G_RET_STS_UNEXP_ERROR;
3132   x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
3133 END Validate_YesNo_Cols;
3134 
3135 
3136 
3137 
3138 /********************************************************************
3139 ---   This procedure accepts a icc intf. record type , does value to id
3140 ---   conversion and other validations for function related columns
3141 ---
3142 ********************************************************************/
3143 
3144 PROCEDURE Validate_Func_Related_Cols ( p_icc_rec       IN OUT NOCOPY ego_icc_rec_type
3145                                       ,x_return_status OUT NOCOPY VARCHAR2
3146                                       ,x_return_msg    OUT NOCOPY VARCHAR2
3147                                      )
3148 IS
3149   l_proc_name  CONSTANT VARCHAR2(30) := 'Validate_Func_Related_Cols';
3150   -- for error logging
3151   --
3152   l_entity_code     VARCHAR2(30) := G_ENTITY_ICC_HEADER;
3153   l_token_table     ERROR_HANDLER.Token_Tbl_Type;
3154 
3155   l_function_id     NUMBER := NULL;
3156   l_func_params_tbl ego_func_param_map_tbl_type;
3157 
3158   l_return_msg      VARCHAR2(4000);
3159   l_return_status   VARCHAR2(1);
3160   l_seq_name        VARCHAR2(30);
3161 
3162 
3163 BEGIN
3164   write_debug(l_proc_name,'Start');
3165   X_return_status := G_RET_STS_SUCCESS;
3166 
3167   --- number generation method type
3168   ---
3169  IF p_icc_rec.ITEM_NUM_GEN_METHOD_TYPE IS NOT NULL
3170              AND p_icc_rec.ITEM_NUM_GEN_METHOD_TYPE <> G_MISS_CHAR THEN
3171 
3172     IF NOT Check_Lookup_value ( p_code => p_icc_rec.ITEM_NUM_GEN_METHOD_TYPE , p_lookup => 'EGO_ITEM_NUM_GEN_METHOD') THEN
3173 
3174            x_return_status := G_RET_STS_ERROR;   -- added bug 9737833
3175            l_token_table(1).token_name := 'ITEM_NUM_GEN_METHOD_TYPE';
3176            l_token_table(1).token_value := p_icc_rec.ITEM_NUM_GEN_METHOD_TYPE;
3177 
3178           ERROR_HANDLER.Add_Error_Message(
3179             p_message_name                  => 'EGO_FUNC_TYPECODE_INVALID'
3180            ,p_application_id                => G_APPL_NAME
3181            ,p_token_tbl                     => l_token_table
3182            ,p_row_identifier                => p_icc_rec.transaction_id
3183            ,p_entity_code                   => l_entity_code
3184            ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3185          );
3186          l_token_table.DELETE;
3187 
3188     END IF;
3189 
3190 
3191     if p_icc_rec.ITEM_NUM_GEN_METHOD_TYPE = 'U' THEN
3192            --- null out the other columns
3193            ---
3194            p_icc_rec.prefix := G_MISS_CHAR;
3195            p_icc_rec.starting_number := G_MISS_NUM;
3196            p_icc_rec.suffix := G_MISS_CHAR;
3197            p_icc_rec.increment_by :=   G_MISS_NUM;
3198            p_icc_rec.item_num_action_id := G_MISS_NUM;
3199 
3200     ELSIF  p_icc_rec.ITEM_NUM_GEN_METHOD_TYPE = 'S' THEN
3201           --- starting number and increment should be provided
3202           ---
3203           p_icc_rec.item_num_action_id := g_miss_num;
3204 
3205           IF (p_icc_rec.starting_number IS NULL OR p_icc_rec.starting_number = G_MISS_NUM )
3206               OR
3207              (p_icc_rec.increment_by IS NULL OR p_icc_rec.increment_by = G_MISS_NUM) THEN
3208               x_return_status := G_RET_STS_ERROR;
3209 
3210              ERROR_HANDLER.Add_Error_Message(
3211                p_message_name                  => 'EGO_ITEM_NUM_FN_COLS_INVALID'
3212               ,p_application_id                => G_APPL_NAME
3213 
3214               ,p_row_identifier                => p_icc_rec.transaction_id
3215               ,p_entity_code                   => l_entity_code
3216               ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3217             );
3218           ELSE /* addd below condition bug 9737368 */
3219 
3220             IF  p_icc_rec.starting_number <=0 OR
3221                 p_icc_rec.increment_by <= 0 THEN
3222 
3223                   x_return_status := G_RET_STS_ERROR;
3224 
3225                  ERROR_HANDLER.Add_Error_Message(
3226                    p_message_name                  => 'EGO_ITEM_NUM_FN_COLS_INVALID'
3227                   ,p_application_id                => G_APPL_NAME
3228                   ,p_row_identifier                => p_icc_rec.transaction_id
3229                   ,p_entity_code                   => l_entity_code
3230                   ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3231                 );
3232 
3233                  ERROR_HANDLER.Add_Error_Message(
3234                    p_message_name                  => 'EGO_INPUT_NUMBERS_ONLY'
3235                   ,p_application_id                => G_APPL_NAME
3236                   ,p_row_identifier                => p_icc_rec.transaction_id
3237                   ,p_entity_code                   => l_entity_code
3238                   ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3239                 );
3240 
3241            END IF;
3242 
3243           END if;
3244 
3245 
3246 
3247 
3248 
3249     ELSIF  p_icc_rec.ITEM_NUM_GEN_METHOD_TYPE = 'F' THEN
3250 
3251            --- null out the other columns
3252            ---
3253            p_icc_rec.prefix := G_MISS_CHAR;
3254            p_icc_rec.starting_number := g_miss_num;
3255            p_icc_rec.suffix := g_miss_char;
3256            p_icc_rec.increment_by :=   g_miss_num;
3257            p_icc_rec.item_num_action_id := g_miss_num;
3258            p_icc_rec.item_num_seq_name := g_miss_char;
3259 
3260            l_function_id := null;
3261            -- validate function id
3262 
3263            --- if none of function_id or name provided then Error
3264            ---
3265            if p_icc_rec.ITEM_NUM_FUNCTION_ID IS  NULL AND p_icc_rec.ITEM_NUM_GENERATION_FUNCTION IS  NULL then
3266                  x_return_status := G_RET_STS_ERROR;
3267 
3268                  ERROR_HANDLER.Add_Error_Message(
3269                    p_message_name                  => 'EGO_ITEM_NUM_FUNC_INVALID'
3270                   ,p_application_id                => G_APPL_NAME
3271 
3272                   ,p_row_identifier                => p_icc_rec.transaction_id
3273                   ,p_entity_code                   => l_entity_code
3274                   ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3275                 );
3276 
3277            --- Validate the id
3278            ---
3279            ELSIF p_icc_rec.ITEM_NUM_FUNCTION_ID IS NOT NULL AND p_icc_rec.ITEM_NUM_FUNCTION_ID <> G_MISS_NUM THEN
3280 
3281               l_function_id :=  Check_Function ( p_func_id => p_icc_rec.ITEM_NUM_FUNCTION_ID );
3282               write_debug ( l_proc_name, ' function id =>'||l_function_id);
3283 
3284               IF l_function_id IS NULL THEN
3285 
3286                  x_return_status := G_RET_STS_ERROR;
3287 
3288                  ERROR_HANDLER.Add_Error_Message(
3289                    p_message_name                  => 'EGO_ITEM_NUM_FUNC_INVALID'
3290                   ,p_application_id                => G_APPL_NAME
3291 
3292                   ,p_row_identifier                => p_icc_rec.transaction_id
3293                   ,p_entity_code                   => l_entity_code
3294                   ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3295                 );
3296 
3297               end if;
3298 
3299            --- validate the name
3300            ---
3301            ELSIF p_icc_rec.ITEM_NUM_GENERATION_FUNCTION IS NOT NULL AND p_icc_rec.ITEM_NUM_GENERATION_FUNCTION <> G_MISS_CHAR
3302               AND p_icc_rec.ITEM_NUM_FUNCTION_ID IS NULL THEN
3303 
3304                 write_debug ( l_proc_name, ' func name =>'||p_icc_rec.ITEM_NUM_GENERATION_FUNCTION);
3305                 l_function_id := Check_Function ( p_func_name => p_icc_rec.ITEM_NUM_GENERATION_FUNCTION );
3306                 write_debug ( l_proc_name, ' function id from func name =>'||NVL(l_function_id, -999));
3307                 IF l_function_id IS NULL THEN
3308 
3309                    x_return_status := G_RET_STS_ERROR;
3310 
3311                    ERROR_HANDLER.Add_Error_Message(
3312                      p_message_name                  => 'EGO_ITEM_NUM_FUNC_INVALID'
3313                     ,p_application_id                => G_APPL_NAME
3314                     ,p_row_identifier                => p_icc_rec.transaction_id
3315                     ,p_entity_code                   => l_entity_code
3316                     ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3317                   );
3318                  else
3319                    p_icc_rec.ITEM_NUM_FUNCTION_ID := l_function_id;
3320                 end if;
3321            ELSE
3322              NULL;
3323            end if;
3324 
3325     ---
3326     --- Added below condition bug 9737144
3327     ---
3328     ELSIF p_icc_rec.ITEM_NUM_GEN_METHOD_TYPE = 'I' THEN
3329 
3330           IF p_icc_rec.transaction_type = G_TTYPE_CREATE
3331               AND p_icc_rec.parent_catalog_group_id IS NULL
3332               OR p_icc_rec.parent_catalog_group_id = G_MISS_NUM THEN
3333 
3334                   x_return_status := G_RET_STS_ERROR;
3335 
3336                   l_token_table(1).token_name := 'ICC_NAME';
3337                   l_token_table(1).token_value := p_icc_rec.item_catalog_name;
3338 
3339                   l_token_table(2).token_name := 'COL_NAME';
3340                   l_token_table(2).token_value := 'ITEM_NUM_GEN_METHOD_TYPE';
3341 
3342 
3343                    ERROR_HANDLER.Add_Error_Message(
3344                      p_message_name                  => 'EGO_INVALID_VAL_PARENT_MISSING'
3345                     ,p_application_id                => G_APPL_NAME
3346                     ,p_token_tbl                     => l_token_table
3347                     ,p_row_identifier                => p_icc_rec.transaction_id
3348                     ,p_entity_code                   => l_entity_code
3349                     ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3350                   );
3351                   l_token_table.delete;
3352 
3353 
3354            ELSIF p_icc_rec.transaction_type = G_TTYPE_UPDATE
3355                 AND ( p_icc_rec.parent_catalog_group_id = G_MISS_NUM         --- trying to NULL out the parent
3356                       OR
3357                       ( p_icc_rec.parent_catalog_group_id IS NULL            --- parent ICC already exists check
3358                         AND
3359                         g_old_icc_rec.parent_catalog_group_id IS NULL
3360                       )
3361                     )  THEN
3362 
3363                     x_return_status := G_RET_STS_ERROR;
3364 
3365                   l_token_table(1).token_name := 'ICC_NAME';
3366                   l_token_table(1).token_value := p_icc_rec.item_catalog_name;
3367 
3368                   l_token_table(2).token_name := 'COL_NAME';
3369                   l_token_table(2).token_value := 'ITEM_NUM_GEN_METHOD_TYPE';
3370 
3371 
3372                    ERROR_HANDLER.Add_Error_Message(
3373                      p_message_name                  => 'EGO_INVALID_VAL_PARENT_MISSING'
3374                     ,p_application_id                => G_APPL_NAME
3375                     ,p_token_tbl                     => l_token_table
3376                     ,p_row_identifier                => p_icc_rec.transaction_id
3377                     ,p_entity_code                   => l_entity_code
3378                     ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3379                   );
3380                   l_token_table.delete;
3381              END IF;
3382 
3383     END IF;  --- method Type
3384   END IF;   --- ITEM_NUM_GEN_METHOD_TYPE
3385 
3386   write_debug(l_proc_name,'Start Descriptin function validation');
3387 
3388   --- Description Generation method validation
3389   ---
3390   IF p_icc_rec.ITEM_DESC_GEN_METHOD_TYPE IS NOT NULL AND p_icc_rec.ITEM_DESC_GEN_METHOD_TYPE <> G_MISS_CHAR THEN
3391 
3392     IF NOT Check_Lookup_Value ( p_code => p_icc_rec.ITEM_DESC_GEN_METHOD_TYPE , p_lookup => 'EGO_ITEM_DESC_GEN_METHOD' )    THEN
3393 
3394              x_return_status := G_RET_STS_ERROR;
3395 
3396              l_token_table(1).token_name := 'ITEM_DESC_GEN_METHOD_TYPE';
3397              l_token_table(1).token_value := p_icc_rec.ITEM_DESC_GEN_METHOD_TYPE;
3398 
3399             ERROR_HANDLER.Add_Error_Message(
3400               p_message_name                  => 'EGO_FUNC_TYPECODE_INVALID'
3401              ,p_application_id                => G_APPL_NAME
3402              ,p_token_tbl                     => l_token_table
3403 
3404              ,p_row_identifier                => p_icc_rec.transaction_id
3405              ,p_entity_code                   => l_entity_code
3406              ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3407            );
3408            l_token_table.DELETE;
3409     END IF;
3410 
3411     IF p_icc_rec.ITEM_DESC_GEN_METHOD_TYPE = 'U' THEN
3412 
3413       p_icc_rec.ITEM_DESC_ACTION_ID := G_MISS_NUM;
3414 
3415     ELSIF p_icc_rec.ITEM_DESC_GEN_METHOD_TYPE = 'F' THEN
3416 
3417            --- if none of function_id or name provided then Error
3418            ---
3419            l_function_id := NULL;
3420            IF p_icc_rec.ITEM_DESC_FUNCTION_ID IS  NULL AND p_icc_rec.ITEM_desc_GENERATION_FUNCTION IS  NULL then
3421                  x_return_status := G_RET_STS_ERROR;
3422 
3423                  ERROR_HANDLER.Add_Error_Message(
3424                    p_message_name                  => 'EGO_ITEM_DESC_FUNC_INVALID'
3425                   ,p_application_id                => G_APPL_NAME
3426 
3427                   ,p_row_identifier                => p_icc_rec.transaction_id
3428                   ,p_entity_code                   => l_entity_code
3429                   ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3430                 );
3431 
3432 
3433            --- Validate the id
3434            ---
3435            ELSIF p_icc_rec.ITEM_DESC_FUNCTION_ID IS NOT NULL AND p_icc_rec.ITEM_DESC_FUNCTION_ID <> G_MISS_NUM THEN
3436 
3437               l_function_id :=  Check_Function ( p_func_id => p_icc_rec.ITEM_DESC_FUNCTION_ID );
3438               IF l_function_id IS NULL THEN
3439 
3440                  x_return_status := G_RET_STS_ERROR;
3441 
3442                  ERROR_HANDLER.Add_Error_Message(
3443                    p_message_name                  => 'EGO_ITEM_DESC_FUNC_INVALID'
3444                   ,p_application_id                => G_APPL_NAME
3445 
3446                   ,p_row_identifier                => p_icc_rec.transaction_id
3447                   ,p_entity_code                   => l_entity_code
3448                   ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3449                 );
3450 
3451                 p_icc_rec.ITEM_DESC_FUNCTION_ID := G_MISS_NUM;
3452               end if;
3453 
3454            --- validate the name
3455            ---
3456            ELSIF p_icc_rec.ITEM_DESC_GENERATION_FUNCTION IS NOT NULL AND p_icc_rec.ITEM_desc_GENERATION_FUNCTION <> G_MISS_CHAR
3457               AND p_icc_rec.ITEM_DESC_FUNCTION_ID IS NULL THEN
3458 
3459                 l_function_id := Check_Function ( p_func_name => p_icc_rec.ITEM_desc_GENERATION_FUNCTION );
3460                 IF l_function_id IS NULL THEN
3461 
3462                    x_return_status := G_RET_STS_ERROR;
3463 
3464                    ERROR_HANDLER.Add_Error_Message(
3465                      p_message_name                  => 'EGO_ITEM_NUM_FUNC_INVALID'
3466                     ,p_application_id                => G_APPL_NAME
3467 
3468                     ,p_row_identifier                => p_icc_rec.transaction_id
3469                     ,p_entity_code                   => l_entity_code
3470                     ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3471                   );
3472                  else
3473                    p_icc_rec.ITEM_DESC_FUNCTION_ID := l_function_id;
3474                 end if;
3475            else
3476              null;
3477            end if;
3478 
3479     ---
3480     --- Added below condition bug 9737144
3481     ---
3482     ELSIF p_icc_rec.ITEM_DESC_GEN_METHOD_TYPE = 'I' THEN
3483 
3484           IF p_icc_rec.transaction_type = G_TTYPE_CREATE
3485               AND p_icc_rec.parent_catalog_group_id IS NULL
3486               OR p_icc_rec.parent_catalog_group_id = G_MISS_NUM THEN
3487 
3488                   x_return_status := G_RET_STS_ERROR;
3489 
3490                   l_token_table(1).token_name := 'ICC_NAME';
3491                   l_token_table(1).token_value := p_icc_rec.item_catalog_name;
3492 
3493                   l_token_table(2).token_name := 'COL_NAME';
3494                   l_token_table(2).token_value := 'ITEM_DESC_GEN_METHOD_TYPE';
3495 
3496 
3497                    ERROR_HANDLER.Add_Error_Message(
3498                      p_message_name                  => 'EGO_INVALID_VAL_PARENT_MISSING'
3499                     ,p_application_id                => G_APPL_NAME
3500                     ,p_token_tbl                     => l_token_table
3501                     ,p_row_identifier                => p_icc_rec.transaction_id
3502                     ,p_entity_code                   => l_entity_code
3503                     ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3504                   );
3505                   l_token_table.delete;
3506 
3507 
3508            ELSIF p_icc_rec.transaction_type = G_TTYPE_UPDATE
3509                 AND ( p_icc_rec.parent_catalog_group_id = G_MISS_NUM         --- trying to NULL out the parent
3510                       OR
3511                       ( p_icc_rec.parent_catalog_group_id IS NULL            --- parent ICC already exists check
3512                         AND
3513                         g_old_icc_rec.parent_catalog_group_id IS NULL
3514                       )
3515                     )  THEN
3516 
3517                     x_return_status := G_RET_STS_ERROR;
3518 
3519                   l_token_table(1).token_name := 'ICC_NAME';
3520                   l_token_table(1).token_value := p_icc_rec.item_catalog_name;
3521 
3522                   l_token_table(2).token_name := 'COL_NAME';
3523                   l_token_table(2).token_value := 'ITEM_DESC_GEN_METHOD_TYPE';
3524 
3525 
3526                    ERROR_HANDLER.Add_Error_Message(
3527                      p_message_name                  => 'EGO_INVALID_VAL_PARENT_MISSING'
3528                     ,p_application_id                => G_APPL_NAME
3529                     ,p_token_tbl                     => l_token_table
3530                     ,p_row_identifier                => p_icc_rec.transaction_id
3531                     ,p_entity_code                   => l_entity_code
3532                     ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3533                   );
3534                   l_token_table.delete;
3535              END IF;
3536 
3537     END IF; --- method type
3538 
3539   END IF;   --- p_icc_rec.ITEM_DESC_GEN_METHOD_TYPE IS NOT NULL
3540 
3541   write_debug(l_proc_name,'End');
3542 EXCEPTION
3543 WHEN OTHERS THEN
3544   x_return_status := G_RET_STS_UNEXP_ERROR;
3545   x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
3546 END Validate_Func_Related_Cols;
3547 
3548 
3549 /********************************************************************
3550 ---   This procedure accepts a record type , validates the NIR related
3551 ---   columns of the ICC
3552 ---
3553 ********************************************************************/
3554 
3555 PROCEDURE validate_NIR_Columns   ( p_icc_rec        IN OUT NOCOPY ego_icc_rec_type
3556                                   ,x_return_status OUT NOCOPY VARCHAR2
3557                                  )
3558 IS
3559   l_proc_name  CONSTANT VARCHAR2(30) := 'validate_NIR_Columns';
3560   -- for error logging
3561   --
3562   l_entity_code     VARCHAR2(30) := G_ENTITY_ICC_HEADER;
3563   l_token_table     ERROR_HANDLER.Token_Tbl_Type;
3564 
3565   l_change_order_type ENG_CHANGE_ORDER_TYPES.change_order_type%TYPE := null;
3566   l_change_type_id   NUMBER := NULL;
3567 
3568    FUNCTION Check_Change_OrderType ( p_change_order_type_id  IN NUMBER DEFAULT NULL
3569                                    ,p_change_order_type_name IN VARCHAR2 DEFAULT NULL
3570                                   )
3571    RETURN NUMBER
3572    IS
3573      l_cotype_id    NUMBER := NULL;
3574 
3575      CURSOR cur_cotype
3576      IS
3577      SELECT change_order_type_id
3578      FROM eng_change_order_types_vl
3579      where (  change_order_type_id = nvl(p_change_order_type_id, change_order_type_id)
3580               AND
3581               change_order_type = nvl(p_change_order_type_name, change_order_type)
3582            )
3583      ;
3584    BEGIN
3585 
3586      for rec_cotype IN cur_cotype
3587      loop
3588          l_cotype_id := rec_cotype.change_order_type_id;
3589 
3590      end loop;
3591 
3592      RETURN l_cotype_id;
3593 
3594   END Check_Change_OrderType;
3595 
3596 BEGIN
3597     write_debug(l_proc_name,'Start');
3598     x_return_status := G_RET_STS_SUCCESS;
3599 
3600     IF p_icc_rec.NEW_ITEM_REQUEST_TYPE is not null and p_icc_rec.NEW_ITEM_REQUEST_TYPE <> G_MISS_CHAR THEN
3601 
3602         IF NOT Check_Lookup_value ( p_code => p_icc_rec.NEW_ITEM_REQUEST_TYPE , p_lookup => 'EGO_NIR_SETUP_CHOICE_LIST') THEN
3603 
3604                x_return_status := G_RET_STS_ERROR;
3605                l_token_table(1).token_name := 'NIR_TYPE';
3606                l_token_table(1).token_value := p_icc_rec.NEW_ITEM_REQUEST_TYPE;
3607 
3608               ERROR_HANDLER.Add_Error_Message(
3609                 p_message_name                  => 'EGO_ICC_NIR_TYPE_INVALID'
3610                ,p_application_id                => G_APPL_NAME
3611                ,p_token_tbl                     => l_token_table
3612                ,p_row_identifier                => p_icc_rec.transaction_id
3613                ,p_entity_code                   => l_entity_code
3614                ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3615              );
3616              l_token_table.DELETE;
3617 
3618         END IF;
3619 
3620     END IF;
3621 
3622     IF p_icc_rec.NEW_ITEM_REQUEST_TYPE = 'Y' THEN -- specify for category
3623 
3624       l_change_type_id := NULL;
3625       IF p_icc_rec.NEW_ITEM_REQ_CHANGE_TYPE_ID IS NOT NULL
3626                AND p_icc_rec.NEW_ITEM_REQ_CHANGE_TYPE_ID  <> G_MISS_NUM THEN
3627 
3628           l_change_type_id :=  Check_Change_OrderType ( p_change_order_type_id => p_icc_rec.NEW_ITEM_REQ_CHANGE_TYPE_ID );
3629 
3630           IF l_change_type_id IS NULL THEN
3631                   x_return_status := G_RET_STS_ERROR;
3632                   l_token_table(1).token_name := 'VALUE';
3633                   l_token_table(1).token_value := p_icc_rec.NEW_ITEM_REQ_CHANGE_TYPE_ID;
3634 
3635                  ERROR_HANDLER.Add_Error_Message(
3636                    p_message_name                  => 'EGO_CHGTYPE_DOESNOT_EXIST'
3637                   ,p_application_id                => G_APPL_NAME
3638                   ,p_token_tbl                     => l_token_table
3639                   ,p_row_identifier                => p_icc_rec.transaction_id
3640                   ,p_entity_code                   => l_entity_code
3641                   ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3642                 );
3643                 l_token_table.delete;
3644                 p_icc_rec.NEW_ITEM_REQ_CHANGE_TYPE_ID := NULL;
3645           END IF;
3646 
3647       ELSIF p_icc_rec.NEW_ITEM_REQUEST_NAME IS NOT NULL
3648              AND p_icc_rec.NEW_ITEM_REQUEST_NAME <> G_MISS_CHAR THEN
3649 
3650             l_change_type_id := Check_Change_OrderType ( p_change_order_type_name => p_icc_rec.NEW_ITEM_REQUEST_NAME);
3651 
3652             IF l_change_type_id IS NULL THEN
3653                     x_return_status := G_RET_STS_ERROR;
3654                     l_token_table(1).token_name := 'VALUE';
3655                     l_token_table(1).token_value := p_icc_rec.NEW_ITEM_REQUEST_NAME;
3656 
3657                    ERROR_HANDLER.Add_Error_Message(
3658                      p_message_name                  => 'EGO_CHGTYPE_DOESNOT_EXIST'
3659                     ,p_application_id                => G_APPL_NAME
3660                     ,p_token_tbl                     => l_token_table
3661                     ,p_row_identifier                => p_icc_rec.transaction_id
3662                     ,p_entity_code                   => l_entity_code
3663                     ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3664                   );
3665                   l_token_table.delete;
3666                   p_icc_rec.NEW_ITEM_REQ_CHANGE_TYPE_ID := NULL;
3667              ELSE
3668                p_icc_rec.NEW_ITEM_REQ_CHANGE_TYPE_ID := l_change_type_id;
3669             end IF;
3670       ELSIF p_icc_rec.NEW_ITEM_REQ_CHANGE_TYPE_ID  <> G_MISS_NUM OR p_icc_rec.NEW_ITEM_REQUEST_NAME <> G_MISS_CHAR THEN
3671 
3672                 x_return_status := G_RET_STS_ERROR;
3673                 l_token_table(1).token_name := 'VALUE';
3674                 l_token_table(1).token_value := p_icc_rec.NEW_ITEM_REQUEST_NAME;
3675 
3676                ERROR_HANDLER.Add_Error_Message(
3677                  p_message_name                  => 'EGO_CHGTYPE_DOESNOT_EXIST'
3678                 ,p_application_id                => G_APPL_NAME
3679                 ,p_token_tbl                     => l_token_table
3680                 ,p_row_identifier                => p_icc_rec.transaction_id
3681                 ,p_entity_code                   => l_entity_code
3682                 ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3683               );
3684               l_token_table.delete;
3685       END IF;
3686 
3687     ---
3688     --- Added below condition bug 9737144
3689     ---
3690     ELSIF p_icc_rec.NEW_ITEM_REQUEST_TYPE = 'I' THEN
3691 
3692       IF p_icc_rec.transaction_type = G_TTYPE_CREATE
3693           AND p_icc_rec.parent_catalog_group_id IS NULL
3694           OR p_icc_rec.parent_catalog_group_id = G_MISS_NUM THEN
3695 
3696               x_return_status := G_RET_STS_ERROR;
3697 
3698               l_token_table(1).token_name := 'ICC_NAME';
3699               l_token_table(1).token_value := p_icc_rec.item_catalog_name;
3700 
3701               l_token_table(2).token_name := 'COL_NAME';
3702               l_token_table(2).token_value := 'NEW_ITEM_REQUEST_TYPE';
3703 
3704 
3705                ERROR_HANDLER.Add_Error_Message(
3706                  p_message_name                  => 'EGO_INVALID_VAL_PARENT_MISSING'
3707                 ,p_application_id                => G_APPL_NAME
3708                 ,p_token_tbl                     => l_token_table
3709                 ,p_row_identifier                => p_icc_rec.transaction_id
3710                 ,p_entity_code                   => l_entity_code
3711                 ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3712               );
3713               l_token_table.delete;
3714 
3715 
3716       ELSIF p_icc_rec.transaction_type = G_TTYPE_UPDATE
3717             AND ( p_icc_rec.parent_catalog_group_id = G_MISS_NUM         --- trying to NULL out the parent
3718                   OR
3719                   ( p_icc_rec.parent_catalog_group_id IS NULL            --- parent ICC already exists check
3720                     AND
3721                     g_old_icc_rec.parent_catalog_group_id IS NULL
3722                   )
3723                 )  THEN
3724 
3725                 x_return_status := G_RET_STS_ERROR;
3726 
3727               l_token_table(1).token_name := 'ICC_NAME';
3728               l_token_table(1).token_value := p_icc_rec.item_catalog_name;
3729 
3730               l_token_table(2).token_name := 'COL_NAME';
3731               l_token_table(2).token_value := 'NEW_ITEM_REQUEST_TYPE';
3732 
3733 
3734                ERROR_HANDLER.Add_Error_Message(
3735                  p_message_name                  => 'EGO_INVALID_VAL_PARENT_MISSING'
3736                 ,p_application_id                => G_APPL_NAME
3737                 ,p_token_tbl                     => l_token_table
3738                 ,p_row_identifier                => p_icc_rec.transaction_id
3739                 ,p_entity_code                   => l_entity_code
3740                 ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
3741               );
3742               l_token_table.delete;
3743 
3744       END IF;
3745 
3746 
3747     ELSIF p_icc_rec.NEW_ITEM_REQUEST_TYPE = 'N' OR p_icc_rec.NEW_ITEM_REQUEST_TYPE = G_MISS_CHAR THEN
3748       p_icc_rec.NEW_ITEM_REQ_CHANGE_TYPE_ID := NULL;
3749     END IF;
3750 
3751   write_debug(l_proc_name,'End');
3752 EXCEPTION
3753 WHEN OTHERS THEN
3754     x_return_status := G_RET_STS_UNEXP_ERROR;
3755 END validate_NIR_Columns;
3756 
3757 
3758  /********************************************************************
3759  --- gets the details for the earlier ICC
3760  --- for UPDATE transaction
3761  ********************************************************************/
3762 
3763  PROCEDURE Fetch_Old_ICC_Dtls  ( p_old_icc_rec   IN OUT NOCOPY mtl_item_catalog_groups_b%ROWTYPE
3764                                 ,p_icc_id        IN NUMBER
3765                                )
3766  IS
3767 
3768    l_proc_name   VARCHAR2(30) := 'Fetch_Old_ICC_Dtls';
3769  BEGIN
3770    write_debug(l_proc_name,'Start');
3771 
3772    SELECT *
3773    INTO p_old_icc_rec
3774    FROM mtl_item_catalog_groups_b
3775    WHERE item_catalog_group_id = p_icc_id;
3776 
3777    write_debug(l_proc_name,'End');
3778  END Fetch_Old_ICC_Dtls;
3779 
3780 /********************************************************************
3781 ---   This procedure accepts a record type , defaults values for CREATE
3782 ---   transaction
3783 ********************************************************************/
3784     PROCEDURE Attribute_Defaulting  (    p_entity         IN varchar2
3785                                         , p_icc_rec        IN OUT NOCOPY ego_icc_rec_type
3786                                         , p_ag_assoc_rec   IN OUT NOCOPY ego_ag_assoc_rec_type
3787                                         , p_func_param_assoc_rec IN OUT NOCOPY ego_func_param_map_rec_type
3788                                         , p_icc_ver_rec    IN OUT NOCOPY ego_icc_vers_rec_type
3789                                         , x_return_status    OUT NOCOPY VARCHAR2
3790                                         , x_return_msg  OUT NOCOPY VARCHAR2
3791                                      )
3792     IS
3793      l_proc_name  CONSTANT VARCHAR2(30) := 'Attribute_Defaulting';
3794      l_null_icc_rec_type EGO_ITEM_CATALOG_PUB.Catalog_Group_Rec_Type := null ;
3795      l_Mesg_Token_tbl  Error_Handler.Mesg_Token_Tbl_Type;
3796 
3797 
3798      -- for error logging
3799      --
3800      l_entity_code     VARCHAR2(30) := G_ENTITY_ICC_HEADER;
3801      l_token_table     ERROR_HANDLER.Token_Tbl_Type;
3802 
3803 
3804 
3805      BEGIN
3806        write_debug(l_proc_name,'Start');
3807        x_return_status := G_RET_STS_SUCCESS;
3808 
3809         IF p_entity = G_ENTITY_ICC_HEADER then
3810 
3811             --- defaulting of other columns takes place in the EGO_ITEM_CATALOG_PUB API
3812             ---
3813             IF (p_icc_rec.Item_Creation_Allowed_Flag = G_MISS_CHAR  OR p_icc_rec.Item_Creation_Allowed_Flag IS NULL ) then
3814                 p_icc_rec.Item_Creation_Allowed_Flag := 'N';
3815             END IF;
3816 
3817 
3818              IF fnd_flex_keyval.summary_flag THEN
3819                p_icc_rec.summary_flag := 'Y';
3820              ELSE
3821                p_icc_rec.summary_flag := 'N';
3822              END IF;
3823 
3824 
3825             IF (p_icc_rec.enabled_flag = G_MISS_CHAR  OR p_icc_rec.enabled_flag IS NULL ) then
3826                 p_icc_rec.enabled_flag := 'Y';
3827             END IF;
3828 
3829 
3830             IF p_icc_rec.item_num_action_id = G_MISS_NUM THEN
3831               p_icc_rec.item_num_action_id := null;
3832             END IF;
3833 
3834             IF p_icc_rec.item_desc_action_id = G_MISS_NUM THEN
3835               p_icc_rec.item_desc_action_id := null;
3836             END IF;
3837 
3838             IF p_icc_rec.item_num_seq_name = G_MISS_CHAR THEN
3839               p_icc_rec.item_num_seq_name :=  null;
3840             END IF;
3841 
3842             --- Bug 9737204
3843             IF p_icc_rec.prefix = G_MISS_CHAR THEN
3844                 p_icc_rec.prefix := NULL;
3845             END IF;
3846 
3847             IF p_icc_rec.starting_number = G_MISS_NUM  THEN
3848               p_icc_rec.starting_number := NULL;
3849             END IF;
3850 
3851             IF p_icc_rec.suffix = G_MISS_CHAR then
3852               p_icc_rec.suffix := NULL;
3853             END IF;
3854 
3855             IF p_icc_rec.increment_by = G_MISS_NUM THEN
3856               p_icc_rec.increment_by := NULL;
3857             END IF;
3858 
3859             -- bug 9737204  end
3860 
3861 
3862             IF p_icc_rec.parent_catalog_group_id IS NULL THEN
3863 
3864                 IF (p_icc_rec.item_desc_gen_method_type = G_MISS_CHAR  OR p_icc_rec.item_desc_gen_method_type IS NULL ) then
3865                     p_icc_rec.item_desc_gen_method_type := 'U';  -- User defined
3866                 END IF;
3867 
3868                 IF (p_icc_rec.item_num_gen_method_type = G_MISS_CHAR  OR p_icc_rec.item_num_gen_method_type IS NULL ) then
3869                     p_icc_rec.item_num_gen_method_type := 'U';  -- User defined
3870                 END IF;
3871 
3872                 IF (p_icc_rec.new_item_request_type = G_MISS_CHAR  OR p_icc_rec.new_item_request_type IS NULL ) then
3873                     p_icc_rec.new_item_request_type := 'N';
3874                 END IF;
3875 
3876             ELSE
3877                 IF (p_icc_rec.item_desc_gen_method_type = G_MISS_CHAR  OR p_icc_rec.item_desc_gen_method_type IS NULL ) then
3878                      p_icc_rec.item_desc_gen_method_type := 'I';  -- Inherit from Parent
3879                 END IF;
3880 
3881                 IF (p_icc_rec.item_num_gen_method_type = G_MISS_CHAR  OR p_icc_rec.item_num_gen_method_type IS NULL ) then
3882                      p_icc_rec.item_num_gen_method_type := 'I';   -- Inherit from Parent
3883                 END IF;
3884 
3885                 IF (p_icc_rec.new_item_request_type = G_MISS_CHAR  OR p_icc_rec.new_item_request_type IS NULL ) then
3886                     p_icc_rec.new_item_request_type := 'I';  --- Inherit from parent
3887                 END IF;
3888 
3889             END IF;
3890 
3891         IF p_icc_rec.enable_key_attrs_num is null or p_icc_rec.enable_key_attrs_num = G_MISS_CHAR  THEN
3892           p_icc_rec.enable_key_attrs_num := 'N';
3893         END IF;
3894 
3895 
3896         IF p_icc_rec.enable_key_attrs_desc is null or p_icc_rec.enable_key_attrs_desc = G_MISS_CHAR  THEN
3897           p_icc_rec.enable_key_attrs_desc := 'N';
3898         END IF;
3899 
3900         IF p_icc_rec.new_item_request_type = G_MISS_CHAR THEN
3901           p_icc_rec.new_item_request_type := 'N';
3902         END IF;
3903 
3904         IF p_icc_rec.new_item_req_change_type_id = G_MISS_NUM THEN
3905           p_icc_rec.new_item_request_type := NULL;
3906         END IF;
3907 
3908 
3909         ELSIF p_entity = G_ENTITY_ICC_FN_PARAM_MAP THEN
3910 
3911             --- Default Func param columns
3912             --- no columns as of now
3913             NULL;
3914 
3915         ELSIF p_entity = G_ENTITY_ICC_AG_ASSOC THEN
3916 
3917             --- Default AG association cols
3918             --- no columns as of now
3919             NULL;
3920 
3921         ELSIF p_entity = G_ENTITY_ICC_VERSION THEN
3922 
3923             --- Default Version specific information
3924             ---no columns as of now
3925             null;
3926 
3927         END IF; --- ICC Header
3928 
3929 
3930        write_debug(l_proc_name,'End');
3931      EXCEPTION
3932      WHEN OTHERS THEN
3933         x_return_status := G_RET_STS_UNEXP_ERROR;
3934         x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
3935      end   Attribute_Defaulting;
3936 
3937 
3938 
3939 
3940 /********************************************************************
3941 --- This procedure will look at the columns that the user
3942 --- has not filled in and will assign those columns a
3943 --- value from the database record.
3944 --- This procedure is not called for CREATE
3945 ********************************************************************/
3946     PROCEDURE Populate_Null_Cols   (   p_entity         IN varchar2
3947                                      , p_icc_rec        IN OUT NOCOPY ego_icc_rec_type
3948                                      , p_ag_assoc_rec   IN OUT NOCOPY ego_ag_assoc_rec_type
3949                                      , p_func_param_assoc_rec IN OUT NOCOPY ego_func_param_map_rec_type
3950                                      , x_return_status    OUT NOCOPY VARCHAR2
3951                                      , x_return_msg  OUT NOCOPY VARCHAR2
3952                                     )
3953     IS
3954      l_proc_name  CONSTANT VARCHAR2(30) := 'Populate_Null_Cols';
3955 
3956      l_null_icc_rec_type EGO_ITEM_CATALOG_PUB.Catalog_Group_Rec_Type := null ;
3957      l_Mesg_Token_tbl  Error_Handler.Mesg_Token_Tbl_Type;
3958 
3959 
3960      -- for error logging
3961      --
3962      l_entity_code     VARCHAR2(30) := G_ENTITY_ICC_HEADER;
3963      l_token_table     ERROR_HANDLER.Token_Tbl_Type;
3964 
3965 
3966      BEGIN
3967        write_debug(l_proc_name,'Start');
3968        x_return_status := G_RET_STS_SUCCESS;
3969 
3970         IF p_entity = G_ENTITY_ICC_HEADER THEN
3971 
3972             --- ************************
3973             --- Populate the old values
3974             --- ************************
3975 
3976             IF p_icc_rec.prefix IS NULL THEN
3977                     p_icc_rec.prefix :=  g_old_icc_rec.prefix;
3978             END IF;
3979 
3980             IF  p_icc_rec.starting_number IS NULL THEN
3981                     p_icc_rec.starting_number :=  g_old_icc_rec.starting_number;
3982             END IF;
3983 
3984 
3985             IF  p_icc_rec.increment_by IS NULL THEN
3986                     p_icc_rec.increment_by :=  g_old_icc_rec.increment_by;
3987             END IF;
3988 
3989             IF p_icc_rec.suffix IS NULL THEN
3990                     p_icc_rec.suffix :=  g_old_icc_rec.suffix;
3991             END IF;
3992 
3993             IF p_icc_rec.item_num_seq_name IS NULL THEN
3994                     p_icc_rec.item_num_seq_name :=  g_old_icc_rec.item_num_seq_name;
3995             END IF;
3996 
3997             IF p_icc_rec.item_num_action_id IS NULL THEN
3998                     p_icc_rec.item_num_action_id :=  g_old_icc_rec.item_num_action_id;
3999             END IF;
4000 
4001 
4002             IF p_icc_rec.ITEM_NUM_GEN_METHOD_TYPE IS NULL THEN
4003                     p_icc_rec.ITEM_NUM_GEN_METHOD_TYPE :=  g_old_icc_rec.ITEM_NUM_GEN_METHOD;
4004             END IF;
4005 
4006 
4007             IF p_icc_rec.ITEM_DESC_GEN_METHOD_TYPE IS NULL THEN
4008                     p_icc_rec.ITEM_DESC_GEN_METHOD_TYPE :=  g_old_icc_rec.ITEM_DESC_GEN_METHOD;
4009             END IF;
4010 
4011             IF  p_icc_rec.item_desc_action_id IS NULL THEN
4012                     p_icc_rec.item_desc_action_id :=  g_old_icc_rec.item_desc_action_id;
4013             END IF;
4014 
4015 
4016             IF p_icc_rec.new_item_req_change_type_id IS NULL THEN
4017                     p_icc_rec.new_item_req_change_type_id :=  g_old_icc_rec.new_item_req_change_type_id;
4018             END IF;
4019 
4020             IF  p_icc_rec.new_item_request_type IS NULL THEN
4021                     p_icc_rec.new_item_request_type :=  g_old_icc_rec.NEW_ITEM_REQUEST_REQD;
4022             END IF;
4023 
4024         --
4025         -- Bug 12394675. Issue #4
4026         -- Populating enable_key_attrs made in
4027         -- create_action_for_func method from current action.
4028         -- sreharih. Tue Apr 26 15:44:49 PDT 2011
4029         --
4030 
4031             /* start comment Bug 12394675
4032             IF p_icc_rec.enable_key_attrs_num IS NULL  THEN
4033               p_icc_rec.enable_key_attrs_num := 'N';
4034             END IF;
4035 
4036             IF p_icc_rec.enable_key_attrs_desc IS NULL  THEN
4037               p_icc_rec.enable_key_attrs_desc := 'N';
4038             END IF;
4039 
4040             IF p_icc_rec.ITEM_CREATION_ALLOWED_FLAG IS NULL THEN
4041                     p_icc_rec.ITEM_CREATION_ALLOWED_FLAG :=  g_old_icc_rec.ITEM_CREATION_ALLOWED_FLAG;
4042             END IF;
4043             end comment Bug 12394675 */
4044 
4045             -- Start DFF attributes
4046             -- Populating NULL is taken care by EGO_ITEM_CATALOG_PUB API ,
4047             --  adding only the additional columns not accepted by the API
4048             --
4049 
4050             IF p_icc_rec.ITEM_NUM_GEN_METHOD_TYPE = G_MISS_CHAR THEN
4051               p_icc_rec.ITEM_NUM_GEN_METHOD_TYPE := 'U';   -- if it is NULL, in UI there is error while rendering ICC
4052             END IF;
4053 
4054             IF p_icc_rec.prefix = G_MISS_CHAR THEN
4055                     p_icc_rec.prefix :=  null;
4056             END IF;
4057 
4058 
4059             IF p_icc_rec.starting_number = G_MISS_NUM THEN
4060                     p_icc_rec.starting_number :=  null;
4061             END IF;
4062 
4063 
4064             IF p_icc_rec.increment_by = G_MISS_NUM  THEN
4065                     p_icc_rec.increment_by := null;
4066             END IF;
4067 
4068             IF p_icc_rec.suffix = G_MISS_CHAR THEN
4069                     p_icc_rec.suffix :=  null;
4070             END IF;
4071 
4072             IF p_icc_rec.item_num_action_id = G_MISS_NUM  THEN
4073                     p_icc_rec.item_num_action_id :=  null;
4074             END IF;
4075 
4076             IF p_icc_rec.ITEM_DESC_GEN_METHOD_TYPE = G_MISS_CHAR THEN
4077                     p_icc_rec.ITEM_DESC_GEN_METHOD_TYPE :=  'U';  -- if it is NULL then in UI there is error while rendering ICC
4078             END IF;
4079 
4080             IF p_icc_rec.item_desc_action_id = G_MISS_NUM THEN
4081                     p_icc_rec.item_desc_action_id :=  null;
4082             END IF;
4083 
4084 
4085             IF p_icc_rec.new_item_req_change_type_id = G_MISS_NUM THEN
4086                     p_icc_rec.new_item_req_change_type_id :=  null;
4087             END IF;
4088 
4089             IF p_icc_rec.new_item_request_type = G_MISS_CHAR  THEN
4090                     p_icc_rec.new_item_request_type :=  null;
4091             END IF;
4092 
4093             IF p_icc_rec.enable_key_attrs_num = G_MISS_CHAR  THEN
4094               p_icc_rec.enable_key_attrs_num := 'N';
4095             END IF;
4096 
4097             IF p_icc_rec.enable_key_attrs_desc = G_MISS_CHAR  THEN
4098               p_icc_rec.enable_key_attrs_desc := 'N';
4099             END IF;
4100 
4101             IF p_icc_rec.ITEM_CREATION_ALLOWED_FLAG = G_MISS_CHAR THEN
4102                     p_icc_rec.ITEM_CREATION_ALLOWED_FLAG := 'N';
4103             END IF;
4104 
4105 
4106 
4107         ELSIF p_entity = G_ENTITY_ICC_FN_PARAM_MAP THEN
4108 
4109             --- Nullify Func param columns
4110             --- no columns as of now
4111             NULL;
4112         ELSIF p_entity = G_ENTITY_ICC_AG_ASSOC THEN
4113 
4114             --- Nullify AG association cols
4115             --- no columns as of now
4116             NULL;
4117 
4118         ELSIF p_entity = G_ENTITY_ICC_VERSION THEN
4119 
4120             --- Nullify Version specific information
4121             --- no columns as of now
4122             null;
4123 
4124         END IF; --- ICC Header
4125 
4126 
4127      write_debug (l_proc_name, 'End');
4128 
4129      EXCEPTION
4130      WHEN OTHERS THEN
4131         x_return_status := G_RET_STS_UNEXP_ERROR;
4132         x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
4133         write_debug(l_proc_name, x_return_msg);
4134      end   Populate_Null_Cols;
4135 
4136 
4137 
4138   /********************************************
4139   ---- Function to check if the data level exists
4140   ----
4141   *******************************************/
4142 
4143   FUNCTION Get_Data_Level_for_AG (  p_data_level_name    IN VARCHAR2 DEFAULT NULL
4144                                    ,p_data_level_id      IN VARCHAR2 DEFAULT NULL
4145                                  )
4146   RETURN NUMBER
4147   IS
4148 
4149     l_data_level_id   ego_data_level_b.data_level_id%TYPE := NULL;
4150     l_proc_name       varchar2(40) := 'Get_Data_Level_for_AG';
4151 
4152     cursor cur_get_data_lvl
4153     IS
4154     SELECT data_level_id
4155     FROM ego_data_level_b
4156     WHERE data_level_id = NVL(p_data_level_id, data_level_id)
4157     AND   data_level_name = NVL (p_data_level_name , data_level_name)
4158     ;
4159 
4160 
4161   BEGIN
4162     write_debug (l_proc_name, 'Start');
4163 
4164     FOR rec_data_lvl IN cur_get_data_lvl
4165     LOOP
4166       l_data_level_id := rec_data_lvl.data_level_id;
4167       EXIT;
4168     END LOOP;
4169 
4170     RETURN l_data_level_id;
4171 
4172     write_debug (l_proc_name, 'End');
4173   exception
4174   WHEN OTHERS THEN
4175     RETURN NULL;
4176   End;
4177 
4178 
4179 /********************************************************************
4180 ---   This procedure accepts the oncatenated segments
4181 ---   and returns the ccid for FINC_COMBINATION and 1 ( segment combination  exists)
4182 ---   or 0  ( combinaiton does not exist ) for CHECK_COMBINATION
4183 ********************************************************************/
4184 
4185 
4186     FUNCTION Get_Catalog_Group_Id (  p_catalog_group_name    IN VARCHAR2
4187                                    , p_operation         IN VARCHAR2
4188                                   )
4189     RETURN NUMBER
4190     IS
4191         l_proc_name    VARCHAR2(30) := 'Get_Catalog_Group_Id';
4192 
4193         is_valid  boolean;
4194 
4195     BEGIN
4196 
4197         -- write_debug(l_proc_name, 'validating segments . . .operation -  ' || p_operation );
4198         -- write_debug((l_proc_name,' concat. value ' || p_catalog_group_name);
4199 
4200         is_valid := FND_FLEX_KEYVAL.Validate_Segs
4201             (  operation         => p_operation
4202             ,  appl_short_name   => G_ITEM_CAT_KFF_APPL
4203             ,  key_flex_code     => G_ICC_KFF_NAME
4204             ,  structure_number  => G_STRUCTURE_NUMBER
4205             ,  concat_segments   => p_catalog_group_name
4206             );
4207         -- write_debug(l_proc_name, 'validate segments finished');
4208 
4209         IF (is_valid AND p_operation = 'FIND_COMBINATION') THEN
4210 
4211                 return FND_FLEX_KEYVAL.Combination_ID;
4212 
4213         ELSIF (is_valid AND p_operation = 'CHECK_SEGMENTS')
4214         THEN
4215 
4216             return 1;
4217         ELSIF ( NOT is_valid AND p_operation = 'CHECK_SEGMENTS')
4218         THEN
4219             return 0;
4220 
4221         ELSE
4222             -- write_debug(l_proc_name, 'operation: ' || p_operation || ' returning NULL ' );
4223             return NULL;
4224 
4225         END IF;
4226 
4227     END Get_Catalog_Group_Id;
4228 
4229 
4230 
4231 --***********************************************
4232 --- Get the concatenated value from the segments
4233 ---**********************************************
4234 
4235     FUNCTION concatenate_segments( p_appl_short_name  IN VARCHAR2
4236                                   ,p_key_flex_code    IN VARCHAR2
4237                                   ,p_structure_number IN NUMBER
4238                                   ,p_icc_rec          IN ego_icc_rec_type
4239                                   )
4240     RETURN VARCHAR2
4241     IS
4242 
4243         l_proc_name               VARCHAR2(30) := 'concatenate_segments';
4244         l_key_flex_field          fnd_flex_key_api.flexfield_type;
4245         l_structure_type          fnd_flex_key_api.structure_type;
4246         l_segment_type            fnd_flex_key_api.segment_type;
4247         l_segment_list            fnd_flex_key_api.segment_list;
4248         l_segment_array           fnd_flex_ext.SegmentArray;
4249         l_cur_icc_segment_array   fnd_flex_ext.SegmentArray;
4250         l_num_segments            NUMBER;
4251         l_flag                    BOOLEAN;
4252         l_concat                  VARCHAR2(2000) := NULL;
4253         j                         NUMBER;
4254         i                         NUMBER;
4255     BEGIN
4256 
4257         write_debug(l_proc_name, 'Start');
4258 
4259         fnd_flex_key_api.set_session_mode('seed_data');
4260 
4261         l_key_flex_field :=
4262             fnd_flex_key_api.find_flexfield(p_appl_short_name,
4263                                      p_key_flex_code);
4264 
4265         l_structure_type :=
4266             fnd_flex_key_api.find_structure(l_key_flex_field,
4267                                      p_structure_number);
4268 
4269         fnd_flex_key_api.get_segments(l_key_flex_field, l_structure_type,
4270                                  TRUE, l_num_segments, l_segment_list);
4271 
4272 
4273         l_cur_icc_segment_array(1) := p_icc_rec.segment1;
4274         l_cur_icc_segment_array(2) := p_icc_rec.segment2;
4275         l_cur_icc_segment_array(3) := p_icc_rec.segment3;
4276         l_cur_icc_segment_array(4) := p_icc_rec.segment4;
4277         l_cur_icc_segment_array(5) := p_icc_rec.segment5;
4278         l_cur_icc_segment_array(6) := p_icc_rec.segment6;
4279         l_cur_icc_segment_array(7) := p_icc_rec.segment7;
4280         l_cur_icc_segment_array(8) := p_icc_rec.segment8;
4281         l_cur_icc_segment_array(9) := p_icc_rec.segment9;
4282         l_cur_icc_segment_array(10) := p_icc_rec.segment10;
4283         l_cur_icc_segment_array(11) := p_icc_rec.segment11;
4284         l_cur_icc_segment_array(12) := p_icc_rec.segment12;
4285         l_cur_icc_segment_array(13) := p_icc_rec.segment13;
4286         l_cur_icc_segment_array(14) := p_icc_rec.segment14;
4287         l_cur_icc_segment_array(15) := p_icc_rec.segment15;
4288         l_cur_icc_segment_array(16) := p_icc_rec.segment16;
4289         l_cur_icc_segment_array(17) := p_icc_rec.segment17;
4290         l_cur_icc_segment_array(18) := p_icc_rec.segment18;
4291         l_cur_icc_segment_array(19) := p_icc_rec.segment19;
4292         l_cur_icc_segment_array(20) := p_icc_rec.segment20;
4293 
4294         FOR i in 1..20 LOOP
4295           IF l_cur_icc_segment_array(i) =  G_MISS_CHAR THEN
4296             l_cur_icc_segment_array(i) := NULL;
4297           END IF;
4298         END LOOP;
4299 
4300 
4301         --
4302         -- The segments in the seg_list array are sorted in display order.
4303         -- i.e. sorted by segment number.
4304         --
4305         for i in 1..l_num_segments
4306         loop
4307                 l_segment_type :=
4308                 fnd_flex_key_api.find_segment(l_key_flex_field,
4309                                       l_structure_type,
4310                                       l_segment_list(i));
4311                 j := to_number(substr(l_segment_type.column_name,8));
4312                 l_segment_array(i) := l_cur_icc_segment_array(j);
4313         end loop;
4314 
4315         --
4316         -- Now we have the all segment values in correct order in segarray.
4317         --
4318         l_concat := fnd_flex_ext.concatenate_segments(l_num_segments,
4319                                       l_segment_array,
4320                                       l_structure_type.segment_separator);
4321 
4322         -- dbms_output.put_line('Return from concatenate_segments ' || l_concat);
4323 
4324         RETURN l_concat;
4325      write_debug(l_proc_name, 'End');
4326     END concatenate_segments;
4327 
4328 ---*******************************************
4329 --- This functin returns true if one of the segment is populated for
4330 --- ICC name
4331 
4332 ---*******************************************
4333 FUNCTION Segments_Populated  ( p_icc_rec IN ego_icc_rec_type)
4334 RETURN BOOLEAN
4335 IS
4336 BEGIN
4337   IF (   (p_icc_rec.Segment1 IS NOT NULL AND
4338           p_icc_rec.Segment1 <> FND_API.G_MISS_CHAR
4339           ) OR
4340          (p_icc_rec.Segment2 IS NOT NULL AND
4341           p_icc_rec.Segment2 <> FND_API.G_MISS_CHAR
4342           ) OR
4343          (p_icc_rec.Segment3 IS NOT NULL AND
4344           p_icc_rec.Segment3 <> FND_API.G_MISS_CHAR
4345           ) OR
4346          (p_icc_rec.Segment4 IS NOT NULL AND
4347           p_icc_rec.Segment4 <> FND_API.G_MISS_CHAR
4348           ) OR
4349          (p_icc_rec.Segment5 IS NOT NULL AND
4350           p_icc_rec.Segment5 <> FND_API.G_MISS_CHAR
4351           ) OR
4352          (p_icc_rec.Segment6 IS NOT NULL AND
4353           p_icc_rec.Segment6 <> FND_API.G_MISS_CHAR
4354           ) OR
4355          (p_icc_rec.Segment7 IS NOT NULL AND
4356           p_icc_rec.Segment7 <> FND_API.G_MISS_CHAR
4357           ) OR
4358          (p_icc_rec.Segment8 IS NOT NULL AND
4359           p_icc_rec.Segment8 <> FND_API.G_MISS_CHAR
4360           ) OR
4361          (p_icc_rec.Segment9 IS NOT NULL AND
4362           p_icc_rec.Segment9 <> FND_API.G_MISS_CHAR
4363           ) OR
4364          (p_icc_rec.Segment10 IS NOT NULL AND
4365           p_icc_rec.Segment10 <> FND_API.G_MISS_CHAR
4366           ) OR
4367          (p_icc_rec.Segment11 IS NOT NULL AND
4368           p_icc_rec.Segment12 <> FND_API.G_MISS_CHAR
4369           ) OR
4370          (p_icc_rec.Segment13 IS NOT NULL AND
4371           p_icc_rec.Segment13 <> FND_API.G_MISS_CHAR
4372           ) OR
4373          (p_icc_rec.Segment14 IS NOT NULL AND
4374           p_icc_rec.Segment14 <> FND_API.G_MISS_CHAR
4375           ) OR
4376          (p_icc_rec.Segment15 IS NOT NULL AND
4377           p_icc_rec.Segment15 <> FND_API.G_MISS_CHAR
4378           ) OR
4379          (p_icc_rec.Segment16 IS NOT NULL AND
4380           p_icc_rec.Segment16 <> FND_API.G_MISS_CHAR
4381           ) OR
4382          (p_icc_rec.Segment17 IS NOT NULL AND
4383           p_icc_rec.Segment17 <> FND_API.G_MISS_CHAR
4384           ) OR
4385          (p_icc_rec.Segment18 IS NOT NULL AND
4386           p_icc_rec.Segment18 <> FND_API.G_MISS_CHAR
4387           ) OR
4388          (p_icc_rec.Segment19 IS NOT NULL AND
4389           p_icc_rec.Segment19<> FND_API.G_MISS_CHAR
4390           ) OR
4391          (p_icc_rec.Segment20 IS NOT NULL AND
4392           p_icc_rec.Segment20 <> FND_API.G_MISS_CHAR
4393           )
4394         )
4395      THEN
4396         return true;
4397      ELSE
4398         return false;
4399      END IF;
4400 END Segments_Populated;
4401 
4402 
4403 /********************************************************************
4404 --- This function checks if the AG is already associated
4405 ---
4406 ********************************************************************/
4407 
4408 function Get_AG_Association ( p_attr_group_id  IN NUMBER
4409                                ,p_icc_id       IN NUMBER
4410                               )
4411 return number
4412 
4413 IS
4414  l_proc_name   VARCHAR2(30) := 'Get_AG_Association';
4415 
4416  l_association_id  ego_obj_ag_assocs_b.association_id%TYPE := null;
4417 
4418  /*
4419  cursor cur_ag_assoc
4420  is
4421  select association_id
4422  from   ego_obj_ag_assocs_b
4423  where attr_group_id = p_attr_group_id
4424  and   classification_code = to_char(p_icc_id)
4425  and   object_id = ( select object_id from fnd_objects where obj_name = G_ITEM_OBJ_NAME)
4426  and rownum = 1
4427  ;
4428  */
4429 
4430  cursor cur_ag_assoc
4431  is
4432     SELECT oagv.association_id
4433       FROM ego_attr_groups_v agv,
4434            ego_obj_attr_grp_assocs_v oagv,
4435            ego_catalog_groups_v cg
4436      WHERE oagv.attr_group_id = agv.attr_group_id
4437        AND agv.attr_group_id =  p_attr_group_id
4438        AND cg.catalog_group_id = oagv.classification_code
4439        AND oagv.object_id = g_item_obj_id
4440        AND oagv.classification_code IN (
4441                                        SELECT TO_CHAR (item_catalog_group_id)
4442                                        FROM mtl_item_catalog_groups_b
4443                                        CONNECT BY PRIOR parent_catalog_group_id = item_catalog_group_id
4444                                        START WITH item_catalog_group_id = p_icc_id
4445                                        )
4446  ;
4447 
4448 
4449 BEGIN
4450   write_debug(l_proc_name, 'start');
4451 
4452   FOR rec_ag_assoc IN cur_ag_assoc  loop
4453     l_association_id := rec_ag_assoc.association_id;
4454   end loop;
4455 
4456   write_debug(l_proc_name, 'End');
4457   return l_association_id;
4458 
4459 END Get_AG_Association;
4460 
4461 /**************************
4462 --- Set EGO application id
4463 ***************************/
4464 procedure set_application_id
4465 is
4466 
4467   l_proc_name   varchar2(30) := 'set_application_id';
4468 begin
4469 
4470   select application_id
4471   into   G_EGO_APPL_ID
4472   from   fnd_application
4473   where application_short_name = G_APPL_NAME;
4474 
4475 exception
4476 when others then
4477   write_debug( l_proc_name , 'Applcation id not found for ego '||SQLERRM);
4478   raise;
4479 end;
4480 
4481 
4482 
4483 /**********************************************************************
4484 --- Check is AG being passed is not one of the base AGs associated to the ICC
4485 ---
4486 ***********************************************************************/
4487 function Check_Seeded_AG_Assoc ( p_attr_grp_id  IN NUMBER
4488                                 ,p_icc_id       IN NUMBER
4489                                )
4490 return boolean
4491 IS
4492 
4493  l_exists  BOOLEAN := false;
4494  l_proc_name  varchar2(30) := 'Check_Seeded_AG_Assoc';
4495 
4496  cursor cur_ag_CHK
4497  is
4498   SELECT 1
4499   from ego_fnd_dsc_flx_ctx_ext
4500   WHERE descriptive_flexfield_name = G_SEEDED_AG_Type
4501    AND  application_id = g_ego_appl_id
4502    and  attr_group_id = p_attr_grp_id
4503  ;
4504 
4505 
4506 
4507 BEGIN
4508   write_debug ( l_proc_name, 'start');
4509   FOR rec_ag_chk IN cur_ag_chk  loop
4510     l_exists := TRUE;
4511     exit;
4512   end loop;
4513 
4514   write_debug ( l_proc_name, 'end');
4515   return l_exists;
4516 
4517 exception
4518 when others then
4519   write_debug( l_proc_name , 'Error which checking attr grp id '||SQLERRM);
4520   raise;
4521 END Check_Seeded_AG_Assoc;
4522 
4523 /***************************************************************
4524 --- Function to check if an ICC has a released version
4525 ---
4526 ****************************************************************/
4527 FUNCTION Has_Released_Version ( p_icc_id   IN NUMBER
4528                              )
4529 RETURN boolean
4530 IS
4531 
4532   CURSOR cur_icc_ver
4533   IS
4534   SELECT 1
4535   FROM   EGO_MTL_CATALOG_GRP_VERS_B b
4536   WHERE  b.item_catalog_group_id = p_icc_id
4537   AND    version_seq_id <> 0;
4538 
4539   l_exists   BOOLEAN := FALSE;
4540   L_PROC_NAME VARCHAR2(30) := 'Has_Released_Version';
4541 
4542 BEGIN
4543 
4544   WRITE_DEBUG(L_PROC_NAME, 'p_icc_id, =>'||p_icc_id);
4545 
4546   FOR cur_chk_ver in cur_icc_ver LOOP
4547     l_exists := TRUE;
4548     exit;
4549   END LOOP;
4550 
4551   RETURN l_exists;
4552 
4553 END Has_Released_Version;
4554 
4555 
4556 /***************************************************************
4557 --- Function to check if an ICC has a released version for a
4558 --- particular date
4559 ----
4560 ****************************************************************/
4561 FUNCTION Has_Released_Version ( p_icc_id   IN NUMBER
4562                              ,p_date     IN DATE
4563                              )
4564 RETURN boolean
4565 IS
4566 
4567   CURSOR cur_icc_ver
4568   IS
4569   SELECT 1
4570   FROM   EGO_MTL_CATALOG_GRP_VERS_B b
4571   WHERE  b.item_catalog_group_id = p_icc_id
4572   AND    p_date  BETWEEN start_active_date
4573                    AND NVL(end_active_date, p_date+1)
4574   AND    version_seq_id <> 0;
4575 
4576   l_exists   BOOLEAN := FALSE;
4577   L_PROC_NAME VARCHAR2(30) := 'Has_Released_Version';
4578 
4579 BEGIN
4580 
4581   WRITE_DEBUG(L_PROC_NAME, 'p_icc_id, p_date=>'||p_icc_id||','||TO_CHAR(p_date, 'dd-mon-yyyy hh24:mi:ss'));
4582 
4583   FOR cur_chk_ver in cur_icc_ver LOOP
4584     l_exists := TRUE;
4585     exit;
4586   END LOOP;
4587 
4588   RETURN l_exists;
4589 
4590 END Has_Released_Version;
4591 
4592 
4593 /***************************************************************
4594 --- Function to check if an ICC has only draft version
4595 ---
4596 ****************************************************************/
4597 FUNCTION Has_OnlyDraft_Version ( p_icc_id   IN NUMBER
4598                              )
4599 RETURN boolean
4600 IS
4601 
4602   CURSOR cur_icc_ver
4603   IS
4604   SELECT 1
4605   FROM   EGO_MTL_CATALOG_GRP_VERS_B b
4606   WHERE  b.item_catalog_group_id = p_icc_id
4607   AND    version_seq_id <> 0;
4608 
4609   l_exists   BOOLEAN := FALSE;
4610 
4611 BEGIN
4612 
4613   FOR cur_chk_ver in cur_icc_ver LOOP
4614     l_exists := TRUE;
4615   END LOOP;
4616 
4617   RETURN (NOT l_exists);
4618 
4619 END Has_OnlyDraft_Version;
4620 
4621 
4622 
4623 /********************************************************************
4624 ---   This procedure accepts a record type , does value to id
4625 ---   conversion and other validations
4626 ---
4627 ********************************************************************/
4628     PROCEDURE Value_To_ID_Conversion(    p_entity         IN varchar2
4629                                        , p_icc_rec        IN OUT NOCOPY ego_icc_rec_type
4630                                        , p_ag_assoc_rec   IN OUT NOCOPY ego_ag_assoc_rec_type
4631                                        , p_func_param_assoc_rec IN OUT NOCOPY ego_func_param_map_rec_type
4632                                        , p_icc_ver_rec    IN OUT NOCOPY ego_icc_vers_rec_type
4633                                        , p_call_from_icc_process IN VARCHAR2 := 'F'    --- Added param bug 9791391
4634                                        , x_return_status    OUT NOCOPY VARCHAR2
4635                                        , x_return_msg  OUT NOCOPY VARCHAR2
4636                                      )
4637     IS
4638      l_proc_name  CONSTANT  VARCHAR2(30) := 'Value_To_ID_COnversion';
4639      e_stop_processing      EXCEPTION;
4640      l_null_icc_rec_type    EGO_ITEM_CATALOG_PUB.Catalog_Group_Rec_Type := null ;
4641      l_Mesg_Token_tbl       Error_Handler.Mesg_Token_Tbl_Type;
4642      l_dummy                boolean;
4643      l_data_level_id        ego_data_level_b.data_level_id%TYPE := NULL;
4644      l_icc_name             mtl_item_catalog_groups_b_kfv.padded_concatenated_segments%TYPE := null;
4645      l_association_id       ego_obj_ag_assocs_b.association_id%TYPE := null;
4646      l_return_status        VARCHAR2(1);
4647      l_return_status2       VARCHAR2(1);
4648      l_locking_party_id     NUMBER;
4649      l_lock_flag            ego_object_lock.lock_flag%TYPE;
4650      l_user_name            ego_user_v.party_name%TYPE;
4651 
4652 
4653      -- for error logging
4654      --
4655      l_entity_code     VARCHAR2(30) := null;
4656      l_token_table     ERROR_HANDLER.Token_Tbl_Type;
4657 
4658 
4659    BEGIN
4660      write_debug (l_proc_name, 'Start of  '||l_proc_name);
4661 
4662      x_return_status := G_RET_STS_SUCCESS;
4663      l_return_status := G_RET_STS_SUCCESS;
4664 
4665      ---
4666      --- Validations which are done as part of BULK_Validate during concurrent processing should
4667      --- be done if the calling process is an API
4668      IF G_Flow_Type = G_EGO_MD_API THEN -- pl/sql processing
4669 
4670          write_debug (l_proc_name, 'API Bulk Validation');
4671          Bulk_Validate_For_API (    p_entity         => p_entity
4672                                   , p_icc_rec        => p_icc_rec
4673                                   , p_ag_assoc_rec   => p_ag_assoc_rec
4674                                   , p_func_param_assoc_rec => p_func_param_assoc_rec
4675                                   , x_return_status  => x_return_status
4676                                   , x_return_msg     => x_return_msg
4677                                );
4678          IF x_return_status = G_RET_STS_UNEXP_ERROR THEN
4679            RAISE e_stop_processing;
4680 
4681          END IF;
4682 
4683      END IF;
4684 
4685      ---
4686      --- ICC HEADER
4687      ---
4688      IF p_ENTITY = G_ENTITY_ICC_HEADER THEN
4689 
4690            write_debug (l_proc_name, 'Start Header VALUE_TO_ID');
4691            l_entity_code := G_ENTITY_ICC_HEADER;
4692            ---
4693            --- Derive ICC id from segments , resolve the SYNC transaction based on that
4694            ---
4695            write_debug (l_proc_name, 'icc segs validation');
4696            IF p_icc_rec.item_catalog_group_id IS NULL and p_icc_rec.item_catalog_name IS NULL
4697              AND Segments_Populated ( p_icc_rec )
4698            THEN
4699              l_icc_name := concatenate_segments( p_appl_short_name  => G_ITEM_CAT_KFF_APPL
4700                                                 ,p_key_flex_code    => G_ICC_KFF_NAME
4701                                                 ,p_structure_number => G_STRUCTURE_NUMBER
4702                                                 ,p_icc_rec          => p_icc_rec
4703                                                );
4704 
4705              p_icc_rec.item_catalog_group_id  --- NULL assigned indicated CCID was not found
4706                         :=  Get_Catalog_Group_Id (  p_catalog_group_name => l_icc_name
4707                                                   , p_operation     => 'FIND_COMBINATION'
4708                                                 );
4709 
4710 
4711            END IF;
4712 
4713            ---
4714            --- Resolve the SYNC transaction type
4715            ---
4716            write_debug (l_proc_name, 'Resolve sync');
4717            IF p_icc_rec.transaction_type = G_TTYPE_SYNC THEN
4718                IF Check_Catalog_CCID (p_icc_rec.item_catalog_group_id) THEN
4719                  ---- ICC already exists
4720                  ----
4721                   p_icc_rec.transaction_type := G_TTYPE_UPDATE;
4722                ELSE
4723                   p_icc_rec.transaction_type := G_TTYPE_CREATE;
4724                END IF;
4725            END IF;
4726 
4727            IF p_icc_rec.transaction_type = G_TTYPE_UPDATE AND NOT Check_Catalog_CCID (p_icc_rec.item_catalog_group_id) THEN
4728 
4729                   l_return_status := G_RET_STS_ERROR;
4730 
4731                   ERROR_HANDLER.Add_Error_Message(
4732                     p_message_name                  => 'EGO_ICC_ID_INVALID'
4733                    ,p_application_id                => G_APPL_NAME
4734                    ,p_token_tbl                     => l_token_table
4735 
4736                    ,p_row_identifier                => p_icc_rec.transaction_id
4737                    ,p_entity_code                   => l_entity_code
4738                    ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
4739                    );
4740            ELSIF p_icc_rec.transaction_type = G_TTYPE_UPDATE AND Check_Catalog_CCID (p_icc_rec.item_catalog_group_id) THEN
4741                --- Get the details for existing ICC , required for validations
4742                ---
4743               Fetch_Old_ICC_Dtls (g_old_icc_rec, p_icc_rec.item_catalog_group_id);
4744            end if;
4745 
4746 
4747            IF p_icc_rec.transaction_type = G_TTYPE_CREATE THEN
4748 
4749              IF p_icc_rec.item_catalog_group_id IS NOT NULL THEN
4750 
4751                   l_return_status := G_RET_STS_ERROR;
4752 
4753                   ERROR_HANDLER.Add_Error_Message(
4754                     p_message_name                  => 'EGO_CATALOG_GROUP_EXISTS'
4755                    ,p_application_id                => G_APPL_NAME
4756                    ,p_token_tbl                     => l_token_table
4757                    ,p_row_identifier                => p_icc_rec.transaction_id
4758                    ,p_entity_code                   => l_entity_code
4759                    ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
4760                    );
4761 
4762              END IF;
4763            END IF;
4764 
4765            --- Bulk Validate takes care of below validation
4766 
4767            --- validate the parent catalog group, parent catalog group id is validated in Bulk validations
4768            ---
4769           write_debug (l_proc_name, 'Parent validation');
4770           IF p_icc_rec.parent_catalog_group_name IS NOT NULL THEN
4771                 --- By this time if the parent catalog group if in the
4772                 --- same interface table , it would have already been created
4773                 ---
4774                   write_debug (l_proc_name, 'Validate parent catalog name');
4775                   p_icc_rec.parent_catalog_group_id := Get_Catalog_Group_Id ( p_icc_rec.parent_catalog_group_name , 'FIND_COMBINATION');
4776                   write_debug (l_proc_name, 'parent catalog GROUP ID =>'||NVL(p_icc_rec.parent_catalog_group_id, -999999));
4777 
4778                 IF p_icc_rec.parent_catalog_group_id IS NULL THEN
4779 
4780                   l_return_status := G_RET_STS_ERROR;
4781                   write_debug (l_proc_name, 'inserting error for parent');
4782 
4783                   l_token_table(1).TOKEN_NAME := 'ICC_NAME';
4784                   l_token_table(1).TOKEN_VALUE := p_icc_rec.parent_catalog_group_name;
4785 
4786                       ERROR_HANDLER.Add_Error_Message(
4787                         p_message_name                  => 'EGO_ICC_PARENT_INVALID'
4788                        ,p_application_id                => G_APPL_NAME
4789                        ,p_token_tbl                     => l_token_table
4790                        ,p_row_identifier                => p_icc_rec.transaction_id
4791                        ,p_entity_code                   => l_entity_code
4792                        ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
4793                        );
4794                        l_token_table.delete();
4795                 --- Parent should have atleast one released at the time of creation of this child ICC
4796                 ---
4797                 ELSIF  p_icc_rec.parent_catalog_group_id IS NOT NULL THEN
4798 
4799 
4800                   IF (NOT Has_Released_Version ( p_icc_rec.parent_catalog_group_id, SYSDATE)) AND G_P4TP_PROFILE_ENABLED THEN
4801 
4802 
4803                     l_return_status := G_RET_STS_ERROR;
4804                     write_debug (l_proc_name, 'inserting error for parent, parent no released version');
4805 
4806                     l_token_table(1).TOKEN_NAME := 'ICC_NAME';
4807                     l_token_table(1).TOKEN_VALUE := p_icc_rec.parent_catalog_group_name;
4808 
4809                       ERROR_HANDLER.Add_Error_Message(
4810                         p_message_name                  => 'ICC_PARENT_NO_RELEASE_VER'
4811                        ,p_application_id                => G_APPL_NAME
4812                        ,p_token_tbl                     => l_token_table
4813                        ,p_row_identifier                => p_icc_rec.transaction_id
4814                        ,p_entity_code                   => l_entity_code
4815                        ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
4816                        );
4817                        l_token_table.delete();
4818                        write_debug(l_proc_name, 'Err_Msg-TID='
4819                              ||p_icc_rec.transaction_id||'-(ICC, PARENT ICC)=('
4820                              ||p_icc_rec.item_catalog_name||','||p_icc_rec.parent_catalog_group_name||')'
4821                              ||' parent does not have a released version'
4822                              );
4823 
4824 
4825                   END IF;
4826 
4827                   --- parent icc has a released version effective sysdate
4828                   --- current icc being updated should not have a released version
4829                   --- if it has a released version, old and new parent icc should be same
4830                   ---
4831                   write_debug ( l_proc_name , ' old parent id=>'||g_old_icc_rec.PARENT_CATALOG_GROUP_ID||'*'
4832                                            || ' curr parent id=>'||p_icc_rec.parent_catalog_group_id);
4833 
4834                   IF p_icc_rec.transaction_type = G_TTYPE_UPDATE
4835                      AND Has_Released_Version(p_icc_rec.item_catalog_group_id)
4836                      AND G_P4TP_PROFILE_ENABLED
4837                      AND NVL(g_old_icc_rec.PARENT_CATALOG_GROUP_ID, -99999) <> p_icc_rec.parent_catalog_group_id THEN
4838 
4839                     ERROR_HANDLER.Add_Error_Message(
4840                       p_message_name                  => 'EGO_ICC_DIS_UPD'
4841                      ,p_application_id                => G_APPL_NAME
4842                      ,p_token_tbl                     => l_token_table
4843                      ,p_row_identifier                => p_icc_rec.transaction_id
4844                      ,p_entity_code                   => l_entity_code
4845                      ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
4846                      );
4847 
4848                      l_return_status := G_RET_STS_ERROR;
4849                      write_debug(l_proc_name, 'Err_Msg-TID='
4850                              ||p_icc_rec.transaction_id||'-(ICC, PARENT ICC)=('
4851                              ||p_icc_rec.item_catalog_name||','||p_icc_rec.parent_catalog_group_name||')'
4852                              ||' change of parent item catalog is not allowed for versioned iccs'
4853                            );
4854                   END IF;
4855 
4856                   --- parent icc has a released version effective sysdate
4857                   --- current icc being updated if it has only draft
4858                   --- then allow the parent icc update only once if parent is null
4859                   ---
4860                   IF p_icc_rec.transaction_type = G_TTYPE_UPDATE
4861                      AND Has_OnlyDraft_Version(p_icc_rec.item_catalog_group_id)
4862                      AND G_P4TP_PROFILE_ENABLED
4863                      AND g_old_icc_rec.PARENT_CATALOG_GROUP_ID <> p_icc_rec.parent_catalog_group_id THEN
4864 
4865                     ERROR_HANDLER.Add_Error_Message(
4866                       p_message_name                  => 'EGO_ICC_DIS_UPD'
4867                      ,p_application_id                => G_APPL_NAME
4868                      ,p_token_tbl                     => l_token_table
4869                      ,p_row_identifier                => p_icc_rec.transaction_id
4870                      ,p_entity_code                   => l_entity_code
4871                      ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
4872                      );
4873 
4874                      l_return_status := G_RET_STS_ERROR;
4875                      write_debug(l_proc_name, 'Err_Msg-TID='
4876                              ||p_icc_rec.transaction_id||'-(ICC, PARENT ICC)=('
4877                              ||p_icc_rec.item_catalog_name||','||p_icc_rec.parent_catalog_group_name||')'
4878                              ||' change of parent item catalog is not allowed for draft(parent asso before) iccs'
4879                            );
4880                   END IF;
4881 
4882 
4883 
4884                 END IF;
4885           END IF;
4886            --- end parent checking
4887            ---
4888 
4889            --- added bug 9737402
4890            ---
4891            write_debug (l_proc_name, 'inactive date validation');
4892            IF p_icc_rec.inactive_date IS NOT NULL
4893               AND p_icc_rec.inactive_date <> G_MISS_DATE
4894               AND TRUNC(p_icc_rec.inactive_date) < TRUNC(SYSDATE) THEN
4895 
4896               ERROR_HANDLER.Add_Error_Message(
4897                 p_message_name                  => 'EGO_ENDDATE_EXCEEDS_SYSDATE'
4898                ,p_application_id                => G_APPL_NAME
4899                ,p_token_tbl                     => l_token_table
4900                ,p_row_identifier                => p_icc_rec.transaction_id
4901                ,p_entity_code                   => l_entity_code
4902                ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
4903                );
4904 
4905                l_return_status := G_RET_STS_ERROR;
4906                write_debug(l_proc_name, 'Err_Msg-TID='
4907                        ||p_icc_rec.transaction_id||'-(ICC)=('
4908                        ||p_icc_rec.item_catalog_name
4909                        ||') inactive date is in past'
4910                      );
4911 
4912 
4913            END IF;
4914 
4915            --- added bug 9737833
4916            ---
4917            Validate_YesNo_Cols ( p_icc_rec => p_icc_rec
4918                                 ,x_return_status    => x_return_status
4919                                , x_return_msg      => x_return_msg
4920                                );
4921 
4922                if x_return_status = G_RET_STS_ERROR THEN
4923                  --- mark the current record as error
4924                  ---
4925                  l_return_status := G_RET_STS_ERROR;
4926 
4927                elsIF x_return_status = G_RET_STS_UNEXP_ERROR then
4928                    raise e_stop_processing;
4929                end if;
4930 
4931 
4932            Validate_Func_Related_Cols ( p_icc_rec => p_icc_rec
4933                                        ,x_return_status    => x_return_status
4934                                        , x_return_msg      => x_return_msg
4935                                       );
4936 
4937                if x_return_status = G_RET_STS_ERROR THEN
4938                  --- mark the current record as error
4939                  ---
4940                  l_return_status := G_RET_STS_ERROR;
4941 
4942                elsIF x_return_status = G_RET_STS_UNEXP_ERROR then
4943                    raise e_stop_processing;
4944                end if;
4945 
4946 
4947 
4948            Validate_NIR_Columns     ( p_icc_rec => p_icc_rec
4949                                        ,x_return_status    => x_return_status
4950                                       );
4951 
4952                IF x_return_status = G_RET_STS_ERROR THEN
4953                  --- mark the current record as error
4954                  ---
4955                  l_return_status := G_RET_STS_ERROR;
4956 
4957                ELSIF x_return_status = G_RET_STS_UNEXP_ERROR then
4958                    raise e_stop_processing; -- skip to next record?
4959                END IF;
4960 
4961            ---- End ICC
4962            ----
4963            x_return_status := l_return_status;
4964            write_debug (l_proc_name, 'End Header');
4965      END IF;
4966      ---------------------------------------------------
4967      -------   AG Association
4968      ---------------------------------------------------
4969 
4970 
4971      IF p_ENTITY = G_ENTITY_ICC_AG_ASSOC THEN
4972 
4973         l_entity_code := G_ENTITY_ICC_AG_ASSOC;
4974          --- Validate if the AG being passed is base/default AG assocatiated to the item
4975          ---
4976 
4977        IF Check_Seeded_AG_Assoc ( p_icc_id => p_ag_assoc_rec.item_catalog_group_id
4978                                  ,p_attr_grp_id =>   p_ag_assoc_rec.attr_group_id
4979                                 ) THEN
4980 
4981           ERROR_HANDLER.Add_Error_Message(
4982             p_message_name                  => 'EGO_CANNOT_UPDATE_SEEDED_AG'
4983            ,p_application_id                => G_APPL_NAME
4984            ,p_row_identifier                => p_ag_assoc_rec.transaction_id
4985            ,p_entity_code                   => l_entity_code
4986            ,p_table_name                    => G_ENTITY_ICC_AG_ASSOC_TAB
4987            );
4988 
4989            l_return_status := G_RET_STS_ERROR;
4990 
4991        END IF;
4992 
4993        write_debug(l_proc_name, 'getting association id');
4994        l_association_id := Get_AG_Association ( p_icc_id => p_ag_assoc_rec.item_catalog_group_id
4995                                               ,p_attr_group_id  => p_ag_assoc_rec.attr_group_id
4996                                               );
4997        write_debug(l_proc_name, 'getting association id=>'||l_association_id);
4998        p_ag_assoc_rec.association_id :=  l_association_id;
4999 
5000        IF l_association_id is not null then
5001 
5002          IF p_ag_assoc_rec.transaction_type = G_TTYPE_CREATE then
5003            l_token_table(1).TOKEN_NAME := 'AG_NAME';
5004            l_token_table(1).TOKEN_VALUE := p_ag_assoc_rec.attr_group_name;
5005 
5006            l_token_table(2).TOKEN_NAME := 'ICC_NAME';
5007            l_token_table(2).TOKEN_VALUE := p_ag_assoc_rec.item_catalog_name;
5008 
5009 
5010            ERROR_HANDLER.Add_Error_Message(
5011              p_message_name                  => 'EGO_AG_ALREADY_ASSOCIATED_ICC'
5012             ,p_application_id                => G_APPL_NAME
5013             ,p_token_tbl                     => l_token_table
5014             ,p_row_identifier                => p_ag_assoc_rec.transaction_id
5015             ,p_entity_code                   => l_entity_code
5016             ,p_table_name                    => G_ENTITY_ICC_AG_ASSOC_TAB
5017             );
5018             l_token_table.DELETE;
5019 
5020             l_return_status := G_RET_STS_ERROR;
5021          end if;
5022 
5023        ELSIF (l_association_id IS NULL and p_ag_assoc_rec.transaction_type IN ( G_TTYPE_DELETE ) ) THEN
5024 
5025           l_token_table(1).TOKEN_NAME := 'AG_NAME';
5026           l_token_table(1).TOKEN_VALUE := p_ag_assoc_rec.attr_group_name;
5027 
5028           ERROR_HANDLER.Add_Error_Message(
5029             p_message_name                  => 'EGO_AG_NOT_ASSOCIATED_ICC'
5030            ,p_application_id                => G_APPL_NAME
5031            ,p_token_tbl                     => l_token_table
5032 
5033            ,p_row_identifier                => p_ag_assoc_rec.transaction_id
5034            ,p_entity_code                   => l_entity_code
5035            ,p_table_name                    => G_ENTITY_ICC_AG_ASSOC
5036            );
5037            l_token_table.DELETE;
5038 
5039 
5040            l_return_status := G_RET_STS_ERROR;
5041        ELSE
5042           null;
5043        END IF;
5044 
5045        x_return_status := l_return_status;
5046    END IF; --- AG assoc rec
5047    --- End AG Associations
5048    ---
5049 
5050 
5051   ---------------------------------------------------
5052   -------   ICC Versions
5053   ---------------------------------------------------
5054 
5055 
5056   IF p_ENTITY = G_ENTITY_ICC_VERSION  THEN
5057   --- Start ICC Versions
5058   ---
5059     l_entity_code := G_ENTITY_ICC_VERSION;
5060 
5061     --- uncommented bug 9752139
5062     --- Validate the transaction type, taken care of in bUlk validate , Validate_trans_Type
5063     ---
5064     IF p_icc_ver_rec.transaction_type IS NULL OR p_icc_ver_rec.transaction_type NOT IN ( G_TTYPE_CREATE) THEN
5065 
5066 
5067       l_token_table(1).TOKEN_NAME := 'entity';
5068       l_token_table(1).TOKEN_VALUE := G_ENTITY_ICC_VERSION;
5069 
5070       ERROR_HANDLER.Add_Error_Message(
5071         p_message_name                  => 'EGO_TRANS_TYPE_INVALID'
5072        ,p_application_id                => G_APPL_NAME
5073        ,p_token_tbl                     => l_token_table
5074        ,p_row_identifier                => p_icc_ver_rec.transaction_id
5075        ,p_entity_code                   => l_entity_code
5076        ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
5077        );
5078        l_token_table.DELETE;
5079 
5080        l_return_status := G_RET_STS_ERROR;
5081 
5082        write_debug(l_proc_name, 'Err_Msg-TID='
5083                     ||p_icc_ver_rec.transaction_id||'-(ICC, STA_DT)=('
5084                     ||p_icc_ver_rec.item_catalog_name||','||to_char(p_icc_ver_rec.start_date, 'DD-MON-YYYY HH24:MI:SS')||')'
5085                     ||' Versions only support CREATE'
5086                   );
5087     END IF;
5088 
5089 
5090     --- Validate the ICC ID
5091     ---
5092     IF p_icc_ver_rec.item_catalog_group_id IS NOT NULL
5093         AND NOT Check_Catalog_CCID (p_icc_ver_rec.item_catalog_group_id) THEN
5094 
5095           l_return_status := G_RET_STS_ERROR;
5096           ERROR_HANDLER.Add_Error_Message(
5097             p_message_name                  => 'EGO_ICC_ID_INVALID'
5098            ,p_application_id                => G_APPL_NAME
5099            ,p_token_tbl                     => l_token_table
5100            ,p_row_identifier                => p_icc_ver_rec.transaction_id
5101            ,p_entity_code                   => l_entity_code
5102            ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
5103            );
5104        write_debug(l_proc_name, 'Err_Msg-TID='
5105                     ||p_icc_ver_rec.transaction_id||'-(ICC, STA_DT)=('
5106                     ||p_icc_ver_rec.item_catalog_name||','||to_char(p_icc_ver_rec.start_date, 'DD-MON-YYYY HH24:MI:SS')||')'
5107                     ||'EGO_ICC_ID_INVALID'
5108                   );
5109 
5110 
5111     ELSIF p_icc_ver_rec.item_catalog_name IS NOT NULL THEN
5112 
5113         p_icc_ver_rec.item_catalog_group_id := Get_Catalog_Group_Id ( p_icc_ver_rec.item_catalog_name , 'FIND_COMBINATION');
5114         write_debug (l_proc_name, 'catalog GROUP ID =>'||NVL(p_icc_ver_rec.item_catalog_group_id, -999999));
5115 
5116         IF p_icc_ver_rec.item_catalog_group_id IS NULL THEN
5117           l_return_status := G_RET_STS_ERROR;
5118           ERROR_HANDLER.Add_Error_Message(
5119                 p_message_name                  => 'EGO_ICC_ID_INVALID'
5120                ,p_application_id                => G_APPL_NAME
5121                ,p_token_tbl                     => l_token_table
5122                ,p_row_identifier                => p_icc_ver_rec.transaction_id
5123                ,p_entity_code                   => l_entity_code
5124                ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
5125                );
5126           write_debug(l_proc_name, 'Err_Msg-TID='
5127                     ||p_icc_ver_rec.transaction_id||'-(ICC, STA_DT)=('
5128                     ||p_icc_ver_rec.item_catalog_name||','||to_char(p_icc_ver_rec.start_date, 'DD-MON-YYYY HH24:MI:SS')||')'
5129                     ||'EGO_ICC_ID_INVALID'
5130                   );
5131         ELSE
5132 
5133            --- Since ICC is created now, update the icc id in the TA interface table
5134            ---
5135            --- Update the ICC id in the TA interface table
5136            ---
5137            EGO_TA_BULKLOAD_PVT.Bulk_Validate_Trans_Attrs_ICC (
5138                                                   p_set_process_id           => G_SET_PROCESS_ID
5139                                                 ,p_item_catalog_group_id    => p_icc_ver_rec.item_catalog_group_id
5140                                                 ,p_item_catalog_group_name  => p_icc_ver_rec.item_catalog_name
5141                                                 );
5142 
5143         END IF;
5144 
5145 
5146     END IF;
5147 
5148     --- uncommented bug 9752139 , made condition <=
5149     ---
5150     --- Version  seq 0 or draft version are not supported
5151     ---
5152     IF p_icc_ver_rec.ver_seq_no <= 0 THEN
5153 
5154           ---
5155           --- Version seq 0 is not supported for create/update
5156           ---
5157           l_token_table(1).TOKEN_NAME := 'ICC_NAME';
5158           l_token_table(1).TOKEN_VALUE := p_icc_ver_rec.item_catalog_name;
5159 
5160           ERROR_HANDLER.Add_Error_Message(
5161             p_message_name                  => 'EGO_VER_SEQ_ZERO_ERROR'
5162            ,p_application_id                => G_APPL_NAME
5163            ,p_token_tbl                     => l_token_table
5164            ,p_row_identifier                => p_icc_ver_rec.transaction_id
5165            ,p_entity_code                   => l_entity_code
5166            ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
5167            );
5168            l_token_table.DELETE;
5169 
5170            l_return_status := G_RET_STS_ERROR;
5171 
5172     END IF;
5173 
5174 
5175     ---
5176     --- Check for start date in the past
5177     ---
5178     IF NVL(p_icc_ver_rec.start_date, SYSDATE+1) < SYSDATE THEN
5179 
5180           ---
5181           --- Version seq already exists in the system
5182           ---
5183           l_token_table(1).TOKEN_NAME := 'START_DATE';
5184           l_token_table(1).TOKEN_VALUE := p_icc_ver_rec.start_date;
5185 
5186           l_token_table(2).TOKEN_NAME := 'VER_SEQ_NO';
5187           l_token_table(2).TOKEN_VALUE := p_icc_ver_rec.ver_seq_no;
5188 
5189           l_token_table(3).TOKEN_NAME := 'ICC_NAME';
5190           l_token_table(3).TOKEN_VALUE := p_icc_ver_rec.item_catalog_name;
5191 
5192           ERROR_HANDLER.Add_Error_Message(
5193             p_message_name                  => 'EGO_VER_START_DATE_PAST'
5194            ,p_application_id                => G_APPL_NAME
5195            ,p_token_tbl                     => l_token_table
5196 
5197            ,p_row_identifier                => p_icc_ver_rec.transaction_id
5198            ,p_entity_code                   => l_entity_code
5199            ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
5200            );
5201            l_token_table.DELETE;
5202 
5203            l_return_status := G_RET_STS_ERROR;
5204 
5205     END IF;
5206 
5207 
5208     ---
5209     --- Default the start date with SYSDATE if NULL
5210     ---
5211     IF p_icc_ver_rec.start_date IS NULL THEN
5212       p_icc_ver_rec.start_date := SYSDATE;
5213     END IF;
5214 
5215     ---
5216     --- Added for bug 9791391, honour locks
5217     ---
5218     write_debug(l_proc_name, 'p_call_from_icc_process=>'||p_call_from_icc_process);
5219 
5220     IF p_call_from_icc_process = 'F' THEN
5221         --- first get the lock info as to who has locked the draft
5222         ---
5223         EGO_METADATA_BULKLOAD_PVT.Get_Lock_Info (   p_object_name  => G_ENTITY_ICC_LOCK
5224                                                    ,p_pk1_value    => p_icc_ver_rec.item_catalog_group_id
5225                                                    ,x_locking_party_id  => l_locking_party_id
5226                                                    ,x_lock_flag         => l_lock_flag
5227                                                    ,x_return_msg        => x_return_msg
5228                                                    ,x_return_status     => x_return_status
5229                                                );
5230          write_debug(l_proc_name, 'Locking flag , party id , g_party_id=>'||l_lock_flag||','|| l_locking_party_id||','||g_party_id);
5231 
5232         IF x_return_status  = G_RET_STS_ERROR THEN
5233           l_return_status := G_RET_STS_ERROR;
5234 
5235           ERROR_HANDLER.Add_Error_Message(
5236                 p_message_text                  => x_return_msg
5237                ,p_application_id                => G_APPL_NAME
5238                ,p_token_tbl                     => l_token_table
5239                ,p_row_identifier                => p_icc_ver_rec.transaction_id
5240                ,p_entity_code                   => l_entity_code
5241                ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
5242                );
5243         ELSIF  x_return_status  = G_RET_STS_UNEXP_ERROR THEN
5244           RAISE e_stop_processing;
5245         END IF;
5246 
5247         ---
5248         --- Draft locked by a different user , error out the verison record
5249         ---
5250         IF l_lock_flag = 'L'  AND l_locking_party_id <> g_party_id THEN
5251 
5252           l_return_status := G_RET_STS_ERROR;   --- added bug 9840409
5253           ego_metadata_bulkload_pvt.Get_Party_Name( l_locking_party_id, l_user_name);
5254 
5255           l_token_table(1).TOKEN_NAME := 'ENTITY_NAME';
5256           l_token_table(1).TOKEN_VALUE := G_ENTITY_ICC_LOCK;
5257 
5258           l_token_table(2).TOKEN_NAME := 'PARTY_NAME';
5259           l_token_table(2).TOKEN_VALUE := l_user_name;
5260 
5261           ERROR_HANDLER.Add_Error_Message(
5262             p_message_name                  => 'EGO_ENTITY_LOCKED'
5263            ,p_application_id                => G_APPL_NAME
5264            ,p_token_tbl                     => l_token_table
5265            ,p_row_identifier                => p_icc_ver_rec.transaction_id
5266            ,p_entity_code                   => l_entity_code
5267            ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
5268            );
5269            l_token_table.DELETE;
5270 
5271         END IF;
5272     END IF;    --- not from ICC process
5273 
5274 
5275     ---
5276     --- Check if version with the curr. start date already exists in
5277     --- the system
5278     ---
5279     FOR rec_dt_chk in  ( SELECT 1
5280                          FROM   ego_mtl_catalog_grp_vers_b
5281                          WHERE  version_seq_id <> 0
5282                          AND    start_active_date = p_icc_ver_rec.start_date
5283                          AND    item_catalog_group_id =   p_icc_ver_rec.item_catalog_group_id
5284                        ) LOOP
5285 
5286           ---
5287           --- Version seq already exists in the system
5288           ---
5289           l_token_table(1).TOKEN_NAME := 'START_DATE';
5290           l_token_table(1).TOKEN_VALUE := to_char(p_icc_ver_rec.start_date, 'DD-MON-YYYY HH24:MI:SS');
5291 
5292           l_token_table(2).TOKEN_NAME := 'ICC_NAME';
5293           l_token_table(2).TOKEN_VALUE := p_icc_ver_rec.item_catalog_name;
5294 
5295           ERROR_HANDLER.Add_Error_Message(
5296             p_message_name                  => 'EGO_VER_ALREADY_EXISTS_DT'
5297            ,p_application_id                => G_APPL_NAME
5298            ,p_token_tbl                     => l_token_table
5299            ,p_row_identifier                => p_icc_ver_rec.transaction_id
5300            ,p_entity_code                   => l_entity_code
5301            ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
5302            );
5303            l_token_table.DELETE;
5304 
5305            l_return_status := G_RET_STS_ERROR;
5306 
5307     END LOOP;
5308 
5309     --- added bug 9752139
5310     IF l_return_status = G_RET_STS_ERROR THEN
5311 
5312       --- fail the associated TA records
5313       ---
5314       EGO_TA_BULKLOAD_PVT.Update_Intf_Err_Trans_Attrs(
5315                  p_set_process_id          => G_SET_PROCESS_ID,
5316                  p_item_catalog_group_id   => p_icc_ver_rec.item_catalog_group_id,
5317                  p_icc_version_number_intf => p_icc_ver_rec.ver_seq_no,
5318                  x_return_status           => l_return_status2,
5319                  x_return_msg              => x_return_msg);
5320 
5321       IF l_return_status2 = G_RET_STS_UNEXP_ERROR THEN
5322         RAISE e_stop_processing;
5323       END IF;
5324 
5325 
5326        l_token_table(1).TOKEN_NAME := 'ICC_NAME';
5327        l_token_table(1).TOKEN_VALUE := p_icc_ver_rec.item_catalog_name;
5328 
5329        l_token_table(2).TOKEN_NAME := 'VER_SEQ';
5330        l_token_table(2).TOKEN_VALUE := p_icc_ver_rec.ver_seq_no;
5331 
5332 
5333        ERROR_HANDLER.Add_Error_Message(
5334          p_message_name                  => 'EGO_RELATED_TA_FAIL'
5335         ,p_application_id                => G_APPL_NAME
5336         ,p_token_tbl                     => l_token_table
5337         ,p_row_identifier                => p_icc_ver_rec.transaction_id
5338         ,p_entity_code                   => l_entity_code
5339         ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
5340         );
5341         l_token_table.DELETE;
5342 
5343 
5344     END IF;
5345 
5346 
5347     x_return_status := l_return_status;
5348 
5349   --- End ICC Versions
5350   ---
5351   END IF;
5352 
5353 
5354   ---------------------------------------------------
5355   -------   Function Parameter
5356   ---------------------------------------------------
5357 
5358 
5359   IF p_ENTITY = G_ENTITY_ICC_FN_PARAM_MAP  THEN
5360     --- Start Func Parameters
5361     ---
5362 
5363       Validate_Func_Param_Mappings    ( p_func_param_assoc_rec =>  p_func_param_assoc_rec
5364                                        ,x_return_status      => x_return_status
5365                                        ,x_return_msg         => x_return_msg
5366                                         );
5367 
5368       IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
5369         RAISE  e_stop_processing;
5370       END IF;
5371 
5372     --- End Func parameters
5373     ---
5374   END IF;
5375 
5376   write_debug (l_proc_name, 'End of  '||l_proc_name);
5377 EXCEPTION
5378 WHEN e_stop_processing THEN
5379    x_return_status := G_RET_STS_UNEXP_ERROR;
5380 WHEN OTHERS THEN
5381    x_return_status := G_RET_STS_UNEXP_ERROR;
5382    x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
5383 end   Value_To_ID_Conversion;
5384 
5385 
5386 ---******************************************
5387 --- Function to get the party id for a user
5388 --- ID
5389 --*******************************************
5390 
5391 FUNCTION Get_party_id ( p_user_id IN NUMBER)
5392 RETURN NUMBER
5393 IS
5394 
5395   l_party_id ego_user_v.party_id%TYPE := null;
5396 
5397 BEGIN
5398 
5399     SELECT party_id
5400     INTO l_party_id
5401     from ego_user_v
5402     where user_id = p_user_id;
5403 
5404     return l_party_id;
5405 
5406   EXCEPTION
5407     WHEN OTHERS THEN
5408       -- defaulting to MFG
5409       SELECT party_id
5410       INTO  l_party_id
5411       from ego_user_v
5412       where user_name = G_DEFAULT_USER_NAME;
5413       return l_party_id;
5414 END Get_party_id;
5415 
5416 
5417 
5418  ---******************************************
5419  --- Create draft version of the ICC
5420  ---******************************************
5421 
5422  PROCEDURE Create_Draft_Version ( p_item_catalog_id IN NUMBER
5423                                  ,x_return_status   OUT NOCOPY VARCHAR2
5424                                  ,x_return_msg  OUT NOCOPY VARCHAR2
5425                                 )
5426 IS
5427 
5428   l_proc_name       VARCHAR2(30) := 'Create_Draft_Version';
5429   l_msg_name        fnd_new_messages.message_name%TYPE := null;
5430   l_msg_text        fnd_new_messages.message_text%TYPE := null;
5431   l_obj_name        VARCHAR2(30)  := 'EGO_ITEM_CATALOG_CATEGORY';
5432   l_sysdate         DATE;
5433   l_party_id        ego_user_v.party_id%type;
5434 
5435 BEGIN
5436   write_debug(l_proc_name, 'Start ');
5437   x_return_status := G_RET_STS_SUCCESS;
5438 
5439 
5440            l_msg_name := 'EGO_ICC_DRAFT_VERSION';
5441            FND_MESSAGE.SET_NAME(G_APPL_NAME,l_msg_name );
5442            l_msg_text := FND_MESSAGE.GET;
5443            l_sysdate := SYSDATE;
5444 
5445            INSERT INTO EGO_MTL_CATALOG_GRP_VERS_B
5446              (item_catalog_group_id,
5447              version_seq_id,
5448              version_description,
5449              start_active_date,
5450              end_active_date,
5451              created_by,
5452              creation_date,
5453              last_updated_by,
5454              last_update_date,
5455              last_update_login)
5456            VALUES
5457              ( p_item_catalog_id,
5458              0,
5459              l_msg_text,
5460              null,
5461              null,
5462              G_USER_ID,
5463              l_sysdate,
5464              G_USER_ID,
5465              l_sysdate,
5466              G_LOGIN_ID);
5467 
5468             ---- Lock the draft version
5469             ----
5470            l_party_id := Get_party_id ( p_user_id => G_USER_ID);
5471            INSERT INTO  EGO_OBJECT_LOCK
5472                 ( lock_id,
5473                   object_name,
5474                   pk1_value,
5475                   locking_party_id,
5476                   lock_flag,
5477                   created_by,
5478                   creation_date,
5479                   last_updated_by,
5480                   last_update_date,
5481                   last_update_login)
5482           VALUES   ( EGO_OBJECT_LOCK_S.NEXTVAL,
5483                      l_obj_name,
5484                      p_item_catalog_id,
5485                      l_party_id,
5486                      'L',
5487                      G_USER_ID,
5488                      l_sysdate,
5489                      G_USER_ID,
5490                      l_sysdate,
5491                      G_LOGIN_ID);
5492 
5493 write_debug(l_proc_name, 'End ');
5494 EXCEPTION
5495 WHEN OTHERS THEN
5496    x_return_status := G_RET_STS_UNEXP_ERROR;
5497    x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
5498 END Create_Draft_Version;
5499 
5500 /********************************************************************
5501 ---   This procedure accepts the interface table record type , converts
5502 ---   it to the record type required by the ego_item_catalog_pub API
5503 ---
5504 ********************************************************************/
5505 
5506 
5507 PROCEDURE    Convert_intf_rec_to_API_type (  p_entity       IN VARCHAR2
5508                                       , p_icc_rec      IN ego_icc_rec_type
5509                                       , x_api_icc_rec  OUT NOCOPY EGO_ITEM_CATALOG_PUB.Catalog_Group_Rec_Type
5510                                      )
5511 IS
5512   l_proc_name    VARCHAR2(30) := 'Convert_to_API_tbl_type';
5513 BEGIN
5514 
5515   write_debug(l_proc_name, 'Start');
5516 
5517   IF p_entity = G_ENTITY_ICC_HEADER THEN
5518 
5519       x_api_icc_rec.Catalog_Group_Name         := p_icc_rec.item_catalog_name;
5520       x_api_icc_rec.Parent_Catalog_Group_Name  := p_icc_rec.parent_catalog_group_name;
5521       x_api_icc_rec.Catalog_Group_Id           := p_icc_rec.item_catalog_group_id;
5522       x_api_icc_rec.Parent_Catalog_Group_Id    := p_icc_rec.parent_catalog_group_id;
5523       x_api_icc_rec.Description                := p_icc_rec.Description;
5524       x_api_icc_rec.Item_Creation_Allowed_Flag := p_icc_rec.Item_Creation_Allowed_Flag;
5525       x_api_icc_rec.Start_Effective_Date       := p_icc_rec.start_date_active;
5526       x_api_icc_rec.Inactive_Date              := trunc(p_icc_rec.Inactive_Date);
5527       x_api_icc_rec.Enabled_Flag               := p_icc_rec.Enabled_Flag;
5528       x_api_icc_rec.Summary_Flag               := p_icc_rec.Summary_Flag;
5529       x_api_icc_rec.segment1                   := p_icc_rec.segment1;
5530       x_api_icc_rec.segment2                   := p_icc_rec.segment2;
5531       x_api_icc_rec.segment3                   := p_icc_rec.segment3;
5532       x_api_icc_rec.segment4                   := p_icc_rec.segment4;
5533       x_api_icc_rec.segment5                   := p_icc_rec.segment5;
5534       x_api_icc_rec.segment6                   := p_icc_rec.segment6;
5535       x_api_icc_rec.segment7                   := p_icc_rec.segment7;
5536       x_api_icc_rec.segment8                   := p_icc_rec.segment8;
5537       x_api_icc_rec.segment9                   := p_icc_rec.segment9;
5538       x_api_icc_rec.segment10                  := p_icc_rec.segment10;
5539       x_api_icc_rec.segment11                  := p_icc_rec.segment11;
5540       x_api_icc_rec.segment12                  := p_icc_rec.segment12;
5541       x_api_icc_rec.segment13                  := p_icc_rec.segment13;
5542       x_api_icc_rec.segment14                  := p_icc_rec.segment14;
5543       x_api_icc_rec.segment15                  := p_icc_rec.segment15;
5544       x_api_icc_rec.segment16                  := p_icc_rec.segment16;
5545       x_api_icc_rec.segment17                  := p_icc_rec.segment17;
5546       x_api_icc_rec.segment18                  := p_icc_rec.segment18;
5547       x_api_icc_rec. segment19                 := p_icc_rec.segment19;
5548       x_api_icc_rec.segment20                  := p_icc_rec.segment20;
5549       x_api_icc_rec.Attribute_category         := p_icc_rec.Attribute_category;
5550       x_api_icc_rec.Attribute1                 := p_icc_rec.Attribute1;
5551       x_api_icc_rec.Attribute2                 := p_icc_rec.Attribute2;
5552       x_api_icc_rec.Attribute3                 := p_icc_rec.Attribute3;
5553       x_api_icc_rec.Attribute4                 := p_icc_rec.Attribute4;
5554       x_api_icc_rec.Attribute5                 := p_icc_rec.Attribute5;
5555       x_api_icc_rec.Attribute6                 := p_icc_rec.Attribute6;
5556       x_api_icc_rec.Attribute7                 := p_icc_rec.Attribute7;
5557       x_api_icc_rec.Attribute8                 := p_icc_rec.Attribute8;
5558       x_api_icc_rec.Attribute9                 := p_icc_rec.Attribute9;
5559       x_api_icc_rec.Attribute10                := p_icc_rec.Attribute10;
5560       x_api_icc_rec.Attribute11                := p_icc_rec.Attribute11;
5561       x_api_icc_rec.Attribute12                := p_icc_rec.Attribute12;
5562       x_api_icc_rec.Attribute13                := p_icc_rec.Attribute13;
5563       x_api_icc_rec.Attribute14                := p_icc_rec.Attribute14;
5564       x_api_icc_rec.Attribute15                := p_icc_rec.Attribute15;
5565       x_api_icc_rec.Transaction_Type           := p_icc_rec.Transaction_Type;
5566          --x_api_icc_rec.Return_Status
5567 
5568   END IF;
5569 
5570   write_debug(l_proc_name, 'End');
5571 END Convert_intf_rec_to_API_type;
5572 
5573 
5574 /********************************************************************
5575 ---   This procedure accepts the ego_item_catalog_pub API record type , converts
5576 ---   it to the interface table record type
5577 ---
5578 ********************************************************************/
5579 
5580 PROCEDURE Convert_API_type_to_intf_rec  (  p_entity       IN VARCHAR2
5581                                          , x_icc_rec      IN OUT NOCOPY ego_icc_rec_type
5582                                          , p_api_icc_rec  IN EGO_ITEM_CATALOG_PUB.Catalog_Group_Rec_Type
5583                                          )
5584 IS
5585   l_proc_name    VARCHAR2(30) := 'Convert_API_type_to_intf_rec';
5586 BEGIN
5587 
5588   write_debug(l_proc_name, 'Start');
5589 
5590   IF p_entity = G_ENTITY_ICC_HEADER THEN
5591 
5592       x_icc_rec.item_catalog_name          := NVL(x_icc_rec.item_catalog_name  ,  p_api_icc_rec.Catalog_Group_Name );
5593       x_icc_rec.parent_catalog_group_name  := NVL(x_icc_rec.parent_catalog_group_name,  p_api_icc_rec.Parent_Catalog_Group_Name );
5594       x_icc_rec.item_catalog_group_id      := NVL(x_icc_rec.item_catalog_group_id  ,  p_api_icc_rec.Catalog_Group_Id );
5595       x_icc_rec.parent_catalog_group_id    := NVL(x_icc_rec.parent_catalog_group_id  ,  p_api_icc_rec.Parent_Catalog_Group_Id );
5596       x_icc_rec.Description                := NVL(x_icc_rec.Description  ,  p_api_icc_rec.Description );
5597       x_icc_rec.Item_Creation_Allowed_Flag := NVL(x_icc_rec.Item_Creation_Allowed_Flag  ,  p_api_icc_rec.Item_Creation_Allowed_Flag );
5598       x_icc_rec.start_date_active          := NVL(x_icc_rec.start_date_active  ,  p_api_icc_rec.Start_Effective_Date );
5599       x_icc_rec.Inactive_Date              := NVL(x_icc_rec.Inactive_Date  ,  p_api_icc_rec.Inactive_Date );
5600       x_icc_rec.Enabled_Flag               := NVL(x_icc_rec.Enabled_Flag  ,  p_api_icc_rec.Enabled_Flag );
5601       x_icc_rec.Summary_Flag               := NVL(x_icc_rec.Summary_Flag  ,  p_api_icc_rec.Summary_Flag );
5602       x_icc_rec.segment1                   := NVL(x_icc_rec.segment1  ,  p_api_icc_rec.segment1 );
5603       x_icc_rec.segment2                   := NVL(x_icc_rec.segment2  ,  p_api_icc_rec.segment2 );
5604       x_icc_rec.segment3                   := NVL(x_icc_rec.segment3  ,  p_api_icc_rec.segment3 );
5605       x_icc_rec.segment4                   := NVL(x_icc_rec.segment4  ,  p_api_icc_rec.segment4 );
5606       x_icc_rec.segment5                   := NVL(x_icc_rec.segment5  ,  p_api_icc_rec.segment5 );
5607       x_icc_rec.segment6                   := NVL(x_icc_rec.segment6  ,  p_api_icc_rec.segment6 );
5608       x_icc_rec.segment7                   := NVL(x_icc_rec.segment7  ,  p_api_icc_rec.segment7 );
5609       x_icc_rec.segment8                   := NVL(x_icc_rec.segment8  ,  p_api_icc_rec.segment8 );
5610       x_icc_rec.segment9                   := NVL(x_icc_rec.segment9  ,  p_api_icc_rec.segment9 );
5611       x_icc_rec.segment10                  := NVL(x_icc_rec.segment10  ,  p_api_icc_rec.segment10 );
5612       x_icc_rec.segment11                  := NVL(x_icc_rec.segment11  ,  p_api_icc_rec.segment11 );
5613       x_icc_rec.segment12                  := NVL(x_icc_rec.segment12  ,  p_api_icc_rec.segment12 );
5614       x_icc_rec.segment13                  := NVL(x_icc_rec.segment13  ,  p_api_icc_rec.segment13 );
5615       x_icc_rec.segment14                  := NVL(x_icc_rec.segment14  ,  p_api_icc_rec.segment14 );
5616       x_icc_rec.segment15                  := NVL(x_icc_rec.segment15  ,  p_api_icc_rec.segment15 );
5617       x_icc_rec.segment16                  := NVL(x_icc_rec.segment16  ,  p_api_icc_rec.segment16 );
5618       x_icc_rec.segment17                  := NVL(x_icc_rec.segment17  ,  p_api_icc_rec.segment17 );
5619       x_icc_rec.segment18                  := NVL(x_icc_rec.segment18  ,  p_api_icc_rec.segment18 );
5620       x_icc_rec.segment19                  := NVL(x_icc_rec.segment19  ,  p_api_icc_rec. segment19 );
5621       x_icc_rec.segment20                  := NVL(x_icc_rec.segment20  ,  p_api_icc_rec.segment20 );
5622       x_icc_rec.Attribute_category         := NVL(x_icc_rec.Attribute_category  ,  p_api_icc_rec.Attribute_category );
5623       x_icc_rec.Attribute1                 := NVL(x_icc_rec.Attribute1  ,  p_api_icc_rec.Attribute1 );
5624       x_icc_rec.Attribute2                 := NVL(x_icc_rec.Attribute2  ,  p_api_icc_rec.Attribute2 );
5625       x_icc_rec.Attribute3                 := NVL(x_icc_rec.Attribute3  ,  p_api_icc_rec.Attribute3 );
5626       x_icc_rec.Attribute4                 := NVL(x_icc_rec.Attribute4  ,  p_api_icc_rec.Attribute4 );
5627       x_icc_rec.Attribute5                 := NVL(x_icc_rec.Attribute5  ,  p_api_icc_rec.Attribute5 );
5628       x_icc_rec.Attribute6                 := NVL(x_icc_rec.Attribute6  ,  p_api_icc_rec.Attribute6 );
5629       x_icc_rec.Attribute7                 := NVL(x_icc_rec.Attribute7  ,  p_api_icc_rec.Attribute7 );
5630       x_icc_rec.Attribute8                 := NVL(x_icc_rec.Attribute8  ,  p_api_icc_rec.Attribute8 );
5631       x_icc_rec.Attribute9                 := NVL(x_icc_rec.Attribute9  ,  p_api_icc_rec.Attribute9 );
5632       x_icc_rec.Attribute10                := NVL(x_icc_rec.Attribute10  ,  p_api_icc_rec.Attribute10 );
5633       x_icc_rec.Attribute11                := NVL(x_icc_rec.Attribute11  ,  p_api_icc_rec.Attribute11 );
5634       x_icc_rec.Attribute12                := NVL(x_icc_rec.Attribute12  ,  p_api_icc_rec.Attribute12 );
5635       x_icc_rec.Attribute13                := NVL(x_icc_rec.Attribute13  ,  p_api_icc_rec.Attribute13 );
5636       x_icc_rec.Attribute14                := NVL(x_icc_rec.Attribute14  ,  p_api_icc_rec.Attribute14 );
5637       x_icc_rec.Attribute15                := NVL(x_icc_rec.Attribute15  ,  p_api_icc_rec.Attribute15 );
5638 
5639                                         --p_api_icc_rec.Return_Status
5640 
5641   END IF;
5642 
5643   write_debug(l_proc_name, 'End');
5644 END Convert_API_type_to_intf_rec;
5645 
5646 
5647 
5648 /******************************************************************
5649 
5650 --- Procedure to log an error message for an entity as a whole
5651 --- when the entity fails because of error in existing APIs being
5652 --- re-used
5653 ---
5654 
5655 *******************************************************************/
5656 
5657 PROCEDURE Log_Error_For_Entity_Rec  ( p_entity_name   IN VARCHAR2
5658                                      ,p_trans_type    IN NUMBER
5659                                      ,p_pkg_name      IN VARCHAR2
5660                                      ,p_proc_name     IN VARCHAR2
5661                                      ,p_entity_code   IN VARCHAR2
5662                                      ,p_table_name    IN VARCHAR2
5663                                      ,p_transaction_id IN VARCHAR2
5664                                      ,p_message_name   IN VARCHAR2 DEFAULT 'EGO_ENTITY_API_FAILED'
5665                                     )
5666 IS
5667   l_proc_name  VARCHAR2(40) := 'Log_Error_For_Entity_Rec';
5668 
5669 BEGIN
5670 
5671 
5672 
5673   NULL;
5674 
5675  /*
5676 
5677 G_TOKEN_TBL(1).Token_Name   :=  'Entity_Name';
5678                 G_TOKEN_TBL(1).Token_Value  :=  G_ENTITY_ICC_HEADER;
5679                 G_TOKEN_TBL(2).Token_Name   :=  'Transaction_Type';
5680                 G_TOKEN_TBL(2).Token_Value  :=  P_pg_tbl(i).transaction_type;
5681                 G_TOKEN_TBL(3).Token_Name   :=  'Package_Name';
5682                 G_TOKEN_TBL(3).Token_Value  :=  'ego_ext_fwk_pub';
5683                 G_TOKEN_TBL(4).Token_Name   :=  'Proc_Name';
5684                 G_TOKEN_TBL(4).Token_Value  :=  'Create_page';
5685 
5686                 error_handler.Add_error_message(p_message_name => 'EGO_ENTITY_API_FAILED',p_application_id => G_EGO_APPLICATION_ID,
5687                                                 p_token_tbl => g_token_table,p_message_type => G_RET_STS_ERROR,
5688                                                 p_row_identifier => p_icc_rec.transaction_id,
5689                                                 p_entity_code => G_ENTITY_ICC_HEADER,p_table_name => G_ENTITY_ICC_HEADER_TAB);
5690 
5691                 G_TOKEN_TBL.DELETE;
5692 
5693 */
5694 
5695 END Log_Error_For_Entity_Rec;
5696 
5697 
5698 
5699 /********************************************************************
5700 ---
5701 ---   This procedure creates/updates/deletes the action id associated with
5702 ---   number generation and desc generation columns in the ICC header record
5703 ---
5704 ********************************************************************/
5705 
5706 Procedure Process_Function_Actions (  p_operation       IN VARCHAR2
5707                                      ,p_function_id      IN NUMBER DEFAULT NULL
5708                                      ,p_icc_id           IN NUMBER DEFAULT NULL
5709                                      ,p_transaction_id   IN NUMBER  DEFAULT NULL
5710                                      ,p_enable_key_attrs IN VARCHAR2 DEFAULT NULL
5711                                      ,p_action_id        IN NUMBER DEFAULT NULL
5712                                      ,x_action_id     OUT NOCOPY NUMBER
5713                                      ,x_return_status OUT NOCOPY VARCHAR2
5714                                      ,x_return_msg    OUT NOCOPY VARCHAR2
5715                                     )
5716 IS
5717   l_proc_name    VARCHAR2(30) := 'Process_Function_Actions';
5718   l_sequence     NUMBER := 100;
5719   l_action_name  EGO_ACTIONS_B.action_name%TYPE := 'ItemRequestProcessAction';
5720   l_entity_code     VARCHAR2(30) := G_ENTITY_ICC_AG_ASSOC;
5721   l_object_id   fnd_objects.object_id%TYPE;
5722   l_association_id  ego_obj_ag_assocs_b.association_id%TYPE;
5723 
5724   l_msg_count           NUMBER := 0;
5725   l_error_code          NUMBER := 0;
5726 
5727   e_skip_record         EXCEPTION;
5728   e_unexpected_error    EXCEPTION;
5729 
5730   l_token_table     ERROR_HANDLER.Token_Tbl_Type;
5731   l_msg_data        VARCHAR2(4000);
5732 
5733 BEGIN
5734   x_return_status := G_RET_STS_SUCCESS;
5735   write_debug (l_proc_name, 'Start');
5736 
5737 
5738 
5739     FOR rec_obj_id IN cur_get_obj_id loop
5740       l_object_id := rec_obj_id.object_id;
5741     end loop;
5742 
5743   IF p_operation = G_TTYPE_CREATE THEN
5744 
5745           EGO_EXT_FWK_PUB.Create_Action (
5746            p_api_version           => 1.0
5747           ,p_object_id             => l_object_id
5748           ,p_classification_code   => to_char( p_icc_id)
5749           ,p_attr_group_id         => NULL
5750           ,p_sequence              => l_sequence
5751           ,p_action_name           => l_action_name
5752           ,p_description           => null
5753           ,p_function_id           => p_function_id
5754           ,p_enable_key_attrs      => p_enable_key_attrs
5755           ,p_security_privilege_id => NULL
5756           ,p_init_msg_list         => FND_API.G_false
5757           ,p_commit                => FND_API.G_FALSE
5758           ,x_action_id             => x_action_id
5759           ,x_return_status         => x_return_status
5760           ,x_errorcode             => l_error_code
5761           ,x_msg_count             => l_msg_count
5762           ,x_msg_data              => x_return_msg
5763                                   );
5764        write_debug(l_proc_name, 'action id =>'||x_action_id);
5765        IF x_return_status = G_RET_STS_SUCCESS THEN
5766 
5767         EGO_EXT_FWK_PUB.Create_Action_Display (
5768                 p_api_version     => 1.0
5769                ,p_action_id       => x_action_id
5770                ,p_trigger_code    => NULL
5771                ,p_init_msg_list   => fnd_api.g_FALSE
5772                ,p_commit          => fnd_api.g_FALSE
5773                ,x_return_status   => x_return_status
5774                ,x_errorcode       => l_error_code
5775                ,x_msg_count       => l_msg_count
5776                ,x_msg_data        => x_return_msg
5777                        );
5778             write_debug(l_proc_name, 'action display ret status =>'||x_action_id);
5779             IF x_return_status = G_RET_STS_ERROR THEN
5780                   ERROR_HANDLER.Add_Error_Message(
5781                     p_message_text                  => x_return_msg
5782                    ,p_application_id                => G_APPL_NAME
5783                    ,p_row_identifier                => p_transaction_id
5784                    ,p_entity_code                   => l_entity_code
5785                    ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
5786                    );
5787 
5788             ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
5789                write_debug(l_proc_name, 'CREATE action=>'||x_return_msg);
5790                RAISE e_unexpected_error;
5791             END IF;
5792 
5793 
5794        ELSIF x_return_status = G_RET_STS_ERROR THEN
5795 
5796               ERROR_HANDLER.Add_Error_Message(
5797                 p_message_text                  => x_return_msg
5798                ,p_application_id                => G_APPL_NAME
5799                ,p_row_identifier                => p_transaction_id
5800                ,p_entity_code                   => l_entity_code
5801                ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
5802                );
5803 
5804        ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
5805          write_debug(l_proc_name, 'CREATE action=>'||x_return_msg);
5806          RAISE e_unexpected_error;
5807        END IF;
5808 
5809   ELSIF p_operation = G_TTYPE_UPDATE THEN
5810 
5811             EGO_EXT_FWK_PUB.Update_Action (
5812              p_api_version           => 1.0
5813             ,p_action_id             => p_action_id
5814             ,p_sequence              => l_sequence
5815             ,p_action_name           => l_action_name
5816             ,p_description           => null
5817             ,p_function_id           => p_function_id
5818             ,p_enable_key_attrs      => p_enable_key_attrs
5819             ,p_security_privilege_id => null
5820             ,p_init_msg_list         => FND_API.G_false
5821             ,p_commit                => FND_API.G_FALSE
5822             ,x_return_status         => x_return_status
5823             ,x_errorcode             => l_error_code
5824             ,x_msg_count             => l_msg_count
5825             ,x_msg_data              => x_return_msg
5826                                     );
5827                  write_debug(l_proc_name, 'action update func id=>'||p_function_id);
5828                  IF x_return_status = G_RET_STS_ERROR THEN
5829 
5830                       ERROR_HANDLER.Add_Error_Message(
5831                         p_message_text                  => x_return_msg
5832                        ,p_application_id                => G_APPL_NAME
5833                        ,p_row_identifier                => p_transaction_id
5834                        ,p_entity_code                   => l_entity_code
5835                        ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
5836                        );
5837 
5838                ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
5839                  write_debug(l_proc_name, 'UPDATE action=>'||x_return_msg);
5840                  RAISE e_unexpected_error;
5841                END IF;
5842 
5843   --
5844   -- Bug 9953881. Action Id not getting updated when
5845   -- user is updating the desc or num generate function.
5846   -- Return the same action id for update scenario.
5847   -- sreharih. Thu Apr 14 18:29:12 PDT 2011
5848   --
5849   x_action_id := p_action_id;
5850 
5851   ELSIF p_operation = G_TTYPE_DELETE THEN
5852 
5853         EGO_EXT_FWK_PUB.Delete_Action (
5854           p_api_version   => 1.0
5855          ,p_action_id     => p_action_id
5856          ,p_init_msg_list => FND_API.g_false
5857          ,p_commit        => FND_API.g_false
5858          ,x_return_status => x_return_status
5859          ,x_errorcode     => l_error_code
5860          ,x_msg_count     => l_msg_count
5861          ,x_msg_data      =>  x_return_msg
5862           );
5863 
5864         IF x_return_status  = G_RET_STS_SUCCESS THEN
5865 
5866                EGO_EXT_FWK_PUB.Delete_Action_Display (
5867                 p_api_version        => 1.0
5868                ,p_action_id          => p_action_id
5869                ,p_init_msg_list      => FND_API.g_false
5870                ,p_commit             => FND_API.g_false
5871                ,x_return_status      => x_return_status
5872                ,x_errorcode          => l_error_code
5873                ,x_msg_count          => l_msg_count
5874                ,x_msg_data           =>  x_return_msg
5875                                     );
5876                  write_debug(l_proc_name, 'action DELETE STS=>'||x_return_status);
5877                  IF x_return_status = G_RET_STS_ERROR THEN
5878 
5879                       ERROR_HANDLER.Add_Error_Message(
5880                         p_message_text                  => x_return_msg
5881                        ,p_application_id                => G_APPL_NAME
5882                        ,p_row_identifier                => p_transaction_id
5883                        ,p_entity_code                   => l_entity_code
5884                        ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
5885                        );
5886                  ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
5887                    write_debug(l_proc_name, 'delete action=>'||x_return_msg);
5888                    RAISE e_unexpected_error;
5889                  END IF;
5890 
5891         ELSIF x_return_status = G_RET_STS_ERROR THEN
5892 
5893                   ERROR_HANDLER.Add_Error_Message(
5894                     p_message_text                  => x_return_msg
5895                    ,p_application_id                => G_APPL_NAME
5896                    ,p_row_identifier                => p_transaction_id
5897                    ,p_entity_code                   => l_entity_code
5898                    ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
5899                    );
5900 
5901         ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
5902              write_debug(l_proc_name, 'DELETE action=>'||x_return_msg);
5903              RAISE e_unexpected_error;
5904         END IF;
5905 
5906   END IF;  --for operation type
5907 
5908   write_debug(l_proc_name, 'End');
5909 EXCEPTION
5910    WHEN e_unexpected_error THEN
5911       x_return_status := G_RET_STS_UNEXP_ERROR;
5912       x_return_msg := x_return_msg||'Stop process error occured in '||G_PKG_NAME||'.'||l_proc_name;
5913       write_debug(l_proc_name, x_return_msg);
5914    WHEN OTHERS THEN
5915       x_return_status := G_RET_STS_UNEXP_ERROR;
5916       x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
5917 END Process_Function_Actions;
5918 
5919 
5920 
5921 /********************************************************************
5922 ---
5923 ---   This procedure calls the relevant procedures for function related
5924 ---   information update to the ICC
5925 ---
5926 ********************************************************************/
5927 
5928 PROCEDURE Create_Action_for_Func   ( p_icc_rec IN OUT NOCOPY ego_icc_rec_type
5929                                     ,x_return_status OUT NOCOPY VARCHAR2
5930                                     ,x_return_msg    OUT NOCOPY VARCHAR2
5931                                     )
5932 
5933 IS
5934 
5935   l_proc_name        VARCHAR2(30) := 'Create_Action_for_Func';
5936   l_entity_code      VARCHAR2(50) := G_ENTITY_ICC_HEADER;
5937   l_object_id        FND_OBJECTS.object_id%TYPE := null;
5938   l_action_id        ego_actions_b.action_id%TYPE := null;
5939   l_old_num_func_id  ego_actions_b.function_id%TYPE := NULL;
5940   l_old_desc_func_id ego_actions_b.function_id%TYPE := NULL;
5941   l_old_key_attrs_num   ego_actions_b.enable_key_attributes%TYPE; -- Bug 12394675
5942   l_old_key_attrs_desc  ego_actions_b.enable_key_attributes%TYPE; -- Bug 12394675
5943 
5944   e_unexpected_error EXCEPTION;
5945   l_seq_name         VARCHAR2(30) := NULL;
5946 
5947   CURSOR cur_get_action ( p_function_id number
5948                          ,p_icc_id      number
5949                          ,p_object_id   number
5950                         )
5951   IS
5952   SELECT action_id
5953   FROM   ego_actions_b
5954   WHERE function_id = p_function_id
5955   and   classification_code = to_char(p_icc_id)
5956   and   object_id = p_object_id
5957   ;
5958 
5959   CURSOR cur_get_function ( p_action_id number
5960                          ,p_icc_id      number
5961                          ,p_object_id   number
5962                         )
5963   IS
5964   SELECT function_id, enable_key_attributes
5965   FROM   ego_actions_b
5966   WHERE action_id = p_action_id
5967   and   classification_code = to_char(p_icc_id)
5968   and   object_id = p_object_id
5969   ;
5970 
5971       ---
5972       --- Inline Procedure to create number generation method
5973       ---
5974       PROCEDURE Create_Num_Gen_Method
5975       IS
5976       BEGIN
5977             Process_Function_Actions (  p_operation        => G_TTYPE_CREATE
5978                                        ,p_function_id      => p_icc_rec.item_num_function_id
5979                                        ,p_icc_id           => p_icc_rec.item_catalog_group_id
5980                                        ,p_transaction_id   => p_icc_rec.transaction_id
5981                                        ,p_enable_key_attrs => p_icc_rec.enable_key_attrs_num
5982                                        ,p_action_id        => null
5983                                        ,x_action_id        => p_icc_rec.item_num_action_id
5984                                        ,x_return_status    => x_return_status
5985                                        ,x_return_msg       => x_return_msg
5986                                    );
5987             IF x_return_status = G_RET_STS_ERROR THEN
5988 
5989                       ERROR_HANDLER.Add_Error_Message(
5990                         p_message_text                  => x_return_msg
5991                        ,p_application_id                => G_APPL_NAME
5992 
5993                        ,p_row_identifier                => p_icc_rec.transaction_id
5994                        ,p_entity_code                   => l_entity_code
5995                        ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
5996                        );
5997 
5998             ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
5999                  RAISE e_unexpected_error;
6000             END IF;
6001       END Create_Num_Gen_Method;
6002 
6003 
6004       ---
6005       --- Inline Procedure to create description generation method
6006       ---
6007       PROCEDURE Create_Desc_Gen_Method
6008       IS
6009       BEGIN
6010             Process_Function_Actions (  p_operation        => G_TTYPE_CREATE
6011                                        ,p_function_id      => p_icc_rec.item_desc_function_id
6012                                        ,p_icc_id           => p_icc_rec.item_catalog_group_id
6013                                        ,p_transaction_id   => p_icc_rec.transaction_id
6014                                        ,p_enable_key_attrs => p_icc_rec.enable_key_attrs_desc
6015                                        ,p_action_id        => null
6016                                        ,x_action_id        => p_icc_rec.item_desc_action_id
6017                                        ,x_return_status    => x_return_status
6018                                        ,x_return_msg       => x_return_msg
6019                                    );
6020             IF x_return_status = G_RET_STS_ERROR THEN
6021 
6022                       ERROR_HANDLER.Add_Error_Message(
6023                         p_message_text                  => x_return_msg
6024                        ,p_application_id                => G_APPL_NAME
6025 
6026                        ,p_row_identifier                => p_icc_rec.transaction_id
6027                        ,p_entity_code                   => l_entity_code
6028                        ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6029                        );
6030 
6031             ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6032                  RAISE e_unexpected_error;
6033             END IF;
6034       END Create_Desc_Gen_Method;
6035 
6036 
6037 
6038 
6039       ---
6040       --- Inline Procedure to delete old number generation method
6041       ---
6042       PROCEDURE Delete_Old_Num_Gen_Method
6043       IS
6044       BEGIN
6045                       Process_Function_Actions (  p_operation        => G_TTYPE_DELETE    --- delete the earlier action associated
6046                                                  ,p_function_id      => l_old_num_func_id
6047                                                  ,p_icc_id           => g_old_icc_rec.item_catalog_group_id
6048                                                  ,p_transaction_id   => p_icc_rec.transaction_id
6049                                                  ,p_enable_key_attrs => NULL
6050                                                  ,p_action_id        => g_old_icc_rec.ITEM_NUM_ACTION_ID
6051                                                  ,x_action_id        => l_action_id   --- dummy
6052                                                  ,x_return_status    => x_return_status
6053                                                  ,x_return_msg       => x_return_msg
6054                                              );
6055                           IF x_return_status = G_RET_STS_ERROR THEN
6056                                     ERROR_HANDLER.Add_Error_Message(
6057                                       p_message_text                  => x_return_msg
6058                                      ,p_application_id                => G_APPL_NAME
6059                                      ,p_row_identifier                => p_icc_rec.transaction_id
6060                                      ,p_entity_code                   => l_entity_code
6061                                      ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6062                                      );
6063                           ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6064                                RAISE e_unexpected_error;
6065                           END IF;  ---error handling
6066 
6067 
6068       END Delete_Old_Num_Gen_Method;
6069 
6070 
6071       ---
6072       --- Inline Procedure to delete old description generation method
6073       ---
6074       PROCEDURE Delete_Old_Desc_Gen_Method
6075       IS
6076       BEGIN
6077                       Process_Function_Actions (  p_operation        => G_TTYPE_DELETE    --- delete the earlier action associated
6078                                                  ,p_function_id      => l_old_desc_func_id
6079                                                  ,p_icc_id           => g_old_icc_rec.item_catalog_group_id
6080                                                  ,p_transaction_id   => p_icc_rec.transaction_id
6081                                                  ,p_enable_key_attrs => p_icc_rec.enable_key_attrs_num
6082                                                  ,p_action_id        => g_old_icc_rec.ITEM_DESC_ACTION_ID
6083                                                  ,x_action_id        => l_action_id   --- dummy
6084                                                  ,x_return_status    => x_return_status
6085                                                  ,x_return_msg       => x_return_msg
6086                                              );
6087                           IF x_return_status = G_RET_STS_ERROR THEN
6088                                     ERROR_HANDLER.Add_Error_Message(
6089                                       p_message_text                  => x_return_msg
6090                                      ,p_application_id                => G_APPL_NAME
6091                                      ,p_row_identifier                => p_icc_rec.transaction_id
6092                                      ,p_entity_code                   => l_entity_code
6093                                      ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6094                                      );
6095                           ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6096                                RAISE e_unexpected_error;
6097                           END IF;  ---error handling
6098 
6099 
6100       END Delete_Old_Desc_Gen_Method;
6101 
6102 
6103 
6104 BEGIN
6105   write_debug (l_proc_name, 'Start');
6106   x_return_status := G_RET_STS_SUCCESS;
6107 
6108             --
6109             -- Bug 9953881. Action ID not getting updated in ICC.
6110             -- When ICC is created from UI num_gen_methods are null.
6111             -- Adding the condition for it.
6112             -- sreharih. Thu Apr 14 18:29:12 PDT 2011
6113             --
6114   g_old_icc_rec.item_num_gen_method  := nvl(g_old_icc_rec.item_num_gen_method ,'U');
6115   g_old_icc_rec.item_desc_gen_method := nvl(g_old_icc_rec.item_desc_gen_method ,'U');
6116 
6117   FOR rec_obj_id IN cur_get_obj_id
6118   loop
6119     l_object_id := rec_obj_id.object_id;
6120   end loop;
6121 
6122 
6123   --- Get the details of the existing ICC for
6124   --- UPDATE transaction
6125   ---
6126   IF p_icc_rec.transaction_type = G_TTYPE_UPDATE THEN
6127 
6128     --
6129     -- Bug 12394675. Issue #4. Enable ket attributes are not getting
6130     -- sync-ed. If user passed null then for update get value from old
6131     -- function.
6132     -- sreharih. Tue Apr 26 15:44:49 PDT 2011
6133     --
6134 
6135     --- Get the existing number generation function id
6136     ---
6137 
6138     FOR rec_get_function IN  cur_get_function (   g_old_icc_rec.item_num_action_id
6139                                                 , g_old_icc_rec.item_catalog_group_id
6140                                                 , l_object_id
6141                                               ) LOOP
6142       l_old_num_func_id := rec_get_function.function_id;
6143       IF  p_icc_rec.enable_key_attrs_num IS NULL THEN -- bug 12394675
6144         p_icc_rec.enable_key_attrs_num  := rec_get_function.enable_key_attributes;
6145       END IF;
6146       l_old_key_attrs_num := rec_get_function.enable_key_attributes;
6147       write_debug(l_proc_name, 'old num gen func id=>'||l_old_num_func_id);
6148 
6149     END LOOP;
6150 
6151     --- Get the existing description generation function id
6152     ---
6153 
6154     FOR rec_get_function IN  cur_get_function (   g_old_icc_rec.item_desc_action_id
6155                                                 , g_old_icc_rec.item_catalog_group_id
6156                                                 , l_object_id
6157                                               ) LOOP
6158       l_old_desc_func_id := rec_get_function.function_id;
6159       IF p_icc_rec.enable_key_attrs_desc IS NULL THEN  -- bug 12394675
6160         p_icc_rec.enable_key_attrs_desc  := rec_get_function.enable_key_attributes;
6161       END IF;
6162       l_old_key_attrs_desc := rec_get_function.enable_key_attributes;
6163       write_debug(l_proc_name, 'old desc gen func id=>'||l_old_desc_func_id);
6164     END LOOP;
6165 
6166 
6167   END IF;
6168 
6169   --- *******************
6170   --- CREATE transaction
6171   --- *******************
6172   IF p_icc_rec.transaction_type = G_TTYPE_CREATE THEN
6173           ---- CREATE for Number generation
6174           ----
6175           IF p_icc_rec.item_num_gen_method_type = 'F' THEN
6176              write_debug(l_proc_name, ' creating number generation action ');
6177              Create_Num_Gen_Method;
6178           END IF;
6179 
6180           ---- CREATE for description
6181           ----
6182           IF p_icc_rec.item_desc_gen_method_type = 'F'  THEN
6183              write_debug(l_proc_name, ' creating description generation action ');
6184              Create_Desc_Gen_Method;
6185           END IF;
6186 
6187           IF p_icc_rec.item_num_gen_method_type = 'S'  THEN
6188              write_debug(l_proc_name, ' creating sequence ');
6189              Generate_Seq_For_Item_Catalog (
6190                    p_icc_id                  => p_icc_rec.item_catalog_group_id
6191                   ,p_seq_start_num           => p_icc_rec.starting_number
6192                   ,p_seq_increment_by        => p_icc_rec.increment_by
6193                   ,x_seq_name                => l_seq_name
6194                   ,x_return_status           => x_return_status
6195                   ,x_return_msg              => x_return_msg
6196                     );
6197               write_debug(l_proc_name, ' creating sequence status =>'||x_return_status);
6198               IF x_return_status = G_RET_STS_SUCCESS THEN
6199                 p_icc_rec.item_num_seq_name := l_seq_name;
6200               END IF;
6201           END IF;
6202 
6203  END IF;
6204 
6205 
6206  -----******************
6207  --- UPDATE transaction
6208  ----*******************
6209 
6210  IF p_icc_rec.transaction_type = G_TTYPE_UPDATE THEN
6211       write_debug(l_proc_name, 'UPDATE transaction');
6212 
6213       ---*******************
6214       ---- Number generation
6215       ---- when new method is FUNCTION generated
6216 
6217       IF p_icc_rec.item_num_gen_method_type = 'F' THEN
6218             write_debug(l_proc_name, 'UPDATE transaction 1');
6219             ---
6220             --- User attempting to add a number generation function
6221             ---
6222             IF g_old_icc_rec.item_num_gen_method IN ('U', 'I') THEN
6223 
6224                 write_debug(l_proc_name, 'create of action func id=>'||p_icc_rec.item_num_function_id);
6225                 Create_Num_Gen_Method;
6226 
6227             ---
6228             --- Old is function generated and user is trying to update it
6229             ---
6230             ELSIF g_old_icc_rec.item_num_gen_method = 'F' AND (l_old_num_func_id <> p_icc_rec.item_num_function_id ) THEN
6231                 --- user attempting to change the function associated
6232                 ---
6233                 write_debug(l_proc_name, 'update of action NUM func id=>'||p_icc_rec.item_num_function_id);
6234 
6235                 Process_Function_Actions (  p_operation        => G_TTYPE_UPDATE
6236                                            ,p_function_id      => p_icc_rec.item_num_function_id
6237                                            ,p_icc_id           => p_icc_rec.item_catalog_group_id
6238                                            ,p_transaction_id   => p_icc_rec.transaction_id
6239                                            ,p_enable_key_attrs => p_icc_rec.enable_key_attrs_num
6240                                            ,p_action_id        => g_old_icc_rec.item_num_action_id
6241                                            ,x_action_id        => p_icc_rec.item_num_action_id
6242                                            ,x_return_status    => x_return_status
6243                                            ,x_return_msg       => x_return_msg
6244                                        );
6245                 IF x_return_status = G_RET_STS_ERROR THEN
6246 
6247                           ERROR_HANDLER.Add_Error_Message(
6248                             p_message_text                  => x_return_msg
6249                            ,p_application_id                => G_APPL_NAME
6250                            ,p_row_identifier                => p_icc_rec.transaction_id
6251                            ,p_entity_code                   => l_entity_code
6252                            ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6253                            );
6254 
6255                 ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6256                      RAISE e_unexpected_error;
6257                 END IF;
6258 
6259                  --
6260                  -- Bug 9953881. Action Id not getting updated when
6261                  -- user is updating the desc or num generate function.
6262                  -- If the user is just trying to update the same function
6263                  -- and synching the params then pass the old action id.
6264                  -- sreharih. Thu Apr 14 18:29:12 PDT 2011
6265                  --
6266 
6267             ELSIF g_old_icc_rec.item_num_gen_method = 'F' AND (l_old_num_func_id = p_icc_rec.item_num_function_id ) THEN
6268                   p_icc_rec.item_num_action_id := g_old_icc_rec.item_num_action_id;
6269 
6270                   --
6271                   -- Bug 12394675. Issue #4. Added logic for updating
6272                   -- ket attribute flag if user just modifies this
6273                   -- sreharih. Tue Apr 26 15:44:49 PDT 2011
6274                   --
6275                   IF  p_icc_rec.enable_key_attrs_num <> l_old_key_attrs_num THEN
6276 
6277                          write_debug(l_proc_name, 'updating the enable key attrs for num function to ' || p_icc_rec.enable_key_attrs_num );
6278 
6279                          Process_Function_Actions (
6280                                             p_operation        => G_TTYPE_UPDATE
6281                                            ,p_function_id      => l_old_num_func_id
6282                                            ,p_icc_id           => p_icc_rec.item_catalog_group_id
6283                                            ,p_transaction_id   => p_icc_rec.transaction_id
6284                                            ,p_enable_key_attrs => p_icc_rec.enable_key_attrs_num
6285                                            ,p_action_id        => g_old_icc_rec.item_num_action_id
6286                                            ,x_action_id        => p_icc_rec.item_num_action_id
6287                                            ,x_return_status    => x_return_status
6288                                            ,x_return_msg       => x_return_msg
6289                                                    );
6290                         write_debug(l_proc_name, 'updating the enable key attrs returned with status ' || x_return_status);
6291 
6292                         IF x_return_status = G_RET_STS_ERROR THEN
6293 
6294                           ERROR_HANDLER.Add_Error_Message(
6295                             p_message_text                  => x_return_msg
6296                            ,p_application_id                => G_APPL_NAME
6297                            ,p_row_identifier                => p_icc_rec.transaction_id
6298                            ,p_entity_code                   => l_entity_code
6299                            ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6300                            );
6301 
6302                         ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6303                             RAISE e_unexpected_error;
6304                         END IF;
6305 
6306 
6307                   END IF;
6308 
6309 
6310             ---
6311             --- if old method was sequence generated then
6312             ---
6313             ELSIF g_old_icc_rec.item_num_gen_method = 'S' THEN
6314 
6315                       write_debug ( l_proc_name, 'dropping sequence =>'||g_old_icc_rec.item_num_seq_name);
6316                       Drop_Sequence_For_Item_Catalog (
6317                                 p_item_catalog_seq_name => g_old_icc_rec.item_num_seq_name
6318                                ,x_return_status         => x_return_status
6319                                ,x_return_msg            => x_return_msg
6320                                 );
6321                       IF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6322                         RAISE e_unexpected_error;
6323                       END IF;  ---error handling
6324 
6325                       write_debug(l_proc_name, 'create of action func id=>'||p_icc_rec.item_num_function_id);
6326                       Create_Num_Gen_Method;
6327             END IF;
6328 
6329       ---
6330       --- If new method is S' U OR I
6331       ELSIF p_icc_rec.item_num_gen_method_type IN ( 'U', 'S' , 'I' ) THEN
6332 
6333              write_debug(l_proc_name, 'UPDATE transaction 2');
6334              --- delete if it was function earlier
6335              ---
6336              IF g_old_icc_rec.item_num_gen_method = 'F' THEN
6337                Delete_Old_Num_Gen_Method;
6338              END IF;
6339 
6340              IF  g_old_icc_rec.item_num_gen_method = 'S'
6341                   AND
6342                   (  g_old_icc_rec.prefix          <> p_icc_rec.prefix
6343                   OR g_old_icc_rec.starting_number <> p_icc_rec.starting_number
6344                   OR g_old_icc_rec.increment_by    <> p_icc_rec.increment_by
6345                   OR g_old_icc_rec.suffix          <> p_icc_rec.suffix
6346                   ) THEN
6347 
6348                   write_debug ( l_proc_name, 'dropping old sequence =>'||g_old_icc_rec.item_num_seq_name);
6349                   Drop_Sequence_For_Item_Catalog (
6350                             p_item_catalog_seq_name => g_old_icc_rec.item_num_seq_name
6351                            ,x_return_status         => x_return_status
6352                            ,x_return_msg            => x_return_msg
6353                             );
6354                   IF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6355                     RAISE e_unexpected_error;
6356                   END IF;
6357                   --- new sequence will be created below
6358               END IF;
6359 
6360 
6361              IF p_icc_rec.item_num_gen_method_type = 'S' THEN
6362                  write_debug(l_proc_name, 'creating sequence ');
6363                  Generate_Seq_For_Item_Catalog (
6364                        p_icc_id                  => p_icc_rec.item_catalog_group_id
6365                       ,p_seq_start_num           => p_icc_rec.starting_number
6366                       ,p_seq_increment_by        => p_icc_rec.increment_by
6367                       ,x_seq_name                => l_seq_name
6368                       ,x_return_status           => x_return_status
6369                       ,x_return_msg              => x_return_msg
6370                         );
6371                   write_debug(l_proc_name, ' creating sequence status =>'||x_return_status);
6372                   IF x_return_status = G_RET_STS_SUCCESS THEN
6373                     p_icc_rec.item_num_seq_name := l_seq_name;
6374                   END IF;
6375              END IF;
6376       END IF;   --- New Method Type for number generation
6377       ---- Number generation End
6378       ---*******************
6379 
6380 
6381       ---*******************
6382       ---- Description  generation Start
6383 
6384       IF p_icc_rec.item_desc_gen_method_type = 'F' THEN
6385 
6386           write_debug(l_proc_name, 'transaction 2');
6387           IF g_old_icc_rec.item_desc_gen_method IN ('U','I') THEN
6388             write_debug(l_proc_name, 'transaction 3');
6389             Create_Desc_Gen_Method;
6390 
6391           ELSIF g_old_icc_rec.item_desc_gen_method = 'F' AND (l_old_desc_func_id <> p_icc_rec.item_desc_function_id) THEN
6392                 write_debug(l_proc_name, 'Old desc function id  present , updating action');
6393                 Process_Function_Actions (  p_operation        => G_TTYPE_UPDATE
6394                                            ,p_function_id      => p_icc_rec.item_desc_function_id
6395                                            ,p_icc_id           => p_icc_rec.item_catalog_group_id
6396                                            ,p_transaction_id   => p_icc_rec.transaction_id
6397                                            ,p_enable_key_attrs => p_icc_rec.enable_key_attrs_num
6398                                            ,p_action_id        => g_old_icc_rec.item_desc_action_id
6399                                            ,x_action_id        => p_icc_rec.item_desc_action_id
6400                                            ,x_return_status    => x_return_status
6401                                            ,x_return_msg       => x_return_msg
6402                                        );
6403                 IF x_return_status = G_RET_STS_ERROR THEN
6404                           ERROR_HANDLER.Add_Error_Message(
6405                             p_message_text                  => x_return_msg
6406                            ,p_application_id                => G_APPL_NAME
6407                            ,p_row_identifier                => p_icc_rec.transaction_id
6408                            ,p_entity_code                   => l_entity_code
6409                            ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6410                            );
6411 
6412                 ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6413                      RAISE e_unexpected_error;
6414                 END IF;
6415 
6416                  --
6417                  -- Bug 9953881. Action Id not getting updated when
6418                  -- user is updating the desc or num generate function.
6419                  -- If the user is just trying to update the same function
6420                  -- and synching the params then pass the old action id.
6421                  -- sreharih. Thu Apr 14 18:29:12 PDT 2011
6422                  --
6423            ELSIF g_old_icc_rec.item_desc_gen_method = 'F' AND (l_old_desc_func_id = p_icc_rec.item_desc_function_id) THEN
6424               p_icc_rec.item_desc_action_id := g_old_icc_rec.item_desc_action_id;
6425 
6426                   --
6427                   -- Bug 12394675. Issue #4. Added logic for updating
6428                   -- ket attribute flag if user just modifies this
6429                   -- sreharih. Tue Apr 26 15:44:49 PDT 2011
6430                   --
6431                   IF  p_icc_rec.enable_key_attrs_desc <> l_old_key_attrs_desc THEN
6432 
6433                          write_debug(l_proc_name, 'updating the enable key attrs for desc function to ' || p_icc_rec.enable_key_attrs_desc );
6434 
6435                          Process_Function_Actions (
6436                                             p_operation        => G_TTYPE_UPDATE
6437                                            ,p_function_id      => l_old_desc_func_id
6438                                            ,p_icc_id           => p_icc_rec.item_catalog_group_id
6439                                            ,p_transaction_id   => p_icc_rec.transaction_id
6440                                            ,p_enable_key_attrs => p_icc_rec.enable_key_attrs_desc
6441                                            ,p_action_id        => g_old_icc_rec.item_desc_action_id
6442                                            ,x_action_id        => p_icc_rec.item_desc_action_id
6443                                            ,x_return_status    => x_return_status
6444                                            ,x_return_msg       => x_return_msg
6445                                                    );
6446                         write_debug(l_proc_name, 'updating the enable key attrs returned with status ' || x_return_status);
6447 
6448                         IF x_return_status = G_RET_STS_ERROR THEN
6449 
6450                           ERROR_HANDLER.Add_Error_Message(
6451                             p_message_text                  => x_return_msg
6452                            ,p_application_id                => G_APPL_NAME
6453                            ,p_row_identifier                => p_icc_rec.transaction_id
6454                            ,p_entity_code                   => l_entity_code
6455                            ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6456                            );
6457 
6458                         ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6459                             RAISE e_unexpected_error;
6460                         END IF;
6461 
6462 
6463                   END IF;
6464 
6465           END IF;
6466 
6467       ELSIF p_icc_rec.item_desc_gen_method_type IN  ('U', 'I') THEN
6468 
6469           IF p_icc_rec.item_desc_gen_method_type = 'F' THEN
6470             Delete_Old_Desc_Gen_Method;
6471           END IF;
6472 
6473       END IF;
6474       ---
6475       ---- Description  generation End
6476       ---*******************
6477   END IF;
6478   ---
6479   --- UPDATE transaction End if
6480   ----*******************
6481 
6482   write_debug (l_proc_name, 'End');
6483 EXCEPTION
6484 WHEN OTHERS THEN
6485   x_return_status := G_RET_STS_UNEXP_ERROR;
6486   x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
6487 END Create_Action_for_Func;
6488 
6489 
6490 /********************************************************************
6491 ---
6492 ---   This procedure updates the Item number Generation and
6493 ---   desc generation columns in the ICC header table
6494 ---   this procedure is called when all the paameters are not mapped
6495 ---   and the function needs to be removed from the ICC header
6496 ---
6497 ********************************************************************/
6498 
6499 PROCEDURE  Update_Func_ICC_Hdr_Cols  (  p_col_name    IN VARCHAR2
6500                                        ,p_icc_id      IN NUMBER
6501                                        ,x_return_status OUT NOCOPY VARCHAR2
6502                                        ,x_return_msg  OUT NOCOPY VARCHAR2
6503                                       )
6504 is
6505   l_proc_name    VARCHAR2(30) := 'Update_Func_ICC_Hdr_Cols';
6506 begin
6507   x_return_status := G_RET_STS_SUCCESS;
6508   write_debug (l_proc_name, 'Start');
6509 
6510 
6511   UPDATE MTL_ITEM_CATALOG_GROUPS_B
6512   SET
6513       ITEM_NUM_ACTION_ID          = decode ( p_col_name, G_NUM_GEN_FUNCTION , null, ITEM_NUM_ACTION_ID)
6514     , ITEM_DESC_ACTION_ID         = decode ( p_col_name, G_DESC_GEN_FUNCTION , null, ITEM_DESC_ACTION_ID)
6515     ,last_updated_by        =   G_USER_ID
6516     ,last_update_date       =   SYSDATE
6517     ,last_update_login      =   G_LOGIN_ID
6518   WHERE   item_catalog_group_id = p_icc_id
6519   ;
6520 
6521 
6522   write_debug (l_proc_name, 'End');
6523 EXCEPTION
6524 WHEN OTHERS THEN
6525   x_return_status := G_RET_STS_UNEXP_ERROR;
6526   x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
6527 END Update_Func_ICC_Hdr_Cols;
6528 
6529 
6530 
6531 
6532 /********************************************************************
6533 ---
6534 ---   This procedure updates the NIR related columns , Item number Generation and
6535 ---   desc generation columns in the ICC header table
6536 ---
6537 ********************************************************************/
6538 
6539  PROCEDURE Update_Other_ICC_Hdr_Cols  ( p_icc_rec IN ego_icc_rec_type
6540                                        ,x_return_status OUT NOCOPY VARCHAR2
6541                                        ,x_return_msg  OUT NOCOPY VARCHAR2
6542                                       )
6543 is
6544   l_proc_name    VARCHAR2(30) := 'Update_Other_ICC_Hdr_Cols';
6545 begin
6546   x_return_status := G_RET_STS_SUCCESS;
6547   write_debug (l_proc_name, 'Start');
6548 
6549 
6550   UPDATE MTL_ITEM_CATALOG_GROUPS_B
6551   SET
6552       ITEM_NUM_GEN_METHOD         = p_icc_rec.item_num_gen_method_type
6553      ,PREFIX                      = p_icc_rec.prefix
6554      ,STARTING_NUMBER             = p_icc_rec.starting_number
6555     , INCREMENT_BY                = p_icc_rec.increment_by
6556     , SUFFIX                      = p_icc_rec.suffix
6557     , ITEM_NUM_SEQ_NAME           = p_icc_rec.item_num_seq_name
6558     , ITEM_NUM_ACTION_ID          = p_icc_rec.item_num_action_id
6559     , ITEM_DESC_GEN_METHOD        = p_icc_rec.item_desc_gen_method_type
6560     , ITEM_DESC_ACTION_ID         = p_icc_rec.item_desc_action_id
6561     , NEW_ITEM_REQUEST_REQD       = p_icc_rec.new_item_request_type
6562     , NEW_ITEM_REQ_CHANGE_TYPE_ID = p_icc_rec.new_item_req_change_type_id
6563     --, ITEM_NUM_SEQ_NAME
6564     ,last_updated_by        =   G_USER_ID
6565     ,last_update_date       =   SYSDATE
6566     ,last_update_login      =   G_LOGIN_ID
6567   WHERE   item_catalog_group_id = p_icc_rec.item_catalog_group_id
6568   ;
6569 
6570 
6571   write_debug (l_proc_name, 'End');
6572 EXCEPTION
6573 WHEN OTHERS THEN
6574   x_return_status := G_RET_STS_UNEXP_ERROR;
6575   x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
6576 END Update_Other_ICC_Hdr_Cols;
6577 
6578 
6579 
6580      --- required, when processing per ICC
6581      ---
6582   PROCEDURE update_icc_id_name ( p_icc_name   IN VARCHAR2, p_icc_id IN NUMBER)
6583   IS
6584 
6585      l_proc_name   VARCHAR2(50) :=  'update_icc_id_name';
6586    BEGIN
6587 
6588    write_debug(l_proc_name, 'updating  name');
6589    UPDATE EGO_ICC_VERS_INTERFACE  eivi
6590         SET    eivi.item_catalog_name = ( select icc_kfv.concatenated_segments
6591                                      from   mtl_item_catalog_groups_kfv icc_kfv
6592                                      where icc_kfv.item_catalog_group_id = eivi.item_catalog_group_id
6593                                    )
6594         WHERE  eivi.item_catalog_group_id = p_icc_id
6595         AND   eivi.process_status = G_PROCESS_STATUS_INITIAL
6596         AND  (
6597                ( G_SET_PROCESS_ID IS NULL )
6598                  OR
6599                ( eivi.set_process_id =  G_SET_PROCESS_ID)
6600             )           ;
6601 
6602    write_debug(l_proc_name, 'updating  NAME=>'||SQL%ROWCOUNT);
6603 
6604 
6605    write_debug(l_proc_name, 'updating  id');
6606 
6607         UPDATE ego_icc_vers_interface eivi
6608         SET    eivi.item_catalog_group_id = ( select icc_kfv.item_catalog_group_id
6609                                                from   mtl_item_catalog_groups_kfv icc_kfv
6610                                                where icc_kfv.concatenated_segments = eivi.item_catalog_name
6611                                              )
6612         WHERE eivi.item_catalog_name = P_ICC_NAME
6613         AND   eivi.item_catalog_group_id IS NULL
6614         AND   eivi.process_status = G_PROCESS_STATUS_INITIAL
6615         AND  (
6616                ( G_SET_PROCESS_ID IS NULL )
6617                  OR
6618                ( eivi.set_process_id =  G_SET_PROCESS_ID)
6619             )
6620         ;
6621         write_debug(l_proc_name, 'updating  id=>'||SQL%ROWCOUNT);
6622 
6623      END update_icc_id_name;
6624 
6625 
6626 
6627 /********************************************************************
6628 ---
6629 ---   This procedure calls the relevant procedures for actual ICC create/update
6630 ---   if creation is successful,
6631 ---
6632 ********************************************************************/
6633 
6634 
6635    PROCEDURE Create_ICC (   p_icc_rec       IN OUT NOCOPY ego_icc_rec_type
6636                               ,x_return_status OUT NOCOPY VARCHAR2
6637                               ,x_return_msg  OUT NOCOPY VARCHAR2
6638                             )
6639    is
6640 
6641      l_proc_name   VARCHAR2(30) := 'Create_ICC';
6642 
6643      l_api_icc_rec   EGO_ITEM_CATALOG_PUB.Catalog_Group_Rec_Type := null;
6644      l_api_icc_tbl   EGO_ITEM_CATALOG_PUB.Catalog_Group_Tbl_Type;
6645      x_api_icc_tbl   EGO_ITEM_CATALOG_PUB.Catalog_Group_Tbl_Type;
6646 
6647      l_grant_guid    fnd_grants.grant_guid%TYPE;
6648 
6649      x_message_list        Error_Handler.Error_Tbl_Type;
6650      l_message_count       NUMBER := 0;
6651      l_error_code          NUMBER := 0;
6652 
6653      e_skip_record         EXCEPTION;
6654      e_stop_processing     EXCEPTION;
6655 
6656      l_entity_code     VARCHAR2(30) := G_ENTITY_ICC_HEADER;
6657      l_token_table     ERROR_HANDLER.Token_Tbl_Type;
6658      l_count           NUMBER;
6659      e_unexpected_error EXCEPTION;
6660 
6661 
6662 
6663    BEGIN
6664      ---
6665      --- Start the savepoint
6666      ---
6667      SAVEPOINT ICC_CREATE_START;
6668 
6669      write_debug(l_proc_name, 'Start ');
6670      x_return_status := G_RET_STS_SUCCESS;
6671 
6672 
6673      IF p_icc_rec.transaction_type = G_TTYPE_CREATE THEN
6674 
6675          Attribute_Defaulting (  p_entity         => G_ENTITY_ICC_HEADER
6676                                , p_icc_rec        => p_icc_rec
6677                                , p_ag_assoc_rec   => g_null_ag_assoc_rec
6678                                , p_func_param_assoc_rec => g_null_func_params_rec
6679                                , p_icc_ver_rec    => g_null_icc_vers_rec
6680                                , x_return_status  => x_return_status
6681                                , x_return_msg     => x_return_msg
6682                               );
6683          IF x_return_status = G_RET_STS_ERROR THEN
6684 
6685             write_debug('Attribute_Defaulting', 'Error Messages :');
6686               ERROR_HANDLER.Add_Error_Message(
6687                    p_message_text                  => x_return_msg
6688                   ,p_application_id                => G_APPL_NAME
6689 
6690                   ,p_row_identifier                => p_icc_rec.transaction_id
6691                   ,p_entity_code                   => l_entity_code
6692                   ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6693                  );
6694              RAISE e_skip_record;
6695          ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6696              RAISE e_skip_record;    --- G_RET_STS_UNEXP_ERROR Handled in caller
6697          END IF;
6698      END IF;
6699 
6700 
6701      IF p_icc_rec.transaction_type = G_TTYPE_UPDATE THEN
6702 
6703          Populate_Null_Cols   (  p_entity         => G_ENTITY_ICC_HEADER
6704                                , p_icc_rec        => p_icc_rec
6705                                , p_ag_assoc_rec   => g_null_ag_assoc_rec
6706                                , p_func_param_assoc_rec => g_null_func_params_rec
6707                                , x_return_status  => x_return_status
6708                                , x_return_msg     => x_return_msg
6709                               );
6710               IF x_return_status = G_RET_STS_ERROR  THEN
6711 
6712                  write_debug('Populate_Null_Cols', 'Error Messages :');
6713                    ERROR_HANDLER.Add_Error_Message(
6714                         p_message_text                  => x_return_msg
6715                        ,p_application_id                => G_APPL_NAME
6716 
6717                        ,p_row_identifier                => p_icc_rec.transaction_id
6718                        ,p_entity_code                   => l_entity_code
6719                        ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6720                       );
6721                   RAISE e_skip_record;
6722              ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6723                   RAISE e_skip_record;    --- G_RET_STS_UNEXP_ERROR Handled in caller
6724               END IF;
6725      END IF;
6726 
6727 
6728      write_debug(l_proc_name, 'Convert Intf rec to API type ');
6729 
6730      Convert_intf_rec_to_API_type (  p_entity   => G_ENTITY_ICC_HEADER
6731                                    , p_icc_rec  => p_icc_rec
6732                                    , x_api_icc_rec => l_api_icc_rec
6733                                   );
6734 
6735      l_api_icc_tbl(1) := l_api_icc_rec;
6736      write_debug(l_proc_name, 'Convert Intf rec to API type end');
6737 
6738      write_debug(l_proc_name, 'Call EGO_ITEM_CATALOG_PUB.Calling Process_Catalog_Groups ');
6739 
6740        --*****************************************************
6741        -- CREATE/UPDATE Base ICC
6742        --*****************************************************
6743        l_entity_code    := G_ENTITY_ICC_HEADER;  -- for error handler
6744 
6745        EGO_ITEM_CATALOG_PUB.Process_Catalog_Groups
6746        (
6747           p_api_version_number      => 1.0
6748         , p_init_msg_list           => FALSE   --- need to be FALSE since this API uses the same error_handler pkg  bug 9767869
6749         , p_catalog_group_tbl       => l_api_icc_tbl
6750         , p_user_id                 => G_USER_ID
6751         , x_catalog_group_tbl       => x_api_icc_tbl
6752         , x_return_status           => x_return_status
6753         , x_msg_count               => l_message_count
6754         , p_debug                   => 'N'
6755         --, p_output_dir              IN  VARCHAR2 := NULL
6756         --, p_debug_filename          IN  VARCHAR2 := 'Ego_Catalog_Grp.log'
6757         , p_bo_identifier           =>'ICC'
6758         --, p_language_code       IN  VARCHAR2 := 'US'
6759       );
6760 
6761       write_debug(l_proc_name, 'End EGO_ITEM_CATALOG_PUB.Calling Process_Catalog_Groups msg count=>'||l_message_count);
6762 
6763       IF x_return_status = G_RET_STS_ERROR THEN
6764 
6765          Error_Handler.GET_MESSAGE_LIST(x_message_list=>x_message_list);
6766          write_debug('EGO_ITEM_CATALOG_PUB.Process_Catalog_Groups', 'Error Messages :');
6767 
6768          FOR i IN 1..l_message_count LOOP
6769            write_debug('EGO_ITEM_CATALOG_PUB.Process_Catalog_Groups', x_message_list(i).message_text);
6770 
6771               ERROR_HANDLER.Add_Error_Message(
6772                 p_message_text                  => x_message_list(i).message_text
6773                ,p_application_id                => G_APPL_NAME
6774                ,p_row_identifier                => p_icc_rec.transaction_id
6775                ,p_entity_code                   => l_entity_code
6776                ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6777                );
6778 
6779          END LOOP;
6780 
6781          RAISE e_skip_record;
6782       ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6783 
6784          Error_Handler.GET_MESSAGE_LIST(x_message_list=>x_message_list);
6785          write_debug('EGO_ITEM_CATALOG_PUB.Process_Catalog_Groups',  'Unexpected error');
6786          FOR i IN 1..l_message_count LOOP
6787            write_debug('EGO_ITEM_CATALOG_PUB.Process_Catalog_Groups', x_message_list(i).message_text);
6788 
6789               ERROR_HANDLER.Add_Error_Message(
6790                 p_message_text                  => x_message_list(i).message_text
6791                ,p_application_id                => G_APPL_NAME
6792                ,p_row_identifier                => p_icc_rec.transaction_id
6793                ,p_entity_code                   => l_entity_code
6794                ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6795                );
6796 
6797          END LOOP;
6798         RAISE e_stop_processing;
6799       END IF;
6800 
6801       Convert_API_type_to_intf_rec (  p_entity   => G_ENTITY_ICC_HEADER
6802                                    , x_icc_rec  => p_icc_rec
6803                                    , p_api_icc_rec => x_api_icc_tbl(1)
6804                                   );
6805 
6806 
6807       ----**************************************************
6808       --- API for creation of the actions for the funciton
6809       --- associations
6810       ----**************************************************
6811       Create_Action_for_Func   ( p_icc_rec => p_icc_rec
6812                                 ,x_return_status => x_return_status
6813                                 ,x_return_msg   => x_return_msg
6814                                  );
6815 
6816       IF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6817         RAISE e_skip_record;    --- G_RET_STS_UNEXP_ERROR Handled in caller
6818       END IF;
6819 
6820        ---**************************************************
6821        --- Update other columns for the ICC header
6822        ---**************************************************
6823        Update_Other_ICC_Hdr_Cols  ( p_icc_rec => p_icc_rec
6824                                   ,x_return_status => x_return_status
6825                                   ,x_return_msg   => x_return_msg
6826                                  );
6827 
6828       IF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6829         RAISE e_skip_record;    --- G_RET_STS_UNEXP_ERROR Handled in caller
6830       END IF;
6831 
6832 
6833        ---
6834        --- Following methods will be called only for CREATE after creation of BASE ICC
6835        ---
6836        IF (p_icc_rec.transaction_type = G_TTYPE_CREATE AND p_icc_rec.item_catalog_group_id IS NOT NULL )
6837         THEN
6838 
6839            IF G_P4TP_PROFILE_ENABLED THEN    --- added if 9791391
6840                ---**************************************************
6841                --- Create draft version for the ICC
6842                ---**************************************************
6843                l_entity_code := G_ENTITY_ICC_VERSION;
6844 
6845                Create_Draft_Version ( p_item_catalog_id => p_icc_rec.item_catalog_group_id
6846                                      ,x_return_status   =>  x_return_status
6847                                      ,x_return_msg      =>  x_return_msg
6848                                     );
6849 
6850                IF x_return_status = G_RET_STS_ERROR THEN
6851                  write_debug('Create_Draft_Version', x_return_msg);
6852 
6853                       ERROR_HANDLER.Add_Error_Message(
6854                         p_message_text                  => x_return_msg
6855                        ,p_application_id                => G_APPL_NAME
6856 
6857                        ,p_row_identifier                => p_icc_rec.transaction_id
6858                        ,p_entity_code                   => l_entity_code
6859                        ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6860                        );
6861 
6862                  RAISE e_skip_record;
6863                ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6864                  RAISE e_skip_record;    --- G_RET_STS_UNEXP_ERROR Handled in caller
6865                END IF;
6866            END IF;
6867 
6868 
6869            ---***************************************************
6870            --- Grant the item catalog user role to the creater
6871            ---***************************************************
6872 
6873 
6874            l_entity_code := G_ENTITY_ICC_HEADER;
6875            EGO_SECURITY_PUB.grant_role_guid(
6876                   p_api_version        => 1.0
6877                 , p_role_name          => 'EGO_CATALOG_GROUP_USER'
6878                 , p_object_name        => 'EGO_CATALOG_GROUP'
6879                 , p_instance_type      => EGO_ITEM_PUB.G_INSTANCE_TYPE_INSTANCE
6880                 , p_instance_set_id    => NULL
6881                 , p_instance_pk1_value => p_icc_rec.item_catalog_group_id
6882                 , p_instance_pk2_value => NULL
6883                 , p_instance_pk3_value => NULL
6884                 , p_instance_pk4_value => NULL
6885                 , p_instance_pk5_value => NULL
6886                 , p_party_id           => G_party_id
6887                 , p_start_date         => NULL
6888                 , p_end_date           => NULL
6889                 , x_return_status      => x_return_status
6890                 , x_errorcode          => l_error_code
6891                 , x_grant_guid         => l_grant_guid
6892                      );
6893                 IF FND_API.TO_BOOLEAN(x_return_status) THEN
6894                   x_return_status := EGO_ITEM_PUB.G_RET_STS_SUCCESS;
6895 
6896                 ELSE
6897 
6898                   x_return_status := EGO_ITEM_PUB.G_RET_STS_ERROR;
6899                   write_debug('EGO_SECURITY_PUB.grant_role_guid', 'Error Messages :');
6900 
6901                   FND_MSG_PUB.count_and_get ( p_count  => l_count
6902                                              ,p_data   => x_return_msg
6903                                            );
6904 
6905                   IF l_count = 1 THEN
6906                       ERROR_HANDLER.Add_Error_Message(
6907                         p_message_text                  => 'EGO_SECURITY_PUB.grant_role_guid'||x_return_msg
6908                        ,p_application_id                => G_APPL_NAME
6909 
6910                        ,p_row_identifier                => p_icc_rec.transaction_id
6911                        ,p_entity_code                   => l_entity_code
6912                        ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6913                        );
6914                   ELSE
6915                     FOR i in 1..l_count LOOP
6916                       ERROR_HANDLER.Add_Error_Message(
6917                         p_message_text                  => 'EGO_SECURITY_PUB.grant_role_guid'||FND_MSG_PUB.get
6918                        ,p_application_id                => G_APPL_NAME
6919 
6920                        ,p_row_identifier                => p_icc_rec.transaction_id
6921                        ,p_entity_code                   => l_entity_code
6922                        ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6923                       );
6924                     END LOOP;
6925                   END IF;
6926                   RAISE e_skip_record;
6927               END IF;
6928 
6929 
6930 
6931            --*****************************************************
6932            -- Associate Base Pages
6933            --*****************************************************
6934            IF p_icc_rec.parent_catalog_group_id IS NULL THEN
6935                EGO_UPLOAD_PUB.createBaseAttributePages (p_catalog_group_id => p_icc_rec.item_catalog_group_id
6936                                                            ,x_return_status    => x_return_status
6937                                                            );
6938                   IF x_return_status = G_RET_STS_ERROR THEN
6939 
6940                      write_debug('EGO_UPLOAD_PUB.createBaseAttributePages', 'Error Messages :');
6941                       FND_MSG_PUB.count_and_get ( p_count  => l_count
6942                                                  ,p_data   => x_return_msg
6943                                                );
6944                      IF l_count = 1 THEN
6945                           ERROR_HANDLER.Add_Error_Message(
6946                             p_message_text                  => 'EGO_SECURITY_PUB.grant_role_guid'||x_return_msg
6947                            ,p_application_id                => G_APPL_NAME
6948 
6949                            ,p_row_identifier                => p_icc_rec.transaction_id
6950                            ,p_entity_code                   => l_entity_code
6951                            ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6952                            );
6953                      ELSE
6954                         FOR i in 1..l_count LOOP
6955                           ERROR_HANDLER.Add_Error_Message(
6956                             p_message_text                  => 'EGO_SECURITY_PUB.grant_role_guid'||FND_MSG_PUB.get
6957                            ,p_application_id                => G_APPL_NAME
6958 
6959                            ,p_row_identifier                => p_icc_rec.transaction_id
6960                            ,p_entity_code                   => l_entity_code
6961                            ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
6962                           );
6963                         END LOOP;
6964                       END IF;
6965 
6966                       RAISE e_skip_record;
6967                  ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6968                    RAISE e_stop_processing;
6969                  END IF;
6970            END IF;
6971 
6972        ELSIF p_icc_rec.transaction_type = G_TTYPE_UPDATE THEN
6973          NULL;
6974        END IF;
6975 
6976        --- For both CREATE as well as UPDATE transaction
6977        --- call the versions API to process the respective ICC versions
6978        ---
6979        ERROR_HANDLER.Set_Bo_Identifier(G_BO_IDENTIFIER_ICC);
6980 
6981        WRITE_DEBUG(l_proc_name, 'calling versions in create icc, id , name=>'||p_icc_rec.item_catalog_group_id||','||p_icc_rec.item_catalog_name);
6982 
6983        --- required by versions, when versions are processed per ICC
6984        UPDATE_ICC_ID_NAME ( p_icc_id => p_icc_rec.item_catalog_group_id, p_icc_name => p_icc_rec.item_catalog_name);
6985 
6986        ---
6987        --- added param p_icc_trans_type bug 12695479, when transaction type = UPDATE
6988        --- locks have to be honoured
6989        ---
6990        Construct_Colltn_And_Validate ( p_entity         => G_ENTITY_ICC_VERSION
6991                                    ,   p_icc_name       => p_icc_rec.item_catalog_name
6992                                    ,   p_icc_id         => p_icc_rec.item_catalog_group_id
6993                                    ,   p_icc_trans_type => p_icc_rec.transaction_type
6994                                    ,   x_return_status  => x_return_status
6995                                    ,   x_return_msg     => x_return_msg
6996                                    );
6997        IF x_return_status = G_RET_STS_UNEXP_ERROR THEN
6998           RAISE e_unexpected_error;
6999        END IF;
7000 
7001      write_debug(l_proc_name, 'End');
7002 
7003    EXCEPTION
7004    WHEN e_skip_record THEN
7005       ---
7006       --- Proceed with the next record
7007       ---
7008       ROLLBACK TO ICC_CREATE_START;
7009       RETURN;
7010    WHEN e_unexpected_error THEN
7011       x_return_status := G_RET_STS_UNEXP_ERROR;
7012       x_return_msg := x_return_msg||'->Unexpected error in '||G_PKG_NAME||'.'||l_proc_name;
7013    WHEN OTHERS THEN
7014       x_return_status := G_RET_STS_UNEXP_ERROR;
7015       x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
7016    END   Create_ICC;
7017 
7018 
7019 --********************************************************************
7020 ----
7021 ---- This procedure resolves the transaction type and calls the relevant
7022 ---- CREATE/UPDATE APIs
7023 --********************************************************************
7024 
7025 
7026 PROCEDURE Call_ICC_APIS (   p_icc_rec       IN OUT NOCOPY ego_icc_rec_type
7027                            ,x_return_status OUT NOCOPY VARCHAR2
7028                            ,x_return_msg  OUT NOCOPY VARCHAR2
7029                        )
7030 IS
7031      l_proc_name   VARCHAR2(30) := 'Call_ICC_APIS';
7032 
7033      e_skip_record      EXCEPTION;
7034      e_unexpected_error EXCEPTION;
7035 
7036 
7037 BEGIN
7038   write_debug(l_proc_name, 'Start ');
7039   x_return_status := G_RET_STS_SUCCESS;
7040 
7041     Create_ICC (   p_icc_rec => p_icc_rec
7042                   ,x_return_status => x_return_status
7043                   ,x_return_msg    => x_return_msg
7044                );
7045     IF  x_return_status = G_RET_STS_ERROR THEN
7046       RAISE e_skip_record;
7047     ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
7048       RAISE e_unexpected_error;  --- G_RET_STS_UNEXP_ERROR Handled in caller
7049     END IF;
7050 
7051 
7052 
7053 
7054   write_debug(l_proc_name, 'End ');
7055 EXCEPTION
7056 WHEN e_skip_record THEN
7057   RETURN;
7058 WHEN e_unexpected_error THEN
7059   x_return_status := G_RET_STS_UNEXP_ERROR;
7060   x_return_msg := x_return_msg||'->'||'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
7061   RETURN;
7062 WHEN OTHERS THEN
7063   x_return_status := G_RET_STS_UNEXP_ERROR;
7064   x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
7065 END Call_ICC_APIS;
7066 
7067 
7068 /********************************************************************
7069 ---
7070 --- APIs for create/update/delete of AG ASSOCIATIONS
7071 ---
7072 ********************************************************************/
7073 
7074 PROCEDURE CALL_AG_ASSOC_API  ( p_ag_assoc_rec  IN OUT nocopy ego_ag_assoc_rec_type
7075                                 ,x_return_status OUT NOCOPY VARCHAR2
7076                                 ,x_return_msg  OUT NOCOPY VARCHAR2
7077                                )
7078 IS
7079   l_proc_name   VARCHAR2(30) :=  'CALL_AG_ASSOC_API';
7080   l_entity_code     VARCHAR2(30) := G_ENTITY_ICC_AG_ASSOC;
7081   l_object_id   fnd_objects.object_id%TYPE;
7082   l_association_id  ego_obj_ag_assocs_b.association_id%TYPE;
7083 
7084   l_msg_count           NUMBER := 0;
7085   l_error_code          NUMBER := 0;
7086 
7087   e_skip_record         EXCEPTION;
7088   e_unexpected_error    EXCEPTION;
7089 
7090   l_token_table     ERROR_HANDLER.Token_Tbl_Type;
7091   l_msg_data        VARCHAR2(4000);
7092 
7093 
7094 BEGIN
7095    write_debug(l_proc_name, 'Start');
7096   x_return_status := G_RET_STS_SUCCESS;
7097 
7098   IF p_ag_assoc_rec.transaction_type = G_TTYPE_CREATE THEN
7099 
7100     FOR rec_obj_id IN cur_get_obj_id loop
7101       l_object_id := rec_obj_id.object_id;
7102     end loop;
7103 
7104 
7105     EGO_EXT_FWK_PUB.Create_Association (
7106         p_api_version             => 1.0
7107        ,p_association_id          => NULL
7108        ,p_object_id               => l_object_id
7109        ,p_classification_code     => TO_CHAR(p_ag_assoc_rec.item_catalog_group_id)
7110        ,p_data_level              => NULL
7111        ,p_attr_group_id           => p_ag_assoc_rec.attr_group_id
7112        ,p_enabled_flag            => 'Y'
7113        ,p_view_privilege_id       => NULL    --ignored for now
7114        ,p_edit_privilege_id       => NULL    --ignored for now
7115        ,p_init_msg_list           => fnd_api.g_FALSE
7116        ,p_commit                  => fnd_api.g_FALSE
7117        ,x_association_id          => l_association_id
7118        ,x_return_status           => x_return_status
7119        ,x_errorcode               => l_error_code
7120        ,x_msg_count               => l_msg_count
7121        ,x_msg_data                => l_msg_data
7122     );
7123         IF x_return_status = G_RET_STS_ERROR THEN
7124 
7125            write_debug('EGO_EXT_FWK_PUB.Create_Association', l_msg_data);
7126 
7127            FND_MSG_PUB.count_and_get ( p_count  => l_msg_count
7128                                       ,p_data   => l_msg_data
7129                                     );
7130 
7131            IF l_msg_count = 1 THEN
7132                ERROR_HANDLER.Add_Error_Message(
7133                  p_message_text                  => 'EGO_EXT_FWK_PUB.Create_Association'||x_return_msg
7134                 ,p_application_id                => G_APPL_NAME
7135 
7136                 ,p_row_identifier                => p_ag_assoc_rec.transaction_id
7137                 ,p_entity_code                   => l_entity_code
7138                 ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
7139                 );
7140            ELSE
7141              FOR i in 1..l_msg_count LOOP
7142                ERROR_HANDLER.Add_Error_Message(
7143                  p_message_text                  => 'EGO_EXT_FWK_PUB.Create_Association'||FND_MSG_PUB.get
7144                 ,p_application_id                => G_APPL_NAME
7145 
7146                 ,p_row_identifier                => p_ag_assoc_rec.transaction_id
7147                 ,p_entity_code                   => l_entity_code
7148                 ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
7149                );
7150              END LOOP;
7151 
7152            END IF;
7153         ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
7154           RAISE e_unexpected_error;
7155         END IF;
7156     END IF;
7157 
7158 
7159   IF p_ag_assoc_rec.transaction_type = G_TTYPE_DELETE THEN
7160 
7161     EGO_EXT_FWK_PUB.Delete_Association (
7162                           p_api_version     => 1.0
7163                          ,p_association_id  => p_ag_assoc_rec.association_id
7164                          ,p_init_msg_list   => fnd_api.g_FALSE
7165                          ,p_commit          => fnd_api.g_FALSE
7166                          ,p_force           => fnd_api.g_FALSE
7167                          ,x_return_status   => x_return_status
7168                          ,x_errorcode       => l_error_code
7169                          ,x_msg_count       => l_msg_count
7170                          ,x_msg_data        => l_msg_data
7171                                        );
7172 
7173     IF x_return_status = G_RET_STS_ERROR THEN
7174 
7175        x_return_status := EGO_ITEM_PUB.G_RET_STS_ERROR;
7176        write_debug('EGO_EXT_FWK_PUB.Delete_Association', l_msg_data);
7177 
7178        FND_MSG_PUB.count_and_get ( p_count  => l_msg_count
7179                                   ,p_data   => l_msg_data
7180                                 );
7181 
7182        IF l_msg_count = 1 THEN
7183            ERROR_HANDLER.Add_Error_Message(
7184              p_message_text                  => 'EGO_EXT_FWK_PUB.Delete_Association'||x_return_msg
7185             ,p_application_id                => G_APPL_NAME
7186 
7187             ,p_row_identifier                => p_ag_assoc_rec.transaction_id
7188             ,p_entity_code                   => l_entity_code
7189             ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
7190             );
7191        ELSE
7192          FOR i in 1..l_msg_count LOOP
7193            ERROR_HANDLER.Add_Error_Message(
7194              p_message_text                  => 'EGO_EXT_FWK_PUB.Delete_Association'||FND_MSG_PUB.get
7195             ,p_application_id                => G_APPL_NAME
7196 
7197             ,p_row_identifier                => p_ag_assoc_rec.transaction_id
7198             ,p_entity_code                   => l_entity_code
7199             ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
7200            );
7201          END LOOP;
7202        END IF;
7203     ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
7204       RAISE e_unexpected_error;
7205     END IF;
7206   END IF;
7207 
7208   IF p_ag_assoc_rec.transaction_type = G_TTYPE_UPDATE THEN
7209     --- nothing to update as only enabled flag, view privilege id , edit privilege id can be updated
7210     --- enabled flag is not available through UI, privilege ids are not used as of now
7211     null;
7212 
7213   END IF;
7214 
7215 
7216  write_debug(l_proc_name, 'End');
7217 EXCEPTION
7218 WHEN e_unexpected_error THEN
7219   write_debug(l_proc_name, x_return_msg);
7220   x_return_status := G_RET_STS_UNEXP_ERROR;
7221   x_return_msg := x_return_msg||'Stop process error occured in '||G_PKG_NAME||'.'||l_proc_name;
7222   write_debug(l_proc_name, x_return_msg);
7223 WHEN OTHERS THEN
7224    x_return_status := G_RET_STS_UNEXP_ERROR;
7225    x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
7226 END CALL_AG_ASSOC_API;
7227 
7228 
7229 
7230 PROCEDURE Call_func_param_assoc_api(  p_func_param_assoc_rec  IN ego_func_param_map_rec_type
7231                                       ,x_return_status   OUT NOCOPY VARCHAR2
7232                                       ,x_return_msg  OUT NOCOPY VARCHAR2
7233                                       )
7234 IS
7235   l_proc_name   VARCHAR2(30) := 'Call_func_param_assoc_api';
7236   l_application_id NUMBER    := NULL;
7237   l_entity_code    VARCHAR2(30) := G_ENTITY_ICC_FN_PARAM_MAP;
7238   l_action_id      ego_actions_b.action_id%TYPE := null;
7239   l_object_id      fnd_objects.object_id%TYPE := null;
7240 
7241 
7242   l_msg_count           NUMBER := 0;
7243   l_error_code          NUMBER := 0;
7244   l_msg_data            VARCHAR2(4000);
7245   l_mapped_obj_type     EGO_MAPPINGS_B.MAPPED_OBJ_TYPE%TYPE := 'A';
7246 
7247   e_skip_record         EXCEPTION;
7248   e_unexpected_error    EXCEPTION;
7249 
7250   l_token_table     ERROR_HANDLER.Token_Tbl_Type;
7251 
7252   CURSOR cur_func_param_count ( p_function_id number)
7253   IS
7254   SELECT COUNT(1) count
7255   from   ego_func_params_b
7256   where function_id = p_function_id;
7257 
7258 
7259 
7260 BEGIN
7261   write_debug(l_proc_name, 'Start');
7262 
7263    --
7264    -- Bug 9953881. Function mappings are not happening correctly
7265    -- Modified the method below to
7266    --  a. Get action id from ICC num or desc generate action col-
7267    --     umns. The value would have been updated correctly before
7268    --     the code flows here.
7269    --  sreharih. Fri Apr 15 16:53:09 PDT 2011
7270    --
7271 
7272   l_object_id := get_object_id;
7273 
7274   l_action_id := get_action_id (p_item_catalog_group_id =>  p_func_param_assoc_rec.item_catalog_group_id,
7275                                 p_function_id           =>  p_func_param_assoc_rec.function_id,
7276                                 p_object_id             =>  l_object_id);
7277 
7278 
7279   write_debug(l_proc_name, 'Action id ' || l_action_id);
7280 
7281 
7282   IF p_func_param_assoc_rec.transaction_type = G_TTYPE_CREATE THEN
7283 
7284       EGO_EXT_FWK_PUB.Create_Mapping (
7285           p_api_version            => 1.0
7286          ,p_function_id            => p_func_param_assoc_rec.function_id
7287          ,p_mapped_obj_type        => l_mapped_obj_type
7288          ,p_mapped_obj_pk1_value   => l_action_id
7289          ,p_func_param_id          => p_func_param_assoc_rec.parameter_id
7290          ,p_attr_group_id          => p_func_param_assoc_rec.attr_group_id
7291          ,p_mapping_value          => p_func_param_assoc_rec.ATTr_name
7292          ,p_mapped_uom_parameter   => p_func_param_assoc_rec.mapped_uom_parameter
7293          ,p_value_uom_source       => p_func_param_assoc_rec.uom_param_value_type
7294          ,p_fixed_uom              => p_func_param_assoc_rec.fixed_uom_value
7295          ,p_init_msg_list          => fnd_api.g_FALSE
7296          ,p_commit                 => fnd_api.g_FALSE
7297          ,x_return_status          => X_RETURN_STATUS
7298          ,x_errorcode              => l_error_code
7299          ,x_msg_count              => l_msg_count
7300          ,x_msg_data               => l_msg_data
7301                       );
7302         IF x_return_status = G_RET_STS_ERROR THEN
7303 
7304            write_debug('EGO_EXT_FWK_PUB.Create_Mapping', l_msg_data);
7305 
7306            FND_MSG_PUB.count_and_get ( p_count  => l_msg_count
7307                                       ,p_data   => l_msg_data
7308                                     );
7309 
7310            IF l_msg_count = 1 THEN
7311                ERROR_HANDLER.Add_Error_Message(
7312                  p_message_text                  => 'EGO_EXT_FWK_PUB.Create_Mapping'||x_return_msg
7313                 ,p_application_id                => G_APPL_NAME
7314 
7315                 ,p_row_identifier                => p_func_param_assoc_rec.transaction_id
7316                 ,p_entity_code                   => l_entity_code
7317                 ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
7318                 );
7319            ELSE
7320              FOR i in 1..l_msg_count LOOP
7321                ERROR_HANDLER.Add_Error_Message(
7322                  p_message_text                  => 'EGO_EXT_FWK_PUB.Create_Mapping'||FND_MSG_PUB.get
7323                 ,p_application_id                => G_APPL_NAME
7324 
7325                 ,p_row_identifier                => p_func_param_assoc_rec.transaction_id
7326                 ,p_entity_code                   => l_entity_code
7327                 ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
7328                );
7329              END LOOP;
7330            END IF;
7331         ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
7332           x_return_msg := l_msg_data;
7333           RAISE e_unexpected_error;
7334         END IF;
7335 
7336   ELSIF p_func_param_assoc_rec.transaction_type = G_TTYPE_UPDATE THEN
7337 
7338         EGO_EXT_FWK_PUB.Update_Mapping (
7339         p_api_version              => 1.0
7340        ,p_function_id              => p_func_param_assoc_rec.function_id
7341        ,p_mapped_obj_type          => l_mapped_obj_type
7342        ,p_mapped_obj_pk1_value     => l_action_id
7343        ,p_func_param_id            => p_func_param_assoc_rec.parameter_id
7344        ,p_attr_group_id            => p_func_param_assoc_rec.attr_group_id
7345        ,p_mapping_value            => p_func_param_assoc_rec.attr_name
7346        ,p_new_func_param_id        => p_func_param_assoc_rec.parameter_id
7347        ,p_new_mapping_value        => p_func_param_assoc_rec.attr_name
7348        ,p_mapped_uom_parameter     => p_func_param_assoc_rec.mapped_uom_parameter
7349        ,p_value_uom_source         => p_func_param_assoc_rec.uom_param_value_type
7350        ,p_fixed_uom                => p_func_param_assoc_rec.fixed_uom_value
7351        ,p_init_msg_list            => fnd_api.g_false
7352        ,p_commit                   => fnd_api.g_FALSE
7353        ,x_return_status            => X_RETURN_STATUS
7354        ,x_errorcode                => l_error_code
7355        ,x_msg_count                => l_msg_count
7356        ,x_msg_data                 => l_msg_data
7357                           );
7358 
7359         IF x_return_status = G_RET_STS_ERROR THEN
7360            write_debug('EGO_EXT_FWK_PUB.Create_Mapping', l_msg_data);
7361 
7362            FND_MSG_PUB.count_and_get ( p_count  => l_msg_count
7363                                       ,p_data   => l_msg_data
7364                                     );
7365 
7366            IF l_msg_count = 1 THEN
7367                ERROR_HANDLER.Add_Error_Message(
7368                  p_message_text                  => 'EGO_EXT_FWK_PUB.Create_Mapping'||x_return_msg
7369                 ,p_application_id                => G_APPL_NAME
7370 
7371                 ,p_row_identifier                => p_func_param_assoc_rec.transaction_id
7372                 ,p_entity_code                   => l_entity_code
7373                 ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
7374                 );
7375            ELSE
7376              FOR i in 1..l_msg_count LOOP
7377                ERROR_HANDLER.Add_Error_Message(
7378                  p_message_text                  => 'EGO_EXT_FWK_PUB.Create_Mapping'||FND_MSG_PUB.get
7379                 ,p_application_id                => G_APPL_NAME
7380 
7381                 ,p_row_identifier                => p_func_param_assoc_rec.transaction_id
7382                 ,p_entity_code                   => l_entity_code
7383                 ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
7384                );
7385              END LOOP;
7386            END IF;
7387         ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
7388           x_return_msg := l_msg_data;
7389           RAISE e_unexpected_error;
7390         END IF;
7391 
7392 
7393 
7394   ELSIF p_func_param_assoc_rec.transaction_type = G_TTYPE_DELETE THEN
7395        EGO_EXT_FWK_PUB.Delete_Func_Param_Mapping (
7396         p_api_version              => 1.0
7397        ,p_function_id              => p_func_param_assoc_rec.function_id
7398        ,p_mapped_obj_type          => l_mapped_obj_type
7399        ,p_mapped_obj_pk1_value     => l_action_id
7400        ,p_func_param_id            => p_func_param_assoc_rec.parameter_id
7401        ,p_init_msg_list            => fnd_api.g_false
7402        ,p_commit                   => fnd_api.g_FALSE
7403        ,x_return_status            => X_RETURN_STATUS
7404        ,x_errorcode                => l_error_code
7405        ,x_msg_count                => l_msg_count
7406        ,x_msg_data                 => l_msg_data
7407         );
7408 
7409         IF x_return_status = G_RET_STS_ERROR THEN
7410 
7411            write_debug('EGO_EXT_FWK_PUB.Create_Mapping', l_msg_data);
7412 
7413            FND_MSG_PUB.count_and_get ( p_count  => l_msg_count
7414                                       ,p_data   => l_msg_data
7415                                     );
7416 
7417            IF l_msg_count = 1 THEN
7418                ERROR_HANDLER.Add_Error_Message(
7419                  p_message_text                  => 'EGO_EXT_FWK_PUB.Create_Mapping'||x_return_msg
7420                 ,p_application_id                => G_APPL_NAME
7421 
7422                 ,p_row_identifier                => p_func_param_assoc_rec.transaction_id
7423                 ,p_entity_code                   => l_entity_code
7424                 ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
7425                 );
7426            ELSE
7427              FOR i in 1..l_msg_count LOOP
7428                ERROR_HANDLER.Add_Error_Message(
7429                  p_message_text                  => 'EGO_EXT_FWK_PUB.Create_Mapping'||FND_MSG_PUB.get
7430                 ,p_application_id                => G_APPL_NAME
7431 
7432                 ,p_row_identifier                => p_func_param_assoc_rec.transaction_id
7433                 ,p_entity_code                   => l_entity_code
7434                 ,p_table_name                    => G_ENTITY_ICC_HEADER_TAB
7435                );
7436              END LOOP;
7437            END IF;
7438         ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
7439           x_return_msg := l_msg_data;
7440           RAISE e_unexpected_error;
7441         END IF;
7442 
7443   END IF;
7444 
7445   write_debug(l_proc_name, 'End');
7446 EXCEPTION
7447 WHEN e_unexpected_error THEN
7448   write_debug(l_proc_name, x_return_msg);
7449   x_return_status := G_RET_STS_UNEXP_ERROR;
7450   x_return_msg := x_return_msg||'Stop process error occured in '||G_PKG_NAME||'.'||l_proc_name;
7451   write_debug(l_proc_name, x_return_msg);
7452 WHEN OTHERS THEN
7453   x_return_status := G_RET_STS_UNEXP_ERROR;
7454   x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
7455 END Call_func_param_assoc_api;
7456 
7457 
7458 /********************************************************************
7459 ---
7460 ---   This procedure syncs the draft version with the latest released
7461 ---   version of the ICC, added method bug 9791391
7462 ---
7463 ********************************************************************/
7464 PROCEDURE Sync_Draft_Version (
7465            p_icc_vers_rec     IN OUT NOCOPY ego_icc_vers_rec_type,
7466            x_return_status    OUT NOCOPY VARCHAR2,
7467            x_return_msg       OUT NOCOPY VARCHAR2)
7468 IS
7469 
7470   l_proc_name        CONSTANT VARCHAR2(30) := 'Sync_Draft_Version';
7471   l_msg_count        NUMBER := 0;
7472   l_msg_data         VARCHAR2(4000);
7473   l_entity_code      VARCHAR2(30) := G_ENTITY_ICC_VERSION;
7474   l_locking_party_id ego_object_lock.locking_party_id%TYPE;
7475   l_lock_flag        ego_object_lock.lock_flag%TYPE;
7476   e_stop_processing  EXCEPTION;
7477   l_return_status    VARCHAR2(1);
7478   l_return_msg       VARCHAR2(2000);
7479 
7480 BEGIN
7481   x_return_status := G_RET_STS_SUCCESS;
7482   write_debug(l_proc_name, 'Start');
7483 
7484   IF p_icc_vers_rec.process_status = G_PROCESS_STATUS_INITIAL THEN   -- only if the version record does not have an error
7485       ---
7486       --- This method will sync the draft with the released version ver_seq_id
7487       ---
7488       EGO_TRANSACTION_ATTRS_PVT.Revert_Transaction_Attribute (
7489                                p_source_icc_id   => p_icc_vers_rec.item_catalog_group_id
7490                                ,p_source_ver_no   => p_icc_vers_rec.ver_seq_id
7491                                ,p_init_msg_list   => FALSE
7492                                ,x_return_status   => x_return_status
7493                                ,x_msg_count       => l_msg_count
7494                                ,x_msg_data        => l_msg_data
7495                                );
7496 
7497         IF x_return_status <> G_RET_STS_SUCCESS THEN
7498             FND_MSG_PUB.RESET;  --- resets the message index pointer to top of table, since count_and_get is called in above api
7499 
7500             FOR i in 1..l_msg_count LOOP
7501               ERROR_HANDLER.Add_Error_Message(
7502                 p_message_text                  => FND_MSG_PUB.GET ( p_encoded => FND_API.G_FALSE)
7503                ,p_application_id                => G_APPL_NAME
7504                ,p_message_type                  => G_TYPE_ERROR
7505                ,p_row_identifier                => p_icc_vers_rec.transaction_id
7506                ,p_entity_code                   => l_entity_code
7507                ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
7508               );
7509             END LOOP;
7510         END IF;
7511 
7512 
7513         --- once the draft is synced , update the lock flag, this call is repeated during validatio
7514         --- need to redesign
7515 
7516         --- first get the lock info
7517         ---
7518         EGO_METADATA_BULKLOAD_PVT.Get_Lock_Info (   p_object_name  => G_ENTITY_ICC_LOCK
7519                                                    ,p_pk1_value    => p_icc_vers_rec.item_catalog_group_id
7520                                                    ,x_locking_party_id  => l_locking_party_id
7521                                                    ,x_lock_flag         => l_lock_flag
7522                                                    ,x_return_msg        => x_return_msg
7523                                                    ,x_return_status     => x_return_status
7524                                                );
7525         IF  x_return_status  = G_RET_STS_SUCCESS THEN
7526           --- update the lock record
7527           ---
7528           IF l_lock_flag = 'L' THEN
7529 
7530                 --- Unlock the record
7531                 ---
7532                 EGO_METADATA_BULKLOAD_PVT.Lock_Unlock_Object  ( p_object_name => G_ENTITY_ICC_LOCK
7533                                    ,p_pk1_value     => p_icc_vers_rec.item_catalog_group_id
7534                                    ,p_lock_flag     => FALSE
7535                                    ,x_return_msg    => l_return_msg
7536                                    ,x_return_status => l_return_status
7537                               );
7538                 IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
7539                     x_return_msg := l_return_msg;
7540                     RAISE e_stop_processing;
7541                 END IF;
7542 
7543 
7544           ELSIF l_lock_flag = 'U' THEN
7545                 --- IF Unlocked, then insert a new unlocked record ( simulating lock and unlock behaviour)
7546                 ---
7547                 EGO_METADATA_BULKLOAD_PVT.Lock_Unlock_Object  ( p_object_name      => G_ENTITY_ICC_LOCK
7548                                                                ,p_pk1_value        => p_icc_vers_rec.item_catalog_group_id
7549                                                                ,p_lock_flag        => TRUE
7550                                                                ,p_Party_id          => G_PARTY_ID
7551                                                                ,x_return_msg       => l_return_msg
7552                                                                ,x_return_status    => l_return_status
7553                                                              );
7554                 IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
7555                     x_return_msg := l_return_msg;
7556                     RAISE e_stop_processing;
7557                 END IF;
7558 
7559           END IF;
7560 
7561 
7562         ELSIF x_return_status  = G_RET_STS_ERROR THEN
7563           ERROR_HANDLER.Add_Error_Message(
7564                 p_message_text                  => x_return_msg
7565                ,p_application_id                => G_APPL_NAME
7566                ,p_row_identifier                => p_icc_vers_rec.transaction_id
7567                ,p_entity_code                   => l_entity_code
7568                ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
7569                );
7570 
7571         ELSIF  x_return_status  = G_RET_STS_UNEXP_ERROR THEN
7572           RAISE e_stop_processing;
7573 
7574         END IF;
7575 
7576 
7577 
7578 
7579 
7580   END IF;
7581 
7582   write_debug(l_proc_name, 'End');
7583 EXCEPTION
7584 WHEN e_stop_processing THEN
7585   x_return_status  := G_RET_STS_UNEXP_ERROR ;
7586   x_return_msg := 'Stop processing error in '||G_PKG_NAME||'.'||l_proc_name||'->'||x_return_msg;
7587 WHEN OTHERS THEN
7588   x_return_status := G_RET_STS_UNEXP_ERROR;
7589   x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
7590 END;
7591 
7592     --
7593     -- Bug 12394675. Issue # 2. New version should be created only if
7594     -- there are changes in TAs. Added below methods to
7595     -- to check whether TA set is same or not.
7596     -- sreharih. Mon Apr 25 16:27:38 PDT 2011
7597     --
7598 
7599 
7600     --
7601     -- Get Latest Version.
7602     --
7603 FUNCTION get_latest_version(p_item_catalog_group_id IN NUMBER) RETURN NUMBER IS
7604 
7605      l_ret ego_mtl_catalog_grp_vers_b.version_seq_id%TYPE;
7606 
7607      CURSOR c IS
7608       SELECT version_seq_id
7609         FROM (
7610                SELECT version_seq_id
7611                  FROM ego_mtl_catalog_grp_vers_b ver
7612                 WHERE ver.item_catalog_group_id = p_item_catalog_group_id
7613             ORDER BY ver.version_seq_id DESC
7614              )
7615       WHERE ROWNUM = 1;
7616 
7617 BEGIN
7618 
7619       OPEN c;
7620       FETCH c INTO l_ret;
7621       CLOSE c;
7622 
7623       RETURN l_ret;
7624 
7625 END get_latest_version;
7626 
7627     --
7628     -- Get all TA records for given ICC version.
7629     --
7630 FUNCTION get_ta_records (p_item_catalog_group_id IN NUMBER,
7631                          p_version_seq_id        IN NUMBER
7632                          ) RETURN t_ta_records IS
7633 
7634     l_ret t_ta_records;
7635      CURSOR c IS
7636       SELECT *
7637         FROM ego_trans_attr_vers_b ta
7638        WHERE ta.item_catalog_group_id = p_item_catalog_group_id
7639          AND ta.icc_version_number    = p_version_seq_id
7640          AND ta.metadata_level        = 'ICC'
7641        ORDER BY ta.sequence;
7642 
7643 BEGIN
7644 
7645        OPEN c;
7646        FETCH c BULK COLLECT INTO l_ret;
7647        CLOSE c;
7648 
7649        RETURN l_ret;
7650 
7651 END get_ta_records;
7652 
7653     --
7654     -- Get all TA interface records for given ICC version and run.
7655     --
7656 FUNCTION get_ta_interface_records (
7657                              p_item_catalog_group_id IN NUMBER,
7658                              p_version_seq_id        IN NUMBER,
7659                              p_set_process_id        IN NUMBER
7660                              ) RETURN t_ta_intf_records IS
7661 
7662     l_ret t_ta_intf_records;
7663 
7664      CURSOR c IS
7665       SELECT *
7666         FROM ego_trans_attrs_vers_intf ta_int
7667        WHERE ta_int.item_catalog_group_id = p_item_catalog_group_id
7668          AND ta_int.icc_version_number    = p_version_seq_id
7669          AND ((ta_int.set_process_id IS NULL AND p_set_process_id IS NULL) OR
7670               (ta_int.set_process_id = p_set_process_id))
7671          AND ta_int.process_status = G_PROCESS_STATUS_INITIAL
7672          AND ta_int.metadata_level = 'ICC'
7673        ORDER BY ta_int.sequence;
7674 
7675 BEGIN
7676 
7677        OPEN c;
7678        FETCH c BULK COLLECT INTO l_ret;
7679        CLOSE c;
7680 
7681        RETURN l_ret;
7682 
7683 END get_ta_interface_records;
7684 
7685     --
7686     -- Get attribute internal name
7687     --
7688 FUNCTION get_attr_internal_name (p_item_catalog_group_id IN NUMBER,
7689                                  p_version_seq_id        IN NUMBER,
7690                                  p_attr_id               IN NUMBER,
7691                                  p_association_id        IN NUMBER) RETURN VARCHAR2 IS
7692 
7693     l_ret        fnd_descr_flex_column_usages.end_user_column_name%TYPE;
7694     l_proc_name  CONSTANT VARCHAR2(30) := 'get_attr_internal_name';
7695     CURSOR c IS
7696      SELECT flex_col.end_user_column_name
7697        FROM ego_trans_attr_vers_b ta,
7698             ego_fnd_df_col_usgs_ext attr ,
7699             fnd_descr_flex_column_usages flex_col
7700       WHERE 1=1
7701         AND ta.item_catalog_group_id = p_item_catalog_group_id
7702         AND ta.icc_version_number    = p_version_seq_id
7703         AND ta.attr_id               = p_attr_id
7704         AND ta.association_id        = p_association_id
7705         AND ta.metadata_level        = 'ICC'
7706         AND ta.attr_id               = attr.attr_id
7707         AND attr.descriptive_flex_context_code  = flex_col.descriptive_flex_context_code
7708         AND attr.descriptive_flexfield_name     = flex_col.descriptive_flexfield_name
7709         AND attr.application_column_name        = flex_col.application_column_name
7710         AND flex_col.descriptive_flexfield_name = 'EGO_ITEM_TRANS_ATTR_GROUP';
7711 
7712 BEGIN
7713     write_debug(l_proc_name,'Entering method with params ' ||
7714                              ' p_item_catalog_group_id = ' || p_item_catalog_group_id ||
7715                                     ' p_version_seq_id = ' || p_version_seq_id  ||
7716                                            ' p_attr_id = ' || p_attr_id ||
7717                                     ' p_association_id = ' || p_association_id);
7718 
7719      OPEN c;
7720      FETCH c INTO l_ret;
7721      CLOSE c;
7722 
7723      write_debug(l_proc_name,'Returning ' || l_ret);
7724      RETURN l_ret;
7725 
7726 END get_attr_internal_name;
7727 
7728     --
7729     -- Check whether TA record matches to TA interface records
7730     --
7731 FUNCTION matches (p_ta_record      IN ego_trans_attr_vers_b%ROWTYPE,
7732                   p_ta_intf_record IN ego_trans_attrs_vers_intf%ROWTYPE )  RETURN BOOLEAN IS
7733 
7734 BEGIN
7735       IF p_ta_record.item_catalog_group_id             = p_ta_intf_record.item_catalog_group_id             AND
7736          p_ta_record.sequence                          = p_ta_intf_record.sequence                          AND
7737          p_ta_record.attr_display_name                 = p_ta_intf_record.attr_display_name                 AND
7738          nvl(p_ta_record.value_set_id,G_MISS_NUM)      = nvl(p_ta_intf_record.value_set_id,G_MISS_NUM)      AND
7739          nvl(p_ta_record.uom_class,G_MISS_CHAR)        = nvl(p_ta_intf_record.uom_class,G_MISS_CHAR)        AND
7740          nvl(p_ta_record.default_value,G_MISS_CHAR)    = nvl(p_ta_intf_record.default_value,G_MISS_CHAR)    AND
7741          nvl(p_ta_record.rejected_value,G_MISS_CHAR)   = nvl(p_ta_intf_record.rejected_value,G_MISS_CHAR)   AND
7742          nvl(p_ta_record.required_flag,'N')            = nvl(p_ta_intf_record.required_flag,'N')            AND
7743          nvl(p_ta_record.readonly_flag,'N')            = nvl(p_ta_intf_record.readonly_flag,'N')            AND
7744          nvl(p_ta_record.hidden_flag,'N')              = nvl(p_ta_intf_record.hidden_flag,'N')              AND
7745          nvl(p_ta_record.searchable_flag,'N')          = nvl(p_ta_intf_record.searchable_flag,'N')          AND
7746          nvl(p_ta_record.check_eligibility,'N')        = nvl(p_ta_intf_record.check_eligibility,'N')        AND
7747          nvl(p_ta_record.inventory_item_id,G_MISS_NUM) = nvl(p_ta_intf_record.inventory_item_id,G_MISS_NUM) AND
7748          nvl(p_ta_record.organization_id,G_MISS_NUM)   = nvl(p_ta_intf_record.organization_id,G_MISS_NUM)   AND
7749          nvl(p_ta_record.revision_id,G_MISS_NUM)       = nvl(p_ta_intf_record.revision_id,G_MISS_NUM)       AND
7750          get_attr_internal_name (
7751                    p_item_catalog_group_id => p_ta_record.item_catalog_group_id,
7752                    p_version_seq_id        => p_ta_record.icc_version_number,
7753                    p_attr_id               => p_ta_record.attr_id,
7754                    p_association_id        => p_ta_record.association_id)
7755                                                        =  p_ta_intf_record.attr_name
7756       THEN
7757          RETURN true;
7758       ELSE
7759           RETURN false;
7760       END IF;
7761 
7762 END matches;
7763 
7764    --
7765    -- Check whether TA set is same or not.
7766    --
7767 FUNCTION is_same (p_ta_records      IN t_ta_records,
7768                   p_ta_intf_records IN t_ta_intf_records) RETURN BOOLEAN IS
7769 
7770      l_ta_count          NUMBER := 0;
7771      l_ta_intf_count     NUMBER := 0;
7772      l_match_count       NUMBER := 0;
7773      l_proc_name         CONSTANT VARCHAR2(30) := 'is_same';
7774 BEGIN
7775       write_debug(l_proc_name, 'Entering');
7776       IF (p_ta_records IS NOT NULL) THEN
7777          l_ta_count :=   p_ta_records.COUNT;
7778       END IF;
7779       write_debug(l_proc_name, 'TA record count ' || l_ta_count);
7780 
7781       IF (p_ta_intf_records IS NOT NULL) THEN
7782         l_ta_intf_count := p_ta_intf_records.COUNT;
7783       END IF;
7784       write_debug(l_proc_name, 'TA intf record count ' || l_ta_intf_count);
7785 
7786 
7787       -- check each record only if total count is same on both
7788       IF (l_ta_count = l_ta_intf_count) AND
7789          (l_ta_count > 0 AND l_ta_intf_count > 0) THEN
7790          write_debug(l_proc_name, ' Both have same count. So checking each records now ...');
7791 
7792          -- assume both ta and ta_intf are ordered by asc sequence
7793          FOR i IN p_ta_records.FIRST .. p_ta_records.LAST LOOP
7794            IF matches(p_ta_records(i), p_ta_intf_records(i)) THEN
7795               write_debug(l_proc_name, ' Sequence ' || p_ta_intf_records(i).sequence || ' matching');
7796               l_match_count := l_match_count + 1;
7797            ELSE
7798               write_debug(l_proc_name, ' Sequence ' || p_ta_intf_records(i).sequence || ' not matching');
7799               RETURN false; -- one record not matching. return false immd
7800            END IF;
7801         END LOOP;
7802 
7803       END IF;
7804 
7805       -- if both are null sets or if all rows are matching
7806       IF (l_match_count = l_ta_count AND l_match_count = l_ta_intf_count) THEN
7807          write_debug(l_proc_name, ' Both are null sets or all rows matching so returning true');
7808          RETURN true;
7809       ELSE
7810          write_debug(l_proc_name, ' Not matching so returning false ');
7811          RETURN false;
7812       END IF;
7813 
7814 END is_same;
7815 
7816     --
7817     -- Check whether change exists between user passed TA set in interface
7818     -- and TA set in the latest version of the ICC.
7819     --
7820 FUNCTION change_exists(p_item_catalog_group_id IN NUMBER,
7821                        p_version_seq_id        IN NUMBER,
7822                        p_set_process_id        IN NUMBER) RETURN BOOLEAN IS
7823 
7824      l_latest_version   ego_mtl_catalog_grp_vers_b.version_seq_id%TYPE;
7825      l_ta_records       t_ta_records;
7826      l_ta_intf_records  t_ta_intf_records;
7827      l_ret              BOOLEAN;
7828      l_proc_name        CONSTANT VARCHAR2(30) := 'change_exists';
7829 BEGIN
7830       write_debug(l_proc_name,'Entering method with params ' ||
7831                               ' p_item_catalog_group_id = ' || p_item_catalog_group_id ||
7832                                      ' p_version_seq_id = ' || p_version_seq_id  ||
7833                                      ' p_set_process_id = ' || p_set_process_id);
7834 
7835       -- get latest revision in the system
7836       l_latest_version := get_latest_version(p_item_catalog_group_id => p_item_catalog_group_id);
7837 
7838       write_debug(l_proc_name, 'Latest version = ' || l_latest_version);
7839 
7840       -- if latest revision is draft, it means user is trying to release new version
7841       IF l_latest_version = 0 THEN
7842         write_debug(l_proc_name, 'Version 0 so returning true');
7843         RETURN true;
7844       END IF;
7845 
7846        -- get TA's for latest revision
7847       l_ta_records := get_ta_records (
7848                              p_item_catalog_group_id => p_item_catalog_group_id,
7849                              p_version_seq_id        => l_latest_version);
7850 
7851       write_debug(l_proc_name, 'Fetched TA records');
7852 
7853        -- get TA's from interface for passed seq_id
7854       l_ta_intf_records := get_ta_interface_records (
7855                              p_item_catalog_group_id => p_item_catalog_group_id,
7856                              p_version_seq_id        => p_version_seq_id,
7857                              p_set_process_id        => p_set_process_id);
7858 
7859      write_debug(l_proc_name, 'Fetched TA interface records');
7860      write_debug(l_proc_name, 'Comparing .. ');
7861 
7862        -- compare TA's
7863        IF is_same (p_ta_records       => l_ta_records,
7864                    p_ta_intf_records  => l_ta_intf_records) THEN
7865          write_debug(l_proc_name, 'same so returning false');
7866          RETURN false;
7867        ELSE
7868          write_debug(l_proc_name, 'not same so returning true');
7869          RETURN true;
7870        END IF;
7871 
7872 END change_exists;
7873 
7874 -- End Bug 12394675.
7875 
7876 
7877 
7878 /********************************************************************
7879 ---
7880 ---   This procedure takes in the icc versions record type and creates
7881 ---   the icc revisions accordingly
7882 ---
7883 ********************************************************************/
7884 
7885 PROCEDURE Call_ICC_Vers_API (  p_icc_vers_rec  IN OUT NOCOPY ego_icc_vers_rec_type
7886                                ,x_return_status   OUT NOCOPY VARCHAR2
7887                                ,x_return_msg  OUT NOCOPY VARCHAR2
7888                              )
7889 IS
7890   l_proc_name   VARCHAR2(30) := 'Call_ICC_Vers_API';
7891   l_application_id NUMBER    := NULL;
7892   l_entity_code    VARCHAR2(30) := G_ENTITY_ICC_VERSION;
7893 
7894   e_skip_record         EXCEPTION;
7895 
7896   l_token_table     ERROR_HANDLER.Token_Tbl_Type;
7897   l_max_seq_id      NUMBER := 0;
7898   l_max_start_date  DATE := null;
7899   l_higher_date       DATE := null;
7900   l_lower_date        DATE := null;
7901   l_version_created   BOOLEAN := FALSE;
7902 
7903 
7904   FUNCTION Get_Max_Sequence
7905   RETURN NUMBER
7906   IS
7907     l_ver_id  number := 0;
7908   BEGIN
7909 
7910     select max(version_seq_id)
7911       into l_ver_id
7912     from   EGO_MTL_CATALOG_GRP_VERS_B
7913     where item_catalog_group_id = p_icc_vers_rec.item_catalog_group_id
7914     ;
7915 
7916     return l_ver_id;
7917 
7918   END Get_Max_Sequence;
7919 
7920 
7921   FUNCTION Check_ICC_Versioned
7922   RETURN BOOLEAN
7923   IS
7924     l_COUNT  number := 0;
7925   BEGIN
7926 
7927     select COUNT(1)
7928     into   l_count
7929     from   EGO_MTL_CATALOG_GRP_VERS_B
7930     where item_catalog_group_id = p_icc_vers_rec.item_catalog_group_id
7931     ;
7932 
7933     IF l_count > 0 THEN
7934       RETURN TRUE;
7935     ELSE
7936       RETURN FALSE;
7937     END IF;
7938 
7939   END Check_ICC_Versioned;
7940 
7941 
7942   FUNCTION Get_Max_St_Date
7943   RETURN DATE
7944   IS
7945     l_date   DATE := null;
7946   BEGIN
7947 
7948     SELECT max(start_active_date)
7949     INTO   l_date
7950     FROM   EGO_MTL_CATALOG_GRP_VERS_B
7951     WHERE item_catalog_group_id = p_icc_vers_rec.item_catalog_group_id
7952     AND   version_seq_id <> 0
7953     ;
7954     RETURN l_date;
7955 
7956   END Get_Max_St_Date;
7957 
7958   /****************************************
7959   ---
7960   --- INLINE Procedure to create a new version
7961   ---
7962   ****************************************/
7963   PROCEDURE Create_Version  ( p_start_date  IN DATE ,
7964                               p_end_date    IN DATE
7965                             )
7966   IS
7967 
7968     l_return_status   VARCHAR2(1) := G_RET_STS_SUCCESS;
7969     l_count           NUMBER := 0;
7970     l_msg_data        VARCHAR2(4000) := NULL;
7971   BEGIN
7972     write_debug(l_proc_name, 'Start insert');
7973 
7974     --- Update the ICC id in the TA interface table
7975     ---
7976     EGO_TA_BULKLOAD_PVT.Bulk_Validate_Trans_Attrs_ICC (
7977                                                       p_set_process_id           => G_SET_PROCESS_ID
7978                                                     ,p_item_catalog_group_id    => p_icc_vers_rec.item_catalog_group_id
7979                                                     ,p_item_catalog_group_name  => p_icc_vers_rec.item_catalog_name
7980                                                     );
7981 
7982 
7983     SAVEPOINT icc_version_create_start;
7984     l_version_created := FALSE;
7985     --- create the new version
7986     ---
7987          l_max_seq_id := Get_Max_Sequence;
7988          --- max seq id is incremented during insert below.
7989 
7990         INSERT into EGO_MTL_CATALOG_GRP_VERS_B
7991           (item_catalog_group_id,
7992           version_seq_id,
7993           version_description,
7994           start_active_date,
7995           end_active_date,
7996           created_by,
7997           creation_date,
7998           last_updated_by,
7999           last_update_date,
8000           last_update_login)
8001         VALUES
8002           (p_icc_vers_rec.item_catalog_group_id,
8003           l_max_seq_id + 1,
8004           p_icc_vers_rec.description,
8005           p_start_date,
8006           p_end_date,
8007           G_USER_ID,
8008           SYSDATE,
8009           G_USER_ID,
8010           SYSDATE,
8011           G_LOGIN_ID);
8012 
8013           p_icc_vers_rec.ver_seq_id := l_max_seq_id + 1;
8014           p_icc_vers_rec.end_date := p_end_date;
8015 
8016           write_debug(l_proc_name, 'inserted rows ver max seq seq=>'||l_max_seq_id||'  dt'||p_icc_vers_rec.start_date
8017            ||'*'||p_icc_vers_rec.end_date);
8018 
8019             --- Call the TA API
8020             ---
8021             EGO_TA_BULKLOAD_PVT.Import_TA_Intf
8022                                ( p_api_version             => 1.0,
8023                                  p_set_process_id          => G_SET_PROCESS_ID,
8024                                  p_item_catalog_group_id   => p_icc_vers_rec.item_catalog_group_id,
8025                                  p_icc_version_number_intf => p_icc_vers_rec.ver_seq_no,
8026                                  p_icc_version_number_act  => l_max_seq_id + 1,
8027                                  x_return_status           => l_return_status,
8028                                  x_return_msg              => x_return_msg
8029                                );
8030 
8031             write_debug(l_proc_name, 'TA api x_return_status =>'||l_return_status);
8032 
8033             IF l_return_status = G_RET_STS_SUCCESS THEN
8034               l_version_created := TRUE;
8035             ELSIF l_return_status = G_RET_STS_ERROR THEN
8036 
8037                   x_return_status := G_RET_STS_ERROR;
8038 
8039                   ROLLBACK TO icc_version_create_start;
8040                   l_version_created := FALSE;
8041 
8042                   write_debug ( l_proc_name , 'Unable to create TA for (icc id, seq no) => '
8043                              ||p_icc_vers_rec.item_catalog_group_id||','||p_icc_vers_rec.ver_seq_no);
8044 
8045                   l_token_table(1).TOKEN_NAME := 'VER_SEQ';
8046                   l_token_table(1).TOKEN_VALUE := p_icc_vers_rec.ver_seq_no;
8047 
8048                   l_token_table(2).TOKEN_NAME := 'ICC_NAME';
8049                   l_token_table(2).TOKEN_VALUE := p_icc_vers_rec.item_catalog_name;
8050 
8051                   ERROR_HANDLER.Set_Bo_Identifier(G_BO_IDENTIFIER_ICC);
8052 
8053                   --- Log a generic error for the version not being created
8054                   ---
8055                   ERROR_HANDLER.Add_Error_Message(
8056                     p_message_name                  => 'EGO_ICC_VERSION_NOT_CREATED'
8057                    ,p_application_id                => G_APPL_NAME
8058                    ,p_token_tbl                     => l_token_table
8059                    ,p_message_type                  => G_TYPE_ERROR
8060                    ,p_row_identifier                => p_icc_vers_rec.transaction_id
8061                    ,p_entity_code                   => l_entity_code
8062                    ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
8063                   );
8064                   l_token_table.DELETE;
8065 
8066 
8067                   -- Log the messages from the TA creation API
8068                   l_count := fnd_msg_pub.count_msg;
8069                   FND_MSG_PUB.RESET;  --- resets the message index pointer to top of table
8070 
8071                   FOR i in 1..l_count LOOP
8072                       ERROR_HANDLER.Add_Error_Message(
8073                         p_message_text                  => FND_MSG_PUB.GET ( p_encoded => FND_API.G_FALSE)  --- bug 9750497, 9756337
8074                        ,p_application_id                => G_APPL_NAME
8075                        ,p_token_tbl                     => l_token_table
8076                        ,p_message_type                  => G_TYPE_WARNING
8077                        ,p_row_identifier                => p_icc_vers_rec.transaction_id
8078                        ,p_entity_code                   => l_entity_code
8079                        ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
8080                       );
8081                   END LOOP;
8082 
8083 
8084                   --- we do not create the version if the TA fails
8085                   ---
8086                   --- Update all the TAs for the ver. seq to error
8087                   --- since we will not be processing any of those TAs
8088                   ---
8089                   EGO_TA_BULKLOAD_PVT.Update_Intf_Err_Trans_Attrs(
8090                              p_set_process_id          => G_SET_PROCESS_ID,
8091                              p_item_catalog_group_id   => p_icc_vers_rec.item_catalog_group_id,
8092                              p_icc_version_number_intf => p_icc_vers_rec.ver_seq_no,
8093                              x_return_status           => l_return_status,
8094                              x_return_msg              => x_return_msg);
8095 
8096                  ERROR_HANDLER.Set_Bo_Identifier(G_BO_IDENTIFIER_ICC);
8097                  IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8098                    l_version_created := FALSE;
8099                    RETURN;        --- Error message is logged in calling procedure
8100                  END IF;
8101             ELSIF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8102               x_return_status := G_RET_STS_UNEXP_ERROR;
8103               l_version_created := FALSE;
8104               ROLLBACK TO icc_version_create_start;
8105               RETURN;
8106             END IF;
8107 
8108     write_debug(l_proc_name, 'create ver ret sts x_return_status=>'||x_return_status);
8109   END Create_Version;
8110 
8111       /****************************************
8112       --- INLINE Procedure which updates the END DATE
8113       --- on an existing version
8114       ---
8115       ****************************************/
8116   PROCEDURE Update_existing_Version ( p_ver_start_date  IN DATE
8117                                      ,p_new_end_date    IN DATE
8118                                     )
8119   IS
8120 
8121   BEGIN
8122 
8123     UPDATE EGO_MTL_CATALOG_GRP_VERS_B
8124     set end_active_date     = p_new_end_date
8125        , last_updated_by    = G_USER_ID
8126        , last_update_date   = SYSDATE
8127        , last_update_login  = G_LOGIN_ID
8128     WHERE start_active_date = p_ver_start_date
8129     and   item_catalog_group_id = p_icc_vers_rec.item_catalog_group_id
8130     and   version_seq_id <> 0;
8131 
8132   END Update_existing_Version;
8133 
8134 
8135       --- function to get the minimum higher date among
8136       --- existing version when compared with the current date
8137       ---
8138   FUNCTION get_high_date ( p_date  IN DATE)
8139   RETURN DATE
8140   IS
8141 
8142     l_date   DATE;
8143 
8144     CURSOR cur_fetch_date
8145     IS
8146     SELECT min(start_active_date)  min_higher_date
8147     FROM   EGO_MTL_CATALOG_GRP_VERS_B
8148     WHERE  item_catalog_group_id = p_icc_vers_rec.item_catalog_group_id
8149     AND    start_active_date > p_date
8150     --AND    p_date < nvl(end_active_date, p_date - 1)
8151     AND    version_seq_id <> 0
8152     ;
8153 
8154   BEGIN
8155 
8156     FOR rec_date in cur_fetch_date loop
8157       l_date :=  rec_date.min_higher_date;
8158     end loop;
8159     RETURN l_date;
8160 
8161   END get_high_date;
8162 
8163   --- function to get the minimum lower date among
8164   --- existing version when compared with the current date
8165   ---
8166   FUNCTION get_low_date ( p_date  IN DATE)
8167   RETURN DATE
8168   IS
8169 
8170     l_date   DATE;
8171 
8172     CURSOR cur_fetch_date
8173     IS
8174     SELECT max(start_active_date)  max_lower_date
8175     FROM   EGO_MTL_CATALOG_GRP_VERS_B
8176     WHERE  item_catalog_group_id = p_icc_vers_rec.item_catalog_group_id
8177     AND    start_active_date < p_date
8178     AND    version_seq_id <> 0
8179     ;
8180 
8181   BEGIN
8182 
8183     FOR rec_date in cur_fetch_date loop
8184       l_date :=  rec_date.max_lower_date;
8185     end loop;
8186     RETURN l_date;
8187 
8188   END get_low_date;
8189 
8190 
8191 
8192 BEGIN
8193   write_debug(l_proc_name, 'Start');
8194   x_return_status := G_RET_STS_SUCCESS;
8195 
8196   --- Check if ICC is versioned
8197   ---
8198   IF NOT Check_ICC_Versioned THEN
8199 
8200     l_token_table(1).TOKEN_NAME := 'ICC_NAME';
8201     l_token_table(1).TOKEN_VALUE := p_icc_vers_rec.item_catalog_name;
8202 
8203     ERROR_HANDLER.Add_Error_Message(
8204       p_message_name                  => 'EGO_ICC_NOT_VERSIONED'
8205       ,p_application_id                => G_APPL_NAME
8206       ,p_token_tbl                     => l_token_table
8207       ,p_message_type                  => G_PROCESS_STATUS_WARNING
8208       ,p_row_identifier                => p_icc_vers_rec.transaction_id
8209       ,p_entity_code                   => l_entity_code
8210       ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
8211       );
8212       l_token_table.DELETE;
8213 
8214       x_return_status := G_RET_STS_ERROR;
8215 
8216       write_debug(l_proc_name, 'Err_Msg-TID='
8217                     ||p_icc_vers_rec.transaction_id||'-(ICC, STA_DT)=('
8218                     ||p_icc_vers_rec.item_catalog_name||','||to_char(p_icc_vers_rec.start_date, 'DD-MON-YYYY HH24:MI:SS')||')'
8219                     ||' EGO_ICC_NOT_VERSIONED'
8220                   );
8221 
8222       RETURN;
8223 
8224   END IF;
8225 
8226     --
8227     -- Bug 12394675. Issue #2. New version should be created only if
8228     -- there are changes in TAs. Added below condition to
8229     -- check for change in TA sets in system and user passed
8230     -- TA set in inteface tables.
8231     -- sreharih. Mon Apr 25 16:27:38 PDT 2011
8232     --
8233 
8234 
8235   IF NOT change_exists(p_item_catalog_group_id => p_icc_vers_rec.item_catalog_group_id,
8236                        p_version_seq_id        => p_icc_vers_rec.ver_seq_no,
8237                        p_set_process_id        => G_SET_PROCESS_ID) THEN
8238 
8239     l_token_table(1).TOKEN_NAME := 'ICC_NAME';
8240     l_token_table(1).TOKEN_VALUE := p_icc_vers_rec.item_catalog_name;
8241 
8242     l_token_table(2).TOKEN_NAME := 'ICC_VERSION';
8243     l_token_table(2).TOKEN_VALUE := p_icc_vers_rec.ver_seq_no;
8244 
8245     ERROR_HANDLER.Add_Error_Message(
8246        p_message_name                  => 'EGO_ICC_NO_TA_CHANGE'
8247       ,p_application_id                => G_APPL_NAME
8248       ,p_token_tbl                     => l_token_table
8249       ,p_message_type                  => G_PROCESS_STATUS_WARNING
8250       ,p_row_identifier                => p_icc_vers_rec.transaction_id
8251       ,p_entity_code                   => l_entity_code
8252       ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
8253       );
8254       l_token_table.DELETE;
8255 
8256       x_return_status := G_RET_STS_ERROR;
8257 
8258       write_debug(l_proc_name, 'Err_Msg-TID='
8259                     || p_icc_vers_rec.transaction_id
8260                     || p_icc_vers_rec.item_catalog_name|| ' version: ' || p_icc_vers_rec.ver_seq_no
8261                     || ' EGO_ICC_NO_TA_CHANGE'
8262                   );
8263 
8264       RETURN;
8265 
8266 
8267   END IF;
8268 
8269   --- CASE 1
8270   --- NEW version being inserted as the topmost version
8271   ---
8272   l_max_start_date := Get_Max_St_Date;
8273   IF p_icc_vers_rec.start_date > NVL(l_max_start_date, p_icc_vers_rec.start_date - 1) THEN
8274 
8275     --- create a new version
8276     ---
8277     l_version_created := FALSE;
8278     Create_Version ( p_start_date => p_icc_vers_rec.start_date
8279                     ,p_end_date   => NULL  -- since it is topmost
8280                    );
8281 
8282     --- end date the version which was earlier on top
8283     ---
8284 
8285     IF l_version_created THEN
8286         Update_existing_Version ( p_ver_start_date => l_max_start_date
8287                                  ,p_new_end_date   => p_icc_vers_rec.start_date - 1/(24*60*60)
8288                                 );
8289     END IF;
8290   ELSE
8291       --- CASE 2
8292       --- Version has to be inserted between two versions
8293       ---
8294       --- get the dates between which this version should lie
8295 
8296       l_higher_date := Get_high_date ( p_date => p_icc_vers_rec.start_date);
8297       l_lower_date  := Get_low_date ( p_date => p_icc_vers_rec.start_date);
8298 
8299       --- Version has to be created between the above dates
8300       ---
8301       l_version_created := FALSE;
8302       Create_Version ( p_start_date => p_icc_vers_rec.start_date
8303                       ,p_end_date   => l_higher_date - 1/(24*60*60)
8304                       );
8305 
8306       --- if lower end date is NULL it means above version inserted is lowest date released version being inserted
8307       --- hence there is no need to update any existing version
8308       ---
8309       IF l_lower_date IS NOT NULL AND l_version_created THEN
8310           --- change the end date on the version below the current (new)version being inserted
8311           ---
8312           Update_existing_Version ( p_ver_start_date => l_lower_date
8313                                    ,p_new_end_date   => p_icc_vers_rec.start_date - 1/(24*60*60)
8314                                   );
8315       END IF;
8316   END IF;
8317 
8318   write_debug(l_proc_name, 'End x_return_status =>'||x_return_status);
8319 EXCEPTION
8320 WHEN OTHERS THEN
8321   x_return_status := G_RET_STS_UNEXP_ERROR;
8322   x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
8323 END Call_ICC_Vers_API;
8324 
8325 
8326 /********************************************************************
8327 ---
8328 ---   This procedure updates the interface table with the pl/sql table
8329 ---   with process_status and other id value conversions which are done
8330 ---
8331 ---
8332 ********************************************************************/
8333 
8334 PROCEDURE Update_Interface_Table ( p_entity IN VARCHAR2
8335                                  , p_icc_tbl        IN ego_icc_tbl_type DEFAULT g_null_icc_tbl
8336                                  , p_ag_assoc_tbl   IN ego_ag_assoc_tbl_type DEFAULT g_null_ag_assoc_tbl
8337                                  , p_func_assoc_tbl IN ego_func_param_map_tbl_type DEFAULT g_null_func_param_map_tbl
8338                                  , p_icc_vers_tbl   IN ego_icc_vers_tbl_type DEFAULT g_null_icc_vers_tbl
8339                                  )
8340 IS
8341 
8342   l_proc_name  VARCHAR2(30) :=  'Update_Interface_Table';
8343 
8344   l_transaction_id_tbl number_tbl_type; -- bug 9701271
8345   l_blank_tbl number_tbl_type; -- bug 9701271
8346 BEGIN
8347   write_debug (l_proc_name, 'Start of  '||l_proc_name);
8348 
8349   IF p_entity = G_ENTITY_ICC_HEADER THEN
8350 
8351       write_debug(l_proc_name, 'Updating interface table for '|| G_ENTITY_ICC_HEADER);
8352       -- bug 9701271
8353       l_transaction_id_tbl := l_blank_tbl;
8354       FOR i IN 1..p_icc_tbl.count LOOP
8355        l_transaction_id_tbl(i) :=  p_icc_tbl(i).transaction_id;
8356       END LOOP;
8357 
8358       FORALL i IN 1..p_icc_tbl.count
8359         UPDATE MTL_ITEM_CAT_GRPS_INTERFACE
8360         SET
8361            ROW = p_icc_tbl(i)   -- bug 9701271
8362         WHERE transaction_id = l_transaction_id_tbl(i)   -- bug 9701271
8363         AND   process_status = G_PROCESS_STATUS_INITIAL
8364         ;
8365 
8366   ELSIF p_entity = G_ENTITY_ICC_AG_ASSOC THEN
8367 
8368         write_debug(l_proc_name, 'Updating interface table for '|| G_ENTITY_ICC_AG_ASSOC);
8369         -- bug 9701271
8370         l_transaction_id_tbl := l_blank_tbl;
8371         FOR i IN 1..p_ag_assoc_tbl.count LOOP
8372          l_transaction_id_tbl(i) :=  p_ag_assoc_tbl(i).transaction_id;
8373         END LOOP;
8374 
8375         FORALL i in 1..p_ag_assoc_tbl.COUNT
8376             UPDATE EGO_ATTR_GRPS_ASSOC_INTERFACE
8377             SET ROW = p_ag_assoc_tbl(i)   -- bug 9701271
8378             WHERE transaction_id = l_transaction_id_tbl(i)
8379             AND   process_status = G_PROCESS_STATUS_INITIAL
8380             ;
8381 
8382   ELSIF p_entity = G_ENTITY_ICC_FN_PARAM_MAP THEN
8383 
8384         write_debug(l_proc_name, 'Updating interface table for '|| G_ENTITY_ICC_FN_PARAM_MAP);
8385         -- bug 9701271
8386         l_transaction_id_tbl := l_blank_tbl;
8387         FOR i IN 1..p_func_assoc_tbl.count LOOP
8388           l_transaction_id_tbl(i) :=  p_func_assoc_tbl(i).transaction_id;
8389         END LOOP;
8390 
8391         FORALL i in  1..p_func_assoc_tbl.COUNT
8392             UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE
8393             SET   ROW = p_func_assoc_tbl(i)      -- bug 9701271
8394             WHERE transaction_id = l_transaction_id_tbl(i)
8395             AND   process_status = G_PROCESS_STATUS_INITIAL
8396             ;
8397 
8398   ELSIF p_entity = G_ENTITY_ICC_VERSION THEN
8399 
8400         write_debug(l_proc_name, 'Updating interface table for '|| G_ENTITY_ICC_VERSION);
8401         -- bug 9701271
8402         l_transaction_id_tbl := l_blank_tbl;
8403         FOR i IN 1..p_icc_vers_tbl.count LOOP
8404           l_transaction_id_tbl(i) :=  p_icc_vers_tbl(i).transaction_id;
8405         END LOOP;
8406 
8407         FORALL i in  1..p_icc_vers_tbl.COUNT
8408             UPDATE EGO_ICC_VERS_INTERFACE
8409             set ROW = p_icc_vers_tbl(i)
8410             WHERE transaction_id = l_transaction_id_tbl(i)
8411             AND   process_status = G_PROCESS_STATUS_INITIAL
8412             ;
8413             write_debug( l_proc_name, 'rows update =>'||SQL%ROWCOUNT);
8414 
8415   END IF;
8416 
8417 
8418 write_debug (l_proc_name, 'End of  '||l_proc_name);
8419 
8420 END Update_Interface_Table;
8421 
8422 
8423 
8424 
8425 
8426 /********************************************************************
8427 ---   This procedure accepts a pl/sql table of records
8428 ---   validates, converts necessary ids, finally processes them
8429 ---
8430 ********************************************************************/
8431 
8432    PROCEDURE Process_Entity ( p_entity         IN varchar2
8433                          , p_icc_tbl        IN OUT NOCOPY ego_icc_tbl_type
8434                          , p_ag_assoc_tbl   IN OUT NOCOPY ego_ag_assoc_tbl_type
8435                          , p_func_assoc_tbl IN OUT NOCOPY ego_func_param_map_tbl_type
8436                          , p_icc_vers_tbl   IN OUT NOCOPY ego_icc_vers_tbl_type
8437                          , p_call_from_icc_process IN varchar2 DEFAULT NULL   --- bug 9791391, added parameter
8438                          , x_return_status    OUT NOCOPY VARCHAR2
8439                          , x_return_msg  OUT NOCOPY VARCHAR2
8440                          )
8441    IS
8442      l_proc_name  CONSTANT VARCHAR2(30) := 'Process_Entity';
8443      e_skip_record EXCEPTION;
8444      e_unexpected_error EXCEPTION;
8445 
8446      l_null_icc_rec          ego_icc_rec_type := null;
8447      l_null_ag_assoc_rec     ego_ag_assoc_rec_type:= null;
8448      l_null_icc_vers_rec     ego_icc_vers_rec_type := null;
8449      l_null_func_params_rec  ego_func_param_map_rec_type := null;
8450      l_count_prod            number := 0;
8451      l_count_current         number := 0;
8452      l_action_id             number := 0;
8453      l_dummy                 number := 0;
8454 
8455      l_func_params_tbl       ego_FN_Param_Obj_Tbl_Type := ego_FN_Param_Obj_Tbl_Type();
8456      l_count_frm_ego_maps    NUMBER := 0;
8457      l_count_frm_func_params NUMBER := 0;
8458      l_token_table           ERROR_HANDLER.Token_Tbl_Type;
8459      l_entity_code           VARCHAR2(30);
8460      l_return_status         VARCHAR2(1) := NULL;
8461 
8462      ---
8463      --- dummy call to get the SUMMARY_FLAG for ICC , KFF in attribute_defaulting
8464      l_delimiter varchar2(1) := FND_Flex_Ext.Get_Delimiter
8465                 (  application_short_name   => G_ITEM_CAT_KFF_APPL
8466                  , key_flex_code            => G_ICC_KFF_NAME
8467                  , structure_number         => G_STRUCTURE_NUMBER
8468                  );
8469 
8470 
8471 
8472      CURSOR cur_prod_param_count  ( p_function_id number)
8473      IS
8474      SELECT COUNT(1) AS count_prod
8475      FROM EGO_FUNC_PARAMS_B
8476      where function_id = p_function_id
8477      ;
8478 
8479      CURSOR cur_curr_param_count  ( p_function_id number, p_icc_id number)
8480      IS
8481      SELECT COUNT(1) AS count_map
8482      FROM EGO_MAPPINGS_B
8483      where function_id = p_function_id
8484      and mapped_obj_type = 'A'
8485      and mapped_obj_pk1_val = ( select action_id
8486                                    from ego_actions_b
8487                                    where function_id = p_function_id
8488                                    and   classification_code = to_char(p_icc_id)
8489                                  )
8490     ;
8491 
8492 
8493      CURSOR cur_icc_column_chk ( p_action_id NUMBER, p_icc_id NUMBER)
8494      IS
8495         SELECT G_NUM_GEN_FUNCTION  column_name
8496         FROM   mtl_item_catalog_groups_b
8497         WHERE item_catalog_group_id =  p_icc_id
8498         AND   item_num_action_id =  p_action_id
8499         UNION ALL
8500         SELECT G_DESC_GEN_FUNCTION column_name
8501         FROM   mtl_item_catalog_groups_b
8502         WHERE item_catalog_group_id =  p_icc_id
8503         AND   item_desc_action_id =  p_action_id
8504         ;
8505 
8506 
8507 
8508    BEGIN
8509      write_debug (l_proc_name, 'Start of  '||l_proc_name);
8510      write_debug (l_proc_name, 'Entity =>'||p_entity);
8511 
8512      x_return_status := G_RET_STS_SUCCESS;
8513 
8514      --- pl/sql validations for ICC header
8515      ---
8516      IF p_entity = G_ENTITY_ICC_HEADER THEN
8517 
8518          IF p_icc_tbl.count = 0 THEN
8519            --- nothing to process
8520            ---
8521            RETURN;
8522          END IF;
8523 
8524          FOR i in 1..p_icc_tbl.count
8525          LOOP
8526            BEGIN
8527 
8528                write_debug (l_proc_name, 'Calling value_to_id');
8529                Value_To_ID_Conversion  ( p_entity        =>  p_entity
8530                                         ,p_icc_rec       =>  p_icc_tbl(i)       --- only header record processed rest are ignored
8531                                         ,p_ag_assoc_rec  =>  g_null_ag_assoc_rec
8532                                         ,p_func_PARAM_assoc_rec => g_null_func_params_rec
8533                                         ,p_icc_ver_rec    => g_null_icc_vers_rec
8534                                         ,x_return_status => l_return_status
8535                                         ,x_return_msg    => x_return_msg
8536                                        );
8537 
8538                IF l_return_status = G_RET_STS_ERROR THEN
8539                  RAISE e_skip_record;
8540                ELSIF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8541                  RAISE e_unexpected_error;
8542                END IF;
8543 
8544                 write_debug (l_proc_name, 'Calling icc API ICC NAME=>'||p_icc_tbl(i).item_catalog_name);
8545                 Call_ICC_APIS (   p_icc_rec       => p_icc_tbl(i)
8546                                  ,x_return_status => x_return_status
8547                                  ,x_return_msg    => x_return_msg
8548                                );
8549 
8550                IF x_return_status = G_RET_STS_ERROR THEN
8551                  RAISE e_skip_record;
8552                ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
8553                  RAISE e_unexpected_error;
8554                END IF;
8555 
8556                --- Successfully processed , mark the record
8557                ---
8558                p_icc_tbl(i).process_status := G_PROCESS_STATUS_SUCCESS;
8559 
8560 
8561 
8562 
8563            EXCEPTION
8564            WHEN e_skip_record THEN
8565              --- Skip the current record and continue processing for next record
8566              --- Mark the current record in p_icc_tbl as Error
8567              --- Message would have been logged by the individual APIs doing the validation
8568              ---
8569              p_icc_tbl(i).process_status := G_PROCESS_STATUS_ERROR;
8570 
8571              NULL;
8572            END;
8573          END LOOP;
8574 
8575          IF G_Flow_Type = G_EGO_MD_INTF THEN --- if called by API then update the interface table with the process status
8576            Update_Interface_Table (p_entity => p_entity, p_icc_tbl  => p_icc_tbl);
8577          END IF;
8578 
8579      END IF;
8580 
8581      --- pl/sql validations for ICC AG associations
8582      ---
8583      IF p_entity =  G_ENTITY_ICC_AG_ASSOC THEN
8584 
8585          IF p_ag_assoc_tbl.count = 0 THEN
8586            --- nothing to process
8587            ---
8588            RETURN;
8589          END IF;
8590 
8591          FOR i in 1..p_ag_assoc_tbl.COUNT
8592          LOOP
8593            BEGIN
8594 
8595                Value_To_ID_Conversion  ( p_entity         => p_entity
8596                                         ,p_icc_rec        => g_null_icc_rec
8597                                         ,p_ag_assoc_rec   => p_ag_assoc_tbl(i)
8598                                         ,p_func_PARAM_assoc_rec => g_null_func_params_rec
8599                                         ,p_icc_ver_rec    => g_null_icc_vers_rec
8600                                         ,x_return_status  => l_return_status
8601                                         ,x_return_msg     => x_return_msg
8602                                        );
8603 
8604                IF l_return_status = G_RET_STS_ERROR THEN
8605                  RAISE e_skip_record;
8606                ELSIF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8607                  RAISE e_unexpected_error;
8608                END IF;
8609 
8610                /*
8611                --- not being used currently
8612                ---
8613                Attribute_Defaulting ( p_entity         => p_entity
8614                                      ,p_icc_rec        => p_icc_tbl(i)
8615                                      ,p_ag_assoc_rec   => p_ag_assoc_tbl(i)
8616                                      ,p_func_param_assoc_rec => g_null_func_params_rec
8617                                      ,p_icc_ver_rec    => l_null_icc_vers_rec
8618                                      ,x_return_status  => x_return_status
8619                                      ,x_return_msg     => x_return_msg
8620                                     );
8621 
8622                IF x_return_status = G_RET_STS_ERROR THEN
8623                  RAISE e_skip_record;
8624                ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
8625                  RAISE e_unexpected_error;
8626                END IF;
8627                */
8628                 Call_ag_assoc_api  (   p_ag_assoc_rec       => p_ag_assoc_tbl(i)
8629                                       ,x_return_status => l_return_status
8630                                       ,x_return_msg    => x_return_msg
8631                                    );
8632 
8633                IF l_return_status = G_RET_STS_ERROR THEN
8634                  RAISE e_skip_record;
8635                ELSIF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8636                  RAISE e_unexpected_error;
8637                END IF;
8638 
8639                --- Successfully processed , mark the record
8640                ---
8641                p_ag_assoc_tbl(i).process_status := G_PROCESS_STATUS_SUCCESS;
8642 
8643 
8644 
8645            EXCEPTION
8646            WHEN e_skip_record THEN
8647              --- Skip the current record and continue processing for next record
8648              p_ag_assoc_tbl(i).process_status := G_PROCESS_STATUS_ERROR;
8649            END;
8650          END LOOP;
8651          IF G_Flow_Type = G_EGO_MD_INTF THEN --- if called by API then update the interface table with the process status
8652            Update_Interface_Table (p_entity => p_entity, p_ag_assoc_tbl  => p_ag_assoc_tbl);
8653          END IF;
8654 
8655 
8656      END IF;
8657 
8658 
8659      --- pl/sql validations for ICC Function  associations
8660      ---
8661      IF p_entity =  G_ENTITY_ICC_FN_PARAM_MAP THEN
8662 
8663          IF p_func_assoc_tbl.count = 0 THEN
8664            --- nothing to process
8665            ---
8666            RETURN;
8667          END IF;
8668 
8669          l_entity_code := G_ENTITY_ICC_FN_PARAM_MAP;
8670 
8671          FOR i in 1..p_func_assoc_tbl.COUNT
8672          LOOP
8673            BEGIN
8674 
8675                Value_To_ID_Conversion  ( p_entity         => p_entity
8676                                         ,p_icc_rec        => g_null_icc_rec
8677                                         ,p_ag_assoc_rec   => g_null_ag_assoc_rec
8678                                         ,p_func_param_assoc_rec => p_func_assoc_tbl(i)
8679                                         ,p_icc_ver_rec    => g_null_icc_vers_rec
8680                                         ,x_return_status  => l_return_status
8681                                         ,x_return_msg     => x_return_msg
8682                                        );
8683 
8684                IF l_return_status = G_RET_STS_ERROR THEN
8685                  RAISE e_skip_record;
8686                ELSIF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8687                  RAISE e_unexpected_error;
8688                END IF;
8689 
8690                  --- not being used currently
8691                  ---
8692                /*
8693                Attribute_Defaulting ( p_entity        => p_entity
8694                                      ,p_icc_rec       => g_null_icc_rec       --- ignored
8695                                      ,p_ag_assoc_rec  =>  g_null_ag_assoc_rec  --- only ag assoc record processed rest are ignored
8696                                      ,p_func_param_assoc_rec => p_func_assoc_tbl(i) --- ignored
8697                                      ,p_icc_ver_rec    => g_null_icc_vers_rec   --- ignored
8698                                      ,x_return_status => x_return_status
8699                                      ,x_return_msg    => x_return_msg
8700                                     );
8701 
8702                IF x_return_status = G_RET_STS_ERROR THEN
8703                  RAISE e_skip_record;
8704                ELSIF x_return_status = G_RET_STS_UNEXP_ERROR THEN
8705                  RAISE e_unexpected_error;
8706                END IF;
8707                */
8708 
8709                 Call_func_param_assoc_api( p_func_param_assoc_rec  => p_func_assoc_tbl(i)
8710                                           ,x_return_status   => l_return_status
8711                                           ,x_return_msg      => x_return_msg
8712                                          );
8713 
8714                IF l_return_status = G_RET_STS_ERROR THEN
8715                  RAISE e_skip_record;
8716                ELSIF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8717                  RAISE e_unexpected_error;
8718                END IF;
8719 
8720                --- Successfully processed , mark the record
8721                ---
8722                p_func_assoc_tbl(i).process_status := G_PROCESS_STATUS_SUCCESS;
8723 
8724            EXCEPTION
8725            WHEN e_skip_record THEN
8726              --- Skip the current record and continue processing for next record
8727              p_func_assoc_tbl(i).process_status := G_PROCESS_STATUS_ERROR;
8728            END;
8729          END LOOP;
8730 
8731          /*
8732          ---
8733          --- If some of the parameters are not mapped then we have to remove the association
8734          --- of the function and remove the mapping
8735          ---
8736          write_debug(l_proc_name, 'start of param check loop');
8737          FOR i in 1..p_func_assoc_tbl.COUNT LOOP
8738            l_func_params_tbl.extend;
8739            l_func_params_tbl(i) := ego_Func_Param_map_Obj_Type (
8740                                         p_func_assoc_tbl(i).item_catalog_group_id
8741                                        ,p_func_assoc_tbl(i).function_id
8742                                        ,p_func_assoc_tbl(i).parameter_id
8743                                        ,p_func_assoc_tbl(i).process_status
8744                                        ,p_func_assoc_tbl(i).item_catalog_name
8745                                        ,p_func_assoc_tbl(i).function_name
8746                                        ,p_func_assoc_tbl(i).transaction_id
8747                                          );
8748          END LOOP;
8749 
8750          write_debug(l_proc_name, 'start of function verification');
8751          <<Function_Verification>>
8752          FOR rec_icc_func  IN ( select item_catalog_group_id
8753                                      , function_id
8754                                      , item_catalog_name
8755                                      , function_name
8756                                      , min(transaction_id) transaction_id
8757                                      , count(1) as count
8758                                 from    table ( cast (l_func_params_tbl as ego_FN_Param_Obj_Tbl_Type))
8759                                 where  process_status = G_RET_STS_SUCCESS
8760                                 group by item_catalog_group_id , function_id , item_catalog_name, function_name
8761                               ) LOOP
8762              --- For every icc and function_id in params table
8763              --- get counts from interface table, get total parameters for the function from production
8764              ---
8765             FOR rec_prod IN cur_prod_param_count ( rec_icc_func.FUNCTION_ID)
8766             LOOP
8767               l_count_frm_func_params := rec_prod.count_prod;
8768             END LOOP;
8769 
8770             FOR rec_curr IN cur_curr_param_count ( p_function_id => rec_icc_func.FUNCTION_ID, p_icc_id => rec_icc_func.item_catalog_group_id) LOOP
8771               l_count_frm_ego_maps := rec_curr.count_map;
8772             END LOOP;
8773 
8774             IF l_count_frm_ego_maps < l_count_frm_func_params THEN
8775                --- All the function parameters are not mapped
8776                --- issue a warning to the user
8777                ---
8778                l_token_table(1).TOKEN_NAME := 'FUNC_NAME';
8779                l_token_table(1).TOKEN_VALUE := rec_icc_func.function_name;
8780 
8781                l_token_table(2).TOKEN_NAME := 'ICC_NAME';
8782                l_token_table(2).TOKEN_VALUE := rec_icc_func.item_catalog_name;
8783 
8784 
8785                ERROR_HANDLER.Add_Error_Message(
8786                 p_message_name                  => 'EGO_FUNC_NOT_ASSOC_ICC_PARAM'
8787                ,p_application_id                => G_APPL_NAME
8788                ,p_token_tbl                     => l_token_table
8789                ,p_message_type                  => G_PROCESS_STATUS_WARNING
8790                ,p_row_identifier                => rec_icc_func.transaction_id
8791                ,p_entity_code                   => l_entity_code
8792                ,p_table_name                    => G_ENTITY_ICC_AG_ASSOC
8793                );
8794                l_token_table.DELETE;
8795 
8796 
8797                --- Check if the function is associated to number generation or desc generation
8798                ---
8799 
8800                SELECT action_id
8801                into   l_action_id
8802                FROM  ego_actions_b
8803                WHERE function_id = rec_icc_func.function_id
8804                AND classification_code = to_char(rec_icc_func.item_catalog_group_id)
8805                ;
8806 
8807 
8808                FOR rec_icc_chk   IN cur_icc_column_chk ( L_action_id , rec_icc_func.item_catalog_group_id)
8809                LOOP
8810 
8811                  Update_Func_ICC_Hdr_Cols  (  p_col_name      => rec_icc_chk.column_name
8812                                              ,p_icc_id        => rec_icc_func.item_catalog_group_id
8813                                              ,x_return_status => l_return_status
8814                                              ,x_return_msg    => x_return_msg
8815                                            );
8816 
8817                    IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8818                      RAISE e_unexpected_error;
8819                    END IF;
8820 
8821                  EXIT;
8822 
8823                END LOOP;
8824 
8825            --- Delete the function association and mappings
8826            ---
8827                 Process_Function_Actions (  p_operation => G_TTYPE_DELETE
8828                                            ,p_action_id        => l_action_id
8829                                            ,x_action_id        => l_dummy
8830                                            ,x_return_status    => l_return_status
8831                                            ,x_return_msg       => x_return_msg
8832                                          );
8833                    IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8834                      RAISE e_unexpected_error;
8835                    END IF;
8836 
8837 
8838                 --- mark the interface table records as Error for that function_id and icc_id
8839                 FOR i in 1..p_func_assoc_tbl.COUNT LOOP
8840 
8841                   IF p_func_assoc_tbl(i).function_id = rec_icc_func.function_id
8842                       AND p_func_assoc_tbl(i).item_catalog_group_id = rec_icc_func.item_catalog_group_id
8843                     THEN
8844                     p_func_assoc_tbl(i).process_status := G_PROCESS_STATUS_ERROR;
8845                   END IF;
8846 
8847                 END LOOP;
8848 
8849             END IF;  ----- l_count_frm_ego_maps < l_count_frm_func_params
8850          END LOOP Function_Verification;
8851          **/
8852 
8853 
8854          IF G_Flow_Type = G_EGO_MD_INTF THEN --- if called by API then update the interface table with the process status
8855            Update_Interface_Table (p_entity => p_entity, p_func_assoc_tbl  => p_func_assoc_tbl);
8856          END IF;
8857 
8858      END IF;  --- pl/sql validations for ICC AF associations
8859 
8860 
8861      IF p_entity = G_ENTITY_ICC_VERSION THEN
8862 
8863           write_debug ( l_proc_name, 'No of records=>'||p_icc_vers_tbl.COUNT);
8864           IF p_icc_vers_tbl.count = 0 THEN
8865             --- nothing to process
8866             ---
8867             RETURN;
8868           END IF;
8869 
8870           FOR i in 1..p_icc_vers_tbl.COUNT LOOP
8871              BEGIN
8872 
8873                Value_To_ID_Conversion  ( p_entity         => p_entity
8874                                         ,p_icc_rec        => g_null_icc_rec
8875                                         ,p_ag_assoc_rec   => g_null_ag_assoc_rec
8876                                         ,p_func_param_assoc_rec => g_null_func_params_rec
8877                                         ,p_icc_ver_rec    => p_icc_vers_tbl(i)
8878                                         ,p_call_from_icc_process => p_call_from_icc_process
8879                                         ,x_return_status  => l_return_status
8880                                         ,x_return_msg     => x_return_msg
8881                                        );
8882 
8883                IF l_return_status = G_RET_STS_ERROR THEN
8884                  RAISE e_skip_record;
8885                ELSIF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8886                  RAISE e_unexpected_error;
8887                END IF;
8888 
8889 
8890                write_debug ( l_proc_name, 'calling vers record=>'||i);
8891                Call_ICC_Vers_API (  p_icc_vers_rec  => p_icc_vers_tbl(i)
8892                                    ,x_return_status => l_return_status
8893                                    ,x_return_msg    => x_return_msg
8894                                  );
8895                write_debug ( l_proc_name, 'calling vers status=>'||l_return_status);
8896                    IF  l_return_status = G_RET_STS_ERROR THEN
8897                       RAISE e_skip_record;
8898                    ELSIF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8899                      RAISE e_unexpected_error;
8900                    END IF;
8901 
8902                --- Added this call Bug 9791391
8903                ---
8904                write_debug ( l_proc_name, 'calling vers record=>'||i);
8905                Sync_Draft_Version (  p_icc_vers_rec  => p_icc_vers_tbl(i)
8906                                     ,x_return_status => l_return_status
8907                                     ,x_return_msg    => x_return_msg
8908                                   );
8909                write_debug ( l_proc_name, 'calling sync draft version =>'||l_return_status);
8910                    IF  l_return_status = G_RET_STS_ERROR THEN
8911                       RAISE e_skip_record;
8912                    ELSIF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8913                      RAISE e_unexpected_error;
8914                    END IF;
8915 
8916 
8917 
8918                    --- Successfully processed , mark the record
8919                    ---
8920                    p_icc_vers_tbl(i).process_status := G_PROCESS_STATUS_SUCCESS;
8921 
8922              EXCEPTION
8923              WHEN e_skip_record THEN
8924                --- Skip the current record and continue processing for next record
8925                p_icc_vers_tbl(i).process_status := G_PROCESS_STATUS_ERROR;
8926              END;
8927            END LOOP;
8928 
8929              IF G_Flow_Type = G_EGO_MD_INTF THEN --- if called by API then update the interface table with the process status
8930                Update_Interface_Table (p_entity => p_entity, p_icc_vers_tbl => p_icc_vers_tbl);
8931              END IF;
8932 
8933      END IF;  ---ICC Versions entity
8934 
8935    write_debug (l_proc_name, 'End of  '||l_proc_name);
8936 
8937    EXCEPTION
8938    WHEN e_unexpected_error THEN
8939       write_debug(l_proc_name, x_return_msg);
8940       x_return_status := G_RET_STS_UNEXP_ERROR;
8941       x_return_msg := x_return_msg||'Stop process error occured in '||G_PKG_NAME||'.'||l_proc_name;
8942       write_debug(l_proc_name, x_return_msg);
8943    WHEN OTHERS THEN
8944       x_return_status := G_RET_STS_UNEXP_ERROR;
8945       x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
8946       write_debug(l_proc_name, x_return_msg);
8947    end   Process_Entity;
8948 
8949 
8950 /*************************************************************************************************
8951 ---
8952 --- This procedure is used to build the hierarchy for the ICCs
8953 --- in the interface table.
8954 ---
8955 --- Techical Design:
8956 ---  First get the interface records which are top-most parents ( parent_id is null),
8957 ---  mark them as level 0 , then get the immediate children of these parents ( level 1)
8958 --- then get the immediate children of the level 1 records and so on until no records are found
8959 ---  process/import the ICC records starting from level 0
8960 **************************************************************************************************/
8961 PROCEDURE Build_ICC_Hierarcy_From_Intf  ( x_icc_hier_tbl   IN OUT NOCOPY ego_ICC_Hier_Tbl_Type
8962                                          ,x_no_levels         OUT NOCOPY NUMBER
8963                                        )
8964 IS
8965   l_proc_name    VARCHAR2(30) := 'Build_ICC_Hierarcy_From_Intf';
8966 
8967   l_icc_hier_rec ego_ICC_Obj_Type;
8968   l_icc_hier_tbl ego_ICC_Hier_Tbl_Type := ego_ICC_Hier_Tbl_Type();
8969   i number := 0;
8970   l_count number := 0;
8971   l_records_found boolean;
8972   l_level   number := 0;
8973 
8974 
8975   CURSOR cur_select_recs
8976   is
8977     select micgi.* ,  0 icc_level
8978     from MTL_ITEM_CAT_GRPS_INTERFACE micgi
8979     where (PARENT_CATALOG_GROUP_NAME IS NULL
8980            OR PARENT_CATALOG_GROUP_ID  IS NOT NULL
8981           )
8982      AND  ( ( G_SET_PROCESS_ID IS NULL )
8983                 OR
8984               ( set_process_id =  G_SET_PROCESS_ID)
8985           )
8986      AND process_status = G_PROCESS_STATUS_INITIAL
8987     ;
8988 
8989   CURSOR cur_select_orph_recs
8990   is
8991     select micgi.*
8992     from MTL_ITEM_CAT_GRPS_INTERFACE micgi
8993     where (PARENT_CATALOG_GROUP_NAME IS NOT NULL
8994            AND PARENT_CATALOG_GROUP_ID  IS NULL
8995           )
8996      AND  ( ( G_SET_PROCESS_ID IS NULL )
8997                 OR
8998               ( set_process_id =  G_SET_PROCESS_ID)
8999           )
9000      AND process_status = G_PROCESS_STATUS_INITIAL
9001     ;
9002 
9003 
9004 
9005   CURSOR cur_select_child_recs ( p_level number)
9006   is
9007     select MICGI.* ,  p_level+1 icc_level
9008     from MTL_ITEM_CAT_GRPS_INTERFACE MICGI
9009     where parent_catalog_group_name
9010     in (
9011         select item_catalog_name
9012         from table ( cast (l_icc_hier_tbl as ego_ICC_Hier_Tbl_Type) ) a
9013         where a.icc_level = p_level
9014        )
9015      AND  ( ( G_SET_PROCESS_ID IS NULL )
9016                 OR
9017               ( set_process_id =  G_SET_PROCESS_ID)
9018           )
9019 
9020     ;
9021 
9022   l_cur_child_recs   cur_select_child_recs%rowtype;
9023 
9024 
9025   cursor cur_fetch_recs
9026   is
9027     select item_catalog_name , icc_level
9028     from table ( cast (l_icc_hier_tbl as ego_ICC_Hier_Tbl_Type ))
9029     ;
9030 
9031 
9032 BEGIN
9033 
9034    ---
9035    --- Built level 0 , top most parents
9036 
9037   for rec_records in cur_select_recs loop
9038 
9039     i:= i+1;
9040     l_icc_hier_tbl.extend;
9041     l_icc_hier_tbl(i)   := ego_ICC_Obj_Type(rec_records.ITEM_CATALOG_NAME
9042                                   , rec_records.ITEM_CATALOG_GROUP_ID
9043                                   , rec_records.pARENT_CATALOG_GROUP_NAME, rec_records.PARENT_CATALOG_GROUP_ID
9044                                   , rec_records.TRANSACTION_TYPE
9045                                   , rec_records.TRANSACTION_ID
9046                                   , rec_records.icc_level
9047                                   ) ;
9048 
9049   end loop;
9050 
9051     l_level := 0;
9052 
9053   LOOP
9054       l_records_found := FALSE;
9055 
9056       FOR rec_child_rec  in cur_select_child_recs ( l_level) loop
9057           l_icc_hier_tbl.extend;
9058           l_icc_hier_tbl(l_icc_hier_tbl.LAST)  := ego_ICC_Obj_Type (rec_child_rec.ITEM_CATALOG_NAME
9059                                                           , rec_child_rec.ITEM_CATALOG_GROUP_ID
9060                                                           , rec_child_rec.pARENT_CATALOG_GROUP_NAME
9061                                                           , rec_child_rec.PARENT_CATALOG_GROUP_ID
9062                                                           , rec_child_rec.TRANSACTION_TYPE
9063                                                           , rec_child_rec.TRANSACTION_ID
9064                                                           , rec_child_rec.ICC_LEVEL
9065                                                           );
9066           l_records_found := TRUE;
9067       END LOOP;
9068 
9069     IF NOT l_records_found then
9070       exit;
9071     else
9072       l_level := l_level + 1;
9073     END IF;
9074 
9075   END LOOP;
9076 
9077 
9078 
9079   FOR rec_cur_fetch_recs in cur_fetch_recs LOOP
9080     write_debug(l_proc_name, rec_cur_fetch_recs.ITEM_CATALOG_NAME||'**'||rec_cur_fetch_recs.icc_level);
9081   END LOOP;
9082 
9083 
9084   --- Append the Orphan records as the last level
9085   ---
9086    l_level := l_level + 1;
9087   FOR rec_orphan_icc IN cur_select_orph_recs
9088   LOOP
9089 
9090     l_icc_hier_tbl.extend;
9091     l_icc_hier_tbl(l_icc_hier_tbl.LAST)  := ego_ICC_Obj_Type (rec_orphan_icc.ITEM_CATALOG_NAME
9092                                                       , rec_orphan_icc.ITEM_CATALOG_GROUP_ID
9093                                                       , rec_orphan_icc.pARENT_CATALOG_GROUP_NAME
9094                                                       , rec_orphan_icc.PARENT_CATALOG_GROUP_ID
9095                                                       , rec_orphan_icc.TRANSACTION_TYPE
9096                                                       , rec_orphan_icc.TRANSACTION_ID
9097                                                       , l_level
9098                                                       );
9099 
9100   END LOOP;
9101 
9102 
9103   x_icc_hier_tbl := l_icc_hier_tbl;
9104 
9105   write_debug(l_proc_name, ' sql count =>'||l_count);
9106   write_debug(l_proc_name,' l_icc_hier_tbl.count =>'||l_icc_hier_tbl.count);
9107 
9108   x_no_levels := l_level;
9109 
9110 END Build_ICC_Hierarcy_From_Intf;
9111 
9112 
9113 /********************************************************************
9114  ---  This procedure concatenated the segment values based
9115  ---   on the KFF setup and updates the concatenated ICC name
9116  ---   to the interface table
9117  ---
9118 ********************************************************************/
9119 
9120 PROCEDURE Update_ICC_Name_Frm_Segs
9121 IS
9122 
9123   --- these records have passed the bulk validate phase
9124   ---
9125   CURSOR cur_update_name_frm_segs
9126   IS
9127     select micgi.*
9128     from MTL_ITEM_CAT_GRPS_INTERFACE micgi
9129     where item_catalog_name IS NULL
9130     AND   item_catalog_group_id  IS NULL
9131     AND  ( ( G_SET_PROCESS_ID IS NULL )
9132                 OR
9133               ( set_process_id =  G_SET_PROCESS_ID)
9134           )
9135      AND process_status = G_PROCESS_STATUS_INITIAL
9136      FOR UPDATE OF ITEM_CATALOG_NAME;
9137 
9138 
9139   l_proc_name        VARCHAR2(40) :=  'Update_ICC_Name_Frm_Segs';
9140   l_key_flex_field   fnd_flex_key_api.flexfield_type;
9141   l_structure_type   fnd_flex_key_api.structure_type;
9142   l_segment_type     fnd_flex_key_api.segment_type;
9143   l_segment_list     fnd_flex_key_api.segment_list;
9144   l_segment_array    fnd_flex_ext.SegmentArray;
9145   l_num_segments     NUMBER;
9146   l_flag             BOOLEAN;
9147   l_concat           VARCHAR2(2000);
9148 
9149 BEGIN
9150     write_debug(l_proc_name, 'Start ');
9151 
9152     fnd_flex_key_api.set_session_mode('seed_data');
9153 
9154     l_key_flex_field :=
9155         fnd_flex_key_api.find_flexfield( G_ITEM_CAT_KFF_APPL,
9156                                          G_ICC_KFF_NAME
9157                                        );
9158 
9159     l_structure_type :=
9160         fnd_flex_key_api.find_structure( l_key_flex_field,
9161                                          G_STRUCTURE_NUMBER
9162                                         );
9163 
9164     fnd_flex_key_api.get_segments(l_key_flex_field
9165                                 , l_structure_type
9166                                 , TRUE             -- GET enabled_segments only
9167                                 , l_num_segments
9168                                 , l_segment_list
9169                                   );
9170     write_debug(l_proc_name, 'KFF num of segments =>'||l_num_segments);
9171 
9172     FOR rec_icc_name_update in cur_update_name_frm_segs
9173     LOOP
9174         --
9175         -- The segments in the seg_list array are sorted in display order.
9176         -- i.e. sorted by segment number.
9177         --
9178         l_segment_array(1)  := CASE rec_icc_name_update.SEGMENT1 WHEN G_MISS_CHAR THEN NULL ELSE rec_icc_name_update.SEGMENT1 END;
9179         l_segment_array(2)  := CASE rec_icc_name_update.SEGMENT2 WHEN G_MISS_CHAR THEN NULL ELSE  rec_icc_name_update.SEGMENT2 END;
9180         l_segment_array(3)  := CASE rec_icc_name_update.SEGMENT3 WHEN G_MISS_CHAR THEN NULL ELSE  rec_icc_name_update.SEGMENT3 END;
9181         l_segment_array(4)  := CASE rec_icc_name_update.SEGMENT4 WHEN G_MISS_CHAR THEN NULL ELSE  rec_icc_name_update.SEGMENT4 END;
9182         l_segment_array(5)  := CASE rec_icc_name_update.SEGMENT5 WHEN G_MISS_CHAR THEN NULL ELSE  rec_icc_name_update.SEGMENT5 END;
9183         l_segment_array(6)  := CASE rec_icc_name_update.SEGMENT6 WHEN G_MISS_CHAR THEN NULL ELSE  rec_icc_name_update.SEGMENT6 END;
9184         l_segment_array(7)  := CASE rec_icc_name_update.SEGMENT7 WHEN G_MISS_CHAR THEN NULL ELSE  rec_icc_name_update.SEGMENT7 END;
9185         l_segment_array(8)  := CASE rec_icc_name_update.SEGMENT8 WHEN G_MISS_CHAR THEN NULL ELSE  rec_icc_name_update.SEGMENT8 END;
9186         l_segment_array(9)  := CASE rec_icc_name_update.SEGMENT9 WHEN G_MISS_CHAR THEN NULL ELSE  rec_icc_name_update.SEGMENT9 END;
9187         l_segment_array(10) := CASE rec_icc_name_update.SEGMENT10 WHEN G_MISS_CHAR THEN NULL ELSE rec_icc_name_update.SEGMENT10 END;
9188         l_segment_array(11) := CASE rec_icc_name_update.SEGMENT11 WHEN G_MISS_CHAR THEN NULL ELSE rec_icc_name_update.SEGMENT11 END;
9189         l_segment_array(12) := CASE rec_icc_name_update.SEGMENT12 WHEN G_MISS_CHAR THEN NULL ELSE rec_icc_name_update.SEGMENT12 END;
9190         l_segment_array(13) := CASE rec_icc_name_update.SEGMENT13 WHEN G_MISS_CHAR THEN NULL ELSE rec_icc_name_update.SEGMENT13 END;
9191         l_segment_array(14) := CASE rec_icc_name_update.SEGMENT14 WHEN G_MISS_CHAR THEN NULL ELSE rec_icc_name_update.SEGMENT14 END;
9192         l_segment_array(15) := CASE rec_icc_name_update.SEGMENT15 WHEN G_MISS_CHAR THEN NULL ELSE rec_icc_name_update.SEGMENT15 END;
9193         l_segment_array(16) := CASE rec_icc_name_update.SEGMENT16 WHEN G_MISS_CHAR THEN NULL ELSE rec_icc_name_update.SEGMENT16 END;
9194         l_segment_array(17) := CASE rec_icc_name_update.SEGMENT17 WHEN G_MISS_CHAR THEN NULL ELSE rec_icc_name_update.SEGMENT17 END;
9195         l_segment_array(18) := CASE rec_icc_name_update.SEGMENT18 WHEN G_MISS_CHAR THEN NULL ELSE rec_icc_name_update.SEGMENT18 END;
9196         l_segment_array(19) := CASE rec_icc_name_update.SEGMENT19 WHEN G_MISS_CHAR THEN NULL ELSE rec_icc_name_update.SEGMENT19 END;
9197         l_segment_array(20) := CASE rec_icc_name_update.SEGMENT20 WHEN G_MISS_CHAR THEN NULL ELSE rec_icc_name_update.SEGMENT20 END;
9198 
9199         --
9200         -- Now we have the all segment values in correct order in segarray.
9201         --
9202         l_concat := fnd_flex_ext.concatenate_segments(l_num_segments,
9203                                       l_segment_array,
9204                                       l_structure_type.segment_separator);
9205 
9206 
9207           update MTL_ITEM_CAT_GRPS_INTERFACE
9208           set item_catalog_name = l_concat
9209           WHERE CURRENT OF cur_update_name_frm_segs
9210           ;
9211 
9212     END LOOP;
9213 
9214  write_debug(l_proc_name, 'End... ');
9215 EXCEPTION
9216 WHEN OTHERS THEN
9217   RAISE;
9218 END  Update_ICC_Name_Frm_Segs;
9219 
9220 
9221 
9222 
9223 /********************************************************************
9224  ---  This procedure constructs the PL/SQL collection for the records
9225  ---    which have passed the initial bulk validation phase
9226  ---    , error records will be in status 3, 'valid' records will be in status 1
9227  ---
9228 ********************************************************************/
9229 
9230  PROCEDURE Construct_Colltn_And_Validate (  p_entity IN VARCHAR2
9231                                            ,p_icc_name IN VARCHAR2 DEFAULT NULL    --- Used by version processing
9232                                            ,p_icc_id   IN NUMBER DEFAULT NULL    --- Used by version processing
9233                                            ,p_icc_trans_type IN VARCHAR2 DEFAULT NULL  --- Added bug 12695479
9234                                            ,x_return_status OUT NOCOPY VARCHAR2
9235                                            ,x_return_msg  OUT NOCOPY VARCHAR2
9236                                          )
9237  IS
9238 
9239      l_ego_icc_tbl      ego_icc_tbl_type;
9240      l_ego_icc_hier_tbl ego_ICC_Hier_Tbl_Type := ego_ICC_Hier_Tbl_Type();
9241      l_counter          NUMBER := 0;
9242      l_level            NUMBER := 0;
9243      l_ag_assoc_tbl     ego_ag_assoc_tbl_type;
9244      l_func_params_tbl  ego_func_param_map_tbl_type;
9245      l_icc_vers_tbl     ego_icc_vers_tbl_type;
9246      l_proc_name      VARCHAR2(40) :=  'Construct_Colltn_And_Validate';
9247      e_stop_processing EXCEPTION;
9248      l_no_levels       NUMBER;
9249      l_call_from_icc_process VARCHAR2(1) := 'F';
9250      l_max_seq_id      NUMBER;
9251      l_max_ver_seq_id  NUMBER;
9252      l_msg_count       NUMBER;
9253      l_msg_data        VARCHAR2(2000);
9254      l_version_processed BOOLEAN := FALSE;
9255 
9256 
9257      ---
9258      --- Pick up the records with process_status = 1
9259      ---
9260      CURSOR cur_icc ( p_level NUMBER)
9261      is
9262      SELECT *
9263      FROM MTL_ITEM_CAT_GRPS_INTERFACE
9264      WHERE  (
9265               ( G_SET_PROCESS_ID IS NULL )
9266                 OR
9267               ( set_process_id =  G_SET_PROCESS_ID)
9268             )
9269      AND process_status = G_PROCESS_STATUS_INITIAL
9270      AND item_catalog_name IN (
9271                                         SELECT item_catalog_name
9272                                         FROM table ( cast (l_ego_icc_hier_tbl as ego_ICC_Hier_Tbl_Type) ) a
9273                                         WHERE a.icc_level = p_level
9274                                        )
9275       ;
9276 
9277      CURSOR cur_icc_no_hier
9278      is
9279      SELECT *
9280      FROM MTL_ITEM_CAT_GRPS_INTERFACE
9281      WHERE  (
9282               ( G_SET_PROCESS_ID IS NULL )
9283                 OR
9284               ( set_process_id =  G_SET_PROCESS_ID)
9285             )
9286      AND process_status = G_PROCESS_STATUS_INITIAL
9287      ;
9288 
9289 
9290 
9291      CURSOR cur_ag_assoc
9292      is
9293      SELECT *
9294      FROM EGO_ATTR_GRPS_ASSOC_INTERFACE
9295      WHERE  (
9296               ( G_SET_PROCESS_ID IS NULL )
9297                 OR
9298               ( set_process_id =  G_SET_PROCESS_ID)
9299             )
9300      AND process_status = G_PROCESS_STATUS_INITIAL ;
9301 
9302 
9303      --- Either process all the eligible version records
9304      --- or process them by passed ICC Name or ID
9305      ---
9306      CURSOR cur_icc_versions
9307      is
9308      SELECT *
9309      FROM EGO_ICC_VERS_INTERFACE
9310      WHERE process_status = G_PROCESS_STATUS_INITIAL
9311      AND (
9312               ( G_SET_PROCESS_ID IS NULL )
9313                 OR
9314               ( set_process_id =  G_SET_PROCESS_ID)
9315          )
9316      AND (
9317               ( p_icc_id IS NULL )
9318                 OR
9319               ( item_catalog_group_id =  p_icc_id)
9320          )
9321      AND (
9322               ( p_icc_name IS NULL )
9323                 OR
9324               ( item_catalog_name = p_icc_name)
9325          )
9326 
9327      ;
9328 
9329 
9330 
9331      CURSOR cur_icc_func_params
9332      is
9333      SELECT *
9334      FROM ego_func_params_map_interface
9335      WHERE  (
9336               ( G_SET_PROCESS_ID IS NULL )
9337                 OR
9338               ( set_process_id =  G_SET_PROCESS_ID)
9339             )
9340      AND process_status = G_PROCESS_STATUS_INITIAL;
9341 
9342 
9343      FUNCTION get_max_seq_id ( p_icc_id  NUMBER)
9344      RETURN NUMBER
9345 
9346      IS
9347        CURSOR cur_seq_id
9348        IS
9349        SELECT MAX(l.lock_id) lock_id
9350        FROM  EGO_OBJECT_LOCK l
9351        WHERE l.pk1_value = p_icc_id
9352        AND   l.object_name = G_ENTITY_ICC_LOCK
9353        ;
9354      BEGIN
9355        l_max_seq_id := 0;
9356        FOR rec_cur_seq_id in cur_seq_id loop
9357          l_max_seq_id := rec_cur_seq_id.lock_id;
9358        end loop;
9359 
9360        return l_max_seq_id;
9361 
9362      END;
9363 
9364 
9365  BEGIN
9366     write_debug (l_proc_name, 'Start of  '||l_proc_name);
9367     x_return_status    := G_RET_STS_SUCCESS;
9368 
9369    ---*************************
9370    --- ICC header
9371    ---
9372    IF p_entity = G_ENTITY_ICC_HEADER THEN
9373 
9374          --- get the concatenated segs for the ICC name from segment combination
9375          --- for those records where only segments are populated
9376          ---
9377          Update_ICC_Name_Frm_Segs;
9378 
9379          Build_ICC_Hierarcy_From_Intf  ( x_icc_hier_tbl => l_ego_icc_hier_tbl , x_no_levels => l_no_levels);
9380 
9381          IF l_ego_icc_hier_tbl.Count = 0 THEN
9382            write_debug (l_proc_name, 'No ICC Hierarchy to process');
9383          END IF;
9384 
9385      <<Level_Loop>>
9386      LOOP
9387          IF l_no_levels > 0 THEN
9388              EXIT WHEN  l_level > l_no_levels;
9389              OPEN cur_icc ( p_level => l_level);
9390          ELSE
9391              OPEN cur_icc_no_hier;
9392          END IF;
9393 
9394        <<Bulk_Limit_Loop>>
9395        LOOP
9396 
9397          IF l_no_levels > 0 THEN
9398             FETCH cur_icc BULK COLLECT INTO l_ego_icc_tbl LIMIT G_MAX_FETCH_SIZE;
9399          ELSE
9400             FETCH cur_icc_no_hier BULK COLLECT INTO l_ego_icc_tbl LIMIT G_MAX_FETCH_SIZE;
9401          END IF;
9402 
9403 
9404          write_debug(l_proc_name, 'icc tbl count=>'||l_ego_icc_tbl.count);
9405          Process_Entity (  p_entity         => G_ENTITY_ICC_HEADER
9406                       , p_icc_tbl        => l_ego_icc_tbl
9407                       , p_ag_assoc_tbl   => l_ag_assoc_tbl
9408                       , p_func_assoc_tbl => l_func_params_tbl
9409                       , p_icc_vers_tbl   => l_icc_vers_tbl
9410                       , x_return_status => x_return_status
9411                       , x_return_msg    => x_return_msg
9412                      ) ;
9413 
9414          IF x_return_status <> G_RET_STS_SUCCESS THEN
9415            RAISE e_stop_processing;
9416          END IF;
9417 
9418          l_counter := l_counter + l_ego_icc_tbl.count;
9419 
9420          IF l_counter >= G_MAX_FETCH_SIZE THEN
9421            COMMIT WORK;
9422            l_counter := 0;
9423          END IF;
9424 
9425          EXIT WHEN l_ego_icc_tbl.count < G_MAX_FETCH_SIZE;
9426        END LOOP Bulk_Limit_Loop;
9427 
9428        IF l_no_levels > 0 THEN
9429            CLOSE cur_icc;
9430            l_level := l_level + 1;
9431        ELSE
9432            CLOSE cur_icc_no_hier;
9433            EXIT;
9434        END IF;
9435 
9436      END LOOP Level_Loop;
9437 
9438 
9439 
9440      COMMIT WORK;  --- commit any remaining ICCs
9441 
9442 
9443 
9444    END IF;    --- End ICC
9445 
9446    ---*************************
9447    --- AG association
9448    ---
9449    IF p_entity = G_ENTITY_ICC_AG_ASSOC THEN
9450        OPEN cur_ag_assoc;
9451        LOOP
9452 
9453          FETCH cur_ag_assoc BULK COLLECT INTO l_ag_assoc_tbl LIMIT G_MAX_FETCH_SIZE;
9454 
9455          Process_Entity (  p_entity         => G_ENTITY_ICC_AG_ASSOC
9456                       , p_icc_tbl        => l_ego_icc_tbl
9457                       , p_ag_assoc_tbl   => l_ag_assoc_tbl
9458                       , p_func_assoc_tbl => l_func_params_tbl
9459                       , p_icc_vers_tbl   => l_icc_vers_tbl
9460                       , x_return_status => x_return_status
9461                       , x_return_msg    => x_return_msg
9462                      ) ;
9463 
9464 
9465          IF x_return_status <> G_RET_STS_SUCCESS THEN
9466            RAISE e_stop_processing;
9467          END IF;
9468 
9469          ---
9470          --- commit after every G_MAX_FETCH_SIZE records are processed
9471          ---
9472          COMMIT WORK;
9473 
9474          EXIT WHEN l_ag_assoc_tbl.count < G_MAX_FETCH_SIZE;
9475 
9476        END LOOP;
9477        CLOSE cur_ag_assoc;
9478    END IF;      --- AG association
9479 
9480    ---*************************
9481    --- Function params
9482    ---
9483    IF p_entity = G_ENTITY_ICC_FN_PARAM_MAP THEN
9484        OPEN cur_icc_func_params;
9485        LOOP
9486 
9487          FETCH cur_icc_func_params BULK COLLECT INTO l_func_params_tbl LIMIT G_MAX_FETCH_SIZE;
9488 
9489          Process_Entity (  p_entity         => G_ENTITY_ICC_FN_PARAM_MAP
9490                       , p_icc_tbl        => l_ego_icc_tbl
9491                       , p_ag_assoc_tbl   => l_ag_assoc_tbl
9492                       , p_func_assoc_tbl => l_func_params_tbl
9493                       , p_icc_vers_tbl   => l_icc_vers_tbl
9494                       , x_return_status => x_return_status
9495                       , x_return_msg    => x_return_msg
9496                      ) ;
9497 
9498 
9499          IF x_return_status <> G_RET_STS_SUCCESS THEN
9500            RAISE e_stop_processing;
9501          END IF;
9502 
9503          ---
9504          --- commit after every G_MAX_FETCH_SIZE records are processed
9505          ---
9506          COMMIT WORK;
9507 
9508          EXIT WHEN l_func_params_tbl.count < G_MAX_FETCH_SIZE;
9509        END LOOP;
9510        CLOSE cur_icc_func_params;
9511    END IF;      --- End funcion parameters
9512 
9513    ---*************************
9514    --- ICC Versions
9515    ---
9516    IF p_entity = G_ENTITY_ICC_VERSION THEN
9517 
9518        write_debug( l_proc_name, 'start of version processing');
9519 
9520         ---
9521         --- l_call_from_icc_process parameter is used to check if the locks are to be
9522         --- verified or Not, in case of CREATE ICC and associated versions in same
9523         --- run , locks need not be verified ,
9524         --- in case of UPDATE ICC and associated versions in the same run, Locks
9525         --- have to be checked
9526         ---
9527 
9528         --
9529         -- changed logic bug 12695479
9530 
9531        IF p_icc_trans_type IS NOT NULL
9532          AND p_icc_trans_type = G_TTYPE_CREATE
9533        THEN
9534          ---
9535          --- locks need not be checked
9536          ---
9537          l_call_from_icc_process := 'T';
9538        ELSE
9539          --- if p_icc_trans_type IS NULL
9540          --- or G_TTYPE_UPDATE then honour
9541          --- locks
9542          ---
9543         l_call_from_icc_process := 'F';
9544        END IF;
9545 
9546        WRITE_DEBUG(l_proc_name, 'G_ENTITY_ICC_VERSION ICC, ID=>'||p_icc_name||'*'||p_icc_id);
9547 
9548 
9549        OPEN cur_icc_versions;
9550        LOOP
9551 
9552          FETCH cur_icc_versions BULK COLLECT INTO l_icc_vers_tbl LIMIT G_MAX_FETCH_SIZE;
9553 
9554          Process_Entity (  p_entity         => G_ENTITY_ICC_VERSION
9555                       , p_icc_tbl        => l_ego_icc_tbl
9556                       , p_ag_assoc_tbl   => l_ag_assoc_tbl
9557                       , p_func_assoc_tbl => l_func_params_tbl
9558                       , p_icc_vers_tbl   => l_icc_vers_tbl
9559                       , p_call_from_icc_process => l_call_from_icc_process
9560                       , x_return_status => x_return_status
9561                       , x_return_msg    => x_return_msg
9562                      ) ;
9563 
9564 
9565          IF x_return_status <> G_RET_STS_SUCCESS THEN
9566            RAISE e_stop_processing;
9567          END IF;
9568          ---
9569          --- commit after every G_MAX_FETCH_SIZE records are processed
9570          ---
9571          COMMIT WORK;
9572 
9573          EXIT WHEN l_icc_vers_tbl.count < G_MAX_FETCH_SIZE;
9574        END LOOP;
9575        CLOSE cur_icc_versions;
9576 
9577        ---
9578        --- Sync the draft to the latest released version
9579        ---
9580        IF l_call_from_icc_process = 'T' AND l_icc_vers_tbl.count > 0 THEN
9581 
9582          --- loop to check if any of the version is processed successfully
9583          ---
9584          l_version_processed := FALSE;
9585          for i in 1..l_icc_vers_tbl.count loop
9586            if l_icc_vers_tbl(i).process_status = G_PROCESS_STATUS_INITIAL then
9587              l_version_processed := true;
9588              exit;
9589            end if;
9590          end loop;
9591 
9592          --- Get the max version id
9593          ---
9594          l_max_ver_seq_id := get_max_seq_id ( p_icc_id => p_icc_id);
9595          if l_max_ver_seq_id > 0 AND l_version_processed then --- only if it is non draft then sync
9596 
9597                   EGO_TRANSACTION_ATTRS_PVT.Revert_Transaction_Attribute (
9598                                             p_source_icc_id   => p_icc_id
9599                                            ,p_source_ver_no  => l_max_ver_seq_id
9600                                            ,p_init_msg_list  => FALSE
9601                                            ,x_return_status  => x_return_status
9602                                            ,x_msg_count      => l_msg_count
9603                                            ,x_msg_data       => l_msg_data
9604                                            );
9605 
9606                     IF x_return_status <> G_RET_STS_SUCCESS THEN
9607                         FND_MSG_PUB.RESET;  --- resets the message index pointer to top of table, since count_and_get is called in above api
9608 
9609                         FOR i in 1..l_msg_count LOOP
9610                           ERROR_HANDLER.Add_Error_Message(
9611                             p_message_text                  => FND_MSG_PUB.GET ( p_encoded => FND_API.G_FALSE)
9612                            ,p_application_id                => G_APPL_NAME
9613                            ,p_message_type                  => G_TYPE_ERROR
9614                            --,p_row_identifier
9615                            ,p_entity_code                   => G_ENTITY_ICC_VERSION
9616                            ,p_table_name                    => G_ENTITY_ICC_VERS_TAB
9617                           );
9618                         END LOOP;
9619                     END IF;
9620 
9621          end if; ---- l_max_ver_seq_id <> 0
9622 
9623 
9624        END IF;
9625 
9626 
9627    END IF;      --- End ICC Versions
9628 
9629 
9630 
9631 
9632    write_debug (l_proc_name, 'End of  '||l_proc_name);
9633  EXCEPTION
9634  WHEN e_stop_processing THEN
9635    IF cur_icc%ISOPEN THEN
9636      CLOSE cur_icc;
9637    END IF;
9638 
9639    IF cur_icc_no_hier%ISOPEN THEN
9640      CLOSE cur_icc_no_hier;
9641    END IF;
9642 
9643    IF cur_ag_assoc%ISOPEN THEN
9644      CLOSE cur_ag_assoc;
9645    END IF;
9646 
9647    IF cur_icc_func_params%ISOPEN THEN
9648      CLOSE cur_icc_func_params;
9649    END IF;
9650 
9651    IF cur_icc_versions%ISOPEN THEN
9652      CLOSE cur_icc_versions;
9653    END IF;
9654 
9655 
9656    write_debug(l_proc_name, ' Error while processing n '||G_PKG_NAME||'.'||l_proc_name||'->'||x_return_msg);
9657    RETURN;
9658  WHEN OTHERS THEN
9659    IF cur_icc%ISOPEN THEN
9660      CLOSE cur_icc;
9661    END IF;
9662 
9663    IF cur_icc_no_hier%ISOPEN THEN
9664      CLOSE cur_icc_no_hier;
9665    END IF;
9666 
9667    IF cur_ag_assoc%ISOPEN THEN
9668      CLOSE cur_ag_assoc;
9669    END IF;
9670 
9671    IF cur_icc_func_params%ISOPEN THEN
9672      CLOSE cur_icc_func_params;
9673    END IF;
9674    IF cur_icc_versions%ISOPEN THEN
9675      CLOSE cur_icc_versions;
9676    END IF;
9677 
9678    x_return_status := G_RET_STS_UNEXP_ERROR;
9679    x_return_msg := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
9680    write_debug(l_proc_name, x_return_msg);
9681    RETURN;
9682  END Construct_Colltn_And_Validate;
9683 
9684 
9685 /********************************************************************
9686    --- This procedure initializes the global variables
9687    --- used for processing across all procedures
9688    ---
9689 ********************************************************************/
9690 
9691 
9692 
9693   PROCEDURE Initialize (p_set_process_id IN  NUMBER
9694                         ,p_entity         IN VARCHAR2
9695 
9696                        )
9697   IS
9698     l_proc_name    VARCHAR2(30) := 'Initialize';
9699     l_sysdate      DATE := SYSDATE;
9700 
9701   BEGIN
9702 
9703      set_application_id; -- sets the EGO application id
9704 
9705       ---
9706       --- Set the g_set_process_id AND G_Flow_Type which will be used
9707       --- for selection of records everywhere
9708       ---
9709 
9710       G_SET_PROCESS_ID := p_set_process_id;
9711       G_Flow_Type      := G_EGO_MD_INTF;
9712       G_PARTY_ID       := GET_PARTY_ID ( G_USER_ID);
9713 
9714       G_P4TP_PROFILE_ENABLED := CASE FND_PROFILE.VALUE('EGO_ENABLE_P4T') WHEN 'Y' THEN TRUE
9715                                                ELSE FALSE END;
9716 
9717 
9718 
9719       IF p_entity = G_ENTITY_ICC_HEADER THEN
9720             write_debug(l_proc_name,'Inside header update ');
9721 
9722             UPDATE MTL_ITEM_CAT_GRPS_INTERFACE
9723             SET transaction_id = mtl_system_items_interface_s.nextval
9724                ,transaction_type = upper(transaction_type)
9725                ,creation_date = nvl(creation_date, l_sysdate)
9726                ,created_by    = NVL(created_by , G_USER_ID)
9727                ,last_updated_by = G_USER_ID
9728                ,last_update_login      = G_LOGIN_ID
9729                ,last_update_date       = l_sysdate
9730                ,request_id             = G_CONC_REQUEST_ID
9731                ,program_application_id = G_PROG_APPL_ID
9732                ,program_id             = G_PROGRAM_ID
9733                ,program_update_date    = l_sysdate
9734             WHERE (
9735                       ( G_SET_PROCESS_ID IS NULL )
9736                       OR
9737                       ( set_process_id =  G_SET_PROCESS_ID)
9738                   )
9739             AND transaction_id IS NULL
9740             AND process_status = G_PROCESS_STATUS_INITIAL
9741              ;
9742 
9743 
9744       ELSIF p_entity =  G_ENTITY_ICC_AG_ASSOC   THEN
9745 
9746              write_debug(l_proc_name,'start ag assoc update ');
9747 
9748             UPDATE EGO_ATTR_GRPS_ASSOC_INTERFACE
9749             SET transaction_id = mtl_system_items_interface_s.nextval
9750                ,transaction_type = upper(transaction_type)
9751                ,creation_date = nvl(creation_date, l_sysdate)
9752                ,created_by    = NVL(created_by , G_USER_ID)
9753                ,last_updated_by = G_USER_ID
9754                ,last_update_login      = G_LOGIN_ID
9755                ,LAST_UPDATE_DATE       = l_sysdate
9756                ,request_id             = G_CONC_REQUEST_ID
9757                ,program_application_id = G_PROG_APPL_ID
9758                ,program_id             = G_PROGRAM_ID
9759                ,program_update_date    = l_sysdate
9760             WHERE (
9761                       ( G_SET_PROCESS_ID IS NULL )
9762                       OR
9763                       ( set_process_id =  G_SET_PROCESS_ID)
9764                   )
9765             AND transaction_id IS NULL
9766             AND process_status = G_PROCESS_STATUS_INITIAL
9767             ;
9768 
9769 
9770       ELSIF p_entity =  G_ENTITY_ICC_FN_PARAM_MAP   THEN
9771 
9772             write_debug(l_proc_name,'start func param update ');
9773 
9774             UPDATE EGO_FUNC_PARAMS_MAP_INTERFACE
9775             SET transaction_id = mtl_system_items_interface_s.nextval
9776                ,transaction_type = upper(transaction_type)
9777                ,creation_date = nvl(creation_date, l_sysdate)
9778                ,created_by    = NVL(created_by , G_USER_ID)
9779                ,last_updated_by = G_USER_ID
9780                ,last_update_login      = G_LOGIN_ID
9781                ,LAST_UPDATE_DATE       = l_sysdate
9782                ,request_id             = G_CONC_REQUEST_ID
9783                ,program_application_id = G_PROG_APPL_ID
9784                ,program_id             = G_PROGRAM_ID
9785                ,program_update_date    = l_sysdate
9786             WHERE (
9787                       ( G_SET_PROCESS_ID IS NULL )
9788                       OR
9789                       ( set_process_id =  G_SET_PROCESS_ID)
9790                   )
9791             AND transaction_id IS NULL
9792             AND process_status = G_PROCESS_STATUS_INITIAL
9793             ;
9794 
9795       ELSIF p_entity =  G_ENTITY_ICC_VERSION   THEN
9796 
9797 
9798             write_debug(l_proc_name,'start icc vers update ');
9799 
9800             UPDATE EGO_ICC_VERS_INTERFACE
9801             SET transaction_id = mtl_system_items_interface_s.nextval
9802                ,transaction_type = upper(transaction_type)
9803                ,creation_date = nvl(creation_date, l_sysdate)
9804                ,created_by    = NVL(created_by , G_USER_ID)
9805                ,last_updated_by = G_USER_ID
9806                ,last_update_login      = G_LOGIN_ID
9807                ,LAST_UPDATE_DATE       = l_sysdate
9808                ,request_id             = G_CONC_REQUEST_ID
9809                ,program_application_id = G_PROG_APPL_ID
9810                ,program_id             = G_PROGRAM_ID
9811                ,program_update_date    = l_sysdate
9812             WHERE (
9813                       ( G_SET_PROCESS_ID IS NULL )
9814                       OR
9815                       ( set_process_id =  G_SET_PROCESS_ID)
9816                   )
9817             AND transaction_id IS NULL
9818             AND process_status = G_PROCESS_STATUS_INITIAL
9819             ;
9820 
9821       END IF;
9822 
9823   END Initialize;
9824 
9825 
9826 
9827 /********************************************************************
9828    --- Starting point of call for this package
9829    ---
9830 ********************************************************************/
9831 
9832    PROCEDURE Import_ICC_Intf
9833     (
9834        p_set_process_id            IN  NUMBER
9835     ,  x_return_status             OUT NOCOPY VARCHAR2
9836     ,  x_return_msg                OUT NOCOPY VARCHAR2
9837 
9838     )
9839     IS
9840 
9841       l_proc_name VARCHAR2(30) :=  'Import_ICC_Intf';
9842       e_unexpected_error    EXCEPTION;
9843 
9844     CURSOR cur_icc_count
9845     IS
9846     SELECT count(1) count
9847     FROM   MTL_ITEM_CAT_GRPS_INTERFACE
9848     WHERE (
9849               ( G_SET_PROCESS_ID IS NULL )
9850               OR
9851               ( set_process_id =  G_SET_PROCESS_ID)
9852           )
9853     AND transaction_id IS NOT NULL
9854     AND process_status = G_PROCESS_STATUS_INITIAL
9855      ;
9856 
9857 
9858     CURSOR cur_ag_assoc_count
9859     IS
9860     SELECT count(1) count
9861     FROM   EGO_ATTR_GRPS_ASSOC_INTERFACE
9862     WHERE (
9863               ( G_SET_PROCESS_ID IS NULL )
9864               OR
9865               ( set_process_id =  G_SET_PROCESS_ID)
9866           )
9867     AND transaction_id IS NOT NULL
9868     AND process_status = G_PROCESS_STATUS_INITIAL
9869      ;
9870 
9871 
9872     CURSOR cur_fn_map_count
9873     IS
9874     SELECT count(1) count
9875     FROM   EGO_FUNC_PARAMS_MAP_INTERFACE
9876     WHERE (
9877               ( G_SET_PROCESS_ID IS NULL )
9878               OR
9879               ( set_process_id =  G_SET_PROCESS_ID)
9880           )
9881     AND transaction_id IS NOT NULL
9882     AND process_status = G_PROCESS_STATUS_INITIAL
9883      ;
9884 
9885 
9886     CURSOR cur_icc_ver_count
9887     IS
9888     SELECT count(1) count
9889     FROM   EGO_ICC_VERS_INTERFACE
9890     WHERE (
9891               ( G_SET_PROCESS_ID IS NULL )
9892               OR
9893               ( set_process_id =  G_SET_PROCESS_ID)
9894           )
9895     AND transaction_id IS NOT NULL
9896     AND process_status = G_PROCESS_STATUS_INITIAL
9897      ;
9898 
9899 
9900     BEGIN
9901       x_return_status := G_RET_STS_SUCCESS;
9902 
9903 
9904       write_debug (l_proc_name, 'Start of  '||l_proc_name);
9905 
9906       --- GET THE item obj id
9907       ---
9908       FOR rec_item_obj_id IN cur_get_obj_id loop
9909         g_item_obj_id := rec_item_obj_id.object_id;
9910       end loop;
9911 
9912       ---
9913       --- initializing once since while calling ego_ext_fwk_pub APIS we need not initialize explicitly --
9914       --- changed during bug 9767869
9915       ---
9916       FND_MSG_PUB.initialize;
9917 
9918 
9919       write_debug (l_proc_name, 'Calling function metadata load');
9920       ----*************************
9921       ---- Functions metadata load
9922       ----*************************
9923 
9924       EGO_FUNCTIONS_BULKLOAD_PVT.import_functions_intf
9925                   (p_set_process_id => p_set_process_id
9926                   ,x_return_status  => x_return_status
9927                   ,x_return_msg     => x_return_msg
9928                   );
9929 
9930           IF x_return_status = G_RET_STS_UNEXP_ERROR THEN    --- we expect this API to return only S or U.
9931             RAISE e_unexpected_error;
9932           END IF;
9933 
9934       ----*************************
9935       --- ICC header
9936       ----*************************
9937       write_debug (l_proc_name, G_ENTITY_ICC_HEADER);
9938       ERROR_HANDLER.Set_Bo_Identifier(G_BO_IDENTIFIER_ICC);
9939 
9940       --- Initialize ICC Header and versions and TAs
9941       ---
9942       Initialize (p_set_process_id, G_ENTITY_ICC_HEADER) ;
9943       Initialize (p_set_process_id, G_ENTITY_ICC_VERSION);
9944       write_debug (l_proc_name, 'Calling TA Initialize');
9945       EGO_TA_BULKLOAD_PVT.Initialize  ( p_set_process_id => G_SET_PROCESS_ID
9946                                        ,x_return_status  => x_return_status
9947                                       );
9948 
9949       IF x_return_status = G_RET_STS_UNEXP_ERROR THEN
9950         write_debug (l_proc_name, 'Unexpected error in EGO_TA_BULKLOAD_PVT.Initialize');
9951         RAISE e_unexpected_error;
9952       END IF;
9953 
9954       ----************************
9955       ---- ICC Versions
9956       ----************************
9957       --- bulk validation required columns and ver_seq_no
9958       ---
9959 
9960       Bulk_Validate ( p_entity         => G_ENTITY_ICC_VERSION
9961                    ,  x_return_status  => x_return_status
9962                    ,  x_return_msg     => x_return_msg
9963                     );
9964       IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
9965          RAISE e_unexpected_error;
9966       END IF;
9967 
9968 
9969       ----**************************************
9970       --- Bulk validate TAs
9971       ----**************************************
9972       write_debug (l_proc_name, 'Calling TA Bulk_Validate_Trans_Attrs');
9973       EGO_TA_BULKLOAD_PVT.Bulk_Validate_Trans_Attrs ( p_set_process_id => G_SET_PROCESS_ID);
9974 
9975       --- store the number of records to process for each entity
9976       ---
9977       FOR rec_count IN cur_icc_count loop
9978         g_icc_rec_count := rec_count.COUNT;
9979       END LOOP;
9980 
9981       write_debug(l_proc_name, 'ICC HEADER count =>'||g_icc_rec_count);
9982 
9983       --- Call validation and import only if there are records to process
9984       ---
9985       IF g_icc_rec_count > 0 THEN
9986           Bulk_Validate ( p_entity         => G_ENTITY_ICC_HEADER
9987                        ,  x_return_status  => x_return_status
9988                        ,  x_return_msg     => x_return_msg
9989                         );
9990           IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
9991              RAISE e_unexpected_error;
9992           END IF;
9993 
9994 
9995           Construct_Colltn_And_Validate ( p_entity        => G_ENTITY_ICC_HEADER
9996                                       ,  x_return_status  => x_return_status
9997                                       ,  x_return_msg     => x_return_msg
9998                                       );
9999           IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
10000              RAISE e_unexpected_error;
10001           END IF;
10002       END IF;
10003 
10004 
10005       ----*************************
10006       --- AG assocs
10007       ----*************************
10008       write_debug (l_proc_name, G_ENTITY_ICC_AG_ASSOC);
10009 
10010       Initialize (p_set_process_id, G_ENTITY_ICC_AG_ASSOC) ;
10011 
10012       FOR rec_count IN cur_ag_assoc_count loop
10013         g_ag_assoc_rec_count := rec_count.COUNT;
10014       END LOOP;
10015 
10016       write_debug(l_proc_name, 'AG Assoc count =>'||g_ag_assoc_rec_count);
10017 
10018       --- Call validation and import only if there are records to process
10019       ---
10020       IF g_ag_assoc_rec_count > 0 THEN
10021           Bulk_Validate ( p_entity         => G_ENTITY_ICC_AG_ASSOC
10022                        ,  x_return_status  => x_return_status
10023                        ,  x_return_msg     => x_return_msg
10024                         );
10025           IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
10026              RAISE e_unexpected_error;
10027           END IF;
10028 
10029 
10030           Construct_Colltn_And_Validate ( p_entity        => G_ENTITY_ICC_AG_ASSOC
10031                                       ,  x_return_status  => x_return_status
10032                                       ,  x_return_msg     => x_return_msg
10033                                       );
10034           IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
10035              RAISE e_unexpected_error;
10036           END IF;
10037       END IF;
10038 
10039 
10040       ----*************************
10041       --- Function params
10042       ----*************************
10043 
10044       write_debug (l_proc_name, G_ENTITY_ICC_FN_PARAM_MAP);
10045 
10046       Initialize (p_set_process_id, G_ENTITY_ICC_FN_PARAM_MAP) ;
10047 
10048       FOR rec_count IN cur_fn_map_count loop
10049         g_fn_param_map_count := rec_count.COUNT;
10050       END LOOP;
10051 
10052       write_debug(l_proc_name, 'FN PARAM count =>'||g_fn_param_map_count);
10053 
10054       --- Call validation and import only if there are records to process
10055       ---
10056       IF g_fn_param_map_count > 0 THEN
10057 
10058           Bulk_Validate ( p_entity         => G_ENTITY_ICC_FN_PARAM_MAP
10059                        ,  x_return_status  => x_return_status
10060                        ,  x_return_msg     => x_return_msg
10061                         );
10062           IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
10063              RAISE e_unexpected_error;
10064           END IF;
10065 
10066 
10067           Construct_Colltn_And_Validate ( p_entity        => G_ENTITY_ICC_FN_PARAM_MAP
10068                                       ,  x_return_status  => x_return_status
10069                                       ,  x_return_msg     => x_return_msg
10070                                       );
10071           IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
10072              RAISE e_unexpected_error;
10073           END IF;
10074 
10075       END IF;
10076 
10077       ----*************************
10078       --- ICC Versions
10079       ----*************************
10080 
10081       write_debug (l_proc_name, G_ENTITY_ICC_VERSION);
10082 
10083       --- Call validation and import only if there are records to process
10084       ---
10085       FOR rec_count IN cur_icc_ver_count loop
10086         g_icc_vers_rec_count := rec_count.COUNT;
10087       END LOOP;
10088 
10089       write_debug(l_proc_name, 'ICC vers count =>'||g_icc_vers_rec_count);
10090 
10091 
10092       IF g_icc_vers_rec_count > 0 THEN
10093           --- Initialize the TA table
10094           ---
10095           /*
10096           --- Validations moved to row by row processing
10097           ---
10098           Bulk_Validate ( p_entity         => G_ENTITY_ICC_VERSION
10099                        ,  x_return_status  => x_return_status
10100                        ,  x_return_msg     => x_return_msg
10101                         );
10102           IF x_return_status =   G_RET_STS_UNEXP_ERROR THEN
10103              RAISE e_unexpected_error;
10104           END IF;
10105           */
10106 
10107           ERROR_HANDLER.Set_Bo_Identifier(G_BO_IDENTIFIER_ICC);
10108           Construct_Colltn_And_Validate ( p_entity        => G_ENTITY_ICC_VERSION
10109                                       ,  x_return_status  => x_return_status
10110                                       ,  x_return_msg     => x_return_msg
10111                                       );
10112           IF x_return_status = G_RET_STS_UNEXP_ERROR THEN
10113              RAISE e_unexpected_error;
10114           END IF;
10115 
10116        END IF;
10117 
10118 
10119 
10120       ----*************************
10121       ---- ICC Pages
10122       ----*************************
10123 
10124       write_debug (l_proc_name, 'Calling Pages metadata load');
10125       ego_pages_bulkload_pvt.import_pg_intf
10126                   ( p_set_process_id => p_set_process_id
10127                    ,x_return_status  => x_return_status
10128                    ,x_return_msg     => x_return_msg
10129                   );
10130 
10131           IF x_return_status = G_RET_STS_UNEXP_ERROR THEN    --- we expect this API to return only S or U.
10132             RAISE e_unexpected_error;
10133           END IF;
10134 
10135       Error_Handler.Log_Error(p_write_err_to_inttable => 'Y', p_write_err_to_conclog => 'Y'); -- bug 12380454
10136       write_debug (l_proc_name, 'End of  '||l_proc_name);
10137     EXCEPTION
10138     WHEN e_unexpected_error THEN
10139       write_debug(l_proc_name, x_return_msg);
10140       write_debug(l_proc_name, 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM);
10141       x_return_msg := x_return_msg||'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name;
10142       RETURN;
10143     WHEN OTHERS THEN
10144       x_return_status := G_RET_STS_UNEXP_ERROR;
10145       write_debug(l_proc_name, 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM);
10146       x_return_msg := NVL(x_return_msg,'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM);
10147       ROLLBACK;
10148       RETURN;
10149     END Import_ICC_Intf;
10150 
10151     ---
10152     --- Procedure to delete the processed records
10153     --- from the various interface tables
10154     ---
10155 
10156     PROCEDURE Delete_Processed_ICC  ( p_set_process_id  IN NUMBER
10157                                    ,  x_return_status    OUT NOCOPY VARCHAR2
10158                                    ,  x_return_msg       OUT NOCOPY VARCHAR2
10159     )
10160     IS
10161 
10162 
10163       l_proc_name     VARCHAR2(30) := 'Delete_Processed_ICC';
10164    BEGIN
10165      x_return_status := G_RET_STS_SUCCESS;
10166 
10167      DELETE FROM MTL_ITEM_CAT_GRPS_INTERFACE
10168        WHERE transaction_id IS NOT NULL
10169        AND process_status = G_PROCESS_STATUS_SUCCESS
10170        AND (
10171               ( G_SET_PROCESS_ID IS NULL )
10172                 OR
10173               ( set_process_id =  G_SET_PROCESS_ID)
10174             );
10175 
10176 
10177      DELETE FROM EGO_ATTR_GRPS_ASSOC_INTERFACE
10178        WHERE transaction_id IS NOT NULL
10179        AND process_status = G_PROCESS_STATUS_SUCCESS
10180        AND (
10181               ( G_SET_PROCESS_ID IS NULL )
10182                 OR
10183               ( set_process_id =  G_SET_PROCESS_ID)
10184             );
10185 
10186 
10187 
10188      DELETE FROM EGO_ICC_VERS_INTERFACE
10189        WHERE transaction_id IS NOT NULL
10190        AND process_status = G_PROCESS_STATUS_SUCCESS
10191        AND (
10192               ( G_SET_PROCESS_ID IS NULL )
10193                 OR
10194               ( set_process_id =  G_SET_PROCESS_ID)
10195             );
10196 
10197 
10198 
10199      DELETE FROM ego_func_params_map_interface
10200        WHERE transaction_id IS NOT NULL
10201        AND process_status = G_PROCESS_STATUS_SUCCESS
10202        AND (
10203               ( G_SET_PROCESS_ID IS NULL )
10204                 OR
10205               ( set_process_id =  G_SET_PROCESS_ID)
10206             );
10207 
10208 
10209    EXCEPTION
10210    WHEN OTHERS THEN
10211      ROLLBACK;
10212      x_return_status := G_RET_STS_UNEXP_ERROR;
10213      x_return_msg  := 'Unexpected error in '||G_PKG_NAME||'.'||l_proc_name||'->'||SQLERRM;
10214      write_debug(l_proc_name ,x_return_msg);
10215      RETURN;
10216    END Delete_Processed_Icc;
10217 
10218 
10219  END EGO_ICC_BULKLOAD_PVT;