DBA Data[Home] [Help]

PACKAGE BODY: APPS.BOM_VALIDATE_SUB_OP_RES

Source


1 PACKAGE BODY BOM_Validate_Sub_Op_Res AS
2 /* $Header: BOMLSORB.pls 120.6 2011/12/06 10:35:58 rambkond ship $ */
3 
4 /****************************************************************************
5 --
6 --  Copyright (c) 2000 Oracle Corporation, Redwood Shores, CA, USA
7 --  All rights reserved.
8 --
9 --  FILENAME
10 --
11 --     BOMLSORB.pls
12 --
13 --  DESCRIPTION
14 --
15 --      Body of package BOM_Validate_Sub_Op_Res
16 --
17 --  NOTES
18 --
19 --  HISTORY
20 --
21 --  22-AUG-00   Masanori Kimizuka Initial Creation
22 --  08-DEC-2005 Bhavnesh Patel    4689856:Validation for new column new_basis_type
23 ****************************************************************************/
24 
25     G_Pkg_Name      VARCHAR2(30) := 'BOM_Validate_Sub_Op_Res';
26 
27     l_ACD_ADD                     CONSTANT NUMBER := 1 ;
28     l_ACD_CHANGE                  CONSTANT NUMBER := 2 ;
29     l_ACD_DISABLE                 CONSTANT NUMBER := 3 ;
30     l_NO_SCHEDULE                 CONSTANT NUMBER := 2 ;
31     l_PRIOR                       CONSTANT NUMBER := 3 ;
32     l_NEXT                        CONSTANT NUMBER := 4 ;
33     l_PO_RECEIPT                  CONSTANT NUMBER := 3 ;
34     l_PO_MOVE                     CONSTANT NUMBER := 4 ;
35 
36 
37     /******************************************************************
38     * OTHER LOCAL FUNCTION AND PROCEDURES
39     * Purpose       : Called by Check_Entity or something
40     *********************************************************************/
41     --
42     -- Function: Check if Op Seq Num exists in Work Order
43     --           in ECO by Lot, Wo, Cum Qty
44     --
45     FUNCTION Check_ECO_By_WO_Effectivity
46              ( p_revised_item_sequence_id IN  NUMBER
47              , p_operation_seq_num        IN  NUMBER
48              , p_resource_id              IN  NUMBER
49              , p_sub_group_num            IN  NUMBER )
50 
51     RETURN BOOLEAN
52     IS
53        l_ret_status BOOLEAN := TRUE ;
54 
55        l_lot_number varchar2(30) := NULL;
56        l_from_wip_entity_id NUMBER :=0;
57        l_to_wip_entity_id NUMBER :=0;
58        l_from_cum_qty  NUMBER :=0;
59 
60 /*     Rewrote the cursor for BUG 4918694
61        CURSOR  l_check_lot_num_csr ( p_lot_number         NUMBER
62                                    , p_operation_seq_num  NUMBER
63                                    , p_resource_id        NUMBER
64                                    , p_sub_group_num      NUMBER )
65        IS
66           SELECT 'Sub Res does not exist'
67           FROM   SYS.DUAL
68           WHERE  EXISTS (SELECT  NULL
69                          FROM    WIP_DISCRETE_JOBS  wdj
70                          WHERE   wdj.lot_number = p_lot_number
71                          AND     (wdj.status_type <> 1
72                                   OR
73                                   NOT EXISTS(SELECT NULL
74                                              FROM   WIP_SUB_OPERATION_RESOURCES wsor
75                                              WHERE  substitute_group_num = p_sub_group_num
76                                              AND    resource_id          = p_resource_id
77                                              AND    operation_seq_num = p_operation_seq_num
78                                              AND    wip_entity_id     = wdj.wip_entity_id)
79                                   )
80                          AND      wdj.lot_number = p_lot_number
81                         ) ;
82 */
83 
84        CURSOR  l_check_lot_num_csr ( p_lot_number         NUMBER
85                                    , p_operation_seq_num  NUMBER
86                                    , p_resource_id        NUMBER
87                                    , p_sub_group_num      NUMBER )
88        IS
89           SELECT 'Sub Res does not exist'
90           FROM  DUAL
91           WHERE NOT EXISTS ( SELECT  NULL
92                              FROM    WIP_DISCRETE_JOBS  wdj
93                              WHERE   wdj.lot_number = p_lot_number
94                              AND     wdj.status_type = 1
95                              AND EXISTS ( SELECT NULL
96                                           FROM   WIP_SUB_OPERATION_RESOURCES wsor
97                                           WHERE  substitute_group_num = p_sub_group_num
98                                           AND    resource_id          = p_resource_id
99                                           AND    operation_seq_num    = p_operation_seq_num
100                                           AND    wip_entity_id        = wdj.wip_entity_id
101                                         )
102                            );
103 
104        CURSOR  l_check_wo_csr (  p_from_wip_entity_id NUMBER
105                                , p_to_wip_entity_id   NUMBER
106                                , p_operation_seq_num  NUMBER
107                                , p_resource_id        NUMBER
108                                , p_sub_group_num      NUMBER )
109        IS
110           SELECT 'Sub Res does not exist'
111           FROM   SYS.DUAL
112           WHERE  EXISTS (SELECT  NULL
113                          FROM    WIP_DISCRETE_JOBS  wdj
114                                , WIP_ENTITIES       we
115                                , WIP_ENTITIES       we1
116                                , WIP_ENTITIES       we2
117                          WHERE   (wdj.status_type <> 1
118                                   OR
119                                   NOT EXISTS (SELECT NULL
120                                               FROM   WIP_SUB_OPERATION_RESOURCES wsor
121                                               WHERE  substitute_group_num = p_sub_group_num
122                                               AND    resource_id          = p_resource_id
123                                               AND    operation_seq_num = p_operation_seq_num
124                                               AND    wip_entity_id     = wdj.wip_entity_id)
125                                  )
126                          AND     wdj.wip_entity_id = we.wip_entity_id
127                          AND     we.wip_entity_name >= we1.wip_entity_name
128                          AND     we.wip_entity_name <= we2.wip_entity_name
129                          AND     we1.wip_entity_id = p_from_wip_entity_id
130                          AND     we2.wip_entity_id = NVL(p_to_wip_entity_id, p_from_wip_entity_id)
131                          ) ;
132 
133       CURSOR  l_check_cum_csr (  p_from_wip_entity_id NUMBER
134                                , p_operation_seq_num  NUMBER
135                                , p_resource_id        NUMBER
136                                , p_sub_group_num      NUMBER )
137 
138 
139        IS
140           SELECT 'Sub Res does not exist'
141           FROM   SYS.DUAL
142           WHERE  EXISTS (SELECT  NULL
143                          FROM    WIP_DISCRETE_JOBS  wdj
144                          WHERE   (wdj.status_type <> 1
145                                   OR
146                                   NOT EXISTS(SELECT NULL
147                                              FROM   WIP_SUB_OPERATION_RESOURCES wsor
148                                              WHERE  substitute_group_num = p_sub_group_num
149                                              AND    resource_id          = p_resource_id
150                                              AND    operation_seq_num = p_operation_seq_num
151                                              AND    wip_entity_id     = wdj.wip_entity_id)
152                                  )
153                          AND     wdj.wip_entity_id = p_from_wip_entity_id
154                          ) ;
155 
156     BEGIN
157 
158 
159        l_lot_number := BOM_Rtg_Globals.Get_Lot_Number;
160        l_from_wip_entity_id := BOM_Rtg_Globals.Get_From_Wip_Entity_Id;
161        l_to_wip_entity_id := BOM_Rtg_Globals.Get_To_Wip_Entity_Id;
162        l_from_cum_qty := BOM_Rtg_Globals.Get_From_Cum_Qty;
163 
164 
165           -- Check if Op Seq Num is exist in ECO by Lot
166           IF    l_lot_number         IS NOT NULL
167            AND  l_from_wip_entity_id IS NULL
168            AND  l_to_wip_entity_id   IS NULL
169            AND  l_from_cum_qty       IS NULL
170           THEN
171 
172              FOR l_lot_num_rec IN l_check_lot_num_csr
173                                ( p_lot_number        => l_lot_number
174                                , p_operation_seq_num => p_operation_seq_num
175                                , p_resource_id       => p_resource_id
176                                , p_sub_group_num     => p_sub_group_num )
177              LOOP
178                  l_ret_status  := FALSE ;
179              END LOOP ;
180 
181           -- Check if Op Seq Num is exist  in ECO by Cum
182           ELSIF   l_lot_number         IS NULL
183            AND    l_from_wip_entity_id IS NOT NULL
184            AND    l_to_wip_entity_id   IS NULL
185            AND    l_from_cum_qty       IS NOT NULL
186           THEN
187 
188              FOR l_lot_num_rec IN l_check_cum_csr
189                                ( p_from_wip_entity_id => l_from_wip_entity_id
190                                , p_operation_seq_num  => p_operation_seq_num
191                                , p_resource_id        => p_resource_id
192                                , p_sub_group_num      => p_sub_group_num )
193              LOOP
194                  l_ret_status  := FALSE ;
195              END LOOP ;
196 
197           -- Check if Op Seq Num is exist  in ECO by WO
198           ELSIF   l_lot_number         IS NULL
199            AND    l_from_wip_entity_id IS NOT NULL
200            AND    l_from_cum_qty       IS NULL
201           THEN
202 
203              FOR l_lot_num_rec IN l_check_wo_csr
204                                ( p_from_wip_entity_id => l_from_wip_entity_id
205                                , p_to_wip_entity_id   => l_to_wip_entity_id
206                                , p_operation_seq_num  => p_operation_seq_num
207                                , p_resource_id        => p_resource_id
208                                , p_sub_group_num      => p_sub_group_num )
209              LOOP
210                  l_ret_status  := FALSE ;
211              END LOOP ;
212 
213           ELSIF   l_lot_number         IS NULL
214            AND    l_from_wip_entity_id IS NULL
215            AND    l_to_wip_entity_id   IS NULL
216            AND    l_from_cum_qty       IS NULL
217           THEN
218              NULL ;
219 
220           --  ELSE
221           --     l_ret_status  := FALSE ;
222           --
223 
224           END IF ;
225 
226        RETURN l_ret_status ;
227 
228     END Check_ECO_By_WO_Effectivity ;
229 
230 
231     /*******************************************************************
232     *Others    :     Following Procedures and Functions are called by
233     *                Check_Entity in Op Resource and Sub Op Resource
234     *Purpose   :     These Shared Logic validate the values on
235     *                inter-dependent columns or get values to validate entity.
236     *******************************************************************/
237     PROCEDURE   Val_Scheduled_Sub_Resource
238     ( p_op_seq_id     IN  NUMBER
239     , p_resource_id   IN  NUMBER
240     , p_sub_group_num IN  NUMBER
241     , p_schedule_flag IN  NUMBER
242     , x_return_status IN OUT NOCOPY VARCHAR2
243     )
244     IS
245 
246        CURSOR l_rel_schedule_csr
247                              ( p_op_seq_id      NUMBER
248                              , p_sub_group_num  NUMBER
249                              , p_schedule_flag  NUMBER
250                              )
251        IS
252           SELECT 'Related Schedule Resource does not exist'
253           FROM   SYS.DUAL
254           WHERE  NOT EXISTS( SELECT NULL
255                              FROM   BOM_OPERATION_RESOURCES
256                              WHERE  schedule_flag         = p_schedule_flag
257                              AND    substitute_group_num  = p_sub_group_num
258                              AND    operation_sequence_id = p_op_seq_id
259                             ) ;
260 
261        CURSOR l_sub_schedule_csr
262                              ( p_op_seq_id      NUMBER
263                              , p_resource_id    NUMBER
264                              , p_sub_group_num  NUMBER
265                              , p_schedule_flag  NUMBER
266                              )
267        IS
268           SELECT 'Already exists'
269           FROM   SYS.DUAL
270           WHERE  EXISTS( SELECT NULL
271                          FROM   BOM_SUB_OPERATION_RESOURCES
272                          WHERE  schedule_flag         =  p_schedule_flag
273                          AND    resource_id           <> p_resource_id
274                          AND    substitute_group_num  =  p_sub_group_num
275                          AND    operation_sequence_id =  p_op_seq_id
276                         ) ;
277 
278 
279     BEGIN
280 
281        x_return_status := FND_API.G_RET_STS_SUCCESS ;
282 
283        FOR l_rel_schedule_rec IN l_rel_schedule_csr
284                                         ( p_op_seq_id
285                                         , p_sub_group_num
286                                         , p_schedule_flag
287                                         )
288        LOOP
289           x_return_status := FND_API.G_RET_STS_ERROR ;
290        END LOOP ;
291 
292        IF x_return_status <> FND_API.G_RET_STS_ERROR
293        THEN
294           FOR l_sub_schedule_rec IN l_sub_schedule_csr
295                                            (  p_op_seq_id
296                                             , p_resource_id
297                                             , p_sub_group_num
298                                             , p_schedule_flag
299                                             )
300           LOOP
301              x_return_status := FND_API.G_RET_STS_ERROR ;
302           END LOOP ;
303        END IF ;
304 
305     END Val_Scheduled_Sub_Resource ;
306 
307 
308     PROCEDURE   Val_Sub_PO_Move
309     ( p_op_seq_id     IN  NUMBER
310     , p_resource_id   IN  NUMBER
311     , p_sub_group_num IN  NUMBER
312     , x_return_status IN OUT NOCOPY VARCHAR2
313     )
314     IS
315 
316        CURSOR l_rel_pomove_csr
317                              ( p_op_seq_id      NUMBER
318                              , p_sub_group_num  NUMBER
319                              )
320        IS
321           SELECT 'Related PO Move Resource does not exist'
322           FROM   SYS.DUAL
323           WHERE  NOT EXISTS( SELECT NULL
324                              FROM   BOM_OPERATION_RESOURCES
325                              WHERE  autocharge_type       = l_PO_MOVE
326                              AND    substitute_group_num  = p_sub_group_num
327                              AND    operation_sequence_id = p_op_seq_id
328                             ) ;
329 
330        CURSOR l_sub_pomove_csr(  p_op_seq_id     NUMBER
331                                , p_resource_id   NUMBER
332                                , p_sub_group_num NUMBER )
333 
334        IS
335           SELECT 'Already exists'
336           FROM   SYS.DUAL
337           WHERE  EXISTS( SELECT NULL
338                          FROM   BOM_SUB_OPERATION_RESOURCES
339                          WHERE  autocharge_type       =  l_PO_MOVE
340                          AND    resource_id           <> p_resource_id
341                          AND    substitute_group_num  =  p_sub_group_num
342                          AND    operation_sequence_id =  p_op_seq_id
343                         ) ;
344 
345 
346     BEGIN
347 
348        x_return_status := FND_API.G_RET_STS_SUCCESS ;
349 
350        FOR l_rel_pomove_rec IN l_rel_pomove_csr
351                                         ( p_op_seq_id
352                                         , p_sub_group_num
353                                         )
354        LOOP
355           x_return_status := FND_API.G_RET_STS_ERROR ;
356        END LOOP ;
357 
358        IF x_return_status <> FND_API.G_RET_STS_ERROR
359        THEN
360           FOR l_sub_pomove_rec IN l_sub_pomove_csr (  p_op_seq_id
361                                                     , p_resource_id
362                                                     , p_sub_group_num
363                                                     )
364           LOOP
365                  x_return_status := FND_API.G_RET_STS_ERROR ;
366           END LOOP ;
367        END IF ;
368 
369     END Val_Sub_PO_Move ;
370 
371     --
372     -- Function: Get_Old_Op_Seq_Id
373     --
374     FUNCTION  Get_Old_Op_Seq_Id(p_op_seq_id IN NUMBER )
375        RETURN NUMBER
376     IS
377         l_old_op_seq_id NUMBER := NULL ;
378     BEGIN
379 
380         SELECT old_operation_sequence_id
381         INTO   l_old_op_seq_id
382         FROM   BOM_OPERATION_SEQUENCES
383         WHERE  operation_sequence_id = p_op_seq_id ;
384 
385         RETURN l_old_op_seq_id ;
386 
387         /* Error should be processed as Unexpected Error */
388 
389     END ;
390 
391 -- Added for bug 2689249
392     -- bug:4689856 Included a check on basis type for identifying sub resource
393     PROCEDURE Val_Principal_Sub_Res_Unique
394     ( p_op_seq_id     IN NUMBER
395     , p_res_id	      IN NUMBER
396     , p_sub_group_num IN NUMBER
397     , p_rep_group_num IN NUMBER
398     , p_basis_type    IN NUMBER
399     , p_schedule_flag IN NUMBER  /* Added new parameter for bug 13005178 */
400     , x_return_status IN OUT NOCOPY VARCHAR2
401     )
402     IS
403        CURSOR l_principal_csr   ( p_op_seq_id     NUMBER
404                                , p_res_id	  NUMBER
405                                , p_sub_group_num  NUMBER
406                                , p_rep_group_num  NUMBER
407                                , p_basis_type     NUMBER
408                                , p_schedule_flag  NUMBER  /* Added for bug 13005178 */
409                                )
410        IS
411           SELECT 'Already exists'
412           FROM   SYS.DUAL
413           WHERE  EXISTS( SELECT NULL
414                          FROM   BOM_SUB_OPERATION_RESOURCES
415                          WHERE  principle_flag = 1 -- Yes
416                          AND    NVL(acd_type, l_ACD_ADD) <> l_ACD_DISABLE
417                          AND    (
418                                     ( resource_id <> p_res_id )
419                                 OR  ( ( resource_id = p_res_id )
420                                       AND ( basis_type <> p_basis_type
421                                            OR schedule_flag <> p_schedule_flag ) ) /* Added for bug 13005178 */
422                                 )
423                          AND    substitute_group_num  = p_sub_group_num
424                          AND    replacement_group_num = p_rep_group_num
425                          AND    operation_sequence_id = p_op_seq_id
426                         ) ;
427 
428     BEGIN
429 
430        x_return_status := FND_API.G_RET_STS_SUCCESS ;
431 
432        FOR l_principal_rec IN l_principal_csr ( p_op_seq_id
433                                             , p_res_id
434                                             , p_sub_group_num
435                                             , p_rep_group_num
436                                             , p_basis_type
437                                             , p_schedule_flag  /* Added for bug 13005178 */
438                                             )
439        LOOP
440           x_return_status := FND_API.G_RET_STS_ERROR ;
441        END LOOP ;
442 
443 /*
444        IF BOM_Rtg_Globals.Get_Bo_Identifier = BOM_Rtg_Globals.G_ECO_BO
445        THEN
446 	  null; -- Substitute resources cannot be added from ECOs
447        END IF ;
448 */
449 
450     END Val_Principal_Sub_Res_Unique ;
451 
452   /*Fix for bug 6074930 -Added below procedure Val_schedule_flag.
453      It is called by procedure Check_Entity.
454      Purpose: Scheduled simultaneous resources/sub-resources should have the
455      same scheduling flag. Resources/sub-resources with schedule flag 'No'
456      are unscheduled and hence exempt for this validation.*/
457 
458      PROCEDURE Val_Schedule_Flag
459     (  p_op_seq_id     IN  NUMBER
460      , p_res_seq_num   IN  NUMBER
461      , p_sch_seq_num   IN  NUMBER
462      , p_sch_flag      IN  NUMBER
463      , p_sub_grp_num   IN  NUMBER
464      , p_rep_grp_num   IN  NUMBER
465      , p_basis_type    IN  NUMBER
466      , p_in_res_id     IN  NUMBER
467      , p_ret_res_id    IN OUT NOCOPY NUMBER
468      , x_return_status IN OUT NOCOPY VARCHAR2
469      )
470      IS
471        l_resource_id number;
472 
473        CURSOR l_sch_res_cur IS
474        SELECT resource_id
475        FROM   bom_operation_resources
476        WHERE  operation_sequence_id = p_op_seq_id
477        AND    nvl(schedule_seq_num,resource_seq_num) = p_sch_seq_num
478        AND    schedule_flag not in (p_sch_flag,l_NO_SCHEDULE)
479        AND    rownum=1;
480 
481        CURSOR l_sch_sub_res_cur IS
482        SELECT resource_id
483        FROM   bom_sub_operation_resources
484        WHERE  operation_sequence_id = p_op_seq_id
485        AND    schedule_seq_num      = p_sch_seq_num
486        AND    schedule_flag not in (p_sch_flag,l_NO_SCHEDULE)
487        AND    (
488                    substitute_group_num  <> p_sub_grp_num
489                OR  replacement_group_num <> p_rep_grp_num
490                OR        basis_type              <> p_basis_type
491                OR        resource_id              <> p_in_res_id
492                )
493        AND    rownum=1;
494 
495      BEGIN
496             x_return_status := FND_API.G_RET_STS_SUCCESS;
497             l_resource_id   := FND_API.G_MISS_NUM;
498 
499             /* Verify whether the current sub-resource violates the validation w.r.t to
500                any existing resource. */
501             OPEN  l_sch_res_cur;
502             FETCH l_sch_res_cur INTO l_resource_id;
503 
504             /* Return error status if violation occurs */
505             IF l_sch_res_cur%FOUND THEN
506                    p_ret_res_id        := l_resource_id;
507                    x_return_status := Error_Handler.G_STATUS_ERROR;
508             END IF;
509 
510             IF l_sch_res_cur%ISOPEN THEN
511                     CLOSE l_sch_res_cur;
512             END IF;
513 
514             /* If no violated resource is found above, then verify whether the current sub-resource
515                violates the validation w.r.t to any existing sub-resource. */
516            IF x_return_status = FND_API.G_RET_STS_SUCCESS THEN
517 
518                    OPEN  l_sch_sub_res_cur;
519                    FETCH l_sch_sub_res_cur INTO l_resource_id;
520 
521                    /* Return error status if violation occurs */
522                    IF l_sch_sub_res_cur%FOUND THEN
523                            p_ret_res_id        := l_resource_id;
524                            x_return_status := Error_Handler.G_STATUS_ERROR;
525                    END IF;
526 
527                    IF l_sch_sub_res_cur%ISOPEN THEN
528                            CLOSE l_sch_sub_res_cur;
529                    END IF;
530 
531            END IF;
532 
533      END Val_Schedule_Flag;
534 
535 
536     /******************************************************************
537     * Procedure     : Check_Existence used by RTG BO
538     * Parameters IN : Sub Operation Resource exposed column record
539     *                 Sub Operation Resource unexposed column record
540     * Parameters out: Old Sub Operation Resource exposed column record
541     *                 Old Sub Operation Resource unexposed column record
542     *                 Mesg Token Table
543     *                 Return Status
544     * Purpose       : Convert Routing Sub Op Resource to Revised Sub Op
545     *                 Resource and Call Check_Existence for ECO Bo.
546     *                 After calling Check_Existence, convert old Revised
547     *                 Op Resource record back to Routing Op Resource
548     *********************************************************************/
549     PROCEDURE Check_Existence
550     (  p_sub_resource_rec        IN  Bom_Rtg_Pub.Sub_Resource_Rec_Type
551      , p_sub_res_unexp_rec       IN  Bom_Rtg_Pub.Sub_Res_Unexposed_Rec_Type
552      , x_old_sub_resource_rec    IN OUT NOCOPY Bom_Rtg_Pub.Sub_Resource_Rec_Type
553      , x_old_sub_res_unexp_rec   IN OUT NOCOPY Bom_Rtg_Pub.Sub_Res_Unexposed_Rec_Type
554      , x_mesg_token_tbl          IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
555      , x_return_status           IN OUT NOCOPY VARCHAR2
556     )
557 
558    IS
559         l_rev_sub_resource_rec      Bom_Rtg_Pub.Rev_Sub_Resource_rec_Type ;
560         l_rev_sub_res_unexp_rec     Bom_Rtg_Pub.Rev_Sub_Res_Unexposed_Rec_Type ;
561         l_old_rev_sub_resource_rec  Bom_Rtg_Pub.Rev_Sub_Resource_rec_Type ;
562         l_old_rev_sub_res_unexp_rec Bom_Rtg_Pub.Rev_Sub_Res_Unexposed_Rec_Type ;
563 
564     BEGIN
565         -- Convert Routing Operation to ECO Operation
566         Bom_Rtg_Pub.Convert_RtgSubRes_To_EcoSubRes
567         (  p_rtg_sub_resource_rec      => p_sub_resource_rec
568          , p_rtg_sub_res_unexp_rec     => p_sub_res_unexp_rec
569          , x_rev_sub_resource_rec      => l_rev_sub_resource_rec
570          , x_rev_sub_res_unexp_rec     => l_rev_sub_res_unexp_rec
571         ) ;
572 
573         -- Call Check_Existence
574         Bom_Validate_Sub_Op_Res.Check_Existence
575         (  p_rev_sub_resource_rec      => l_rev_sub_resource_rec
576          , p_rev_sub_res_unexp_rec     => l_rev_sub_res_unexp_rec
577          , x_old_rev_sub_resource_rec  => l_old_rev_sub_resource_rec
578          , x_old_rev_sub_res_unexp_rec => l_old_rev_sub_res_unexp_rec
579          , x_return_status             => x_return_status
580          , x_mesg_token_tbl            => x_mesg_token_tbl
581         ) ;
582 
583         -- Convert old Eco Opeartion Record back to Routing Operation
584         Bom_Rtg_Pub.Convert_EcoSubRes_To_RtgSubRes
585         (  p_rev_sub_resource_rec      => l_old_rev_sub_resource_rec
586          , p_rev_sub_res_unexp_rec     => l_old_rev_sub_res_unexp_rec
587          , x_rtg_sub_resource_rec      => x_old_sub_resource_rec
588          , x_rtg_sub_res_unexp_rec     => x_old_sub_res_unexp_rec
589          ) ;
590 
591 
592     END Check_Existence ;
593 
594 
595     /******************************************************************
596     * Procedure     : Check_Existence used by ECO BO
597     *                                   and internally called by RTG BO
598     * Parameters IN : Sub Revised operation resource exposed column record
599     *                 Sub Revised operation resource unexposed column record
600     * Parameters out: Old Sub Revised operation resource exposed column record
601     *                 Old Sub Revised operation resource unexposed column record
602     *                 Mesg Token Table
603     *                 Return Status
604     * Purpose       : Check_Existence will query using the primary key
605     *                 information and return a success if the operation
606     *                 resource is CREATE and the record EXISTS or will
607     *                 return an error if the substitute operation resource
608     *                 is UPDATE and record DOES NOT EXIST.
609     *                 In case of UPDATE if record exists, then the procedure
610     *                 will return old record in the old entity parameters
611     *                 with a success status.
612     *********************************************************************/
613 
614     PROCEDURE Check_Existence
615     (  p_rev_sub_resource_rec        IN  Bom_Rtg_Pub.Rev_Sub_Resource_rec_Type
616      , p_rev_sub_res_unexp_rec       IN  Bom_Rtg_Pub.Rev_Sub_Res_Unexposed_Rec_Type
617      , x_old_rev_sub_resource_rec    IN OUT NOCOPY Bom_Rtg_Pub.Rev_Sub_Resource_rec_Type
618      , x_old_rev_sub_res_unexp_rec   IN OUT NOCOPY Bom_Rtg_Pub.Rev_Sub_Res_Unexposed_Rec_Type
619      , x_mesg_token_tbl              IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
620      , x_return_status               IN OUT NOCOPY VARCHAR2
621     )
622     IS
623        l_Token_Tbl      Error_Handler.Token_Tbl_Type;
624        l_mesg_token_tbl Error_Handler.Mesg_Token_Tbl_Type;
625        l_return_status  VARCHAR2(1);
626        l_default_basis_type NUMBER;
627 
628     BEGIN
629 
630        l_return_status := FND_API.G_RET_STS_SUCCESS;
631        x_return_status := FND_API.G_RET_STS_SUCCESS;
632 
633 
634        l_Token_Tbl(1).token_name  := 'SUB_RESOURCE_CODE';
635        l_Token_Tbl(1).token_value :=
636                         p_rev_sub_resource_rec.sub_resource_code ;
637        l_Token_Tbl(2).token_name  := 'SCHEDULE_SEQ_NUMBER';
638        l_Token_Tbl(2).token_value :=
639                         nvl(p_rev_sub_resource_rec.substitute_group_number, p_rev_sub_res_unexp_rec.substitute_group_number) ;
640        l_Token_Tbl(3).token_name  := 'REVISED_ITEM_NAME';
641        l_Token_Tbl(3).token_value := p_rev_sub_resource_rec.revised_item_name;
642 
643        -- If basis type is null then take the resource's default basis type
644        IF (   p_rev_sub_resource_rec.basis_type IS NULL
645           OR  p_rev_sub_resource_rec.basis_type = FND_API.G_MISS_NUM )
646        THEN
647          BEGIN
648            SELECT  br.DEFAULT_BASIS_TYPE
649            INTO    l_default_basis_type
650            FROM    BOM_RESOURCES br
651            WHERE   br.RESOURCE_ID = p_rev_sub_res_unexp_rec.resource_id;
652          EXCEPTION
653            WHEN NO_DATA_FOUND THEN
654              l_default_basis_type := 1;
655          END;
656        ELSE
657          l_default_basis_type := p_rev_sub_resource_rec.basis_type;
658        END IF;
659 
660        Bom_Sub_Op_Res_Util.Query_Row
661        ( p_resource_id               =>  p_rev_sub_res_unexp_rec.resource_id
662        , p_substitute_group_number   =>  nvl(p_rev_sub_resource_rec.substitute_group_number, p_rev_sub_res_unexp_rec.substitute_group_number)
663        , p_operation_sequence_id     =>  p_rev_sub_res_unexp_rec.operation_sequence_id
664        , p_replacement_group_number  =>  p_rev_sub_resource_rec.replacement_group_number--bug 2489765
665        , p_basis_type                =>  l_default_basis_type
666        , p_schedule_flag             =>  p_rev_sub_resource_rec.schedule_flag  /* Added for bug 13005178 */
667        , p_acd_type                  =>  p_rev_sub_resource_rec.acd_type
668        , p_mesg_token_tbl            =>  l_mesg_token_tbl
669        , x_rev_sub_resource_rec      =>  x_old_rev_sub_resource_rec
670        , x_rev_sub_res_unexp_rec     =>  x_old_rev_sub_res_unexp_rec
671        , x_mesg_token_tbl            =>  l_mesg_token_tbl
672        , x_return_status             =>  l_return_status
673        ) ;
674 
675             IF l_return_status = BOM_Rtg_Globals.G_RECORD_FOUND AND
676                p_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE
677             THEN
678                     Error_Handler.Add_Error_Token
679                     (  x_Mesg_token_tbl => l_Mesg_Token_Tbl
680                      , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
681                      , p_message_name   => 'BOM_SUB_RES_ALREADY_EXISTS'
682                      , p_token_tbl      => l_token_tbl
683                      ) ;
684                     l_return_status := FND_API.G_RET_STS_ERROR ;
685 
686             ELSIF l_return_status = BOM_Rtg_Globals.G_RECORD_NOT_FOUND AND
687                p_rev_sub_resource_rec.transaction_type IN
688                     (BOM_Rtg_Globals.G_OPR_UPDATE, BOM_Rtg_Globals.G_OPR_DELETE)
689             THEN
690                     Error_Handler.Add_Error_Token
691                     (  x_Mesg_token_tbl => l_Mesg_Token_Tbl
692                      , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
693                      , p_message_name   => 'BOM_SUB_RES_DOESNOT_EXIST'
694                      , p_token_tbl      => l_token_tbl
695                     ) ;
696                     l_return_status := FND_API.G_RET_STS_ERROR ;
697 
698             ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
699             THEN
700                     Error_Handler.Add_Error_Token
701                     (  x_Mesg_token_tbl     => l_Mesg_Token_Tbl
702                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
703                      , p_message_name       => NULL
704                      , p_message_text       => 'Unexpected error while existence verification of '
705                                                || 'Sub Operation Resources '
706                                                || p_rev_sub_resource_rec.sub_resource_code
707                                                || ': Schedule Seq Num '
708                                                || nvl(p_rev_sub_resource_rec.substitute_group_number, p_rev_sub_res_unexp_rec.substitute_group_number)
709                      , p_token_tbl          => l_token_tbl
710                      ) ;
711             ELSE
712                     l_return_status := FND_API.G_RET_STS_SUCCESS;
713             END IF ;
714 
715             x_return_status  := l_return_status;
716             x_mesg_token_tbl := l_Mesg_Token_Tbl;
717 
718     END Check_Existence;
719 
720 
721 
722     /********************************************************************
723     * Procedure : Check_Attributes used by RTG BO
724     * Parameters IN : Sub Operation Resource exposed column record
725     *                 Sub Operation Resource unexposed column record
726     * Parameters out: Return Status
727     *                 Message Token Table
728     * Purpose   : Convert Routing Sub Operation Resource to ECO Sub Operation
729     *             Resource and Call Check_Attributes for ECO BO.
730     *             Check_Attributes will verify the exposed attributes
731     *             of the operation resource record in their own entirety.
732     *             No cross entity validations will be performed.
733     ********************************************************************/
734     PROCEDURE Check_Attributes
735     (  p_sub_resource_rec    IN  Bom_Rtg_Pub.Sub_Resource_Rec_Type
736      , p_sub_res_unexp_rec   IN  Bom_Rtg_Pub.Sub_Res_Unexposed_Rec_Type
737      , x_mesg_token_tbl      IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
738      , x_return_status       IN OUT NOCOPY VARCHAR2
739     )
740     IS
741 
742        l_rev_sub_resource_rec    Bom_Rtg_Pub.Rev_Sub_Resource_rec_Type ;
743        l_rev_sub_res_unexp_rec   Bom_Rtg_Pub.Rev_Sub_Res_Unexposed_Rec_Type ;
744 
745     BEGIN
746 
747        -- Convert Routing Operation to ECO Operation
748        Bom_Rtg_Pub.Convert_RtgSubRes_To_EcoSubRes
749         (  p_rtg_sub_resource_rec      => p_sub_resource_rec
750          , p_rtg_sub_res_unexp_rec     => p_sub_res_unexp_rec
751          , x_rev_sub_resource_rec      => l_rev_sub_resource_rec
752          , x_rev_sub_res_unexp_rec     => l_rev_sub_res_unexp_rec
753         ) ;
754 
755        -- Call Check Attributes procedure
756        Bom_Validate_Sub_Op_Res.Check_Attributes
757         (  p_rev_sub_resource_rec  => l_rev_sub_resource_rec
758          , p_rev_sub_res_unexp_rec => l_rev_sub_res_unexp_rec
759          , x_return_status         => x_return_status
760          , x_mesg_token_tbl        => x_mesg_token_tbl
761         ) ;
762 
763     END Check_Attributes ;
764 
765 
766     /***************************************************************
767     * Procedure : Check_Attribute (Validation) for CREATE and UPDATE
768     *             by ECO BO  and internally called by RTG BO
769     * Parameters IN : Revised Sub Operation Resource exposed column record
770     *                 Revised Sub Operation Resource unexposed column record
771     * Parameters out: Return Status
772     *                 Message Token Table
773     * Purpose   : Attribute validation procedure will validate each
774     *             attribute of Sub Revised operation resource in its entirety.
775     *             If the validation of a column requires looking at some
776     *             other columns value then the validation is done at
777     *             the Entity level instead.
778     *             All errors in the attribute validation are accumulated
779     *             before the procedure returns with a Return_Status
780     *             of 'E'.
781     *********************************************************************/
782     PROCEDURE Check_Attributes
783     (  p_rev_sub_resource_rec   IN  Bom_Rtg_Pub.Rev_Sub_Resource_rec_Type
784      , p_rev_sub_res_unexp_rec  IN  Bom_Rtg_Pub.Rev_Sub_Res_Unexposed_Rec_Type
785      , x_mesg_token_tbl         IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
786      , x_return_status          IN OUT NOCOPY VARCHAR2
787     )
788     IS
789 
790     l_return_status     VARCHAR2(1) ;
791     l_err_text          VARCHAR2(2000) ;
792     l_Mesg_Token_Tbl    Error_Handler.Mesg_Token_Tbl_Type ;
793     l_Token_Tbl         Error_Handler.Token_Tbl_Type ;
794 
795     BEGIN
796 
797         l_return_status := FND_API.G_RET_STS_SUCCESS;
798         x_return_status := FND_API.G_RET_STS_SUCCESS;
799 
800         -- Set the first token to be equal to the operation sequence number
801        l_Token_Tbl(1).token_name  := 'SUB_RESOURCE_CODE';
802        l_Token_Tbl(1).token_value :=
803                         p_rev_sub_resource_rec.sub_resource_code ;
804        l_Token_Tbl(2).token_name  := 'SCHEDULE_SEQ_NUMBER';
805        l_Token_Tbl(2).token_value :=
806                         nvl(p_rev_sub_resource_rec.substitute_group_number, p_rev_sub_res_unexp_rec.substitute_group_number) ;
807 
808         --
809         -- Check if the user is trying to update a record with
810         -- missing value when the column value is required.
811         --
812         IF p_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_UPDATE
813         THEN
814 
815         IF Bom_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
816         ('Sub Operation Resource Attr Validation: Missing Value. . . ' ) ;
817         END IF;
818 
819             -- New Sub Resource Code
820             IF p_rev_sub_resource_rec.new_sub_resource_code = FND_API.G_MISS_CHAR
821             THEN
822                 Error_Handler.Add_Error_Token
823                 (  p_Message_Name       => 'BOM_SUB_RESCODE_MISSING'
824                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
825                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
826                  , p_Token_Tbl          => l_Token_Tbl
827                  );
828                 l_return_status := FND_API.G_RET_STS_ERROR;
829             END IF ;
830 
831 
832 
833             -- Replacement Group Number
834             IF p_rev_sub_resource_rec.replacement_group_number = FND_API.G_MISS_NUM
835             THEN
836                 Error_Handler.Add_Error_Token
837                 (  p_Message_Name       => 'BOM_SUB_RES_RPLAC_GNUM_MISSING'
838                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
839                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
840                  , p_Token_Tbl          => l_Token_Tbl
841                  );
842                 l_return_status := FND_API.G_RET_STS_ERROR;
843             END IF ;
844 
845 
846             -- New Replacement Group Number -- bug 3741570
847             IF p_rev_sub_resource_rec.new_replacement_group_number = FND_API.G_MISS_NUM
848             THEN
849                Error_Handler.Add_Error_Token
850                (  p_Message_Name       => 'BOM_SUB_RES_RPLAC_GNUM_MISSING'
851                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
852                 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
853                 , p_Token_Tbl          => l_Token_Tbl
854                );
855                l_return_status := FND_API.G_RET_STS_ERROR;
856             END IF;
857 
858 
859             -- Standard Rate Flag
860             IF p_rev_sub_resource_rec.standard_rate_flag = FND_API.G_MISS_NUM
861             THEN
862                 Error_Handler.Add_Error_Token
863                 (  p_Message_Name       => 'BOM_SUB_RES_STD_RATE_MISSING'
864                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
865                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
866                  , p_Token_Tbl          => l_Token_Tbl
867                  );
868                 l_return_status := FND_API.G_RET_STS_ERROR;
869             END IF;
870 
871 
872             -- Assigned Units
873             IF p_rev_sub_resource_rec.assigned_units = FND_API.G_MISS_NUM
874             THEN
875                 Error_Handler.Add_Error_Token
876                 (  p_Message_Name       => 'BOM_SUB_RES_ASGND_UNTS_MISSING'
877                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
878                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
879                  , p_Token_Tbl          => l_Token_Tbl
880                  );
881                 l_return_status := FND_API.G_RET_STS_ERROR;
882             END IF;
883 
884 
885             -- Usage Rate or Amount
886             IF p_rev_sub_resource_rec.usage_rate_or_amount = FND_API.G_MISS_NUM
887             THEN
888                 Error_Handler.Add_Error_Token
889                 (  p_Message_Name       => 'BOM_SUB_RES_RATE_AMT_MISSING'
890                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
891                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
892                  , p_Token_Tbl          => l_Token_Tbl
893                  );
894                 l_return_status := FND_API.G_RET_STS_ERROR;
895             END IF;
896 
897             -- Usage Rate or Amount Inverse
898             IF p_rev_sub_resource_rec.usage_rate_or_amount_inverse = FND_API.G_MISS_NUM
899             THEN
900                 Error_Handler.Add_Error_Token
901                 (  p_Message_Name       => 'BOM_SUB_RES_RTAMT_INVR_MISSING'
902                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
903                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
904                  , p_Token_Tbl          => l_Token_Tbl
905                  );
906                 l_return_status := FND_API.G_RET_STS_ERROR;
907             END IF;
908 
909             -- Basis Type
910             IF p_rev_sub_resource_rec.basis_type = FND_API.G_MISS_NUM
911             THEN
912                 Error_Handler.Add_Error_Token
913                 (  p_Message_Name       => 'BOM_SUB_RES_BASISTYPE_MISSING'
914                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
915                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
916                  , p_Token_Tbl          => l_Token_Tbl
917                  );
918                 l_return_status := FND_API.G_RET_STS_ERROR;
919             END IF;
920 
921             -- New Basis Type
922             IF p_rev_sub_resource_rec.new_basis_type = FND_API.G_MISS_NUM
923             THEN
924                 Error_Handler.Add_Error_Token
925                 (  p_Message_Name       => 'BOM_SUB_RES_BASISTYPE_MISSING'
926                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
927                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
928                  , p_Token_Tbl          => l_Token_Tbl
929                  );
930                 l_return_status := FND_API.G_RET_STS_ERROR;
931             END IF;
932 
933             -- Schedule Flag
934             IF p_rev_sub_resource_rec.schedule_flag = FND_API.G_MISS_NUM
935             THEN
936                 Error_Handler.Add_Error_Token
937                 (  p_Message_Name       => 'BOM_SUB_RES_SCHED_FLAG_MISSING'
938                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
939                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
940                  , p_Token_Tbl          => l_Token_Tbl
941                  );
942                 l_return_status := FND_API.G_RET_STS_ERROR;
943             END IF ;
944 
945             -- Added for bug 13005178, New Schedule Flag validation
946             IF p_rev_sub_resource_rec.new_schedule_flag = FND_API.G_MISS_NUM
947             THEN
948                 Error_Handler.Add_Error_Token
949                 (  p_Message_Name       => 'BOM_SUB_RES_SCHED_FLAG_MISSING'
950                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
951                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
952                  , p_Token_Tbl          => l_Token_Tbl
953                  );
954                 l_return_status := FND_API.G_RET_STS_ERROR;
955             END IF ;
956 
957             -- Autocharge Type
958             IF p_rev_sub_resource_rec.autocharge_type = FND_API.G_MISS_NUM
959             THEN
960                 Error_Handler.Add_Error_Token
961                 (  p_Message_Name       => 'BOM_SUB_RES_ACHRG_TYPE_MISSING'
962                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
963                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
964                  , p_Token_Tbl          => l_Token_Tbl
965                  );
966                 l_return_status := FND_API.G_RET_STS_ERROR;
967             END IF ;
968 
969         END IF ;
970 
971         --
972         -- Check if the user is trying to create/update a record with
973         -- invalid value.
974         --
975 
976         IF Bom_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
977         ('Sub Operation Resource Attr Validation: Invalid Value. . . ' || l_return_status) ;
978         END IF;
979 
980 
981             -- New Sub Resource Code
982             IF p_rev_sub_resource_rec.new_sub_resource_code IS NOT NULL
983                AND p_rev_sub_resource_rec.new_sub_resource_code <> FND_API.G_MISS_CHAR
984                AND BOM_Rtg_Globals.Get_Bo_Identifier = BOM_Rtg_Globals.G_ECO_BO
985             THEN
986                 Error_Handler.Add_Error_Token
987                 (  p_Message_Name       => 'BOM_SUB_RES_CODE_NOTUPDATE'
988                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
989                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
990                  , p_Token_Tbl          => l_Token_Tbl
991                  );
992                 l_return_status := FND_API.G_RET_STS_ERROR;
993             END IF ;
994 
995 
996             -- Replacement Group Num
997             IF p_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE
998                AND (p_rev_sub_resource_rec.replacement_group_number IS NULL
999                    OR p_rev_sub_resource_rec.replacement_group_number = FND_API.G_MISS_NUM)
1000             THEN
1001                 Error_Handler.Add_Error_Token
1002                 (  p_Message_Name       => 'BOM_SUB_RES_REPLCMNT_GNUM_NULL'
1003                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1004                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1005                  , p_Token_Tbl          => l_Token_Tbl
1006                  );
1007                 l_return_status := FND_API.G_RET_STS_ERROR ;
1008 
1009             ELSIF p_rev_sub_resource_rec.replacement_group_number IS NOT NULL AND
1010                   p_rev_sub_resource_rec.replacement_group_number <> FND_API.G_MISS_NUM AND
1011                  ( p_rev_sub_resource_rec.replacement_group_number < 1
1012                  OR  p_rev_sub_resource_rec.replacement_group_number > 9999 )
1013             THEN
1014                 Error_Handler.Add_Error_Token
1015                 (  p_Message_Name       => 'BOM_SUB_RES_RPLMT_GNUM_INVALID'
1016                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1017                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1018                  , p_Token_Tbl          => l_Token_Tbl
1019                  );
1020                 l_return_status := FND_API.G_RET_STS_ERROR ;
1021             END IF;
1022 
1023 
1024             -- New Replacement Group Number -- bug 3741570
1025             IF p_rev_sub_resource_rec.replacement_group_number IS NOT NULL
1026                AND p_rev_sub_resource_rec.replacement_group_number <> FND_API.G_MISS_NUM
1027                AND ( p_rev_sub_resource_rec.replacement_group_number < 1
1028                   OR p_rev_sub_resource_rec.replacement_group_number > 9999 )
1029             THEN
1030                Error_Handler.Add_Error_Token
1031                (  p_Message_Name       => 'BOM_SUB_RES_RPLMT_GNUM_INVALID'
1032                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1033                 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1034                 , p_Token_Tbl          => l_Token_Tbl
1035                );
1036                l_return_status := FND_API.G_RET_STS_ERROR ;
1037             END IF;
1038 
1039 
1040             -- Standard Rate Flag
1041             IF  p_rev_sub_resource_rec.standard_rate_flag IS NOT NULL
1042             AND p_rev_sub_resource_rec.standard_rate_flag NOT IN (1,2)
1043             AND p_rev_sub_resource_rec.standard_rate_flag <> FND_API.G_MISS_NUM
1044             THEN
1045                 Error_Handler.Add_Error_Token
1046                 (  p_Message_Name       => 'BOM_SUB_RES_STD_RATE_INVALID'
1047                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1048                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1049                  , p_Token_Tbl          => l_Token_Tbl
1050                  );
1051                 l_return_status := FND_API.G_RET_STS_ERROR;
1052             END IF;
1053 
1054 
1055             -- Principle Flag
1056             IF  p_rev_sub_resource_rec.principle_flag IS NOT NULL
1057             AND p_rev_sub_resource_rec.principle_flag NOT IN (1,2)
1058             AND p_rev_sub_resource_rec.principle_flag <> FND_API.G_MISS_NUM
1059             THEN
1060                 Error_Handler.Add_Error_Token
1061                 (  p_Message_Name       => 'BOM_SUB_RES_PCLFLAG_INVALID'
1062                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1063                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1064                  , p_Token_Tbl          => l_Token_Tbl
1065                  );
1066                 l_return_status := FND_API.G_RET_STS_ERROR;
1067             END IF;
1068 
1069             -- Resource Offset Percent
1070             IF  p_rev_sub_resource_rec.resource_offset_percent IS NOT NULL
1071             AND (p_rev_sub_resource_rec.resource_offset_percent < 0
1072                  OR  p_rev_sub_resource_rec.resource_offset_percent > 100 )
1073             AND  p_rev_sub_resource_rec.resource_offset_percent <> FND_API.G_MISS_NUM
1074             THEN
1075                IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
1076                THEN
1077                    Error_Handler.Add_Error_Token
1078                    ( p_Message_Name   => 'BOM_SUB_RES_OFFSET_PCT_INVALID'
1079                    , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1080                    , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1081                    , p_Token_Tbl      => l_Token_Tbl
1082                    ) ;
1083                END IF ;
1084                l_return_status := FND_API.G_RET_STS_ERROR;
1085             END IF ;
1086 
1087 
1088             -- Assigned Units
1089             IF  p_rev_sub_resource_rec.assigned_units IS NOT NULL
1090             AND p_rev_sub_resource_rec.assigned_units  <= 0.00001
1091             AND p_rev_sub_resource_rec.assigned_units <> FND_API.G_MISS_NUM
1092             THEN
1093                 Error_Handler.Add_Error_Token
1094                 (  p_Message_Name       => 'BOM_SUB_RES_ASSGN_UNTS_INVALID'
1095                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1096                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1097                  , p_Token_Tbl          => l_Token_Tbl
1098                  );
1099                 l_return_status := FND_API.G_RET_STS_ERROR;
1100             END IF;
1101 
1102 
1103             -- Basis Type
1104             IF  p_rev_sub_resource_rec.basis_type IS NOT NULL
1105             AND p_rev_sub_resource_rec.basis_type NOT IN (1,2)
1106             AND p_rev_sub_resource_rec.basis_type <> FND_API.G_MISS_NUM
1107             THEN
1108                 Error_Handler.Add_Error_Token
1109                 (  p_Message_Name       => 'BOM_SUB_RES_BASISTYPE_INVALID'
1110                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1111                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1112                  , p_Token_Tbl          => l_Token_Tbl
1113                  );
1114                 l_return_status := FND_API.G_RET_STS_ERROR;
1115             END IF;
1116 
1117             -- New Basis Type
1118             IF  p_rev_sub_resource_rec.new_basis_type IS NOT NULL
1119             AND p_rev_sub_resource_rec.new_basis_type NOT IN (1,2)
1120             AND p_rev_sub_resource_rec.new_basis_type <> FND_API.G_MISS_NUM
1121             THEN
1122                 Error_Handler.Add_Error_Token
1123                 (  p_Message_Name       => 'BOM_SUB_RES_BASISTYPE_INVALID'
1124                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1125                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1126                  , p_Token_Tbl          => l_Token_Tbl
1127                  );
1128                 l_return_status := FND_API.G_RET_STS_ERROR;
1129             END IF;
1130 
1131             -- Schedule Flag
1132             IF  p_rev_sub_resource_rec.schedule_flag IS NOT NULL
1133             AND p_rev_sub_resource_rec.schedule_flag NOT IN (1,2,3,4)
1134             AND p_rev_sub_resource_rec.schedule_flag <> FND_API.G_MISS_NUM
1135             THEN
1136                 Error_Handler.Add_Error_Token
1137                 (  p_Message_Name       => 'BOM_SUB_RES_SCHED_FLAG_INVALID'
1138                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1139                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1140                  , p_Token_Tbl          => l_Token_Tbl
1141                  );
1142                 l_return_status := FND_API.G_RET_STS_ERROR;
1143             END IF ;
1144 
1145             -- Added for bug 13005178, New Schedule Flag Validation Added
1146             IF  p_rev_sub_resource_rec.new_schedule_flag IS NOT NULL
1147             AND p_rev_sub_resource_rec.new_schedule_flag NOT IN (1,2,3,4)
1148             AND p_rev_sub_resource_rec.new_schedule_flag <> FND_API.G_MISS_NUM
1149             THEN
1150                Error_Handler.Add_Error_Token
1151                (  p_Message_Name       => 'BOM_SUB_RES_SCHED_FLAG_INVALID'
1152                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1153                 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1154                 , p_Token_Tbl          => l_Token_Tbl
1155                 );
1156                l_return_status := FND_API.G_RET_STS_ERROR;
1157             END IF ;
1158 
1159             -- Autocharge Type
1160             IF  p_rev_sub_resource_rec.autocharge_type IS NOT NULL
1161             AND p_rev_sub_resource_rec.autocharge_type NOT IN (1,2,3,4)
1162             AND p_rev_sub_resource_rec.autocharge_type <> FND_API.G_MISS_NUM
1163             THEN
1164                 Error_Handler.Add_Error_Token
1165                 (  p_Message_Name       => 'BOM_SUB_RES_ACHRG_TYPE_INVALID'
1166                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1167                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1168                  , p_Token_Tbl          => l_Token_Tbl
1169                  );
1170                 l_return_status := FND_API.G_RET_STS_ERROR;
1171             END IF ;
1172 
1173 
1174             -- ACD Type
1175             IF p_rev_sub_resource_rec.acd_type IS NOT NULL
1176                AND p_rev_sub_resource_rec.acd_type NOT IN
1177                         (l_ACD_ADD, l_ACD_DISABLE)
1178                AND BOM_Rtg_Globals.Get_Bo_Identifier = BOM_Rtg_Globals.G_ECO_BO
1179             THEN
1180 
1181                l_token_tbl(2).token_name  := 'ACD_TYPE';
1182                l_token_tbl(2).token_value := p_rev_sub_resource_rec.acd_type;
1183 
1184                Error_Handler.Add_Error_Token
1185                 (  p_Message_Name       => 'BOM_SUB_RES_ACD_TYPE_INVALID'
1186                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1187                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1188                  , p_Token_Tbl          => l_Token_Tbl
1189                 );
1190                l_return_status := FND_API.G_RET_STS_ERROR ;
1191             END IF ;
1192 
1193             -- Schedule Sequence Number
1194             IF (p_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE
1195                 AND p_rev_sub_resource_rec.schedule_sequence_number IS NULL)
1196               OR (p_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_UPDATE
1197                   AND p_rev_sub_resource_rec.schedule_sequence_number = FND_API.G_MISS_NUM)
1198               OR p_rev_sub_resource_rec.schedule_sequence_number = 0
1199             THEN
1200                Error_Handler.Add_Error_Token
1201                (  p_Message_Name       => 'BOM_SSN_ZERO_VALUE'
1202                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1203                 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1204                 --, p_Token_Tbl          => l_Token_Tbl
1205                );
1206                l_return_status := FND_API.G_RET_STS_ERROR ;
1207             END IF;
1208 
1209        --  Done validating attributes
1210         IF Bom_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1211         ('Sub Operation Resource Attr Validation completed with return_status: ' || l_return_status) ;
1212         END IF;
1213 
1214        x_return_status := l_return_status;
1215        x_mesg_token_tbl := l_Mesg_Token_Tbl;
1216 
1217     EXCEPTION
1218        WHEN OTHERS THEN
1219           IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1220           ('Some unknown error in Attribute Validation . . .' || SQLERRM );
1221           END IF ;
1222 
1223 
1224           l_err_text := G_PKG_NAME || ' Validation (Attr. Validation) '
1225                                 || substrb(SQLERRM,1,200);
1226           -- dbms_output.put_line('Unexpected Error: '||l_err_text);
1227 
1228           Error_Handler.Add_Error_Token
1229           (  p_message_name   => NULL
1230            , p_message_text   => l_err_text
1231            , p_mesg_token_tbl => l_mesg_token_tbl
1232            , x_mesg_token_tbl => l_mesg_token_tbl
1233           ) ;
1234 
1235           -- Return the status and message table.
1236           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1237           x_mesg_token_tbl := l_mesg_token_tbl ;
1238 
1239 
1240     END Check_Attributes ;
1241 
1242 
1243     /*******************************************************************
1244     * Procedure : Check_Entity used by RTG BO
1245     * Parameters IN : Sub Operation Resource exposed column record
1246     *                 Sub Operation Resource unexposed column record
1247     *                 Old Sub Operation Resource exposed column record
1248     *                 Old Sub Operation Resource unexposed column record
1249     * Parameters out: Return Status
1250     *                 Message Token Table
1251     * Purpose   :     Convert Routing Op Resource to ECO Op Resource and
1252     *                 Call Check_Entity for ECO BO.
1253     *                 Procedure will execute the business logic and will
1254     *                 also perform any required cross entity validations
1255     *******************************************************************/
1256     PROCEDURE Check_Entity
1257     (  p_sub_resource_rec      IN  Bom_Rtg_Pub.Sub_Resource_Rec_Type
1258      , p_sub_res_unexp_rec     IN  Bom_Rtg_Pub.Sub_Res_Unexposed_Rec_Type
1259      , p_old_sub_resource_rec  IN  Bom_Rtg_Pub.Sub_Resource_Rec_Type
1260      , p_old_sub_res_unexp_rec IN  Bom_Rtg_Pub.Sub_Res_Unexposed_Rec_Type
1261      , x_sub_resource_rec      IN OUT NOCOPY Bom_Rtg_Pub.Sub_Resource_Rec_Type
1262      , x_sub_res_unexp_rec     IN OUT NOCOPY Bom_Rtg_Pub.Sub_Res_Unexposed_Rec_Type
1263      , x_mesg_token_tbl       IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1264      , x_return_status        IN OUT NOCOPY VARCHAR2
1265     )
1266     IS
1267         l_rev_sub_resource_rec      Bom_Rtg_Pub.Rev_Sub_Resource_rec_Type ;
1268         l_rev_sub_res_unexp_rec     Bom_Rtg_Pub.Rev_Sub_Res_Unexposed_Rec_Type ;
1269         l_old_rev_sub_resource_rec  Bom_Rtg_Pub.Rev_Sub_Resource_rec_Type ;
1270         l_old_rev_sub_res_unexp_rec Bom_Rtg_Pub.Rev_Sub_Res_Unexposed_Rec_Type ;
1271 
1272     BEGIN
1273         -- Convert Routing Operation to ECO Operation
1274         Bom_Rtg_Pub.Convert_RtgSubRes_To_EcoSubRes
1275         (  p_rtg_sub_resource_rec      => p_sub_resource_rec
1276          , p_rtg_sub_res_unexp_rec     => p_sub_res_unexp_rec
1277          , x_rev_sub_resource_rec      => l_rev_sub_resource_rec
1278          , x_rev_sub_res_unexp_rec     => l_rev_sub_res_unexp_rec
1279         ) ;
1280 
1281 
1282         -- Also Convert Old Routing Operation to Old ECO Operation
1283         Bom_Rtg_Pub.Convert_RtgSubRes_To_EcoSubRes
1284         (  p_rtg_sub_resource_rec      => p_old_sub_resource_rec
1285          , p_rtg_sub_res_unexp_rec     => p_old_sub_res_unexp_rec
1286          , x_rev_sub_resource_rec      => l_old_rev_sub_resource_rec
1287          , x_rev_sub_res_unexp_rec     => l_old_rev_sub_res_unexp_rec
1288         ) ;
1289 
1290         -- Call Check_Entity
1291         Bom_Validate_Sub_Op_Res.Check_Entity
1292        (  p_rev_sub_resource_rec      => l_rev_sub_resource_rec
1293         , p_rev_sub_res_unexp_rec     => l_rev_sub_res_unexp_rec
1294         , p_old_rev_sub_resource_rec  => l_old_rev_sub_resource_rec
1295         , p_old_rev_sub_res_unexp_rec => l_old_rev_sub_res_unexp_rec
1296         , p_control_rec => Bom_Rtg_Pub.G_DEFAULT_CONTROL_REC
1297         , x_rev_sub_resource_rec      => l_rev_sub_resource_rec
1298         , x_rev_sub_res_unexp_rec     => l_rev_sub_res_unexp_rec
1299         , x_return_status            => x_return_status
1300         , x_mesg_token_tbl           => x_mesg_token_tbl
1301         ) ;
1302 
1303 
1304         -- Convert Eco Op Resource Record back to Routing Op Resource
1305         Bom_Rtg_Pub.Convert_EcoSubRes_To_RtgSubRes
1306         (  p_rev_sub_resource_rec      => l_rev_sub_resource_rec
1307          , p_rev_sub_res_unexp_rec     => l_rev_sub_res_unexp_rec
1308          , x_rtg_sub_resource_rec      => x_sub_resource_rec
1309          , x_rtg_sub_res_unexp_rec     => x_sub_res_unexp_rec
1310          ) ;
1311 
1312 
1313     END Check_Entity ;
1314 
1315 
1316     /*******************************************************************
1317     * Procedure : Check_Entity used by RTG BO and internally called by RTG BO
1318     * Parameters IN : Revised Sub Op Resource exposed column record
1319     *                 Revised Sub Op Resource unexposed column record
1320     *                 Old Revised Sub Op Resource exposed column record
1321     *                 Old Revised Sub Op Resource unexposed column record
1322     * Parameters out: Return Status
1323     *                 Message Token Table
1324     * Purpose   :     Check_Entity validate the entity for the correct
1325     *                 business logic. It will verify the values by running
1326     *                 checks on inter-dependent columns.
1327     *                 It will also verify that changes in one column value
1328     *                 does not invalidate some other columns.
1329     *******************************************************************/
1330     PROCEDURE Check_Entity
1331     (  p_rev_sub_resource_rec      IN  Bom_Rtg_Pub.Rev_Sub_Resource_rec_Type
1332      , p_rev_sub_res_unexp_rec     IN  Bom_Rtg_Pub.Rev_Sub_Res_Unexposed_Rec_Type
1333      , p_old_rev_sub_resource_rec  IN  Bom_Rtg_Pub.Rev_Sub_Resource_rec_Type
1334      , p_old_rev_sub_res_unexp_rec IN  Bom_Rtg_Pub.Rev_Sub_Res_Unexposed_Rec_Type
1335      , p_control_rec               IN  Bom_Rtg_Pub.Control_Rec_Type
1336      , x_rev_sub_resource_rec      IN OUT NOCOPY Bom_Rtg_Pub.Rev_Sub_Resource_rec_Type
1337      , x_rev_sub_res_unexp_rec     IN OUT NOCOPY Bom_Rtg_Pub.Rev_Sub_Res_Unexposed_Rec_Type
1338      , x_mesg_token_tbl            IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1339      , x_return_status             IN OUT NOCOPY VARCHAR2
1340     )
1341     IS
1342 
1343     -- Variables
1344     l_eco_processed     BOOLEAN ;      -- Indicate ECO has been processed
1345 
1346     l_hour_uom_code     VARCHAR2(3) ;  -- Hour UOM Code
1347     l_hour_uom_class    VARCHAR2(10) ; -- Hour UOM Class
1348     l_res_uom_code      VARCHAR2(3) ;  -- Resource UOM Code
1349     l_res_uom_class     VARCHAR2(10) ; -- Resource UOM Class
1350     l_temp_status       VARCHAR2(1)  ;  -- Temp Error Status
1351     l_old_op_seq_id     NUMBER := NULL ;  -- Old Operation Sequence Id
1352     /* Added below 3 vars for fixing bug 6074930 */
1353     l_res_code        VARCHAR2(10);
1354     l_res_code_2      VARCHAR2(10);
1355     l_res_id          NUMBER;
1356 
1357     l_rev_sub_resource_rec        Bom_Rtg_Pub.Rev_Sub_Resource_rec_Type ;
1358     l_rev_sub_res_unexp_rec       Bom_Rtg_Pub.Rev_Sub_Res_Unexposed_Rec_Type ;
1359 
1360     -- Error Handlig Variables
1361     l_return_status   VARCHAR2(1);
1362     l_err_text        VARCHAR2(2000) ;
1363     l_Mesg_Token_Tbl  Error_Handler.Mesg_Token_Tbl_Type ;
1364     l_token_tbl       Error_Handler.Token_Tbl_Type;
1365 
1366     l_get_setups        NUMBER;
1367     l_batchable         NUMBER;
1368 
1369     CURSOR   get_setups (  p_resource_id NUMBER
1370                          , p_org_id NUMBER
1371 			 )
1372     IS
1373 	SELECT count(setup_id)
1374 	FROM bom_resource_setups
1375 	WHERE resource_id = p_resource_id
1376 	AND organization_id = p_org_id;
1377 
1378 
1379 
1380     -- Check Rev Sub Op Resource exists
1381     CURSOR  l_disable_subres_exist_csr
1382                                 (   p_resource_id    NUMBER
1383                                    , p_sub_group_num  NUMBER
1384                                    , p_op_seq_id      NUMBER
1385                                  )
1386     IS
1387        SELECT 'Rev Sub Op Resource Not Exists'
1388        FROM   DUAL
1389        WHERE NOT EXISTS (SELECT NULL
1390                          FROM  BOM_OPERATION_SEQUENCES bos
1391                              , BOM_SUB_OPERATION_RESOURCES bsor
1392                          WHERE bsor.substitute_group_num  = p_sub_group_num
1393                          AND   bsor.resource_id           = p_resource_id
1394                          AND   bsor.operation_sequence_id = bos.operation_sequence_id
1395                          AND   bos.operation_sequence_id  = p_op_seq_id
1396                          ) ;
1397 
1398     -- Check Uniqueness
1399     CURSOR l_duplicate_csr (   p_resource_id             NUMBER
1400                              , p_substitute_group_number  NUMBER
1401                              , p_replacement_group_number NUMBER -- bug 3741570
1402                              , p_op_seq_id               NUMBER
1403                              , p_acd_type                NUMBER
1404                              , p_basis_type              NUMBER
1405                              , p_schedule_flag           NUMBER  /* Added for bug 13005178 */
1406                             )
1407     IS
1408         SELECT 'Sub Res Duplicate'
1409         FROM   DUAL
1410         WHERE  EXISTS  ( SELECT NULL
1411                          FROM   BOM_SUB_OPERATION_RESOURCES
1412                          WHERE  NVL(ACD_TYPE, 1)         = NVL(p_acd_type, 1)
1413                          AND    BASIS_TYPE               = p_basis_type
1414                          AND    RESOURCE_ID              = p_resource_id
1415                          AND    SUBSTITUTE_GROUP_NUM     = p_substitute_group_number
1416                          AND    REPLACEMENT_GROUP_NUM    = p_replacement_group_number -- bug 3741570
1417                          AND    OPERATION_SEQUENCE_ID    = p_op_seq_id
1418                          AND    SCHEDULE_FLAG            = p_schedule_flag  /* Added filter for bug 13005178 */
1419                         ) ;
1420 
1421 
1422 
1423     BEGIN
1424        --
1425        -- Initialize Common Record and Status
1426        --
1427 
1428        l_rev_sub_resource_rec    := p_rev_sub_resource_rec ;
1429        l_rev_sub_res_unexp_rec   := p_rev_sub_res_unexp_rec ;
1430        l_return_status := FND_API.G_RET_STS_SUCCESS;
1431        x_return_status := FND_API.G_RET_STS_SUCCESS;
1432 
1433        IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1434            ('Performing Sub Op Resource Check Entitity Validation . . .') ;
1435        END IF ;
1436 
1437        --
1438        -- Set the 1st token of Token Table to Revised Operation value
1439        --
1440        l_Token_Tbl(1).token_name  := 'SUB_RESOURCE_CODE';
1441        l_Token_Tbl(1).token_value :=
1442                         p_rev_sub_resource_rec.sub_resource_code ;
1443        l_Token_Tbl(2).token_name  := 'SCHEDULE_SEQ_NUMBER';
1444        l_Token_Tbl(2).token_value :=
1445                         nvl(p_rev_sub_resource_rec.substitute_group_number, p_rev_sub_res_unexp_rec.substitute_group_number) ;
1446 
1447 
1448        -- The ECO can be updated but a warning needs to be generated and
1449        -- scheduled revised items need to be update to Open
1450        -- and the ECO status need to be changed to Not Submitted for Approval
1451 
1452        IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1453        ('Check if ECO has been approved and has a workflow process. . . ' || l_return_status) ;
1454        END IF ;
1455 
1456        IF BOM_Rtg_Globals.Get_Bo_Identifier = BOM_Rtg_Globals.G_ECO_BO
1457        THEN
1458           BOM_Rtg_Globals.Check_Approved_For_Process
1459           ( p_change_notice    => l_rev_sub_resource_rec.eco_name
1460           , p_organization_id  => l_rev_sub_res_unexp_rec.organization_id
1461           , x_processed        => l_eco_processed
1462           , x_err_text         => l_err_text
1463           ) ;
1464 
1465           IF l_eco_processed THEN
1466            -- If the above process returns true then set the ECO approval.
1467                 BOM_Rtg_Globals.Set_Request_For_Approval
1468                 ( p_change_notice    => l_rev_sub_resource_rec.eco_name
1469                 , p_organization_id  => l_rev_sub_res_unexp_rec.organization_id
1470                 , x_err_text         => l_err_text
1471                 ) ;
1472 
1473           END IF ;
1474        END IF;
1475 
1476 
1477        --
1478        -- Performing Entity Validation in Revised Sub Op Resource(ECO BO)
1479        --
1480        IF BOM_Rtg_Globals.Get_Bo_Identifier = BOM_Rtg_Globals.G_ECO_BO
1481        THEN
1482           IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1483             ('Performing Entitity Validation for Eco Routing :ACD Type. . .') ;
1484           END IF ;
1485 
1486           --
1487           -- ACD Type
1488           -- If the Transaction Type is CREATE and the ACD_Type = Disable, then
1489           -- the sub operation resource should already exist for the revised operation.
1490           --
1491           IF l_rev_sub_resource_rec.Transaction_Type = BOM_Rtg_Globals.G_OPR_CREATE
1492             AND ( NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD ) = l_ACD_DISABLE )
1493           THEN
1494 
1495              FOR l_disable_subres_exist_rec IN l_disable_subres_exist_csr -- add replacement_group_num to this check??
1496                   (   p_resource_id    => l_rev_sub_res_unexp_rec.resource_id
1497                     , p_sub_group_num  => nvl(l_rev_sub_resource_rec.substitute_group_number, l_rev_sub_res_unexp_rec.substitute_group_number)
1498                     , p_op_seq_id      => l_rev_sub_res_unexp_rec.operation_sequence_id
1499                   )
1500 
1501              LOOP
1502                 l_token_tbl(3).token_name  := 'OP_SEQ_NUMBER';
1503                 l_token_tbl(3).token_value := l_rev_sub_resource_rec.operation_sequence_number ;
1504 
1505                 Error_Handler.Add_Error_Token
1506                 (  p_message_name   => 'BOM_SUB_RES_DSBL_RES_NOT_FOUND'
1507                  , p_mesg_token_tbl => l_Mesg_Token_Tbl
1508                  , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1509                  , p_token_tbl      => l_token_tbl
1510                 ) ;
1511                 l_token_tbl.delete(3) ;
1512                 l_return_status := FND_API.G_RET_STS_ERROR ;
1513              END LOOP ;
1514           END IF ;
1515 
1516 
1517           --
1518           -- ACD Type,
1519           -- If the Transaction Type is CREATE and the ACD_Type of parent revised
1520           -- operation is Add then,the ACD_Type must be Add.
1521           -- Call BOM_Validate_Op_Res.Get_Rev_Op_ACD(p_op_seq_id to get parent revised
1522           -- operation's ACD Type
1523           --
1524           IF l_rev_sub_resource_rec.Transaction_Type = BOM_Rtg_Globals.G_OPR_CREATE
1525           THEN
1526              IF
1527                l_ACD_ADD =
1528                BOM_Validate_Op_Res.Get_Rev_Op_ACD(p_op_seq_id
1529                               => l_rev_sub_res_unexp_rec.operation_sequence_id)
1530               AND  NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD ) <> l_ACD_ADD
1531              THEN
1532                 l_token_tbl(3).token_name  := 'OP_SEQ_NUMBER';
1533                 l_token_tbl(3).token_value := l_rev_sub_resource_rec.operation_sequence_number ;
1534 
1535                 Error_Handler.Add_Error_Token
1536                 (  p_message_name   => 'BOM_SUB_RES_ACD_NOT_COMPATIBLE'
1537                  , p_mesg_token_tbl => l_Mesg_Token_Tbl
1538                  , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1539                  , p_token_tbl      => l_token_tbl
1540                 ) ;
1541 
1542                 l_token_tbl.delete(3) ;
1543                 l_return_status := FND_API.G_RET_STS_ERROR ;
1544               END IF ;
1545            END IF ;
1546 
1547 
1548           --
1549           -- For UPDATE, ACD Type not updateable
1550           --
1551           IF  l_rev_sub_resource_rec.Transaction_Type = BOM_Rtg_Globals.G_OPR_UPDATE
1552               AND l_rev_sub_resource_rec.acd_type <> p_old_rev_sub_resource_rec.acd_type
1553           THEN
1554              IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
1555              THEN
1556                 Error_Handler.Add_Error_Token
1557                 ( p_message_name    => 'BOM_SUB_RES_ACDTPNT_UPDATEABLE'
1558                 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1559                 , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1560                 , p_token_tbl      => l_token_tbl
1561                 ) ;
1562              END IF ;
1563              l_return_status := FND_API.G_RET_STS_ERROR ;
1564           END IF ;
1565 
1566 
1567           --
1568           -- Verify the ECO by WO Effectivity, If ECO by WO, Lot Num, Or Cum Qty, then
1569           -- Check if the operation resource exist in the WO or Lot Num.
1570           --
1571           IF   l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE
1572           THEN
1573              IF NOT Check_ECO_By_WO_Effectivity
1574                     ( p_revised_item_sequence_id => l_rev_sub_res_unexp_rec.revised_item_sequence_id
1575                     , p_operation_seq_num        => l_rev_sub_resource_rec.operation_sequence_number
1576                     , p_resource_id              => l_rev_sub_res_unexp_rec.resource_id
1577                     , p_sub_group_num            => nvl(l_rev_sub_resource_rec.substitute_group_number, l_rev_sub_res_unexp_rec.substitute_group_number) )
1578              THEN
1579                 l_token_tbl(1).token_name  := 'SUB_RESOURCE_CODE';
1580                 l_token_tbl(1).token_value :=
1581                         p_rev_sub_resource_rec.sub_resource_code ;
1582                 l_token_tbl(2).token_name  := 'SCHEDULE_SEQ_NUMBER';
1583                 l_token_tbl(2).token_value :=
1584                         nvl(p_rev_sub_resource_rec.substitute_group_number, p_rev_sub_res_unexp_rec.substitute_group_number) ;
1585                 l_token_tbl(3).token_name  := 'REVISED_ITEM_NAME';
1586                 l_token_tbl(3).token_value := l_rev_sub_resource_rec.revised_item_name;
1587 
1588                 Error_Handler.Add_Error_Token
1589                 (  p_message_name   => 'BOM_SUB_RES_RITECOWOEF_INVALID'
1590                  , p_mesg_token_tbl => l_Mesg_Token_Tbl
1591                  , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1592                  , p_token_tbl      => l_token_tbl
1593                 );
1594                 l_return_status := FND_API.G_RET_STS_ERROR;
1595 
1596                 l_Token_Tbl(1).token_name  := 'SUB_RESOURCE_CODE';
1597                 l_Token_Tbl(1).token_value :=
1598                                 p_rev_sub_resource_rec.sub_resource_code ;
1599                 l_Token_Tbl(2).token_name  := 'SCHEDULE_SEQ_NUMBER';
1600                 l_Token_Tbl(2).token_value :=
1601                                 nvl(p_rev_sub_resource_rec.substitute_group_number, p_rev_sub_res_unexp_rec.substitute_group_number) ;
1602                 l_token_tbl.delete(3) ;
1603              END IF ;
1604           END IF ;
1605 
1606 
1607        END IF ; -- ECO BO Validation
1608 
1609 
1610 	-- Validation for Assigned Units
1611 	IF Bom_Rtg_Globals.Get_Debug = 'Y' THEN
1612 	  Error_Handler.Write_Debug ('Validating the Assigned Units for a Batchable Alternate Resource . . .') ;
1613 	END IF;
1614 
1615 	IF l_rev_sub_resource_rec.Transaction_Type IN
1616 	(BOM_Rtg_Globals.G_OPR_CREATE, BOM_Rtg_Globals.G_OPR_UPDATE)
1617 	THEN
1618 	--
1619 	-- APS Enhancement for Routings.
1620 	-- Verify that if a resource has setups defined, or is Batchable then
1621 	-- the Assigned Units for that Resource have to be 1.
1622 	--
1623 	  IF p_rev_sub_resource_rec.assigned_units <> FND_API.G_MISS_NUM THEN
1624 		OPEN get_setups (p_rev_sub_res_unexp_rec.resource_id, p_rev_sub_res_unexp_rec.organization_id);
1625 		FETCH get_setups INTO l_get_setups;
1626 		CLOSE get_setups;
1627 		SELECT nvl(batchable,2) INTO l_batchable
1628 		FROM bom_resources
1629 		WHERE resource_id = p_rev_sub_res_unexp_rec.resource_id;
1630 		IF (l_get_setups > 0 or l_batchable = 1) THEN
1631 			IF p_rev_sub_resource_rec.assigned_units <> 1 THEN
1632 			    l_Token_Tbl(2).token_name  := 'RES_SEQ_NUMBER';
1633 			    --l_Token_Tbl(2).token_value  := p_rev_sub_resource_rec.Sub_Resource_Code;
1634 			    l_Token_Tbl(2).token_value  := p_rev_sub_resource_rec.Schedule_Sequence_Number;
1635 			    Error_Handler.Add_Error_Token
1636 			    (  p_Message_Name       => 'BOM_SUBRES_ASSIGND_UNITS_WRONG'
1637 			     , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1638 			     , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1639 			     , p_Token_Tbl          => l_Token_Tbl
1640 			    );
1641 			    l_return_status := FND_API.G_RET_STS_ERROR ;
1642 			END IF;
1643 		END IF;
1644 	  END IF;
1645 	END IF;
1646 
1647 
1648        --
1649        -- For UPDATE
1650        -- Validation specific to the Transaction Type of Update
1651        --
1652        IF l_rev_sub_resource_rec.Transaction_Type = BOM_Rtg_Globals.G_OPR_UPDATE
1653 
1654           -- In this release, Acd type : Change is not allowed.
1655           --
1656           -- OR
1657           -- (l_rev_sub_resource_rec.Transaction_Type = BOM_Rtg_Globals.G_OPR_CREATE
1658           --  AND  l_rev_sub_resource_rec.acd_type    = l_ACD_CHANGE
1659           --  )
1660        THEN
1661             NULL ;
1662        END IF ;  --  Transation: UPDATE
1663 
1664 
1665        IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1666        ('End of Validation specific to the Transaction Type of Update' || l_return_status) ;
1667        END IF ;
1668 
1669        --
1670        -- Validation for Transaction Type : Create and Update
1671        --
1672        IF l_rev_sub_resource_rec.transaction_type IN
1673          ( BOM_Rtg_Globals.G_OPR_CREATE, BOM_Rtg_Globals.G_OPR_UPDATE )
1674        THEN
1675 
1676        IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1677        ('Common Validateion for Transaction Type : Create and Update . . . . ' || l_return_status) ;
1678        END IF ;
1679 
1680           --
1681           -- Resource Id
1682           -- Check if valid resource id exists and belongs to depatment
1683           -- Call BOM_Validate_Op_Res.Val_Resource_Id
1684           --
1685 
1686           IF ( (  NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD) = l_ACD_ADD
1687                   AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE )
1688                OR  l_rev_sub_res_unexp_rec.resource_id <>
1689                    NVL(l_rev_sub_res_unexp_rec.new_resource_id, l_rev_sub_res_unexp_rec.resource_id )
1690              )
1691           THEN
1692 
1693 
1694              /* Call Val_Resource_Id */
1695              BOM_Validate_Op_Res.Val_Resource_Id
1696                              (  p_resource_id   => NVL(l_rev_sub_res_unexp_rec.new_resource_id,
1697                                                        l_rev_sub_res_unexp_rec.resource_id )
1698                              ,  p_op_seq_id     => l_rev_sub_res_unexp_rec.operation_sequence_id
1699                              ,  x_return_status => l_temp_status
1700                              ) ;
1701 
1702 
1703              IF  l_temp_status = FND_API.G_RET_STS_ERROR
1704              THEN
1705                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
1706                 THEN
1707                    Error_Handler.Add_Error_Token
1708                    (  p_message_name   => 'BOM_SUB_RES_RESID_INVALID'
1709                     , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1710                     , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1711                     , p_Token_Tbl      => l_Token_Tbl
1712                    ) ;
1713                 END IF ;
1714 
1715                 l_return_status := FND_API.G_RET_STS_ERROR ;
1716 
1717           IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1718           ('Check if Resource is enabled. . . . ' || l_return_status) ;
1719           END IF ;
1720 
1721              END IF ;
1722           END IF ;
1723 
1724           --
1725           -- Check Uniqueness of Sub Op Resource Record
1726           --
1727           IF ( (  NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD) = l_ACD_ADD
1728                   AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE )
1729                OR  l_rev_sub_res_unexp_rec.resource_id <>
1730                    NVL(l_rev_sub_res_unexp_rec.new_resource_id, l_rev_sub_res_unexp_rec.resource_id )
1731                OR  l_rev_sub_resource_rec.replacement_Group_number <>  -- bug 3741570
1732                    NVL(l_rev_sub_resource_rec.new_replacement_Group_number, l_rev_sub_resource_rec.replacement_Group_number)
1733                OR  l_rev_sub_resource_rec.basis_type <>
1734                    NVL(l_rev_sub_resource_rec.new_basis_type, l_rev_sub_resource_rec.basis_type)
1735                OR  l_rev_sub_resource_rec.schedule_flag <>
1736  	                    NVL(l_rev_sub_resource_rec.new_schedule_flag,  l_rev_sub_resource_rec.schedule_flag)  /* Added for bug 13005178 */
1737              )
1738           THEN
1739              IF     BOM_Rtg_Globals.Get_Bo_Identifier = BOM_Rtg_Globals.G_RTG_BO
1740                 AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_UPDATE
1741              THEN
1742 
1743                  FOR l_duplicate_rec  IN  l_duplicate_csr
1744                  (    p_resource_id            => NVL(l_rev_sub_res_unexp_rec.new_resource_id,
1745                                                       l_rev_sub_res_unexp_rec.resource_id )
1746                     , p_substitute_group_number => nvl(l_rev_sub_resource_rec.substitute_group_number,
1747                                                        l_rev_sub_res_unexp_rec.substitute_group_number)
1748                     , p_replacement_group_number => NVL(l_rev_sub_resource_rec.new_replacement_Group_number, -- bug 3741570
1749                                                         l_rev_sub_resource_rec.replacement_Group_number)
1750                     , p_op_seq_id              => l_rev_sub_res_unexp_rec.operation_sequence_id
1751                     , p_acd_type               => l_rev_sub_resource_rec.acd_type
1752                     , p_basis_type             => NVL(l_rev_sub_resource_rec.new_basis_type,
1753                                                       l_rev_sub_resource_rec.basis_type)
1754                     , p_schedule_flag          => NVL(l_rev_sub_resource_rec.new_schedule_flag,
1755  	                                                       l_rev_sub_resource_rec.schedule_flag)      /* Added for bug 13005178 */
1756                   )
1757 
1758                  LOOP
1759                     l_Token_Tbl(1).token_name  := 'SUB_RESOURCE_CODE';
1760                     l_Token_Tbl(1).token_value :=
1761                                 p_rev_sub_resource_rec.new_sub_resource_code ;
1762                     l_token_tbl(3).token_name  := 'OP_SEQ_NUMBER';
1763                     l_token_tbl(3).token_value := l_rev_sub_resource_rec.operation_sequence_number ;
1764 
1765                     IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
1766                     THEN
1767                        Error_Handler.Add_Error_Token
1768                        (  p_message_name   => 'BOM_SUB_RES_NOTUNIQUE'
1769                         , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1770                         , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1771                         , p_Token_Tbl      => l_Token_Tbl
1772                        ) ;
1773                     END IF ;
1774 
1775                     l_return_status := FND_API.G_RET_STS_ERROR ;
1776 
1777                     l_Token_Tbl(1).token_name  := 'SUB_RESOURCE_CODE';
1778                     l_Token_Tbl(1).token_value :=
1779                                 p_rev_sub_resource_rec.sub_resource_code ;
1780                     l_token_tbl.delete(3) ;
1781                  END LOOP ;
1782              ELSIF     BOM_Rtg_Globals.Get_Bo_Identifier = BOM_Rtg_Globals.G_ECO_BO
1783              THEN
1784                  l_old_op_seq_id := Get_Old_Op_Seq_Id
1785                                     (p_op_seq_id =>
1786                                      l_rev_sub_res_unexp_rec.operation_sequence_id ) ;
1787 
1788 
1789                  FOR l_duplicate_rec  IN  l_duplicate_csr
1790                  (    p_resource_id            => NVL(l_rev_sub_res_unexp_rec.new_resource_id,
1791                                                       l_rev_sub_res_unexp_rec.resource_id )
1792                     , p_substitute_group_number => nvl(l_rev_sub_resource_rec.substitute_group_number,
1793                                                        l_rev_sub_res_unexp_rec.substitute_group_number)
1794                     , p_replacement_group_number => l_rev_sub_resource_rec.replacement_Group_number -- bug 3741570
1795                     , p_op_seq_id              => l_old_op_seq_id
1796                     , p_acd_type               => l_rev_sub_resource_rec.acd_type
1797                     , p_basis_type             => l_rev_sub_resource_rec.basis_type
1798                     , p_schedule_flag          => l_rev_sub_resource_rec.schedule_flag   /* Added for bug 13005178 */
1799                   )
1800 
1801                  LOOP
1802                     l_Token_Tbl(1).token_name  := 'SUB_RESOURCE_CODE';
1803                     l_Token_Tbl(1).token_value :=
1804                                 NVL(p_rev_sub_resource_rec.new_sub_resource_code,
1805                                     p_rev_sub_resource_rec.sub_resource_code    ) ;
1806                     l_token_tbl(3).token_name  := 'OP_SEQ_NUMBER';
1807                     l_token_tbl(3).token_value := l_rev_sub_resource_rec.operation_sequence_number ;
1808 
1809                     IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
1810                     THEN
1811                        Error_Handler.Add_Error_Token
1812                        (  p_message_name   => 'BOM_SUB_RES_NOTUNIQUE'
1813                         , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1814                         , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1815                         , p_Token_Tbl      => l_Token_Tbl
1816                        ) ;
1817                     END IF ;
1818 
1819                     l_return_status := FND_API.G_RET_STS_ERROR ;
1820 
1821                     l_Token_Tbl(1).token_name  := 'SUB_RESOURCE_CODE';
1822                     l_Token_Tbl(1).token_value := p_rev_sub_resource_rec.sub_resource_code ;
1823 
1824                     l_token_tbl.delete(3) ;
1825 
1826                  END LOOP ;
1827 
1828                  IF l_old_op_seq_id IS NULL THEN
1829                         -- This is an unexpected error.
1830                         Error_Handler.Add_Error_Token
1831                         (  p_Message_Name       => NULL
1832                          , p_Message_Text       => 'Unexpected error occurred. Sinse
1833                                                     Parent Revised Operation does not have old operation
1834                                                     sequence id'  || ' in ' ||
1835                                                    G_PKG_NAME
1836                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1837                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1838                         );
1839                         l_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1840                  END IF;
1841 
1842              END IF ;
1843 
1844           IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1845           ('Check uniquness of Sub Op Resource Record. . . . ' || l_return_status) ;
1846           END IF ;
1847 
1848           END IF ;
1849 
1850           --
1851           -- Activity Id
1852           -- Check if Activity is enabled
1853           -- BOM_Validate_Op_Res.Val_Activity_Id
1854           --
1855           IF ( (  NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD) = l_ACD_ADD
1856                   AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE )
1857                   OR NVL(l_rev_sub_res_unexp_rec.activity_id, FND_API.G_MISS_NUM)
1858                       <> NVL(p_old_rev_sub_res_unexp_rec.activity_id, FND_API.G_MISS_NUM)
1859               )
1860              AND ( l_rev_sub_res_unexp_rec.activity_id IS NOT NULL AND
1861                    l_rev_sub_res_unexp_rec.activity_id <> FND_API.G_MISS_NUM )
1862           THEN
1863 
1864           IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1865           ('Activity_Id : ' || to_char(l_rev_sub_res_unexp_rec.activity_id)) ;
1866           END IF ;
1867 
1868 
1869              /* Call Val_Activity_Id */
1870              BOM_Validate_Op_Res.Val_Activity_Id
1871                              (  p_activity_id   => l_rev_sub_res_unexp_rec.activity_id
1872                              ,  p_op_seq_id     => l_rev_sub_res_unexp_rec.operation_sequence_id
1873                              ,  x_return_status => l_temp_status
1874                              ) ;
1875 
1876 
1877              IF  l_temp_status = FND_API.G_RET_STS_ERROR
1878              THEN
1879                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
1880                 THEN
1881                    Error_Handler.Add_Error_Token
1882                    (  p_message_name   => 'BOM_SUB_RES_ACTID_INVALID'
1883                     , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1884                     , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1885                     , p_Token_Tbl      => l_Token_Tbl
1886                    ) ;
1887                 END IF ;
1888 
1889                 l_return_status := FND_API.G_RET_STS_ERROR ;
1890 
1891              END IF ;
1892 
1893           IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1894           ('Check if Activity is enabled. . . . ' || l_return_status) ;
1895           END IF ;
1896 
1897           END IF ;
1898 
1899 
1900           --
1901           -- Activity Id
1902           -- Check if Activity is enabled
1903           -- BOM_Validate_Op_Res.Val_Activity_Id
1904           --
1905           IF ( (  NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD) = l_ACD_ADD
1906                   AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE )
1907                   OR NVL(l_rev_sub_res_unexp_rec.setup_Id , FND_API.G_MISS_NUM)
1908                       <> NVL(p_old_rev_sub_res_unexp_rec.setup_id, FND_API.G_MISS_NUM)
1909               )
1910              AND ( l_rev_sub_res_unexp_rec.setup_id IS NOT NULL AND
1911                    l_rev_sub_res_unexp_rec.setup_Id <> FND_API.G_MISS_NUM )
1912           THEN
1913 
1914           IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1915           ('Setup_Id : ' || to_char(l_rev_sub_res_unexp_rec.setup_id )) ;
1916           END IF ;
1917 
1918 
1919              /* Call Val_Activity_Id */
1920              BOM_Validate_Op_Res.Val_Setup_Id
1921              (  p_setup_id          => l_rev_sub_res_unexp_rec.setup_id
1922              ,  p_resource_id       =>  NVL(l_rev_sub_res_unexp_rec.new_resource_id,
1923                                             l_rev_sub_res_unexp_rec.resource_id )
1924              ,  p_organization_id   => l_rev_sub_res_unexp_rec.organization_id
1925              ,  x_return_status     => l_temp_status
1926              ) ;
1927 
1928 
1929              IF  l_temp_status = FND_API.G_RET_STS_ERROR
1930              THEN
1931                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
1932                 THEN
1933 
1934 
1935                    l_token_tbl(3).token_name  := 'SETUP_CODE';
1936                    l_token_tbl(3).token_value :=
1937                                         l_rev_sub_resource_rec.setup_type ;
1938 
1939                    Error_Handler.Add_Error_Token
1940                    (  p_message_name   => 'BOM_SUB_RES_SETUPID_INVALID'
1941                     , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1942                     , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1943                     , p_Token_Tbl      => l_Token_Tbl
1944                    ) ;
1945                 END IF ;
1946 
1947                 l_token_tbl.delete(3) ;
1948                 l_return_status := FND_API.G_RET_STS_ERROR ;
1949 
1950              END IF ;
1951 
1952           IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1953           ('Check if Setup is enabled. . . . ' || l_return_status) ;
1954           END IF ;
1955 
1956           END IF ;
1957 
1958 
1959           --
1960           -- Schedule Flag
1961           -- Schedule Flag must be 2:No in following case
1962           -- 1. Resource UOM <> Hour UOM code(if they're the same, class would be
1963           --    same
1964           -- 2. Resource UOM class <> Hour UOM class
1965           -- 3. No conversion between resource UOM and Hour UOM
1966           --
1967           -- Call BOM_Validate_Op_Res.Get_Resource_Uom
1968           --      and BOM_Validate_Op_Res.Val_Res_UOM_For_Schedule
1969           --
1970           IF  p_rev_sub_resource_rec.schedule_flag <> l_NO_SCHEDULE -- 2: No
1971           THEN
1972 
1973              IF ( l_hour_uom_code   IS NULL OR
1974                   l_hour_uom_class  IS NULL OR
1975                   l_res_uom_code    IS NULL OR
1976                   l_res_uom_class   IS NULL
1977                  )
1978              THEN
1979                 BOM_Validate_Op_Res.Get_Resource_Uom
1980                                  ( p_resource_id
1981                                   => NVL(l_rev_sub_res_unexp_rec.new_resource_id,
1982                                          l_rev_sub_res_unexp_rec.resource_id)
1983                                  , x_hour_uom_code  => l_hour_uom_code
1984                                  , x_hour_uom_class => l_hour_uom_class
1985                                  , x_res_uom_code   => l_res_uom_code
1986                                  , x_res_uom_class  => l_res_uom_class ) ;
1987              END IF ;
1988 
1989              /* Call Val_Scheduled_Resource */
1990              BOM_Validate_Op_Res.Val_Res_UOM_For_Schedule
1991                 ( p_hour_uom_class  => l_hour_uom_class
1992                 , p_res_uom_class   => l_res_uom_class
1993                 , p_hour_uom_code   => l_hour_uom_code
1994                 , p_res_uom_code    => l_res_uom_code
1995                 , x_return_status   => l_temp_status
1996                 ) ;
1997 
1998              IF  l_temp_status = FND_API.G_RET_STS_ERROR
1999              THEN
2000                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2001                 THEN
2002                       Error_Handler.Add_Error_Token
2003                       (  p_message_name   => 'BOM_SUB_RES_SCHEDULE_MUSTBE_NO'
2004                        , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2005                        , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2006                        , p_Token_Tbl      => l_Token_Tbl
2007                       ) ;
2008                 END IF ;
2009 
2010                 l_return_status := FND_API.G_RET_STS_ERROR ;
2011 
2012              END IF ;
2013 
2014 IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
2015           ('Check if schedule flag is valid. . . . ' || l_return_status) ;
2016 END IF ;
2017 
2018           END IF ;
2019 
2020           --
2021           -- Scheduled Resource
2022           -- Cannot have more than one next or prior sheduled resource for
2023           -- an operation.
2024           -- Hence, there must be related one next or prior sheduled resource
2025           -- in operation resource
2026           -- and cannot have more than one next or prior sheduled sub resource
2027           -- whitin substitute group num.
2028           --
2029           IF  ( ( NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD) = l_ACD_ADD
2030                   AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE )
2031               OR  l_rev_sub_resource_rec.schedule_flag
2032                                      <> p_old_rev_sub_resource_rec.schedule_flag
2033               )
2034           THEN
2035 
2036              IF p_rev_sub_resource_rec.schedule_flag  = l_PRIOR -- 3: Prior
2037              THEN
2038                 /* Call Val_Scheduled_Sub_Resource
2039                 -- From does not have this validation, then comment out
2040                 Val_Scheduled_Sub_Resource
2041                 ( p_op_seq_id     => l_rev_sub_res_unexp_rec.operation_sequence_id
2042                 , p_resource_id   => l_rev_sub_res_unexp_rec.resource_id
2043                 , p_sub_group_num => l_rev_sub_res_unexp_rec.substitute_group_number
2044                 , p_schedule_flag => l_rev_sub_resource_rec.schedule_flag
2045                 , x_return_status => l_temp_status
2046                 ) ;
2047                */
2048 
2049 
2050                 IF  l_temp_status = FND_API.G_RET_STS_ERROR
2051                 THEN
2052                    IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2053                    THEN
2054                       Error_Handler.Add_Error_Token
2055                       (  p_message_name   => 'BOM_SUB_RES_PRIOR_INVALID'
2056                        , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2057                        , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2058                        , p_Token_Tbl      => l_Token_Tbl
2059                       ) ;
2060                    END IF ;
2061 
2062                    l_return_status := FND_API.G_RET_STS_ERROR ;
2063 
2064                 END IF ;
2065 
2066              ELSIF p_rev_sub_resource_rec.schedule_flag  = l_NEXT -- 4: Next
2067              THEN
2068 
2069                 /* Call Val_Scheduled_Sub_Resource
2070                 -- From does not have this validation, then comment out
2071                 Val_Scheduled_Sub_Resource
2072                 ( p_op_seq_id     => l_rev_sub_res_unexp_rec.operation_sequence_id
2073                 , p_resource_id   => l_rev_sub_res_unexp_rec.resource_id
2074                 , p_sub_group_num => l_rev_sub_res_unexp_rec.substitute_group_number
2075                 , p_schedule_flag => l_rev_sub_resource_rec.schedule_flag
2076                 , x_return_status => l_temp_status
2077                 ) ;
2078                 */
2079 
2080                 IF  l_temp_status = FND_API.G_RET_STS_ERROR
2081                 THEN
2082                    IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2083                    THEN
2084                       Error_Handler.Add_Error_Token
2085                       (  p_message_name   => 'BOM_SUB_RES_NEXT_INVALID'
2086                        , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2087                        , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2088                        , p_Token_Tbl      => l_Token_Tbl
2089                       ) ;
2090                    END IF ;
2091 
2092                    l_return_status := FND_API.G_RET_STS_ERROR ;
2093 
2094                 END IF ;
2095 
2096 IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
2097           ('Check next or prior scheduled resource. . . . ' || l_return_status) ;
2098 END IF ;
2099 
2100              END IF ;
2101 
2102           END IF ;
2103 
2104           --
2105           -- Autocharge Type
2106           -- Autocharge type cannot be PO Receipt if the
2107           -- department has no location.
2108           -- Call BOM_Validate_Op_Res.Val_Dept_Has_Location
2109           --
2110           IF ( ( NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD) = l_ACD_ADD
2111                  AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE )
2112              OR  l_rev_sub_resource_rec.autocharge_type <> p_old_rev_sub_resource_rec.autocharge_type
2113              )
2114              AND l_rev_sub_resource_rec.autocharge_type = l_PO_RECEIPT
2115           THEN
2116 
2117                 /* Call Val_Dept_Has_Location */
2118                 BOM_Validate_Op_Res.Val_Dept_Has_Location
2119                 ( p_op_seq_id     => l_rev_sub_res_unexp_rec.operation_sequence_id
2120                 , x_return_status => l_temp_status
2121                 ) ;
2122 
2123              IF  l_temp_status = FND_API.G_RET_STS_ERROR
2124              THEN
2125                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2126                 THEN
2127                       Error_Handler.Add_Error_Token
2128                       (  p_message_name   => 'BOM_SUB_RES_POAUTO_LOC_INVALID'
2129                        , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2130                        , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2131                        , p_Token_Tbl      => l_Token_Tbl
2132                       ) ;
2133                 END IF ;
2134 
2135                 l_return_status := FND_API.G_RET_STS_ERROR ;
2136 
2137              END IF ;
2138 
2139 IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
2140      ('Check if Dept has a location for PO Receipt Res. . . . ' || l_return_status) ;
2141 END IF ;
2142 
2143           END IF ;
2144 
2145 
2146           --
2147           -- Autocharge Type
2148           -- Autocharge Type cannot be PO Move or PO Receipt if the resource
2149           -- is non-OSP resource
2150           -- Call BOM_Validate_Op_Res.Val_Autocharge_for_OSP_Res
2151           --
2152           IF ( ( NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD) = l_ACD_ADD
2153                  AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE )
2154              OR  l_rev_sub_resource_rec.autocharge_type <> p_old_rev_sub_resource_rec.autocharge_type
2155              )
2156              AND l_rev_sub_resource_rec.autocharge_type IN (l_PO_RECEIPT, l_PO_MOVE )
2157           THEN
2158 
2159                 /* Call Val_Autocharge_for_OSP_Res */
2160                 BOM_Validate_Op_Res.Val_Autocharge_for_OSP_Res
2161                 ( p_resource_id     => NVL(l_rev_sub_res_unexp_rec.new_resource_id,
2162                                          l_rev_sub_res_unexp_rec.resource_id)
2163                 , p_organization_id => l_rev_sub_res_unexp_rec.organization_id
2164                 , x_return_status   => l_temp_status
2165                 ) ;
2166 
2167 
2168              IF  l_temp_status = FND_API.G_RET_STS_ERROR
2169              THEN
2170                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2171                 THEN
2172                       Error_Handler.Add_Error_Token
2173                       (  p_message_name   => 'BOM_SUB_RES_AUTO_CSTCD_INVALID'
2174                        , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2175                        , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2176                        , p_Token_Tbl      => l_Token_Tbl
2177                       ) ;
2178                 END IF ;
2179 
2180                 l_return_status := FND_API.G_RET_STS_ERROR ;
2181 
2182              END IF ;
2183 
2184 IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
2185      ('Check if resource is OSP resource when autocharge is PO Move or PO Receipt. . . . ' || l_return_status) ;
2186 END IF ;
2187 
2188           END IF ;
2189 
2190           --
2191           -- Autocharge Type
2192           -- Cannnot have more than one PO Move per an operation
2193           -- Hence, there must be related PO Move resource in operation resource
2194           -- and cannot have more than one PO Move whitin substitute group num.
2195           --
2196           IF ( ( NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD) = l_ACD_ADD
2197                  AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE )
2198              OR  l_rev_sub_resource_rec.autocharge_type <> p_old_rev_sub_resource_rec.autocharge_type
2199              )
2200              AND l_rev_sub_resource_rec.autocharge_type = l_PO_MOVE
2201           THEN
2202 
2203                 /* Call Val_Sub_PO_Move
2204                 -- From does not have this validation, then comment out
2205                 Val_Sub_PO_Move
2206                 ( p_op_seq_id     => l_rev_sub_res_unexp_rec.operation_sequence_id
2207                 , p_resource_id   => l_rev_sub_res_unexp_rec.resource_id
2208                 , p_sub_group_num => l_rev_sub_res_unexp_rec.substitute_group_number
2209                 , x_return_status => l_temp_status
2210                 ) ;
2211                 */
2212 
2213              IF  l_temp_status = FND_API.G_RET_STS_ERROR
2214              THEN
2215 
2216                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2217                 THEN
2218                    Error_Handler.Add_Error_Token
2219                    (  p_message_name   => 'BOM_SUB_RES_POMOVE_INVALID'
2220                     , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2221                     , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2222                     , p_Token_Tbl      => l_Token_Tbl
2223                    ) ;
2224                 END IF ;
2225 
2226                 l_return_status := FND_API.G_RET_STS_ERROR ;
2227              END IF ;
2228 
2229 IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
2230           ('Check if Autocharge Type is enabled. . . . ' || l_return_status) ;
2231 END IF ;
2232 
2233 
2234           END IF ;
2235 
2236 
2237           --
2238           -- Usage Rate or Amount
2239           -- Check round values for Usage Rate or Amount and the Inverse.
2240           -- Call BOM_Validate_Op_Res.Val_Usage_Rate_or_Amount
2241           --
2242           IF ( ( NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD) = l_ACD_ADD
2243                  AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE )
2244              OR  l_rev_sub_resource_rec.usage_rate_or_amount
2245                                         <> p_old_rev_sub_resource_rec.usage_rate_or_amount
2246              OR  l_rev_sub_resource_rec.usage_rate_or_amount_inverse
2247                                         <> p_old_rev_sub_resource_rec.usage_rate_or_amount_inverse
2248              )
2249           THEN
2250 
2251              /* Call Val_Usage_Rate_or_Amount */
2252              BOM_Validate_Op_Res.Val_Usage_Rate_or_Amount
2253               (  p_usage_rate_or_amount          => l_rev_sub_resource_rec.usage_rate_or_amount
2254               ,  p_usage_rate_or_amount_inverse  => l_rev_sub_resource_rec.usage_rate_or_amount_inverse
2255               ,  x_return_status                 => l_temp_status
2256               ) ;
2257 
2258 
2259              IF  l_temp_status = FND_API.G_RET_STS_ERROR
2260              THEN
2261                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2262                 THEN
2263                    Error_Handler.Add_Error_Token
2264                    (  p_message_name   => 'BOM_SUB_RES_RATEORAMT_INVALID'
2265                     , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2266                     , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2267                     , p_Token_Tbl      => l_Token_Tbl
2268                    ) ;
2269                 END IF ;
2270 
2271                 l_return_status := FND_API.G_RET_STS_ERROR ;
2272 
2273              END IF ;
2274 
2275 IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
2276      ('Check round value for Usage Rate or Amount and the Inverse . . . ' || l_return_status) ;
2277 END IF ;
2278 
2279           END IF ;
2280 
2281 
2282           --
2283           -- Usage Rate or Amount
2284           -- Cannot have negative usage rate or amount in following case
2285           -- 1. Autocharge Type = 3: PO Receipt or 4: PO Move
2286           -- 2. Schedul Flag <> 2
2287           -- comment out 3. Resource UOM Class = Hour UOM Class
2288           -- Form allows No.3
2289           --
2290 
2291           IF ( ( NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD) = l_ACD_ADD
2292                  AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE )
2293              OR  l_rev_sub_resource_rec.usage_rate_or_amount
2294                                         <> p_old_rev_sub_resource_rec.usage_rate_or_amount
2295              OR  l_rev_sub_resource_rec.usage_rate_or_amount_inverse
2296                                         <> p_old_rev_sub_resource_rec.usage_rate_or_amount_inverse
2297              OR  l_rev_sub_resource_rec.schedule_flag <> p_old_rev_sub_resource_rec.schedule_flag
2298              OR  l_rev_sub_resource_rec.autocharge_type <> p_old_rev_sub_resource_rec.autocharge_type
2299              )
2300              AND l_rev_sub_resource_rec.usage_rate_or_amount < 0
2301           THEN
2302              IF ( l_hour_uom_code   IS NULL OR
2303                   l_hour_uom_class  IS NULL OR
2304                   l_res_uom_code    IS NULL OR
2305                   l_res_uom_class   IS NULL
2306                  )
2307              THEN
2308                 BOM_Validate_Op_Res.Get_Resource_Uom
2309                       ( p_resource_id    => NVL(l_rev_sub_res_unexp_rec.new_resource_id,
2310                                                l_rev_sub_res_unexp_rec.resource_id)
2311                       , x_hour_uom_code  => l_hour_uom_code
2312                       , x_hour_uom_class => l_hour_uom_class
2313                       , x_res_uom_code   => l_res_uom_code
2314                       , x_res_uom_class  => l_res_uom_class ) ;
2315              END IF ;
2316 
2317 
2318              /* Call Val_Negative_Usage_Rate */
2319              BOM_Validate_Op_Res.Val_Negative_Usage_Rate
2320                ( p_autocharge_type => l_rev_sub_resource_rec.autocharge_type
2321                , p_schedule_flag   => l_rev_sub_resource_rec.schedule_flag
2322                , p_hour_uom_class  => l_hour_uom_class
2323                , p_res_uom_class   => l_res_uom_class
2324                , x_return_status   => l_temp_status
2325                ) ;
2326 
2327 
2328              IF  l_temp_status = FND_API.G_RET_STS_ERROR
2329              THEN
2330                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2331                 THEN
2332                    Error_Handler.Add_Error_Token
2333                    (  p_message_name   => 'BOM_SUB_RES_NEG_USAGRT_INVALID'
2334                     , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2335                     , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2336                     , p_Token_Tbl      => l_Token_Tbl
2337                    ) ;
2338                 END IF ;
2339 
2340                 l_return_status := FND_API.G_RET_STS_ERROR ;
2341 
2342              END IF ;
2343 
2344 IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
2345           ('Check negative usage rate. . . . ' || l_return_status) ;
2346 END IF ;
2347 
2348           END IF ;
2349 
2350 	  -- Principal Flag
2351           -- Cannot have one more principal resource in a group of simulatenous
2352           -- resources
2353           --
2354 	  /* Added by deepu. Validation for Principal flag is required for patchset I Bug 2689249*/
2355 
2356           IF  ( ( NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD) = l_ACD_ADD
2357                   AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE )
2358               OR  l_rev_sub_resource_rec.principle_flag
2359                                            <> p_old_rev_sub_resource_rec.principle_flag
2360               OR  l_rev_sub_resource_rec.replacement_group_number
2361                                            <> p_old_rev_sub_resource_rec.replacement_group_number
2362               OR  l_rev_sub_resource_rec.basis_type
2363                                            <> p_old_rev_sub_resource_rec.basis_type
2364               OR  l_rev_sub_resource_rec.schedule_flag
2365  	                    <> p_old_rev_sub_resource_rec.schedule_flag  /* Added for bug 13005178 */
2366                   )
2367               AND l_rev_sub_resource_rec.principle_flag = 1 -- Yes
2368           THEN
2369              -- Call Val_Principal_Res_Unique
2370              Val_Principal_Sub_Res_Unique
2371                 ( p_op_seq_id     => l_rev_sub_res_unexp_rec.operation_sequence_id
2372                 , p_res_id        => l_rev_sub_res_unexp_rec.resource_id
2373                 , p_sub_group_num => nvl(l_rev_sub_resource_rec.substitute_group_number, l_rev_sub_res_unexp_rec.substitute_group_number)
2374                 , p_rep_group_num => l_rev_sub_resource_rec.replacement_group_number
2375                 , p_basis_type    => l_rev_sub_resource_rec.basis_type
2376                 , p_schedule_flag => l_rev_sub_resource_rec.schedule_flag   /* Added for bug 13005178 */
2377                 , x_return_status => l_temp_status
2378                 ) ;
2379 
2380 
2381              IF  l_temp_status = FND_API.G_RET_STS_ERROR
2382              THEN
2383 -- dbms_output.put_line('found error in principal flag for sub resources');
2384 		IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2385                 THEN
2386                    Error_Handler.Add_Error_Token
2387                    (  p_message_name   => 'BOM_SUB_RES_PCFLAG_DUPLICATE'
2388                     , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2389                     , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2390                     , p_Token_Tbl      => l_Token_Tbl
2391                    ) ;
2392                 END IF ;
2393 
2394                 l_return_status := FND_API.G_RET_STS_ERROR ;
2395 
2396              END IF ;
2397 
2398           IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
2399           ('Check principal flag . . . . ' || l_return_status) ;
2400           END IF ;
2401 
2402           END IF ;
2403 
2404  /*Fix for bug 6074930- Scheduled simultaneous resources/sub-resources must have the same scheduling flag.
2405              Added below code to do this validation. Sub-Resources with scheduling flag 'NO' are exempt
2406              for this validation. Call Val_Schedule_Flag procedure both while creating/updating a sub-resource.
2407              For sub-resources schedule_sequence_number is a mandatory column.*/
2408 
2409              IF ( l_rev_sub_resource_rec.schedule_flag <> l_NO_SCHEDULE)
2410                 AND
2411                 ( ( NVL(l_rev_sub_resource_rec.acd_type,l_ACD_ADD) = l_ACD_ADD
2412                     AND l_rev_sub_resource_rec.transaction_type = BOM_Rtg_Globals.G_OPR_CREATE )
2413                 OR  l_rev_sub_resource_rec.schedule_sequence_number <> p_old_rev_sub_resource_rec.schedule_sequence_number
2414                 OR  l_rev_sub_resource_rec.schedule_flag <>  p_old_rev_sub_resource_rec.schedule_flag
2415                 )
2416              THEN
2417                    l_res_id := FND_API.G_MISS_NUM;
2418 
2419                    Val_Schedule_Flag
2420                    ( p_op_seq_id     => l_rev_sub_res_unexp_rec.operation_sequence_id
2421                    , p_res_seq_num          => null
2422                    , p_sch_seq_num   => l_rev_sub_resource_rec.schedule_sequence_number
2423                    , p_sch_flag          => l_rev_sub_resource_rec.schedule_flag
2424                    , p_sub_grp_num   => l_rev_sub_resource_rec.substitute_group_number
2425                    , p_rep_grp_num   => l_rev_sub_resource_rec.replacement_group_number
2426                    , p_basis_type    => l_rev_sub_resource_rec.basis_type
2427                    , p_in_res_id          => l_rev_sub_res_unexp_rec.resource_id
2428                    , p_ret_res_id          => l_res_id
2429                    , x_return_status => l_temp_status
2430                    );
2431 
2432                    IF l_temp_status = FND_API.G_RET_STS_ERROR THEN
2433                            IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
2434                              If (l_rev_sub_resource_rec.sub_resource_code is not null) Then
2435                                    l_res_code := l_rev_sub_resource_rec.sub_resource_code;
2436                              Else
2437                                    Select resource_code into l_res_code
2438                                    from bom_resources_v
2439                                    where resource_id=l_rev_sub_res_unexp_rec.resource_id;
2440                              End If;
2441 
2442                                    Select resource_code into l_res_code_2
2443                                    from bom_resources_v
2444                                    where resource_id=l_res_id;
2445 
2446                              l_Token_Tbl(1).Token_Name  := 'RES_SEQ_1';
2447                              l_Token_Tbl(1).Token_Value:=  l_res_code;
2448                              l_Token_Tbl(2).Token_Name  := 'RES_SEQ_2';
2449                              l_Token_Tbl(2).Token_Value:=  l_res_code_2;
2450                              l_Token_Tbl(3).Token_Name  := 'OP_SEQ';
2451                              l_Token_Tbl(3).Token_Value := l_rev_sub_resource_rec.operation_sequence_number;
2452 
2453                              Error_Handler.Add_Error_Token
2454                              ( p_message_name   => 'BOM_SIM_RES_SAME_PRIOR_NEXT'
2455                              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2456                              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
2457                              , p_Token_Tbl      => l_Token_Tbl
2458                              );
2459                            END IF; /* end of check_msg_level */
2460                          l_return_status := FND_API.G_RET_STS_ERROR ;
2461                   END IF; /* end of l_temp_status */
2462              END IF; /* end of validation on resource and ssn*/
2463            /*End of fix for bug 6074930 */
2464 
2465 
2466        END IF ; -- Transaction Type : Create and Update
2467 
2468 
2469       IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
2470        ('Entity Validation was processed. . . ' || l_return_status);
2471       END IF ;
2472 
2473 
2474 
2475        --
2476        -- Return Records
2477        --
2478        x_rev_sub_resource_rec    := l_rev_sub_resource_rec ;
2479        x_rev_sub_res_unexp_rec   := l_rev_sub_res_unexp_rec ;
2480 
2481        --
2482        -- Return Error Status
2483        --
2484        x_return_status  := l_return_status;
2485        x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
2486 
2487 
2488     EXCEPTION
2489        WHEN OTHERS THEN
2490           IF BOM_Rtg_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
2491           ('Some unknown error in Entity Validation . . .' || SQLERRM );
2492           END IF ;
2493 
2494 
2495           l_err_text := G_PKG_NAME || ' Validation (Entity Validation) '
2496                                 || substrb(SQLERRM,1,200);
2497           -- dbms_output.put_line('Unexpected Error: '||l_err_text);
2498 
2499           Error_Handler.Add_Error_Token
2500           (  p_message_name   => NULL
2501            , p_message_text   => l_err_text
2502            , p_mesg_token_tbl => l_mesg_token_tbl
2503            , x_mesg_token_tbl => l_mesg_token_tbl
2504           ) ;
2505 
2506           -- Return the status and message table.
2507           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2508           x_mesg_token_tbl := l_mesg_token_tbl ;
2509     END Check_Entity ;
2510 
2511 END BOM_Validate_Sub_Op_Res ;