DBA Data[Home] [Help]

PACKAGE BODY: APPS.INV_UI_RCV_LOVS

Source


1 PACKAGE BODY inv_ui_rcv_lovs AS
2 /* $Header: INVRCVLB.pls 120.56.12020000.4 2013/02/06 02:06:19 abasheer ship $ */
3 
4 
5 
6 --Bug No: 5246626:Added the procedures Print_debug and GET_RCV_SHP_FLEX_DETAILS
7 
8 PROCEDURE print_debug(p_err_msg VARCHAR2, p_level NUMBER) IS
9 
10 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
11 
12 BEGIN
13    IF (l_debug = 1) THEN
14        inv_mobile_helper_functions.tracelog(p_err_msg => p_err_msg, p_module => 'inv_ui_rcv_lovs', p_level => p_level);
15    END IF;
16 END print_debug;
17 
18 --      Name: GET_PO_LOV
19 --
20 --      Input parameters:
21 --       p_Organization_Id   which restricts LOV SQL to current org
22 --       p_po_number   which restricts LOV SQL to the user input text
23 --       p_manual_po_num_type  NUMERIC or ALPHANUMERIC
24 --       p_mobile_form   which mobile form this LOV is for (RECEIPT or DELIVER)
25 --                       SQL query will be different for these forms
26 --
27 --      Output parameters:
28 --       x_po_num_lov      returns LOV rows as reference cursor
29 --
30 --      Functions: This API returns PO number for a given org
31 --
32 
33 PROCEDURE GET_PO_LOV(x_po_num_lov OUT NOCOPY t_genref,
34          p_organization_id IN NUMBER,
35          p_po_number IN VARCHAR2,
36          p_mobile_form IN VARCHAR2,
37          p_shipment_header_id IN VARCHAR2)
38 
39    IS
40    l_append varchar2(2):='';
41 
42 BEGIN
43    IF (WMS_DEPLOY.wms_deployment_mode='L') THEN --LSP
44       l_append:='%';
45    END IF;
46    IF p_mobile_form = 'RCVTXN' THEN
47       OPEN x_po_num_lov FOR
48 
49 /*        SELECT DISTINCT poh.segment1
50   , poh.po_header_id
51   , poh.type_lookup_code
52   , MO_GLOBAL.get_ou_name(poh.org_id)  --<R12 MOAC>
53   , PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID)
54   , poh.vendor_id
55   , poh.vendor_site_id
56   , 'Vendor'
57   , poh.note_to_receiver
58   , to_char(poh.org_id)               --<R12 MOAC>
59   FROM rcv_supply ms
60   , rcv_transactions rt
61   , po_headers_all poh
62   , po_lines_all pol
63         , po_line_types plt
64         , mtl_parameters mp
65   WHERE poh.po_header_id = ms.po_header_id
66   AND ms.quantity > 0
67   AND ms.supply_type_code = 'RECEIVING'
68   AND ms.to_organization_id = p_organization_id
69   AND ms.supply_source_id = rt.transaction_id
70   AND rt.organization_id = ms.to_organization_id
71   AND rt.transaction_type <> 'UNORDERED'
72   AND mp.organization_id = ms.to_organization_id
73   AND poh.po_header_id = pol.po_header_id
74   AND pol.line_type_id = plt.line_type_id
75   AND (mp.wms_enabled_flag = 'N' OR (mp.wms_enabled_flag = 'Y'
76              AND (plt.outside_operation_flag = 'Y'
77             OR pol.item_id is NULL
78             OR exists (SELECT 1
79                  FROM mtl_system_items_kfv msik
80                  WHERE msik.inventory_item_id = pol.item_id
81                  AND msik.organization_id = p_organization_id
82                  AND msik.mtl_transactions_enabled_flag = 'N'))))
83         AND poh.segment1 LIKE (p_po_number)
84         AND (exists
85        (SELECT 1
86           FROM rcv_transactions rt1
87          WHERE rt1.transaction_id = rt.transaction_id
88            AND rt1.inspection_status_code <> 'NOT INSPECTED'
89            AND rt1.routing_header_id = 2)
90        OR rt.routing_header_id <> 2
91        OR rt.routing_header_id IS NULL)
92   ORDER BY   decode(rtrim(poh.segment1,'0123456789'),null,null,poh.segment1),
93   decode(rtrim(poh.segment1,'0123456789'),null,to_number(poh.segment1),null); --<R12 MOAC>  */
94 
95   /* Modified the above Query for Bug # 7113772. Removed the join from po_lines_all and po_line_types due to bad performance */
96 
97   SELECT DISTINCT poh.Segment1                            ,
98         poh.po_Header_Id                                  ,
99         poh.Type_LookUp_Code                              ,
100         wms_deploy.get_po_client_name(poh.po_header_id)   ,--LSP
101         MO_GLOBAL.get_ou_name(poh.org_id)                 ,--<R12 MOAC>
102         po_Vendors_sv2.Get_vendor_name_func(poh.Vendor_Id),
103         poh.Vendor_Id                                     ,
104         poh.Vendor_Site_Id                                ,
105         'Vendor'                                          ,
106         poh.Note_To_Receiver                              ,
107         to_char(poh.org_id)               --<R12 MOAC>
108 
109 FROM    rcv_Supply ms      ,
110         rcv_Transactions rt,
111         po_Headers_trx_v poh , -- CLM, bug 9403291
112         mtl_Parameters mp
113 WHERE   poh.po_Header_Id    = ms.po_Header_Id
114     AND ms.Quantity         > 0
115     AND ms.Supply_Type_Code = 'RECEIVING'
116     AND ms.To_Organization_Id = p_organization_id
117     AND ms.Supply_Source_Id  = rt.Transaction_Id
118     AND rt.Organization_Id   = ms.To_Organization_Id
119     AND rt.Transaction_Type <> 'UNORDERED'
120     AND mp.Organization_Id   = ms.To_Organization_Id
121     AND (mp.wms_Enabled_Flag = 'N'
122      OR (mp.wms_Enabled_Flag = 'Y'
123     AND ( EXISTS
124         (SELECT 1
125         FROM    po_Line_Types
126         WHERE   Outside_Operation_Flag = 'Y'
127             AND Line_Type_Id          IN
128                 (SELECT Line_Type_Id
129                 FROM    po_Lines_trx_v
130                 WHERE   po_Header_Id = poh.po_Header_Id
131                 )
132         )
133      OR EXISTS
134         (SELECT 1
135         FROM    po_Lines_trx_v -- CLM project, bug 9403291
136         WHERE   po_Header_Id = poh.po_Header_Id
137             AND Item_Id     IS NULL
138         )
139      OR EXISTS
140         (SELECT 1
141         FROM    mtl_System_Items_kfv msik
142         WHERE   msik.Inventory_Item_Id IN
143                 (SELECT Item_Id
144                 FROM    po_Lines_trx_v
145                 WHERE   po_Header_Id = poh.po_Header_Id
146                 )
147                 AND msik.Organization_Id = p_organization_id
148             AND msik.mtl_Transactions_Enabled_Flag = 'N'
149         ))))
150     AND poh.Segment1 LIKE (p_po_number||l_append)
151     AND (EXISTS
152         (SELECT 1
153         FROM    rcv_Transactions rt1
154         WHERE   rt1.Transaction_Id          = rt.Transaction_Id
155             AND rt1.Inspection_Status_Code <> 'NOT INSPECTED'
156             AND rt1.RoutIng_Header_Id       = 2
157         )
158      OR rt.RoutIng_Header_Id <> 2
159      OR rt.RoutIng_Header_Id IS NULL )
160   ORDER BY   decode(rtrim(poh.segment1,'0123456789'),null,null,poh.segment1),
161   decode(rtrim(poh.segment1,'0123456789'),null,to_number(poh.segment1),null); --<R12 MOAC>
162 
163 
164     ELSIF p_mobile_form = 'RECEIPT' THEN
165       OPEN x_po_num_lov FOR
166 
167     SELECT DISTINCT poh.segment1
168   , poh.po_header_id
169   , poh.type_lookup_code
170   , wms_deploy.get_po_client_name(poh.po_header_id)        --LSP
171   , MO_GLOBAL.get_ou_name(poh.org_id)     --<R12 MOAC>
172   , PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID)
173   , poh.vendor_id
174   , poh.vendor_site_id
175   , 'Vendor'
176   , poh.note_to_receiver
177   , to_char(poh.org_id)                   --<R12 MOAC>
178   FROM po_headers_trx_v poh      -- CLM project, bug 9403291
179   WHERE exists (SELECT 'Valid PO Shipments'
180             FROM po_line_locations_trx_v poll  -- CLM project, bug 9403291
181 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
182                , mtl_parameters mp,
183                  rcv_parameters rp
184 --  End for Bug 7440217
185            WHERE poh.po_header_id = poll.po_header_id
186              AND Nvl(poll.approved_flag,'N') =  'Y'
187              AND Nvl(poll.cancel_flag,'N') = 'N'
188              AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
189              AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
190           AND poll.ship_to_organization_id = p_organization_id
191 --  For Bug 7440217 Checking if it is LCM enabled
192           AND mp.organization_id = p_organization_id
193           AND rp.organization_id = p_organization_id
194           AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
195                      OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
196                         OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
197               )
198 --  End for Bug 7440217
199           )
200   AND poh.segment1 LIKE (p_po_number||l_append)
201   AND POH.TYPE_LOOKUP_CODE IN ('STANDARD','PLANNED', 'BLANKET','CONTRACT')
202   AND NVL(POH.CANCEL_FLAG, 'N') IN ('N', 'I')
203   AND NVL(POH.CLOSED_CODE, 'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3152693
204 ORDER BY   decode(rtrim(poh.segment1,'0123456789'),null,null,poh.segment1),
205   decode(rtrim(poh.segment1,'0123456789'),null,to_number(poh.segment1),null);--<R12 MOAC>
206 
207     ELSIF p_mobile_form = 'RCPTASN' THEN
208       OPEN x_po_num_lov FOR
209 
210   SELECT DISTINCT poh.segment1
211   , poh.po_header_id
212   , poh.type_lookup_code
213   , wms_deploy.get_po_client_name(poh.po_header_id)        --LSP
214   , MO_GLOBAL.get_ou_name(poh.org_id)    --<R12 MOAC>
215   , PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID)
216   , poh.vendor_id
217   , poh.vendor_site_id
218   , 'Vendor'
219   , poh.note_to_receiver
220   , to_char(poh.org_id)                  --<R12 MOAC>
221   FROM po_headers_trx_v poh              -- CLM project, bug 9403291
222   , rcv_shipment_lines rsl
223   WHERE exists (SELECT 'Valid PO Shipments'
224           FROM po_line_locations_trx_v poll -- CLM project, bug 9403291
225 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
226              , mtl_parameters mp,
227                rcv_parameters rp
228 --  End for Bug 7440217
229           WHERE poh.po_header_id = poll.po_header_id
230           AND Nvl(poll.approved_flag,'N') =  'Y'
231           AND Nvl(poll.cancel_flag,'N') = 'N'
232           AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
233           AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
234           AND poll.ship_to_organization_id = p_organization_id
235 --  For Bug 7440217 Checking if it is LCM enabled
236           AND mp.organization_id = p_organization_id
237           AND rp.organization_id = p_organization_id
238           AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
239                      OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
240                         OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
241               )
242 --  End for Bug 7440217
243           )
244   AND  poh.segment1 LIKE (p_po_number||l_append)
245   AND poh.po_header_id = rsl.po_header_id
246   AND POH.TYPE_LOOKUP_CODE IN ('STANDARD','PLANNED', 'BLANKET','CONTRACT')
247   AND NVL(POH.CANCEL_FLAG, 'N') IN ('N', 'I')
248   AND NVL(POH.CLOSED_CODE, 'OPEN') NOT IN ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED') -- 3152693
249   AND rsl.shipment_header_id = Nvl(To_number(p_shipment_header_id), rsl.shipment_header_id)
250   ORDER BY Decode(rtrim(poh.segment1,'0123456789'),null,null,poh.segment1),
251   Decode(rtrim(poh.segment1,'0123456789'),null,to_number(poh.segment1),null); --<R12 MOAC>
252 
253    ELSIF p_mobile_form = 'INSPECT' THEN
254       OPEN x_po_num_lov FOR
255       /*Bug: 4951739
256       Modified query: Referencing base table instead of
257       RCV_TRANSACTIONS_V
258       */
259       SELECT    DISTINCT poh.segment1   ,
260               poh.po_header_id   ,
261               poh.type_lookup_code   ,
262               wms_deploy.get_po_client_name(poh.po_header_id)        ,--LSP
263               MO_GLOBAL.get_ou_name(poh.org_id)   ,
264               PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID)   ,
265               poh.vendor_id   ,
266               poh.vendor_site_id   ,
267               'Vendor'   ,
268               poh.note_to_receiver   ,
269               to_char(poh.org_id)
270       FROM    RCV_SUPPLY RSUP,
271               RCV_TRANSACTIONS RT,
272               PO_LOOKUP_CODES PLC,
273               PO_LINES_trx_v pol, -- CLM project, bug 9403291
274               PO_LINE_LOCATIONS_trx_v PLL,   -- CLM project, bug 9403291
275               PO_HEADERS_trx_v POH,   -- CLM project, bug 9403291
276               po_line_types plt,--BUG 5166887
277               mtl_parameters mp --BUG 5166887
278 --  For Bug 7440217 Added RCV_PRAMETERS to find out if the organization is LCM enabled or not
279             , rcv_parameters rp
280 --  End for Bug 7440217
281       WHERE          RSUP.SUPPLY_TYPE_CODE                  =  'RECEIVING'
282               AND    RT.TRANSACTION_TYPE                    <>  'UNORDERED'
283               AND    RT.TRANSACTION_TYPE                    =  PLC.LOOKUP_CODE
284               AND    PLC.LOOKUP_TYPE                        =  'RCV TRANSACTION TYPE'
285               AND    RT.TRANSACTION_ID                      =  RSUP.RCV_TRANSACTION_ID
286               AND    PLL.LINE_LOCATION_ID(+)                =  RSUP.PO_LINE_LOCATION_ID
287               AND    NVL(PLL.MATCHING_BASIS(+),'QUANTITY')  <>  'AMOUNT'
288               AND    PLL.PAYMENT_TYPE IS NULL
289               AND    RSUP.po_header_id                =  poh.po_header_id
290               AND    RSUP.to_organization_id          =  p_organization_id
291               AND    RT.inspection_status_code        =  'NOT INSPECTED'
292               AND    RT.routing_header_id             =  2  /* Inspection routing */
293               AND    poh.segment1 LIKE (p_po_number||l_append)
294 
295               -- BUG 5166887: Do not return any rows if user access WMS org through the
296               -- MSCA menu option
297               AND    poh.po_header_id = pol.po_header_id
298               AND    pol.line_type_id = plt.line_type_id
299               AND    nvl(pol.item_id,-1) = nvl(rsup.item_id,-1)
300               AND    mp.organization_id = p_organization_id
301               AND    (mp.wms_enabled_flag = 'N'
302                       OR (mp.wms_enabled_flag = 'Y'
303                           AND (plt.outside_operation_flag = 'Y'
304                                OR pol.item_id is NULL
305                                OR exists (SELECT 1
306                                           FROM mtl_system_items_kfv msik
307                                           WHERE msik.inventory_item_id = pol.item_id
308                                           AND msik.organization_id = p_organization_id
309                                           AND msik.mtl_transactions_enabled_flag = 'N'))))
310               -- END BUG 5166887
311       ORDER BY   Decode(rtrim(poh.segment1,'0123456789'),          null,null,          poh.segment1),
312                  Decode(rtrim(poh.segment1,'0123456789'),          null,to_number(poh.segment1),          null);  --<R12 MOAC>
313    END IF;
314 
315 END get_po_lov;
316 
317 
318 
319 PROCEDURE GET_PO_RELEASE_LOV(x_po_release_num_lov OUT NOCOPY t_genref,
320            p_organization_id IN NUMBER,
321            p_po_header_id IN NUMBER,
322            p_mobile_form IN VARCHAR2,
323            p_po_release_num IN VARCHAR2)
324   IS
325  po_release_number VARCHAR2(20);
326 BEGIN
327     BEGIN
328        /* Start - Fix for Bug# 6640083 */
329        -- po_release_number := to_char(to_number(p_po_release_num));
330        -- This will convert String to number - Bug#6012703
331        -- Commented the code for  Bug#6640083
332        SELECT TRIM(LEADING '0' FROM p_po_release_num ) INTO po_release_number FROM Dual;
333            -- This will trim leading zeroes - Bug#6640083
334        /* End - Fix for Bug# 6640083 */
335     EXCEPTION
336      WHEN OTHERS then
337        po_release_number := p_po_release_num;
338     END;
339    IF p_mobile_form = 'RECEIPT' THEN
340       OPEN x_po_release_num_lov FOR
341         select distinct pr.release_num
342         , pr.po_release_id
343         , pr.release_date
344         from po_releases_all pr
345         where pr.po_header_id = p_po_header_id
346         --AND pr.org_id = p_organization_id
347         and nvl(pr.cancel_flag, 'N') = 'N'
348         and nvl(pr.approved_flag, 'N') <> 'N'
349         and nvl(pr.closed_code, 'OPEN') NOT IN ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
350         AND exists (SELECT 'Valid PO Shipments' --Added the exists to fix bug4350175
351                     FROM po_line_locations_all poll
352 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
353                        , mtl_parameters mp,
354                          rcv_parameters rp
355 --  End for Bug 7440217
356                     WHERE pr.po_header_id = poll.po_header_id
357                     AND pr.po_release_id = poll.po_release_id
358                     AND Nvl(poll.approved_flag,'N') =  'Y'
359                     AND Nvl(poll.cancel_flag,'N') = 'N'
360                     AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
361                     AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING','CLOSED')
362                     AND poll.ship_to_organization_id = p_organization_id
363 --  For Bug 7440217 Checking if it is LCM enabled
364                     AND mp.organization_id = p_organization_id
365                     AND rp.organization_id = p_organization_id
366                     AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
367                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
368                                 OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
369                         )
370 --  End for Bug 7440217
371                    )
372 	AND pr.release_num LIKE (po_release_number)
373         order by pr.release_num;
374     ELSE
375       OPEN x_po_release_num_lov FOR
376         select distinct pr.release_num
377         , pr.po_release_id
378         , pr.release_date
379         from rcv_supply rsup
380         , po_releases_all pr
381         where rsup.po_header_id = p_po_header_id
382         --AND pr.org_id = p_organization_id
383         and nvl(pr.cancel_flag, 'N') = 'N'
384         and nvl(pr.approved_flag, 'N') <> 'N'
385         AND rsup.po_release_id = pr.po_release_id
386 	AND pr.release_num LIKE (po_release_number)
387         order by pr.release_num;
388    END IF;
389 END GET_PO_RELEASE_LOV;
390 
391 
392 
393 --      Name: GET_PO_LINE_NUM_LOV
394 --
395 --      Input parameters:
396 --       p_Organization_Id   which restricts LOV SQL to current org
397 --       p_po_header_id      which restricts LOV SQL to the PO
398 --       p_po_line_num which restricts the LOV to the user input text.
399 --
400 --      Output parameters:
401 --       x_po_line_num_lov returns LOV rows as reference cursor
402 --
403 --      Functions: This API returns PO Line numbers for a given PO
404 --
405 PROCEDURE GET_PO_LINE_NUM_LOV(x_po_line_num_lov OUT NOCOPY t_genref,
406             p_organization_id IN NUMBER,
407             p_po_header_id IN NUMBER,
408             p_mobile_form IN VARCHAR2,
409             p_po_line_num IN VARCHAR2)
410   IS
411   po_line_number VARCHAR2(20);
412 BEGIN
413   -- Added for bug 9776756
414   if PO_CLM_INTG_GRP.is_clm_po(p_po_header_id,null,null,null) = 'Y' THEN
415      po_line_number := p_po_line_num;
416   else
417   -- End of Bug 9776756
418     BEGIN
419       /* Start - Fix for Bug# 6640083 */
420        --  po_line_number := to_char(to_number(p_po_line_num));
421        -- This will convert String to number - Bug#6012703
422        -- Commented the code for  Bug#6640083
423         SELECT TRIM(LEADING '0' FROM p_po_line_num ) INTO po_line_number FROM Dual;
424            -- This will trim leading zeroes - Bug#6640083
425        /* End - Fix for Bug# 6640083 */
426      EXCEPTION
427      WHEN OTHERS then
428        po_line_number := p_po_line_num;
429      END;
430    END IF; -- bug 9776756
431 
432    IF p_mobile_form = 'RECEIPT' THEN
433       OPEN x_po_line_num_lov FOR
434   select distinct pl.line_num
435              , pl.po_line_id
436              --Bug 7274407
437 			 , NVL(pl.item_description, msi.description)
438              , pl.item_id
439              , pl.item_revision
440              , msi.concatenated_segments
441        , msi.outside_operation_flag
442   from po_lines_trx_v pl   -- CLM project, bug 9403291
443              , mtl_system_items_vl msi
444          where pl.item_id = msi.inventory_item_id (+)
445            and Nvl(msi.organization_id, p_organization_id) = p_organization_id
446            and pl.po_header_id = p_po_header_id
447      and exists (SELECT 'Valid PO Shipments'
448                         FROM po_line_locations_trx_v poll -- CLM project, bug 9403291
449 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
450                            , mtl_parameters mp,
451                              rcv_parameters rp
452 --  End for Bug 7440217
453                        WHERE poll.po_header_id = pl.po_header_id
454        AND poll.po_line_id = pl.po_line_id
455                          AND Nvl(poll.approved_flag,'N') =  'Y'
456                          AND Nvl(poll.cancel_flag,'N') = 'N'
457              AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
458                          --AND poll.closed_code = 'OPEN'
459                          AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
460                          AND poll.ship_to_organization_id = p_organization_id
461 --  For Bug 7440217 Checking if it is LCM enabled
462                          AND mp.organization_id = p_organization_id
463                          AND rp.organization_id = p_organization_id
464                          AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
465                                   OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
466                                       OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
467                               )
468 --  End for Bug 7440217
469                          )
470            AND pl.line_num LIKE (po_line_number)
471          order by 1;
472     ELSE
473       OPEN x_po_line_num_lov FOR
474   select distinct pl.line_num
475              , pl.po_line_id
476              --Bug 7274407
477 			 , NVL(pl.item_description,msi.description) --bug 14645109
478              , pl.item_id
479              , pl.item_revision
480              , msi.concatenated_segments
481        , msi.outside_operation_flag
482          -- bug 2805640
483              , inv_ui_item_lovs.get_conversion_rate(mum.uom_code,
484                                    p_organization_id,
485                                    pl.Item_Id)
486                uom_code
487   FROM rcv_supply rsup
488          -- bug 2805640
489              , mtl_units_of_measure mum
490        , po_lines_trx_v pl -- CLM project, bug 9403291
491              , mtl_system_items_vl msi
492    WHERE rsup.po_line_id = pl.po_line_id
493          -- bug 2805640
494      and mum.UNIT_OF_MEASURE(+) = pl.UNIT_MEAS_LOOKUP_CODE
495      AND pl.item_id = msi.inventory_item_id (+)
496            and Nvl(msi.organization_id, p_organization_id) = p_organization_id
497            and rsup.po_header_id = p_po_header_id
498            AND pl.line_num LIKE (po_line_number)
499            AND rsup.to_organization_id = p_organization_id  --BUG 4108624
500          order by 1;
501    END IF;
502 END GET_PO_LINE_NUM_LOV;
503 
504 
505 
506 
507 --      Name: GET_LOCATION_LOV
508 --
509 --      Input parameters:
510 --       p_Organization_Id   which restricts LOV SQL to current org
511 --       p_location_code   which restricts LOV SQL to the user input text
512 --
513 --
514 --      Output parameters:
515 --       x_location      returns LOV rows as reference cursor
516 --
517 --      Functions: This API returns location for given org
518 
519 
520 PROCEDURE get_location_lov (x_location OUT NOCOPY t_genref,
521           p_organization_id IN NUMBER,
522           p_location_code IN VARCHAR2)
523   IS
524 BEGIN
525    -- this query is returning more than 50,000 record in dom1151
526    -- it is caused by nvl(inventory_organization_id,0) = 0 )
527    -- need to confirm
528    OPEN x_location FOR
529      SELECT location_code
530           , location_id
531           , description
532        FROM hr_locations hrl
533       WHERE (inventory_organization_id = p_organization_id
534        OR Nvl(inventory_organization_id,0) = 0)
535         AND receiving_site_flag = 'Y'
536         AND (inactive_date IS NULL OR inactive_date > Sysdate)
537         AND location_code LIKE (p_location_code)
538       ORDER BY Upper(location_code);
539 END get_location_lov;
540 
541 
542 
543 --      Name: get_freight_carrier_lov
544 --
545 --      Input parameters:
546 --       p_Organization_Id   which restricts LOV SQL to current org
547 --       p_freight_carrier  which restricts LOV SQL to the user input text
548 --
549 --
550 --      Output parameters:
551 --       x_location      returns LOV rows as reference cursor
552 --
553 --      Functions: This API returns freight carrier for given org
554 
555 
556 PROCEDURE get_freight_carrier_lov (x_freight_carrier OUT NOCOPY t_genref,
557            p_organization_id IN NUMBER,
558            p_freight_carrier IN VARCHAR2)
559   IS
560 BEGIN
561    OPEN x_freight_carrier FOR
562      select freight_code
563           , description
564        from org_freight
565       where organization_id = p_organization_id
566         and nvl(disable_date, sysdate+1) > sysdate
567         AND freight_code LIKE (p_freight_carrier)
568       order by upper(freight_code);
569 END get_freight_carrier_lov;
570 
571 
572 --      Name: GET_SHIPMENT_NUM_LOV
573 --
574 --      Input parameters:
575 --       p_Organization_Id   which restricts LOV SQL to current org
576 --       p_shipment_num   which restricts LOV SQL to the user input text
577 --       p_mobile_form   which mobile form this LOV is for (RECEIPT or DELIVER)
578 --                       SQL query will be different for these forms
579 --
580 --      Output parameters:
581 --       x_shipment_num_lov      returns LOV rows as reference cursor
582 --
583 --      Functions: This API returns Shipment number for a given org
584 --                 Also it returns an ASN numner for ASN receipt
585 
586 PROCEDURE GET_SHIPMENT_NUM_LOV(x_shipment_num_lov OUT NOCOPY t_genref,
587              p_organization_id IN NUMBER,
588              p_shipment_num IN VARCHAR2,
589              p_mobile_form IN VARCHAR2,
590              p_po_header_id IN VARCHAR2)
591 
592    IS
593 
594 BEGIN
595 
596 
597    IF p_mobile_form = 'RCVTXN' THEN
598       OPEN x_shipment_num_lov FOR
599 
600   SELECT DISTINCT rsh.shipment_num,
601   rsh.shipment_header_id,
602   rsh.shipped_date,
603   rsh.expected_receipt_date,
604   rsl.from_organization_id,
605   ood.organization_name,
606   'Organization',
607   rsh.packing_slip,
608   rsh.bill_of_lading,
609   rsh.waybill_airbill_num,
610   rsh.freight_carrier_code
611   FROM
612   rcv_shipment_headers rsh,
613   rcv_shipment_lines rsl,
614   rcv_supply ms,
615   rcv_transactions rt,
616   org_organization_definitions ood
617   WHERE rsh.shipment_header_id = ms.shipment_header_id
618   AND ms.to_organization_id = p_organization_id
619   AND rt.organization_id = p_organization_id
620   AND rsl.from_organization_id = ood.organization_id(+)
621   AND ms.supply_source_id = rt.transaction_id
622   AND ms.supply_type_code = 'RECEIVING'
623   AND rt.transaction_type <> 'UNORDERED'
624   AND rsl.shipment_header_id = rsh.shipment_header_id
625   AND Nvl(ms.quantity,0) > 0
626         AND (exists
627        (SELECT 1
628           FROM rcv_transactions rt1
629          WHERE rt1.transaction_id = rt.transaction_id
630            AND rt1.inspection_status_code <> 'NOT INSPECTED'
631            AND rt1.routing_header_id = 2)
632        OR rt.routing_header_id <> 2
633        OR rt.routing_header_id IS NULL)
634   AND rsh.shipment_num IS NOT NULL
635   AND rsh.shipment_num LIKE (p_shipment_num)
636   ORDER BY rsh.shipment_header_id DESC;
637 
638     ELSIF p_mobile_form = 'RECEIPT' THEN
639       OPEN x_shipment_num_lov FOR
640 
641   SELECT DISTINCT sh.shipment_num,
642   sh.shipment_header_id,
643   sh.shipped_date,
644   sh.expected_receipt_date,
645   Decode(sh.receipt_source_code,'VENDOR',sh.vendor_id, sl.from_organization_id) from_organization_id,
646   Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id,sl.from_organization_id),1,80) organization_name,
647   /* Bug 4253199 ** Receipt source code is fetched properly
648   Decode(sh.receipt_source_code,'VENDOR','Vendor','Organization'),
649   */
650   Decode(sh.receipt_source_code,'VENDOR','Vendor',sh.receipt_source_code),
651   sh.packing_slip,
652   sh.bill_of_lading,
653   sh.waybill_airbill_num,
654   sh.freight_carrier_code
655   FROM rcv_shipment_headers sh,
656   rcv_shipment_lines sl
657   WHERE sh.shipment_num IS NOT NULL
658     AND sh.shipment_header_id = sl.shipment_header_id
659     AND sl.to_organization_id = p_organization_id
660     AND sh.receipt_source_code IN ('INTERNAL ORDER','INVENTORY')
661     AND exists
662          (SELECT 'available supply'
663     FROM mtl_supply ms
664     WHERE ms.to_organization_id = p_organization_id
665     AND ms.shipment_header_id = sh.shipment_header_id)
666     -- This was fix for bug 2740648/2752094
667     AND sl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED')
668     AND sh.shipment_num LIKE (p_shipment_num)
669     ORDER BY sh.shipment_num;
670 
671     ELSIF p_mobile_form = 'RCPTASN' THEN
672       OPEN x_shipment_num_lov FOR
673 
674   SELECT DISTINCT sh.shipment_num,
675   sh.shipment_header_id,
676   sh.shipped_date,
677   sh.expected_receipt_date,
678   Decode(sh.receipt_source_code,'VENDOR',sh.vendor_id, sl.from_organization_id) from_organization_id,
679   Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id,sl.from_organization_id),1,80) organization_name,
680   Decode(sh.receipt_source_code,'VENDOR','Vendor','Organization'),
681   sh.packing_slip,
682   sh.bill_of_lading,
683   sh.waybill_airbill_num,
684   sh.freight_carrier_code
685   FROM rcv_shipment_headers sh,
686   rcv_shipment_lines sl
687   WHERE sh.shipment_num IS NOT NULL
688     AND sh.shipment_header_id = sl.shipment_header_id
689     AND sl.to_organization_id = p_organization_id
690     AND sl.po_header_id = Nvl(To_number(p_po_header_id), sl.po_header_id)
691     AND sh.receipt_source_code = 'VENDOR'
692     AND sl.shipment_line_status_code <> 'CANCELLED'
693     AND sh.shipment_header_id = sl.shipment_header_id
694     -- This was fix for bug 2740648/2752094
695     AND sh.asn_type in ('ASN','ASBN')
696     AND sl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED')
697     AND sl.to_organization_id = p_organization_id
698     AND sh.shipment_num LIKE (p_shipment_num)
699     ORDER BY sh.shipment_num;
700     ELSIF p_mobile_form = 'INSPECT' THEN
701       OPEN x_shipment_num_lov FOR
702       /*Bug: 4951739
703       Modified query: Referencing base table instead of
704       RCV_TRANSACTIONS_V
705       */
706       SELECT  DISTINCT   rsh.shipment_num,
707               rsh.shipment_header_id,
708               rsh.shipped_date,
709               rsh.expected_receipt_date,
710               rsl.from_organization_id,
711               ood.name organization_name,
712               'Organization',
713               rsh.packing_slip,
714               rsh.bill_of_lading,
715               rsh.waybill_airbill_num,
716               rsh.freight_carrier_code
717       FROM      RCV_SUPPLY RSUP,
718               RCV_SHIPMENT_LINES RSL,
719               RCV_TRANSACTIONS RT,
720               RCV_SHIPMENT_HEADERS RSH,
721               PO_LOOKUP_CODES PLC,
722               PO_LINE_LOCATIONS_ALL PLL,
723               HR_ALL_ORGANIZATION_UNITS_TL OOD
724 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
725             , mtl_parameters mp,
726               rcv_parameters rp
727 --  End for Bug 7440217
728       WHERE    RSH.receipt_source_code                     <>  'VENDOR'
729               AND    RSUP.SUPPLY_TYPE_CODE                  =  'RECEIVING'
730               AND    RT.TRANSACTION_TYPE                    <>  'UNORDERED'
731               AND    RT.TRANSACTION_TYPE                    =  PLC.LOOKUP_CODE
732               AND    PLC.LOOKUP_TYPE                        =  'RCV TRANSACTION TYPE'
733               AND    RSL.SHIPMENT_LINE_ID                   =  RSUP.SHIPMENT_LINE_ID
734               AND    RT.TRANSACTION_ID                      =  RSUP.RCV_TRANSACTION_ID
735               AND    RSH.SHIPMENT_HEADER_ID                 =  RSUP.SHIPMENT_HEADER_ID
736               AND    PLL.LINE_LOCATION_ID(+)                =  RSUP.PO_LINE_LOCATION_ID
737               AND    NVL(PLL.MATCHING_BASIS(+),'QUANTITY') <>  'AMOUNT'
738               AND    PLL.PAYMENT_TYPE IS NULL
739               AND    RSUP.to_organization_id          =  p_organization_id
740               AND    RT.inspection_status_code        =  'NOT INSPECTED'
741               AND    RT.routing_header_id             =  2 /* Inspection Routing */
742               AND    RSL.from_organization_id   =  OOD.organization_id(+)
743               AND    OOD.LANGUAGE(+)            =  USERENV('LANG')
744               AND    RSL.shipment_header_id     =  rsh.shipment_header_id
745               AND    RSH.shipment_num IS NOT NULL
746               AND    RSH.shipment_num LIKE (p_shipment_num)
747       ORDER BY RSH.shipment_header_id DESC;
748    END IF;
749 
750 END GET_SHIPMENT_NUM_LOV;
751 
752 
753 --      Name: GET_REQ_NUM_LOV
754 --
755 --      Input parameters:
756 --       p_Organization_Id   which restricts LOV SQL to current org
757 --       p_requisition_num   which restricts LOV SQL to the user input text
758 --       p_mobile_form   which mobile form this LOV is for (RECEIPT or DELIVER)
759 --                       SQL query will be different for these forms
760 --
761 --      Output parameters:
762 --       x_requisition_num_lov      returns LOV rows as reference cursor
763 --
764 --      Functions: This API returns Shipment number for a given org
765 --                 Also it returns an ASN numner for ASN receipt
766 
767 
768 PROCEDURE GET_REQ_NUM_LOV(x_requisition_num_lov OUT NOCOPY t_genref,
769         p_organization_id IN NUMBER,
770         p_requisition_num IN VARCHAR2,
771         p_mobile_form IN VARCHAR2
772         )
773   IS
774 
775 BEGIN
776 
777    IF p_mobile_form = 'RCVTXN' THEN
778       OPEN x_requisition_num_lov FOR
779 
780   SELECT DISTINCT
781   prh.segment1,
782   MO_GLOBAL.get_ou_name(prh.org_id), --<R12 MOAC>
783   prh.requisition_header_id,
784   prh.description,
785   NULL,
786   to_char(prh.org_id) --<R12 MOAC>
787   FROM
788   po_req_headers_trx_v prh, -- CLM project, bug 9403291
789   rcv_supply ms,
790   po_req_lines_trx_v prl,  -- CLM project, bug 9403291
791   rcv_transactions rt
792   WHERE
793   prh.requisition_header_id = ms.req_header_id
794   AND prl.requisition_header_id = prh.requisition_header_id
795   AND prl.destination_organization_id = p_organization_id
796   AND prl.source_type_code = 'INVENTORY'
797   AND ms.supply_source_id = rt.transaction_id
798   AND rt.transaction_type <> 'UNORDERED'
799   AND ms.quantity > 0
800   AND ms.supply_type_code = 'RECEIVING'
801   AND ms.to_organization_id = p_organization_id
802   AND rt.organization_id = p_organization_id
803   -- Bug# 3631580: Performance Fixes
804   -- Added the following line to avoid a full table scan
805   AND rt.requisition_line_id = prl.requisition_line_id
806         AND (exists
807        (SELECT 1
808           FROM rcv_transactions rt1
809          WHERE rt1.transaction_id = rt.transaction_id
810            AND rt1.inspection_status_code <> 'NOT INSPECTED'
811            AND rt1.routing_header_id = 2)
812        OR rt.routing_header_id <> 2
813        OR rt.routing_header_id IS NULL)
814   AND prh.segment1 LIKE (p_requisition_num)
815   ORDER BY prh.segment1;
816 
817     ELSIF p_mobile_form = 'RECEIPT' THEN
818       OPEN x_requisition_num_lov FOR
819 
820   SELECT DISTINCT
821   prh.segment1,
822   MO_GLOBAL.get_ou_name(prh.org_id),   --<R12 MOAC>
823   prh.requisition_header_id,
824   prh.description,
825   null,
826   to_char(prh.org_id)                 --<R12 MOAC>
827   FROM
828   po_req_headers_trx_v prh, -- CLM project, bug 9403291
829   po_req_lines_trx_v prl    -- CLM project, bug 9403291
830   WHERE
831   Nvl(prl.cancel_flag,'N') = 'N'
832   AND prl.destination_organization_id = p_organization_id
833   AND prh.requisition_header_id = prl.requisition_header_id
834   AND prh.authorization_status || '' = 'APPROVED'
835   AND prh.segment1 LIKE (p_requisition_num)
836   AND exists
837   (SELECT 1
838    FROM rcv_shipment_lines rsl
839    WHERE rsl.requisition_line_id = prl.requisition_line_id
840          AND rsl.routing_header_id > 0
841          AND rsl.shipment_line_status_code <> 'FULLY RECEIVED')
842   ORDER BY prh.segment1;
843     ELSIF p_mobile_form = 'INSPECT' THEN
844       --BUG 3421219: Returns the IR that needs to be inspected
845       --Look at RTV for routing_id = 2 and inspection_status_code =
846       --'NOT INSPECTED'
847       OPEN x_requisition_num_lov FOR
848   SELECT DISTINCT
849   prh.segment1,
850   MO_GLOBAL.get_ou_name(prh.org_id), --<R12 MOAC>
851   prh.requisition_header_id,
852   prh.description,
853   null,
854   to_char(prh.org_id)                --<R12 MOAC>
855   FROM
856   po_req_headers_trx_v prh, -- CLM project, bug 9403291
857   po_req_lines_trx_v prl  -- CLM project, bug 9403291
858   WHERE
859   Nvl(prl.cancel_flag,'N') = 'N'
860   AND prl.destination_organization_id = p_organization_id
861   AND prh.requisition_header_id = prl.requisition_header_id
862   AND prh.authorization_status || '' = 'APPROVED'
863   AND prh.segment1 LIKE (p_requisition_num)
864   AND exists
865   (SELECT 1
866    FROM rcv_shipment_lines rsl,
867    rcv_shipment_headers rsh,
868    rcv_transactions_v rtv
869    WHERE rsl.requisition_line_id = prl.requisition_line_id
870    AND rsh.shipment_header_id = rsl.shipment_header_id
871    AND rtv.shipment_header_id = rsh.shipment_header_id
872    AND rtv.shipment_line_id = rsl.shipment_line_id
873    AND rtv.receipt_source_code <> 'VENDOR'
874    AND rtv.inspection_status_code = 'NOT INSPECTED'
875    AND rtv.routing_id = 2
876          AND rsl.routing_header_id > 0
877    )
878   ORDER BY prh.segment1;
879    END IF;
880 
881 END get_req_num_lov;
882 
883 
884 
885 -- LOV for the pack slip numbers of a shipment (mainly sfor ASN)
886 -- Almost exactly same as shipment LOV
887 
888 
889 PROCEDURE  GET_PACK_SLIP_NUM_LOV(x_pack_slip_num_lov OUT NOCOPY t_genref,
890          p_organization_id IN NUMBER,
891          p_pack_slip_num IN VARCHAR2,
892          p_po_header_id IN VARCHAR2)
893     IS
894 
895 BEGIN
896    IF p_po_header_id IS NOT NULL THEN
897       OPEN x_pack_slip_num_lov FOR
898   SELECT DISTINCT sh.packing_slip,
899   sh.shipment_num,
900   sh.shipment_header_id,
901   sh.shipped_date,
902   sh.expected_receipt_date,
903   Decode(sh.receipt_source_code,'VENDOR',sh.vendor_id, sl.from_organization_id) from_organization_id,
904   Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id,sl.from_organization_id),1,80) organization_name,
905   Decode(sh.receipt_source_code,'VENDOR','Vendor','Organization')
906   FROM rcv_shipment_headers sh,
907   rcv_shipment_lines sl
908   WHERE sh.packing_slip IS NOT NULL
909     AND sh.shipment_header_id = sl.shipment_header_id
910     AND sl.to_organization_id = p_organization_id
911     AND sl.po_header_id = To_number(p_po_header_id)
912     AND ( sh.receipt_source_code = 'VENDOR'
913     AND sl.shipment_line_status_code <> 'CANCELLED')
914     AND sh.packing_slip LIKE (p_pack_slip_num)
915     ORDER BY sh.packing_slip;
916     ELSE
917       OPEN x_pack_slip_num_lov FOR
918   SELECT DISTINCT sh.packing_slip,
919   sh.shipment_num,
920   sh.shipment_header_id,
921   sh.shipped_date,
922   sh.expected_receipt_date,
923   Decode(sh.receipt_source_code,'VENDOR',sh.vendor_id, sl.from_organization_id) from_organization_id,
924   Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id,sl.from_organization_id),1,80) organization_name,
925   Decode(sh.receipt_source_code,'VENDOR','Vendor','Organization')
926   FROM rcv_shipment_headers sh,
927   rcv_shipment_lines sl
928   WHERE sh.packing_slip IS NOT NULL
929     AND sh.shipment_header_id = sl.shipment_header_id
930     AND sl.to_organization_id = p_organization_id
931     AND sl.po_header_id = Nvl(To_number(p_po_header_id), sl.po_header_id)
932     AND ( sh.receipt_source_code = 'VENDOR'
933     AND sl.shipment_line_status_code <> 'CANCELLED')
934     AND sh.packing_slip LIKE (p_pack_slip_num)
935     ORDER BY sh.packing_slip;
936    END IF;
937 END GET_PACK_SLIP_NUM_LOV;
938 
939 
940 -- LOV for the possible receipt numbers that can be used.
941 PROCEDURE GET_RECEIPT_NUMBER_LOV(x_getRcptNumLOV OUT NOCOPY t_genref,
942          p_organization_id IN NUMBER,
943          p_receipt_number IN VARCHAR2)
944   IS
945 BEGIN
946    OPEN x_getRcptNumLOV FOR
947      SELECT DISTINCT rsh.receipt_num
948           , Trunc(ms.receipt_date)
949           , rsh.shipment_header_id
950           , rsh.shipment_num
951           , rt.po_header_id
952           , rt.oe_order_header_id
953           , rt.po_release_id --bug6594996 add PO release header ID associated with the receip
954           , ms.from_organization_id    -- bug #6917248
955        FROM rcv_supply ms
956           , rcv_transactions rt
957           , rcv_shipment_headers rsh
958           , rcv_shipment_lines rsl
959           , mtl_parameters mp
960       WHERE rsh.shipment_header_id = ms.shipment_header_id
961         AND rsh.shipment_header_id = rt.shipment_header_id
962         AND ms.to_organization_id = p_organization_id
963         and mp.organization_id = ms.to_organization_id
964         and rsl.to_organization_id = ms.to_organization_id
965         and rsl.shipment_header_id = rsh.shipment_header_id
966         and (mp.wms_enabled_flag = 'N'
967              OR (mp.wms_enabled_flag = 'Y' AND (rsl.item_id is NULL
968             OR exists (SELECT 1
969                  FROM mtl_system_items_kfv msik
970                  WHERE msik.inventory_item_id = rsl.item_id
971                  AND msik.organization_id = p_organization_id
972                  AND msik.mtl_transactions_enabled_flag = 'N')
973                                                 OR exists
974                                                 (select '1' from po_headers_all poh
975                                                           , po_lines_all pol
976                                                           , po_line_types plt
977                                                         where rt.po_header_id is not null
978                                                         and rt.po_header_id = poh.po_header_id
979                                                         and poh.po_header_id = pol.po_header_id
980                                                         and pol.line_type_id = plt.line_type_id
981                                                         and rsl.item_id = pol.item_id
982                                                         AND plt.outside_operation_flag = 'Y'))))
983         AND rt.transaction_id = ms.supply_source_id
984   AND ms.quantity > 0
985         AND ms.supply_type_code = 'RECEIVING'
986         --and rt.SOURCE_DOCUMENT_CODE <> 'RMA'
987         AND rt.transaction_type IN ('ACCEPT','MATCH','RECEIVE',
988             'REJECT','RETURN TO RECEIVING','TRANSFER')
989         AND (exists
990        (SELECT 1
991           FROM rcv_transactions rt1
992          WHERE rt1.transaction_id = rt.transaction_id
993            AND rt1.inspection_status_code <> 'NOT INSPECTED'
994            AND rt1.routing_header_id = 2)
995        OR rt.routing_header_id <> 2
996        OR rt.routing_header_id IS NULL)
997         AND rsh.receipt_num LIKE (p_receipt_number)
998    ORDER BY Decode(rtrim(rsh.receipt_num,'0123456789'),null,null,rsh.receipt_num),
999    Decode(rtrim(rsh.receipt_num,'0123456789'),null,to_number(rsh.receipt_num),null);
1000                                                                         --<R12 MOAC>
1001 
1002 END GET_RECEIPT_NUMBER_LOV;
1003 
1004 -- This LOV is used in ORG Tranfer Transaction
1005 -- for Mobile Inventory.
1006 
1007 
1008 PROCEDURE GET_CARRIER(x_getcarrierLOV OUT NOCOPY t_genref,
1009           p_FromOrganization_Id IN NUMBER,
1010           p_ToOrganization_Id IN NUMBER,
1011           p_carrier IN VARCHAR2)
1012   IS
1013 BEGIN
1014    OPEN x_getcarrierLOV FOR
1015      select freight_code, description, distribution_account
1016      from
1017      org_enabled_freight_val_v
1018      where organization_id = (SELECT decode(FOB_POINT,1,TO_ORGANIZATION_ID,2, FROM_ORGANIZATION_ID) from mtl_interorg_parameters where TO_ORGANIZATION_ID = p_ToOrganization_Id and from_organization_id =p_FromOrganization_Id )
1019      AND freight_code LIKE (p_carrier)
1020      order by freight_code;
1021 END GET_CARRIER;
1022 
1023 --
1024 -- LOV for the possible quality codes for mobile inspection form
1025 --
1026 PROCEDURE GET_QUALITY_CODES_LOV(
1027  x_getQltyCodesLOV      OUT NOCOPY t_genref
1028 ,p_quality_code         IN  VARCHAR2)
1029 is
1030 begin
1031   open x_getQltyCodesLOV for
1032   select
1033           code
1034         , ranking
1035   , description
1036   from po_quality_codes
1037   where nvl(inactive_date,sysdate + 1) > sysdate
1038         and   code like (p_quality_code)
1039   order by ranking;
1040 end GET_QUALITY_CODES_LOV;
1041 
1042 --
1043 -- LOV for the possible reason codes for mobile inspection form
1044 --
1045 PROCEDURE GET_REASON_CODES_LOV(
1046  x_getReasonCodesLOV    OUT NOCOPY t_genref
1047 ,p_reason_code         IN  VARCHAR2)
1048 IS
1049 BEGIN
1050   OPEN   x_getReasonCodesLOV FOR
1051   SELECT reason_name ,description ,reason_id
1052   FROM   mtl_transaction_reasons
1053   WHERE  NVL(disable_date,SYSDATE + 1) > SYSDATE
1054   AND    reason_name LIKE (p_reason_code)
1055   ORDER BY upper(reason_name);
1056 
1057 END GET_REASON_CODES_LOV;
1058 
1059 --
1060 -- Procedure overloaded for Transaction Reason Security build.
1061 -- 4505091, nsrivast
1062 
1063 PROCEDURE GET_REASON_CODES_LOV(
1064            x_getReasonCodesLOV    OUT NOCOPY t_genref
1065           ,p_reason_code          IN  VARCHAR2
1066           ,p_txn_type_id          IN  VARCHAR2 )
1067 
1068 IS
1069 BEGIN
1070   OPEN   x_getReasonCodesLOV FOR
1071   SELECT reason_name ,description ,reason_id
1072   FROM   mtl_transaction_reasons
1073   WHERE  NVL(disable_date,SYSDATE + 1) > SYSDATE
1074   AND    reason_name LIKE (p_reason_code)
1075    -- nsrivast, invconv , transaction reason security
1076   AND   ( NVL  ( fnd_profile.value_wnps('INV_TRANS_REASON_SECURITY'), 'N') = 'N'
1077           OR
1078           reason_id IN (SELECT  reason_id FROM mtl_trans_reason_security mtrs
1079                               WHERE(( responsibility_id = fnd_global.resp_id OR NVL(responsibility_id, -1) = -1 )
1080                                         AND
1081                                     ( mtrs.transaction_type_id =  p_txn_type_id OR  NVL(mtrs.transaction_type_id, -1) = -1 )
1082                                     )-- where ends
1083                             )-- select ends
1084           ) -- and condn ends ,-- nsrivast, invconv
1085    ORDER BY upper(reason_name);
1086 
1087 END GET_REASON_CODES_LOV;
1088 
1089 
1090 
1091 
1092 -- LOV for the possible receipt numbers for inspection
1093 PROCEDURE GET_RECEIPT_NUMBER_INSPECT_LOV(
1094   x_getRcptNumLOV   OUT NOCOPY t_genref
1095 , p_organization_id   IN  NUMBER
1096 , p_receipt_number  IN  VARCHAR2)
1097 is
1098 begin
1099      OPEN x_getRcptNumLOV FOR
1100      /*Bug: 4951739
1101       Modified query: Referencing base table instead of
1102       RCV_TRANSACTIONS_V
1103       */
1104      SELECT  DISTINCT   rsh.receipt_num   ,
1105         null   ,
1106         rsup.shipment_header_id   ,
1107         null   ,
1108         null   ,
1109         null
1110         , null     -- bug # 6917248
1111         ,  rsup.from_organization_id -- bug # 6917248
1112      FROM    RCV_SUPPLY RSUP,
1113              RCV_TRANSACTIONS RT,
1114              RCV_SHIPMENT_HEADERS RSH,
1115              RCV_SHIPMENT_LINES RSL,
1116              PO_LOOKUP_CODES PLC,
1117              PO_LINE_LOCATIONS_ALL PLL,
1118              mtl_parameters mp --BUG 5166887
1119      WHERE         RSUP.SUPPLY_TYPE_CODE              =  'RECEIVING'
1120             AND    RT.TRANSACTION_TYPE                   <>  'UNORDERED'
1121             AND    RT.TRANSACTION_TYPE                    =  PLC.LOOKUP_CODE
1122             AND    PLC.LOOKUP_TYPE                        =  'RCV TRANSACTION TYPE'
1123             AND    RT.TRANSACTION_ID                      =  RSUP.RCV_TRANSACTION_ID
1124             AND    RSH.SHIPMENT_HEADER_ID                 =  RSUP.SHIPMENT_HEADER_ID
1125             AND    PLL.LINE_LOCATION_ID(+)                =  RSUP.PO_LINE_LOCATION_ID
1126             AND    NVL(PLL.MATCHING_BASIS(+),'QUANTITY') <>  'AMOUNT'
1127             AND    PLL.PAYMENT_TYPE IS NULL
1128             AND    RSUP.to_organization_id          =  p_organization_id
1129             AND    RT.inspection_status_code        =  'NOT INSPECTED'
1130             AND    RT.routing_header_id             =  2  /* Inspection Routing */
1131             AND    RSH.receipt_num LIKE (p_receipt_number)
1132 
1133             -- BUG 5166887: Do not return any rows if user access WMS org through the
1134             -- MSCA menu option
1135             AND    rsl.shipment_header_id = rsh.shipment_header_id
1136             AND    rsl.to_organization_id = rsup.to_organization_id
1137             AND    mp.organization_id = rsup.to_organization_id
1138             AND    (mp.wms_enabled_flag = 'N'
1139                     OR (mp.wms_enabled_flag = 'Y'
1140                         AND (rsl.item_id is NULL
1141                              OR exists (SELECT 1
1142                                         FROM mtl_system_items_kfv msik
1143                                         WHERE msik.inventory_item_id = rsl.item_id
1144                                         AND msik.organization_id = p_organization_id
1145                                         AND msik.mtl_transactions_enabled_flag = 'N')
1146                              OR exists (select '1'
1147                                         from po_headers_all poh
1148                                            , po_lines_all pol
1149                                            , po_line_types plt
1150                                         where rt.po_header_id is not null
1151                                         and rt.po_header_id = poh.po_header_id
1152                                         and poh.po_header_id = pol.po_header_id
1153                                         and pol.line_type_id = plt.line_type_id
1154                                         and rsl.item_id = pol.item_id
1155                                         AND plt.outside_operation_flag = 'Y'))))
1156             -- END BUG 5166887
1157              ORDER BY   Decode(rtrim(RSH.receipt_num,'0123456789'),          null,null,          RSH.receipt_num),
1158              Decode(rtrim(RSH.receipt_num,'0123456789'),          null,to_number(RSH.receipt_num),          null);                                                                      --<R12 MOAC>
1159 end GET_RECEIPT_NUMBER_INSPECT_LOV;
1160 
1161 
1162 -- LOV for RMA
1163 PROCEDURE get_rma_lov
1164   (x_getRMALOV  OUT NOCOPY t_genref,
1165    p_organization_id  IN  NUMBER,
1166    p_rma_number IN VARCHAR,
1167    p_mobile_form IN VARCHAR2)
1168   IS
1169 BEGIN
1170 
1171    IF p_mobile_form = 'RCVTXN' THEN
1172       OPEN x_getrmalov FOR
1173 
1174   SELECT DISTINCT
1175   oeh.order_number ,
1176   oeh.header_id ,
1177   --  oet.name ,
1178   --  oet.ORDER_CATEGORY_CODE ,
1179         OTT_TL.NAME ORDER_TYPE, --OLT.NAME  ORDER_TYPE,
1180         OTT_ALL.ORDER_CATEGORY_CODE ORDER_TYPE_CODE, --OLT.ORDER_CATEGORY_CODE ORDER_TYPE_CODE,
1181   oec.customer_id,
1182   oec.name customer_name,
1183   oec.customer_number
1184   FROM rcv_transactions rt,
1185   rcv_supply ms,
1186   oe_order_headers_all oeh,
1187   oe_order_lines_all oel,
1188   --  oe_line_types_v oet,
1189   OE_TRANSACTION_TYPES_TL OTT_TL,
1190         OE_TRANSACTION_TYPES_ALL OTT_ALL,
1191   oe_sold_to_orgs_v oec
1192   WHERE oeh.header_id = rt.oe_order_header_id
1193   --  AND   oet.order_category_code = 'RETURN'
1194   AND   rt.source_document_code = 'RMA'
1195   AND   rt.oe_order_header_id = ms.oe_order_header_id
1196   AND   ms.quantity > 0
1197   AND   ms.supply_type_code = 'RECEIVING'
1198   AND   ms.to_organization_id = p_organization_id
1199   AND   ms.supply_source_id = rt.transaction_id
1200   AND   rt.organization_id = ms.to_organization_id
1201   AND   rt.transaction_type <> 'UNORDERED'
1202   AND   oeh.HEADER_ID = oel.HEADER_ID
1203   and   oeh.order_type_id = ott_all.transaction_type_id
1204         and   ott_all.order_category_code in ('MIXED', 'RETURN')
1205         and   ott_all.transaction_type_id = ott_tl.transaction_type_id
1206         and   ott_tl.language = userenv('LANG')
1207   --  AND   oel.line_type_id    =  oet.line_type_id
1208   AND   oeh.sold_to_org_id   =  oec.customer_id
1209         AND (exists
1210        (SELECT 1
1211           FROM rcv_transactions rt1
1212          WHERE rt1.transaction_id = rt.transaction_id
1213            AND rt1.inspection_status_code <> 'NOT INSPECTED'
1214            AND rt1.routing_header_id = 2)
1215        OR rt.routing_header_id <> 2
1216        OR rt.routing_header_id IS NULL)
1217         AND   oeh.order_number LIKE (p_rma_number)
1218   ORDER BY oeh.order_number;
1219 
1220     ELSIF  p_mobile_form = 'RECEIPT' THEN
1221 
1222       OPEN x_getrmalov FOR
1223   SELECT  DISTINCT
1224   OEH.ORDER_NUMBER OE_ORDER_NUM,
1225   OEL.HEADER_ID OE_ORDER_HEADER_ID,
1226   --  OLT.NAME  ORDER_TYPE,
1227   OTT_TL.NAME ORDER_TYPE,
1228   --  OLT.ORDER_CATEGORY_CODE ORDER_TYPE_CODE,
1229   OTT_ALL.ORDER_CATEGORY_CODE ORDER_TYPE_CODE,
1230   OESOLD.CUSTOMER_ID,
1231   --TCA Cleanup
1232   --OEC.customer_name,
1233   --OEC.customer_number
1234   PARTY.PARTY_NAME CUSTOMER_NAME,
1235   PARTY.PARTY_NUMBER CUSTOMER_NUMBER
1236   FROM
1237   OE_ORDER_LINES_all OEL,
1238   OE_ORDER_HEADERS_all OEH,
1239   OE_TRANSACTION_TYPES_TL OTT_TL,
1240         OE_TRANSACTION_TYPES_ALL OTT_ALL,
1241 
1242   --  OE_LINE_TYPES_V OLT,
1243   OE_SOLD_TO_ORGS_V OESOLD,
1244   WF_ITEM_ACTIVITY_STATUSES WF,
1245   WF_PROCESS_ACTIVITIES WPA,
1246   --RA_CUSTOMERS OEC /*TCA Cleanup */
1247   HZ_PARTIES PARTY,
1248   HZ_CUST_ACCOUNTS CUST_ACCT
1249   WHERE
1250   OEL.LINE_CATEGORY_CODE='RETURN'
1251   AND nvl(OEL.SHIP_FROM_ORG_ID, OEH.SHIP_FROM_ORG_ID) = p_organization_id
1252   AND OEL.HEADER_ID = OEH.HEADER_ID
1253   AND OEL.SOLD_TO_ORG_ID = OESOLD.ORGANIZATION_ID
1254   --AND OESOLD.CUSTOMER_ID = oec.customer_id  /*TCA Cleanup */
1255   --Bug5417779: oesold.customer_id should be joined with cust_acct.cust_account_id
1256   AND OESOLD.CUSTOMER_ID = CUST_ACCT.CUST_ACCOUNT_ID
1257   AND CUST_ACCT.PARTY_ID = PARTY.PARTY_ID
1258   and oeh.order_type_id = ott_all.transaction_type_id
1259         and ott_all.order_category_code in ('MIXED', 'RETURN')
1260         and ott_all.transaction_type_id = ott_tl.transaction_type_id
1261         and ott_tl.language = userenv('LANG')
1262 
1263   --  AND OEL.LINE_TYPE_ID = OLT.LINE_TYPE_ID
1264   AND OEH.BOOKED_FLAG='Y'
1265   AND OEH.OPEN_FLAG='Y'
1266   AND OEL.ORDERED_QUANTITY > NVL(OEL.SHIPPED_QUANTITY,0)
1267   AND WPA.ACTIVITY_ITEM_TYPE = 'OEOL'
1268   AND WPA.ACTIVITY_NAME = 'RMA_WAIT_FOR_RECEIVING'
1269   AND WF.ITEM_TYPE = 'OEOL'
1270   AND WF.PROCESS_ACTIVITY = WPA.INSTANCE_ID
1271   AND WF.ACTIVITY_STATUS = 'NOTIFIED'
1272   AND OEL.LINE_ID = TO_NUMBER(WF.ITEM_KEY)
1273   AND oeh.order_number LIKE (p_rma_number)
1274   ORDER BY oeh.order_number;
1275 
1276     ELSIF  p_mobile_form = 'INSPECT' THEN
1277 
1278       OPEN x_getrmalov FOR
1279   SELECT DISTINCT
1280   oeh.order_number ,
1281   oeh.header_id ,
1282   OTT_TL.NAME ORDER_TYPE, --OLT.NAME  ORDER_TYPE,
1283         OTT_ALL.ORDER_CATEGORY_CODE ORDER_TYPE_CODE,
1284   --  oet.name ,
1285   --  oet.ORDER_CATEGORY_CODE ,
1286   oec.customer_id,
1287   oec.name customer_name,
1288   oec.customer_number
1289   FROM rcv_transactions_v rtv,
1290   oe_order_headers_all    oeh,
1291   OE_TRANSACTION_TYPES_TL OTT_TL,
1292         OE_TRANSACTION_TYPES_ALL OTT_ALL,
1293   oe_order_lines_all      oel,
1294   --  oe_line_types_v         oet,
1295   oe_sold_to_orgs_v       oec
1296   WHERE oeh.header_id              = rtv.oe_order_header_id
1297         AND   rtv.receipt_source_code    = 'CUSTOMER'
1298         AND   rtv.to_organization_id     = p_organization_id
1299     AND   rtv.inspection_status_code = 'NOT INSPECTED'
1300         AND   rtv.routing_id             = 2 /* Inspection Routing */
1301   AND   oeh.HEADER_ID      = oel.HEADER_ID
1302   --  AND   oel.line_type_id           =  oet.line_type_id
1303   --  AND   oet.order_category_code    = 'RETURN'
1304   and   oeh.order_type_id = ott_all.transaction_type_id
1305         and   ott_all.order_category_code in ('MIXED', 'RETURN')
1306         and   ott_all.transaction_type_id = ott_tl.transaction_type_id
1307         and   ott_tl.language = userenv('LANG')
1308 
1309   AND   oeh.sold_to_org_id         =  oec.customer_id
1310         AND   oeh.order_number LIKE (p_rma_number);
1311 
1312    END IF;
1313 END get_rma_lov;
1314 
1315 --
1316 --
1317 -- Bug 2192815
1318 -- UOM Lov for Expense Items
1319 --
1320 --
1321 FUNCTION get_conversion_rate_expense(p_from_uom_code   varchar2,
1322                              p_organization_id NUMBER,
1323                              p_item_id         NUMBER,
1324                              p_primary_uom_code varchar2 )
1325   RETURN VARCHAR2 IS
1326      l_primary_uom_code VARCHAR2(3) := p_primary_uom_code;
1327      l_conversion_rate NUMBER;
1328      l_return_string VARCHAR2(50);
1329 BEGIN
1330       inv_convert.inv_um_conversion(p_from_uom_code,
1331                                     l_primary_uom_code,
1332                                     p_item_id,
1333                                     l_conversion_rate);
1334       IF l_conversion_rate IS NOT NULL AND l_conversion_rate > 0 THEN
1335          l_return_string :=
1336            p_from_uom_code||'('||To_char(TRUNC(l_conversion_rate,4))||' '||l_primary_uom_code||')';
1337          RETURN l_return_string;
1338       END IF;
1339       RETURN p_from_uom_code;
1340 END;
1341 
1342 PROCEDURE get_uom_lov_expense(x_uoms OUT NOCOPY t_genref,
1343                           p_organization_id IN NUMBER,
1344                           p_item_id IN NUMBER,
1345                           p_uom_type IN NUMBER,
1346                           p_uom_code IN VARCHAR2,
1347                           p_primary_uom_code IN VARCHAR2)
1348 IS
1349 p_primary_uom_class varchar2(10);
1350 l_code VARCHAR2(20):=p_UOM_Code;
1351 BEGIN
1352 
1353     IF (INSTR(l_code,'(') > 0) THEN
1354       l_code := SUBSTR(p_UOM_Code,1,INSTR(p_UOM_Code,'(')-1);
1355     END IF;
1356 
1357 
1358 -- Find the Class from Primary UOM
1359 Begin
1360 
1361 select uom_class
1362   into p_primary_uom_class
1363 from  mtl_units_of_measure muom
1364 where muom.uom_code = p_primary_uom_code;
1365 
1366 Exception
1367  When others then p_primary_uom_class := '';
1368 End;
1369 
1370 OPEN x_uoms FOR
1371 SELECT
1372       get_conversion_rate_expense(muom.uom_code,
1373                                    p_Organization_Id,
1374                                    0,
1375                                    p_primary_uom_code )
1376       uom_code
1377       , muc.unit_of_measure unit_of_measure
1378       , ''
1379       , muc.uom_class uom_class
1380 from
1381  mtl_uom_conversions_val_v muc ,
1382  mtl_units_of_measure muom
1383 where muc.uom_class = p_primary_uom_class
1384 and muc.item_id = 0
1385 and nvl(muc.disable_date,sysdate+1)>sysdate
1386 and muc.unit_of_measure = muom.unit_of_measure
1387 and nvl(muom.disable_date,sysdate+1) > sysdate
1388 and muom.uom_code like (l_code)
1389 order by muc.unit_of_measure;
1390 
1391 --FROM mtl_units_of_measure
1392 --WHERE base_uom_flag = 'Y'
1393 --AND uom_code LIKE (p_uom_code || '%')
1394 --ORDER BY Upper(uom_code);
1395 
1396 END get_uom_lov_expense;
1397 
1398 
1399 /* Direct Shipping */
1400 -- LOV for Location (used in Delivery Info Page )
1401 PROCEDURE get_directship_location_lov (
1402     x_location OUT NOCOPY t_genref
1403    ,    p_organization_id IN NUMBER
1404    ,    p_location_code IN VARCHAR2) IS
1405 BEGIN
1406 
1407    OPEN x_location FOR
1408        SELECT   address1
1409           ,   wsh_location_id
1410           ,   ui_location_code
1411        FROM wsh_locations
1412       WHERE (inactive_date IS NULL OR inactive_date > Sysdate)
1413         AND address1 LIKE (p_location_code)
1414       ORDER BY Upper (address1);
1415 
1416 END get_directship_location_lov;
1417 
1418 
1419 -- LOV for Location Code
1420 PROCEDURE get_locationcode_lov (
1421     x_locationcode OUT NOCOPY t_genref
1422    ,    p_location_code IN VARCHAR2) IS
1423 BEGIN
1424 
1425    OPEN x_locationcode FOR
1426       SELECT lookup_code, meaning, description
1427       FROM   ar_lookups
1428       WHERE  lookup_type = 'FOB'
1429       AND    nvl(start_date_active, sysdate)<=sysdate
1430       AND    nvl(end_date_active,sysdate)>=sysdate
1431       AND    enabled_flag = 'Y'
1432       AND    meaning like (p_location_code)
1433       ORDER BY Upper (lookup_code);
1434  --Bug 2961355:Changed the query to query from ar_lookups as fnd_lookup_values_vl had duplicate entries based on application id
1435  END get_locationcode_lov;
1436 
1437 /* Direct Shipping */
1438 
1439 --      Name: GET_DOC_LOV
1440 --
1441 --      Input parameters:
1442 --       p_Organization_Id   which restricts LOV SQL to current org
1443 --       p_doc_number   which restricts LOV SQL to the user input text
1444 --       p_manual_po_num_type  NUMERIC or ALPHANUMERIC
1445 --       p_mobile_form   which mobile form this LOV is for (RECEIPT or DELIVER)
1446 --                       SQL query will be different for these forms
1447 --
1448 --      Output parameters:
1449 --       x_doc_num_lov      returns LOV rows as reference cursor
1450 --
1451 --      Functions: This API returns PO number for a given org
1452 --
1453 
1454 PROCEDURE GET_DOC_LOV
1455           (
1456           x_doc_num_lov        OUT NOCOPY t_genref,
1457           p_organization_id    IN  NUMBER,
1458           p_doc_number         IN  VARCHAR2,
1459           p_mobile_form        IN  VARCHAR2,
1460           p_shipment_header_id IN  VARCHAR2,
1461           p_inventory_item_id  IN  VARCHAR2,
1462           p_item_description   IN  VARCHAR2,
1463           p_doc_type           IN  VARCHAR2,
1464           p_vendor_prod_num    IN  VARCHAR2
1465           )
1466    IS
1467 
1468 /* bug 4638235
1469    New local variables
1470 */
1471 
1472 l_doc_num_passed  BOOLEAN := FALSE ;
1473 l_doc_num_length  NUMBER  := NVL(LENGTH(p_doc_number),0) ;
1474 l_instr_pos       NUMBER  := INSTR(p_doc_number , '%' , 1 , 1) ;
1475 l_append varchar2(2):='';
1476 
1477 BEGIN
1478 
1479 /*
1480 As part of the fix for the Performance Bug 3908402 the following changes have
1481 been done with the help of Apps Performance Team.
1482 1. The single query has been split into multiple queries based on the Doc Type
1483    and the original query has been placed at last if the Doc Type is ALL.
1484 2. Removed the following  condition " AND nvl(p_doc_type,'ALL') in ('PO', 'ALL') "
1485    because this check has been already incorporated through if/else.
1486 3. For the Doc Type of PO and ASN, query has been split further based on the
1487    value passed for p_inventory_item_id and p_item_description parameters.
1488 
1489 The following changes have been done while selecting Purchase Orders.
1490 i.e. doc type of PO.
1491    a. In the condition, "AND NVL(poll.approved_flag,'N') = 'Y' " ,
1492       nvl() has been removed.
1493    b. Removed the tables mtl_system_items_kfv and mtl_units_of_measure which are
1494       joined with po_lines_all table through outer join.
1495    c. Added the hint " +index(POH PO_HEADERS_U2) " to use the  index PO_HEADERS_U2.
1496    d. Removed the Distinct clause from the select statement.
1497 */
1498 
1499 -- Fix for the performance Bug 4638235
1500 -- We are determining whether the Doc Number has been passed with some value
1501 -- other than % and the % shouldn't be at the beginning.
1502 -- For Eg. P101% or % or %P101% or %P1%01% or P1%01
1503 -- Based on the variable l_doc_num_passed and parameter p_inventory_item_id
1504 -- the queries have been formed.
1505 IF (WMS_DEPLOY.wms_deployment_mode='L') THEN --LSP
1506    l_append:='%';
1507 END IF;
1508 IF p_doc_number IS NOT NULL  THEN
1509    IF  l_doc_num_length > 1
1510        AND
1511        (
1512             l_instr_pos = l_doc_num_length
1513          OR (l_instr_pos = 0 OR l_instr_pos > 1)
1514        )
1515        THEN
1516       l_doc_num_passed := TRUE ;
1517    END IF;
1518 ELSE
1519  l_doc_num_passed := FALSE ;
1520 END IF;
1521 -- End of fix
1522 
1523     IF p_mobile_form = 'RECEIPT' THEN
1524        IF  NVL(p_doc_type,'ALL') = 'PO' THEN
1525 	  IF l_doc_num_passed AND p_inventory_item_id IS NOT NULL THEN
1526 	   --bug 4638235  added checking for l_doc_number passed
1527            -- This select takes care of Vendor Item and any non-expense item
1528            -- and cross ref item case.
1529            OPEN x_doc_num_lov FOR
1530             SELECT /*+index(POH PO_HEADERS_U2) */
1531                 -- DISTINCT
1532                 -- DOCTYPE PO
1533                 meaning FIELD0 ,
1534                 poh.segment1 FIELD1 ,
1535                 to_char(poh.po_header_id) FIELD2 ,
1536                 poh.type_lookup_code FIELD3 ,
1537                 wms_deploy.get_po_client_name(poh.po_header_id)   FIELD4,--LSP
1538                 MO_GLOBAL.get_ou_name(poh.org_id) FIELD5,  --<R12 MOAC>
1539                 PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID) FIELD6 ,
1540                 to_char(poh.vendor_id) FIELD7 ,
1541                 to_char(poh.vendor_site_id) FIELD8 ,
1542                 'Vendor' FIELD9 ,
1543                 poh.note_to_receiver FIELD10 ,
1544                 NULL FIELD11 ,
1545                 NULL FIELD12 ,
1546                 NULL FIELD13 ,
1547                 lookup_code FIELD14 ,
1548                 to_char(poh.org_id) FIELD15  --<R12 MOAC>
1549             FROM po_headers_trx_v poh, -- CLM project, bug 9403291
1550                 fnd_lookup_values_vl flv
1551             WHERE flv.lookup_code = 'PO'
1552                 AND flv.lookup_type = 'DOC_TYPE'
1553                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
1554                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
1555                 AND flv.enabled_flag = 'Y'
1556                 -- Bug 2859355 Added the Extra conditions for poh.
1557                 AND POH.TYPE_LOOKUP_CODE IN ('STANDARD','PLANNED', 'BLANKET','CONTRACT')
1558                 AND NVL(POH.CANCEL_FLAG, 'N') IN ('N', 'I')
1559                 AND NVL(POH.CLOSED_CODE, 'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3152693
1560                 AND poh.segment1 LIKE (p_doc_number||l_append)
1561                 AND EXISTS
1562                 (
1563                 SELECT
1564                     'Valid PO Shipments'
1565                 FROM po_lines_trx_v pl, -- CLM project, bug 9403291
1566                      po_line_locations_trx_v poll -- CLM project, bug 9403291
1567 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
1568                    , mtl_parameters mp,
1569                      rcv_parameters rp
1570 --  End for Bug 7440217
1571                 WHERE pl.item_id = p_inventory_item_id
1572                     AND pl.po_header_id = poh.po_header_id
1573                     AND Nvl(pl.vendor_product_num,' ') = Nvl(p_vendor_prod_num, Nvl(pl.vendor_product_num,' '))
1574                     AND poh.po_header_id = poll.po_header_id
1575                     AND pl.po_line_id = poll.po_line_id
1576                     AND poll.approved_flag = 'Y'
1577                     AND Nvl(poll.cancel_flag,'N') = 'N'
1578                     -- AND poll.closed_code = 'OPEN' -- Bug 2859335
1579                     AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
1580                     AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
1581                  AND poll.ship_to_organization_id = p_organization_id
1582                  AND poll.payment_type IS NULL  --R12 excludes all Complex Work POs (Bug4236155)
1583 --  For Bug 7440217 Checking if it is LCM enabled
1584                  AND mp.organization_id = p_organization_id
1585                  AND rp.organization_id = p_organization_id
1586                  AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
1587                           OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
1588                               OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
1589                      )
1590 --  End for Bug 7440217
1591                 )
1592             UNION
1593             -- This Select Handles Substitute Items
1594             SELECT /*+index(POH PO_HEADERS_U2) */
1595                 -- DISTINCT
1596                 -- DOCTYPE PO
1597                 meaning FIELD0 ,
1598                 poh.segment1 FIELD1 ,
1599                 to_char(poh.po_header_id) FIELD2 ,
1600                 poh.type_lookup_code FIELD3 ,
1601                 wms_deploy.get_po_client_name(poh.po_header_id)   FIELD4,--LSP
1602                 MO_GLOBAL.get_ou_name(poh.org_id) FIELD5,   --<R12 MOAC>
1603                 PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID) FIELD6 ,
1604                 to_char(poh.vendor_id) FIELD7 ,
1605                 to_char(poh.vendor_site_id) FIELD8 ,
1606                 'Vendor' FIELD9 ,
1607                 poh.note_to_receiver FIELD10 ,
1608                 NULL FIELD11 ,
1609                 NULL FIELD12 ,
1610                 NULL FIELD13 ,
1611                 lookup_code FIELD14 ,
1612                 to_char(poh.org_id) FIELD15  --<R12 MOAC>
1613             FROM po_headers_trx_v poh, -- CLM project, bug 9403291
1614                 fnd_lookup_values_vl flv
1615             WHERE flv.lookup_code = 'PO'
1616                 AND flv.lookup_type = 'DOC_TYPE'
1617                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
1618                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
1619                 AND flv.enabled_flag = 'Y'
1620                 -- Bug 2859355 Added the Extra conditions for poh.
1621                 AND POH.TYPE_LOOKUP_CODE IN ('STANDARD','PLANNED', 'BLANKET','CONTRACT')
1622                 AND NVL(POH.CANCEL_FLAG, 'N') IN ('N', 'I')
1623                 AND NVL(POH.CLOSED_CODE, 'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3152693
1624                 AND poh.segment1 LIKE (p_doc_number||l_append)
1625                 AND EXISTS
1626                 (
1627                 SELECT
1628                     'Valid PO Shipments'
1629                 FROM po_lines_trx_v pl , -- CLM project, bug 9403291
1630                     mtl_related_items mri ,
1631                     mtl_system_items_kfv msi ,
1632                     po_line_locations_trx_v poll -- CLM project, bug 9403291
1633 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
1634                   , mtl_parameters mp,
1635                     rcv_parameters rp
1636 --  End for Bug 7440217
1637                 WHERE msi.organization_id = p_organization_id
1638                     AND pl.po_header_id = poh.po_header_id
1639                     AND
1640                     (
1641                         (
1642                             mri.related_item_id = msi.inventory_item_id
1643                             AND pl.item_id = mri.inventory_item_id
1644                             AND msi.inventory_item_id LIKE p_inventory_item_id
1645                         )
1646                         OR
1647                         (
1648                             mri.inventory_item_id = msi.inventory_item_id
1649                             AND pl.item_id = mri.related_item_id
1650                             AND mri.reciprocal_flag = 'Y'
1651                             AND msi.inventory_item_id LIKE p_inventory_item_id
1652                         )
1653                     )
1654                     AND Nvl(pl.vendor_product_num,' ') = Nvl(p_vendor_prod_num,Nvl(pl.vendor_product_num,' '))
1655                     AND poh.po_header_id = poll.po_header_id
1656                     AND pl.po_line_id = poll.po_line_id
1657                     AND poll.approved_flag = 'Y'
1658                     AND Nvl(poll.cancel_flag,'N') = 'N'
1659                     -- AND poll.closed_code = 'OPEN' -- Bug 2859355
1660                     AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
1661                     AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
1662                    AND poll.ship_to_organization_id = p_organization_id
1663                    AND poll.payment_type IS NULL  --R12 excludes all Complex Work POs (Bug4236155)
1664 --  For Bug 7440217 Checking if it is LCM enabled
1665                    AND mp.organization_id = p_organization_id
1666                    AND rp.organization_id = p_organization_id
1667                    AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
1668                            OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
1669                               OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
1670                        )
1671 --  End for Bug 7440217
1672                 )
1673             ORDER BY 1,2 ;
1674 
1675           ELSIF NOT l_doc_num_passed AND p_inventory_item_id IS NOT NULL THEN
1676            -- This select takes care of Vendor Item and any non-expense item
1677            -- and cross ref item case.
1678 
1679            -- Added the Hint /*+LEADING(PL)*/ as part of Fix for Bug 4638235
1680            -- incase Item ID is given and Doc No is not given.
1681            -- Query needs to be driven from PO_LINES_ALL table. Here subquery
1682            -- has been made as join.
1683            OPEN x_doc_num_lov FOR
1684             SELECT /*+LEADING(PL)*/
1685                 -- DISTINCT
1686                 -- DOCTYPE PO
1687                 meaning FIELD0 ,
1688                 poh.segment1 FIELD1 ,
1689                 to_char(poh.po_header_id) FIELD2 ,
1690                 poh.type_lookup_code FIELD3 ,
1691                 wms_deploy.get_po_client_name(poh.po_header_id)  FIELD4 ,--LSP
1692                 MO_GLOBAL.get_ou_name(poh.org_id) FIELD5,  --<R12 MOAC>
1693 	        PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID) FIELD6 ,
1694                 to_char(poh.vendor_id) FIELD7 ,
1695                 to_char(poh.vendor_site_id) FIELD8 ,
1696                 'Vendor' FIELD9 ,
1697                 poh.note_to_receiver FIELD10 ,
1698 	        NULL FIELD11,
1699 	        NULL FIELD12,
1700                 NULL FIELD13,
1701 	        lookup_code FIELD14,
1702 	        to_char(poh.org_id) FIELD15  --<R12 MOAC>
1703             FROM po_headers_trx_v poh, -- CLM project, bug 9403291
1704                 fnd_lookup_values_vl flv ,
1705                 po_lines_trx_v pl, -- CLM project, bug 9403291
1706                 po_line_locations_trx_v poll -- CLM project, bug 9403291
1707 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
1708               , mtl_parameters mp,
1709                 rcv_parameters rp
1710 --  End for Bug 7440217
1711             WHERE flv.lookup_code = 'PO'
1712                 AND flv.lookup_type = 'DOC_TYPE'
1713                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
1714                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
1715                 AND flv.enabled_flag = 'Y'
1716                 -- Bug 2859355 Added the Extra conditions for poh.
1717                 AND POH.TYPE_LOOKUP_CODE IN ('STANDARD','PLANNED', 'BLANKET','CONTRACT')
1718                 AND NVL(POH.CANCEL_FLAG, 'N') IN ('N', 'I')
1719                 AND NVL(POH.CLOSED_CODE, 'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3152693
1720                 AND poh.segment1 LIKE (p_doc_number||l_append)
1721                 AND pl.item_id = p_inventory_item_id
1722                 AND pl.po_header_id = poh.po_header_id
1723                 AND Nvl(pl.vendor_product_num,' ') = Nvl(p_vendor_prod_num, Nvl(pl.vendor_product_num,' '))
1724                 AND poh.po_header_id = poll.po_header_id
1725                 AND pl.po_line_id = poll.po_line_id
1726                 AND poll.approved_flag = 'Y'
1727                 AND Nvl(poll.cancel_flag,'N') = 'N'
1728              -- AND poll.closed_code = 'OPEN' -- Bug 2859335
1729                 AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
1730                 AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
1731                 AND poll.ship_to_organization_id = p_organization_id
1732                 AND poll.payment_type IS NULL  --R12 excludes all Complex Work POs (Bug4236155)
1733 --  For Bug 7440217 Checking if it is LCM enabled
1734                 AND mp.organization_id = p_organization_id
1735                 AND rp.organization_id = p_organization_id
1736                 AND (    (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
1737                           OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
1738                               OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
1739                     )
1740 --  End for Bug 7440217
1741             UNION
1742                 -- This Select Handles Substitute Items
1743             SELECT /*+LEADING(MRI)*/				-- Bug 6600650
1744                 -- DISTINCT
1745                 -- DOCTYPE PO
1746                 meaning FIELD0 ,
1747                 poh.segment1 FIELD1 ,
1748                 to_char(poh.po_header_id) FIELD2 ,
1749                 poh.type_lookup_code FIELD3 ,
1750                 wms_deploy.get_po_client_name(poh.po_header_id)   FIELD4,--LSP
1751 		MO_GLOBAL.get_ou_name(poh.org_id) FIELD5,   --<R12 MOAC>
1752                 PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID) FIELD6 ,
1753                 to_char(poh.vendor_id) FIELD7 ,
1754                 to_char(poh.vendor_site_id) FIELD8 ,
1755                 'Vendor' FIELD9 ,
1756                 poh.note_to_receiver FIELD10 ,
1757                 NULL FIELD11 ,
1758                 NULL FIELD12 ,
1759                 NULL FIELD13 ,
1760 	        lookup_code FIELD14,
1761 		to_char(poh.org_id) FIELD15  --<R12 MOAC>
1762             FROM po_headers_trx_v poh, -- CLM project, bug 9403291
1763                 fnd_lookup_values_vl flv ,
1764                 po_lines_trx_v pl ,   -- CLM project, bug 9403291
1765                 mtl_related_items mri ,
1766                 mtl_system_items_kfv msi ,
1767                 po_line_locations_trx_v poll  -- CLM project, bug 9403291
1768 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
1769              ,  mtl_parameters mp,
1770                 rcv_parameters rp
1771 --  End for Bug 7440217
1772             WHERE flv.lookup_code = 'PO'
1773                 AND flv.lookup_type = 'DOC_TYPE'
1774                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
1775                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
1776                 AND flv.enabled_flag = 'Y'
1777                 -- Bug 2859355 Added the Extra conditions for poh.
1778                 AND POH.TYPE_LOOKUP_CODE IN ('STANDARD','PLANNED', 'BLANKET','CONTRACT')
1779                 AND NVL(POH.CANCEL_FLAG, 'N') IN ('N', 'I')
1780                 AND NVL(POH.CLOSED_CODE, 'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3152693
1781                 AND poh.segment1 LIKE (p_doc_number||l_append)
1782                 AND msi.organization_id = p_organization_id
1783                 AND pl.po_header_id = poh.po_header_id
1784                 AND mri.related_item_id = msi.inventory_item_id
1785                 AND pl.item_id = mri.inventory_item_id
1786                 AND msi.inventory_item_id = TO_NUMBER(p_inventory_item_id)
1787                 AND Nvl(pl.vendor_product_num,' ') = Nvl(p_vendor_prod_num,Nvl(pl.vendor_product_num,' '))
1788                 AND poh.po_header_id = poll.po_header_id
1789                 AND pl.po_line_id = poll.po_line_id
1790                 AND poll.approved_flag = 'Y'
1791                 AND Nvl(poll.cancel_flag,'N') = 'N'
1792              -- AND poll.closed_code = 'OPEN' -- Bug 2859355
1793                 AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
1794                 AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
1795                 AND poll.ship_to_organization_id = p_organization_id
1796                 AND poll.payment_type IS NULL  --R12 excludes all Complex Work POs (Bug4236155)
1797 --  For Bug 7440217 Checking if it is LCM enabled
1798                 AND mp.organization_id = p_organization_id
1799                 AND rp.organization_id = p_organization_id
1800                 AND (    (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
1801                           OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
1802                               OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
1803                     )
1804 --  End for Bug 7440217
1805            UNION
1806             SELECT /*+LEADING(MRI)*/				-- Bug 6600650
1807                 -- DISTINCT
1808                 -- DOCTYPE PO
1809                 meaning FIELD0 ,
1810                 poh.segment1 FIELD1 ,
1811                 to_char(poh.po_header_id) FIELD2 ,
1812 		poh.type_lookup_code FIELD3 ,
1813       wms_deploy.get_po_client_name(poh.po_header_id)  FIELD4 ,--LSP
1814 		MO_GLOBAL.get_ou_name(poh.org_id) FIELD5,   --<R12 MOAC>
1815                 PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID) FIELD6 ,
1816                 to_char(poh.vendor_id) FIELD7 ,
1817                 to_char(poh.vendor_site_id) FIELD8 ,
1818                 'Vendor' FIELD9 ,
1819                 poh.note_to_receiver FIELD10 ,
1820                 NULL FIELD11 ,
1821                 NULL FIELD12 ,
1822                 NULL FIELD13 ,
1823 		lookup_code FIELD14,
1824 	        to_char(poh.org_id) FIELD15  --<R12 MOAC>
1825             FROM po_headers_trx_v poh, -- CLM project, bug 9403291
1826                 fnd_lookup_values_vl flv ,
1827                 po_lines_trx_v pl ,    -- CLM project, bug 9403291
1828                 mtl_related_items mri ,
1829                 mtl_system_items_kfv msi ,
1830                 po_line_locations_trx_v poll -- CLM project, bug 9403291
1831 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
1832               , mtl_parameters mp,
1833                 rcv_parameters rp
1834 --  End for Bug 7440217
1835             WHERE flv.lookup_code = 'PO'
1836                 AND flv.lookup_type = 'DOC_TYPE'
1837                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
1838                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
1839                 AND flv.enabled_flag = 'Y'
1840                 -- Bug 2859355 Added the Extra conditions for poh.
1841                 AND POH.TYPE_LOOKUP_CODE IN ('STANDARD','PLANNED', 'BLANKET','CONTRACT')
1842                 AND NVL(POH.CANCEL_FLAG, 'N') IN ('N', 'I')
1843                 AND NVL(POH.CLOSED_CODE, 'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3152693
1844                 AND poh.segment1 LIKE (p_doc_number||l_append)
1845                 AND msi.organization_id = p_organization_id
1846                 AND pl.po_header_id = poh.po_header_id
1847                 AND mri.inventory_item_id = msi.inventory_item_id
1848                 AND pl.item_id = mri.related_item_id
1849                 AND mri.reciprocal_flag = 'Y'
1850                 AND msi.inventory_item_id = TO_NUMBER(p_inventory_item_id)
1851                 AND Nvl(pl.vendor_product_num,' ') = Nvl(p_vendor_prod_num,Nvl(pl.vendor_product_num,' '))
1852                 AND poh.po_header_id = poll.po_header_id
1853                 AND pl.po_line_id = poll.po_line_id
1854                 AND poll.approved_flag = 'Y'
1855                 AND Nvl(poll.cancel_flag,'N') = 'N'
1856              -- AND poll.closed_code = 'OPEN' -- Bug 2859355
1857                 AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
1858                 AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
1859                 AND poll.ship_to_organization_id = p_organization_id
1860                 AND poll.payment_type IS NULL  --R12 excludes all Complex Work POs (Bug4236155)
1861 --  For Bug 7440217 Checking if it is LCM enabled
1862                 AND mp.organization_id = p_organization_id
1863                 AND rp.organization_id = p_organization_id
1864                 AND (    (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
1865                           OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
1866                               OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
1867                      )
1868 --  End for Bug 7440217
1869             ORDER BY 1,2 ;
1870 
1871          ELSIF p_item_description IS NOT NULL THEN
1872             OPEN x_doc_num_lov FOR
1873             -- This Select Handles Expense Items
1874               SELECT /*+index(POH PO_HEADERS_U2) */
1875                   -- DISTINCT
1876                   -- DOCTYPE PO
1877                   meaning FIELD0 ,
1878                   poh.segment1 FIELD1 ,
1879                   to_char(poh.po_header_id) FIELD2 ,
1880                   poh.type_lookup_code FIELD3 ,
1881                   wms_deploy.get_po_client_name(poh.po_header_id)  FIELD4 ,--LSP
1882                   MO_GLOBAL.get_ou_name(poh.org_id) FIELD5 ,  --<R12 MOAC>
1883                   PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID) FIELD6 ,
1884                   to_char(poh.vendor_id) FIELD7 ,
1885                   to_char(poh.vendor_site_id) FIELD8 ,
1886                   'Vendor' FIELD9 ,
1887                   poh.note_to_receiver FIELD10 ,
1888                   NULL FIELD11 ,
1889                   NULL FIELD12 ,
1890                   NULL FIELD13 ,
1891                   lookup_code FIELD14 ,
1892                   to_char(poh.org_id) FIELD15    --<R12 MOAC>
1893               FROM po_headers_trx_v poh, -- CLM project, bug 9403291
1894                   fnd_lookup_values_vl flv
1895               WHERE flv.lookup_code = 'PO'
1896                   AND flv.lookup_type = 'DOC_TYPE'
1897                   AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
1898                   AND nvl(flv.end_date_active,sysdate) >= SYSDATE
1899                   AND flv.enabled_flag = 'Y'
1900                   -- Bug 2859355 Added the Extra conditions for poh.
1901                   AND POH.TYPE_LOOKUP_CODE IN ('STANDARD','PLANNED', 'BLANKET','CONTRACT')
1902                   AND NVL(POH.CANCEL_FLAG, 'N') IN ('N', 'I')
1903                   AND NVL(POH.CLOSED_CODE, 'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3152693
1904                   AND poh.segment1 LIKE (p_doc_number||l_append)
1905                   AND EXISTS
1906                   (
1907                   SELECT
1908                       'Valid PO Shipments'
1909                   FROM po_lines_trx_v pl , -- CLM project, bug 9403291
1910                        po_line_locations_trx_v poll  -- CLM project, bug 9403291
1911 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
1912                      , mtl_parameters mp,
1913                        rcv_parameters rp
1914 --  End for Bug 7440217
1915                   WHERE pl.ITEM_ID IS NULL
1916                       AND pl.item_description LIKE p_item_description||'%'
1917                       AND pl.po_header_id = poh.po_header_id
1918                       AND Nvl(pl.vendor_product_num,' ') = Nvl(p_vendor_prod_num,Nvl(pl.vendor_product_num,' '))
1919                       AND poh.po_header_id = poll.po_header_id
1920                       AND pl.po_line_id = poll.po_line_id
1921                       AND poll.approved_flag = 'Y'
1922                       AND Nvl(poll.cancel_flag,'N') = 'N'
1923                       -- AND poll.closed_code = 'OPEN' --Bug 2859355
1924                       AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
1925                       AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
1926                       AND poll.ship_to_organization_id = p_organization_id
1927                       AND poll.payment_type IS NULL  --R12 excludes all Complex Work POs (Bug4236155)
1928 --  For Bug 7440217 Checking if it is LCM enabled
1929                       AND mp.organization_id = p_organization_id
1930                       AND rp.organization_id = p_organization_id
1931                       AND (    (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
1932                                 OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
1933                                     OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
1934                           )
1935 --  End for Bug 7440217
1936                   )
1937              ORDER BY 1,2 ;
1938          ELSE
1939            --Both Inventory Item Id and Item Desc are Null
1940            --And also Both Item Id and Item Desc won't be passed together.
1941             OPEN x_doc_num_lov FOR
1942               SELECT /*+index(POH PO_HEADERS_U2) */
1943                   -- DISTINCT
1944                   -- DOCTYPE PO
1945                   meaning FIELD0 ,
1946                   poh.segment1 FIELD1 ,
1947                   to_char(poh.po_header_id) FIELD2 ,
1948                   poh.type_lookup_code FIELD3 ,
1949                   wms_deploy.get_po_client_name(poh.po_header_id)  FIELD4 ,--LSP
1950                   MO_GLOBAL.get_ou_name(poh.org_id) FIELD5 ,   --<R12 MOAC>
1951                   PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID) FIELD6 ,
1952                   to_char(poh.vendor_id) FIELD7 ,
1953                   to_char(poh.vendor_site_id) FIELD8 ,
1954                   'Vendor' FIELD9 ,
1955                   poh.note_to_receiver FIELD10 ,
1956                   NULL FIELD11 ,
1957                   NULL FIELD12 ,
1958                   NULL FIELD13 ,
1959                   lookup_code FIELD14 ,
1960                   to_char(poh.org_id) FIELD15    --<R12 MOAC>
1961               FROM po_headers_trx_v poh,  -- CLM project, bug 9403291
1962                   fnd_lookup_values_vl flv
1963               WHERE flv.lookup_code = 'PO'
1964                   AND flv.lookup_type = 'DOC_TYPE'
1965                   AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
1966                   AND nvl(flv.end_date_active,sysdate) >= SYSDATE
1967                   AND flv.enabled_flag = 'Y'
1968                   -- Bug 2859355 Added the Extra conditions for poh.
1969                   AND POH.TYPE_LOOKUP_CODE IN ('STANDARD','PLANNED', 'BLANKET','CONTRACT')
1970                   AND NVL(POH.CANCEL_FLAG, 'N') IN ('N', 'I')
1971                   AND NVL(POH.CLOSED_CODE, 'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3152693
1972                   AND poh.segment1 LIKE (p_doc_number||l_append)
1973                   AND EXISTS
1974                   (
1975                   SELECT
1976                       'Valid PO Shipments'
1977                   FROM po_line_locations_trx_v poll  -- CLM project, bug 9403291
1978 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
1979                      , mtl_parameters mp,
1980                        rcv_parameters rp
1981 --  End for Bug 7440217
1982                   WHERE poh.po_header_id = poll.po_header_id
1983                       AND poll.approved_flag = 'Y'
1984                       AND Nvl(poll.cancel_flag,'N') = 'N'
1985                       -- AND poll.closed_code = 'OPEN' --Bug 2859355
1986                       AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
1987                       AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
1988                       AND poll.ship_to_organization_id = p_organization_id
1989                       AND poll.payment_type IS NULL  --R12 excludes all Complex Work POs (Bug4236155)
1990 --  For Bug 7440217 Checking if it is LCM enabled
1991                       AND mp.organization_id = p_organization_id
1992                       AND rp.organization_id = p_organization_id
1993                       AND (    (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
1994                                 OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
1995                                     OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
1996                           )
1997 --  End for Bug 7440217
1998                   )
1999              ORDER BY 1,2 ;
2000          END IF;  --Check for Item Id or Desc value
2001        ELSIF NVL(p_doc_type,'ALL') = 'RMA' THEN
2002           OPEN x_doc_num_lov FOR
2003             -- This Select Handles RMAs
2004             SELECT DISTINCT
2005                 -- DOCTYPE RMA
2006                 meaning FIELD0,
2007                 to_char(OEH.ORDER_NUMBER) FIELD1,
2008                 to_char(OEL.HEADER_ID) FIELD2,
2009                 OTT_TL.NAME FIELD3, --OLT.NAME                FIELD3,--bug3173013
2010                 NULL FIELD4, --LSP
2011                 NULL FIELD5,
2012                 OTT_ALL.ORDER_CATEGORY_CODE FIELD6, --OLT.ORDER_CATEGORY_CODE FIELD5,
2013                 to_char(OESOLD.CUSTOMER_ID) FIELD7,
2014                 /*TCA Cleanup */
2015                 --OEC.customer_name FIELD6,
2016                 --OEC.customer_number FIELD7,
2017                 PARTY.party_name FIELD8,
2018                 PARTY.party_number FIELD9,
2019                 NULL FIELD10,
2020                 NULL FIELD11,
2021                 NULL FIELD12,
2022                 NULL FIELD13,
2023                 lookup_code FIELD14 ,
2024                 to_char(oel.org_id) FIELD15
2025             FROM fnd_lookup_values_vl flv,
2026                 OE_ORDER_LINES_all OEL,
2027                 OE_ORDER_HEADERS_all OEH,
2028                 --OE_LINE_TYPES_V OLT,    --bug3173013
2029                 OE_TRANSACTION_TYPES_TL OTT_TL,
2030                 OE_TRANSACTION_TYPES_ALL OTT_ALL,
2031                 OE_SOLD_TO_ORGS_V OESOLD,
2032                 --WF_ITEM_ACTIVITY_STATUSES WF,
2033                 --WF_PROCESS_ACTIVITIES WPA,
2034                 --RA_CUSTOMERS OEC
2035                 HZ_PARTIES PARTY,
2036                 HZ_CUST_ACCOUNTS CUST_ACCT
2037             WHERE flv.lookup_code = 'RMA'
2038                 AND flv.lookup_type = 'DOC_TYPE'
2039                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2040                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2041                 AND flv.enabled_flag = 'Y'
2042                 AND OEL.LINE_CATEGORY_CODE='RETURN'
2043                 AND nvl(OEL.SHIP_FROM_ORG_ID, OEH.SHIP_FROM_ORG_ID) = p_organization_id
2044                 AND OEL.HEADER_ID = OEH.HEADER_ID
2045                 AND OEL.SOLD_TO_ORG_ID = OESOLD.ORGANIZATION_ID
2046                 --AND OESOLD.CUSTOMER_ID = oec.customer_id /*TCA Cleanup */
2047 		--Bug5417779: oesold.customer_id should be joined with cust_acct.cust_account_id
2048 		AND OESOLD.CUSTOMER_ID = CUST_ACCT.CUST_ACCOUNT_ID
2049                 AND CUST_ACCT.party_id = PARTY.party_id
2050                 --AND OEL.LINE_TYPE_ID = OLT.LINE_TYPE_ID--bug3173013
2051                 AND OEH.ORDER_TYPE_ID = OTT_ALL.TRANSACTION_TYPE_ID
2052                 AND OTT_ALL.ORDER_CATEGORY_CODE in ('MIXED', 'RETURN')
2053                 AND OTT_ALL.TRANSACTION_TYPE_ID = OTT_TL.TRANSACTION_TYPE_ID
2054                 AND OTT_TL.LANGUAGE = USERENV('LANG')
2055                 AND OEH.BOOKED_FLAG='Y'
2056                 AND OEH.OPEN_FLAG='Y'
2057                 AND OEL.ORDERED_QUANTITY > NVL(OEL.SHIPPED_QUANTITY,0)
2058                 AND OEL.FLOW_STATUS_CODE = 'AWAITING_RETURN'
2059                 --
2060                 -- The following lines are commented for Performance Improvement
2061                 -- instead flow_status_code is used from oel
2062                 --AND WPA.ACTIVITY_ITEM_TYPE = 'OEOL'
2063                 --AND WPA.ACTIVITY_NAME = 'RMA_WAIT_FOR_RECEIVING'
2064                 --AND WF.ITEM_TYPE = 'OEOL'
2065                 --AND WF.PROCESS_ACTIVITY = WPA.INSTANCE_ID
2066                 --AND WF.ACTIVITY_STATUS = 'NOTIFIED'
2067                 --AND OEL.LINE_ID = TO_NUMBER(WF.ITEM_KEY)
2068                 --
2069                 AND oeh.order_number LIKE (p_doc_number)
2070                 AND OEL.inventory_item_id LIKE Nvl(p_inventory_item_id,'%')
2071             ORDER BY 1,2 ;
2072        ELSIF NVL(p_doc_type,'ALL') = 'INTSHIP' THEN
2073           OPEN x_doc_num_lov FOR
2074             -- This Select Handles Internal Sales Order , Org Transfer
2075             SELECT DISTINCT
2076                 -- DOCTYPE INTSHIP
2077                 meaning FIELD0,
2078                 sh.shipment_num FIELD1,
2079                 to_char(sh.shipment_header_id) FIELD2,
2080                 to_char(sh.shipped_date) FIELD3,
2081                 NULL FIELD4, --LSP
2082                 NULL FIELD5 ,   --<R12 MOAC>
2083                 to_char(sh.expected_receipt_date) FIELD6,
2084                 to_char(Decode(sh.receipt_source_code, 'VENDOR',sh.vendor_id, sl.from_organization_id)) FIELD7,
2085                 Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id, sl.from_organization_id),1,80) FIELD8,
2086                 Decode(sh.receipt_source_code,'VENDOR','Vendor',sh.receipt_source_code) FIELD9, --bug fix 3939003
2087                 sh.packing_slip FIELD10,
2088                 sh.bill_of_lading FIELD11,
2089                 sh.waybill_airbill_num FIELD12,
2090                 sh.freight_carrier_code FIELD13,
2091                 lookup_code FIELD14,
2092                 NULL FIELD15    --<R12 MOAC>
2093             FROM fnd_lookup_values_vl flv,
2094                 rcv_shipment_headers sh,
2095                 rcv_shipment_lines sl
2096             WHERE flv.lookup_code = 'INTSHIP'
2097                 AND flv.lookup_type = 'DOC_TYPE'
2098                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2099                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2100                 AND flv.enabled_flag = 'Y'
2101                 AND sh.shipment_num IS NOT NULL
2102                 AND sh.shipment_header_id = sl.shipment_header_id
2103                 AND sl.to_organization_id = p_organization_id
2104                 AND sh.receipt_source_code IN ('INTERNAL ORDER','INVENTORY')
2105                 AND EXISTS
2106                 (
2107                 SELECT
2108                     'available supply'
2109                 FROM mtl_supply ms
2110                 WHERE ms.to_organization_id = p_organization_id
2111                     AND ms.shipment_header_id = sh.shipment_header_id
2112                 )
2113                 -- This was fix for bug 2740648/2752094
2114                 AND sl.shipment_line_status_code IN ('EXPECTED','PARTIALLY RECEIVED')
2115                 AND sh.shipment_num LIKE (p_doc_number)
2116                 AND sl.item_id LIKE Nvl(p_inventory_item_id,'%')
2117                 AND p_item_description IS NULL
2118             ORDER BY 1,2 ;
2119        ELSIF NVL(p_doc_type,'ALL') = 'ASN' THEN
2120          IF p_inventory_item_id IS NOT NULL THEN
2121             OPEN x_doc_num_lov FOR
2122               -- This Select Handles ASN
2123               SELECT DISTINCT
2124                   -- DOCTYPE ASN
2125                   meaning FIELD0,
2126                   sh.shipment_num FIELD1,
2127                   to_char(sh.shipment_header_id) FIELD2,
2128                   to_char(sh.shipped_date) FIELD3,
2129                   NULL FIELD4, --LSP
2130                   NULL FIELD5 ,   --<R12 MOAC>
2131                   to_char(sh.expected_receipt_date) FIELD6,
2132                   to_char(Decode(sh.receipt_source_code, 'VENDOR',sh.vendor_id, sl.from_organization_id)) FIELD7,
2133                   Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id, sl.from_organization_id),1,80) FIELD8,
2134                   Decode(sh.receipt_source_code,'VENDOR','Vendor','Organization') FIELD9,
2135                   sh.packing_slip FIELD10,
2136                   sh.bill_of_lading FIELD11,
2137                   sh.waybill_airbill_num FIELD12,
2138                   sh.freight_carrier_code FIELD13,
2139                   lookup_code FIELD14,
2140                   NULL FIELD15    --<R12 MOAC>
2141               FROM fnd_lookup_values_vl flv,
2142                   rcv_shipment_headers sh,
2143                   rcv_shipment_lines sl
2144               WHERE flv.lookup_code = 'ASN'
2145                   AND flv.lookup_type = 'DOC_TYPE'
2146                   AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2147                   AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2148                   AND flv.enabled_flag = 'Y'
2149                   AND sh.shipment_num IS NOT NULL
2150                   AND sh.shipment_header_id = sl.shipment_header_id
2151                   AND sl.to_organization_id = p_organization_id
2152                   AND sh.receipt_source_code = 'VENDOR'
2153                   AND sl.shipment_line_status_code <> 'CANCELLED'
2154                   AND sh.shipment_header_id = sl.shipment_header_id
2155                   AND sl.to_organization_id = p_organization_id
2156                   -- This was fix for bug 2740648/2752094
2157                   AND sh.asn_type in ('ASN','ASBN')
2158                   AND sl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED')
2159                   AND sh.shipment_num LIKE (p_doc_number)
2160                   -- This was fix for bug 2774080
2161                   AND sl.item_id = p_inventory_item_id
2162               ORDER BY 1,2 ;
2163          ELSIF p_item_description IS NOT NULL THEN
2164             OPEN x_doc_num_lov FOR
2165               -- This Select Handles ASN
2166               SELECT DISTINCT
2167                   -- DOCTYPE ASN
2168                   meaning FIELD0,
2169                   sh.shipment_num FIELD1,
2170                   to_char(sh.shipment_header_id) FIELD2,
2171                   to_char(sh.shipped_date) FIELD3,
2172                   NULL FIELD4, --LSP
2173                   NULL FIELD5 ,  --<R12 MOAC>
2174                   to_char(sh.expected_receipt_date) FIELD6,
2175                   to_char(Decode(sh.receipt_source_code, 'VENDOR',sh.vendor_id, sl.from_organization_id)) FIELD7,
2176                   Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id, sl.from_organization_id),1,80) FIELD8,
2177                   Decode(sh.receipt_source_code,'VENDOR','Vendor','Organization') FIELD9,
2178                   sh.packing_slip FIELD10,
2179                   sh.bill_of_lading FIELD11,
2180                   sh.waybill_airbill_num FIELD12,
2181                   sh.freight_carrier_code FIELD13,
2182                   lookup_code FIELD14,
2183                   NULL FIELD15    --<R12 MOAC>
2184               FROM fnd_lookup_values_vl flv,
2185                   rcv_shipment_headers sh,
2186                   rcv_shipment_lines sl
2187               WHERE flv.lookup_code = 'ASN'
2188                   AND flv.lookup_type = 'DOC_TYPE'
2189                   AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2190                   AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2191                   AND flv.enabled_flag = 'Y'
2192                   AND sh.shipment_num IS NOT NULL
2193                   AND sh.shipment_header_id = sl.shipment_header_id
2194                   AND sl.to_organization_id = p_organization_id
2195                   AND sh.receipt_source_code = 'VENDOR'
2196                   AND sl.shipment_line_status_code <> 'CANCELLED'
2197                   AND sh.shipment_header_id = sl.shipment_header_id
2198                   AND sl.to_organization_id = p_organization_id
2199                   -- This was fix for bug 2740648/2752094
2200                   AND sh.asn_type in ('ASN','ASBN')
2201                   AND sl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED')
2202                   AND sh.shipment_num LIKE (p_doc_number)
2203                   -- This was fix for bug 2774080
2204                   AND sl.item_description like p_item_description || '%'
2205               ORDER BY 1,2 ;
2206          ELSE
2207          --Both Inventory Item Id and Item Desc are Null
2208          --And also Both Item Id and Item Desc won't be passed together.
2209             OPEN x_doc_num_lov FOR
2210               SELECT DISTINCT
2211                   -- DOCTYPE ASN
2212                   meaning FIELD0,
2213                   sh.shipment_num FIELD1,
2214                   to_char(sh.shipment_header_id) FIELD2,
2215                   to_char(sh.shipped_date) FIELD3,
2216                   NULL FIELD4, --LSP
2217                   NULL FIELD5 ,    --<R12 MOAC>
2218                   to_char(sh.expected_receipt_date) FIELD6,
2219                   to_char(Decode(sh.receipt_source_code, 'VENDOR',sh.vendor_id, sl.from_organization_id)) FIELD7,
2220                   Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id, sl.from_organization_id),1,80) FIELD8,
2221                   Decode(sh.receipt_source_code,'VENDOR','Vendor','Organization') FIELD9,
2222                   sh.packing_slip FIELD10,
2223                   sh.bill_of_lading FIELD11,
2224                   sh.waybill_airbill_num FIELD12,
2225                   sh.freight_carrier_code FIELD13,
2226                   lookup_code FIELD14 ,
2227                   NULL FIELD15      --<R12 MOAC>
2228               FROM fnd_lookup_values_vl flv,
2229                   rcv_shipment_headers sh,
2230                   rcv_shipment_lines sl
2231               WHERE flv.lookup_code = 'ASN'
2232                   AND flv.lookup_type = 'DOC_TYPE'
2233                   AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2234                   AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2235                   AND flv.enabled_flag = 'Y'
2236                   AND sh.shipment_num IS NOT NULL
2237                   AND sh.shipment_header_id = sl.shipment_header_id
2238                   AND sl.to_organization_id = p_organization_id
2239                   AND sh.receipt_source_code = 'VENDOR'
2240                   AND sl.shipment_line_status_code <> 'CANCELLED'
2241                   AND sh.shipment_header_id = sl.shipment_header_id
2242                   AND sl.to_organization_id = p_organization_id
2243                   -- This was fix for bug 2740648/2752094
2244                   AND sh.asn_type IN ('ASN','ASBN')
2245                   AND sl.shipment_line_status_code IN ('EXPECTED','PARTIALLY RECEIVED')
2246                   AND sh.shipment_num LIKE (p_doc_number)
2247                ORDER BY 1,2 ;
2248          END IF ;  --Check for Item Id or Desc value
2249 --  For Bug 7440217 Added a the followign code for the documnet type as LCM
2250      ELSIF NVL(p_doc_type,'ALL') = 'LCM' THEN
2251          IF p_inventory_item_id IS NOT NULL THEN
2252             OPEN x_doc_num_lov FOR
2253               -- This Select Handles LCM
2254               SELECT DISTINCT
2255                   -- DOCTYPE LCM
2256                   meaning FIELD0,
2257                   sh.shipment_num FIELD1,
2258                   to_char(sh.shipment_header_id) FIELD2,
2259                   to_char(sh.shipped_date) FIELD3,
2260                   NULL FIELD4, --LSP
2261                   NULL FIELD5 ,   --<R12 MOAC>
2262                   to_char(sh.expected_receipt_date) FIELD6,
2263                   to_char(Decode(sh.receipt_source_code, 'VENDOR',sh.vendor_id, sl.from_organization_id)) FIELD7,
2264                   Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id, sl.from_organization_id),1,80) FIELD8,
2265                   Decode(sh.receipt_source_code,'VENDOR','Vendor','Organization') FIELD9,
2266                   sh.packing_slip FIELD10,
2267                   sh.bill_of_lading FIELD11,
2268                   sh.waybill_airbill_num FIELD12,
2269                   sh.freight_carrier_code FIELD13,
2270                   lookup_code FIELD14,
2271                   NULL FIELD15    --<R12 MOAC>
2272               FROM fnd_lookup_values_vl flv,
2273                   rcv_shipment_headers sh,
2274                   rcv_shipment_lines sl
2275               WHERE flv.lookup_code = 'LCM'
2276                   AND flv.lookup_type = 'DOC_TYPE'
2277                   AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2278                   AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2279                   AND flv.enabled_flag = 'Y'
2280                   AND sh.shipment_num IS NOT NULL
2281                   AND sh.shipment_header_id = sl.shipment_header_id
2282                   AND sl.to_organization_id = p_organization_id
2283                   AND sh.receipt_source_code = 'VENDOR'
2284                   AND sl.shipment_line_status_code <> 'CANCELLED'
2285                   AND sh.shipment_header_id = sl.shipment_header_id
2286                   AND sl.to_organization_id = p_organization_id
2287                   -- This was fix for bug 2740648/2752094
2288                   AND sh.asn_type in ('LCM')
2289                   AND sl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED')
2290                   AND sh.shipment_num LIKE (p_doc_number)
2291                   -- This was fix for bug 2774080
2292                   AND sl.item_id = p_inventory_item_id
2293               ORDER BY 1,2 ;
2294          ELSIF p_item_description IS NOT NULL THEN
2295             OPEN x_doc_num_lov FOR
2296               -- This Select Handles LCM
2297               SELECT DISTINCT
2298                   -- DOCTYPE LCM
2299                   meaning FIELD0,
2300                   sh.shipment_num FIELD1,
2301                   to_char(sh.shipment_header_id) FIELD2,
2302                   to_char(sh.shipped_date) FIELD3,
2303                   NULL FIELD4, --LSP
2304                   NULL FIELD5 ,  --<R12 MOAC>
2305                   to_char(sh.expected_receipt_date) FIELD6,
2306                   to_char(Decode(sh.receipt_source_code, 'VENDOR',sh.vendor_id, sl.from_organization_id)) FIELD7,
2307                   Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id, sl.from_organization_id),1,80) FIELD8,
2308                   Decode(sh.receipt_source_code,'VENDOR','Vendor','Organization') FIELD9,
2309                   sh.packing_slip FIELD10,
2310                   sh.bill_of_lading FIELD11,
2311                   sh.waybill_airbill_num FIELD12,
2312                   sh.freight_carrier_code FIELD13,
2313                   lookup_code FIELD14,
2314                   NULL FIELD15    --<R12 MOAC>
2315               FROM fnd_lookup_values_vl flv,
2316                   rcv_shipment_headers sh,
2317                   rcv_shipment_lines sl
2318               WHERE flv.lookup_code = 'LCM'
2319                   AND flv.lookup_type = 'DOC_TYPE'
2320                   AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2321                   AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2322                   AND flv.enabled_flag = 'Y'
2323                   AND sh.shipment_num IS NOT NULL
2324                   AND sh.shipment_header_id = sl.shipment_header_id
2325                   AND sl.to_organization_id = p_organization_id
2326                   AND sh.receipt_source_code = 'VENDOR'
2327                   AND sl.shipment_line_status_code <> 'CANCELLED'
2328                   AND sh.shipment_header_id = sl.shipment_header_id
2329                   AND sl.to_organization_id = p_organization_id
2330                   -- This was fix for bug 2740648/2752094
2331                   AND sh.asn_type in ('LCM')
2332                   AND sl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED')
2333                   AND sh.shipment_num LIKE (p_doc_number)
2334                   -- This was fix for bug 2774080
2335                   AND sl.item_description like p_item_description || '%'
2336               ORDER BY 1,2 ;
2337          ELSE
2338          --Both Inventory Item Id and Item Desc are Null
2339          --And also Both Item Id and Item Desc won't be passed together.
2340             OPEN x_doc_num_lov FOR
2341               SELECT DISTINCT
2342                   -- DOCTYPE LCM
2343                   meaning FIELD0,
2344                   sh.shipment_num FIELD1,
2345                   to_char(sh.shipment_header_id) FIELD2,
2346                   to_char(sh.shipped_date) FIELD3,
2347                   NULL FIELD4, --LSP
2348                   NULL FIELD5 ,    --<R12 MOAC>
2349                   to_char(sh.expected_receipt_date) FIELD6,
2350                   to_char(Decode(sh.receipt_source_code, 'VENDOR',sh.vendor_id, sl.from_organization_id)) FIELD7,
2351                   Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id, sl.from_organization_id),1,80) FIELD8,
2352                   Decode(sh.receipt_source_code,'VENDOR','Vendor','Organization') FIELD9,
2353                   sh.packing_slip FIELD10,
2354                   sh.bill_of_lading FIELD11,
2355                   sh.waybill_airbill_num FIELD12,
2356                   sh.freight_carrier_code FIELD13,
2357                   lookup_code FIELD14 ,
2358                   NULL FIELD15      --<R12 MOAC>
2359               FROM fnd_lookup_values_vl flv,
2360                   rcv_shipment_headers sh,
2361                   rcv_shipment_lines sl
2362               WHERE flv.lookup_code = 'LCM'
2363                   AND flv.lookup_type = 'DOC_TYPE'
2364                   AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2365                   AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2366                   AND flv.enabled_flag = 'Y'
2367                   AND sh.shipment_num IS NOT NULL
2368                   AND sh.shipment_header_id = sl.shipment_header_id
2369                   AND sl.to_organization_id = p_organization_id
2370                   AND sh.receipt_source_code = 'VENDOR'
2371                   AND sl.shipment_line_status_code <> 'CANCELLED'
2372                   AND sh.shipment_header_id = sl.shipment_header_id
2373                   AND sl.to_organization_id = p_organization_id
2374                   -- This was fix for bug 2740648/2752094
2375                   AND sh.asn_type IN ('LCM')
2376                   AND sl.shipment_line_status_code IN ('EXPECTED','PARTIALLY RECEIVED')
2377                   AND sh.shipment_num LIKE (p_doc_number)
2378                ORDER BY 1,2 ;
2379          END IF ;  --Check for Item Id or Desc value
2380 --  End for Bug 7440217
2381        ELSIF NVL(p_doc_type,'ALL') = 'REQ' THEN
2382          OPEN x_doc_num_lov FOR
2383             -- This Select Handles Requisitions
2384           SELECT DISTINCT
2385               meaning FIELD0,
2386               prh.segment1 FIELD1,
2387               to_char(prh.requisition_header_id) FIELD2,
2388               prh.description FIELD3,
2389               NULL FIELD4, --LSP
2390               MO_GLOBAL.get_ou_name (prh.org_id) FIELD5 ,     --<R12 MOAC>
2391               NULL FIELD6,
2392               NULL FIELD7,
2393               NULL FIELD8,
2394               NULL FIELD9,
2395               NULL FIELD10,
2396               NULL FIELD11,
2397               NULL FIELD12,
2398               NULL FIELD13,
2399               lookup_code FIELD14 ,
2400               to_char(prh.org_id) FIELD15        --<R12 MOAC>
2401           FROM fnd_lookup_values_vl flv,
2402               po_req_headers_trx_v prh,  -- CLM project, bug 9403291
2403               po_req_lines_trx_v prl     -- CLM project, bug 9403291
2404           WHERE flv.lookup_code = 'REQ'
2405               AND flv.lookup_type = 'DOC_TYPE'
2406               AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2407               AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2408               AND flv.enabled_flag = 'Y'
2409               AND Nvl(prl.cancel_flag,'N') = 'N'
2410               AND prl.destination_organization_id = p_organization_id
2411               AND prh.requisition_header_id = prl.requisition_header_id
2412               AND prh.authorization_status || '' = 'APPROVED'
2413               AND prh.segment1 LIKE (p_doc_number)
2414               AND EXISTS
2415               (
2416               SELECT
2417                   1
2418               FROM rcv_shipment_lines rsl
2419               WHERE rsl.requisition_line_id = prl.requisition_line_id
2420                   AND rsl.routing_header_id > 0 --Bug 3349131
2421                   AND rsl.shipment_line_status_code <> 'FULLY RECEIVED'
2422                   AND rsl.item_id LIKE Nvl(p_inventory_item_id,rsl.item_id)
2423               )
2424               AND p_item_description IS NULL
2425           ORDER BY 1,2 ;
2426        ELSIF NVL(p_doc_type,'ALL') = 'ALL' THEN
2427            OPEN x_doc_num_lov FOR
2428              -- This select takes care of Vendor Item and any non-expense item
2429              -- and cross ref item case.
2430              SELECT /*+index(POH PO_HEADERS_U2) */
2431                 DISTINCT
2432                 -- DOCTYPE PO
2433                 meaning FIELD0 ,
2434                 poh.segment1 FIELD1 ,
2435                 to_char(poh.po_header_id) FIELD2 ,
2436                 poh.type_lookup_code FIELD3 ,
2437                 wms_deploy.get_po_client_name(poh.po_header_id)  FIELD4 ,--LSP
2438                 MO_GLOBAL.get_ou_name(poh.org_id) FIELD5 ,     --<R12 MOAC>
2439                 PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID) FIELD6 ,
2440                 to_char(poh.vendor_id) FIELD7 ,
2441                 to_char(poh.vendor_site_id) FIELD8 ,
2442                 'Vendor' FIELD9 ,
2443                 poh.note_to_receiver FIELD10 ,
2444                 NULL FIELD11 ,
2445                 NULL FIELD12 ,
2446                 NULL FIELD13 ,
2447                 lookup_code FIELD14 ,
2448                 to_char(poh.org_id) FIELD15       --<R12 MOAC>
2449             FROM po_headers_trx_v poh, -- CLM project, bug 9403291
2450                 fnd_lookup_values_vl flv
2451             WHERE flv.lookup_code = 'PO'
2452                 AND flv.lookup_type = 'DOC_TYPE'
2453                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2454                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2455                 AND flv.enabled_flag = 'Y'
2456                 -- Bug 2859355 Added the Extra conditions for poh.
2457                 AND POH.TYPE_LOOKUP_CODE IN ('STANDARD','PLANNED', 'BLANKET','CONTRACT')
2458                 AND NVL(POH.CANCEL_FLAG, 'N') IN ('N', 'I')
2459                 AND NVL(POH.CLOSED_CODE, 'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3152693
2460                 AND poh.segment1 LIKE (p_doc_number||l_append)
2461                 AND EXISTS
2462                 (
2463                 SELECT
2464                     'Valid PO Shipments'
2465                 FROM po_lines_trx_v pl , -- CLM project, bug 9403291
2466                      po_line_locations_trx_v poll --CLM project, bug 9403291
2467 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
2468                    , mtl_parameters mp,
2469                      rcv_parameters rp
2470 --  End for Bug 7440217
2471                 WHERE pl.po_header_id = poh.po_header_id
2472                     AND Nvl(pl.vendor_product_num,' ') = Nvl(p_vendor_prod_num, Nvl(pl.vendor_product_num,' '))
2473                     AND Nvl(pl.item_id,-999) LIKE Nvl(p_inventory_item_id,'%')
2474                     AND poh.po_header_id = poll.po_header_id
2475                     AND pl.po_line_id = poll.po_line_id
2476                     AND poll.approved_flag = 'Y'
2477                     AND Nvl(poll.cancel_flag,'N') = 'N'
2478                     -- AND poll.closed_code = 'OPEN' -- Bug 2859335
2479                     AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
2480                     AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
2481                     AND poll.ship_to_organization_id = p_organization_id
2482                     AND poll.payment_type IS NULL  --R12 excludes all Complex Work POs (Bug4236155)
2483 --  For Bug 7440217 Checking if it is LCM enabled
2484                     AND mp.organization_id = p_organization_id
2485                     AND rp.organization_id = p_organization_id
2486                     AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
2487                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
2488                                  OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
2489                         )
2490 --  End for Bug 7440217
2491                 )
2492                 AND p_item_description IS NULL
2493             UNION
2494             -- This Select Handles Substitute Items
2495             SELECT /*+index(POH PO_HEADERS_U2) */
2496                 DISTINCT
2497                 -- DOCTYPE PO
2498                 meaning FIELD0 ,
2499                 poh.segment1 FIELD1 ,
2500                 to_char(poh.po_header_id) FIELD2 ,
2501                 poh.type_lookup_code FIELD3 ,
2502                 wms_deploy.get_po_client_name(poh.po_header_id)  FIELD4 ,--LSP
2503                 MO_GLOBAL.get_ou_name(poh.org_id) FIELD5,     --<R12 MOAC>
2504                 PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID) FIELD6 ,
2505                 to_char(poh.vendor_id) FIELD7 ,
2506                 to_char(poh.vendor_site_id) FIELD8 ,
2507                 'Vendor' FIELD9 ,
2508                 poh.note_to_receiver FIELD10 ,
2509                 NULL FIELD11 ,
2510                 NULL FIELD12 ,
2511                 NULL FIELD13 ,
2512                 lookup_code FIELD14 ,
2513                 to_char(poh.org_id) FIELD15       --<R12 MOAC>
2514             FROM po_headers_trx_v poh, --CLM project, bug 9403291
2515                 fnd_lookup_values_vl flv
2516             WHERE flv.lookup_code = 'PO'
2517                 AND flv.lookup_type = 'DOC_TYPE'
2518                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2519                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2520                 AND flv.enabled_flag = 'Y'
2521                 -- Bug 2859355 Added the Extra conditions for poh.
2522                 AND POH.TYPE_LOOKUP_CODE IN ('STANDARD','PLANNED', 'BLANKET','CONTRACT')
2523                 AND NVL(POH.CANCEL_FLAG, 'N') IN ('N', 'I')
2524                 AND NVL(POH.CLOSED_CODE, 'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3152693
2525                 AND poh.segment1 LIKE (p_doc_number||l_append)
2526                 AND EXISTS
2527                 (
2528                 SELECT
2529                     'Valid PO Shipments'
2530                 FROM po_lines_trx_v pl , -- CLM project, bug 9403291
2531                     mtl_related_items mri ,
2532                     mtl_system_items_kfv msi ,
2533                     po_line_locations_trx_v poll -- CLM project, bug 9403291
2534 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
2535                   , mtl_parameters mp,
2536                     rcv_parameters rp
2537 --  End for Bug 7440217
2538                 WHERE msi.organization_id = p_organization_id
2539                     AND
2540                     (
2541                         (
2542                             mri.related_item_id = msi.inventory_item_id
2543                             AND pl.item_id = mri.inventory_item_id
2544                             AND msi.inventory_item_id LIKE p_inventory_item_id
2545                         )
2546                         OR
2547                         (
2548                             mri.inventory_item_id = msi.inventory_item_id
2549                             AND pl.item_id = mri.related_item_id
2550                             AND mri.reciprocal_flag = 'Y'
2551                             AND msi.inventory_item_id LIKE p_inventory_item_id
2552                         )
2553                     )
2554                     AND pl.po_header_id = poh.po_header_id
2555                     AND Nvl(pl.vendor_product_num,' ') = Nvl(p_vendor_prod_num,Nvl(pl.vendor_product_num,' '))
2556                     AND poh.po_header_id = poll.po_header_id
2557                     AND pl.po_line_id = poll.po_line_id
2558                     AND poll.approved_flag = 'Y'
2559                     AND Nvl(poll.cancel_flag,'N') = 'N'
2560                     -- AND poll.closed_code = 'OPEN' -- Bug 2859355
2561                     AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
2562                     AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
2563                     AND poll.ship_to_organization_id = p_organization_id
2564                     AND poll.payment_type IS NULL  --R12 excludes all Complex Work POs (Bug4236155)
2565 --  For Bug 7440217 Checking if it is LCM enabled
2566                     AND mp.organization_id = p_organization_id
2567                     AND rp.organization_id = p_organization_id
2568                     AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
2569                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
2570                                  OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
2571                         )
2572 --  End for Bug 7440217
2573                 )
2574                 AND p_item_description IS NULL
2575             UNION
2576             -- This Select Handles Expense Items
2577             SELECT /*+index(POH PO_HEADERS_U2) */
2578                 DISTINCT
2579                 -- DOCTYPE PO
2580                 meaning FIELD0 ,
2581                 poh.segment1 FIELD1 ,
2582                 to_char(poh.po_header_id) FIELD2 ,
2583                 poh.type_lookup_code FIELD3 ,
2584                 wms_deploy.get_po_client_name(poh.po_header_id)  FIELD4 ,--LSP
2585                 MO_GLOBAL.get_ou_name(poh.org_id) FIELD5 ,    --<R12 MOAC>
2586                 PO_VENDORS_SV2.GET_VENDOR_NAME_FUNC(POH.VENDOR_ID) FIELD6 ,
2587                 to_char(poh.vendor_id) FIELD7 ,
2588                 to_char(poh.vendor_site_id) FIELD8 ,
2589                 'Vendor' FIELD9 ,
2590                 poh.note_to_receiver FIELD10 ,
2591                 NULL FIELD11 ,
2592                 NULL FIELD12 ,
2593                 NULL FIELD13 ,
2594                 lookup_code FIELD14 ,
2595                 to_char(poh.org_id) FIELD15        --<R12 MOAC>
2596             FROM po_headers_trx_v poh, -- CLM project, bug 9403291
2597                 fnd_lookup_values_vl flv
2598             WHERE flv.lookup_code = 'PO'
2599                 AND flv.lookup_type = 'DOC_TYPE'
2600                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2601                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2602                 AND flv.enabled_flag = 'Y'
2603                 -- Bug 2859355 Added the Extra conditions for poh.
2604                 AND POH.TYPE_LOOKUP_CODE IN ('STANDARD','PLANNED', 'BLANKET','CONTRACT')
2605                 AND NVL(POH.CANCEL_FLAG, 'N') IN ('N', 'I')
2606                 AND NVL(POH.CLOSED_CODE, 'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3152693
2607                 AND poh.segment1 LIKE (p_doc_number||l_append)
2608                 AND EXISTS
2609                 (
2610                 SELECT
2611                     'Valid PO Shipments'
2612                 FROM po_lines_trx_v pl ,  -- CLM project, bug 9403291
2613                      po_line_locations_trx_v poll  -- CLM project, bug 9403291
2614 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
2615                    , mtl_parameters mp,
2616                      rcv_parameters rp
2617 --  End for Bug 7440217
2618                 WHERE pl.item_id IS NULL
2619                     AND pl.item_description LIKE p_item_description||'%'
2620                     AND pl.po_header_id = poh.po_header_id
2621                     AND Nvl(pl.vendor_product_num,' ') = Nvl(p_vendor_prod_num,Nvl(pl.vendor_product_num,' '))
2622                     AND poh.po_header_id = poll.po_header_id
2623                     AND pl.po_line_id = poll.po_line_id
2624                     AND Nvl(poll.approved_flag,'N') = 'Y'
2625                     AND Nvl(poll.cancel_flag,'N') = 'N'
2626                     -- AND poll.closed_code = 'OPEN' --Bug 2859355
2627                     AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
2628                     AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
2629                     AND poll.ship_to_organization_id = p_organization_id
2630                     AND poll.payment_type IS NULL  --R12 excludes all Complex Work POs (Bug4236155)
2631 --  For Bug 7440217 Checking if it is LCM enabled
2632                     AND mp.organization_id = p_organization_id
2633                     AND rp.organization_id = p_organization_id
2634                     AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
2635                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
2636                                  OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
2637                         )
2638 --  End for Bug 7440217
2639                 )
2640                 AND p_item_description IS NOT NULL
2641             UNION ALL
2642             -- This Select Handles RMAs
2643             SELECT DISTINCT
2644                 -- DOCTYPE RMA
2645                 meaning FIELD0,
2646                 to_char(OEH.ORDER_NUMBER) FIELD1,
2647                 to_char(OEL.HEADER_ID) FIELD2,
2648                 OTT_TL.NAME FIELD3, --OLT.NAME                FIELD3,--bug3173013
2649                 NULL FIELD4, --LSP
2650                 NULL FIELD5,                    --<R12 MOAC>
2651                 OTT_ALL.ORDER_CATEGORY_CODE FIELD6, --OLT.ORDER_CATEGORY_CODE FIELD5,
2652                 to_char(OESOLD.CUSTOMER_ID) FIELD7,
2653                 /* TCA Cleanup */
2654                 PARTY.party_name FIELD8,
2655                 PARTY.party_number FIELD9,
2656                 --OEC.customer_name FIELD7,
2657                 --OEC.customer_number FIELD8,
2658                 NULL FIELD10,
2659                 NULL FIELD11,
2660                 NULL FIELD12,
2661                 NULL FIELD13,
2662                 lookup_code FIELD14 ,
2663                 to_char(oel.org_id) FIELD15     --<R12 MOAC>
2664             FROM fnd_lookup_values_vl flv,
2665                 OE_ORDER_LINES_all OEL,
2666                 OE_ORDER_HEADERS_all OEH,
2667                 --OE_LINE_TYPES_V OLT,    --bug3173013
2668                 OE_TRANSACTION_TYPES_TL OTT_TL,
2669                 OE_TRANSACTION_TYPES_ALL OTT_ALL,
2670                 OE_SOLD_TO_ORGS_V OESOLD,
2671                 --WF_ITEM_ACTIVITY_STATUSES WF,
2672                 --WF_PROCESS_ACTIVITIES WPA,
2673                 --RA_CUSTOMERS OEC /*TCA Cleanup */
2674                 HZ_PARTIES PARTY,
2675                 HZ_CUST_ACCOUNTS CUST_ACCT
2676             WHERE flv.lookup_code = 'RMA'
2677                 AND flv.lookup_type = 'DOC_TYPE'
2678                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2679                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2680                 AND flv.enabled_flag = 'Y'
2681                 AND OEL.LINE_CATEGORY_CODE='RETURN'
2682                 AND nvl(OEL.SHIP_FROM_ORG_ID, OEH.SHIP_FROM_ORG_ID) = p_organization_id
2683                 AND OEL.HEADER_ID = OEH.HEADER_ID
2684                 AND OEL.SOLD_TO_ORG_ID = OESOLD.ORGANIZATION_ID
2685                 --AND OESOLD.CUSTOMER_ID = oec.customer_id /*TCA Cleanup */
2686 		--Bug5417779: oesold.customer_id should be joined with cust_acct.cust_account_id
2687 	        AND OESOLD.CUSTOMER_ID = CUST_ACCT.CUST_ACCOUNT_ID
2688                 AND CUST_ACCT.PARTY_ID = PARTY.party_id
2689                 --AND OEL.LINE_TYPE_ID = OLT.LINE_TYPE_ID--bug3173013
2690                 AND OEH.ORDER_TYPE_ID = OTT_ALL.TRANSACTION_TYPE_ID
2691                 AND OTT_ALL.ORDER_CATEGORY_CODE in ('MIXED', 'RETURN')
2692                 AND OTT_ALL.TRANSACTION_TYPE_ID = OTT_TL.TRANSACTION_TYPE_ID
2693                 AND OTT_TL.LANGUAGE = USERENV('LANG')
2694                 AND OEH.BOOKED_FLAG='Y'
2695                 AND OEH.OPEN_FLAG='Y'
2696                 AND OEL.ORDERED_QUANTITY > NVL(OEL.SHIPPED_QUANTITY,0)
2697                 AND OEL.FLOW_STATUS_CODE = 'AWAITING_RETURN'
2698                 --
2699                 -- The following lines are commented for Performance Improvement
2700                 -- instead flow_status_code is used from oel
2701                 --AND WPA.ACTIVITY_ITEM_TYPE = 'OEOL'
2702                 --AND WPA.ACTIVITY_NAME = 'RMA_WAIT_FOR_RECEIVING'
2703                 --AND WF.ITEM_TYPE = 'OEOL'
2704                 --AND WF.PROCESS_ACTIVITY = WPA.INSTANCE_ID
2705                 --AND WF.ACTIVITY_STATUS = 'NOTIFIED'
2706                 --AND OEL.LINE_ID = TO_NUMBER(WF.ITEM_KEY)
2707                 --
2708                 AND oeh.order_number LIKE (p_doc_number)
2709                 AND OEL.inventory_item_id LIKE Nvl(p_inventory_item_id,'%')
2710                 AND p_item_description IS NULL
2711             UNION ALL
2712              -- This Select Handles Internal Sales Order , Org Transfer
2713             SELECT DISTINCT
2714                 -- DOCTYPE INTSHIP
2715                 meaning FIELD0,
2716                 sh.shipment_num FIELD1,
2717                 to_char(sh.shipment_header_id) FIELD2,
2718                 to_char(sh.shipped_date) FIELD3,
2719                 NULL FIELD4, --LSP
2720                 NULL FIELD5 ,     --<R12 MOAC>
2721                 to_char(sh.expected_receipt_date) FIELD6,
2722                 to_char(Decode(sh.receipt_source_code, 'VENDOR',sh.vendor_id, sl.from_organization_id)) FIELD7,
2723                 Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id, sl.from_organization_id),1,80) FIELD8,
2724                 Decode(sh.receipt_source_code,'VENDOR','Vendor',sh.receipt_source_code) FIELD9, --bug fix 3939003
2725                 sh.packing_slip FIELD10,
2726                 sh.bill_of_lading FIELD11,
2727                 sh.waybill_airbill_num FIELD12,
2728                 sh.freight_carrier_code FIELD13,
2729                 lookup_code FIELD14,
2730                 NULL FIELD15     --<R12 MOAC>
2731             FROM fnd_lookup_values_vl flv,
2732                 rcv_shipment_headers sh,
2733                 rcv_shipment_lines sl
2734             WHERE flv.lookup_code = 'INTSHIP'
2735                 AND flv.lookup_type = 'DOC_TYPE'
2736                 AND nvl(flv.start_date_active, SYSDATE )<= SYSDATE
2737                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2738                 AND flv.enabled_flag = 'Y'
2739                 AND sh.shipment_num IS NOT NULL
2740                 AND sh.shipment_header_id = sl.shipment_header_id
2741                 AND sl.to_organization_id = p_organization_id
2742                 AND sh.receipt_source_code IN ('INTERNAL ORDER','INVENTORY')
2743                 AND EXISTS
2744                 (
2745                 SELECT
2746                     'available supply'
2747                 FROM mtl_supply ms
2748                 WHERE ms.to_organization_id = p_organization_id
2749                     AND ms.shipment_header_id = sh.shipment_header_id
2750                 )
2751                 -- This was fix for bug 2740648/2752094
2752                 AND sl.shipment_line_status_code IN ('EXPECTED','PARTIALLY RECEIVED')
2753                 AND sh.shipment_num LIKE (p_doc_number)
2754                 AND sl.item_id like Nvl(p_inventory_item_id,'%')
2755                 AND p_item_description IS NULL
2756             UNION ALL
2757             -- This Select Handles ASN
2758             SELECT DISTINCT
2759                 -- DOCTYPE ASN
2760                 meaning FIELD0,
2761                 sh.shipment_num FIELD1,
2762                 to_char(sh.shipment_header_id) FIELD2,
2763                 to_char(sh.shipped_date) FIELD3,
2764                 NULL FIELD4, --LSP
2765                 NULL FIELD5 ,      --<R12 MOAC>
2766                 to_char(sh.expected_receipt_date) FIELD6,
2767                 to_char(Decode(sh.receipt_source_code, 'VENDOR',sh.vendor_id, sl.from_organization_id)) FIELD7,
2768                 Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id, sl.from_organization_id),1,80) FIELD8,
2769                 Decode(sh.receipt_source_code,'VENDOR','Vendor','Organization') FIELD9,
2770                 sh.packing_slip FIELD10,
2771                 sh.bill_of_lading FIELD11,
2772                 sh.waybill_airbill_num FIELD12,
2773                 sh.freight_carrier_code FIELD13,
2774                 lookup_code FIELD14,
2775                 NULL FIELD15      --<R12 MOAC>
2776             FROM fnd_lookup_values_vl flv,
2777                 rcv_shipment_headers sh,
2778                 rcv_shipment_lines sl
2779             WHERE flv.lookup_code = 'ASN'
2780                 AND flv.lookup_type = 'DOC_TYPE'
2781                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2782                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2783                 AND flv.enabled_flag = 'Y'
2784                 AND sh.shipment_num IS NOT NULL
2785                 AND sh.shipment_header_id = sl.shipment_header_id
2786                 AND sl.to_organization_id = p_organization_id
2787                 AND sh.receipt_source_code = 'VENDOR'
2788                 AND sl.shipment_line_status_code <> 'CANCELLED'
2789                 AND sh.shipment_header_id = sl.shipment_header_id
2790                 AND sl.to_organization_id = p_organization_id
2791                 -- This was fix for bug 2740648/2752094
2792                 AND sh.asn_type in ('ASN','ASBN')
2793                 AND sl.shipment_line_status_code IN ('EXPECTED','PARTIALLY RECEIVED')
2794                 AND sh.shipment_num LIKE (p_doc_number)
2795                 -- This was fix for bug 2774080
2796                 AND
2797                 (
2798                     (
2799                             p_item_description IS NULL
2800                         AND sl.item_id LIKE Nvl(p_inventory_item_id,'%')
2801 
2802                     )
2803                     OR
2804                     (
2805                             p_inventory_item_id IS NULL
2806                         AND sl.item_description LIKE Nvl(p_item_description , '%' )
2807                     )
2808                 )
2809 --  For Bug 7440217 adding all LCM Docs also to the LOV query
2810        UNION ALL
2811             -- This Select Handles LCM
2812             SELECT DISTINCT
2813                 -- DOCTYPE LCM
2814                 meaning FIELD0,
2815                 sh.shipment_num FIELD1,
2816                 to_char(sh.shipment_header_id) FIELD2,
2817                 to_char(sh.shipped_date) FIELD3,
2818                 NULL FIELD4, --LSP
2819                 NULL FIELD5 ,      --<R12 MOAC>
2820                 to_char(sh.expected_receipt_date) FIELD6,
2821                 to_char(Decode(sh.receipt_source_code, 'VENDOR',sh.vendor_id, sl.from_organization_id)) FIELD7,
2822                 Substr( rcv_intransit_sv.rcv_get_org_name(sh.receipt_source_code,sh.vendor_id, sl.from_organization_id),1,80) FIELD8,
2823                 Decode(sh.receipt_source_code,'VENDOR','Vendor','Organization') FIELD9,
2824                 sh.packing_slip FIELD10,
2825                 sh.bill_of_lading FIELD11,
2826                 sh.waybill_airbill_num FIELD12,
2827                 sh.freight_carrier_code FIELD13,
2828                 lookup_code FIELD14,
2829                 NULL FIELD15      --<R12 MOAC>
2830             FROM fnd_lookup_values_vl flv,
2831                 rcv_shipment_headers sh,
2832                 rcv_shipment_lines sl
2833             WHERE flv.lookup_code = 'LCM'
2834                 AND flv.lookup_type = 'DOC_TYPE'
2835                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2836                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2837                 AND flv.enabled_flag = 'Y'
2838                 AND sh.shipment_num IS NOT NULL
2839                 AND sh.shipment_header_id = sl.shipment_header_id
2840                 AND sl.to_organization_id = p_organization_id
2841                 AND sh.receipt_source_code = 'VENDOR'
2842                 AND sl.shipment_line_status_code <> 'CANCELLED'
2843                 AND sh.shipment_header_id = sl.shipment_header_id
2844                 AND sl.to_organization_id = p_organization_id
2845                 -- This was fix for bug 2740648/2752094
2846                 AND sh.asn_type in ('LCM')
2847                 AND sl.shipment_line_status_code IN ('EXPECTED','PARTIALLY RECEIVED')
2848                 AND sh.shipment_num LIKE (p_doc_number)
2849                 -- This was fix for bug 2774080
2850                 AND
2851                 (
2852                     (
2853                             p_item_description IS NULL
2854                         AND sl.item_id LIKE Nvl(p_inventory_item_id,'%')
2855 
2856                     )
2857                     OR
2858                     (
2859                             p_inventory_item_id IS NULL
2860                         AND sl.item_description LIKE Nvl(p_item_description , '%' )
2861                     )
2862                 )
2863 --  End for Bug 7440217
2864             UNION ALL
2865             -- This Select Handles Requisitions
2866             SELECT DISTINCT
2867                 meaning FIELD0,
2868                 prh.segment1 FIELD1,
2869                 to_char(prh.requisition_header_id) FIELD2,
2870                 prh.description FIELD3,
2871                 NULL FIELD4, --LSP
2872                 MO_GLOBAL.get_ou_name (prh.org_id) FIELD5 ,  --<R12 MOAC>
2873                 NULL FIELD6,
2874                 NULL FIELD7,
2875                 NULL FIELD8,
2876                 NULL FIELD9,
2877                 NULL FIELD10,
2878                 NULL FIELD11,
2879                 NULL FIELD12,
2880                 NULL FIELD13,
2881                 lookup_code FIELD14 ,
2882                 to_char(prh.org_id) FIELD15             --<R12 MOAC>
2883             FROM fnd_lookup_values_vl flv,
2884                 po_req_headers_trx_v prh, -- CLM project, bug 9403291
2885                 po_req_lines_trx_v prl    -- CLM project, bug 9403291
2886             WHERE flv.lookup_code = 'REQ'
2887                 AND flv.lookup_type = 'DOC_TYPE'
2888                 AND nvl(flv.start_date_active, SYSDATE) <= SYSDATE
2889                 AND nvl(flv.end_date_active,sysdate) >= SYSDATE
2890                 AND flv.enabled_flag = 'Y'
2891                 AND Nvl(prl.cancel_flag,'N') = 'N'
2892                 AND prl.destination_organization_id = p_organization_id
2893                 AND prh.requisition_header_id = prl.requisition_header_id
2894                 AND prh.authorization_status || '' = 'APPROVED'
2895                 AND prh.segment1 LIKE (p_doc_number)
2896                 AND EXISTS
2897                 (
2898                 SELECT
2899                     1
2900                 FROM rcv_shipment_lines rsl
2901                 WHERE rsl.requisition_line_id = prl.requisition_line_id
2902                     AND rsl.routing_header_id > 0 --Bug 3349131
2903                     AND rsl.shipment_line_status_code <> 'FULLY RECEIVED'
2904                     AND rsl.item_id LIKE Nvl(p_inventory_item_id,rsl.item_id)
2905                 )
2906                 AND p_item_description IS NULL
2907             ORDER BY 1,2 ;
2908        END IF;  -- Check for p_doc_type
2909      END IF ; --  Check for p_mobile_form
2910   END GET_DOC_LOV ;
2911 
2912 --      Name: GET_PO_LINE_ITEM NUM_LOV
2913 --
2914 --      Input parameters:
2915 --       p_Organization_Id   which restricts LOV SQL to current org
2916 --       p_po_header_id      which restricts LOV SQL to the PO
2917 --       p_po_line_num which restricts the LOV to the user input text.
2918 --
2919 --      Output parameters:
2920 --       x_po_line_num_lov returns LOV rows as reference cursor
2921 --
2922 --      Functions: This API returns PO Line numbers for a given PO and Item Id
2923 --
2924 PROCEDURE GET_PO_LINE_ITEM_NUM_LOV(x_po_line_num_lov OUT NOCOPY t_genref,
2925             p_organization_id IN NUMBER,
2926             p_po_header_id IN NUMBER,
2927             p_mobile_form IN VARCHAR2,
2928             p_po_line_num IN VARCHAR2,
2929                               p_inventory_item_id IN VARCHAR2)
2930   IS
2931   po_line_number VARCHAR2(20);
2932 BEGIN
2933    -- Added for bug 9776756
2934   if PO_CLM_INTG_GRP.is_clm_po(p_po_header_id,null,null,null) = 'Y' THEN
2935      po_line_number := p_po_line_num;
2936   else
2937   -- End of Bug 9776756
2938     BEGIN
2939       /* Start - Fix for Bug# 6640083 */
2940        -- po_line_number := to_char(to_number(p_po_line_num));
2941        -- This will convert String to number - Bug#6012703
2942        -- Commented the code for  Bug#6640083
2943       SELECT TRIM(LEADING '0' FROM p_po_line_num ) INTO po_line_number FROM Dual;
2944            -- This will trim leading zeroes - Bug#6640083
2945        /* End - Fix for Bug# 6640083 */
2946      EXCEPTION
2947      WHEN OTHERS then
2948        po_line_number := p_po_line_num;
2949      END;
2950   END IF; -- bug 9776756
2951    --  CLM project
2952    IF p_mobile_form = 'RECEIPT' THEN
2953      /*Bug#5612236. In the below query, replaced 'MTL_SYSTEM_ITEMS_KFV' with
2954        'MTL_SYSTEM_ITEMS_VL' and item desc is selected from this table.*/
2955 
2956       /*Bug # 8687063  : Because of the fix done for bug 6437363, the query was returning
2957        zero row for expense item (We do not enter item while creating PO in this case).
2958        For this case,we have value if item_id in po_lines_all table as null,
2959        Modified the AND clasue in such a way that MSI should not be checked for organization_id
2960        if po_lines_all.item_id is null */
2961 
2962       OPEN x_po_line_num_lov FOR
2963       -- Bug 6437363 : Modified the query for better performance.
2964   select distinct pl.line_num
2965              , pl.po_line_id
2966               -- Bug 10004703
2967 			 , NVL(pl.item_description, msi.description) -- Bug 14645109
2968              , pl.item_id
2969              , pl.item_revision
2970              , msi.concatenated_segments
2971              , msi.outside_operation_flag
2972              , inv_ui_item_lovs.get_conversion_rate(mum.uom_code,
2973                                    p_organization_id,
2974                                    pl.Item_Id)
2975                uom_code
2976           from po_lines_trx_v pl -- CLM project, bug 9403291
2977              , mtl_units_of_measure mum
2978              , mtl_system_items_vl msi
2979          where pl.item_id = msi.inventory_item_id (+)
2980            and mum.UNIT_OF_MEASURE(+) = pl.UNIT_MEAS_LOOKUP_CODE
2981  --        and msi.organization_id = p_organization_id -- Bug 6437363
2982            and (pl.item_id is null or msi.organization_id = p_organization_id)  --Bug 8687063
2983            and pl.po_header_id = p_po_header_id
2984      and exists (SELECT 'Valid PO Shipments'
2985                         FROM po_line_locations_trx_v poll -- CLM project, bug 9403291
2986 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
2987                            , mtl_parameters mp,
2988                              rcv_parameters rp
2989 --  End for Bug 7440217
2990                        WHERE poll.po_header_id = pl.po_header_id
2991                          AND poll.po_line_id = pl.po_line_id
2992                          AND Nvl(poll.approved_flag,'N') =  'Y'
2993                          AND Nvl(poll.cancel_flag,'N') = 'N'
2994                          -- AND poll.closed_code = 'OPEN' -- Bug 2859355
2995                          AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
2996                          AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
2997                          AND poll.ship_to_organization_id = p_organization_id
2998 --  For Bug 7440217 Checking if it is LCM enabled
2999                          AND mp.organization_id = p_organization_id
3000                          AND rp.organization_id = p_organization_id
3001                          AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
3002                                   OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
3003                                      OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
3004                              )
3005 --  End for Bug 7440217
3006                          )
3007            AND pl.line_num LIKE (po_line_number)
3008            AND nvl(pl.item_id,-999) LIKE nvl(p_inventory_item_id,'%')
3009            UNION ALL
3010      select distinct pl.line_num
3011              , pl.po_line_id
3012                -- Bug 10004703
3013 			 , NVL(pl.item_description, msi.description) -- Bug 14645109
3014              , pl.item_id
3015              , pl.item_revision
3016              , msi.concatenated_segments
3017              , msi.outside_operation_flag
3018              , inv_ui_item_lovs.get_conversion_rate(mum.uom_code,
3019                                    p_organization_id,
3020                                    pl.Item_Id)
3021                uom_code
3022           from po_lines_trx_v pl -- CLM project, bug 9403291
3023              , mtl_units_of_measure mum
3024              , mtl_system_items_vl msi
3025              , mtl_related_items mri
3026          where msi.organization_id = p_organization_id -- Bug 6437363
3027            and msi.inventory_item_id = p_inventory_item_id -- Bug 6311550
3028            and mum.UNIT_OF_MEASURE(+) = pl.UNIT_MEAS_LOOKUP_CODE
3029            and pl.po_header_id = p_po_header_id
3030      and exists (SELECT 'Valid PO Shipments'
3031                         FROM po_line_locations_trx_v poll -- CLM project, bug 9403291
3032 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
3033                            , mtl_parameters mp,
3034                              rcv_parameters rp
3035 --  End for Bug 7440217
3036                        WHERE poll.po_header_id = pl.po_header_id
3037                          AND poll.po_line_id = pl.po_line_id
3038                          AND Nvl(poll.approved_flag,'N') =  'Y'
3039                          AND Nvl(poll.cancel_flag,'N') = 'N'
3040                          -- AND poll.closed_code = 'OPEN' --Bug 2859355
3041                          AND Nvl(poll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
3042                          AND poll.shipment_type IN ('STANDARD','BLANKET','SCHEDULED')
3043                          AND poll.ship_to_organization_id = p_organization_id
3044 --  For Bug 7440217 Checking if it is LCM enabled
3045                          AND mp.organization_id = p_organization_id
3046                          AND rp.organization_id = p_organization_id
3047                          AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
3048                                   OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
3049                                       OR (NVL(poll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
3050                              )
3051 --  End for Bug 7440217
3052                          )
3053                          AND pl.line_num LIKE (po_line_number)
3054                          AND exists (select 'c'                               -- Bug 6437363
3055                                     from  MTL_RELATED_ITEMS MRI
3056                                     where MRI.RELATED_ITEM_ID = MSI.INVENTORY_ITEM_ID
3057                                       AND PL.ITEM_ID =  MRI.INVENTORY_ITEM_ID
3058                                     union all
3059                                     select 'c'
3060                                      from  MTL_RELATED_ITEMS MRI
3061                                      where MRI.INVENTORY_ITEM_ID = MSI.INVENTORY_ITEM_ID
3062                                        AND PL.ITEM_ID = MRI.RELATED_ITEM_ID
3063                                        AND MRI.RECIPROCAL_FLAG = 'Y'  )
3064                         order by 1;
3065     ELSE
3066       OPEN x_po_line_num_lov FOR
3067   select distinct pl.line_num
3068              , pl.po_line_id
3069              -- Bug 7274407
3070 			 , NVL(pl.item_description, msi.description) -- Bug 14645109
3071              , pl.item_id
3072              , pl.item_revision
3073              , msi.concatenated_segments
3074        , msi.outside_operation_flag
3075              , inv_ui_item_lovs.get_conversion_rate(mum.uom_code,
3076                                    p_organization_id,
3077                                    pl.Item_Id)
3078                uom_code
3079   FROM rcv_supply rsup
3080              , mtl_units_of_measure mum
3081        , po_lines_trx_v pl -- CLM project, bug 9403291
3082              , mtl_system_items_vl msi
3083    WHERE rsup.po_line_id = pl.po_line_id
3084            and mum.UNIT_OF_MEASURE(+) = pl.UNIT_MEAS_LOOKUP_CODE
3085      AND pl.item_id = msi.inventory_item_id (+)
3086            and Nvl(msi.organization_id, p_organization_id) = p_organization_id
3087            and rsup.po_header_id = p_po_header_id
3088            AND pl.line_num LIKE (po_line_number)
3089          order by 1;
3090    END IF;
3091 END GET_PO_LINE_ITEM_NUM_LOV;
3092 
3093 
3094 PROCEDURE get_job_lov (x_job_lov OUT NOCOPY t_genref,
3095            p_organization_id IN NUMBER,
3096            p_po_header_id IN NUMBER,
3097            p_po_line_id IN NUMBER,
3098            p_item_id IN NUMBER,
3099            p_Job IN VARCHAR2,
3100                        p_po_release_id IN NUMBER DEFAULT NULL,  --Bug #3883926
3101 		       p_shipment_header_id IN NUMBER DEFAULT NULL)--Added for Bug 9525003
3102   IS
3103 BEGIN
3104   --Fix for Bug # 3883926
3105   --Added the IF clause to check whether Release Id is
3106   --passed or not and execute the appropriate query.
3107   IF p_po_release_id IS NOT NULL THEN
3108    OPEN x_job_lov FOR
3109      SELECT wojv.wip_entity_name
3110      , wojv.wip_entity_id
3111      , wolv.line_code
3112      , woov.operation_seq_num
3113      , woov.department_code
3114      , pda.po_distribution_id
3115      , (pda.quantity_ordered - pda.quantity_delivered)
3116      , woov.repetitive_schedule_id
3117      FROM po_headers_all phl
3118      , po_lines_all pla
3119      , po_distributions_all pda
3120      , po_releases_all prl
3121      , wip_osp_jobs_val_v wojv
3122      , wip_osp_lines_val_v wolv
3123      , wip_osp_operations_val_v woov
3124      WHERE phl.po_header_id = p_po_header_id
3125      AND phl.po_header_id = pla.po_header_id
3126      AND pla.po_line_id = nvl (p_po_line_id, pla.po_line_id)
3127      AND pla.item_id = nvl (p_item_id, pla.item_id)
3128      AND pla.po_line_id = pda.po_line_id
3129      --Bug # 3883926
3130      AND prl.po_header_id = phl.po_header_id
3131      AND prl.po_release_id = p_po_release_id
3132      AND prl.po_release_id = pda.po_release_id
3133      --Bug # 3883926
3134      AND wojv.wip_entity_id = pda.wip_entity_id
3135      AND wojv.organization_id = pda.destination_organization_id
3136      AND wojv.organization_id = p_organization_id
3137      AND wolv.line_id (+) = pda.wip_line_id
3138      AND wolv.organization_id (+) = pda.destination_organization_id
3139      AND woov.wip_entity_id = pda.wip_entity_id
3140      AND woov.organization_id = pda.destination_organization_id
3141      AND woov.operation_seq_num (+) = pda.wip_operation_seq_num
3142      AND nvl (woov.repetitive_schedule_id, -1) = nvl (pda.wip_repetitive_schedule_id, -1)
3143      AND wojv.wip_entity_name like (p_job)
3144      ORDER BY wojv.wip_entity_name;
3145 
3146       --Added for bug 9525003 - Start
3147   ELSIF p_shipment_header_id IS NOT NULL THEN
3148    OPEN x_job_lov FOR
3149      SELECT wojv.wip_entity_name
3150      , wojv.wip_entity_id
3151      , wolv.line_code
3152      , woov.operation_seq_num
3153      , woov.department_code
3154      , pda.po_distribution_id
3155      , (pda.quantity_ordered - pda.quantity_delivered)
3156      , woov.repetitive_schedule_id
3157      FROM po_headers_all phl
3158      , po_lines_all pla
3159      , po_distributions_all pda
3160      , wip_osp_jobs_val_v wojv
3161      , wip_osp_lines_val_v wolv
3162      , wip_osp_operations_val_v woov
3163      , rcv_shipment_headers shh
3164      , rcv_shipment_lines shl
3165      WHERE shh.shipment_header_id = p_shipment_header_id
3166      AND shl.shipment_header_id = shh.shipment_header_id
3167      AND phl.po_header_id =shl.po_header_id
3168      AND phl.po_header_id = pla.po_header_id
3169      AND pla.po_line_id = nvl (p_po_line_id, pla.po_line_id)
3170      AND pla.item_id = nvl (p_item_id, pla.item_id)
3171      AND pla.po_line_id = pda.po_line_id
3172      AND wojv.wip_entity_id = pda.wip_entity_id
3173      AND wojv.organization_id = pda.destination_organization_id
3174      AND wojv.organization_id = p_organization_id
3175      AND wolv.line_id (+) = pda.wip_line_id
3176      AND wolv.organization_id (+) = pda.destination_organization_id
3177      AND woov.wip_entity_id = pda.wip_entity_id
3178      AND woov.organization_id = pda.destination_organization_id
3179      AND woov.operation_seq_num (+) = pda.wip_operation_seq_num
3180      AND nvl (woov.repetitive_schedule_id, -1) = nvl (pda.wip_repetitive_schedule_id, -1)
3181      AND wojv.wip_entity_name like (p_job)
3182      ORDER BY wojv.wip_entity_name;
3183      --  End of bug 9525003
3184 
3185  ELSE
3186    OPEN x_job_lov FOR
3187      SELECT wojv.wip_entity_name
3188      , wojv.wip_entity_id
3189      , wolv.line_code
3190      , woov.operation_seq_num
3191      , woov.department_code
3192      , pda.po_distribution_id
3193      , (pda.quantity_ordered - pda.quantity_delivered)
3194      , woov.repetitive_schedule_id
3195      FROM po_headers_all phl
3196      , po_lines_all pla
3197      , po_distributions_all pda
3198      , wip_osp_jobs_val_v wojv
3199      , wip_osp_lines_val_v wolv
3200      , wip_osp_operations_val_v woov
3201      WHERE phl.po_header_id = p_po_header_id
3202      AND phl.po_header_id = pla.po_header_id
3203      AND pla.po_line_id = nvl (p_po_line_id, pla.po_line_id)
3204      AND pla.item_id = nvl (p_item_id, pla.item_id)
3205      AND pla.po_line_id = pda.po_line_id
3206      AND wojv.wip_entity_id = pda.wip_entity_id
3207      AND wojv.organization_id = pda.destination_organization_id
3208      AND wojv.organization_id = p_organization_id
3209      AND wolv.line_id (+) = pda.wip_line_id
3210      AND wolv.organization_id (+) = pda.destination_organization_id
3211      AND woov.wip_entity_id = pda.wip_entity_id
3212      AND woov.organization_id = pda.destination_organization_id
3213      AND woov.operation_seq_num (+) = pda.wip_operation_seq_num
3214      AND nvl (woov.repetitive_schedule_id, -1) = nvl (pda.wip_repetitive_schedule_id, -1)
3215      AND wojv.wip_entity_name like (p_job)
3216      ORDER BY wojv.wip_entity_name;
3217  END IF;
3218 END get_job_lov;
3219 
3220 PROCEDURE GET_PO_RELEASE_ITEM_LOV(x_po_release_num_lov OUT NOCOPY t_genref,
3221           p_organization_id IN NUMBER,
3222           p_po_header_id IN NUMBER,
3223           p_mobile_form IN VARCHAR2,
3224           p_po_release_num IN VARCHAR2,
3225           p_item_id IN NUMBER)
3226   IS
3227   po_release_number VARCHAR2(20);
3228 BEGIN
3229     BEGIN
3230        /* Start - Fix for Bug# 6640083 */
3231        -- po_release_number := to_char(to_number(p_po_release_num));
3232        -- This will convert String to number - Bug#6012703
3233        -- Commented the code for  Bug#6640083
3234        SELECT TRIM(LEADING '0' FROM p_po_release_num ) INTO po_release_number FROM Dual;
3235            -- This will trim leading zeroes - Bug#6640083
3236        /* End - Fix for Bug# 6640083 */
3237      EXCEPTION
3238      WHEN OTHERS then
3239        po_release_number := p_po_release_num;
3240     END;
3241    IF p_mobile_form = 'RECEIPT' THEN
3242       OPEN x_po_release_num_lov FOR
3243         select distinct pr.release_num
3244         , pr.po_release_id
3245         , pr.release_date
3246         from po_releases_all pr
3247         , po_line_locations_all pll
3248         , po_lines_all pl
3249 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
3250         , mtl_parameters mp
3251         , rcv_parameters rp
3252 --  End for Bug 7440217
3253         where pr.po_header_id = p_po_header_id
3254         and nvl(pr.cancel_flag, 'N') = 'N'
3255         and nvl(pr.approved_flag, 'N') <> 'N'
3256         --and nvl(pr.closed_code, 'OPEN') NOT IN ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
3257         and nvl(pll.closed_code, 'OPEN') NOT IN ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED') --4350175
3258         AND pll.po_release_id = pr.po_release_id
3259         AND pll.po_header_id = pr.po_header_id
3260         AND pll.po_line_id = pl.po_line_id
3261         AND pll.po_header_id = pl.po_header_id
3262         AND ((p_item_id IS NOT NULL AND pl.item_id = p_item_id) OR
3263              p_item_id IS NULL)
3264         AND pr.release_num LIKE (po_release_number)
3265 --  For Bug 7440217 Checking if it is LCM enabled
3266         AND mp.organization_id = p_organization_id
3267         AND rp.organization_id = p_organization_id
3268         AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
3269                  OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
3270                      OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
3271              )
3272 --  End for Bug 7440217
3273                order by pr.release_num;
3274     ELSE
3275       OPEN x_po_release_num_lov FOR
3276         select distinct pr.release_num
3277         , pr.po_release_id
3278         , pr.release_date
3279         from rcv_supply rsup
3280         , po_releases_all pr
3281         where rsup.po_header_id = p_po_header_id
3282         --AND pr.org_id = p_organization_id
3283         and nvl(pr.cancel_flag, 'N') = 'N'
3284         and nvl(pr.approved_flag, 'N') <> 'N'
3285         AND rsup.po_release_id = pr.po_release_id
3286 	AND pr.release_num LIKE (po_release_number)
3287         order by pr.release_num;
3288    END IF;
3289 END GET_PO_RELEASE_ITEM_LOV;
3290 
3291 -- Start of Bug 2442518
3292 
3293 PROCEDURE GET_ITEM_LOV_RECEIVING (
3294 x_Items                               OUT NOCOPY t_genref,
3295 p_Organization_Id                     IN NUMBER,
3296 p_Concatenated_Segments               IN VARCHAR2,
3297 p_poHeaderID                          IN VARCHAR2,
3298 p_poReleaseID                         IN VARCHAR2,
3299 p_poLineID                            IN VARCHAR2,
3300 p_shipmentHeaderID                    IN VARCHAR2,
3301 p_oeOrderHeaderID                     IN VARCHAR2,
3302 p_reqHeaderID                         IN VARCHAR2,
3303 p_projectId                           IN VARCHAR2,
3304 p_taskId                              IN VARCHAR2,
3305 p_pjmorg                              IN VARCHAR2,
3306 p_crossreftype                        IN VARCHAR2,
3307 p_from_lpn_id                         IN VARCHAR2
3308 )
3309 
3310 IS
3311 -- Changes for GTIN CrossRef Type
3312 --
3313 g_gtin_cross_ref_type VARCHAR2(25) := fnd_profile.value('INV:GTIN_CROSS_REFERENCE_TYPE');
3314 g_gtin_code_length NUMBER := 14;
3315 g_crossref         VARCHAR2(40) := lpad(Rtrim(p_concatenated_segments, '%'), g_gtin_code_length, '00000000000000');
3316 l_from_lpn_id VARCHAR2(400) := p_from_lpn_id;
3317 l_append varchar2(2):='';
3318 
3319 BEGIN
3320 
3321 l_append:=wms_deploy.get_item_suffix_for_lov(p_Concatenated_Segments);
3322 
3323 print_debug('p_Organization_Id :'||p_Organization_Id,4);
3324 print_debug('p_Concatenated_Segments :'||p_Concatenated_Segments,4);
3325 print_debug('p_poHeaderID :'||p_poHeaderID,4);
3326 print_debug('p_poReleaseID :'||p_poReleaseID,4);
3327 print_debug('p_poLineID :'||p_poLineID,4);
3328 print_debug('p_shipmentHeaderID :'||p_shipmentHeaderID,4);
3329 print_debug('p_oeOrderHeaderID :'||p_oeOrderHeaderID,4);
3330 print_debug('p_reqHeaderID :'||p_reqHeaderID,4);
3331 print_debug('p_projectId :'||p_projectId,4);
3332 print_debug('p_taskId :'||p_taskId,4);
3333 print_debug('p_pjmorg :'||p_pjmorg,4);
3334 print_debug('p_crossreftype :'||p_crossreftype,4);
3335 print_debug('p_from_lpn_id :'||p_from_lpn_id,4);
3336 print_debug('l_append :'||l_append,4);
3337 
3338 -- if  ( ( p_doctype = 'PO') or  (p_doctype = 'RMA') or (p_doctype = 'REQ') or (p_doctype = 'SHIP') )
3339 -- then
3340 
3341 -- CLM Project, change PO tables to PO views
3342 
3343 if  (p_poHeaderID is not null       or
3344      p_poReleaseID is not null      or
3345      p_oeOrderHeaderID is not null  or
3346      p_shipmentHeaderID is not null or
3347      p_reqHeaderID is not null      or
3348      p_projectId is not null        or
3349      p_taskId is not null )
3350 then
3351 
3352 IF (p_from_lpn_id IS NULL) THEN
3353   l_from_lpn_id := NULL;
3354 ELSIF (p_from_lpn_id IS NOT NULL AND p_from_lpn_id = '0') THEN
3355   l_from_lpn_id := NULL;
3356 END IF;
3357 
3358 -- *****************************
3359 ---- Case for Document Info already entered in the session , txn starts with document ID
3360 -- *****************************
3361 
3362 if (p_poHeaderID is not null ) then
3363 -- *****************************
3364 --- START  OF PO HEADER  ID SECTION
3365 -- *****************************
3366 
3367   if  ( p_pjmorg = 1) then --and ( p_projectId is not null ) )  then
3368 
3369 -- *****************************
3370 ---- Start of  PJM BASED Tran.
3371 -- *****************************
3372 
3373       if (p_poReleaseID is not null) then
3374 -- *****************************
3375 --- releaseBased  PJM Transaction
3376 -- *****************************
3377          open x_items for
3378          -- Bug# 6747729
3379          -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
3380          select concatenated_segments,
3381          inventory_item_id,
3382          description,
3383          Nvl(revision_qty_control_code,1),
3384          Nvl(lot_control_code, 1),
3385          Nvl(serial_number_control_code, 1),
3386          Nvl(restrict_subinventories_code, 2),
3387          Nvl(restrict_locators_code, 2),
3388          Nvl(location_control_code, 1),
3389          primary_uom_code,
3390          Nvl(inspection_required_flag, 'N'),
3391          Nvl(shelf_life_code, 1),
3392          Nvl(shelf_life_days,0),
3393          Nvl(allowed_units_lookup_code, 2),
3394          Nvl(effectivity_control,1),
3395          0,
3396          0,
3397          Nvl(default_serial_status_id,1),
3398          Nvl(serial_status_enabled,'N'),
3399          Nvl(default_lot_status_id,0),
3400          Nvl(lot_status_enabled,'N'),
3401          '',
3402          'N',
3403          inventory_item_flag,
3404          0,
3405 	   wms_deploy.get_item_client_name(inventory_item_id),
3406          inventory_asset_flag,
3407          outside_operation_flag,
3408          --Bug 3952081
3409          --Select DUOM Attributes for every Item
3410          NVL(GRADE_CONTROL_FLAG,'N'),
3411          NVL(DEFAULT_GRADE,''),
3412          NVL(EXPIRATION_ACTION_INTERVAL,0),
3413          NVL(EXPIRATION_ACTION_CODE,''),
3414          NVL(HOLD_DAYS,0),
3415          NVL(MATURITY_DAYS,0),
3416          NVL(RETEST_INTERVAL,0),
3417          NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
3418          NVL(CHILD_LOT_FLAG,'N'),
3419          NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
3420          NVL(LOT_DIVISIBLE_FLAG,'Y'),
3421          NVL(SECONDARY_UOM_CODE,''),
3422          NVL(SECONDARY_DEFAULT_IND,''),
3423          NVL(TRACKING_QUANTITY_IND,'P'),
3424          NVL(DUAL_UOM_DEVIATION_HIGH,0),
3425          NVL(DUAL_UOM_DEVIATION_LOW,0),
3426          stock_enabled_flag,
3427          ' ',
3428          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
3429          from mtl_system_items_vl, /* Bug 5581528 */
3430 		 po_lines_all pol    -- Bug 14645109 s added
3431          WHERE organization_id = p_Organization_Id
3432          and concatenated_segments like p_concatenated_segments||l_append
3433          and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
3434          and inventory_item_id = pol.item_id   -- Bug 14645109 s change this
3435          and  pol.po_header_id =   p_poHeaderID  -- Bug 14645109 s change this
3436 
3437          and exists (select 1
3438                        from po_line_locations_trx_v pll  -- CLM project, bug 9403291
3439 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
3440                           , mtl_parameters mp,
3441                             rcv_parameters rp
3442 --  End for Bug 7440217
3443                      WHERE NVL(pll.closed_code,'OPEN')
3444                      not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')
3445                      and pll.po_header_id = p_poHeaderID
3446                      and pll.po_release_id = p_poReleaseID
3447                      and pll.po_line_id = pol.po_line_id
3448                      and pll.ship_to_organization_id = p_Organization_Id
3449 --  For Bug 7440217 Checking if it is LCM enabled
3450                      AND mp.organization_id = p_Organization_Id
3451                      AND rp.organization_id = p_Organization_Id
3452                      AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
3453                               OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
3454                                   OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
3455                          )
3456 --  End for Bug 7440217
3457                     )--Bug 3972931-Added the filter condition based on ship_to_organization_id
3458          and  exists (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
3459          where pd.po_header_id =  p_poHeaderID
3460          and pd.po_line_id = pol.po_line_id
3461          and pd.po_release_id = p_poReleaseID
3462          and ((p_projectId is null or pd.project_id = p_projectId)
3463                and (p_taskId is null or pd.task_id = p_taskId)
3464              )
3465         )
3466        -- Bug 14645109 s remove this )
3467         UNION ALL
3468         -- Substitute Item SQL
3469         -- Bug# 6747729
3470         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
3471         select distinct msi.concatenated_segments,
3472         msi.inventory_item_id,
3473 		Nvl(pol.item_description, msi.description), -- Bug 14645109
3474         Nvl(msi.revision_qty_control_code,1),
3475         Nvl(msi.lot_control_code, 1),
3476         Nvl(msi.serial_number_control_code, 1),
3477         Nvl(msi.restrict_subinventories_code, 2),
3478         Nvl(msi.restrict_locators_code,2),
3479         Nvl(msi.location_control_code,1),
3480         msi.primary_uom_code,
3481         Nvl(msi.inspection_required_flag,'N'),
3482         Nvl(msi.shelf_life_code, 1),
3483         Nvl(msi.shelf_life_days,0),
3484         Nvl(msi.allowed_units_lookup_code, 2),
3485         Nvl(msi.effectivity_control,1),
3486         0,
3487         0,
3488         Nvl(msi.default_serial_status_id,1),
3489         Nvl(msi.serial_status_enabled,'N'),
3490         Nvl(msi.default_lot_status_id,0),
3491         Nvl(msi.lot_status_enabled,'N'),
3492         msi.concatenated_segments,
3493         'S',
3494         msi.inventory_item_flag,
3495         0,
3496 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
3497         msi.inventory_asset_flag,
3498         msi.outside_operation_flag,
3499          --Bug 3952081
3500          --Select DUOM Attributes for every Item
3501          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
3502          NVL(MSI.DEFAULT_GRADE,''),
3503          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
3504          NVL(MSI.EXPIRATION_ACTION_CODE,''),
3505          NVL(MSI.HOLD_DAYS,0),
3506          NVL(MSI.MATURITY_DAYS,0),
3507          NVL(MSI.RETEST_INTERVAL,0),
3508          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
3509          NVL(MSI.CHILD_LOT_FLAG,'N'),
3510          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
3511          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
3512          NVL(MSI.SECONDARY_UOM_CODE,''),
3513          NVL(MSI.SECONDARY_DEFAULT_IND,''),
3514          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
3515          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
3516          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
3517          msi.stock_enabled_flag,
3518          ' ',
3519          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
3520         from po_lines_trx_v pol  -- CLM project, bug 9403291
3521         ,mtl_related_items mri
3522         ,mtl_system_items_vl msi /* Bug 5581528 */
3523         /*,mtl_system_items_kfv msia */ /* Bug 6334679*/
3524         where msi.organization_id =  p_organization_id
3525         and msi.concatenated_segments like  p_concatenated_segments||l_append
3526         and pol.po_header_id = p_poHeaderID
3527         and pol.item_id = mri.inventory_item_id /* Condition changed by Bug10124916 */
3528         and msi.organization_id = p_organization_id
3529         and ((    mri.related_item_id = msi.inventory_item_id
3530         and pol.item_id = mri.inventory_item_id) or
3531          (    mri.inventory_item_id = msi.inventory_item_id
3532          and pol.item_id = mri.related_item_id
3533          and mri.reciprocal_flag = 'Y'))
3534          and exists (select 1
3535                       from  po_line_locations_trx_v pll -- CLM project, bug 9403291
3536 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
3537                          , mtl_parameters mp,
3538                            rcv_parameters rp
3539 --  End for Bug 7440217
3540                            where NVL(pll.closed_code,'OPEN')
3541                            not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')
3542                            and   Nvl(pll.allow_substitute_receipts_flag, 'N') = 'Y'
3543                            and   pll.po_header_id = pol.po_header_id
3544                            and   pll.po_line_id = pol.po_line_id
3545                            and   pll.po_release_id = p_poReleaseID
3546                            and   pll.ship_to_organization_id = p_Organization_Id
3547 --  For Bug 7440217 Checking if it is LCM enabled
3548                            AND   mp.organization_id = p_Organization_Id
3549                            AND   rp.organization_id = p_Organization_Id
3550                            AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
3551                                     OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
3552                                         OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
3553                                )
3554 --  End for Bug 7440217
3555                      )--Bug 3972931-Added the filter condition based on ship_to_organization_id
3556         and  exists (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
3557         where pd.po_header_id =  p_poHeaderID
3558         and pd.po_line_id = pol.po_line_id
3559         and pd.po_release_id = p_poReleaseID
3560         and ((p_projectId is null or pd.project_id = p_projectId)
3561                and (p_taskId is null or pd.task_id = p_taskId)
3562              )
3563         )
3564         UNION ALL
3565         -- Vendor Item SQL
3566         -- Bug# 6747729
3567         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
3568         select distinct pol.vendor_product_num,
3569         msi.inventory_item_id,
3570         Nvl(pol.item_description, msi.description) ,  -- Bug 14645109
3571         Nvl(msi.revision_qty_control_code,1),
3572         Nvl(msi.lot_control_code, 1),
3573         Nvl(msi.serial_number_control_code, 1),
3574         Nvl(msi.restrict_subinventories_code, 2),
3575         Nvl(msi.restrict_locators_code,2),
3576         Nvl(msi.location_control_code,1),
3577         msi.primary_uom_code,
3578         Nvl(msi.inspection_required_flag,'N'),
3579         Nvl(msi.shelf_life_code, 1),
3580         Nvl(msi.shelf_life_days,0),
3581         Nvl(msi.allowed_units_lookup_code, 2),
3582         Nvl(msi.effectivity_control,1),
3583         0,
3584         0,
3585         Nvl(msi.default_serial_status_id,1),
3586         Nvl(msi.serial_status_enabled,'N'),
3587         Nvl(msi.default_lot_status_id,0),
3588         Nvl(msi.lot_status_enabled,'N'),
3589         msi.concatenated_segments,
3590         'Y',
3591         msi.inventory_item_flag,
3592         0,
3593 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
3594         msi.inventory_asset_flag,
3595         msi.outside_operation_flag,
3596          --Bug 3952081
3597          --Select DUOM Attributes for every Item
3598          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
3599          NVL(MSI.DEFAULT_GRADE,''),
3600          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
3601          NVL(MSI.EXPIRATION_ACTION_CODE,''),
3602          NVL(MSI.HOLD_DAYS,0),
3603          NVL(MSI.MATURITY_DAYS,0),
3604          NVL(MSI.RETEST_INTERVAL,0),
3605          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
3606          NVL(MSI.CHILD_LOT_FLAG,'N'),
3607          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
3608          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
3609          NVL(MSI.SECONDARY_UOM_CODE,''),
3610          NVL(MSI.SECONDARY_DEFAULT_IND,''),
3611          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
3612          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
3613          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
3614          msi.stock_enabled_flag,
3615          ' ',
3616          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
3617         from po_lines_trx_v pol -- CLM project, bug 9403291
3618         , mtl_system_items_vl msi   /* Bug 5581528 */
3619         where organization_id =  p_organization_id
3620         and pol.vendor_product_num like  p_concatenated_segments
3621         and pol.item_id = msi.inventory_item_id
3622         and  pol.vendor_product_num IS NOT NULL
3623         and pol.po_header_id =  p_poHeaderID
3624         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
3625         and inventory_item_id IN (SELECT pol.item_id FROM po_lines_trx_v pol
3626         where pol.po_header_id =   p_poHeaderID
3627         and exists (select 1
3628                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
3629 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
3630                          , mtl_parameters mp,
3631                            rcv_parameters rp
3632 --  End for Bug 7440217
3633                      WHERE NVL(pll.closed_code,'OPEN')
3634                      not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')
3635                      and  pll.po_header_id = p_poHeaderID
3636                      and pll.po_release_id = p_poReleaseID
3637                      and pll.po_line_id = pol.po_line_id
3638                      and pll.ship_to_organization_id = p_Organization_Id
3639 --  For Bug 7440217 Checking if it is LCM enabled
3640                      AND mp.organization_id = p_Organization_Id
3641                      AND rp.organization_id = p_Organization_Id
3642                      AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
3643                               OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
3644                                   OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
3645                         )
3646 --  End for Bug 7440217
3647         )--Bug 3972931-Added the filter condition based on ship_to_organization_id
3648         and  exists (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
3649         where pd.po_header_id =  p_poHeaderID
3650         and pd.po_line_id = pol.po_line_id
3651         and pd.po_release_id = p_poReleaseID
3652         and ((p_projectId is null or pd.project_id = p_projectId)
3653                and (p_taskId is null or pd.task_id = p_taskId)
3654              )
3655         )
3656         )
3657         UNION ALL
3658         -- non item Master
3659         -- Bug# 6747729
3660         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
3661         select distinct pol.item_description,
3662         to_number(''),
3663         pol.item_description,
3664         1,
3665         1,
3666         1,
3667         2,
3668         2,
3669         1,
3670         mum.uom_code,
3671         'N',
3672         1,
3673         0,
3674         2,
3675         1,
3676         0,
3677         0,
3678         1,
3679         'N',
3680         0,
3681         'N',
3682         '',
3683         'N',
3684         'N',
3685         0,
3686 	  wms_deploy.get_item_client_name(pol.item_id),
3687         to_char(NULL),
3688         'N' ,
3689          --Bug 3952081
3690          --Select DUOM Attributes for every Item
3691          'N',
3692          '',
3693          0,
3694          '',
3695          0,
3696          0,
3697          0,
3698          'N',
3699          'N',
3700          'N',
3701          'Y',
3702          '',
3703          '',
3704          'P',
3705          0,
3706          0,
3707         'N',
3708          ' ',
3709          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
3710         from po_lines_trx_v pol -- CLM project, bug 9403291
3711         , mtl_units_of_measure mum
3712   -- Bug 2619063, 2614016
3713   -- Modified to select the base uom for the uom class defined on po.
3714   where mum.uom_class = (SELECT mum2.uom_class
3715                FROM mtl_units_of_measure mum2
3716               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
3717         and mum.base_uom_flag = 'Y'
3718         and pol.ITEM_ID is null
3719         and pol.item_description is not null
3720         and pol.po_header_id = p_poHeaderID
3721         and pol.item_description like  p_concatenated_segments
3722         and  exists (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
3723         where pd.po_header_id =  p_poHeaderID
3724         and pd.po_line_id = pol.po_line_id
3725         and pd.po_release_id = p_poReleaseID
3726         and ((p_projectId is null or pd.project_id = p_projectId)
3727                and (p_taskId is null or pd.task_id = p_taskId)
3728              )
3729         )
3730   /* Bug 3972931-Added the following exists condition to restrict the PO receipt
3731   to shipments due to be received only in the organizationientered with.*/
3732         and exists (select 1
3733                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
3734 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
3735                          , mtl_parameters mp,
3736                            rcv_parameters rp
3737 --  End for Bug 7440217
3738                      where pll.po_header_id = p_poHeaderID
3739                       and pll.po_line_id = pol.po_line_id
3740 					  and pll.po_release_id = p_poReleaseID
3741                       and pll.ship_to_organization_id = p_Organization_Id
3742 --  For Bug 7440217 Checking if it is LCM enabled
3743                       AND mp.organization_id = p_Organization_Id
3744                       AND rp.organization_id = p_Organization_Id
3745                       AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
3746                                OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
3747                                    OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
3748                            )
3749 --  End for Bug 7440217
3750                       )
3751   --End of fix for Bug 3972931
3752         UNION ALL
3753         -- Cross Ref  SQL
3754         -- Bug# 6747729
3755         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
3756         select distinct mcr.cross_reference,
3757         msi.inventory_item_id,
3758         msi.description,
3759         Nvl(msi.revision_qty_control_code,1),
3760         Nvl(msi.lot_control_code, 1),
3761         Nvl(msi.serial_number_control_code, 1),
3762         Nvl(msi.restrict_subinventories_code, 2),
3763         Nvl(msi.restrict_locators_code,2),
3764         Nvl(msi.location_control_code,1),
3765         msi.primary_uom_code,
3766         Nvl(msi.inspection_required_flag,'N'),
3767         Nvl(msi.shelf_life_code, 1),
3768         Nvl(msi.shelf_life_days,0),
3769         Nvl(msi.allowed_units_lookup_code, 2),
3770         Nvl(msi.effectivity_control,1),
3771         0,
3772         0,
3773         Nvl(msi.default_serial_status_id,1),
3774         Nvl(msi.serial_status_enabled,'N'),
3775         Nvl(msi.default_lot_status_id,0),
3776         Nvl(msi.lot_status_enabled,'N'),
3777         msi.concatenated_segments,
3778         'C',
3779         msi.inventory_item_flag,
3780         0,
3781 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
3782         msi.inventory_asset_flag,
3783         msi.outside_operation_flag,
3784          --Bug 3952081
3785          --Select DUOM Attributes for every Item
3786          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
3787          NVL(MSI.DEFAULT_GRADE,''),
3788          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
3789          NVL(MSI.EXPIRATION_ACTION_CODE,''),
3790          NVL(MSI.HOLD_DAYS,0),
3791          NVL(MSI.MATURITY_DAYS,0),
3792          NVL(MSI.RETEST_INTERVAL,0),
3793          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
3794          NVL(MSI.CHILD_LOT_FLAG,'N'),
3795          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
3796          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
3797          NVL(MSI.SECONDARY_UOM_CODE,''),
3798          NVL(MSI.SECONDARY_DEFAULT_IND,''),
3799          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
3800          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
3801          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
3802          msi.stock_enabled_flag,
3803          ' ',
3804          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
3805         from po_lines_trx_v pol -- CLM project, bug 9403291
3806         ,mtl_system_items_vl msi /* Bug 5581528 */
3807         ,mtl_cross_references mcr
3808         where msi.organization_id = p_organization_id
3809         and ( (mcr.cross_reference_type = p_crossreftype
3810                and mcr.cross_reference like  p_concatenated_segments
3811               ) or
3812               ( mcr.cross_reference_type = g_gtin_cross_ref_type
3813                AND mcr.cross_reference      LIKE g_crossref )
3814             )
3815         and ( (mcr.org_independent_flag = 'Y') or (mcr.org_independent_flag = 'N'
3816         and mcr.organization_id = p_organization_id
3817                ) )
3818         and mcr.inventory_item_id = msi.inventory_item_id
3819         and pol.item_id = msi.inventory_item_id
3820         and pol.po_header_id = p_poHeaderID
3821         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
3822         and msi.inventory_item_id IN (SELECT pol.item_id FROM po_lines_trx_v pol  -- CLM project, bug 9403291
3823         where pol.po_header_id =   p_poHeaderID
3824         and exists (select 1
3825                       from po_line_locations_trx_v pll --CLM project, bug 9403291
3826 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
3827                          , mtl_parameters mp,
3828                            rcv_parameters rp
3829 --  End for Bug 7440217
3830                      WHERE NVL(pll.closed_code,'OPEN')
3831                      not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')
3832                      and pll.po_header_id = p_poHeaderID
3833                      and pll.po_release_id = p_poReleaseID
3834                      and pll.po_line_id = pol.po_line_id
3835                      and pll.ship_to_organization_id = p_Organization_Id
3836 --  For Bug 7440217 Checking if it is LCM enabled
3837                      AND mp.organization_id = p_Organization_Id
3838                      AND rp.organization_id = p_Organization_Id
3839                      AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
3840                               OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
3841                                   OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
3842                           )
3843 --  End for Bug 7440217
3844                     )--Bug 3972931-Added the filter condition based on ship_to_organization_id
3845         and  exists (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
3846         where pd.po_header_id = p_poHeaderID
3847         and pd.po_line_id = pol.po_line_id
3848         and pd.po_release_id = p_poReleaseID
3849         and ((p_projectId is null or pd.project_id = p_projectId)
3850                and (p_taskId is null or pd.task_id = p_taskId)
3851              )
3852         )
3853         )
3854 /* Bug 12348588 When use mobile to receive PO, item lov not display supplier item for one time item.
3855                That is because there is no record in item table: mtl_system_items_vl when the item is one time item.
3856 			   Now, we do not join the item table when the item id is null in the po lines table.*/
3857 
3858 		UNION ALL
3859 		select distinct pol.vendor_product_num,
3860         to_number(''),
3861         pol.item_description,
3862         1,
3863         1,
3864         1,
3865         2,
3866         2,
3867         1,
3868         mum.uom_code,
3869         'N',
3870         1,
3871         0,
3872         2,
3873         1,
3874         0,
3875         0,
3876         1,
3877         'N',
3878         0,
3879         'N',
3880         pol.item_description,
3881         'Y',
3882         'N',
3883         0,
3884 	  wms_deploy.get_item_client_name(pol.item_id),
3885         to_char(NULL),
3886         'N' ,
3887          --Bug 3952081
3888          --Select DUOM Attributes for every Item
3889          'N',
3890          '',
3891          0,
3892          '',
3893          0,
3894          0,
3895          0,
3896          'N',
3897          'N',
3898          'N',
3899          'Y',
3900          '',
3901          '',
3902          'P',
3903          0,
3904          0,
3905         'N',
3906          ' ',
3907          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
3908         from po_lines_trx_v pol -- CLM project, bug 9403291
3909         , mtl_units_of_measure mum
3910   -- Bug 2619063, 2614016
3911   -- Modified to select the base uom for the uom class defined on po.
3912   where mum.uom_class = (SELECT mum2.uom_class
3913                FROM mtl_units_of_measure mum2
3914               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
3915         and mum.base_uom_flag = 'Y'
3916         and pol.ITEM_ID is null
3917         and pol.vendor_product_num is not null
3918         and pol.po_header_id = p_poHeaderID
3919         and pol.vendor_product_num like  p_concatenated_segments
3920         and  exists (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
3921         where pd.po_header_id =  p_poHeaderID
3922         and pd.po_line_id = pol.po_line_id
3923         and pd.po_release_id = p_poReleaseID
3924         and ((p_projectId is null or pd.project_id = p_projectId)
3925                and (p_taskId is null or pd.task_id = p_taskId)
3926              )
3927         )
3928         /* Bug 3972931-Added the following exists condition to restrict the PO receipt
3929         to shipments due to be received only in the organizationientered with.*/
3930         and exists (select 1
3931                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
3932 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
3933                          , mtl_parameters mp,
3934                            rcv_parameters rp
3935 --  End for Bug 7440217
3936                      where pll.po_header_id = p_poHeaderID
3937 --  For Bug 7440217 Checking if it is LCM enabled
3938                        AND mp.organization_id = p_organization_id
3939                        AND rp.organization_id = p_organization_id
3940                        AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
3941                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
3942                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
3943                         )
3944 --  End for Bug 7440217
3945 					   and pll.po_release_id = p_poReleaseID
3946                        and pll.po_line_id = pol.po_line_id
3947                        and pll.ship_to_organization_id = p_Organization_Id)
3948     /* End of fix for Bug 12348588 */
3949         ;
3950       elsif  (p_poLineID IS NOT NULL) then
3951 -- *****************************
3952 ----- lineBased PJM Transaction
3953 -- *****************************
3954         open x_items for
3955         -- Bug# 6747729
3956         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
3957         select concatenated_segments,
3958         inventory_item_id,
3959         description,
3960         Nvl(revision_qty_control_code,1),
3961         Nvl(lot_control_code, 1),
3962         Nvl(serial_number_control_code, 1),
3963         Nvl(restrict_subinventories_code, 2),
3964         Nvl(restrict_locators_code, 2),
3965         Nvl(location_control_code, 1),
3966         primary_uom_code,
3967         Nvl(inspection_required_flag, 'N'),
3968         Nvl(shelf_life_code, 1),
3969         Nvl(shelf_life_days,0),
3970         Nvl(allowed_units_lookup_code, 2),
3971         Nvl(effectivity_control,1),
3972         0,
3973         0,
3974         Nvl(default_serial_status_id,1),
3975         Nvl(serial_status_enabled,'N'),
3976         Nvl(default_lot_status_id,0),
3977         Nvl(lot_status_enabled,'N'),
3978         '',
3979         'N',
3980         inventory_item_flag,
3981         0,
3982 	  wms_deploy.get_item_client_name(inventory_item_id),
3983         inventory_asset_flag,
3984         outside_operation_flag,
3985          --Bug 3952081
3986          --Select DUOM Attributes for every Item
3987          NVL(GRADE_CONTROL_FLAG,'N'),
3988          NVL(DEFAULT_GRADE,''),
3989          NVL(EXPIRATION_ACTION_INTERVAL,0),
3990          NVL(EXPIRATION_ACTION_CODE,''),
3991          NVL(HOLD_DAYS,0),
3992          NVL(MATURITY_DAYS,0),
3993          NVL(RETEST_INTERVAL,0),
3994          NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
3995          NVL(CHILD_LOT_FLAG,'N'),
3996          NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
3997          NVL(LOT_DIVISIBLE_FLAG,'Y'),
3998          NVL(SECONDARY_UOM_CODE,''),
3999          NVL(SECONDARY_DEFAULT_IND,''),
4000          NVL(TRACKING_QUANTITY_IND,'P'),
4001          NVL(DUAL_UOM_DEVIATION_HIGH,0),
4002          NVL(DUAL_UOM_DEVIATION_LOW,0),
4003         stock_enabled_flag,
4004          ' ',
4005          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
4006         from mtl_system_items_vl, /* Bug 5581528 */
4007 		po_lines_all pol   -- Bug 14645109 s added
4008         WHERE organization_id = p_Organization_Id
4009         and concatenated_segments like p_concatenated_segments||l_append
4010         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
4011 		 -- CLM project, bug 9403291
4012 		and inventory_item_id = pol.item_id  -- Bug 14645109 change this
4013         and pol.po_header_id = p_poHeaderID  -- Bug 14645109 change this
4014 
4015 
4016         and pol.po_line_id = p_poLineID
4017         and exists (select 1
4018                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
4019 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
4020                          , mtl_parameters mp,
4021                            rcv_parameters rp
4022 --  End for Bug 7440217
4023                      where NVL(pll.closed_code, 'OPEN')
4024                      not in ('FINALLY CLOSED' , 'CLOSED FOR RECEIVING', 'CLOSED' )
4025                      and  pll.po_header_id = p_poHeaderID
4026                      and pll.po_line_id = p_poLineID
4027                      and pll.ship_to_organization_id = p_Organization_Id
4028 --  For Bug 7440217 Checking if it is LCM enabled
4029                      AND mp.organization_id = p_Organization_Id
4030                      AND rp.organization_id = p_Organization_Id
4031                      AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
4032                               OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
4033                                   OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
4034                           )
4035 --  End for Bug 7440217
4036                    )--Bug 3972931-Added the filter condition based on ship_to_organization_id
4037   and  exists (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
4038         where pd.po_header_id =  p_poHeaderID
4039         and pd.po_line_id = p_poLineID
4040         and pd.po_line_id = pol.po_line_id
4041         and ((p_projectId is null or pd.project_id = p_projectId)
4042                and (p_taskId is null or pd.task_id = p_taskId)
4043              )
4044         )
4045       -- Bug 14645109 s remove this  )
4046         UNION ALL
4047         -- Substitute Item SQL
4048         -- Bug# 6747729
4049         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
4050         select distinct msi.concatenated_segments,
4051         msi.inventory_item_id,
4052         msi.description,
4053         Nvl(msi.revision_qty_control_code,1),
4054         Nvl(msi.lot_control_code, 1),
4055         Nvl(msi.serial_number_control_code, 1),
4056         Nvl(msi.restrict_subinventories_code, 2),
4057         Nvl(msi.restrict_locators_code,2),
4058         Nvl(msi.location_control_code,1),
4059         msi.primary_uom_code,
4060         Nvl(msi.inspection_required_flag,'N'),
4061         Nvl(msi.shelf_life_code, 1),
4062         Nvl(msi.shelf_life_days,0),
4063         Nvl(msi.allowed_units_lookup_code, 2),
4064         Nvl(msi.effectivity_control,1),
4065         0,
4066         0,
4067         Nvl(msi.default_serial_status_id,1),
4068         Nvl(msi.serial_status_enabled,'N'),
4069         Nvl(msi.default_lot_status_id,0),
4070         Nvl(msi.lot_status_enabled,'N'),
4071         msi.concatenated_segments,
4072         'S',
4073         msi.inventory_item_flag,
4074         0,
4075 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
4076         msi.inventory_asset_flag,
4077         msi.outside_operation_flag ,
4078          --Bug 3952081
4079          --Select DUOM Attributes for every Item
4080          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
4081          NVL(MSI.DEFAULT_GRADE,''),
4082          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
4083          NVL(MSI.EXPIRATION_ACTION_CODE,''),
4084          NVL(MSI.HOLD_DAYS,0),
4085          NVL(MSI.MATURITY_DAYS,0),
4086          NVL(MSI.RETEST_INTERVAL,0),
4087          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
4088          NVL(MSI.CHILD_LOT_FLAG,'N'),
4089          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
4090          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
4091          NVL(MSI.SECONDARY_UOM_CODE,''),
4092          NVL(MSI.SECONDARY_DEFAULT_IND,''),
4093          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
4094          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
4095          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
4096         msi.stock_enabled_flag,
4097          ' ',
4098          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
4099         from po_lines_trx_v pol -- CLM project, bug 9403291
4100         ,mtl_related_items mri
4101        ,mtl_system_items_vl msi /* Bug 5581528 */
4102        /*,mtl_system_items_kfv msia */ /* Bug 6334679 */
4103         where msi.organization_id =  p_organization_id
4104         and msi.concatenated_segments like  p_concatenated_segments||l_append
4105         and pol.po_header_id = p_poHeaderID
4106         and pol.item_id = mri.inventory_item_id
4107         and msi.organization_id = p_organization_id
4108         and ((    mri.related_item_id = msi.inventory_item_id
4109         and pol.item_id = mri.inventory_item_id) or
4110          (    mri.inventory_item_id = msi.inventory_item_id
4111          and pol.item_id = mri.related_item_id
4112          and mri.reciprocal_flag = 'Y'))
4113          and pol.po_line_id = p_poLineID
4114          and exists (select 1
4115                       from  po_line_locations_trx_v pll -- CLM project, bug 9403291
4116 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
4117                           , mtl_parameters mp,
4118                             rcv_parameters rp
4119 --  End for Bug 7440217
4120                       where NVL(pll.closed_code,'OPEN')
4121                       not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED') -- 3687249
4122                       and   Nvl(pll.allow_substitute_receipts_flag, 'N') = 'Y'
4123                       and   pll.po_header_id = pol.po_header_id
4124                       and   pll.po_line_id = pol.po_line_id
4125                       and pll.ship_to_organization_id = p_Organization_Id
4126 --  For Bug 7440217 Checking if it is LCM enabled
4127                       AND mp.organization_id = p_Organization_Id
4128                       AND rp.organization_id = p_Organization_Id
4129                       AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
4130                                OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
4131                                    OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
4132                          )
4133 --  End for Bug 7440217
4134                      )--Bug 3972931-Added the filter condition based on ship_to_organization_id
4135         and  exists ( select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
4136         where pd.po_header_id =  p_poHeaderID
4137         and pd.po_line_id = p_poLineID
4138         and pd.po_line_id = pol.po_line_id
4139         and ((p_projectId is null or pd.project_id = p_projectId)
4140                and (p_taskId is null or pd.task_id = p_taskId)
4141              )
4142         )
4143         UNION ALL
4144         -- Vendor Item SQL
4145         -- Bug# 6747729
4146         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
4147         select distinct pol.vendor_product_num,
4148         msi.inventory_item_id,
4149         Nvl(pol.item_description, msi.description) ,  -- Bug 14645109 change this
4150         Nvl(msi.revision_qty_control_code,1),
4151         Nvl(msi.lot_control_code, 1),
4152         Nvl(msi.serial_number_control_code, 1),
4153         Nvl(msi.restrict_subinventories_code, 2),
4154         Nvl(msi.restrict_locators_code,2),
4155         Nvl(msi.location_control_code,1),
4156         msi.primary_uom_code,
4157         Nvl(msi.inspection_required_flag,'N'),
4158         Nvl(msi.shelf_life_code, 1),
4159         Nvl(msi.shelf_life_days,0),
4160         Nvl(msi.allowed_units_lookup_code, 2),
4161         Nvl(msi.effectivity_control,1),
4162         0,
4163         0,
4164         Nvl(msi.default_serial_status_id,1),
4165         Nvl(msi.serial_status_enabled,'N'),
4166         Nvl(msi.default_lot_status_id,0),
4167         Nvl(msi.lot_status_enabled,'N'),
4168         msi.concatenated_segments,
4169         'Y',
4170         msi.inventory_item_flag,
4171         0,
4172 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
4173         msi.inventory_asset_flag,
4174         msi.outside_operation_flag ,
4175          --Bug 3952081
4176          --Select DUOM Attributes for every Item
4177          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
4178          NVL(MSI.DEFAULT_GRADE,''),
4179          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
4180          NVL(MSI.EXPIRATION_ACTION_CODE,''),
4181          NVL(MSI.HOLD_DAYS,0),
4182          NVL(MSI.MATURITY_DAYS,0),
4183          NVL(MSI.RETEST_INTERVAL,0),
4184          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
4185          NVL(MSI.CHILD_LOT_FLAG,'N'),
4186          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
4187          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
4188          NVL(MSI.SECONDARY_UOM_CODE,''),
4189          NVL(MSI.SECONDARY_DEFAULT_IND,''),
4190          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
4191          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
4192          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
4193         msi.stock_enabled_flag,
4194          ' ',
4195          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
4196         from po_lines_trx_v pol -- CLM project, bug 9403291
4197         , mtl_system_items_vl msi  /* Bug 5581528 */
4198         where organization_id =  p_organization_id
4199         and pol.vendor_product_num like  p_concatenated_segments
4200         and pol.item_id = msi.inventory_item_id
4201         and  pol.vendor_product_num IS NOT NULL
4202         and pol.po_header_id =  p_poHeaderID
4203         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
4204         and inventory_item_id IN (SELECT pl.item_id FROM po_lines_trx_v pl -- CLM project, bug 9403291
4205         WHERE pl.po_header_id = p_poHeaderID
4206         and pl.po_line_id = p_poLineID
4207         and exists (select 1
4208                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
4209 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
4210                          , mtl_parameters mp,
4211                            rcv_parameters rp
4212 --  End for Bug 7440217
4213                      where NVL(pll.closed_code, 'OPEN')
4214                      not in ('FINALLY CLOSED' , 'CLOSED FOR RECEIVING' , 'CLOSED') -- 3687249
4215                      and  pll.po_header_id = p_poHeaderID
4216                      and pll.po_line_id = p_poLineID
4217                      and pll.ship_to_organization_id = p_Organization_Id
4218 --  For Bug 7440217 Checking if it is LCM enabled
4219                      AND mp.organization_id = p_Organization_Id
4220                      AND rp.organization_id = p_Organization_Id
4221                      AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
4222                               OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
4223                                   OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
4224                         )
4225 --  End for Bug 7440217
4226                     )--Bug 3972931-Added the filter condition based on ship_to_organization_id
4227         and  exists (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
4228         where pd.po_header_id =  p_poHeaderID
4229         and pd.po_line_id = pol.po_line_id
4230         and pd.po_line_id = p_poLineID
4231         and ((p_projectId is null or pd.project_id = p_projectId)
4232                and (p_taskId is null or pd.task_id = p_taskId)
4233              )
4234         )
4235         )
4236         UNION ALL
4237         -- non item Master
4238         -- Bug# 6747729
4239         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
4240         select distinct pol.item_description,
4241         to_number(''),
4242         pol.item_description,
4243         1,
4244         1,
4245         1,
4246         2,
4247         2,
4248         1,
4249         mum.uom_code,
4250         'N',
4251         1,
4252         0,
4253         2,
4254         1,
4255         0,
4256         0,
4257         1,
4258         'N',
4259         0,
4260         'N',
4261         '',
4262         'N',
4263         'N',
4264         0,
4265 	  wms_deploy.get_item_client_name(pol.item_id),
4266         to_char(NULL),
4267         'N' ,
4268          --Bug 3952081
4269          --Select DUOM Attributes for every Item
4270          'N',
4271          '',
4272          0,
4273          '',
4274          0,
4275          0,
4276          0,
4277          'N',
4278          'N',
4279          'N',
4280          'Y',
4281          '',
4282          '',
4283          'P',
4284          0,
4285          0,
4286         'N',
4287          ' ',
4288          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
4289         from po_lines_trx_v pol -- CLM project, bug 9403291
4290         , mtl_units_of_measure mum
4291   -- Bug 2619063, 2614016
4292   -- Modified to select the base uom for the uom class defined on po.
4293   where mum.uom_class = (SELECT mum2.uom_class
4294                FROM mtl_units_of_measure mum2
4295               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
4296         and mum.base_uom_flag = 'Y'
4297         and pol.ITEM_ID is null
4298         and pol.item_description is not null
4299         and pol.po_header_id = p_poHeaderID
4300         and pol.item_description like  p_concatenated_segments
4301         and  exists ( select 1 from po_distributions_trx_v pd
4302         where pd.po_header_id =  p_poHeaderID
4303         and pd.po_line_id = p_poLineID
4304         and pd.po_line_id = pol.po_line_id
4305         and ((p_projectId is null or pd.project_id = p_projectId)
4306                and (p_taskId is null or pd.task_id = p_taskId)
4307              )
4308         )
4309         /* Bug 3972931-Added the following exists condition to restrict the PO receipt
4310         to shipments due to be received only in the organization entered with.*/
4311         and exists (select 1
4312                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
4313 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
4314                          , mtl_parameters mp,
4315                            rcv_parameters rp
4316 --  End for Bug 7440217
4317                      where pll.po_header_id = p_poHeaderID
4318                        and pll.po_line_id = pol.po_line_id
4319                        and pll.ship_to_organization_id = p_Organization_Id
4320 --  For Bug 7440217 Checking if it is LCM enabled
4321                        AND mp.organization_id = p_Organization_Id
4322                        AND rp.organization_id = p_Organization_Id
4323                        AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
4324                                 OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
4325                                     OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
4326                            )
4327 --  End for Bug 7440217
4328                     )
4329         --End of fix for Bug 3972931
4330         UNION ALL
4331         -- Cross Ref  SQL
4332         -- Bug# 6747729
4333         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
4334         select distinct mcr.cross_reference,
4335         msi.inventory_item_id,
4336         msi.description,
4337         Nvl(msi.revision_qty_control_code,1),
4338         Nvl(msi.lot_control_code, 1),
4339         Nvl(msi.serial_number_control_code, 1),
4340         Nvl(msi.restrict_subinventories_code, 2),
4341         Nvl(msi.restrict_locators_code,2),
4342         Nvl(msi.location_control_code,1),
4343         msi.primary_uom_code,
4344         Nvl(msi.inspection_required_flag,'N'),
4345         Nvl(msi.shelf_life_code, 1),
4346         Nvl(msi.shelf_life_days,0),
4347         Nvl(msi.allowed_units_lookup_code, 2),
4348         Nvl(msi.effectivity_control,1),
4349         0,
4350         0,
4351         Nvl(msi.default_serial_status_id,1),
4352         Nvl(msi.serial_status_enabled,'N'),
4353         Nvl(msi.default_lot_status_id,0),
4354         Nvl(msi.lot_status_enabled,'N'),
4355         msi.concatenated_segments,
4356         'C',
4357         msi.inventory_item_flag,
4358         0,
4359 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
4360         msi.inventory_asset_flag,
4361         msi.outside_operation_flag,
4362          --Bug 3952081
4363          --Select DUOM Attributes for every Item
4364          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
4365          NVL(MSI.DEFAULT_GRADE,''),
4366          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
4367          NVL(MSI.EXPIRATION_ACTION_CODE,''),
4368          NVL(MSI.HOLD_DAYS,0),
4369          NVL(MSI.MATURITY_DAYS,0),
4370          NVL(MSI.RETEST_INTERVAL,0),
4371          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
4372          NVL(MSI.CHILD_LOT_FLAG,'N'),
4373          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
4374          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
4375          NVL(MSI.SECONDARY_UOM_CODE,''),
4376          NVL(MSI.SECONDARY_DEFAULT_IND,''),
4377          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
4378          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
4379          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
4380         msi.stock_enabled_flag,
4381          ' ',
4382          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
4383         from po_lines_trx_v pol -- CLM project, bug 9403291
4384         ,mtl_system_items_vl msi /* Bug 5581528 */
4385         ,mtl_cross_references mcr
4386         where msi.organization_id = p_organization_id
4387         and ( (mcr.cross_reference_type = p_crossreftype
4388                and mcr.cross_reference like  p_concatenated_segments
4389               ) or
4390               ( mcr.cross_reference_type = g_gtin_cross_ref_type
4391                AND mcr.cross_reference      LIKE g_crossref )
4392             )
4393         and ( (mcr.org_independent_flag = 'Y') or (mcr.org_independent_flag = 'N'
4394         and mcr.organization_id = p_organization_id
4395                ) )
4396         and mcr.inventory_item_id = msi.inventory_item_id
4397         and pol.item_id = msi.inventory_item_id
4398         and pol.po_header_id = p_poHeaderID
4399         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
4400         and msi.inventory_item_id IN (SELECT pl.item_id FROM po_lines_trx_v pl -- CLM project, bug 9403291
4401         WHERE pl.po_header_id = p_poHeaderID
4402         and pl.po_line_id = p_poLineID
4403         and exists (select 1
4404                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
4405 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
4406                          , mtl_parameters mp,
4407                            rcv_parameters rp
4408 --  End for Bug 7440217
4409                       where NVL(pll.closed_code, 'OPEN')
4410                       not in ('FINALLY CLOSED' , 'CLOSED FOR RECEIVING', 'CLOSED' )  -- 3687249
4411                       and  pll.po_header_id = p_poHeaderID
4412                       and pll.po_line_id = p_poLineID
4413                       and pll.ship_to_organization_id = p_Organization_Id
4414 --  For Bug 7440217 Checking if it is LCM enabled
4415                       AND mp.organization_id = p_Organization_Id
4416                       AND rp.organization_id = p_Organization_Id
4417                       AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
4418                                OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
4419                                    OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
4420                         )
4421 --  End for Bug 7440217
4422                     )--Bug 3972931-Added the filter condition based on ship_to_organization_id
4423         and  exists (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
4424         where pd.po_header_id =  p_poHeaderID
4425         and pd.po_line_id = pol.po_line_id
4426         and pd.po_line_id = p_poLineID
4427         and ((p_projectId is null or pd.project_id = p_projectId)
4428                and (p_taskId is null or pd.task_id = p_taskId)
4429              )
4430         )
4431         )
4432 		/* Bug 12348588 When use mobile to receive PO, item lov not display supplier item for one time item.
4433                That is because there is no record in item table: mtl_system_items_vl when the item is one time item.
4434 			   Now, we do not join the item table when the item id is null in the po lines table.*/
4435 
4436 		UNION ALL
4437 		select distinct pol.vendor_product_num,
4438         to_number(''),
4439         pol.item_description,
4440         1,
4441         1,
4442         1,
4443         2,
4444         2,
4445         1,
4446         mum.uom_code,
4447         'N',
4448         1,
4449         0,
4450         2,
4451         1,
4452         0,
4453         0,
4454         1,
4455         'N',
4456         0,
4457         'N',
4458 
4459 
4460         pol.item_description,
4461         'Y',
4462         'N',
4463         0,
4464 	  wms_deploy.get_item_client_name(pol.item_id),
4465         to_char(NULL),
4466         'N' ,
4467          --Bug 3952081
4468          --Select DUOM Attributes for every Item
4469          'N',
4470          '',
4471          0,
4472          '',
4473          0,
4474          0,
4475          0,
4476          'N',
4477          'N',
4478          'N',
4479          'Y',
4480          '',
4481          '',
4482          'P',
4483          0,
4484          0,
4485         'N',
4486          ' ',
4487          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
4488         from po_lines_trx_v pol -- CLM project, bug 9403291
4489         , mtl_units_of_measure mum
4490   -- Bug 2619063, 2614016
4491   -- Modified to select the base uom for the uom class defined on po.
4492   where mum.uom_class = (SELECT mum2.uom_class
4493                FROM mtl_units_of_measure mum2
4494               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
4495         and mum.base_uom_flag = 'Y'
4496         and pol.ITEM_ID is null
4497         and pol.vendor_product_num is not null
4498         and pol.po_header_id = p_poHeaderID
4499         and pol.vendor_product_num like  p_concatenated_segments
4500         and  exists (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
4501         where pd.po_header_id =  p_poHeaderID
4502 		and pd.po_line_id = p_poLineID
4503         and pd.po_line_id = pol.po_line_id
4504         and ((p_projectId is null or pd.project_id = p_projectId)
4505                and (p_taskId is null or pd.task_id = p_taskId)
4506              )
4507         )
4508         /* Bug 3972931-Added the following exists condition to restrict the PO receipt
4509         to shipments due to be received only in the organizationientered with.*/
4510         and exists (select 1
4511                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
4512 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
4513                          , mtl_parameters mp,
4514                            rcv_parameters rp
4515 --  End for Bug 7440217
4516                      where pll.po_header_id = p_poHeaderID
4517 
4518 
4519 --  For Bug 7440217 Checking if it is LCM enabled
4520                        AND mp.organization_id = p_organization_id
4521                        AND rp.organization_id = p_organization_id
4522                        AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
4523                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
4524                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
4525                         )
4526 --  End for Bug 7440217
4527 
4528 					   and pll.po_release_id = p_poReleaseID
4529                        and pll.po_line_id = pol.po_line_id
4530                        and pll.ship_to_organization_id = p_Organization_Id)
4531     /* End of fix for Bug 12348588 */
4532 
4533         ;
4534       else
4535 -- *****************************
4536 --- headerBased PJM Transaction
4537 --  Bug 4602289
4538 --  In the first query PO_LINES_ALL is
4539 --  joined to enforce a nested loop
4540 --  which would perform better for queries
4541 --  with/without item
4542 --  HeaderBased PJM PO_LINES_U2 is enforced
4543 --  In the query for Vendor item
4544 --
4545 -- *****************************
4546         open x_items for
4547         -- Bug# 6747729
4548         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
4549         select concatenated_segments,
4550         inventory_item_id,
4551         nvl(pol.item_description, description), -- Bug 14645109 change this
4552         Nvl(revision_qty_control_code,1),
4553         Nvl(lot_control_code, 1),
4554         Nvl(serial_number_control_code, 1),
4555         Nvl(restrict_subinventories_code, 2),
4556         Nvl(restrict_locators_code, 2),
4557         Nvl(location_control_code, 1),
4558         primary_uom_code,
4559         Nvl(mtl_system_items_vl.inspection_required_flag, 'N'), -- bug 4610452
4560         Nvl(shelf_life_code, 1),
4561         Nvl(shelf_life_days,0),
4562         Nvl(allowed_units_lookup_code, 2),
4563         Nvl(effectivity_control,1),
4564         0,
4565         0,
4566         Nvl(default_serial_status_id,1),
4567         Nvl(serial_status_enabled,'N'),
4568         Nvl(default_lot_status_id,0),
4569         Nvl(lot_status_enabled,'N'),
4570         '',
4571         'N',
4572         inventory_item_flag,
4573         0,
4574 	  wms_deploy.get_item_client_name(inventory_item_id),
4575         inventory_asset_flag,
4576         outside_operation_flag,
4577          --Bug 3952081
4578          --Select DUOM Attributes for every Item
4579          NVL(GRADE_CONTROL_FLAG,'N'),
4580          NVL(DEFAULT_GRADE,''),
4581          NVL(EXPIRATION_ACTION_INTERVAL,0),
4582          NVL(EXPIRATION_ACTION_CODE,''),
4583          NVL(HOLD_DAYS,0),
4584          NVL(MATURITY_DAYS,0),
4585          NVL(RETEST_INTERVAL,0),
4586          NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
4587          NVL(CHILD_LOT_FLAG,'N'),
4588          NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
4589          NVL(LOT_DIVISIBLE_FLAG,'Y'),
4590          NVL(SECONDARY_UOM_CODE,''),
4591          NVL(SECONDARY_DEFAULT_IND,''),
4592          NVL(TRACKING_QUANTITY_IND,'P'),
4593          NVL(DUAL_UOM_DEVIATION_HIGH,0),
4594          NVL(DUAL_UOM_DEVIATION_LOW,0),
4595         stock_enabled_flag,
4596          ' ',
4597          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
4598 	 from mtl_system_items_vl , /* Bug 5581528 */
4599              po_lines_trx_v pol   --CLM project, bug 9403291 -- bug 4602289
4600         WHERE organization_id = p_Organization_Id
4601         and concatenated_segments like p_concatenated_segments||l_append
4602         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
4603         and inventory_item_id = pol.item_id -- bug 4602289
4604         and pol.po_header_id = p_poHeaderID -- bug 4602289
4605         and exists (select 1
4606                       from po_line_locations_trx_v pll -- CLM Project, bug 9403291
4607 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
4608                          , mtl_parameters mp,
4609                           rcv_parameters rp
4610 --  End for Bug 7440217
4611                      where NVL(pll.closed_code,'OPEN')
4612                      not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')
4613                      and  pll.po_header_id = p_poHeaderID
4614                      and pll.po_line_id = pol.po_line_id
4615                      and pll.ship_to_organization_id = p_Organization_Id
4616 --  For Bug 7440217 Checking if it is LCM enabled
4617                      AND mp.organization_id = p_Organization_Id
4618                      AND rp.organization_id = p_Organization_Id
4619                      AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
4620                               OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
4621                                   OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
4622                           )
4623 --  End for Bug 7440217
4624                    )--Bug 3972931-Added the filter condition based on ship_to_organization_id
4625         and  exists
4626         (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
4627         where pd.po_header_id =  p_poHeaderID
4628         and pd.po_line_id = pol.po_line_id
4629         and ((p_projectId is null or pd.project_id = p_projectId)
4630                and (p_taskId is null or pd.task_id = p_taskId)
4631              )
4632         )
4633 
4634         UNION ALL
4635         -- Substitute Item SQL
4636         -- Bug# 6747729
4637         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
4638         select distinct msi.concatenated_segments,
4639         msi.inventory_item_id,
4640         Nvl(pol.item_description, msi.description),  -- Bug 14645109 change this
4641         Nvl(msi.revision_qty_control_code,1),
4642         Nvl(msi.lot_control_code, 1),
4643         Nvl(msi.serial_number_control_code, 1),
4644         Nvl(msi.restrict_subinventories_code, 2),
4645         Nvl(msi.restrict_locators_code,2),
4646         Nvl(msi.location_control_code,1),
4647         msi.primary_uom_code,
4648         Nvl(msi.inspection_required_flag,'N'),
4649         Nvl(msi.shelf_life_code, 1),
4650         Nvl(msi.shelf_life_days,0),
4651         Nvl(msi.allowed_units_lookup_code, 2),
4652         Nvl(msi.effectivity_control,1),
4653         0,
4654         0,
4655         Nvl(msi.default_serial_status_id,1),
4656         Nvl(msi.serial_status_enabled,'N'),
4657         Nvl(msi.default_lot_status_id,0),
4658         Nvl(msi.lot_status_enabled,'N'),
4659         msi.concatenated_segments,
4660         'S',
4661         msi.inventory_item_flag,
4662         0,
4663 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
4664         msi.inventory_asset_flag,
4665         msi.outside_operation_flag ,
4666          --Bug 3952081
4667          --Select DUOM Attributes for every Item
4668          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
4669          NVL(MSI.DEFAULT_GRADE,''),
4670          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
4671          NVL(MSI.EXPIRATION_ACTION_CODE,''),
4672          NVL(MSI.HOLD_DAYS,0),
4673          NVL(MSI.MATURITY_DAYS,0),
4674          NVL(MSI.RETEST_INTERVAL,0),
4675          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
4676          NVL(MSI.CHILD_LOT_FLAG,'N'),
4677          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
4678          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
4679          NVL(MSI.SECONDARY_UOM_CODE,''),
4680          NVL(MSI.SECONDARY_DEFAULT_IND,''),
4681          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
4682          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
4683          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
4684         msi.stock_enabled_flag,
4685          ' ',
4686          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
4687         from po_lines_trx_v pol  -- CLM project, bug 9403291
4688         ,mtl_related_items mri
4689        ,mtl_system_items_vl msi /* Bug 5581528 */
4690        /*,mtl_system_items_kfv msia */ /* Bug 6334679 */
4691         where msi.organization_id =  p_organization_id
4692         and msi.concatenated_segments like  p_concatenated_segments||l_append
4693         and pol.po_header_id = p_poHeaderID
4694         and pol.item_id = mri.inventory_item_id /* Condition changed by Bug10124916 */
4695         and msi.organization_id = p_organization_id
4696         and ((    mri.related_item_id = msi.inventory_item_id
4697         and pol.item_id = mri.inventory_item_id) or
4698          (    mri.inventory_item_id = msi.inventory_item_id
4699          and pol.item_id = mri.related_item_id
4700          and mri.reciprocal_flag = 'Y'))
4701          and exists (select 1
4702                       from  po_line_locations_trx_v pll -- CLM project, bug 9403291
4703 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
4704                           , mtl_parameters mp,
4705                             rcv_parameters rp
4706 --  End for Bug 7440217
4707                       where NVL(pll.closed_code,'OPEN') not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')
4708                       and   Nvl(pll.allow_substitute_receipts_flag, 'N') = 'Y'
4709                       and   pll.po_header_id = pol.po_header_id
4710                       and   pll.po_line_id = pol.po_line_id
4711                       and pll.ship_to_organization_id = p_Organization_Id
4712 --  For Bug 7440217 Checking if it is LCM enabled
4713                       AND mp.organization_id = p_Organization_Id
4714                       AND rp.organization_id = p_Organization_Id
4715                       AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
4716                                OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
4717                                    OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
4718                           )
4719 --  End for Bug 7440217
4720                       )--Bug 3972931-Added the filter condition based on ship_to_organization_id
4721         and  exists
4722         (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
4723         where pd.po_header_id =  p_poHeaderID
4724         and pd.po_line_id = pol.po_line_id
4725         and ((p_projectId is null or pd.project_id = p_projectId)
4726                and (p_taskId is null or pd.task_id = p_taskId)
4727              )
4728         )
4729         UNION ALL
4730 	-- Vendor Item SQL
4731         -- Bug# 6747729
4732         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
4733 	select /*+ INDEX(PO_LINES_ALL PO_LINES_U2) */	 --bug 4602289
4734         distinct pol.vendor_product_num,
4735         msi.inventory_item_id,
4736         Nvl(pol.item_description, msi.description),  -- Bug 14645109 s change this
4737         Nvl(msi.revision_qty_control_code,1),
4738         Nvl(msi.lot_control_code, 1),
4739         Nvl(msi.serial_number_control_code, 1),
4740         Nvl(msi.restrict_subinventories_code, 2),
4741         Nvl(msi.restrict_locators_code,2),
4742         Nvl(msi.location_control_code,1),
4743         msi.primary_uom_code,
4744         Nvl(msi.inspection_required_flag,'N'),
4745         Nvl(msi.shelf_life_code, 1),
4746         Nvl(msi.shelf_life_days,0),
4747         Nvl(msi.allowed_units_lookup_code, 2),
4748         Nvl(msi.effectivity_control,1),
4749         0,
4750         0,
4751         Nvl(msi.default_serial_status_id,1),
4752         Nvl(msi.serial_status_enabled,'N'),
4753         Nvl(msi.default_lot_status_id,0),
4754         Nvl(msi.lot_status_enabled,'N'),
4755         msi.concatenated_segments,
4756         'Y',
4757         msi.inventory_item_flag,
4758         0,
4759 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
4760         msi.inventory_asset_flag,
4761         msi.outside_operation_flag ,
4762          --Bug 3952081
4763          --Select DUOM Attributes for every Item
4764          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
4765          NVL(MSI.DEFAULT_GRADE,''),
4766          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
4767          NVL(MSI.EXPIRATION_ACTION_CODE,''),
4768          NVL(MSI.HOLD_DAYS,0),
4769          NVL(MSI.MATURITY_DAYS,0),
4770          NVL(MSI.RETEST_INTERVAL,0),
4771          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
4772          NVL(MSI.CHILD_LOT_FLAG,'N'),
4773          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
4774          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
4775          NVL(MSI.SECONDARY_UOM_CODE,''),
4776          NVL(MSI.SECONDARY_DEFAULT_IND,''),
4777          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
4778          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
4779          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
4780         msi.stock_enabled_flag,
4781          ' ',
4782          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
4783         from po_lines_trx_v pol -- CLM project, bug 9403291
4784         , mtl_system_items_vl msi  /* Bug 5581528 */
4785         where organization_id =  p_organization_id
4786         and pol.vendor_product_num like  p_concatenated_segments
4787         and pol.item_id = msi.inventory_item_id
4788         and  pol.vendor_product_num IS NOT NULL
4789         and pol.po_header_id =  p_poHeaderID
4790         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
4791         and inventory_item_id IN
4792         ( SELECT pl.item_id FROM po_lines_trx_v pl -- CLM project, bug 9403291
4793           WHERE pl.po_header_id = p_poHeaderID
4794         and exists (select 1
4795                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
4796 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
4797                          , mtl_parameters mp,
4798                            rcv_parameters rp
4799 --  End for Bug 7440217
4800                      where NVL(pll.closed_code,'OPEN')  not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')
4801                      and  pll.po_header_id = p_poHeaderID
4802                      and pll.po_line_id = pl.po_line_id
4803                      and pll.ship_to_organization_id = p_Organization_Id
4804 --  For Bug 7440217 Checking if it is LCM enabled
4805                      AND mp.organization_id = p_Organization_Id
4806                      AND rp.organization_id = p_Organization_Id
4807                      AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
4808                               OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
4809                                   OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
4810                          )
4811 --  End for Bug 7440217
4812                      )--Bug 3972931-Added the filter condition based on ship_to_organization_id
4813                and  exists
4814         (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
4815         where pd.po_header_id =  p_poHeaderID
4816         and pd.po_line_id = pol.po_line_id
4817         and ((p_projectId is null or pd.project_id = p_projectId)
4818                and (p_taskId is null or pd.task_id = p_taskId)
4819              )
4820         )
4821         )
4822         UNION ALL
4823         -- non item Master
4824         -- Bug# 6747729
4825         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
4826         select distinct pol.item_description,
4827         to_number(''),
4828         pol.item_description,
4829         1,
4830         1,
4831         1,
4832         2,
4833         2,
4834         1,
4835         mum.uom_code,
4836         'N',
4837         1,
4838         0,
4839         2,
4840         1,
4841         0,
4842         0,
4843         1,
4844         'N',
4845         0,
4846         'N',
4847         '',
4848         'N',
4849         'N',
4850         0,
4851 	  wms_deploy.get_item_client_name(pol.item_id),
4852         to_char(NULL),
4853         'N' ,
4854          --Bug 3952081
4855          --Select DUOM Attributes for every Item
4856          'N',
4857          '',
4858          0,
4859          '',
4860          0,
4861          0,
4862          0,
4863          'N',
4864          'N',
4865          'N',
4866          'Y',
4867          '',
4868          '',
4869          'P',
4870          0,
4871          0,
4872         'N',
4873          ' ',
4874          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
4875         from po_lines_trx_v pol  -- CLM project, bug 9403291
4876         , mtl_units_of_measure mum
4877   -- Bug 2619063, 2614016
4878   -- Modified to select the base uom for the uom class defined on po.
4879   where mum.uom_class = (SELECT mum2.uom_class
4880                FROM mtl_units_of_measure mum2
4881               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
4882         and mum.base_uom_flag = 'Y'
4883         and pol.ITEM_ID is null
4884         and pol.item_description is not null
4885         and pol.po_header_id = p_poHeaderID
4886         and pol.item_description like  p_concatenated_segments
4887         and  exists
4888         (select 1 from po_distributions_trx_v pd -- CLM project, bug 9403291
4889         where pd.po_header_id =  p_poHeaderID
4890         and pd.po_line_id = pol.po_line_id
4891         and ((p_projectId is null or pd.project_id = p_projectId)
4892                and (p_taskId is null or pd.task_id = p_taskId)
4893              )
4894         )
4895         /* Bug 3972931-Added the following exists condition to restrict the PO receipt
4896         to shipments due to be received only in the organizationientered with.*/
4897         and exists (select 1
4898                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
4899 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
4900                          , mtl_parameters mp,
4901                            rcv_parameters rp
4902 --  End for Bug 7440217
4903                      where pll.po_header_id = p_poHeaderID
4904                        and pll.po_line_id = pol.po_line_id
4905                        and pll.ship_to_organization_id = p_Organization_Id
4906 --  For Bug 7440217 Checking if it is LCM enabled
4907                        AND mp.organization_id = p_Organization_Id
4908                        AND rp.organization_id = p_Organization_Id
4909                        AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
4910                                 OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
4911                                     OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
4912                            )
4913 --  End for Bug 7440217
4914                        )
4915         --End of fix for Bug 3972931
4916         UNION ALL
4917         -- Cross Ref  SQL
4918         -- Bug# 6747729
4919         -- Added code to also fetch stock_enabled_flag from mtl_system_items_vl
4920         select distinct mcr.cross_reference,
4921         msi.inventory_item_id,
4922         msi.description,
4923         Nvl(msi.revision_qty_control_code,1),
4924         Nvl(msi.lot_control_code, 1),
4925         Nvl(msi.serial_number_control_code, 1),
4926         Nvl(msi.restrict_subinventories_code, 2),
4927         Nvl(msi.restrict_locators_code,2),
4928         Nvl(msi.location_control_code,1),
4929         msi.primary_uom_code,
4930         Nvl(msi.inspection_required_flag,'N'),
4931         Nvl(msi.shelf_life_code, 1),
4932         Nvl(msi.shelf_life_days,0),
4933         Nvl(msi.allowed_units_lookup_code, 2),
4934         Nvl(msi.effectivity_control,1),
4935         0,
4936         0,
4937         Nvl(msi.default_serial_status_id,1),
4938         Nvl(msi.serial_status_enabled,'N'),
4939         Nvl(msi.default_lot_status_id,0),
4940         Nvl(msi.lot_status_enabled,'N'),
4941         msi.concatenated_segments,
4942         'C',
4943         msi.inventory_item_flag,
4944         0,
4945 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
4946         msi.inventory_asset_flag,
4947         msi.outside_operation_flag,
4948          --Bug 3952081
4949          --Select DUOM Attributes for every Item
4950          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
4951          NVL(MSI.DEFAULT_GRADE,''),
4952          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
4953          NVL(MSI.EXPIRATION_ACTION_CODE,''),
4954          NVL(MSI.HOLD_DAYS,0),
4955          NVL(MSI.MATURITY_DAYS,0),
4956          NVL(MSI.RETEST_INTERVAL,0),
4957          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
4958          NVL(MSI.CHILD_LOT_FLAG,'N'),
4959          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
4960          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
4961          NVL(MSI.SECONDARY_UOM_CODE,''),
4962          NVL(MSI.SECONDARY_DEFAULT_IND,''),
4963          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
4964          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
4965          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
4966         msi.stock_enabled_flag,
4967          ' ',
4968          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
4969         from po_lines_trx_v pol -- CLM project, bug 9403291
4970         ,mtl_system_items_vl msi /* Bug 5581528 */
4971         ,mtl_cross_references mcr
4972         where msi.organization_id = p_organization_id
4973         and ( (mcr.cross_reference_type = p_crossreftype
4974                and mcr.cross_reference like  p_concatenated_segments
4975               ) or
4976               ( mcr.cross_reference_type = g_gtin_cross_ref_type
4977                AND mcr.cross_reference      LIKE g_crossref )
4978             )
4979         and ( (mcr.org_independent_flag = 'Y') or (mcr.org_independent_flag = 'N'
4980         and mcr.organization_id = p_organization_id
4981                ) )
4982         and mcr.inventory_item_id = msi.inventory_item_id
4983         and pol.item_id = msi.inventory_item_id
4984         and pol.po_header_id = p_poHeaderID
4985         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
4986         and msi.inventory_item_id IN
4987         ( SELECT pl.item_id FROM po_lines_trx_v pl  -- CLM project, bug 9403291
4988           WHERE pl.po_header_id = p_poHeaderID
4989           and exists (select 1
4990                         from po_line_locations_trx_v pll -- CLM project, bug 9403291
4991 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
4992                            , mtl_parameters mp,
4993                              rcv_parameters rp
4994 --  End for Bug 7440217
4995                        where NVL(pll.closed_code,'OPEN')
4996                        not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')  -- 3687249
4997                        and  pll.po_header_id =   p_poHeaderID and pll.po_line_id = pl.po_line_id
4998                        and pll.ship_to_organization_id = p_Organization_Id
4999 --  For Bug 7440217 Checking if it is LCM enabled
5000                        AND mp.organization_id = p_Organization_Id
5001                        AND rp.organization_id = p_Organization_Id
5002                        AND (   (NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
5003                                 OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
5004                                     OR (NVL(pll.lcm_flag,'N') = 'N')        -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
5005                           )
5006 --  End for Bug 7440217
5007                        )--Bug 3972931-Added the filter condition based on ship_to_organization_id
5008                        and  exists (select 1
5009                                       from po_distributions_trx_v pd -- CLM project, bug 9403291
5010                                      where pd.po_header_id =  p_poHeaderID
5011                                       and pd.po_line_id = pol.po_line_id
5012                                       and ((p_projectId is null or pd.project_id = p_projectId)
5013                                       and (p_taskId is null or pd.task_id = p_taskId)
5014                                    )
5015                       )
5016         )
5017 				/* Bug 12348588 When use mobile to receive PO, item lov not display supplier item for one time item.
5018                That is because there is no record in item table: mtl_system_items_vl when the item is one time item.
5019 			   Now, we do not join the item table when the item id is null in the po lines table.*/
5020 
5021 		UNION ALL
5022 		select distinct pol.vendor_product_num,
5023         to_number(''),
5024         pol.item_description,
5025         1,
5026         1,
5027         1,
5028         2,
5029         2,
5030         1,
5031         mum.uom_code,
5032         'N',
5033         1,
5034         0,
5035         2,
5036         1,
5037         0,
5038         0,
5039         1,
5040         'N',
5041         0,
5042         'N',
5043         pol.item_description,
5044         'Y',
5045         'N',
5046         0,
5047 	  wms_deploy.get_item_client_name(pol.item_id),
5048         to_char(NULL),
5049         'N' ,
5050          --Bug 3952081
5051          --Select DUOM Attributes for every Item
5052          'N',
5053          '',
5054          0,
5055          '',
5056          0,
5057          0,
5058          0,
5059          'N',
5060          'N',
5061          'N',
5062          'Y',
5063          '',
5064          '',
5065          'P',
5066          0,
5067          0,
5068         'N',
5069          ' ',
5070          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
5071         from po_lines_trx_v pol -- CLM project, bug 9403291
5072         , mtl_units_of_measure mum
5073   -- Bug 2619063, 2614016
5074   -- Modified to select the base uom for the uom class defined on po.
5075   where mum.uom_class = (SELECT mum2.uom_class
5076                FROM mtl_units_of_measure mum2
5077               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
5078         and mum.base_uom_flag = 'Y'
5079         and pol.ITEM_ID is null
5080         and pol.vendor_product_num is not null
5081         and pol.po_header_id = p_poHeaderID
5082         and pol.vendor_product_num like  p_concatenated_segments
5083         /* Bug 3972931-Added the following exists condition to restrict the PO receipt
5084         to shipments due to be received only in the organizationientered with.*/
5085         and exists (select 1
5086                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
5087 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
5088                          , mtl_parameters mp,
5089                            rcv_parameters rp
5090 --  End for Bug 7440217
5091                      where pll.po_header_id = p_poHeaderID
5092 --  For Bug 7440217 Checking if it is LCM enabled
5093                        AND mp.organization_id = p_organization_id
5094                        AND rp.organization_id = p_organization_id
5095                        AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
5096                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
5097                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
5098                         )
5099 --  End for Bug 7440217
5100                        and pll.po_line_id = pol.po_line_id
5101                        and pll.ship_to_organization_id = p_Organization_Id)
5102     /* End of fix for Bug 12348588 */
5103         ;
5104       end if;
5105       -- End of PJM Based Tran
5106   else
5107 
5108 -- *****************************
5109 --- Start of not PJM BASED Tran.
5110 -- *****************************
5111 
5112       if (p_poReleaseID is not null) then
5113 -- *****************************
5114 -- Release Based Transaction
5115 -- *****************************
5116         open x_items for
5117         -- Bug# 6747729
5118         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
5119         select concatenated_segments,
5120         inventory_item_id,
5121         Nvl(pol.item_description, description),  -- Bug 14645109 s
5122         Nvl(revision_qty_control_code,1),
5123         Nvl(lot_control_code, 1),
5124         Nvl(serial_number_control_code, 1),
5125         Nvl(restrict_subinventories_code, 2),
5126         Nvl(restrict_locators_code, 2),
5127         Nvl(location_control_code, 1),
5128         primary_uom_code,
5129         Nvl(inspection_required_flag, 'N'),
5130         Nvl(shelf_life_code, 1),
5131         Nvl(shelf_life_days,0),
5132         Nvl(allowed_units_lookup_code, 2),
5133         Nvl(effectivity_control,1),
5134         0,
5135         0,
5136         Nvl(default_serial_status_id,1),
5137         Nvl(serial_status_enabled,'N'),
5138         Nvl(default_lot_status_id,0),
5139         Nvl(lot_status_enabled,'N'),
5140         '',
5141         'N',
5142         inventory_item_flag,
5143         0,
5144 	  wms_deploy.get_item_client_name(inventory_item_id),
5145         inventory_asset_flag,
5146         outside_operation_flag,
5147          --Bug 3952081
5148          --Select DUOM Attributes for every Item
5149          NVL(GRADE_CONTROL_FLAG,'N'),
5150          NVL(DEFAULT_GRADE,''),
5151          NVL(EXPIRATION_ACTION_INTERVAL,0),
5152          NVL(EXPIRATION_ACTION_CODE,''),
5153          NVL(HOLD_DAYS,0),
5154          NVL(MATURITY_DAYS,0),
5155          NVL(RETEST_INTERVAL,0),
5156          NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
5157          NVL(CHILD_LOT_FLAG,'N'),
5158          NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
5159          NVL(LOT_DIVISIBLE_FLAG,'Y'),
5160          NVL(SECONDARY_UOM_CODE,''),
5161          NVL(SECONDARY_DEFAULT_IND,''),
5162          NVL(TRACKING_QUANTITY_IND,'P'),
5163          NVL(DUAL_UOM_DEVIATION_HIGH,0),
5164          NVL(DUAL_UOM_DEVIATION_LOW,0),
5165         stock_enabled_flag,
5166          ' ',
5167          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
5168         from mtl_system_items_vl, /* Bug 5581528 */
5169 		po_lines_all  pol   -- Bug 14645109 s
5170         WHERE organization_id = p_Organization_Id
5171               and concatenated_segments like p_concatenated_segments||l_append
5172               and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
5173               and inventory_item_id =pol.item_id --Bug 14645109 s changed from this part
5174 			  and pol.po_header_id =   p_poHeaderID
5175         and exists (select 1
5176                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
5177 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
5178                          , mtl_parameters mp,
5179                            rcv_parameters rp
5180 --  End for Bug 7440217
5181                       WHERE NVL(pll.closed_code,'OPEN')
5182                       not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')
5183                       and  pll.po_header_id = p_poHeaderID
5184                       and pll.po_release_id = p_poReleaseID
5185                       and pll.po_line_id = pol.po_line_id
5186                       and pll.ship_to_organization_id = p_Organization_Id
5187 --  For Bug 7440217 Checking if it is LCM enabled
5188                       AND mp.organization_id = p_organization_id
5189                       AND rp.organization_id = p_organization_id
5190                       AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
5191                             OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
5192                                 OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
5193                    )
5194 --  End for Bug 7440217
5195                       )--Bug 3972931-Added the filter condition based on ship_to_organization_id
5196         --Bug 14645109 s remove this)
5197         UNION ALL
5198         -- Substitute ITEM SQL
5199         -- Bug# 6747729
5200         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
5201         select distinct msi.concatenated_segments,
5202         msi.inventory_item_id,
5203         Nvl(pol.item_description, msi.description),  -- Bug 14645109
5204         Nvl(msi.revision_qty_control_code,1),
5205         Nvl(msi.lot_control_code, 1),
5206         Nvl(msi.serial_number_control_code, 1),
5207         Nvl(msi.restrict_subinventories_code, 2),
5208         Nvl(msi.restrict_locators_code,2),
5209         Nvl(msi.location_control_code,1),
5210         msi.primary_uom_code,
5211         Nvl(msi.inspection_required_flag,'N'),
5212         Nvl(msi.shelf_life_code, 1),
5213         Nvl(msi.shelf_life_days,0),
5214         Nvl(msi.allowed_units_lookup_code, 2),
5215         Nvl(msi.effectivity_control,1),
5216         0,
5217         0,
5218         Nvl(msi.default_serial_status_id,1),
5219         Nvl(msi.serial_status_enabled,'N'),
5220         Nvl(msi.default_lot_status_id,0),
5221         Nvl(msi.lot_status_enabled,'N'),
5222         msi.concatenated_segments,
5223         'S',
5224         msi.inventory_item_flag,
5225         0,
5226 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
5227         msi.inventory_asset_flag,
5228         msi.outside_operation_flag ,
5229          --Bug 3952081
5230          --Select DUOM Attributes for every Item
5231          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
5232          NVL(MSI.DEFAULT_GRADE,''),
5233          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
5234          NVL(MSI.EXPIRATION_ACTION_CODE,''),
5235          NVL(MSI.HOLD_DAYS,0),
5236          NVL(MSI.MATURITY_DAYS,0),
5237          NVL(MSI.RETEST_INTERVAL,0),
5238          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
5239          NVL(MSI.CHILD_LOT_FLAG,'N'),
5240          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
5241          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
5242          NVL(MSI.SECONDARY_UOM_CODE,''),
5243          NVL(MSI.SECONDARY_DEFAULT_IND,''),
5244          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
5245          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
5246          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
5247         msi.stock_enabled_flag,
5248          ' ',
5249          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
5250         from po_lines_trx_v pol -- CLM project, bug 9403291
5251         ,mtl_related_items mri
5252         ,mtl_system_items_vl msi /* Bug 5581528 */
5253        /*,mtl_system_items_kfv msia */ /* Bug 6334679 */
5254         where msi.organization_id =  p_organization_id
5255         and msi.concatenated_segments like  p_concatenated_segments||l_append
5256         and pol.po_header_id = p_poHeaderID
5257         and pol.item_id = mri.inventory_item_id /* Condition changed by Bug10124916 */
5258         and msi.organization_id = p_organization_id
5259         and ((    mri.related_item_id = msi.inventory_item_id
5260         and pol.item_id = mri.inventory_item_id) or
5261          (    mri.inventory_item_id = msi.inventory_item_id
5262          and pol.item_id = mri.related_item_id
5263          and mri.reciprocal_flag = 'Y'))
5264          and exists (select 1
5265                       from  po_line_locations_trx_v pll -- CLM project, bug 9403291
5266 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
5267                           , mtl_parameters mp,
5268                             rcv_parameters rp
5269 --  End for Bug 7440217
5270                       where NVL(pll.closed_code,'OPEN')
5271                       not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')  -- 3687249
5272                       and   Nvl(pll.allow_substitute_receipts_flag, 'N') = 'Y'
5273                       and   pll.po_header_id = pol.po_header_id
5274                       and   pll.po_line_id = pol.po_line_id
5275                       and   pll.po_release_id = p_poReleaseID
5276                       and pll.ship_to_organization_id = p_Organization_Id
5277 --  For Bug 7440217 Checking if it is LCM enabled
5278                       AND  mp.organization_id = p_organization_id
5279                       AND  rp.organization_id = p_organization_id
5280                       AND  ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
5281                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
5282                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
5283                    )
5284 --  End for Bug 7440217
5285                       )--Bug 3972931-Added the filter condition based on ship_to_organization_id
5286         UNION ALL
5287         -- Vendor Item SQL
5288         -- Bug# 6747729
5289         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
5290         select distinct pol.vendor_product_num,
5291         msi.inventory_item_id,
5292         Nvl(pol.item_description, msi.description),  -- Bug 14645109 s
5293         Nvl(msi.revision_qty_control_code,1),
5294         Nvl(msi.lot_control_code, 1),
5295         Nvl(msi.serial_number_control_code, 1),
5296         Nvl(msi.restrict_subinventories_code, 2),
5297         Nvl(msi.restrict_locators_code,2),
5298         Nvl(msi.location_control_code,1),
5299         msi.primary_uom_code,
5300         Nvl(msi.inspection_required_flag,'N'),
5301         Nvl(msi.shelf_life_code, 1),
5302         Nvl(msi.shelf_life_days,0),
5303         Nvl(msi.allowed_units_lookup_code, 2),
5304         Nvl(msi.effectivity_control,1),
5305         0,
5306         0,
5307         Nvl(msi.default_serial_status_id,1),
5308         Nvl(msi.serial_status_enabled,'N'),
5309         Nvl(msi.default_lot_status_id,0),
5310         Nvl(msi.lot_status_enabled,'N'),
5311         msi.concatenated_segments,
5312         'Y',
5313         msi.inventory_item_flag,
5314         0,
5315 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
5316         msi.inventory_asset_flag,
5317         msi.outside_operation_flag ,
5318          --Bug 3952081
5319          --Select DUOM Attributes for every Item
5320          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
5321          NVL(MSI.DEFAULT_GRADE,''),
5322          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
5323          NVL(MSI.EXPIRATION_ACTION_CODE,''),
5324          NVL(MSI.HOLD_DAYS,0),
5325          NVL(MSI.MATURITY_DAYS,0),
5326          NVL(MSI.RETEST_INTERVAL,0),
5327          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
5328          NVL(MSI.CHILD_LOT_FLAG,'N'),
5329          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
5330          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
5331          NVL(MSI.SECONDARY_UOM_CODE,''),
5332          NVL(MSI.SECONDARY_DEFAULT_IND,''),
5333          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
5334          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
5335          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
5336         msi.stock_enabled_flag,
5337          ' ',
5338          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
5339         from po_lines_trx_v pol  -- CLM project, bug 9403291
5340         , mtl_system_items_vl msi  /* Bug 5581528 */
5341         where organization_id =  p_organization_id
5342         and pol.vendor_product_num like  p_concatenated_segments
5343         and pol.item_id = msi.inventory_item_id
5344         and  pol.vendor_product_num IS NOT NULL
5345         and pol.po_header_id =  p_poHeaderID
5346         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
5347         and inventory_item_id IN (SELECT pol.item_id FROM po_lines_trx_v pol -- CLM project, bug 9403291
5348         where pol.po_header_id =   p_poHeaderID
5349         and exists (select 1
5350                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
5351 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
5352                          , mtl_parameters mp,
5353                            rcv_parameters rp
5354 --  End for Bug 7440217
5355                       WHERE NVL(pll.closed_code,'OPEN')
5356                       not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')
5357                       and pll.po_header_id = p_poHeaderID
5358                       and pll.po_release_id = p_poReleaseID
5359                       and pll.po_line_id = pol.po_line_id
5360                       and pll.ship_to_organization_id = p_Organization_Id
5361 --  For Bug 7440217 Checking if it is LCM enabled
5362                       AND mp.organization_id = p_organization_id
5363                       AND rp.organization_id = p_organization_id
5364                       AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
5365                             OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
5366                                 OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
5367                     )
5368 --  End for Bug 7440217
5369                       )--Bug 3972931-Added the filter condition based on ship_to_organization_id
5370         )
5371         UNION ALL
5372         -- non item Master
5373         -- Bug# 6747729
5374         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
5375         select distinct pol.item_description,
5376         to_number(''),
5377         pol.item_description,
5378         1,
5379         1,
5380         1,
5381         2,
5382         2,
5383         1,
5384         mum.uom_code,
5385         'N',
5386         1,
5387         0,
5388         2,
5389         1,
5390         0,
5391         0,
5392         1,
5393         'N',
5394         0,
5395         'N',
5396         '',
5397         'N',
5398         'N',
5399         0,
5400 	  wms_deploy.get_item_client_name(pol.item_id),
5401         to_char(NULL),
5402         'N' ,
5403          --Bug 3952081
5404          --Select DUOM Attributes for every Item
5405          'N',
5406          '',
5407          0,
5408          '',
5409          0,
5410          0,
5411          0,
5412          'N',
5413          'N',
5414          'N',
5415          'Y',
5416          '',
5417          '',
5418          'P',
5419          0,
5420          0,
5421         'N',
5422          ' ',
5423          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
5424         from po_lines_trx_v pol  -- CLM project, bug 9403291
5425         , mtl_units_of_measure mum
5426   -- Bug 2619063, 2614016
5427   -- Modified to select the base uom for the uom class defined on po.
5428   where mum.uom_class = (SELECT mum2.uom_class
5429                FROM mtl_units_of_measure mum2
5430               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
5431         and mum.base_uom_flag = 'Y'
5432         and pol.ITEM_ID is null
5433         and pol.item_description is not null
5434         and pol.po_header_id = p_poHeaderID
5435         and pol.item_description like  p_concatenated_segments
5436         /* Bug 3972931-Added the following exists condition to restrict the PO receipt
5437         to shipments due to be received only in the organizationientered with.*/
5438         and exists (select 1
5439                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
5440 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
5441                          , mtl_parameters mp,
5442                            rcv_parameters rp
5443 --  End for Bug 7440217
5444                      where pll.po_header_id = p_poHeaderID
5445                        and pll.po_line_id = pol.po_line_id
5446                        and pll.ship_to_organization_id = p_Organization_Id
5447 					   and pll.po_release_id = p_poReleaseID
5448 --  For Bug 7440217 Checking if it is LCM enabled
5449                        AND mp.organization_id = p_organization_id
5450                        AND rp.organization_id = p_organization_id
5451                        AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
5452                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
5453                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
5454                             )
5455 --  End for Bug 7440217
5456 
5457                        )
5458         --End of fix for Bug 3972931
5459         UNION ALL
5460         -- Cross Ref  SQL
5461         -- Bug# 6747729
5462         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
5463         select distinct mcr.cross_reference,
5464         msi.inventory_item_id,
5465         Nvl(pol.item_description, msi.description),  -- Bug 14645109 s
5466         Nvl(msi.revision_qty_control_code,1),
5467         Nvl(msi.lot_control_code, 1),
5468         Nvl(msi.serial_number_control_code, 1),
5469         Nvl(msi.restrict_subinventories_code, 2),
5470         Nvl(msi.restrict_locators_code,2),
5471         Nvl(msi.location_control_code,1),
5472         msi.primary_uom_code,
5473         Nvl(msi.inspection_required_flag,'N'),
5474         Nvl(msi.shelf_life_code, 1),
5475         Nvl(msi.shelf_life_days,0),
5476         Nvl(msi.allowed_units_lookup_code, 2),
5477         Nvl(msi.effectivity_control,1),
5478         0,
5479         0,
5480         Nvl(msi.default_serial_status_id,1),
5481         Nvl(msi.serial_status_enabled,'N'),
5482         Nvl(msi.default_lot_status_id,0),
5483         Nvl(msi.lot_status_enabled,'N'),
5484         msi.concatenated_segments,
5485         'C',
5486         msi.inventory_item_flag,
5487         0,
5488 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
5489         msi.inventory_asset_flag,
5490         msi.outside_operation_flag,
5491          --Bug 3952081
5492          --Select DUOM Attributes for every Item
5493          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
5494          NVL(MSI.DEFAULT_GRADE,''),
5495          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
5496          NVL(MSI.EXPIRATION_ACTION_CODE,''),
5497          NVL(MSI.HOLD_DAYS,0),
5498          NVL(MSI.MATURITY_DAYS,0),
5499          NVL(MSI.RETEST_INTERVAL,0),
5500          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
5501          NVL(MSI.CHILD_LOT_FLAG,'N'),
5502          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
5503          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
5504          NVL(MSI.SECONDARY_UOM_CODE,''),
5505          NVL(MSI.SECONDARY_DEFAULT_IND,''),
5506          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
5507          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
5508          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
5509         msi.stock_enabled_flag,
5510          ' ',
5511          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
5512         from po_lines_trx_v pol -- CLM project, bug 9403291
5513         ,mtl_system_items_vl msi /* Bug 5581528 */
5514         ,mtl_cross_references mcr
5515         where msi.organization_id = p_organization_id
5516         and ( (mcr.cross_reference_type = p_crossreftype
5517                and mcr.cross_reference like  p_concatenated_segments
5518               ) or
5519               ( mcr.cross_reference_type = g_gtin_cross_ref_type
5520                AND mcr.cross_reference      LIKE g_crossref )
5521             )
5522         and ( (mcr.org_independent_flag = 'Y') or (mcr.org_independent_flag = 'N'
5523         and mcr.organization_id = p_organization_id
5524                ) )
5525         and mcr.inventory_item_id = msi.inventory_item_id
5526         and pol.item_id = msi.inventory_item_id
5527         and pol.po_header_id = p_poHeaderID
5528         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
5529         and msi.inventory_item_id IN (SELECT pol.item_id FROM po_lines_trx_v pol -- CLM project, bug 9403291
5530         where pol.po_header_id =   p_poHeaderID
5531         and exists (select 1
5532                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
5533 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
5534                          , mtl_parameters mp,
5535                            rcv_parameters rp
5536 --  End for Bug 7440217
5537                       WHERE NVL(pll.closed_code,'OPEN')
5538                       not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')
5539                       and pll.po_header_id = p_poHeaderID
5540                       and pll.po_release_id = p_poReleaseID
5541                       and pll.po_line_id = pol.po_line_id
5542                       and pll.ship_to_organization_id = p_Organization_Id
5543 --  For Bug 7440217 Checking if it is LCM enabled
5544                       AND mp.organization_id = p_organization_id
5545                       AND rp.organization_id = p_organization_id
5546                       AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
5547                             OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
5548                                 OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
5549                           )
5550 --  End for Bug 7440217
5551                       )--Bug 3972931-Added the filter condition based on ship_to_organization_id
5552         )
5553 				/* Bug 12348588 When use mobile to receive PO, item lov not display supplier item for one time item.
5554                That is because there is no record in item table: mtl_system_items_vl when the item is one time item.
5555 			   Now, we do not join the item table when the item id is null in the po lines table.*/
5556 
5557 		UNION ALL
5558 		select distinct pol.vendor_product_num,
5559         to_number(''),
5560         pol.item_description,
5561         1,
5562         1,
5563         1,
5564         2,
5565         2,
5566         1,
5567         mum.uom_code,
5568         'N',
5569         1,
5570         0,
5571         2,
5572         1,
5573         0,
5574         0,
5575         1,
5576         'N',
5577         0,
5578         'N',
5579         pol.item_description,
5580         'Y',
5581         'N',
5582         0,
5583 	  wms_deploy.get_item_client_name(pol.item_id),
5584         to_char(NULL),
5585         'N' ,
5586          --Bug 3952081
5587          --Select DUOM Attributes for every Item
5588          'N',
5589          '',
5590          0,
5591          '',
5592          0,
5593          0,
5594          0,
5595          'N',
5596          'N',
5597          'N',
5598          'Y',
5599          '',
5600          '',
5601          'P',
5602          0,
5603          0,
5604         'N',
5605          ' ',
5606          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
5607         from po_lines_trx_v pol -- CLM project, bug 9403291
5608         , mtl_units_of_measure mum
5609   -- Bug 2619063, 2614016
5610   -- Modified to select the base uom for the uom class defined on po.
5611   where mum.uom_class = (SELECT mum2.uom_class
5612                FROM mtl_units_of_measure mum2
5613               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
5614         and mum.base_uom_flag = 'Y'
5615         and pol.ITEM_ID is null
5616         and pol.vendor_product_num is not null
5617         and pol.po_header_id = p_poHeaderID
5618         and pol.vendor_product_num like  p_concatenated_segments
5619         /* Bug 3972931-Added the following exists condition to restrict the PO receipt
5620         to shipments due to be received only in the organizationientered with.*/
5621         and exists (select 1
5622                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
5623 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
5624                          , mtl_parameters mp,
5625                            rcv_parameters rp
5626 --  End for Bug 7440217
5627                      where pll.po_header_id = p_poHeaderID
5628 --  For Bug 7440217 Checking if it is LCM enabled
5629                        AND mp.organization_id = p_organization_id
5630                        AND rp.organization_id = p_organization_id
5631                        AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
5632                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
5633                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
5634                         )
5635 --  End for Bug 7440217
5636 					   and pll.po_release_id = p_poReleaseID
5637                        and pll.po_line_id = pol.po_line_id
5638                        and pll.ship_to_organization_id = p_Organization_Id)
5639     /* End of fix for Bug 12348588 */
5640         ;
5641       elsif  (p_poLineID IS NOT NULL) then
5642 -- *****************************
5643 --  Deafult Line Based  Tran
5644 --- ***************************
5645         open x_items for
5646         -- Bug# 6747729
5647         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
5648         select concatenated_segments,
5649         inventory_item_id,
5650          nvl(pl.item_description, description),  -- Bug 14645109 s
5651         Nvl(revision_qty_control_code,1),
5652         Nvl(lot_control_code, 1),
5653         Nvl(serial_number_control_code, 1),
5654         Nvl(restrict_subinventories_code, 2),
5655         Nvl(restrict_locators_code, 2),
5656         Nvl(location_control_code, 1),
5657         primary_uom_code,
5658         Nvl(inspection_required_flag, 'N'),
5659         Nvl(shelf_life_code, 1),
5660         Nvl(shelf_life_days,0),
5661         Nvl(allowed_units_lookup_code, 2),
5662         Nvl(effectivity_control,1),
5663         0,
5664         0,
5665         Nvl(default_serial_status_id,1),
5666         Nvl(serial_status_enabled,'N'),
5667         Nvl(default_lot_status_id,0),
5668         Nvl(lot_status_enabled,'N'),
5669         '',
5670         'N',
5671         inventory_item_flag,
5672         0,
5673 	  wms_deploy.get_item_client_name(inventory_item_id),
5674         inventory_asset_flag,
5675         outside_operation_flag,
5676          --Bug 3952081
5677          --Select DUOM Attributes for every Item
5678          NVL(GRADE_CONTROL_FLAG,'N'),
5679          NVL(DEFAULT_GRADE,''),
5680          NVL(EXPIRATION_ACTION_INTERVAL,0),
5681          NVL(EXPIRATION_ACTION_CODE,''),
5682          NVL(HOLD_DAYS,0),
5683          NVL(MATURITY_DAYS,0),
5684          NVL(RETEST_INTERVAL,0),
5685          NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
5686          NVL(CHILD_LOT_FLAG,'N'),
5687          NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
5688          NVL(LOT_DIVISIBLE_FLAG,'Y'),
5689          NVL(SECONDARY_UOM_CODE,''),
5690          NVL(SECONDARY_DEFAULT_IND,''),
5691          NVL(TRACKING_QUANTITY_IND,'P'),
5692          NVL(DUAL_UOM_DEVIATION_HIGH,0),
5693          NVL(DUAL_UOM_DEVIATION_LOW,0),
5694         stock_enabled_flag,
5695          ' ',
5696          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
5697         from mtl_system_items_vl , /* Bug 5581528 */
5698 		     po_lines_all pl     -- Bug 14645109 s
5699         WHERE organization_id = p_Organization_Id
5700               and concatenated_segments like p_concatenated_segments||l_append
5701               and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
5702 			  -- CLM project, bug 9403291
5703               and inventory_item_id = pl.item_id -- Bug 14624321 changed this part
5704         and pl.po_header_id = p_poHeaderID
5705         and pl.po_line_id = p_poLineID
5706         and exists (select 1
5707                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
5708 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
5709                          , mtl_parameters mp,
5710                            rcv_parameters rp
5711 --  End for Bug 7440217
5712                       where NVL(pll.closed_code, 'OPEN')
5713                       not in ('FINALLY CLOSED' , 'CLOSED FOR RECEIVING', 'CLOSED' )  -- 3687249
5714                       and  pll.po_header_id = p_poHeaderID
5715                       and pll.po_line_id = p_poLineID
5716                       and pll.ship_to_organization_id = p_Organization_Id
5717 --  For Bug 7440217 Checking if it is LCM enabled
5718                       AND mp.organization_id = p_organization_id
5719                       AND rp.organization_id = p_organization_id
5720                       AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
5721                             OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
5722                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
5723                     )
5724 --  End for Bug 7440217
5725                       )
5726 			--	bug 14645109 s reomve this	  )--Bug 3972931-Added the filter condition based on ship_to_organization_id
5727         UNION ALL
5728         -- Substitute Item SQL
5729         -- Bug# 6747729
5730         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
5731         select distinct msi.concatenated_segments,
5732         msi.inventory_item_id,
5733         Nvl(pol.item_description, msi.description),  -- Bug 14645109
5734         Nvl(msi.revision_qty_control_code,1),
5735         Nvl(msi.lot_control_code, 1),
5736         Nvl(msi.serial_number_control_code, 1),
5737         Nvl(msi.restrict_subinventories_code, 2),
5738         Nvl(msi.restrict_locators_code,2),
5739         Nvl(msi.location_control_code,1),
5740         msi.primary_uom_code,
5741         Nvl(msi.inspection_required_flag,'N'),
5742         Nvl(msi.shelf_life_code, 1),
5743         Nvl(msi.shelf_life_days,0),
5744         Nvl(msi.allowed_units_lookup_code, 2),
5745         Nvl(msi.effectivity_control,1),
5746         0,
5747         0,
5748         Nvl(msi.default_serial_status_id,1),
5749         Nvl(msi.serial_status_enabled,'N'),
5750         Nvl(msi.default_lot_status_id,0),
5751         Nvl(msi.lot_status_enabled,'N'),
5752         msi.concatenated_segments,
5753         'S',
5754         msi.inventory_item_flag,
5755         0,
5756 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
5757         msi.inventory_asset_flag,
5758         msi.outside_operation_flag ,
5759          --Bug 3952081
5760          --Select DUOM Attributes for every Item
5761          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
5762          NVL(MSI.DEFAULT_GRADE,''),
5763          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
5764          NVL(MSI.EXPIRATION_ACTION_CODE,''),
5765          NVL(MSI.HOLD_DAYS,0),
5766          NVL(MSI.MATURITY_DAYS,0),
5767          NVL(MSI.RETEST_INTERVAL,0),
5768          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
5769          NVL(MSI.CHILD_LOT_FLAG,'N'),
5770          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
5771          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
5772          NVL(MSI.SECONDARY_UOM_CODE,''),
5773          NVL(MSI.SECONDARY_DEFAULT_IND,''),
5774          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
5775          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
5776          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
5777         msi.stock_enabled_flag,
5778          ' ',
5779          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
5780         from po_lines_trx_v pol -- CLM project, bug 9403291
5781         ,mtl_related_items mri
5782         ,mtl_system_items_vl msi /* Bug 5581528 */
5783         /*,mtl_system_items_kfv msia*/ /* Bug 6334679 */
5784         where msi.organization_id =  p_organization_id
5785         and msi.concatenated_segments like  p_concatenated_segments||l_append
5786         and pol.po_header_id = p_poHeaderID
5787         and pol.item_id = mri.inventory_item_id /* Condition changed by Bug10124916 */
5788         and msi.organization_id = p_organization_id
5789         and ((    mri.related_item_id = msi.inventory_item_id
5790         and pol.item_id = mri.inventory_item_id) or
5791         (    mri.inventory_item_id = msi.inventory_item_id
5792         and pol.item_id = mri.related_item_id
5793         and mri.reciprocal_flag = 'Y'))
5794         and pol.po_line_id = p_poLineID
5795         and exists (select 1
5796                      from  po_line_locations_trx_v pll -- CLM project, bug 9403291
5797 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
5798                          , mtl_parameters mp,
5799                            rcv_parameters rp
5800 --  End for Bug 7440217
5801                      where NVL(pll.closed_code,'OPEN')
5802                      not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')  -- 3687249
5803 --  For Bug 7440217 Checking if it is LCM enabled
5804                      AND mp.organization_id = p_organization_id
5805                      AND rp.organization_id = p_organization_id
5806                      AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
5807                            OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
5808                                OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
5809                         )
5810 --  End for Bug 7440217
5811                      and   Nvl(pll.allow_substitute_receipts_flag, 'N') = 'Y'
5812                      and   pll.po_header_id = pol.po_header_id
5813                      and   pll.po_line_id = pol.po_line_id
5814                      and   pll.ship_to_organization_id = p_Organization_Id)--Bug 3972931-Added the filter condition based on ship_to_organization_id
5815         UNION ALL
5816         -- Vendor Item SQL
5817         -- Bug# 6747729
5818         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
5819         select distinct pol.vendor_product_num,
5820         msi.inventory_item_id,
5821         Nvl(pol.item_description, msi.description),  -- Bug 14645109
5822         Nvl(msi.revision_qty_control_code,1),
5823         Nvl(msi.lot_control_code, 1),
5824         Nvl(msi.serial_number_control_code, 1),
5825         Nvl(msi.restrict_subinventories_code, 2),
5826         Nvl(msi.restrict_locators_code,2),
5827         Nvl(msi.location_control_code,1),
5828         msi.primary_uom_code,
5829         Nvl(msi.inspection_required_flag,'N'),
5830         Nvl(msi.shelf_life_code, 1),
5831         Nvl(msi.shelf_life_days,0),
5832         Nvl(msi.allowed_units_lookup_code, 2),
5833         Nvl(msi.effectivity_control,1),
5834         0,
5835         0,
5836         Nvl(msi.default_serial_status_id,1),
5837         Nvl(msi.serial_status_enabled,'N'),
5838         Nvl(msi.default_lot_status_id,0),
5839         Nvl(msi.lot_status_enabled,'N'),
5840         msi.concatenated_segments,
5841         'Y',
5842         msi.inventory_item_flag,
5843         0,
5844 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
5845         msi.inventory_asset_flag,
5846         msi.outside_operation_flag ,
5847          --Bug 3952081
5848          --Select DUOM Attributes for every Item
5849          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
5850          NVL(MSI.DEFAULT_GRADE,''),
5851          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
5852          NVL(MSI.EXPIRATION_ACTION_CODE,''),
5853          NVL(MSI.HOLD_DAYS,0),
5854          NVL(MSI.MATURITY_DAYS,0),
5855          NVL(MSI.RETEST_INTERVAL,0),
5856          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
5857          NVL(MSI.CHILD_LOT_FLAG,'N'),
5858          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
5859          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
5860          NVL(MSI.SECONDARY_UOM_CODE,''),
5861          NVL(MSI.SECONDARY_DEFAULT_IND,''),
5862          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
5863          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
5864          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
5865          msi.stock_enabled_flag,
5866          ' ',
5867          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
5868         from po_lines_trx_v pol  -- CLM project, bug 9403291
5869         ,mtl_system_items_vl msi  /* Bug 5581528 */
5870         where organization_id =  p_organization_id
5871         and pol.vendor_product_num like  p_concatenated_segments
5872         and pol.item_id = msi.inventory_item_id
5873         and  pol.vendor_product_num IS NOT NULL
5874         and pol.po_header_id =  p_poHeaderID
5875         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
5876         and inventory_item_id IN (SELECT pl.item_id FROM po_lines_trx_v pl -- CLM project, bug 9403291
5877         WHERE pl.po_header_id = p_poHeaderID
5878         and pl.po_line_id = p_poLineID
5879         and exists (select 1
5880                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
5881 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
5882                          , mtl_parameters mp,
5883                            rcv_parameters rp
5884 --  End for Bug 7440217
5885                       where NVL(pll.closed_code, 'OPEN')
5886                       not in ('FINALLY CLOSED' , 'CLOSED FOR RECEIVING', 'CLOSED' )  -- 3687249
5887 --  For Bug 7440217 Checking if it is LCM enabled
5888                       AND mp.organization_id = p_organization_id
5889                       AND rp.organization_id = p_organization_id
5890                       AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
5891                             OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
5892                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
5893                      )
5894 --  End for Bug 7440217
5895                       and  pll.po_header_id = p_poHeaderID
5896                       and pll.po_line_id = p_poLineID
5897                       and pll.ship_to_organization_id = p_Organization_Id)--Bug 3972931-Added the filter condition based on ship_to_organization_id
5898   )
5899         UNION ALL
5900         -- non item Master
5901         -- Bug# 6747729
5902         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
5903         select distinct pol.item_description,
5904         to_number(''),
5905         pol.item_description,
5906         1,
5907         1,
5908         1,
5909         2,
5910         2,
5911         1,
5912         mum.uom_code,
5913         'N',
5914         1,
5915         0,
5916         2,
5917         1,
5918         0,
5919         0,
5920         1,
5921         'N',
5922         0,
5923         'N',
5924         '',
5925         'N',
5926         'N',
5927         0,
5928 	  wms_deploy.get_item_client_name(pol.item_id),
5929         to_char(NULL),
5930         'N' ,
5931          --Bug 3952081
5932          --Select DUOM Attributes for every Item
5933          'N',
5934          '',
5935          0,
5936          '',
5937          0,
5938          0,
5939          0,
5940          'N',
5941          'N',
5942          'N',
5943          'Y',
5944          '',
5945          '',
5946          'P',
5947          0,
5948          0,
5949         'N',
5950          ' ',
5951          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
5952         from po_lines_trx_v pol -- CLM project, bug 9403291
5953         , mtl_units_of_measure mum
5954   -- Bug 2619063, 2614016
5955   -- Modified to select the base uom for the uom class defined on po.
5956   where mum.uom_class = (SELECT mum2.uom_class
5957                FROM mtl_units_of_measure mum2
5958               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
5959         and mum.base_uom_flag = 'Y'
5960         and pol.ITEM_ID is null
5961         and pol.item_description is not null
5962         and pol.po_header_id = p_poHeaderID
5963         and pol.item_description like  p_concatenated_segments
5964 		and pol.po_line_id = p_poLineID
5965         /* Bug 3972931-Added the following exists condition to restrict the PO receipt
5966         to shipments due to be received only in the organizationientered with.*/
5967         and exists (select 1
5968                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
5969 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
5970                          , mtl_parameters mp,
5971                            rcv_parameters rp
5972 --  End for Bug 7440217
5973                      where pll.po_header_id = p_poHeaderID
5974 --  For Bug 7440217 Checking if it is LCM enabled
5975                        AND mp.organization_id = p_organization_id
5976                        AND rp.organization_id = p_organization_id
5977                        AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
5978                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
5979                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
5980                         )
5981 --  End for Bug 7440217
5982                        and pll.po_line_id = pol.po_line_id
5983                        and pll.ship_to_organization_id = p_Organization_Id)
5984         --End of fix for Bug 3972931
5985         UNION ALL
5986         -- Cross Ref  SQL
5987         -- Bug# 6747729
5988         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
5989         select distinct mcr.cross_reference,
5990         msi.inventory_item_id,
5991         Nvl(pol.item_description, msi.description),  -- Bug 14645109
5992         Nvl(msi.revision_qty_control_code,1),
5993         Nvl(msi.lot_control_code, 1),
5994         Nvl(msi.serial_number_control_code, 1),
5995         Nvl(msi.restrict_subinventories_code, 2),
5996         Nvl(msi.restrict_locators_code,2),
5997         Nvl(msi.location_control_code,1),
5998         msi.primary_uom_code,
5999         Nvl(msi.inspection_required_flag,'N'),
6000         Nvl(msi.shelf_life_code, 1),
6001         Nvl(msi.shelf_life_days,0),
6002         Nvl(msi.allowed_units_lookup_code, 2),
6003         Nvl(msi.effectivity_control,1),
6004         0,
6005         0,
6006         Nvl(msi.default_serial_status_id,1),
6007         Nvl(msi.serial_status_enabled,'N'),
6008         Nvl(msi.default_lot_status_id,0),
6009         Nvl(msi.lot_status_enabled,'N'),
6010         msi.concatenated_segments,
6011         'C',
6012         msi.inventory_item_flag,
6013         0,
6014 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
6015         msi.inventory_asset_flag,
6016         msi.outside_operation_flag,
6017          --Bug 3952081
6018          --Select DUOM Attributes for every Item
6019          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
6020          NVL(MSI.DEFAULT_GRADE,''),
6021          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
6022          NVL(MSI.EXPIRATION_ACTION_CODE,''),
6023          NVL(MSI.HOLD_DAYS,0),
6024          NVL(MSI.MATURITY_DAYS,0),
6025          NVL(MSI.RETEST_INTERVAL,0),
6026          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
6027          NVL(MSI.CHILD_LOT_FLAG,'N'),
6028          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
6029          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
6030          NVL(MSI.SECONDARY_UOM_CODE,''),
6031          NVL(MSI.SECONDARY_DEFAULT_IND,''),
6032          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
6033          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
6034          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
6035         msi.stock_enabled_flag,
6036          ' ',
6037          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
6038         from po_lines_trx_v pol -- CLM project, bug 9403291
6039         ,mtl_system_items_vl msi /* Bug 5581528 */
6040         ,mtl_cross_references mcr
6041         where msi.organization_id = p_organization_id
6042         and ( (mcr.cross_reference_type = p_crossreftype
6043                and mcr.cross_reference like  p_concatenated_segments
6044               ) or
6045               ( mcr.cross_reference_type = g_gtin_cross_ref_type
6046                AND mcr.cross_reference      LIKE g_crossref )
6047             )
6048         and ( (mcr.org_independent_flag = 'Y') or (mcr.org_independent_flag = 'N'
6049         and mcr.organization_id = p_organization_id
6050                ) )
6051         and mcr.inventory_item_id = msi.inventory_item_id
6052         and pol.item_id = msi.inventory_item_id
6053         and pol.po_header_id = p_poHeaderID
6054         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
6055         and msi.inventory_item_id IN (SELECT pl.item_id FROM po_lines_trx_v pl -- CLM project, bug 9403291
6056         WHERE pl.po_header_id = p_poHeaderID
6057         and pl.po_line_id = p_poLineID
6058         and exists (select 1
6059                       from po_line_locations_trx_v pll  -- CLM project, bug 9403291
6060 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
6061                          , mtl_parameters mp,
6062                            rcv_parameters rp
6063 --  End for Bug 7440217
6064                      where NVL(pll.closed_code, 'OPEN')
6065                      not in ('FINALLY CLOSED' , 'CLOSED FOR RECEIVING', 'CLOSED' ) -- 3687249
6066 --  For Bug 7440217 Checking if it is LCM enabled
6067                      AND mp.organization_id = p_organization_id
6068                      AND rp.organization_id = p_organization_id
6069                      AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
6070                            OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
6071                                OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
6072                         )
6073 --  End for Bug 7440217
6074                      and  pll.po_header_id = p_poHeaderID
6075                      and pll.po_line_id = p_poLineID
6076                      and pll.ship_to_organization_id = p_Organization_Id)--Bug 3972931-Added the filter condition based on ship_to_organization_id
6077         )
6078 		/* Bug 12348588 When use mobile to receive PO, item lov not display supplier item for one time item.
6079                That is because there is no record in item table: mtl_system_items_vl when the item is one time item.
6080 			   Now, we do not join the item table when the item id is null in the po lines table.*/
6081 
6082 		UNION ALL
6083 		select distinct pol.vendor_product_num,
6084         to_number(''),
6085         pol.item_description,
6086         1,
6087         1,
6088         1,
6089         2,
6090         2,
6091         1,
6092         mum.uom_code,
6093         'N',
6094         1,
6095         0,
6096         2,
6097         1,
6098         0,
6099         0,
6100         1,
6101         'N',
6102         0,
6103         'N',
6104         pol.item_description,
6105         'Y',
6106         'N',
6107         0,
6108 	  wms_deploy.get_item_client_name(pol.item_id),
6109         to_char(NULL),
6110         'N' ,
6111          --Bug 3952081
6112          --Select DUOM Attributes for every Item
6113          'N',
6114          '',
6115          0,
6116          '',
6117          0,
6118          0,
6119          0,
6120          'N',
6121          'N',
6122          'N',
6123          'Y',
6124          '',
6125          '',
6126          'P',
6127          0,
6128          0,
6129         'N',
6130          ' ',
6131          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
6132         from po_lines_trx_v pol -- CLM project, bug 9403291
6133         , mtl_units_of_measure mum
6134   -- Bug 2619063, 2614016
6135   -- Modified to select the base uom for the uom class defined on po.
6136   where mum.uom_class = (SELECT mum2.uom_class
6137                FROM mtl_units_of_measure mum2
6138               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
6139         and mum.base_uom_flag = 'Y'
6140         and pol.ITEM_ID is null
6141         and pol.vendor_product_num is not null
6142         and pol.po_header_id = p_poHeaderID
6143         and pol.vendor_product_num like  p_concatenated_segments
6144 		and pol.po_line_id = p_poLineID
6145         /* Bug 3972931-Added the following exists condition to restrict the PO receipt
6146         to shipments due to be received only in the organizationientered with.*/
6147         and exists (select 1
6148                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
6149 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
6150                          , mtl_parameters mp,
6151                            rcv_parameters rp
6152 --  End for Bug 7440217
6153                      where pll.po_header_id = p_poHeaderID
6154 --  For Bug 7440217 Checking if it is LCM enabled
6155                        AND mp.organization_id = p_organization_id
6156                        AND rp.organization_id = p_organization_id
6157                        AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
6158                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
6159                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
6160                         )
6161 --  End for Bug 7440217
6162                        and pll.po_line_id = pol.po_line_id
6163                        and pll.ship_to_organization_id = p_Organization_Id)
6164     /* End of fix for Bug 12348588 */
6165         ;
6166       else
6167 -- *****************************
6168 --      Deafult headerBased  Tran
6169 -- ***************************
6170 
6171         open x_Items for
6172         -- Bug# 6747729
6173         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
6174         select concatenated_segments,
6175         inventory_item_id,
6176         description,
6177         Nvl(revision_qty_control_code,1),
6178         Nvl(lot_control_code, 1),
6179         Nvl(serial_number_control_code, 1),
6180         Nvl(restrict_subinventories_code, 2),
6181         Nvl(restrict_locators_code, 2),
6182         Nvl(location_control_code, 1),
6183         primary_uom_code,
6184         Nvl(inspection_required_flag, 'N'),
6185         Nvl(shelf_life_code, 1),
6186         Nvl(shelf_life_days,0),
6187         Nvl(allowed_units_lookup_code, 2),
6188         Nvl(effectivity_control,1),
6189         0,
6190         0,
6191         Nvl(default_serial_status_id,1),
6192         Nvl(serial_status_enabled,'N'),
6193         Nvl(default_lot_status_id,0),
6194         Nvl(lot_status_enabled,'N'),
6195         '',
6196         'N',
6197         inventory_item_flag,
6198         0,
6199 	  wms_deploy.get_item_client_name(inventory_item_id),
6200         inventory_asset_flag,
6201         outside_operation_flag,
6202          --Bug 3952081
6203          --Select DUOM Attributes for every Item
6204          NVL(GRADE_CONTROL_FLAG,'N'),
6205          NVL(DEFAULT_GRADE,''),
6206          NVL(EXPIRATION_ACTION_INTERVAL,0),
6207          NVL(EXPIRATION_ACTION_CODE,''),
6208          NVL(HOLD_DAYS,0),
6209          NVL(MATURITY_DAYS,0),
6210          NVL(RETEST_INTERVAL,0),
6211          NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
6212          NVL(CHILD_LOT_FLAG,'N'),
6213          NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
6214          NVL(LOT_DIVISIBLE_FLAG,'Y'),
6215          NVL(SECONDARY_UOM_CODE,''),
6216          NVL(SECONDARY_DEFAULT_IND,''),
6217          NVL(TRACKING_QUANTITY_IND,'P'),
6218          NVL(DUAL_UOM_DEVIATION_HIGH,0),
6219          NVL(DUAL_UOM_DEVIATION_LOW,0),
6220         stock_enabled_flag,
6221          ' ',
6222          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
6223         from mtl_system_items_vl /* Bug 5581528 */
6224         WHERE organization_id = p_Organization_Id
6225         and concatenated_segments like p_concatenated_segments||l_append
6226         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
6227         and inventory_item_id IN
6228         ( SELECT pl.item_id FROM po_lines_trx_v pl -- CLM project, bug 9403291
6229         WHERE pl.po_header_id = p_poHeaderID
6230         and exists (select 1
6231                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
6232 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
6233                          , mtl_parameters mp,
6234                            rcv_parameters rp
6235 --  End for Bug 7440217
6236                       where NVL(pll.closed_code,'OPEN')
6237                       not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')   -- 3687249
6238 --  For Bug 7440217 Checking if it is LCM enabled
6239                       AND mp.organization_id = p_organization_id
6240                       AND rp.organization_id = p_organization_id
6241                       AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
6242                             OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
6243                                 OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
6244                            )
6245 --  End for Bug 7440217
6246                       and  pll.po_header_id = p_poHeaderID
6247                       and pll.po_line_id = pl.po_line_id
6248                       and pll.ship_to_organization_id = p_Organization_Id)--Bug 3972931-Added the filter condition based on ship_to_organization_id
6249         )
6250         UNION ALL
6251         -- Substitute Item SQL
6252         -- Bug# 6747729
6253         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
6254         select distinct msi.concatenated_segments,
6255         msi.inventory_item_id,
6256 		Nvl(pol.item_description, msi.description),  -- Bug 14645109 s
6257         Nvl(msi.revision_qty_control_code,1),
6258         Nvl(msi.lot_control_code, 1),
6259         Nvl(msi.serial_number_control_code, 1),
6260         Nvl(msi.restrict_subinventories_code, 2),
6261         Nvl(msi.restrict_locators_code,2),
6262         Nvl(msi.location_control_code,1),
6263         msi.primary_uom_code,
6264         Nvl(msi.inspection_required_flag,'N'),
6265         Nvl(msi.shelf_life_code, 1),
6266         Nvl(msi.shelf_life_days,0),
6267         Nvl(msi.allowed_units_lookup_code, 2),
6268         Nvl(msi.effectivity_control,1),
6269         0,
6270         0,
6271         Nvl(msi.default_serial_status_id,1),
6272         Nvl(msi.serial_status_enabled,'N'),
6273         Nvl(msi.default_lot_status_id,0),
6274         Nvl(msi.lot_status_enabled,'N'),
6275         msi.concatenated_segments,
6276         'S',
6277         msi.inventory_item_flag,
6278         0,
6279 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
6280         msi.inventory_asset_flag,
6281         msi.outside_operation_flag ,
6282          --Bug 3952081
6283          --Select DUOM Attributes for every Item
6284          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
6285          NVL(MSI.DEFAULT_GRADE,''),
6286          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
6287          NVL(MSI.EXPIRATION_ACTION_CODE,''),
6288          NVL(MSI.HOLD_DAYS,0),
6289          NVL(MSI.MATURITY_DAYS,0),
6290          NVL(MSI.RETEST_INTERVAL,0),
6291          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
6292          NVL(MSI.CHILD_LOT_FLAG,'N'),
6293          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
6294          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
6295          NVL(MSI.SECONDARY_UOM_CODE,''),
6296          NVL(MSI.SECONDARY_DEFAULT_IND,''),
6297          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
6298          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
6299          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
6300         msi.stock_enabled_flag,
6301          ' ',
6302          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
6303         from po_lines_trx_v pol -- CLM project, bug 9403291
6304         ,mtl_related_items mri
6305         ,mtl_system_items_vl msi /* Bug 5581528 */
6306        /*,mtl_system_items_kfv msia */ /* Bug 6334679 */
6307         where msi.organization_id =  p_organization_id
6308         and msi.concatenated_segments like  p_concatenated_segments||l_append
6309         and pol.po_header_id = p_poHeaderID
6310         and pol.item_id = mri.inventory_item_id /* Condition changed by Bug10124916 */
6311         and msi.organization_id = p_organization_id
6312         and ((    mri.related_item_id = msi.inventory_item_id
6313         and pol.item_id = mri.inventory_item_id) or
6314         (    mri.inventory_item_id = msi.inventory_item_id
6315         and pol.item_id = mri.related_item_id
6316         and mri.reciprocal_flag = 'Y'))
6317         and exists (select 1
6318                      from  po_line_locations_trx_v pll -- CLM project, bug 9403291
6319 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
6320                          , mtl_parameters mp,
6321                            rcv_parameters rp
6322 --  End for Bug 7440217
6323                      where NVL(pll.closed_code,'OPEN')
6324                      not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')  -- 3687249
6325 --  For Bug 7440217 Checking if it is LCM enabled
6326                      AND mp.organization_id = p_organization_id
6327                      AND rp.organization_id = p_organization_id
6328                      AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
6329                            OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
6330                                OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
6331                          )
6332 --  End for Bug 7440217
6333                      and   Nvl(pll.allow_substitute_receipts_flag, 'N') = 'Y'
6334                      and   pll.po_header_id = pol.po_header_id
6335                      and   pll.po_line_id = pol.po_line_id
6336                      and   pll.ship_to_organization_id = p_Organization_Id)--Bug 3972931-Added the filter condition based on ship_to_organization_id
6337         UNION ALL
6338         -- Vendor Item SQL
6339         -- Bug# 6747729
6340         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
6341         select distinct pol.vendor_product_num,
6342         msi.inventory_item_id,
6343         Nvl(pol.item_description, msi.description),  -- Bug 14645109 s
6344         Nvl(msi.revision_qty_control_code,1),
6345         Nvl(msi.lot_control_code, 1),
6346         Nvl(msi.serial_number_control_code, 1),
6347         Nvl(msi.restrict_subinventories_code, 2),
6348         Nvl(msi.restrict_locators_code,2),
6349         Nvl(msi.location_control_code,1),
6350         msi.primary_uom_code,
6351         Nvl(msi.inspection_required_flag,'N'),
6352         Nvl(msi.shelf_life_code, 1),
6353         Nvl(msi.shelf_life_days,0),
6354         Nvl(msi.allowed_units_lookup_code, 2),
6355         Nvl(msi.effectivity_control,1),
6356         0,
6357         0,
6358         Nvl(msi.default_serial_status_id,1),
6359         Nvl(msi.serial_status_enabled,'N'),
6360         Nvl(msi.default_lot_status_id,0),
6361         Nvl(msi.lot_status_enabled,'N'),
6362         msi.concatenated_segments,
6363         'Y',
6364         msi.inventory_item_flag,
6365         0,
6366 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
6367         msi.inventory_asset_flag,
6368         msi.outside_operation_flag ,
6369          --Bug 3952081
6370          --Select DUOM Attributes for every Item
6371          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
6372          NVL(MSI.DEFAULT_GRADE,''),
6373          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
6374          NVL(MSI.EXPIRATION_ACTION_CODE,''),
6375          NVL(MSI.HOLD_DAYS,0),
6376          NVL(MSI.MATURITY_DAYS,0),
6377          NVL(MSI.RETEST_INTERVAL,0),
6378          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
6379          NVL(MSI.CHILD_LOT_FLAG,'N'),
6380          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
6381          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
6382          NVL(MSI.SECONDARY_UOM_CODE,''),
6383          NVL(MSI.SECONDARY_DEFAULT_IND,''),
6384          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
6385          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
6386          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
6387         msi.stock_enabled_flag,
6388          ' ',
6389          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
6390         from po_lines_trx_v pol  -- CLM project, bug 9403291
6391         , mtl_system_items_vl msi  /* Bug 5581528 */
6392         where organization_id =  p_organization_id
6393         and pol.vendor_product_num like  p_concatenated_segments
6394         and pol.item_id = msi.inventory_item_id
6395         and  pol.vendor_product_num IS NOT NULL
6396         and pol.po_header_id =  p_poHeaderID
6397         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
6398         and inventory_item_id IN
6399         ( SELECT pl.item_id FROM po_lines_trx_v pl -- CLM project, bug 9403291
6400         WHERE pl.po_header_id = p_poHeaderID
6401         and exists (select 1
6402                        from po_line_locations_trx_v pll -- CLM project, bug 9403291
6403 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
6404                           , mtl_parameters mp,
6405                             rcv_parameters rp
6406 --  End for Bug 7440217
6407                        where NVL(pll.closed_code,'OPEN')
6408                        not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')   -- 3687249
6409 --  For Bug 7440217 Checking if it is LCM enabled
6410                        AND mp.organization_id = p_organization_id
6411                        AND rp.organization_id = p_organization_id
6412                        AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
6413                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
6414                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
6415                            )
6416 --  End for Bug 7440217
6417                        and  pll.po_header_id = p_poHeaderID
6418                        and pll.po_line_id = pl.po_line_id
6419                        and pll.ship_to_organization_id = p_Organization_Id)--Bug 3972931-Added the filter condition based on ship_to_organization_id
6420         )
6421         UNION ALL
6422         -- non item Master
6423         -- Bug# 6747729
6424         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
6425         select distinct pol.item_description,
6426         to_number(''),
6427         pol.item_description,
6428         1,
6429         1,
6430         1,
6431         2,
6432         2,
6433         1,
6434         mum.uom_code,
6435         'N',
6436         1,
6437         0,
6438         2,
6439         1,
6440         0,
6441         0,
6442         1,
6443         'N',
6444         0,
6445         'N',
6446         '',
6447         'N',
6448         'N',
6449         0,
6450 	  wms_deploy.get_item_client_name(pol.item_id),
6451         to_char(NULL),
6452         'N' ,
6453          --Bug 3952081
6454          --Select DUOM Attributes for every Item
6455          'N',
6456          '',
6457          0,
6458          '',
6459          0,
6460          0,
6461          0,
6462          'N',
6463          'N',
6464          'N',
6465          'Y',
6466          '',
6467          '',
6468          'P',
6469          0,
6470          0,
6471         'N',
6472          ' ',
6473          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
6474         from po_lines_trx_v pol -- CLM project, bug 9403291
6475         , mtl_units_of_measure mum
6476   -- Bug 2619063, 2614016
6477   -- Modified to select the base uom for the uom class defined on po.
6478   where mum.uom_class = (SELECT mum2.uom_class
6479                FROM mtl_units_of_measure mum2
6480               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
6481         and mum.base_uom_flag = 'Y'
6482         and pol.ITEM_ID is null
6483         and pol.item_description is not null
6484         and pol.po_header_id = p_poHeaderID
6485         and pol.item_description like  p_concatenated_segments
6486         /* Bug 3972931-Added the following exists condition to restrict the PO receipt
6487         to shipments due to be received only in the organizationientered with.*/
6488         and exists (select 1
6489                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
6490 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
6491                          , mtl_parameters mp,
6492                            rcv_parameters rp
6493 --  End for Bug 7440217
6494                      where pll.po_header_id = p_poHeaderID
6495 --  For Bug 7440217 Checking if it is LCM enabled
6496                        AND mp.organization_id = p_organization_id
6497                        AND rp.organization_id = p_organization_id
6498                        AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
6499                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
6500                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
6501                         )
6502 --  End for Bug 7440217
6503                        and pll.po_line_id = pol.po_line_id
6504                        and pll.ship_to_organization_id = p_Organization_Id)
6505         --End of fix for Bug 3972931
6506         UNION ALL
6507         -- Cross Ref  SQL
6508         -- Bug# 6747729
6509         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
6510         select distinct mcr.cross_reference,
6511         msi.inventory_item_id,
6512         msi.description,
6513         Nvl(msi.revision_qty_control_code,1),
6514         Nvl(msi.lot_control_code, 1),
6515         Nvl(msi.serial_number_control_code, 1),
6516         Nvl(msi.restrict_subinventories_code, 2),
6517         Nvl(msi.restrict_locators_code,2),
6518         Nvl(msi.location_control_code,1),
6519         msi.primary_uom_code,
6520         Nvl(msi.inspection_required_flag,'N'),
6521         Nvl(msi.shelf_life_code, 1),
6522         Nvl(msi.shelf_life_days,0),
6523         Nvl(msi.allowed_units_lookup_code, 2),
6524         Nvl(msi.effectivity_control,1),
6525         0,
6526         0,
6527         Nvl(msi.default_serial_status_id,1),
6528         Nvl(msi.serial_status_enabled,'N'),
6529         Nvl(msi.default_lot_status_id,0),
6530         Nvl(msi.lot_status_enabled,'N'),
6531         msi.concatenated_segments,
6532         'C',
6533         msi.inventory_item_flag,
6534         0,
6535 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
6536         msi.inventory_asset_flag,
6537         msi.outside_operation_flag,
6538          --Bug 3952081
6539          --Select DUOM Attributes for every Item
6540          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
6541          NVL(MSI.DEFAULT_GRADE,''),
6542          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
6543          NVL(MSI.EXPIRATION_ACTION_CODE,''),
6544          NVL(MSI.HOLD_DAYS,0),
6545          NVL(MSI.MATURITY_DAYS,0),
6546          NVL(MSI.RETEST_INTERVAL,0),
6547          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
6548          NVL(MSI.CHILD_LOT_FLAG,'N'),
6549          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
6550          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
6551          NVL(MSI.SECONDARY_UOM_CODE,''),
6552          NVL(MSI.SECONDARY_DEFAULT_IND,''),
6553          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
6554          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
6555          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
6556         msi.stock_enabled_flag,
6557          ' ',
6558          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
6559         from po_lines_trx_v pol -- CLM project, bug 9403291
6560         ,mtl_system_items_vl msi /* Bug 5581528 */
6561         ,mtl_cross_references mcr
6562         where msi.organization_id = p_organization_id
6563         and ( (mcr.cross_reference_type = p_crossreftype
6564                and mcr.cross_reference like  p_concatenated_segments
6565               ) or
6566               ( mcr.cross_reference_type = g_gtin_cross_ref_type
6567                AND mcr.cross_reference      LIKE g_crossref )
6568             )
6569         and ( (mcr.org_independent_flag = 'Y') or (mcr.org_independent_flag = 'N'
6570         and mcr.organization_id = p_organization_id
6571                ) )
6572         and mcr.inventory_item_id = msi.inventory_item_id
6573         and pol.item_id = msi.inventory_item_id
6574         and pol.po_header_id = p_poHeaderID
6575         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
6576         and msi.inventory_item_id IN
6577         ( SELECT pl.item_id FROM po_lines_trx_v pl -- CLM project, bug 9403291
6578         WHERE pl.po_header_id = p_poHeaderID
6579         and exists (select 1
6580                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
6581 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
6582                          , mtl_parameters mp,
6583                            rcv_parameters rp
6584 --  End for Bug 7440217
6585                      where NVL(pll.closed_code,'OPEN')
6586                      not in ('FINALLY CLOSED', 'CLOSED FOR RECEIVING', 'CLOSED')   -- 3687249
6587 --  For Bug 7440217 Checking if it is LCM enabled
6588                      AND mp.organization_id = p_organization_id
6589                      AND rp.organization_id = p_organization_id
6590                      AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
6591                            OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
6592                                 OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
6593                         )
6594 --  End for Bug 7440217
6595                       and  pll.po_header_id = p_poHeaderID
6596                       and pll.po_line_id = pl.po_line_id
6597                       and pll.ship_to_organization_id = p_Organization_Id)--Bug 3972931-Added the filter condition based on ship_to_organization_id
6598         )
6599           /* Bug 12348588 When use mobile to receive PO, item lov not display supplier item for one time item.
6600                That is because there is no record in item table: mtl_system_items_vl when the item is one time item.
6601 			   Now, we do not join the item table when the item id is null in the po lines table.*/
6602 
6603 		UNION ALL
6604 		select distinct pol.vendor_product_num,
6605         to_number(''),
6606         pol.item_description,
6607         1,
6608         1,
6609         1,
6610         2,
6611         2,
6612         1,
6613         mum.uom_code,
6614         'N',
6615         1,
6616         0,
6617         2,
6618         1,
6619         0,
6620         0,
6621         1,
6622         'N',
6623         0,
6624         'N',
6625         pol.item_description,
6626         'Y',
6627         'N',
6628         0,
6629 	  wms_deploy.get_item_client_name(pol.item_id),
6630         to_char(NULL),
6631         'N' ,
6632          --Bug 3952081
6633          --Select DUOM Attributes for every Item
6634          'N',
6635          '',
6636          0,
6637          '',
6638          0,
6639          0,
6640          0,
6641          'N',
6642          'N',
6643          'N',
6644          'Y',
6645          '',
6646          '',
6647          'P',
6648          0,
6649          0,
6650         'N',
6651          ' ',
6652          ' ' -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
6653         from po_lines_trx_v pol -- CLM project, bug 9403291
6654         , mtl_units_of_measure mum
6655   -- Bug 2619063, 2614016
6656   -- Modified to select the base uom for the uom class defined on po.
6657   where mum.uom_class = (SELECT mum2.uom_class
6658                FROM mtl_units_of_measure mum2
6659               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
6660         and mum.base_uom_flag = 'Y'
6661         and pol.ITEM_ID is null
6662         and pol.vendor_product_num is not null
6663         and pol.po_header_id = p_poHeaderID
6664         and pol.vendor_product_num like  p_concatenated_segments
6665         /* Bug 3972931-Added the following exists condition to restrict the PO receipt
6666         to shipments due to be received only in the organizationientered with.*/
6667         and exists (select 1
6668                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
6669 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
6670                          , mtl_parameters mp,
6671                            rcv_parameters rp
6672 --  End for Bug 7440217
6673                      where pll.po_header_id = p_poHeaderID
6674 --  For Bug 7440217 Checking if it is LCM enabled
6675                        AND mp.organization_id = p_organization_id
6676                        AND rp.organization_id = p_organization_id
6677                        AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
6678                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
6679                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
6680                         )
6681 --  End for Bug 7440217
6682                        and pll.po_line_id = pol.po_line_id
6683                        and pll.ship_to_organization_id = p_Organization_Id)
6684     /* End of fix for Bug 12348588 */
6685         ;
6686 
6687       end if;
6688 
6689 -- *****************************
6690 -- End of not PJM Based Tran
6691 -- *****************************
6692 
6693 end if;
6694 
6695 -- *****************************
6696 --- END OF PO HEADER  ID SECTION
6697 -- *****************************
6698 
6699 elsif  (p_shipmentHeaderID is not null ) then
6700 -- *****************************
6701 --- START  OF SHIPMENT HEADER  ID SECTION
6702 -- *****************************
6703 
6704   IF (l_from_lpn_id IS NOT NULL)  THEN --Bug13016935
6705       open x_Items for
6706       -- Bug# 6747729
6707       -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
6708       select distinct concatenated_segments,
6709        msn.inventory_item_id,
6710 	   Nvl(rsl.item_description, msn.description) ,  -- Bug 14645109
6711        Nvl(revision_qty_control_code,1),
6712        Nvl(lot_control_code, 1),
6713        Nvl(serial_number_control_code, 1),
6714        Nvl(restrict_subinventories_code, 2),
6715        Nvl(restrict_locators_code, 2),
6716        Nvl(location_control_code, 1),
6717        primary_uom_code,
6718        Nvl(inspection_required_flag, 'N'),
6719        Nvl(shelf_life_code, 1),
6720        Nvl(shelf_life_days,0),
6721        Nvl(allowed_units_lookup_code, 2),
6722        Nvl(effectivity_control,1),
6723        0,
6724        0,
6725        Nvl(default_serial_status_id,1),
6726        Nvl(serial_status_enabled,'N'),
6727        Nvl(default_lot_status_id,0),
6728        Nvl(lot_status_enabled,'N'),
6729        '',
6730        'N',
6731        inventory_item_flag,
6732        0,
6733 	  wms_deploy.get_item_client_name(msn.inventory_item_id),
6734        inventory_asset_flag,
6735        outside_operation_flag,
6736          --Bug 3952081
6737          --Select DUOM Attributes for every Item
6738          NVL(GRADE_CONTROL_FLAG,'N'),
6739          NVL(DEFAULT_GRADE,''),
6740          NVL(EXPIRATION_ACTION_INTERVAL,0),
6741          NVL(EXPIRATION_ACTION_CODE,''),
6742          NVL(HOLD_DAYS,0),
6743          NVL(MATURITY_DAYS,0),
6744          NVL(RETEST_INTERVAL,0),
6745          NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
6746          NVL(CHILD_LOT_FLAG,'N'),
6747          NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
6748          NVL(LOT_DIVISIBLE_FLAG,'Y'),
6749          NVL(msn.SECONDARY_UOM_CODE,''),
6750          NVL(SECONDARY_DEFAULT_IND,''),
6751          NVL(TRACKING_QUANTITY_IND,'P'),
6752          NVL(DUAL_UOM_DEVIATION_HIGH,0),
6753          NVL(DUAL_UOM_DEVIATION_LOW,0),
6754          stock_enabled_flag,
6755          DECODE (p_reqHeaderID,to_char(null),' ', rsh.shipment_num),
6756          DECODE (p_reqHeaderID,to_char(null),' ',p_shipmentHeaderID) -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
6757        from wms_lpn_contents wlc ,
6758 	        mtl_system_items_vl msn, /* Bug 5581528 */
6759             rcv_shipment_lines rsl,
6760             rcv_shipment_headers rsh /* Added for Bug9257750 */
6761        WHERE msn.organization_id = p_Organization_Id
6762 	   and wlc.parent_lpn_id = l_from_lpn_id
6763        and wlc.inventory_item_id = rsl.item_id
6764        and msn.concatenated_segments like p_concatenated_segments||l_append
6765        and (msn.purchasing_enabled_flag = 'Y' OR msn.stock_enabled_flag = 'Y')
6766        and rsl.SHIPMENT_HEADER_ID = p_shipmentHeaderID
6767        and rsh.SHIPMENT_HEADER_ID = rsl.SHIPMENT_HEADER_ID /* Added for Bug9257750 */
6768        -- This was fix for bug 2740648/2752094
6769        AND rsl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED')
6770        AND rsl.to_organization_id= p_Organization_Id--Bug 3972931-Added the condiotn to filter based on organization_id
6771        and rsl.item_id = msn.inventory_item_id
6772 
6773       UNION
6774     -- bug 2775596
6775     -- added unions for the substitute item and vendor item
6776     -- if receiving an ASN.
6777         -- Vendor Item SQL
6778         -- Bug# 6747729
6779         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
6780         select distinct pol.vendor_product_num,
6781         msi.inventory_item_id,
6782 		msi.description,
6783         Nvl(msi.revision_qty_control_code,1),
6784         Nvl(msi.lot_control_code, 1),
6785         Nvl(msi.serial_number_control_code, 1),
6786         Nvl(msi.restrict_subinventories_code, 2),
6787         Nvl(msi.restrict_locators_code,2),
6788         Nvl(msi.location_control_code,1),
6789         msi.primary_uom_code,
6790         Nvl(msi.inspection_required_flag,'N'),
6791         Nvl(msi.shelf_life_code, 1),
6792         Nvl(msi.shelf_life_days,0),
6793         Nvl(msi.allowed_units_lookup_code, 2),
6794         Nvl(msi.effectivity_control,1),
6795         0,
6796         0,
6797         Nvl(msi.default_serial_status_id,1),
6798         Nvl(msi.serial_status_enabled,'N'),
6799         Nvl(msi.default_lot_status_id,0),
6800         Nvl(msi.lot_status_enabled,'N'),
6801         msi.concatenated_segments,
6802         'Y',
6803         msi.inventory_item_flag,
6804         0,
6805 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
6806         msi.inventory_asset_flag,
6807         msi.outside_operation_flag ,
6808          --Bug 3952081
6809          --Select DUOM Attributes for every Item
6810          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
6811          NVL(MSI.DEFAULT_GRADE,''),
6812          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
6813          NVL(MSI.EXPIRATION_ACTION_CODE,''),
6814          NVL(MSI.HOLD_DAYS,0),
6815          NVL(MSI.MATURITY_DAYS,0),
6816          NVL(MSI.RETEST_INTERVAL,0),
6817          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
6818          NVL(MSI.CHILD_LOT_FLAG,'N'),
6819          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
6820          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
6821          NVL(MSI.SECONDARY_UOM_CODE,''),
6822          NVL(MSI.SECONDARY_DEFAULT_IND,''),
6823          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
6824          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
6825          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
6826         msi.stock_enabled_flag,
6827         DECODE (p_reqHeaderID,to_char(null),' ',
6828         rsh.shipment_num),
6829         DECODE (p_reqHeaderID,to_char(null),' ',
6830         p_shipmentHeaderID) -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
6831         from wms_lpn_contents wlc
6832 		  ,po_lines_trx_v pol -- CLM project, bug 9403291
6833           ,mtl_system_items_vl msi /* Bug 5581528 */
6834           ,rcv_shipment_lines rsl
6835           ,rcv_shipment_headers rsh /* Added for Bug9257750 */
6836         where msi.organization_id =  p_Organization_Id
6837 		and wlc.parent_lpn_id = l_from_lpn_id
6838         and wlc.inventory_item_id = msi.inventory_item_id
6839         and pol.vendor_product_num like  p_concatenated_segments
6840         and pol.item_id = msi.inventory_item_id
6841         and pol.vendor_product_num IS NOT NULL
6842         and pol.po_header_id = Nvl(p_poheaderid,pol.po_header_id)
6843         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
6844         and msi.inventory_item_id IN
6845 		      (SELECT pl.item_id
6846                 FROM po_lines_trx_v pl
6847                WHERE pl.po_header_id = rsl.po_header_id
6848               and pl.po_line_id = rsl.po_line_id
6849               and exists (select 1
6850                         from po_line_locations_trx_v pll -- CLM project, bug 9403291
6851                           --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
6852                            , mtl_parameters mp,
6853                              rcv_parameters rp
6854                           --  End for Bug 7440217
6855                        where NVL(pll.closed_code,'OPEN') not in ('FINALLY CLOSED' , 'CLOSED FOR RECEIVING', 'CLOSED' ) -- 3687249
6856                             --  For Bug 7440217 Checking if it is LCM enabled
6857                           AND mp.organization_id = p_organization_id
6858                           AND rp.organization_id = p_organization_id
6859                           AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
6860                                 OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
6861                                     OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
6862                                )
6863                            --  End for Bug 7440217
6864                         and  pll.po_header_id = rsl.po_header_id
6865                         and pll.po_line_id = rsl.po_line_id
6866                         and pll.ship_to_organization_id = p_Organization_Id
6867 					 )--Bug 3972931-Added the filter condition based on ship_to_organization_id
6868                  )
6869          and pol.po_line_id = rsl.po_line_id
6870          and rsl.SHIPMENT_HEADER_ID = p_shipmentHeaderID
6871          and rsh.SHIPMENT_HEADER_ID = rsl.SHIPMENT_HEADER_ID /* Added for Bug9257750 */
6872          and rsl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED')
6873          and rsl.source_document_code = 'PO'
6874        UNION
6875        -- Bug 2775532
6876        -- This section is non item master stuff for ASNs
6877         -- Bug# 6747729
6878         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
6879         select distinct pol.item_description,
6880         to_number(''),
6881         pol.item_description,
6882         1,
6883         1,
6884         1,
6885         2,
6886         2,
6887         1,
6888         mum.uom_code,
6889         'N',
6890         1,
6891         0,
6892         2,
6893         1,
6894         0,
6895         0,
6896         1,
6897         'N',
6898         0,
6899         'N',
6900         '',
6901         'N',
6902         'N',
6903         0,
6904 	  wms_deploy.get_item_client_name(pol.item_id),
6905         to_char(NULL),
6906         'N' ,
6907          --Bug 3952081
6908          --Select DUOM Attributes for every Item
6909          'N',
6910          '',
6911          0,
6912          '',
6913          0,
6914          0,
6915          0,
6916          'N',
6917          'N',
6918          'N',
6919          'Y',
6920          '',
6921          '',
6922          'P',
6923          0,
6924          0,
6925         'N',
6926         DECODE (p_reqHeaderID,to_char(null),' ',
6927         rsh.shipment_num),
6928         DECODE (p_reqHeaderID,to_char(null),' ',
6929         p_shipmentHeaderID)  -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
6930         from po_lines_trx_v pol -- CLM project, bug 9403291
6931         , mtl_units_of_measure mum
6932         ,rcv_shipment_lines rsl
6933         , rcv_shipment_headers rsh /* Added for Bug9257750 */
6934        -- Bug 2619063, 2614016
6935          -- Modified to select the base uom for the uom class defined on po.
6936          where mum.uom_class = (SELECT mum2.uom_class
6937                FROM mtl_units_of_measure mum2
6938               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
6939         and mum.base_uom_flag = 'Y'
6940         and pol.ITEM_ID is null
6941         and pol.item_description is not null
6942         and pol.po_header_id = Nvl(p_poheaderid,pol.po_header_id)
6943         and pol.item_description like  p_concatenated_segments
6944         and pol.po_line_id = rsl.po_line_id
6945         and rsl.SHIPMENT_HEADER_ID = p_shipmentHeaderID
6946         and rsh.SHIPMENT_HEADER_ID = rsl.SHIPMENT_HEADER_ID  /* Added for Bug9257750 */
6947         and rsl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED')
6948         and  rsl.source_document_code = 'PO'
6949            /* Bug 3972931-Added the following exists condition to restrict the PO receipt
6950            to shipments due to be received only in the organizationientered with.*/
6951         and exists (select 1
6952                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
6953                           --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
6954                          , mtl_parameters mp,
6955                            rcv_parameters rp
6956                            --  End for Bug 7440217
6957                      where pll.po_header_id = rsl.po_header_id  --Bug 13490287
6958                         --  For Bug 7440217 Checking if it is LCM enabled
6959                        AND mp.organization_id = p_organization_id
6960                        AND rp.organization_id = p_organization_id
6961                        AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
6962                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
6963                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
6964                            )
6965                          --  End for Bug 7440217
6966                        and pll.po_line_id = pol.po_line_id
6967                        and pll.ship_to_organization_id = p_Organization_Id
6968 					   )
6969         --End of fix for Bug 3972931
6970        UNION
6971        -- This Section for GTIN Cross Ref
6972        -- Bug# 6747729
6973        -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
6974        select distinct mcr.cross_reference,
6975        msn.inventory_item_id,
6976       Nvl(rsl.item_description, msn.description),  -- Bug 14645109 s
6977        Nvl(msn.revision_qty_control_code,1),
6978        Nvl(msn.lot_control_code, 1),
6979        Nvl(msn.serial_number_control_code, 1),
6980        Nvl(msn.restrict_subinventories_code, 2),
6981        Nvl(msn.restrict_locators_code, 2),
6982        Nvl(msn.location_control_code, 1),
6983        msn.primary_uom_code,
6984        Nvl(msn.inspection_required_flag, 'N'),
6985        Nvl(msn.shelf_life_code, 1),
6986        Nvl(msn.shelf_life_days,0),
6987        Nvl(msn.allowed_units_lookup_code, 2),
6988        Nvl(msn.effectivity_control,1),
6989        0,
6990        0,
6991        Nvl(msn.default_serial_status_id,1),
6992        Nvl(msn.serial_status_enabled,'N'),
6993        Nvl(msn.default_lot_status_id,0),
6994        Nvl(msn.lot_status_enabled,'N'),
6995        msn.concatenated_segments,
6996        'C',
6997        msn.inventory_item_flag,
6998        0,
6999 	  wms_deploy.get_item_client_name(msn.inventory_item_id),
7000        msn.inventory_asset_flag,
7001        msn.outside_operation_flag,
7002          --Bug 3952081
7003          --Select DUOM Attributes for every Item
7004          NVL(MSN.GRADE_CONTROL_FLAG,'N'),
7005          NVL(MSN.DEFAULT_GRADE,''),
7006          NVL(MSN.EXPIRATION_ACTION_INTERVAL,0),
7007          NVL(MSN.EXPIRATION_ACTION_CODE,''),
7008          NVL(MSN.HOLD_DAYS,0),
7009          NVL(MSN.MATURITY_DAYS,0),
7010          NVL(MSN.RETEST_INTERVAL,0),
7011          NVL(MSN.COPY_LOT_ATTRIBUTE_FLAG,'N'),
7012          NVL(MSN.CHILD_LOT_FLAG,'N'),
7013          NVL(MSN.CHILD_LOT_VALIDATION_FLAG,'N'),
7014          NVL(MSN.LOT_DIVISIBLE_FLAG,'Y'),
7015          NVL(MSN.SECONDARY_UOM_CODE,''),
7016          NVL(MSN.SECONDARY_DEFAULT_IND,''),
7017          NVL(MSN.TRACKING_QUANTITY_IND,'P'),
7018          NVL(MSN.DUAL_UOM_DEVIATION_HIGH,0),
7019          NVL(MSN.DUAL_UOM_DEVIATION_LOW,0),
7020          msn.stock_enabled_flag,
7021          DECODE (p_reqHeaderID,to_char(null),' ',
7022          rsh.shipment_num),
7023          DECODE (p_reqHeaderID,to_char(null),' ',
7024          p_shipmentHeaderID)  -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
7025        from wms_lpn_contents wlc,
7026 	        mtl_system_items_vl msn, /* Bug 5581528 */
7027             rcv_shipment_lines rsl,
7028             rcv_shipment_headers rsh, /* Added for Bug9257750 */
7029             mtl_cross_references mcr
7030        WHERE msn.organization_id = p_Organization_Id
7031 	    and wlc.parent_lpn_id = l_from_lpn_id
7032         and wlc.inventory_item_id = rsl.item_id
7033         and ( mcr.cross_reference_type = g_gtin_cross_ref_type
7034                AND mcr.cross_reference      LIKE g_crossref
7035             )
7036         and ( (mcr.org_independent_flag = 'Y') or (mcr.org_independent_flag = 'N'
7037                and mcr.organization_id = p_organization_id
7038                ) )
7039        and mcr.inventory_item_id = msn.inventory_item_id
7040        and (msn.purchasing_enabled_flag = 'Y' OR msn.stock_enabled_flag = 'Y')
7041        and rsl.SHIPMENT_HEADER_ID = p_shipmentHeaderID
7042        and rsh.SHIPMENT_HEADER_ID = rsl.SHIPMENT_HEADER_ID /* Added for Bug9257750 */
7043        and rsl.to_organization_id= p_Organization_Id--Bug 3972931-Added the condiotn to filter based on organization_id
7044        and rsl.item_id = msn.inventory_item_id
7045        ;
7046    ELSE
7047       --l_from_lpn_id is null --
7048       open x_Items for
7049       -- Bug# 6747729
7050       -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
7051       select concatenated_segments,
7052        msn.inventory_item_id,
7053 	   Nvl(rsl.item_description, msn.description) ,  -- Bug 14645109 s xb
7054        Nvl(revision_qty_control_code,1),
7055        Nvl(lot_control_code, 1),
7056        Nvl(serial_number_control_code, 1),
7057        Nvl(restrict_subinventories_code, 2),
7058        Nvl(restrict_locators_code, 2),
7059        Nvl(location_control_code, 1),
7060        primary_uom_code,
7061        Nvl(inspection_required_flag, 'N'),
7062        Nvl(shelf_life_code, 1),
7063        Nvl(shelf_life_days,0),
7064        Nvl(allowed_units_lookup_code, 2),
7065        Nvl(effectivity_control,1),
7066        0,
7067        0,
7068        Nvl(default_serial_status_id,1),
7069        Nvl(serial_status_enabled,'N'),
7070        Nvl(default_lot_status_id,0),
7071        Nvl(lot_status_enabled,'N'),
7072        '',
7073        'N',
7074        inventory_item_flag,
7075        0,
7076 	  wms_deploy.get_item_client_name(msn.inventory_item_id),
7077        inventory_asset_flag,
7078        outside_operation_flag,
7079          --Bug 3952081
7080          --Select DUOM Attributes for every Item
7081          NVL(GRADE_CONTROL_FLAG,'N'),
7082          NVL(DEFAULT_GRADE,''),
7083          NVL(EXPIRATION_ACTION_INTERVAL,0),
7084          NVL(EXPIRATION_ACTION_CODE,''),
7085          NVL(HOLD_DAYS,0),
7086          NVL(MATURITY_DAYS,0),
7087          NVL(RETEST_INTERVAL,0),
7088          NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
7089          NVL(CHILD_LOT_FLAG,'N'),
7090          NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
7091          NVL(LOT_DIVISIBLE_FLAG,'Y'),
7092          NVL(msn.SECONDARY_UOM_CODE,''),
7093          NVL(SECONDARY_DEFAULT_IND,''),
7094          NVL(TRACKING_QUANTITY_IND,'P'),
7095          NVL(DUAL_UOM_DEVIATION_HIGH,0),
7096          NVL(DUAL_UOM_DEVIATION_LOW,0),
7097          stock_enabled_flag,
7098         DECODE (p_reqHeaderID,to_char(null),' ',
7099         rsh.shipment_num),
7100         DECODE (p_reqHeaderID,to_char(null),' ',
7101         p_shipmentHeaderID) -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
7102        from mtl_system_items_vl msn, /* Bug 5581528 */
7103             rcv_shipment_lines rsl,
7104             rcv_shipment_headers rsh /* Added for Bug9257750 */
7105        WHERE msn.organization_id = p_Organization_Id
7106        and msn.concatenated_segments like p_concatenated_segments||l_append
7107        and (msn.purchasing_enabled_flag = 'Y' OR msn.stock_enabled_flag = 'Y')
7108        and rsl.SHIPMENT_HEADER_ID = p_shipmentHeaderID
7109        and rsh.SHIPMENT_HEADER_ID = rsl.SHIPMENT_HEADER_ID /* Added for Bug9257750 */
7110        -- This was fix for bug 2740648/2752094
7111        AND rsl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED')
7112        AND rsl.to_organization_id= p_Organization_Id--Bug 3972931-Added the condiotn to filter based on organization_id
7113        and rsl.item_id = msn.inventory_item_id
7114        UNION
7115     -- bug 2775596
7116     -- added unions for the substitute item and vendor item
7117     -- if receiving an ASN.
7118         -- Vendor Item SQL
7119         -- Bug# 6747729
7120         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
7121         select distinct pol.vendor_product_num,
7122         msi.inventory_item_id,
7123         msi.description,
7124         Nvl(msi.revision_qty_control_code,1),
7125         Nvl(msi.lot_control_code, 1),
7126         Nvl(msi.serial_number_control_code, 1),
7127         Nvl(msi.restrict_subinventories_code, 2),
7128         Nvl(msi.restrict_locators_code,2),
7129         Nvl(msi.location_control_code,1),
7130         msi.primary_uom_code,
7131         Nvl(msi.inspection_required_flag,'N'),
7132         Nvl(msi.shelf_life_code, 1),
7133         Nvl(msi.shelf_life_days,0),
7134         Nvl(msi.allowed_units_lookup_code, 2),
7135         Nvl(msi.effectivity_control,1),
7136         0,
7137         0,
7138         Nvl(msi.default_serial_status_id,1),
7139         Nvl(msi.serial_status_enabled,'N'),
7140         Nvl(msi.default_lot_status_id,0),
7141         Nvl(msi.lot_status_enabled,'N'),
7142         msi.concatenated_segments,
7143         'Y',
7144         msi.inventory_item_flag,
7145         0,
7146 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
7147         msi.inventory_asset_flag,
7148         msi.outside_operation_flag ,
7149          --Bug 3952081
7150          --Select DUOM Attributes for every Item
7151          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
7152          NVL(MSI.DEFAULT_GRADE,''),
7153          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
7154          NVL(MSI.EXPIRATION_ACTION_CODE,''),
7155          NVL(MSI.HOLD_DAYS,0),
7156          NVL(MSI.MATURITY_DAYS,0),
7157          NVL(MSI.RETEST_INTERVAL,0),
7158          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
7159          NVL(MSI.CHILD_LOT_FLAG,'N'),
7160          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
7161          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
7162          NVL(MSI.SECONDARY_UOM_CODE,''),
7163          NVL(MSI.SECONDARY_DEFAULT_IND,''),
7164          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
7165          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
7166          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
7167         msi.stock_enabled_flag,
7168         DECODE (p_reqHeaderID,to_char(null),' ',
7169         rsh.shipment_num),
7170         DECODE (p_reqHeaderID,to_char(null),' ',
7171         p_shipmentHeaderID) -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
7172         from po_lines_trx_v pol -- CLM project, bug 9403291
7173         ,mtl_system_items_vl msi /* Bug 5581528 */
7174         ,rcv_shipment_lines rsl
7175         ,rcv_shipment_headers rsh /* Added for Bug9257750 */
7176         where msi.organization_id =  p_Organization_Id
7177         and pol.vendor_product_num like  p_concatenated_segments
7178         and pol.item_id = msi.inventory_item_id
7179         and pol.vendor_product_num IS NOT NULL
7180         and pol.po_header_id = Nvl(p_poheaderid,pol.po_header_id)
7181         and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
7182         and msi.inventory_item_id IN (SELECT pl.item_id
7183           FROM po_lines_trx_v pl
7184           WHERE pl.po_header_id = rsl.po_header_id
7185           and pl.po_line_id = rsl.po_line_id
7186           and exists (select 1
7187                         from po_line_locations_trx_v pll -- CLM project, bug 9403291
7188 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
7189                            , mtl_parameters mp,
7190                              rcv_parameters rp
7191 --  End for Bug 7440217
7192                        where NVL(pll.closed_code,'OPEN')
7193                        not in ('FINALLY CLOSED' , 'CLOSED FOR RECEIVING', 'CLOSED' ) -- 3687249
7194 --  For Bug 7440217 Checking if it is LCM enabled
7195                           AND mp.organization_id = p_organization_id
7196                           AND rp.organization_id = p_organization_id
7197                           AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
7198                                 OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
7199                                     OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
7200                                )
7201 --  End for Bug 7440217
7202                         and  pll.po_header_id = rsl.po_header_id
7203                         and pll.po_line_id = rsl.po_line_id
7204                         and pll.ship_to_organization_id = p_Organization_Id)--Bug 3972931-Added the filter condition based on ship_to_organization_id
7205                  )
7206   AND pol.po_line_id = rsl.po_line_id
7207   and rsl.SHIPMENT_HEADER_ID = p_shipmentHeaderID
7208   and rsh.SHIPMENT_HEADER_ID = rsl.SHIPMENT_HEADER_ID /* Added for Bug9257750 */
7209   AND rsl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED')
7210   AND rsl.source_document_code = 'PO'
7211 
7212        UNION
7213   -- Bug 2775532
7214   -- This section is non item master stuff for ASNs
7215         -- Bug# 6747729
7216         -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
7217         select distinct pol.item_description,
7218         to_number(''),
7219         pol.item_description,
7220         1,
7221         1,
7222         1,
7223         2,
7224         2,
7225         1,
7226         mum.uom_code,
7227         'N',
7228         1,
7229         0,
7230         2,
7231         1,
7232         0,
7233         0,
7234         1,
7235         'N',
7236         0,
7237         'N',
7238         '',
7239         'N',
7240         'N',
7241         0,
7242 	  wms_deploy.get_item_client_name(pol.item_id),
7243         to_char(NULL),
7244         'N' ,
7245          --Bug 3952081
7246          --Select DUOM Attributes for every Item
7247          'N',
7248          '',
7249          0,
7250          '',
7251          0,
7252          0,
7253          0,
7254          'N',
7255          'N',
7256          'N',
7257          'Y',
7258          '',
7259          '',
7260          'P',
7261          0,
7262          0,
7263         'N',
7264         DECODE (p_reqHeaderID,to_char(null),' ',
7265         rsh.shipment_num),
7266         DECODE (p_reqHeaderID,to_char(null),' ',
7267         p_shipmentHeaderID)  -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
7268         from po_lines_trx_v pol -- CLM project, bug 9403291
7269         , mtl_units_of_measure mum
7270         ,rcv_shipment_lines rsl
7271         , rcv_shipment_headers rsh /* Added for Bug9257750 */
7272   -- Bug 2619063, 2614016
7273   -- Modified to select the base uom for the uom class defined on po.
7274   where mum.uom_class = (SELECT mum2.uom_class
7275                FROM mtl_units_of_measure mum2
7276               WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
7277         and mum.base_uom_flag = 'Y'
7278         and pol.ITEM_ID is null
7279         and pol.item_description is not null
7280         and pol.po_header_id = Nvl(p_poheaderid,pol.po_header_id)
7281         and pol.item_description like  p_concatenated_segments
7282   AND pol.po_line_id = rsl.po_line_id
7283   and rsl.SHIPMENT_HEADER_ID = p_shipmentHeaderID
7284   and rsh.SHIPMENT_HEADER_ID = rsl.SHIPMENT_HEADER_ID  /* Added for Bug9257750 */
7285   AND rsl.shipment_line_status_code in ('EXPECTED','PARTIALLY RECEIVED')
7286   AND rsl.source_document_code = 'PO'
7287   /* Bug 3972931-Added the following exists condition to restrict the PO receipt
7288         to shipments due to be received only in the organizationientered with.*/
7289         and exists (select 1
7290                       from po_line_locations_trx_v pll -- CLM project, bug 9403291
7291 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
7292                          , mtl_parameters mp,
7293                            rcv_parameters rp
7294 --  End for Bug 7440217
7295                      where pll.po_header_id = rsl.po_header_id  --Bug 13490287
7296 --  For Bug 7440217 Checking if it is LCM enabled
7297                        AND mp.organization_id = p_organization_id
7298                        AND rp.organization_id = p_organization_id
7299                        AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
7300                              OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
7301                                  OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
7302                            )
7303 --  End for Bug 7440217
7304                        and pll.po_line_id = pol.po_line_id
7305                        and pll.ship_to_organization_id = p_Organization_Id)
7306         --End of fix for Bug 3972931
7307        UNION
7308        -- This Section for GTIN Cross Ref
7309        -- Bug# 6747729
7310        -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
7311        select mcr.cross_reference,
7312        msn.inventory_item_id,
7313        msn.description,
7314        Nvl(msn.revision_qty_control_code,1),
7315        Nvl(msn.lot_control_code, 1),
7316        Nvl(msn.serial_number_control_code, 1),
7317        Nvl(msn.restrict_subinventories_code, 2),
7318        Nvl(msn.restrict_locators_code, 2),
7319        Nvl(msn.location_control_code, 1),
7320        msn.primary_uom_code,
7321        Nvl(msn.inspection_required_flag, 'N'),
7322        Nvl(msn.shelf_life_code, 1),
7323        Nvl(msn.shelf_life_days,0),
7324        Nvl(msn.allowed_units_lookup_code, 2),
7325        Nvl(msn.effectivity_control,1),
7326        0,
7327        0,
7328        Nvl(msn.default_serial_status_id,1),
7329        Nvl(msn.serial_status_enabled,'N'),
7330        Nvl(msn.default_lot_status_id,0),
7331        Nvl(msn.lot_status_enabled,'N'),
7332        msn.concatenated_segments,
7333        'C',
7334        msn.inventory_item_flag,
7335        0,
7336 	  wms_deploy.get_item_client_name(msn.inventory_item_id),
7337        msn.inventory_asset_flag,
7338        msn.outside_operation_flag,
7339          --Bug 3952081
7340          --Select DUOM Attributes for every Item
7341          NVL(MSN.GRADE_CONTROL_FLAG,'N'),
7342          NVL(MSN.DEFAULT_GRADE,''),
7343          NVL(MSN.EXPIRATION_ACTION_INTERVAL,0),
7344          NVL(MSN.EXPIRATION_ACTION_CODE,''),
7345          NVL(MSN.HOLD_DAYS,0),
7346          NVL(MSN.MATURITY_DAYS,0),
7347          NVL(MSN.RETEST_INTERVAL,0),
7348          NVL(MSN.COPY_LOT_ATTRIBUTE_FLAG,'N'),
7349          NVL(MSN.CHILD_LOT_FLAG,'N'),
7350          NVL(MSN.CHILD_LOT_VALIDATION_FLAG,'N'),
7351          NVL(MSN.LOT_DIVISIBLE_FLAG,'Y'),
7352          NVL(MSN.SECONDARY_UOM_CODE,''),
7353          NVL(MSN.SECONDARY_DEFAULT_IND,''),
7354          NVL(MSN.TRACKING_QUANTITY_IND,'P'),
7355          NVL(MSN.DUAL_UOM_DEVIATION_HIGH,0),
7356          NVL(MSN.DUAL_UOM_DEVIATION_LOW,0),
7357          msn.stock_enabled_flag,
7358          DECODE (p_reqHeaderID,to_char(null),' ',
7359          rsh.shipment_num),
7360          DECODE (p_reqHeaderID,to_char(null),' ',
7361          p_shipmentHeaderID)  -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
7362        from mtl_system_items_vl msn, /* Bug 5581528 */
7363             rcv_shipment_lines rsl,
7364             rcv_shipment_headers rsh, /* Added for Bug9257750 */
7365             mtl_cross_references mcr
7366        WHERE msn.organization_id = p_Organization_Id
7367         and ( mcr.cross_reference_type = g_gtin_cross_ref_type
7368                AND mcr.cross_reference      LIKE g_crossref
7369             )
7370         and ( (mcr.org_independent_flag = 'Y') or (mcr.org_independent_flag = 'N'
7371         and mcr.organization_id = p_organization_id
7372                ) )
7373        and mcr.inventory_item_id = msn.inventory_item_id
7374        and (msn.purchasing_enabled_flag = 'Y' OR msn.stock_enabled_flag = 'Y')
7375        and rsl.SHIPMENT_HEADER_ID = p_shipmentHeaderID
7376        and rsh.SHIPMENT_HEADER_ID = rsl.SHIPMENT_HEADER_ID /* Added for Bug9257750 */
7377        and rsl.to_organization_id= p_Organization_Id--Bug 3972931-Added the condiotn to filter based on organization_id
7378        and rsl.item_id = msn.inventory_item_id
7379        ;
7380     END IF;    --End of l_from_lpn_id is not null
7381 
7382 
7383 
7384 -- *****************************
7385 --- END  OF SHIPMENT HEADER  ID SECTION
7386 -- *****************************
7387 
7388 elsif (p_oeOrderHeaderID is not null) then
7389 
7390 -- *****************************
7391 --- START  OF OE ORDER HEADER  ID SECTION
7392 -- *****************************
7393 
7394        open x_items for
7395        -- Bug# 6747729
7396        -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
7397        select concatenated_segments,
7398        inventory_item_id,
7399        description,
7400        Nvl(revision_qty_control_code,1),
7401        Nvl(lot_control_code, 1),
7402        Nvl(serial_number_control_code, 1),
7403        Nvl(restrict_subinventories_code, 2),
7404        Nvl(restrict_locators_code, 2),
7405        Nvl(location_control_code, 1),
7406        primary_uom_code,
7407        Nvl(inspection_required_flag, 'N'),
7408        Nvl(shelf_life_code, 1),
7409        Nvl(shelf_life_days,0),
7410        Nvl(allowed_units_lookup_code, 2),
7411        Nvl(effectivity_control,1),
7412        0,
7413        0,
7414        Nvl(default_serial_status_id,1),
7415        Nvl(serial_status_enabled,'N'),
7416        Nvl(default_lot_status_id,0),
7417        Nvl(lot_status_enabled,'N'),
7418        '',
7419        'N',
7420        inventory_item_flag,
7421        0,
7422 	  wms_deploy.get_item_client_name(inventory_item_id),
7423        inventory_asset_flag,
7424        outside_operation_flag,
7425          --Bug 3952081
7426          --Select DUOM Attributes for every Item
7427          NVL(GRADE_CONTROL_FLAG,'N'),
7428          NVL(DEFAULT_GRADE,''),
7429          NVL(EXPIRATION_ACTION_INTERVAL,0),
7430          NVL(EXPIRATION_ACTION_CODE,''),
7431          NVL(HOLD_DAYS,0),
7432          NVL(MATURITY_DAYS,0),
7433          NVL(RETEST_INTERVAL,0),
7434          NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
7435          NVL(CHILD_LOT_FLAG,'N'),
7436          NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
7437          NVL(LOT_DIVISIBLE_FLAG,'Y'),
7438          NVL(SECONDARY_UOM_CODE,''),
7439          NVL(SECONDARY_DEFAULT_IND,''),
7440          NVL(TRACKING_QUANTITY_IND,'P'),
7441          NVL(DUAL_UOM_DEVIATION_HIGH,0),
7442          NVL(DUAL_UOM_DEVIATION_LOW,0),
7443        stock_enabled_flag,
7444          ' ',
7445          ' '    -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
7446        from mtl_system_items_vl  /* Bug 5581528 */
7447        WHERE organization_id = p_Organization_Id
7448        and concatenated_segments like p_concatenated_segments||l_append
7449        and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
7450        and inventory_item_id IN (SELECT oel.inventory_item_id FROM
7451        oe_order_lines_all oel,oe_order_headers_all oeh--Bug 3972931-Added the table oe_order_headers_all
7452        WHERE oel.HEADER_ID = p_oeOrderHeaderID
7453        and oel.header_id = oeh.header_id --Bug4060261 -Added the join between the tables.
7454        and oel.ORDERED_QUANTITY > NVL(oel.SHIPPED_QUANTITY,0)
7455        and ((p_projectId is null or oel.project_id = p_projectId)
7456              and (p_taskID is null or oel.task_id = p_taskId ))
7457        and nvl(oel.ship_from_org_id, nvl(oeh.ship_from_org_id,p_Organization_Id)) = p_Organization_Id
7458        and    oel.line_category_code = 'RETURN' --added for bug 4417549
7459        )
7460        --Bug 3972931-Added the filter condition based on ship_from_org_id
7461        UNION
7462        -- This Section Added for GTIN Cross Ref
7463        -- Bug# 6747729
7464        -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
7465        select mcr.cross_reference,
7466        msi.inventory_item_id,
7467        msi.description,
7468        Nvl(msi.revision_qty_control_code,1),
7469        Nvl(msi.lot_control_code, 1),
7470        Nvl(msi.serial_number_control_code, 1),
7471        Nvl(msi.restrict_subinventories_code, 2),
7472        Nvl(msi.restrict_locators_code, 2),
7473        Nvl(msi.location_control_code, 1),
7474        msi.primary_uom_code,
7475        Nvl(msi.inspection_required_flag, 'N'),
7476        Nvl(msi.shelf_life_code, 1),
7477        Nvl(msi.shelf_life_days,0),
7478        Nvl(msi.allowed_units_lookup_code, 2),
7479        Nvl(msi.effectivity_control,1),
7480        0,
7481        0,
7482        Nvl(msi.default_serial_status_id,1),
7483        Nvl(msi.serial_status_enabled,'N'),
7484        Nvl(msi.default_lot_status_id,0),
7485        Nvl(msi.lot_status_enabled,'N'),
7486        msi.concatenated_segments,
7487        'C',
7488        msi.inventory_item_flag,
7489        0,
7490 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
7491        msi.inventory_asset_flag,
7492        msi.outside_operation_flag,
7493          --Bug 3952081
7494          --Select DUOM Attributes for every Item
7495          NVL(MSI.GRADE_CONTROL_FLAG,'N'),
7496          NVL(MSI.DEFAULT_GRADE,''),
7497          NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
7498          NVL(MSI.EXPIRATION_ACTION_CODE,''),
7499          NVL(MSI.HOLD_DAYS,0),
7500          NVL(MSI.MATURITY_DAYS,0),
7501          NVL(MSI.RETEST_INTERVAL,0),
7502          NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
7503          NVL(MSI.CHILD_LOT_FLAG,'N'),
7504          NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
7505          NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
7506          NVL(MSI.SECONDARY_UOM_CODE,''),
7507          NVL(MSI.SECONDARY_DEFAULT_IND,''),
7508          NVL(MSI.TRACKING_QUANTITY_IND,'P'),
7509          NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
7510          NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
7511        msi.stock_enabled_flag,
7512          ' ',
7513          ' '    -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
7514        from mtl_system_items_vl msi /* Bug 5581528 */
7515            ,mtl_cross_references mcr
7516        WHERE msi.organization_id = p_Organization_Id
7517         and ( mcr.cross_reference_type = g_gtin_cross_ref_type
7518                AND mcr.cross_reference      LIKE g_crossref
7519             )
7520         and ( (mcr.org_independent_flag = 'Y') or (mcr.org_independent_flag = 'N'
7521         and mcr.organization_id = p_organization_id
7522                ) )
7523        and mcr.inventory_item_id = msi.inventory_item_id
7524        and (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
7525        and msi.inventory_item_id IN (SELECT oel.inventory_item_id FROM
7526        oe_order_lines_all oel,oe_order_headers_all oeh--Bug 3972931-Added the table oe_order_headers_all
7527        WHERE oel.HEADER_ID = p_oeOrderHeaderID
7528        and oel.header_id = oeh.header_id --Bug4060261-Added the join between the tables.
7529        and oel.ORDERED_QUANTITY > NVL(oel.SHIPPED_QUANTITY,0)
7530        and ((p_projectId is null or oel.project_id = p_projectId)
7531              and (p_taskID is null or oel.task_id = p_taskId ))
7532        and nvl(oel.ship_from_org_id, nvl(oeh.ship_from_org_id,p_Organization_id)) = p_Organization_Id);
7533        --Bug 3972931-Added the filter condition based on ship_from_org_id
7534 
7535 -- *****************************
7536 --- END  OF OE ORDER HEADER  ID SECTION
7537 -- *****************************
7538 
7539 elsif  (p_reqHeaderID is not null) then
7540 
7541 -- *****************************
7542 --- START  OF REQ HEADER  ID SECTION
7543 -- *****************************
7544 
7545        open x_items for
7546        -- Bug# 6747729
7547        -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
7548        --Start of Fix for Bug# 7216416
7549 
7550        SELECT  /*+ leading(rsl1) use_nl(rsl1 mtl_system_items_vl)
7551         index(mtl_system_items_vl MTL_SYSTEM_ITEMS_B_U1) */
7552 
7553 	      concatenated_segments               ,
7554         inventory_item_id                   ,
7555         description                         ,
7556         NVL(revision_qty_control_code,1)    ,
7557         NVL(lot_control_code, 1)            ,
7558         NVL(serial_number_control_code, 1)  ,
7559         NVL(restrict_subinventories_code, 2),
7560         NVL(restrict_locators_code, 2)      ,
7561         NVL(location_control_code, 1)       ,
7562         primary_uom_code                    ,
7563         NVL(inspection_required_flag, 'N')  ,
7564         NVL(shelf_life_code, 1)             ,
7565         NVL(shelf_life_days,0)              ,
7566         NVL(allowed_units_lookup_code, 2)   ,
7567         NVL(effectivity_control,1)          ,
7568         0                                   ,
7569         0                                   ,
7570         NVL(default_serial_status_id,1)     ,
7571         NVL(serial_status_enabled,'N')      ,
7572         NVL(default_lot_status_id,0)        ,
7573         NVL(lot_status_enabled,'N')         ,
7574         ''                                  ,
7575         'N'                                 ,
7576         inventory_item_flag                 ,
7577         0                                   ,
7578 	  wms_deploy.get_item_client_name(inventory_item_id),
7579         inventory_asset_flag                ,
7580         outside_operation_flag              ,
7581         --Bug 3952081
7582         --Select DUOM Attributes for every Item
7583         NVL(GRADE_CONTROL_FLAG,'N')       ,
7584         NVL(DEFAULT_GRADE,'')             ,
7585         NVL(EXPIRATION_ACTION_INTERVAL,0) ,
7586         NVL(EXPIRATION_ACTION_CODE,'')    ,
7587         NVL(HOLD_DAYS,0)                  ,
7588         NVL(MATURITY_DAYS,0)              ,
7589         NVL(RETEST_INTERVAL,0)            ,
7590         NVL(COPY_LOT_ATTRIBUTE_FLAG,'N')  ,
7591         NVL(CHILD_LOT_FLAG,'N')           ,
7592         NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
7593         NVL(LOT_DIVISIBLE_FLAG,'Y')       ,
7594         NVL(SECONDARY_UOM_CODE,'')        ,
7595         NVL(SECONDARY_DEFAULT_IND,'')     ,
7596         NVL(TRACKING_QUANTITY_IND,'P')    ,
7597         NVL(DUAL_UOM_DEVIATION_HIGH,0)    ,
7598         NVL(DUAL_UOM_DEVIATION_LOW,0)     ,
7599         stock_enabled_flag,
7600         rsl1.shipment_num,
7601         to_char(rsl1.shipment_header_id)  -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
7602 FROM    mtl_system_items_vl,
7603         /* Bug 5581528 */
7604         (
7605         SELECT rsl.Item_Id,rsh.shipment_num shipment_num, /* Added by Bug9257750 */
7606         rsh.shipment_header_id shipment_header_id
7607         FROM    po_Req_Lines_trx_v prl, -- CLM project, bug 9403291
7608                 rcv_Shipment_Lines rsl      ,
7609                 rcv_shipment_headers rsh,/* Added by Bug9257750 */
7610                 po_req_Distributions_All prd
7611         WHERE   prl.Requisition_Header_Id = p_reqHeadeRid
7612             AND rsh.shipment_header_id	= rsl.shipment_header_id /* Added by Bug9257750 */
7613             AND l_From_lpn_Id            IS NOT NULL
7614             AND EXISTS
7615                 (SELECT '1'
7616                 FROM    wms_lpn_Contents wlc
7617                 WHERE   wlc.Parent_lpn_Id     = l_From_lpn_Id
7618                     AND wlc.Inventory_Item_Id = rsl.Item_Id
7619                 )
7620             AND prl.Requisition_Line_Id         = rsl.Requisition_Line_Id
7621 			AND(rsl.shipment_line_status_code IS NULL OR rsl.shipment_line_status_code <> 'FULLY RECEIVED') -- Modified for bug 7283630
7622             AND prl.Requisition_Line_Id         = prd.Requisition_Line_Id
7623             AND prl.Destination_Organization_Id = p_Organization_Id--Bug 3972931- Added the condition to filter based on destination org
7624             AND (p_ProjectId                   IS NULL
7625              OR prd.Project_Id                  = p_ProjectId)
7626             AND (p_TaskId                      IS NULL
7627              OR prd.Task_Id                     = p_TaskId)
7628         ) rsl1
7629 WHERE   organization_id = p_Organization_Id
7630     AND concatenated_segments LIKE p_concatenated_segments||l_append
7631     AND (purchasing_enabled_flag = 'Y'
7632      OR stock_enabled_flag       = 'Y')
7633     AND Inventory_Item_Id        = rsl1.Item_Id
7634 
7635 UNION
7636 
7637 SELECT  /*+ leading(rsl1) use_nl(rsl1 msiv1)
7638         index(msiv1 MTL_SYSTEM_ITEMS_B_U1) */
7639 
7640 	      concatenated_segments               ,
7641         inventory_item_id                   ,
7642         description                         ,
7643         NVL(revision_qty_control_code,1)    ,
7644         NVL(lot_control_code, 1)            ,
7645         NVL(serial_number_control_code, 1)  ,
7646         NVL(restrict_subinventories_code, 2),
7647         NVL(restrict_locators_code, 2)      ,
7648         NVL(location_control_code, 1)       ,
7649         primary_uom_code                    ,
7650         NVL(inspection_required_flag, 'N')  ,
7651         NVL(shelf_life_code, 1)             ,
7652         NVL(shelf_life_days,0)              ,
7653         NVL(allowed_units_lookup_code, 2)   ,
7654         NVL(effectivity_control,1)          ,
7655         0                                   ,
7656         0                                   ,
7657         NVL(default_serial_status_id,1)     ,
7658         NVL(serial_status_enabled,'N')      ,
7659         NVL(default_lot_status_id,0)        ,
7660         NVL(lot_status_enabled,'N')         ,
7661         ''                                  ,
7662         'N'                                 ,
7663         inventory_item_flag                 ,
7664         0                                   ,
7665 	  wms_deploy.get_item_client_name(inventory_item_id),
7666         inventory_asset_flag                ,
7667         outside_operation_flag              ,
7668         --Bug 3952081
7669         --Select DUOM Attributes for every Item
7670         NVL(GRADE_CONTROL_FLAG,'N')       ,
7671         NVL(DEFAULT_GRADE,'')             ,
7672         NVL(EXPIRATION_ACTION_INTERVAL,0) ,
7673         NVL(EXPIRATION_ACTION_CODE,'')    ,
7674         NVL(HOLD_DAYS,0)                  ,
7675         NVL(MATURITY_DAYS,0)              ,
7676         NVL(RETEST_INTERVAL,0)            ,
7677         NVL(COPY_LOT_ATTRIBUTE_FLAG,'N')  ,
7678         NVL(CHILD_LOT_FLAG,'N')           ,
7679         NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
7680         NVL(LOT_DIVISIBLE_FLAG,'Y')       ,
7681         NVL(SECONDARY_UOM_CODE,'')        ,
7682         NVL(SECONDARY_DEFAULT_IND,'')     ,
7683         NVL(TRACKING_QUANTITY_IND,'P')    ,
7684         NVL(DUAL_UOM_DEVIATION_HIGH,0)    ,
7685         NVL(DUAL_UOM_DEVIATION_LOW,0)     ,
7686         stock_enabled_flag,
7687         rsl1.shipment_num,
7688         to_char(rsl1.shipment_header_id)  -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
7689 FROM    mtl_system_items_vl,
7690         /* Bug 5581528 */
7691         (
7692         SELECT rsl.Item_Id,rsh.shipment_num shipment_num, /* Added by Bug9257750 */
7693         rsh.shipment_header_id shipment_header_id
7694         FROM    po_Req_Lines_trx_v prl, -- CLM project, bug 9403291
7695                 rcv_Shipment_Lines rsl      ,
7696                 po_req_Distributions_All prd,
7697                 rcv_shipment_headers rsh /* Added by Bug9257750 */
7698         WHERE   prl.Requisition_Header_Id       = p_reqHeadeRid
7699             AND rsh.shipment_header_id	= rsl.shipment_header_id /* Added by Bug9257750 */
7700             AND l_From_lpn_Id                  IS NULL
7701             AND prl.Requisition_Line_Id         = rsl.Requisition_Line_Id
7702 			AND(rsl.shipment_line_status_code IS NULL OR rsl.shipment_line_status_code <> 'FULLY RECEIVED') -- Modified for bug 7283630
7703             AND prl.Requisition_Line_Id         = prd.Requisition_Line_Id
7704             AND prl.Destination_Organization_Id = p_Organization_Id--Bug 3972931- Added the condition to filter based on destination org
7705             AND (p_ProjectId                   IS NULL
7706              OR prd.Project_Id                  = p_ProjectId)
7707             AND (p_TaskId                      IS NULL
7708              OR prd.Task_Id                     = p_TaskId)
7709         ) rsl1
7710 WHERE   organization_id = p_Organization_Id
7711     AND concatenated_segments LIKE p_concatenated_segments||l_append
7712     AND (purchasing_enabled_flag = 'Y'
7713      OR stock_enabled_flag       = 'Y')
7714     AND Inventory_Item_Id        = rsl1.Item_Id
7715 
7716 UNION
7717 
7718 -- Section for GTIN Cross Ref.
7719 -- Bug# 6747729
7720 -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
7721 SELECT  mcr.cross_reference                     ,
7722         msi.inventory_item_id                   ,
7723         msi.description                         ,
7724         NVL(msi.revision_qty_control_code,1)    ,
7725         NVL(msi.lot_control_code, 1)            ,
7726         NVL(msi.serial_number_control_code, 1)  ,
7727         NVL(msi.restrict_subinventories_code, 2),
7728         NVL(msi.restrict_locators_code, 2)      ,
7729         NVL(msi.location_control_code, 1)       ,
7730         msi.primary_uom_code                    ,
7731         NVL(msi.inspection_required_flag, 'N')  ,
7732         NVL(msi.shelf_life_code, 1)             ,
7733         NVL(msi.shelf_life_days,0)              ,
7734         NVL(msi.allowed_units_lookup_code, 2)   ,
7735         NVL(msi.effectivity_control,1)          ,
7736         0                                       ,
7737         0                                       ,
7738         NVL(msi.default_serial_status_id,1)     ,
7739         NVL(msi.serial_status_enabled,'N')      ,
7740         NVL(msi.default_lot_status_id,0)        ,
7741         NVL(msi.lot_status_enabled,'N')         ,
7742         msi.concatenated_segments               ,
7743         'C'                                     ,
7744         msi.inventory_item_flag                 ,
7745         0                                       ,
7746 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
7747         msi.inventory_asset_flag                ,
7748         msi.outside_operation_flag              ,
7749         --Bug 3952081
7750         --Select DUOM Attributes for every Item
7751         NVL(MSI.GRADE_CONTROL_FLAG,'N')       ,
7752         NVL(MSI.DEFAULT_GRADE,'')             ,
7753         NVL(MSI.EXPIRATION_ACTION_INTERVAL,0) ,
7754         NVL(MSI.EXPIRATION_ACTION_CODE,'')    ,
7755         NVL(MSI.HOLD_DAYS,0)                  ,
7756         NVL(MSI.MATURITY_DAYS,0)              ,
7757         NVL(MSI.RETEST_INTERVAL,0)            ,
7758         NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N')  ,
7759         NVL(MSI.CHILD_LOT_FLAG,'N')           ,
7760         NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
7761         NVL(MSI.LOT_DIVISIBLE_FLAG,'Y')       ,
7762         NVL(MSI.SECONDARY_UOM_CODE,'')        ,
7763         NVL(MSI.SECONDARY_DEFAULT_IND,'')     ,
7764         NVL(MSI.TRACKING_QUANTITY_IND,'P')    ,
7765         NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0)    ,
7766         NVL(MSI.DUAL_UOM_DEVIATION_LOW,0)     ,
7767         msi.stock_enabled_flag,
7768         rsl1.shipment_num,
7769         to_char(rsl1.shipment_header_id)  -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
7770 FROM    mtl_system_items_vl msi
7771         /* Bug 5581528 */
7772         ,
7773         mtl_cross_references mcr,
7774         -- This Select clause added by Bug9257750 to fetch the values of Shipment Number and Shipment Header id
7775         (
7776         SELECT  rsl.Item_Id,rsh.shipment_num shipment_num,
7777                 rsh.shipment_header_id shipment_header_id
7778         FROM    po_req_lines_trx_v prl,
7779                 rcv_Shipment_Lines rsl      ,
7780                 po_req_Distributions_All prd,
7781                 rcv_shipment_headers  rsh
7782         WHERE   prl.Requisition_Header_Id       = p_reqHeadeRid
7783 	    AND rsh.shipment_header_id		= rsl.shipment_header_id
7784             AND l_From_lpn_Id                  IS NULL
7785             AND prl.Requisition_Line_Id         = rsl.Requisition_Line_Id
7786 	        AND(rsl.shipment_line_status_code IS NULL OR rsl.shipment_line_status_code <> 'FULLY RECEIVED') -- Modified for bug 7283630
7787             AND prl.Requisition_Line_Id         = prd.Requisition_Line_Id
7788             AND prl.Destination_Organization_Id = p_Organization_Id--Bug 3972931- Added the condition to filter based on destination org
7789             AND (p_ProjectId                   IS NULL
7790              OR prd.Project_Id                  = p_ProjectId)
7791             AND (p_TaskId                      IS NULL
7792              OR prd.Task_Id                     = p_TaskId)
7793         ) rsl1
7794 WHERE   msi.organization_id        = p_Organization_Id
7795     AND ( mcr.cross_reference_type = g_gtin_cross_ref_type
7796     AND mcr.cross_reference LIKE g_crossref )
7797     AND ( (mcr.org_independent_flag = 'Y')
7798      OR (mcr.org_independent_flag   = 'N'
7799     AND mcr.organization_id         = p_organization_id ) )
7800     AND mcr.inventory_item_id       = msi.inventory_item_id
7801     AND (purchasing_enabled_flag    = 'Y'
7802      OR stock_enabled_flag          = 'Y')
7803     AND EXISTS
7804         (SELECT 1
7805         FROM    po_req_lines_trx_v prl,
7806                 rcv_shipment_lines rsl      ,
7807                 po_req_distributions_all prd
7808         WHERE   prl.requisition_header_id = p_reqHeaderID
7809             AND rsl.item_id               = msi.inventory_item_id
7810             AND ( (l_from_lpn_id         IS NULL)
7811              OR (l_from_lpn_id           IS NOT NULL
7812             AND EXISTS
7813                 (SELECT '1'
7814                 FROM    wms_lpn_contents wlc
7815                 WHERE   wlc.parent_lpn_id     = l_from_lpn_id
7816                     AND wlc.inventory_item_id = rsl.item_id
7817                 ) ) )
7818             AND prl.requisition_line_id        = rsl.requisition_line_id
7819             AND prl.requisition_line_id        = prd.requisition_line_id
7820             AND prl.destination_organization_id=p_Organization_Id--Bug 3972931- Added the condition to filter based on destination org
7821             AND (p_projectId                  IS NULL
7822              OR prd.project_id                 = p_projectId)
7823             AND (p_taskId                     IS NULL
7824              OR prd.task_id                    = p_taskId)
7825         ) ;
7826 
7827        --End of Fix for Bug# 7216416
7828 
7829 -- *****************************
7830 --- END  OF REQ HEADER  ID SECTION
7831 -- *****************************
7832 
7833 end if;   --- End of doc Entered transaction
7834 
7835 else
7836 
7837 -- *****************************
7838 ---- Case for Document Info is not  entered in the session , i.e transaction starts with Item
7839 -- *****************************
7840 
7841        OPEN x_items FOR
7842        --Items from Item Master
7843        -- Bug# 6747729
7844        -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
7845        SELECT
7846        msi.concatenated_segments,
7847        msi.inventory_item_id,
7848        msi.description,
7849        Nvl(msi.revision_qty_control_code,1),
7850        Nvl(msi.lot_control_code, 1),
7851        Nvl(msi.serial_number_control_code, 1),
7852        Nvl(msi.restrict_subinventories_code, 2),
7853        Nvl(msi.restrict_locators_code, 2),
7854        Nvl(msi.location_control_code, 1),
7855        msi.primary_uom_code,
7856        Nvl(msi.inspection_required_flag, 'N'),
7857        Nvl(msi.shelf_life_code, 1),
7858        Nvl(msi.shelf_life_days,0),
7859        Nvl(msi.allowed_units_lookup_code, 2),
7860        Nvl(msi.effectivity_control,1),
7861        0,
7862        0,
7863        Nvl(msi.default_serial_status_id,1),
7864        Nvl(msi.serial_status_enabled,'N'),
7865        Nvl(msi.default_lot_status_id,0),
7866        Nvl(msi.lot_status_enabled,'N'),
7867        '',
7868        'N',
7869        msi.inventory_item_flag,
7870        0,
7871 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
7872        msi.inventory_asset_flag,
7873        msi.outside_operation_flag,
7874        --Bug 3952081
7875        --Select DUOM Attributes for every Item
7876        NVL(msi.GRADE_CONTROL_FLAG,'N'),
7877        NVL(msi.DEFAULT_GRADE,''),
7878        NVL(msi.EXPIRATION_ACTION_INTERVAL,0),
7879        NVL(msi.EXPIRATION_ACTION_CODE,''),
7880        NVL(msi.HOLD_DAYS,0),
7881        NVL(msi.MATURITY_DAYS,0),
7882        NVL(msi.RETEST_INTERVAL,0),
7883        NVL(msi.COPY_LOT_ATTRIBUTE_FLAG,'N'),
7884        NVL(msi.CHILD_LOT_FLAG,'N'),
7885        NVL(msi.CHILD_LOT_VALIDATION_FLAG,'N'),
7886        NVL(msi.LOT_DIVISIBLE_FLAG,'Y'),
7887        NVL(msi.SECONDARY_UOM_CODE,''),
7888        NVL(msi.SECONDARY_DEFAULT_IND,''),
7889        NVL(msi.TRACKING_QUANTITY_IND,'P'),
7890        NVL(msi.DUAL_UOM_DEVIATION_HIGH,0),
7891        NVL(msi.DUAL_UOM_DEVIATION_LOW,0),
7892        msi.stock_enabled_flag,
7893        ' ',
7894        ' '      -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
7895        FROM
7896        mtl_system_items_vl msi /* Bug 5581528 */
7897        WHERE msi.organization_id = p_organization_Id
7898        AND msi.concatenated_segments LIKE p_concatenated_segments||l_append
7899        AND (msi.purchasing_enabled_flag = 'Y' OR msi.stock_enabled_flag = 'Y')
7900        UNION -- ALL
7901        --Bug 7608067 This should Union but not Union ALL which is causing of displaying duplicate items in the LOV
7902        --This is caused by the 5353920 who has changed this query in one version and reverted back but didnt reverted this.
7903        --- Substitute Item SQL
7904        -- Bug# 6747729
7905        -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
7906        SELECT
7907        msi.concatenated_segments,
7908        msi.inventory_item_id,
7909        msi.description,
7910        Nvl(msi.revision_qty_control_code,1),
7911        Nvl(msi.lot_control_code, 1),
7912        Nvl(msi.serial_number_control_code, 1),
7913        Nvl(msi.restrict_subinventories_code, 2),
7914        Nvl(msi.restrict_locators_code,2),
7915        Nvl(msi.location_control_code,1),
7916        msi.primary_uom_code,
7917        Nvl(msi.inspection_required_flag,'N'),
7918        Nvl(msi.shelf_life_code, 1),
7919        Nvl(msi.shelf_life_days,0),
7920        Nvl(msi.allowed_units_lookup_code, 2),
7921        Nvl(msi.effectivity_control,1),
7922        0,
7923        0,
7924        Nvl(msi.default_serial_status_id,1),
7925        Nvl(msi.serial_status_enabled,'N'),
7926        Nvl(msi.default_lot_status_id,0),
7927        Nvl(msi.lot_status_enabled,'N'),
7928        '',
7929        'N',
7930        msi.inventory_item_flag,
7931        0,
7932 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
7933        msi.inventory_asset_flag,
7934        msi.outside_operation_flag,
7935        --Bug 3952081
7936        --Select DUOM Attributes for every Item
7937        NVL(MSI.GRADE_CONTROL_FLAG,'N'),
7938        NVL(MSI.DEFAULT_GRADE,''),
7939        NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
7940        NVL(MSI.EXPIRATION_ACTION_CODE,''),
7941        NVL(MSI.HOLD_DAYS,0),
7942        NVL(MSI.MATURITY_DAYS,0),
7943        NVL(MSI.RETEST_INTERVAL,0),
7944        NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
7945        NVL(MSI.CHILD_LOT_FLAG,'N'),
7946        NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
7947        NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
7948        NVL(MSI.SECONDARY_UOM_CODE,''),
7949        NVL(MSI.SECONDARY_DEFAULT_IND,''),
7950        NVL(MSI.TRACKING_QUANTITY_IND,'P'),
7951        NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
7952        NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
7953        msi.stock_enabled_flag,
7954        ' ',
7955        ' '      -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
7956        FROM
7957        mtl_system_items_vl msi /* Bug 5581528 */
7958        WHERE msi.organization_id = p_organization_Id
7959        AND msi.concatenated_segments LIKE  p_concatenated_segments||l_append
7960        AND (msi.purchasing_enabled_flag = 'Y' OR msi.stock_enabled_flag = 'Y')
7961        AND EXISTS (SELECT '1'
7962                      FROM po_lines_trx_v pol, -- CLM project, bug 9403291
7963                           mtl_related_items mri,
7964                           po_line_locations_trx_v pll -- CLM project, bug 9403291
7965 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
7966                         , mtl_parameters mp,
7967                           rcv_parameters rp
7968 --  End for Bug 7440217
7969                     WHERE NVL(pll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED')
7970                       AND NVL(pll.allow_substitute_receipts_flag, 'N') = 'Y'
7971                       AND pll.po_line_id = pol.po_line_id
7972                       AND pll.ship_to_organization_id = msi.organization_id
7973                       AND ((    mri.related_item_id = msi.inventory_item_id
7974                       AND pol.item_id = mri.inventory_item_id)
7975                        OR
7976                        (    mri.inventory_item_id = msi.inventory_item_id
7977                         AND pol.item_id = mri.related_item_id
7978                         AND mri.reciprocal_flag = 'Y')
7979                        )
7980 --  For Bug 7440217 Checking if it is LCM enabled
7981                       AND mp.organization_id = p_organization_id
7982                       AND rp.organization_id = p_organization_id
7983                       AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
7984                             OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
7985                                 OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
7986                            )
7987 --  End for Bug 7440217
7988                    )
7989        UNION ALL
7990        ---- Vendor Item SQL
7991        -- Bug# 6747729
7992        -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
7993        SELECT DISTINCT
7994        pol.vendor_product_num,
7995        msi.inventory_item_id,
7996        msi.description,
7997        Nvl(msi.revision_qty_control_code,1),
7998        Nvl(msi.lot_control_code, 1),
7999        Nvl(msi.serial_number_control_code, 1),
8000        Nvl(msi.restrict_subinventories_code, 2),
8001        Nvl(msi.restrict_locators_code,2),
8002        Nvl(msi.location_control_code,1),
8003        msi.primary_uom_code,
8004        Nvl(msi.inspection_required_flag,'N'),
8005        Nvl(msi.shelf_life_code, 1),
8006        Nvl(msi.shelf_life_days,0),
8007        Nvl(msi.allowed_units_lookup_code, 2),
8008        Nvl(msi.effectivity_control,1),
8009        0,
8010        0,
8011        Nvl(msi.default_serial_status_id,1),
8012        Nvl(msi.serial_status_enabled,'N'),
8013        Nvl(msi.default_lot_status_id,0),
8014        Nvl(msi.lot_status_enabled,'N'),
8015        msi.concatenated_segments,
8016        'Y',
8017        msi.inventory_item_flag,
8018        0,
8019 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
8020        msi.inventory_asset_flag,
8021        msi.outside_operation_flag,
8022        --Bug 3952081
8023        --Select DUOM Attributes for every Item
8024        NVL(MSI.GRADE_CONTROL_FLAG,'N'),
8025        NVL(MSI.DEFAULT_GRADE,''),
8026        NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
8027        NVL(MSI.EXPIRATION_ACTION_CODE,''),
8028        NVL(MSI.HOLD_DAYS,0),
8029        NVL(MSI.MATURITY_DAYS,0),
8030        NVL(MSI.RETEST_INTERVAL,0),
8031        NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
8032        NVL(MSI.CHILD_LOT_FLAG,'N'),
8033        NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
8034        NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
8035        NVL(MSI.SECONDARY_UOM_CODE,''),
8036        NVL(MSI.SECONDARY_DEFAULT_IND,''),
8037        NVL(MSI.TRACKING_QUANTITY_IND,'P'),
8038        NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
8039        NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
8040        msi.stock_enabled_flag,
8041        ' ',
8042        ' '      -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
8043        FROM
8044        po_lines_trx_v pol, -- CLM project, bug 9403291
8045        mtl_system_items_vl msi /* Bug 5581528 */
8046        WHERE msi.organization_id = p_organization_Id
8047        AND (msi.purchasing_enabled_flag = 'Y' OR msi.stock_enabled_flag = 'Y')
8048        AND pol.vendor_product_num like p_concatenated_segments
8049        AND pol.item_id = msi.inventory_item_id
8050        AND pol.vendor_product_num IS NOT NULL
8051        AND EXISTS (SELECT '1'
8052                      FROM po_line_locations_trx_v pll -- CLM project, bug 9403291
8053 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
8054                         , mtl_parameters mp,
8055                           rcv_parameters rp
8056 --  End for Bug 7440217
8057                     WHERE pll.po_line_id = pol.po_line_id
8058                       AND pll.ship_to_organization_id = msi.organization_id
8059                       AND NVL(pll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED')
8060 --  For Bug 7440217 Checking if it is LCM enabled
8061                       AND mp.organization_id = p_organization_id
8062                       AND rp.organization_id = p_organization_id
8063                       AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
8064                             OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
8065                                 OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
8066                           )
8067 --  End for Bug 7440217
8068                    )
8069        UNION ALL
8070        --- Cross Ref Items
8071        -- Bug# 6747729
8072        -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
8073        SELECT DISTINCT
8074        mcr.cross_reference,
8075        msi.inventory_item_id,
8076        msi.description,
8077        Nvl(msi.revision_qty_control_code,1),
8078        Nvl(msi.lot_control_code, 1),
8079        Nvl(msi.serial_number_control_code, 1),
8080        Nvl(msi.restrict_subinventories_code, 2),
8081        Nvl(msi.restrict_locators_code,2),
8082        Nvl(msi.location_control_code,1),
8083        msi.primary_uom_code,
8084        Nvl(msi.inspection_required_flag,'N'),
8085        Nvl(msi.shelf_life_code, 1),
8086        Nvl(msi.shelf_life_days,0),
8087        Nvl(msi.allowed_units_lookup_code, 2),
8088        Nvl(msi.effectivity_control,1),
8089        0,
8090        0,
8091        Nvl(msi.default_serial_status_id,1),
8092        Nvl(msi.serial_status_enabled,'N'),
8093        Nvl(msi.default_lot_status_id,0),
8094        Nvl(msi.lot_status_enabled,'N'),
8095        msi.concatenated_segments,
8096        'C',
8097        msi.inventory_item_flag,
8098        0,
8099 	  wms_deploy.get_item_client_name(msi.inventory_item_id),
8100        msi.inventory_asset_flag,
8101        msi.outside_operation_flag,
8102        --Bug 3952081
8103        --Select DUOM Attributes for every Item
8104        NVL(MSI.GRADE_CONTROL_FLAG,'N'),
8105        NVL(MSI.DEFAULT_GRADE,''),
8106        NVL(MSI.EXPIRATION_ACTION_INTERVAL,0),
8107        NVL(MSI.EXPIRATION_ACTION_CODE,''),
8108        NVL(MSI.HOLD_DAYS,0),
8109        NVL(MSI.MATURITY_DAYS,0),
8110        NVL(MSI.RETEST_INTERVAL,0),
8111        NVL(MSI.COPY_LOT_ATTRIBUTE_FLAG,'N'),
8112        NVL(MSI.CHILD_LOT_FLAG,'N'),
8113        NVL(MSI.CHILD_LOT_VALIDATION_FLAG,'N'),
8114        NVL(MSI.LOT_DIVISIBLE_FLAG,'Y'),
8115        NVL(MSI.SECONDARY_UOM_CODE,''),
8116        NVL(MSI.SECONDARY_DEFAULT_IND,''),
8117        NVL(MSI.TRACKING_QUANTITY_IND,'P'),
8118        NVL(MSI.DUAL_UOM_DEVIATION_HIGH,0),
8119        NVL(MSI.DUAL_UOM_DEVIATION_LOW,0),
8120        msi.stock_enabled_flag,
8121        ' ',
8122        ' '      -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
8123        FROM
8124        mtl_system_items_vl msi, /* Bug 5581528 */
8125        mtl_cross_references mcr
8126        WHERE msi.organization_id = p_organization_Id
8127        AND ( (mcr.cross_reference_type = p_crossreftype
8128                AND mcr.cross_reference LIKE  p_concatenated_segments
8129               ) OR
8130               ( mcr.cross_reference_type = g_gtin_cross_ref_type
8131                AND mcr.cross_reference      LIKE g_crossref )
8132             )
8133        AND ( (mcr.org_independent_flag = 'Y') OR (mcr.org_independent_flag = 'N'
8134        AND mcr.organization_id = p_organization_Id
8135                ) )
8136        AND mcr.inventory_item_id = msi.inventory_item_id
8137        AND (msi.purchasing_enabled_flag = 'Y' OR msi.stock_enabled_flag = 'Y')
8138        UNION ALL
8139        -- Non Item Master
8140        -- Bug# 6747729
8141        -- Added code to also fetch stock_enabled_flag from mtl_system_items_v
8142        SELECT DISTINCT pol.item_description,
8143        to_number(''),
8144        pol.item_description,
8145        1,
8146        1,
8147        1,
8148        2,
8149        2,
8150        1,
8151        mum.uom_code,
8152        'N',
8153        1,
8154        0,
8155        2,
8156        1,
8157        0,
8158        0,
8159         1,
8160        'N',
8161        0,
8162        'N',
8163        '',
8164        'N',
8165        'N',
8166        0,
8167 	  wms_deploy.get_item_client_name(pol.item_id),
8168        to_char(NULL),
8169        'N',
8170          --Bug 3952081
8171          --Select DUOM Attributes for every Item
8172          'N',
8173          '',
8174          0,
8175          '',
8176          0,
8177          0,
8178          0,
8179          'N',
8180          'N',
8181          'N',
8182          'Y',
8183          '',
8184          '',
8185          'P',
8186          0,
8187          0,
8188          'N',
8189        ' ',
8190        ' '      -- Added by Bug9257750 for values corr to Shipment Number and Shipment Header id
8191        FROM
8192        po_lines_trx_v pol, -- CLM project, bug 9403291
8193        mtl_units_of_measure mum
8194   -- Bug 2619063, 2614016
8195   -- Modified to select the base uom for the uom class defined on po.
8196        WHERE mum.uom_class = (SELECT mum2.uom_class
8197               FROM mtl_units_of_measure mum2
8198              WHERE mum2.unit_of_measure(+) = pol.unit_meas_lookup_code)
8199        AND mum.base_uom_flag = 'Y'
8200        AND pol.ITEM_ID is NULL
8201        AND pol.item_description IS NOT NULL
8202        AND pol.item_description LIKE p_concatenated_segments
8203        AND EXISTS (SELECT '1'
8204                      FROM po_line_locations_trx_v pll -- CLM project, bug 9403291
8205 --  For Bug 7440217 Added MTL_PARAMETERS and RCV_PRAMETERS to find out if the organization is LCM enabled or not
8206                         , mtl_parameters mp,
8207                           rcv_parameters rp
8208 --  End for Bug 7440217
8209                     WHERE pll.po_line_id = pol.po_line_id
8210                       AND pll.ship_to_organization_id = p_organization_id
8211 --  For Bug 7440217 Checking if it is LCM enabled
8212                       AND mp.organization_id = p_organization_id
8213                       AND rp.organization_id = p_organization_id
8214                       AND ((NVL(mp.lcm_enabled_flag,'N') = 'N') -- Org is non-lcm enabled
8215                             OR (NVL(rp.pre_receive,'N') = 'N')      -- Org is lcm enabled and it is post-receiving
8216                                 OR (NVL(pll.lcm_flag,'N') = 'N')       -- Org is lcm enabled, pre-receiving and non-lcm enabled shipment
8217                           )
8218 --  End for Bug 7440217
8219                       AND NVL(pll.closed_code,'OPEN') NOT IN ('FINALLY CLOSED','CLOSED FOR RECEIVING', 'CLOSED'));
8220 end if;
8221 
8222 END GET_ITEM_LOV_RECEIVING ;
8223 -- ************** End of Bug 2442518
8224 
8225 PROCEDURE GET_ITEM_LOV_INVTXN (
8226 x_Items                               OUT NOCOPY t_genref,
8227 p_Organization_Id                     IN NUMBER   default null ,
8228 p_Concatenated_Segments               IN VARCHAR2 default null )
8229 IS
8230    g_gtin_cross_ref_type VARCHAR2(25) := fnd_profile.value('INV:GTIN_CROSS_REFERENCE_TYPE');
8231    g_gtin_code_length NUMBER := 14;
8232    g_crossref         VARCHAR2(40) := lpad(Rtrim(p_concatenated_segments, '%'), g_gtin_code_length, '00000000000000');
8233    l_append varchar2(2):='';
8234 BEGIN
8235 
8236 	l_append:=wms_deploy.get_item_suffix_for_lov(p_concatenated_segments);
8237 
8238        open x_items for
8239 
8240        select concatenated_segments,
8241        inventory_item_id,
8242        description,
8243        Nvl(revision_qty_control_code,1),
8244        Nvl(lot_control_code, 1),
8245        Nvl(serial_number_control_code, 1),
8246        Nvl(restrict_subinventories_code, 2),
8247        Nvl(restrict_locators_code, 2),
8248        Nvl(location_control_code, 1),
8249        primary_uom_code,
8250        Nvl(inspection_required_flag, 'N'),
8251        Nvl(shelf_life_code, 1),
8252        Nvl(shelf_life_days,0),
8253        Nvl(allowed_units_lookup_code, 2),
8254        Nvl(effectivity_control,1),
8255        0,
8256        0,
8257        Nvl(default_serial_status_id,1),
8258        Nvl(serial_status_enabled,'N'),
8259        Nvl(default_lot_status_id,0),
8260        Nvl(lot_status_enabled,'N'),
8261        '',
8262        'N',
8263        inventory_item_flag,
8264        0,
8265 	 wms_deploy.get_item_client_name(inventory_item_id),
8266        inventory_asset_flag,
8267        outside_operation_flag,
8268          --Bug 3952081
8269          --Select DUOM Attributes for every Item
8270          NVL(GRADE_CONTROL_FLAG,'N'),
8271          NVL(DEFAULT_GRADE,''),
8272          NVL(EXPIRATION_ACTION_INTERVAL,0),
8273          NVL(EXPIRATION_ACTION_CODE,''),
8274          NVL(HOLD_DAYS,0),
8275          NVL(MATURITY_DAYS,0),
8276          NVL(RETEST_INTERVAL,0),
8277          NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
8278          NVL(CHILD_LOT_FLAG,'N'),
8279          NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
8280          NVL(LOT_DIVISIBLE_FLAG,'Y'),
8281          NVL(SECONDARY_UOM_CODE,''),
8282          NVL(SECONDARY_DEFAULT_IND,''),
8283          NVL(TRACKING_QUANTITY_IND,'P'),
8284          NVL(DUAL_UOM_DEVIATION_HIGH,0),
8285          NVL(DUAL_UOM_DEVIATION_LOW,0)
8286        from mtl_system_items_vl
8287        WHERE organization_id = p_Organization_Id
8288        and concatenated_segments like p_concatenated_segments||l_append
8289        and mtl_transactions_enabled_flag = 'Y'
8290        and bom_item_type=4
8291 
8292    UNION
8293 
8294    select msik.concatenated_segments,
8295        msik.inventory_item_id,
8296        msik.description,
8297        Nvl(revision_qty_control_code,1),
8298        Nvl(lot_control_code, 1),
8299        Nvl(serial_number_control_code, 1),
8300        Nvl(restrict_subinventories_code, 2),
8301        Nvl(restrict_locators_code, 2),
8302        Nvl(location_control_code, 1),
8303        primary_uom_code,
8304        Nvl(inspection_required_flag, 'N'),
8305        Nvl(shelf_life_code, 1),
8306        Nvl(shelf_life_days,0),
8307        Nvl(allowed_units_lookup_code, 2),
8308        Nvl(effectivity_control,1),
8309        0,
8310        0,
8311        Nvl(default_serial_status_id,1),
8312        Nvl(serial_status_enabled,'N'),
8313        Nvl(default_lot_status_id,0),
8314        Nvl(lot_status_enabled,'N'),
8315        mcr.cross_reference,
8316        'N',
8317        inventory_item_flag,
8318        0,
8319 	 wms_deploy.get_item_client_name(msik.inventory_item_id),
8320        inventory_asset_flag,
8321        outside_operation_flag,
8322          --Bug 3952081
8323          --Select DUOM Attributes for every Item
8324          NVL(GRADE_CONTROL_FLAG,'N'),
8325          NVL(DEFAULT_GRADE,''),
8326          NVL(EXPIRATION_ACTION_INTERVAL,0),
8327          NVL(EXPIRATION_ACTION_CODE,''),
8328          NVL(HOLD_DAYS,0),
8329          NVL(MATURITY_DAYS,0),
8330          NVL(RETEST_INTERVAL,0),
8331          NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
8332          NVL(CHILD_LOT_FLAG,'N'),
8333          NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
8334          NVL(LOT_DIVISIBLE_FLAG,'Y'),
8335          NVL(SECONDARY_UOM_CODE,''),
8336          NVL(SECONDARY_DEFAULT_IND,''),
8337          NVL(TRACKING_QUANTITY_IND,'P'),
8338          NVL(DUAL_UOM_DEVIATION_HIGH,0),
8339          NVL(DUAL_UOM_DEVIATION_LOW,0)
8340        from mtl_system_items_vl msik, /* Bug 5581528 */
8341             mtl_cross_references mcr
8342        WHERE msik.organization_id = p_Organization_Id
8343    AND msik.inventory_item_id   = mcr.inventory_item_id
8344    AND mcr.cross_reference_type = g_gtin_cross_ref_type
8345    AND mcr.cross_reference      LIKE g_crossref
8346    AND (mcr.organization_id     = msik.organization_id
8347     OR
8348         mcr.org_independent_flag = 'Y')
8349    AND mtl_transactions_enabled_flag = 'Y' --Added for bug 5196506
8350    AND bom_item_type=4; --Added for bug 5196506
8351 
8352 
8353 END GET_ITEM_LOV_INVTXN;
8354 
8355 -- Use of Bind Variables in Inspect Page
8356 -- 2442758
8357 
8358 PROCEDURE GET_LPN_LOV_INSPECT
8359   (x_lpn_lov  OUT  NOCOPY t_genref,
8360    p_lpn      IN   VARCHAR2,
8361    p_orgid    IN   NUMBER ,
8362    p_projid   IN   NUMBER ,
8363    p_taskid   IN   NUMBER
8364 )
8365 IS
8366 BEGIN
8367    OPEN x_lpn_lov FOR
8368      SELECT DISTINCT wlpn.license_plate_number,
8369            wlpn.lpn_id,
8370            NVL(wlpn.inventory_item_id, 0),
8371            NVL(wlpn.organization_id, 0),
8372            wlpn.revision,
8373            wlpn.lot_number,
8374            wlpn.serial_number,
8375            wlpn.subinventory_code,
8376            NVL(wlpn.locator_id, 0),
8377            NVL(wlpn.parent_lpn_id, 0),
8378            NVL(wlpn.sealed_status, 2),
8379            wlpn.gross_weight_uom_code,
8380            NVL(wlpn.gross_weight, 0),
8381            wlpn.content_volume_uom_code,
8382            NVL(wlpn.content_volume, 0),
8383            milk.concatenated_segments,
8384            wlpn.lpn_context
8385      FROM  wms_license_plate_numbers wlpn,
8386            mtl_item_locations_kfv milk,
8387            wms_lpn_contents wlc
8388      WHERE wlpn.organization_id = milk.organization_id (+)
8389        AND wlpn.locator_id = milk.inventory_location_id(+)
8390        AND wlc.parent_lpn_id (+) = wlpn.lpn_id
8391        AND wlpn.license_plate_number LIKE p_lpn
8392        AND wlpn.organization_id = p_orgid
8393        AND wlpn.lpn_context in (3,5)
8394        AND (wlpn.lpn_context = 3 and wlpn.lpn_id  IN (Select mtrl.lpn_id from mtl_txn_request_lines mtrl
8395             where mtrl.lpn_id = wlpn.lpn_id AND NVL(mtrl.project_id, -99)  = p_projid
8396             AND NVL(mtrl.task_id, -99) = p_taskid ) )
8397        ORDER BY wlpn.license_plate_number
8398        ;
8399 END GET_LPN_LOV_INSPECT;
8400 
8401 PROCEDURE GET_LPN_LOV_INVTXN
8402   (x_lpn_lov  OUT  NOCOPY t_genref,
8403    p_lpn      IN   VARCHAR2,
8404    p_orgid    IN   NUMBER
8405 )
8406 IS
8407 BEGIN
8408    OPEN x_lpn_lov FOR
8409      SELECT DISTINCT wlpn.license_plate_number,
8410            wlpn.lpn_id,
8411            NVL(wlpn.inventory_item_id, 0),
8412            NVL(wlpn.organization_id, 0),
8413            wlpn.revision,
8414            wlpn.lot_number,
8415            wlpn.serial_number,
8416            wlpn.subinventory_code,
8417            NVL(wlpn.locator_id, 0),
8418            NVL(wlpn.parent_lpn_id, 0),
8419            NVL(wlpn.sealed_status, 2),
8420            wlpn.gross_weight_uom_code,
8421            NVL(wlpn.gross_weight, 0),
8422            wlpn.content_volume_uom_code,
8423            NVL(wlpn.content_volume, 0),
8424            milk.concatenated_segments,
8425            wlpn.lpn_context
8426      FROM  wms_license_plate_numbers wlpn,
8427            mtl_item_locations_kfv milk,
8428            wms_lpn_contents wlc
8429      WHERE wlpn.organization_id = milk.organization_id (+)
8430        AND wlpn.locator_id = milk.inventory_location_id(+)
8431        AND wlc.parent_lpn_id (+) = wlpn.lpn_id
8432        AND wlpn.license_plate_number LIKE p_lpn
8433        AND wlpn.lpn_context in (1,5)
8434        AND wlpn.organization_id = p_orgid
8435        ;
8436 END GET_LPN_LOV_INVTXN;
8437 
8438 PROCEDURE GET_LPN_LOV_PJM
8439   (x_lpn_lov  OUT  NOCOPY t_genref,
8440    p_lpn      IN   VARCHAR2,
8441    p_orgid    IN   NUMBER
8442 )
8443 IS
8444 BEGIN
8445    OPEN x_lpn_lov FOR
8446      SELECT DISTINCT wlpn.license_plate_number,
8447            wlpn.lpn_id,
8448            NVL(wlpn.inventory_item_id, 0),
8449            NVL(wlpn.organization_id, 0),
8450            wlpn.revision,
8451            wlpn.lot_number,
8452            wlpn.serial_number,
8453            wlpn.subinventory_code,
8454            NVL(wlpn.locator_id, 0),
8455            NVL(wlpn.parent_lpn_id, 0),
8456            NVL(wlpn.sealed_status, 2),
8457            wlpn.gross_weight_uom_code,
8458            NVL(wlpn.gross_weight, 0),
8459            wlpn.content_volume_uom_code,
8460            NVL(wlpn.content_volume, 0),
8461            INV_PROJECT.GET_LOCSEGS(milk.inventory_location_id,milk.organization_id),
8462            INV_PROJECT.GET_PROJECT_ID,
8463            INV_PROJECT.GET_PROJECT_NUMBER,
8464            INV_PROJECT.GET_TASK_ID,
8465            INV_PROJECT.GET_TASK_NUMBER,
8466            wlpn.lpn_context
8467      FROM  wms_license_plate_numbers wlpn,
8468            mtl_item_locations_kfv milk,
8469            wms_lpn_contents wlc
8470      WHERE wlpn.organization_id = milk.organization_id (+)
8471        AND wlpn.locator_id = milk.inventory_location_id(+)
8472        AND wlc.parent_lpn_id (+) = wlpn.lpn_id
8473        AND wlpn.license_plate_number LIKE p_lpn
8474        AND wlpn.lpn_context in (1,5)
8475        AND wlpn.organization_id = p_orgid
8476        ;
8477 END GET_LPN_LOV_PJM;
8478 
8479 PROCEDURE GET_COUNTRY_LOV
8480   (x_country_lov OUT NOCOPY t_genref,
8481    p_country IN VARCHAR2 )
8482 IS
8483 BEGIN
8484   OPEN x_country_lov FOR
8485        SELECT  territory_code, territory_short_name
8486          FROM  fnd_territories_vl
8487         WHERE  territory_code LIKE p_country || '%'
8488      ORDER BY  territory_code;
8489 END GET_COUNTRY_LOV;
8490 
8491 PROCEDURE get_hr_hz_locations_lov(
8492   x_location_codes OUT NOCOPY t_genref,
8493   p_location_code IN VARCHAR2) IS
8494   -- This procedure will return all HR and HZ Active Locations.
8495   -- Added as part of eIB Build; Bug# 4348541
8496 BEGIN
8497   OPEN x_location_codes FOR
8498   SELECT location_code, location_id, description
8499   FROM( SELECT hr.location_code location_code,
8500                hr.location_id location_id,
8501                hr.description
8502          FROM hr_locations hr
8503          WHERE NVL(inactive_date, SYSDATE+1) > SYSDATE
8504          UNION
8505          SELECT DECODE (
8506            inv_check_product_install.check_cse_install,
8507            'Y', NVL(clli_code, SUBSTR(city, 1, 10) || SUBSTR(location_id, 1, 10)),
8508            SUBSTR (city, 1, 10)|| SUBSTR (location_id, 1, 10)) location_code,
8509            hz.location_id location_id,
8510            hz.short_description
8511          FROM hz_locations hz
8512          WHERE (SYSDATE BETWEEN NVL(hz.address_effective_date,  SYSDATE-1) AND
8513                                 NVL(hz.address_expiration_date, SYSDATE+1)))
8514   WHERE UPPER(location_code) LIKE UPPER(NVL(p_location_code, location_code)||'%')
8515   ORDER BY location_code;
8516 END get_hr_hz_locations_lov;
8517 
8518 --Added for BUG 4309432
8519 PROCEDURE GET_ACTRJTQTY_LOV
8520   (x_actrjtqty_lov OUT NOCOPY t_genref,
8521    p_deliver_type IN VARCHAR2)
8522 IS
8523 BEGIN
8524   OPEN x_actrjtqty_lov FOR
8525        SELECT lookup_code, meaning
8526          FROM mfg_lookups
8527         WHERE lookup_type = 'INV_RCV_DELIVER_TYPE'
8528           AND meaning LIKE p_deliver_type || '%' ;
8529 END GET_ACTRJTQTY_LOV;
8530 
8531 --Added for Bug 4498173
8532 PROCEDURE GET_INV_ITEM_LOV_RECEIVING
8533 (
8534 	x_Items				OUT NOCOPY t_genref,
8535 	p_Organization_Id		IN NUMBER,
8536 	p_Concatenated_Segments		IN VARCHAR2,
8537 	p_receiptNum			IN VARCHAR2,
8538 	p_poHeaderID			IN VARCHAR2,
8539 	p_poReleaseID			IN VARCHAR2,
8540 	p_poLineID			IN VARCHAR2,
8541 	p_shipmentHeaderID		IN VARCHAR2,
8542 	p_oeOrderHeaderID		IN VARCHAR2,
8543 	p_reqHeaderID			IN VARCHAR2,
8544 	p_shipmentHeaderReceipt		IN VARCHAR2
8545 )
8546 
8547 IS
8548 
8549 g_gtin_cross_ref_type VARCHAR2(25) := fnd_profile.value('INV:GTIN_CROSS_REFERENCE_TYPE');
8550 g_gtin_code_length NUMBER := 14;
8551 g_crossref         VARCHAR2(40) := lpad(Rtrim(p_concatenated_segments, '%'), g_gtin_code_length, '00000000000000');
8552 l_append varchar2(2):='';
8553 
8554 BEGIN
8555     l_append:=wms_deploy.get_item_suffix_for_lov(p_concatenated_segments);
8556 
8557     IF (p_receiptNum IS NOT NULL ) THEN
8558 
8559         open x_items for
8560 	SELECT
8561 	concatenated_segments,
8562 	msik.inventory_item_id,
8563 	msik.description,
8564 	Nvl(revision_qty_control_code,1),
8565 	Nvl(lot_control_code, 1),
8566 	Nvl(serial_number_control_code, 1),
8567 	Nvl(restrict_subinventories_code, 2),
8568 	Nvl(restrict_locators_code, 2),
8569 	Nvl(location_control_code, 1),
8570 	primary_uom_code,
8571 	Nvl(inspection_required_flag, 'N'),
8572 	Nvl(shelf_life_code, 1),
8573 	Nvl(shelf_life_days,0),
8574 	Nvl(allowed_units_lookup_code, 2),
8575 	Nvl(effectivity_control,1),
8576 	0,
8577 	0,
8578 	Nvl(default_serial_status_id,1),
8579 	Nvl(serial_status_enabled,'N'),
8580 	Nvl(default_lot_status_id,0),
8581 	Nvl(lot_status_enabled,'N'),
8582 	null,
8583 	'N',
8584 	inventory_item_flag,
8585 	0,
8586       wms_deploy.get_item_client_name(msik.inventory_item_id),
8587 	inventory_asset_flag,
8588 	outside_operation_flag,
8589 	--Bug 3952081
8590 	--Select DUOM Attributes for every Item
8591 	NVL(GRADE_CONTROL_FLAG,'N'),
8592 	NVL(DEFAULT_GRADE,''),
8593 	NVL(EXPIRATION_ACTION_INTERVAL,0),
8594 	NVL(EXPIRATION_ACTION_CODE,''),
8595 	NVL(HOLD_DAYS,0),
8596 	NVL(MATURITY_DAYS,0),
8597 	NVL(RETEST_INTERVAL,0),
8598 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
8599 	NVL(CHILD_LOT_FLAG,'N'),
8600 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
8601 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
8602 	NVL(SECONDARY_UOM_CODE,''),
8603 	NVL(SECONDARY_DEFAULT_IND,''),
8604 	NVL(TRACKING_QUANTITY_IND,'P'),
8605 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
8606 	NVL(DUAL_UOM_DEVIATION_LOW,0)
8607 	FROM
8608 	mtl_system_items_vl msik /* Bug 5581528 */
8609 	WHERE
8610 	organization_id = p_Organization_Id
8611 	AND concatenated_segments like p_concatenated_segments||l_append
8612 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
8613 	AND msik.inventory_item_id IN	(
8614 					SELECT item_id
8615 					from rcv_supply
8616 					WHERE shipment_header_id = p_shipmentHeaderReceipt
8617 					)
8618 	UNION
8619 
8620 	select
8621 	concatenated_segments,
8622 	msik.inventory_item_id,
8623 	msik.description,
8624 	Nvl(revision_qty_control_code,1),
8625 	Nvl(lot_control_code, 1),
8626 	Nvl(serial_number_control_code, 1),
8627 	Nvl(restrict_subinventories_code, 2),
8628 	Nvl(restrict_locators_code, 2),
8629 	Nvl(location_control_code, 1),
8630 	primary_uom_code,
8631 	Nvl(inspection_required_flag, 'N'),
8632 	Nvl(shelf_life_code, 1),
8633 	Nvl(shelf_life_days,0),
8634 	Nvl(allowed_units_lookup_code, 2),
8635 	Nvl(effectivity_control,1),
8636 	0,
8637 	0,
8638 	Nvl(default_serial_status_id,1),
8639 	Nvl(serial_status_enabled,'N'),
8640 	Nvl(default_lot_status_id,0),
8641 	Nvl(lot_status_enabled,'N'),
8642 	mcr.cross_reference,
8643 	'N',
8644 	inventory_item_flag,
8645 	0,
8646       wms_deploy.get_item_client_name(msik.inventory_item_id),
8647 	inventory_asset_flag,
8648 	outside_operation_flag,
8649 	--Bug No 3952081
8650 	--Additional Fields for Process Convergence
8651 	NVL(GRADE_CONTROL_FLAG,'N'),
8652 	NVL(DEFAULT_GRADE,''),
8653 	NVL(EXPIRATION_ACTION_INTERVAL,0),
8654 	NVL(EXPIRATION_ACTION_CODE,''),
8655 	NVL(HOLD_DAYS,0),
8656 	NVL(MATURITY_DAYS,0),
8657 	NVL(RETEST_INTERVAL,0),
8658 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
8659 	NVL(CHILD_LOT_FLAG,'N'),
8660 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
8661 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
8662 	NVL(SECONDARY_UOM_CODE,''),
8663 	NVL(SECONDARY_DEFAULT_IND,''),
8664 	NVL(TRACKING_QUANTITY_IND,'P'),
8665 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
8666 	NVL(DUAL_UOM_DEVIATION_LOW,0)
8667 	FROM
8668 	mtl_system_items_vl msik,  /* Bug 5581528 */
8669 	mtl_cross_references mcr
8670 	WHERE
8671 	msik.organization_id = p_organization_id
8672 	AND msik.inventory_item_id = mcr.inventory_item_id
8673 	AND mcr.cross_reference_type = g_gtin_cross_ref_type
8674 	AND mcr.cross_reference  like g_crossref
8675 	AND (mcr.organization_id = msik.organization_id
8676 	     OR mcr.org_independent_flag = 'Y' )
8677 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
8678 	AND msik.inventory_item_id IN	(
8679 					SELECT item_id
8680 					from rcv_supply
8681 					WHERE shipment_header_id = p_shipmentHeaderReceipt
8682 					);
8683 
8684    ELSIF (p_poHeaderID IS NOT NULL ) THEN
8685 
8686       IF (p_poReleaseID IS NOT NULL ) THEN
8687         open x_items for
8688 	SELECT
8689 	concatenated_segments,
8690 	msik.inventory_item_id,
8691 	msik.description,
8692 	Nvl(revision_qty_control_code,1),
8693 	Nvl(lot_control_code, 1),
8694 	Nvl(serial_number_control_code, 1),
8695 	Nvl(restrict_subinventories_code, 2),
8696 	Nvl(restrict_locators_code, 2),
8697 	Nvl(location_control_code, 1),
8698 	primary_uom_code,
8699 	Nvl(inspection_required_flag, 'N'),
8700 	Nvl(shelf_life_code, 1),
8701 	Nvl(shelf_life_days,0),
8702 	Nvl(allowed_units_lookup_code, 2),
8703 	Nvl(effectivity_control,1),
8704 	0,
8705 	0,
8706 	Nvl(default_serial_status_id,1),
8707 	Nvl(serial_status_enabled,'N'),
8708 	Nvl(default_lot_status_id,0),
8709 	Nvl(lot_status_enabled,'N'),
8710 	null,
8711 	'N',
8712 	inventory_item_flag,
8713 	0,
8714       wms_deploy.get_item_client_name(msik.inventory_item_id),
8715 	inventory_asset_flag,
8716 	outside_operation_flag,
8717 	--Bug 3952081
8718 	--Select DUOM Attributes for every Item
8719 	NVL(GRADE_CONTROL_FLAG,'N'),
8720 	NVL(DEFAULT_GRADE,''),
8721 	NVL(EXPIRATION_ACTION_INTERVAL,0),
8722 	NVL(EXPIRATION_ACTION_CODE,''),
8723 	NVL(HOLD_DAYS,0),
8724 	NVL(MATURITY_DAYS,0),
8725 	NVL(RETEST_INTERVAL,0),
8726 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
8727 	NVL(CHILD_LOT_FLAG,'N'),
8728 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
8729 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
8730 	NVL(SECONDARY_UOM_CODE,''),
8731 	NVL(SECONDARY_DEFAULT_IND,''),
8732 	NVL(TRACKING_QUANTITY_IND,'P'),
8733 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
8734 	NVL(DUAL_UOM_DEVIATION_LOW,0)
8735 	FROM
8736 	mtl_system_items_vl msik /* Bug 5581528 */
8737 	WHERE
8738 	organization_id = p_Organization_Id
8739 	AND concatenated_segments like p_concatenated_segments||l_append
8740 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
8741 	AND msik.inventory_item_id IN (SELECT item_id FROM rcv_supply WHERE po_header_id = p_poHeaderID  and po_release_id = p_poReleaseID)
8742 	UNION
8743 	select
8744 	concatenated_segments,
8745 	msik.inventory_item_id,
8746 	msik.description,
8747 	Nvl(revision_qty_control_code,1),
8748 	Nvl(lot_control_code, 1),
8749 	Nvl(serial_number_control_code, 1),
8750 	Nvl(restrict_subinventories_code, 2),
8751 	Nvl(restrict_locators_code, 2),
8752 	Nvl(location_control_code, 1),
8753 	primary_uom_code,
8754 	Nvl(inspection_required_flag, 'N'),
8755 	Nvl(shelf_life_code, 1),
8756 	Nvl(shelf_life_days,0),
8757 	Nvl(allowed_units_lookup_code, 2),
8758 	Nvl(effectivity_control,1),
8759 	0,
8760 	0,
8761 	Nvl(default_serial_status_id,1),
8762 	Nvl(serial_status_enabled,'N'),
8763 	Nvl(default_lot_status_id,0),
8764 	Nvl(lot_status_enabled,'N'),
8765 	mcr.cross_reference,
8766 	'N',
8767 	inventory_item_flag,
8768 	0,
8769       wms_deploy.get_item_client_name(msik.inventory_item_id),
8770 	inventory_asset_flag,
8771 	outside_operation_flag,
8772 	--Bug No 3952081
8773 	--Additional Fields for Process Convergence
8774 	NVL(GRADE_CONTROL_FLAG,'N'),
8775 	NVL(DEFAULT_GRADE,''),
8776 	NVL(EXPIRATION_ACTION_INTERVAL,0),
8777 	NVL(EXPIRATION_ACTION_CODE,''),
8778 	NVL(HOLD_DAYS,0),
8779 	NVL(MATURITY_DAYS,0),
8780 	NVL(RETEST_INTERVAL,0),
8781 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
8782 	NVL(CHILD_LOT_FLAG,'N'),
8783 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
8784 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
8785 	NVL(SECONDARY_UOM_CODE,''),
8786 	NVL(SECONDARY_DEFAULT_IND,''),
8787 	NVL(TRACKING_QUANTITY_IND,'P'),
8788 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
8789 	NVL(DUAL_UOM_DEVIATION_LOW,0)
8790 	FROM
8791 	mtl_system_items_vl msik, /* Bug 5581528 */
8792 	mtl_cross_references mcr
8793 	WHERE
8794 	msik.organization_id = p_organization_id
8795 	AND msik.inventory_item_id = mcr.inventory_item_id
8796 	AND mcr.cross_reference_type = g_gtin_cross_ref_type
8797 	AND mcr.cross_reference  like g_crossref
8798 	AND (mcr.organization_id = msik.organization_id
8799 	     OR mcr.org_independent_flag = 'Y' )
8800 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
8801 	AND msik.inventory_item_id IN (SELECT item_id FROM rcv_supply WHERE po_header_id = p_poHeaderID  and po_release_id = p_poReleaseID);
8802 
8803       ELSIF (p_poLineID IS NOT null ) THEN
8804         open x_items for
8805 	SELECT
8806 	concatenated_segments,
8807 	msik.inventory_item_id,
8808 	msik.description,
8809 	Nvl(revision_qty_control_code,1),
8810 	Nvl(lot_control_code, 1),
8811 	Nvl(serial_number_control_code, 1),
8812 	Nvl(restrict_subinventories_code, 2),
8813 	Nvl(restrict_locators_code, 2),
8814 	Nvl(location_control_code, 1),
8815 	primary_uom_code,
8816 	Nvl(inspection_required_flag, 'N'),
8817 	Nvl(shelf_life_code, 1),
8818 	Nvl(shelf_life_days,0),
8819 	Nvl(allowed_units_lookup_code, 2),
8820 	Nvl(effectivity_control,1),
8821 	0,
8822 	0,
8823 	Nvl(default_serial_status_id,1),
8824 	Nvl(serial_status_enabled,'N'),
8825 	Nvl(default_lot_status_id,0),
8826 	Nvl(lot_status_enabled,'N'),
8827 	null,
8828 	'N',
8829 	inventory_item_flag,
8830 	0,
8831       wms_deploy.get_item_client_name(msik.inventory_item_id),
8832 	inventory_asset_flag,
8833 	outside_operation_flag,
8834 	--Bug 3952081
8835 	--Select DUOM Attributes for every Item
8836 	NVL(GRADE_CONTROL_FLAG,'N'),
8837 	NVL(DEFAULT_GRADE,''),
8838 	NVL(EXPIRATION_ACTION_INTERVAL,0),
8839 	NVL(EXPIRATION_ACTION_CODE,''),
8840 	NVL(HOLD_DAYS,0),
8841 	NVL(MATURITY_DAYS,0),
8842 	NVL(RETEST_INTERVAL,0),
8843 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
8844 	NVL(CHILD_LOT_FLAG,'N'),
8845 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
8846 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
8847 	NVL(SECONDARY_UOM_CODE,''),
8848 	NVL(SECONDARY_DEFAULT_IND,''),
8849 	NVL(TRACKING_QUANTITY_IND,'P'),
8850 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
8851 	NVL(DUAL_UOM_DEVIATION_LOW,0)
8852 	FROM
8853 	mtl_system_items_vl msik /* Bug 5581528 */
8854 	WHERE
8855 	organization_id = p_Organization_Id
8856 	AND concatenated_segments like p_concatenated_segments||l_append
8857 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
8858 	AND msik.inventory_item_id IN (SELECT item_id FROM rcv_supply WHERE po_header_id =  p_poHeaderID and po_line_id = p_poLineID )
8859 	UNION
8860 	select
8861 	concatenated_segments,
8862 	msik.inventory_item_id,
8863 	msik.description,
8864 	Nvl(revision_qty_control_code,1),
8865 	Nvl(lot_control_code, 1),
8866 	Nvl(serial_number_control_code, 1),
8867 	Nvl(restrict_subinventories_code, 2),
8868 	Nvl(restrict_locators_code, 2),
8869 	Nvl(location_control_code, 1),
8870 	primary_uom_code,
8871 	Nvl(inspection_required_flag, 'N'),
8872 	Nvl(shelf_life_code, 1),
8873 	Nvl(shelf_life_days,0),
8874 	Nvl(allowed_units_lookup_code, 2),
8875 	Nvl(effectivity_control,1),
8876 	0,
8877 	0,
8878 	Nvl(default_serial_status_id,1),
8879 	Nvl(serial_status_enabled,'N'),
8880 	Nvl(default_lot_status_id,0),
8881 	Nvl(lot_status_enabled,'N'),
8882 	mcr.cross_reference,
8883 	'N',
8884 	inventory_item_flag,
8885 	0,
8886       wms_deploy.get_item_client_name(msik.inventory_item_id),
8887 	inventory_asset_flag,
8888 	outside_operation_flag,
8889 	--Bug No 3952081
8890 	--Additional Fields for Process Convergence
8891 	NVL(GRADE_CONTROL_FLAG,'N'),
8892 	NVL(DEFAULT_GRADE,''),
8893 	NVL(EXPIRATION_ACTION_INTERVAL,0),
8894 	NVL(EXPIRATION_ACTION_CODE,''),
8895 	NVL(HOLD_DAYS,0),
8896 	NVL(MATURITY_DAYS,0),
8897 	NVL(RETEST_INTERVAL,0),
8898 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
8899 	NVL(CHILD_LOT_FLAG,'N'),
8900 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
8901 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
8902 	NVL(SECONDARY_UOM_CODE,''),
8903 	NVL(SECONDARY_DEFAULT_IND,''),
8904 	NVL(TRACKING_QUANTITY_IND,'P'),
8905 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
8906 	NVL(DUAL_UOM_DEVIATION_LOW,0)
8907 	FROM
8908 	mtl_system_items_vl msik,  /* Bug 5581528 */
8909 	mtl_cross_references mcr
8910 	WHERE
8911 	msik.organization_id = p_organization_id
8912 	AND msik.inventory_item_id = mcr.inventory_item_id
8913 	AND mcr.cross_reference_type = g_gtin_cross_ref_type
8914 	AND mcr.cross_reference  like g_crossref
8915 	AND (mcr.organization_id = msik.organization_id
8916 	     OR mcr.org_independent_flag = 'Y' )
8917 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
8918 	AND msik.inventory_item_id IN (SELECT item_id FROM rcv_supply WHERE po_header_id =  p_poHeaderID and po_line_id = p_poLineID );
8919 
8920       ELSE
8921         open x_items for
8922 	SELECT
8923 	concatenated_segments,
8924 	msik.inventory_item_id,
8925 	msik.description,
8926 	Nvl(revision_qty_control_code,1),
8927 	Nvl(lot_control_code, 1),
8928 	Nvl(serial_number_control_code, 1),
8929 	Nvl(restrict_subinventories_code, 2),
8930 	Nvl(restrict_locators_code, 2),
8931 	Nvl(location_control_code, 1),
8932 	primary_uom_code,
8933 	Nvl(inspection_required_flag, 'N'),
8934 	Nvl(shelf_life_code, 1),
8935 	Nvl(shelf_life_days,0),
8936 	Nvl(allowed_units_lookup_code, 2),
8937 	Nvl(effectivity_control,1),
8938 	0,
8939 	0,
8940 	Nvl(default_serial_status_id,1),
8941 	Nvl(serial_status_enabled,'N'),
8942 	Nvl(default_lot_status_id,0),
8943 	Nvl(lot_status_enabled,'N'),
8944 	null,
8945 	'N',
8946 	inventory_item_flag,
8947 	0,
8948       wms_deploy.get_item_client_name(msik.inventory_item_id),
8949 	inventory_asset_flag,
8950 	outside_operation_flag,
8951 	--Bug 3952081
8952 	--Select DUOM Attributes for every Item
8953 	NVL(GRADE_CONTROL_FLAG,'N'),
8954 	NVL(DEFAULT_GRADE,''),
8955 	NVL(EXPIRATION_ACTION_INTERVAL,0),
8956 	NVL(EXPIRATION_ACTION_CODE,''),
8957 	NVL(HOLD_DAYS,0),
8958 	NVL(MATURITY_DAYS,0),
8959 	NVL(RETEST_INTERVAL,0),
8960 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
8961 	NVL(CHILD_LOT_FLAG,'N'),
8962 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
8963 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
8964 	NVL(SECONDARY_UOM_CODE,''),
8965 	NVL(SECONDARY_DEFAULT_IND,''),
8966 	NVL(TRACKING_QUANTITY_IND,'P'),
8967 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
8968 	NVL(DUAL_UOM_DEVIATION_LOW,0)
8969 	FROM
8970 	mtl_system_items_vl msik /* Bug 5581528 */
8971 	WHERE
8972 	organization_id = p_Organization_Id
8973 	AND concatenated_segments like p_concatenated_segments||l_append
8974 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
8975 	AND msik.inventory_item_id IN (SELECT item_id FROM rcv_supply WHERE po_header_id = p_poHeaderID )
8976 	UNION
8977 	select
8978 	concatenated_segments,
8979 	msik.inventory_item_id,
8980 	msik.description,
8981 	Nvl(revision_qty_control_code,1),
8982 	Nvl(lot_control_code, 1),
8983 	Nvl(serial_number_control_code, 1),
8984 	Nvl(restrict_subinventories_code, 2),
8985 	Nvl(restrict_locators_code, 2),
8986 	Nvl(location_control_code, 1),
8987 	primary_uom_code,
8988 	Nvl(inspection_required_flag, 'N'),
8989 	Nvl(shelf_life_code, 1),
8990 	Nvl(shelf_life_days,0),
8991 	Nvl(allowed_units_lookup_code, 2),
8992 	Nvl(effectivity_control,1),
8993 	0,
8994 	0,
8995 	Nvl(default_serial_status_id,1),
8996 	Nvl(serial_status_enabled,'N'),
8997 	Nvl(default_lot_status_id,0),
8998 	Nvl(lot_status_enabled,'N'),
8999 	mcr.cross_reference,
9000 	'N',
9001 	inventory_item_flag,
9002 	0,
9003       wms_deploy.get_item_client_name(msik.inventory_item_id),
9004 	inventory_asset_flag,
9005 	outside_operation_flag,
9006 	--Bug No 3952081
9007 	--Additional Fields for Process Convergence
9008 	NVL(GRADE_CONTROL_FLAG,'N'),
9009 	NVL(DEFAULT_GRADE,''),
9010 	NVL(EXPIRATION_ACTION_INTERVAL,0),
9011 	NVL(EXPIRATION_ACTION_CODE,''),
9012 	NVL(HOLD_DAYS,0),
9013 	NVL(MATURITY_DAYS,0),
9014 	NVL(RETEST_INTERVAL,0),
9015 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
9016 	NVL(CHILD_LOT_FLAG,'N'),
9017 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
9018 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
9019 	NVL(SECONDARY_UOM_CODE,''),
9020 	NVL(SECONDARY_DEFAULT_IND,''),
9021 	NVL(TRACKING_QUANTITY_IND,'P'),
9022 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
9023 	NVL(DUAL_UOM_DEVIATION_LOW,0)
9024 	FROM
9025 	mtl_system_items_vl msik,  /* Bug 5581528 */
9026 	mtl_cross_references mcr
9027 	WHERE
9028 	msik.organization_id = p_organization_id
9029 	AND msik.inventory_item_id = mcr.inventory_item_id
9030 	AND mcr.cross_reference_type = g_gtin_cross_ref_type
9031 	AND mcr.cross_reference  like g_crossref
9032 	AND (mcr.organization_id = msik.organization_id
9033 	     OR mcr.org_independent_flag = 'Y' )
9034 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
9035 	AND msik.inventory_item_id IN (SELECT item_id FROM rcv_supply WHERE po_header_id = p_poHeaderID );
9036       end if;
9037 
9038     ELSIF (p_shipmentHeaderID IS NOT null ) THEN
9039         open x_items for
9040 	SELECT
9041 	concatenated_segments,
9042 	msik.inventory_item_id,
9043 	msik.description,
9044 	Nvl(revision_qty_control_code,1),
9045 	Nvl(lot_control_code, 1),
9046 	Nvl(serial_number_control_code, 1),
9047 	Nvl(restrict_subinventories_code, 2),
9048 	Nvl(restrict_locators_code, 2),
9049 	Nvl(location_control_code, 1),
9050 	primary_uom_code,
9051 	Nvl(inspection_required_flag, 'N'),
9052 	Nvl(shelf_life_code, 1),
9053 	Nvl(shelf_life_days,0),
9054 	Nvl(allowed_units_lookup_code, 2),
9055 	Nvl(effectivity_control,1),
9056 	0,
9057 	0,
9058 	Nvl(default_serial_status_id,1),
9059 	Nvl(serial_status_enabled,'N'),
9060 	Nvl(default_lot_status_id,0),
9061 	Nvl(lot_status_enabled,'N'),
9062 	null,
9063 	'N',
9064 	inventory_item_flag,
9065 	0,
9066       wms_deploy.get_item_client_name(msik.inventory_item_id),
9067 	inventory_asset_flag,
9068 	outside_operation_flag,
9069 	--Bug 3952081
9070 	--Select DUOM Attributes for every Item
9071 	NVL(GRADE_CONTROL_FLAG,'N'),
9072 	NVL(DEFAULT_GRADE,''),
9073 	NVL(EXPIRATION_ACTION_INTERVAL,0),
9074 	NVL(EXPIRATION_ACTION_CODE,''),
9075 	NVL(HOLD_DAYS,0),
9076 	NVL(MATURITY_DAYS,0),
9077 	NVL(RETEST_INTERVAL,0),
9078 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
9079 	NVL(CHILD_LOT_FLAG,'N'),
9080 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
9081 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
9082 	NVL(SECONDARY_UOM_CODE,''),
9083 	NVL(SECONDARY_DEFAULT_IND,''),
9084 	NVL(TRACKING_QUANTITY_IND,'P'),
9085 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
9086 	NVL(DUAL_UOM_DEVIATION_LOW,0)
9087 	FROM
9088 	mtl_system_items_vl msik /* Bug 5581528 */
9089 	WHERE
9090 	organization_id = p_Organization_Id
9091 	AND concatenated_segments like p_concatenated_segments||l_append
9092 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
9093 	AND msik.inventory_item_id IN (SELECT item_id FROM rcv_supply WHERE SHIPMENT_HEADER_ID = p_shipmentHeaderID )
9094 	UNION
9095 	select
9096 	concatenated_segments,
9097 	msik.inventory_item_id,
9098 	msik.description,
9099 	Nvl(revision_qty_control_code,1),
9100 	Nvl(lot_control_code, 1),
9101 	Nvl(serial_number_control_code, 1),
9102 	Nvl(restrict_subinventories_code, 2),
9103 	Nvl(restrict_locators_code, 2),
9104 	Nvl(location_control_code, 1),
9105 	primary_uom_code,
9106 	Nvl(inspection_required_flag, 'N'),
9107 	Nvl(shelf_life_code, 1),
9108 	Nvl(shelf_life_days,0),
9109 	Nvl(allowed_units_lookup_code, 2),
9110 	Nvl(effectivity_control,1),
9111 	0,
9112 	0,
9113 	Nvl(default_serial_status_id,1),
9114 	Nvl(serial_status_enabled,'N'),
9115 	Nvl(default_lot_status_id,0),
9116 	Nvl(lot_status_enabled,'N'),
9117 	mcr.cross_reference,
9118 	'N',
9119 	inventory_item_flag,
9120 	0,
9121       wms_deploy.get_item_client_name(msik.inventory_item_id),
9122 	inventory_asset_flag,
9123 	outside_operation_flag,
9124 	--Bug No 3952081
9125 	--Additional Fields for Process Convergence
9126 	NVL(GRADE_CONTROL_FLAG,'N'),
9127 	NVL(DEFAULT_GRADE,''),
9128 	NVL(EXPIRATION_ACTION_INTERVAL,0),
9129 	NVL(EXPIRATION_ACTION_CODE,''),
9130 	NVL(HOLD_DAYS,0),
9131 	NVL(MATURITY_DAYS,0),
9132 	NVL(RETEST_INTERVAL,0),
9133 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
9134 	NVL(CHILD_LOT_FLAG,'N'),
9135 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
9136 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
9137 	NVL(SECONDARY_UOM_CODE,''),
9138 	NVL(SECONDARY_DEFAULT_IND,''),
9139 	NVL(TRACKING_QUANTITY_IND,'P'),
9140 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
9141 	NVL(DUAL_UOM_DEVIATION_LOW,0)
9142 	FROM
9143 	mtl_system_items_vl msik,  /* Bug 5581528 */
9144 	mtl_cross_references mcr
9145 	WHERE
9146 	msik.organization_id = p_organization_id
9147 	AND msik.inventory_item_id = mcr.inventory_item_id
9148 	AND mcr.cross_reference_type = g_gtin_cross_ref_type
9149 	AND mcr.cross_reference  like g_crossref
9150 	AND (mcr.organization_id = msik.organization_id
9151 	     OR mcr.org_independent_flag = 'Y' )
9152 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
9153 	AND msik.inventory_item_id IN (SELECT item_id FROM rcv_supply WHERE SHIPMENT_HEADER_ID = p_shipmentHeaderID );
9154 
9155     ELSIF (p_reqHeaderID IS NOT NULL ) THEN
9156         open x_items for
9157 	SELECT
9158 	concatenated_segments,
9159 	msik.inventory_item_id,
9160 	msik.description,
9161 	Nvl(revision_qty_control_code,1),
9162 	Nvl(lot_control_code, 1),
9163 	Nvl(serial_number_control_code, 1),
9164 	Nvl(restrict_subinventories_code, 2),
9165 	Nvl(restrict_locators_code, 2),
9166 	Nvl(location_control_code, 1),
9167 	primary_uom_code,
9168 	Nvl(inspection_required_flag, 'N'),
9169 	Nvl(shelf_life_code, 1),
9170 	Nvl(shelf_life_days,0),
9171 	Nvl(allowed_units_lookup_code, 2),
9172 	Nvl(effectivity_control,1),
9173 	0,
9174 	0,
9175 	Nvl(default_serial_status_id,1),
9176 	Nvl(serial_status_enabled,'N'),
9177 	Nvl(default_lot_status_id,0),
9178 	Nvl(lot_status_enabled,'N'),
9179 	null,
9180 	'N',
9181 	inventory_item_flag,
9182 	0,
9183       wms_deploy.get_item_client_name(msik.inventory_item_id),
9184 	inventory_asset_flag,
9185 	outside_operation_flag,
9186 	--Bug 3952081
9187 	--Select DUOM Attributes for every Item
9188 	NVL(GRADE_CONTROL_FLAG,'N'),
9189 	NVL(DEFAULT_GRADE,''),
9190 	NVL(EXPIRATION_ACTION_INTERVAL,0),
9191 	NVL(EXPIRATION_ACTION_CODE,''),
9192 	NVL(HOLD_DAYS,0),
9193 	NVL(MATURITY_DAYS,0),
9194 	NVL(RETEST_INTERVAL,0),
9195 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
9196 	NVL(CHILD_LOT_FLAG,'N'),
9197 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
9198 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
9199 	NVL(SECONDARY_UOM_CODE,''),
9200 	NVL(SECONDARY_DEFAULT_IND,''),
9201 	NVL(TRACKING_QUANTITY_IND,'P'),
9202 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
9203 	NVL(DUAL_UOM_DEVIATION_LOW,0)
9204 	FROM
9205 	mtl_system_items_vl msik /* Bug 5581528 */
9206 	WHERE
9207 	organization_id = p_Organization_Id
9208 	AND concatenated_segments like p_concatenated_segments||l_append
9209 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
9210 	AND msik.inventory_item_id IN (SELECT item_id FROM po_requisition_lines prl WHERE prl.requisition_header_id = p_reqHeaderID
9211   -- Bug 4346684
9212   -- Add condition to filter the item that dosen't exists in shipments.
9213   AND EXISTS(SELECT 1 FROM rcv_supply rs WHERE rs.req_line_id=prl.requisition_line_id and rs.supply_type_code = 'RECEIVING'))
9214 
9215 	UNION
9216 	select
9217 	concatenated_segments,
9218 	msik.inventory_item_id,
9219 	msik.description,
9220 	Nvl(revision_qty_control_code,1),
9221 	Nvl(lot_control_code, 1),
9222 	Nvl(serial_number_control_code, 1),
9223 	Nvl(restrict_subinventories_code, 2),
9224 	Nvl(restrict_locators_code, 2),
9225 	Nvl(location_control_code, 1),
9226 	primary_uom_code,
9227 	Nvl(inspection_required_flag, 'N'),
9228 	Nvl(shelf_life_code, 1),
9229 	Nvl(shelf_life_days,0),
9230 	Nvl(allowed_units_lookup_code, 2),
9231 	Nvl(effectivity_control,1),
9232 	0,
9233 	0,
9234 	Nvl(default_serial_status_id,1),
9235 	Nvl(serial_status_enabled,'N'),
9236 	Nvl(default_lot_status_id,0),
9237 	Nvl(lot_status_enabled,'N'),
9238 	mcr.cross_reference,
9239 	'N',
9240 	inventory_item_flag,
9241 	0,
9242       wms_deploy.get_item_client_name(msik.inventory_item_id),
9243 	inventory_asset_flag,
9244 	outside_operation_flag,
9245 	--Bug No 3952081
9246 	--Additional Fields for Process Convergence
9247 	NVL(GRADE_CONTROL_FLAG,'N'),
9248 	NVL(DEFAULT_GRADE,''),
9249 	NVL(EXPIRATION_ACTION_INTERVAL,0),
9250 	NVL(EXPIRATION_ACTION_CODE,''),
9251 	NVL(HOLD_DAYS,0),
9252 	NVL(MATURITY_DAYS,0),
9253 	NVL(RETEST_INTERVAL,0),
9254 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
9255 	NVL(CHILD_LOT_FLAG,'N'),
9256 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
9257 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
9258 	NVL(SECONDARY_UOM_CODE,''),
9259 	NVL(SECONDARY_DEFAULT_IND,''),
9260 	NVL(TRACKING_QUANTITY_IND,'P'),
9261 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
9262 	NVL(DUAL_UOM_DEVIATION_LOW,0)
9263 	FROM
9264 	mtl_system_items_vl msik,  /* Bug 5581528 */
9265 	mtl_cross_references mcr
9266 	WHERE
9267 	msik.organization_id = p_organization_id
9268 	AND msik.inventory_item_id = mcr.inventory_item_id
9269 	AND mcr.cross_reference_type = g_gtin_cross_ref_type
9270 	AND mcr.cross_reference  like g_crossref
9271 	AND (mcr.organization_id = msik.organization_id
9272 	     OR mcr.org_independent_flag = 'Y' )
9273 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
9274 	AND msik.inventory_item_id IN (SELECT item_id FROM po_requisition_lines prl WHERE prl.requisition_header_id = p_reqHeaderID
9275   -- Bug 4346684
9276   -- Add condition to filter the item that dosen't exists in shipments.
9277   AND EXISTS(SELECT 1 FROM rcv_supply rs WHERE rs.req_line_id=prl.requisition_line_id and rs.supply_type_code = 'RECEIVING'));
9278 
9279 
9280     ELSIF (p_oeOrderHeaderID IS NOT NULL ) THEN
9281         open x_items for
9282 	SELECT
9283 	concatenated_segments,
9284 	msik.inventory_item_id,
9285 	msik.description,
9286 	Nvl(revision_qty_control_code,1),
9287 	Nvl(lot_control_code, 1),
9288 	Nvl(serial_number_control_code, 1),
9289 	Nvl(restrict_subinventories_code, 2),
9290 	Nvl(restrict_locators_code, 2),
9291 	Nvl(location_control_code, 1),
9292 	primary_uom_code,
9293 	Nvl(inspection_required_flag, 'N'),
9294 	Nvl(shelf_life_code, 1),
9295 	Nvl(shelf_life_days,0),
9296 	Nvl(allowed_units_lookup_code, 2),
9297 	Nvl(effectivity_control,1),
9298 	0,
9299 	0,
9300 	Nvl(default_serial_status_id,1),
9301 	Nvl(serial_status_enabled,'N'),
9302 	Nvl(default_lot_status_id,0),
9303 	Nvl(lot_status_enabled,'N'),
9304 	null,
9305 	'N',
9306 	inventory_item_flag,
9307 	0,
9308       wms_deploy.get_item_client_name(msik.inventory_item_id),
9309 	inventory_asset_flag,
9310 	outside_operation_flag,
9311 	--Bug 3952081
9312 	--Select DUOM Attributes for every Item
9313 	NVL(GRADE_CONTROL_FLAG,'N'),
9314 	NVL(DEFAULT_GRADE,''),
9315 	NVL(EXPIRATION_ACTION_INTERVAL,0),
9316 	NVL(EXPIRATION_ACTION_CODE,''),
9317 	NVL(HOLD_DAYS,0),
9318 	NVL(MATURITY_DAYS,0),
9319 	NVL(RETEST_INTERVAL,0),
9320 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
9321 	NVL(CHILD_LOT_FLAG,'N'),
9322 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
9323 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
9324 	NVL(SECONDARY_UOM_CODE,''),
9325 	NVL(SECONDARY_DEFAULT_IND,''),
9326 	NVL(TRACKING_QUANTITY_IND,'P'),
9327 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
9328 	NVL(DUAL_UOM_DEVIATION_LOW,0)
9329 	FROM
9330 	mtl_system_items_vl msik /* Bug 5581528 */
9331 	WHERE
9332 	organization_id = p_Organization_Id
9333 	AND concatenated_segments like p_concatenated_segments||l_append
9334 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
9335 	AND msik.inventory_item_id IN (SELECT item_id FROM rcv_supply WHERE OE_ORDER_HEADER_ID = p_oeOrderHeaderID )
9336 	UNION
9337 	select
9338 	concatenated_segments,
9339 	msik.inventory_item_id,
9340 	msik.description,
9341 	Nvl(revision_qty_control_code,1),
9342 	Nvl(lot_control_code, 1),
9343 	Nvl(serial_number_control_code, 1),
9344 	Nvl(restrict_subinventories_code, 2),
9345 	Nvl(restrict_locators_code, 2),
9346 	Nvl(location_control_code, 1),
9347 	primary_uom_code,
9348 	Nvl(inspection_required_flag, 'N'),
9349 	Nvl(shelf_life_code, 1),
9350 	Nvl(shelf_life_days,0),
9351 	Nvl(allowed_units_lookup_code, 2),
9352 	Nvl(effectivity_control,1),
9353 	0,
9354 	0,
9355 	Nvl(default_serial_status_id,1),
9356 	Nvl(serial_status_enabled,'N'),
9357 	Nvl(default_lot_status_id,0),
9358 	Nvl(lot_status_enabled,'N'),
9359 	mcr.cross_reference,
9360 	'N',
9361 	inventory_item_flag,
9362 	0,
9363       wms_deploy.get_item_client_name(msik.inventory_item_id),
9364 	inventory_asset_flag,
9365 	outside_operation_flag,
9366 	--Bug No 3952081
9367 	--Additional Fields for Process Convergence
9368 	NVL(GRADE_CONTROL_FLAG,'N'),
9369 	NVL(DEFAULT_GRADE,''),
9370 	NVL(EXPIRATION_ACTION_INTERVAL,0),
9371 	NVL(EXPIRATION_ACTION_CODE,''),
9372 	NVL(HOLD_DAYS,0),
9373 	NVL(MATURITY_DAYS,0),
9374 	NVL(RETEST_INTERVAL,0),
9375 	NVL(COPY_LOT_ATTRIBUTE_FLAG,'N'),
9376 	NVL(CHILD_LOT_FLAG,'N'),
9377 	NVL(CHILD_LOT_VALIDATION_FLAG,'N'),
9378 	NVL(LOT_DIVISIBLE_FLAG,'Y'),
9379 	NVL(SECONDARY_UOM_CODE,''),
9380 	NVL(SECONDARY_DEFAULT_IND,''),
9381 	NVL(TRACKING_QUANTITY_IND,'P'),
9382 	NVL(DUAL_UOM_DEVIATION_HIGH,0),
9383 	NVL(DUAL_UOM_DEVIATION_LOW,0)
9384 	FROM
9385 	mtl_system_items_vl msik,  /* Bug 5581528 */
9386 	mtl_cross_references mcr
9387 	WHERE
9388 	msik.organization_id = p_organization_id
9389 	AND msik.inventory_item_id = mcr.inventory_item_id
9390 	AND mcr.cross_reference_type = g_gtin_cross_ref_type
9391 	AND mcr.cross_reference  like g_crossref
9392 	AND (mcr.organization_id = msik.organization_id
9393 	     OR mcr.org_independent_flag = 'Y' )
9394 	AND (purchasing_enabled_flag = 'Y' OR stock_enabled_flag = 'Y')
9395 	AND msik.inventory_item_id IN (SELECT item_id FROM rcv_supply WHERE OE_ORDER_HEADER_ID = p_oeOrderHeaderID );
9396 
9397     END IF;
9398 
9399 END GET_INV_ITEM_LOV_RECEIVING;
9400 
9401 
9402 
9403 
9404 
9405 PROCEDURE GET_RCV_SHP_FLEX_DETAILS
9406      ( p_shipment_num IN VARCHAR2
9407      , p_orgid    IN   NUMBER
9408      , x_attribute1           OUT    NOCOPY VARCHAR2
9409      , x_attribute2           OUT    NOCOPY VARCHAR2
9410      , x_attribute3           OUT    NOCOPY VARCHAR2
9411      , x_attribute4           OUT    NOCOPY VARCHAR2
9412      , x_attribute5           OUT    NOCOPY VARCHAR2
9413      , x_attribute6           OUT    NOCOPY VARCHAR2
9414      , x_attribute7           OUT    NOCOPY VARCHAR2
9415      , x_attribute8           OUT    NOCOPY VARCHAR2
9416      , x_attribute9           OUT    NOCOPY VARCHAR2
9417      , x_attribute10          OUT    NOCOPY VARCHAR2
9418      , x_attribute11          OUT    NOCOPY VARCHAR2
9419      , x_attribute12          OUT    NOCOPY VARCHAR2
9420      , x_attribute13          OUT    NOCOPY VARCHAR2
9421      , x_attribute14          OUT    NOCOPY VARCHAR2
9422      , x_attribute15          OUT    NOCOPY VARCHAR2
9423      , x_val_attribute1       OUT    NOCOPY VARCHAR2
9424      , x_val_attribute2       OUT    NOCOPY VARCHAR2
9425      , x_val_attribute3       OUT    NOCOPY VARCHAR2
9426      , x_val_attribute4       OUT    NOCOPY VARCHAR2
9427      , x_val_attribute5       OUT    NOCOPY VARCHAR2
9428      , x_val_attribute6       OUT    NOCOPY VARCHAR2
9429      , x_val_attribute7       OUT    NOCOPY VARCHAR2
9430      , x_val_attribute8       OUT    NOCOPY VARCHAR2
9431      , x_val_attribute9       OUT    NOCOPY VARCHAR2
9432      , x_val_attribute10      OUT    NOCOPY VARCHAR2
9433      , x_val_attribute11      OUT    NOCOPY VARCHAR2
9434      , x_val_attribute12      OUT    NOCOPY VARCHAR2
9435      , x_val_attribute13      OUT    NOCOPY VARCHAR2
9436      , x_val_attribute14      OUT    NOCOPY VARCHAR2
9437      , x_val_attribute15      OUT    NOCOPY VARCHAR2
9438      , x_attribute_category   OUT    NOCOPY VARCHAR2
9439      , x_concatenated_val     OUT    NOCOPY VARCHAR2
9440       )
9441    IS
9442        TYPE seg_name IS TABLE OF VARCHAR2(1000)
9443        INDEX BY BINARY_INTEGER;
9444        l_context          VARCHAR2(1000);
9445        l_context_r        fnd_dflex.context_r;
9446        l_contexts_dr      fnd_dflex.contexts_dr;
9447        l_dflex_r          fnd_dflex.dflex_r;
9448        l_segments_dr      fnd_dflex.segments_dr;
9449        l_enabled_seg_name seg_name;
9450        l_wms_all_segs_tbl seg_name;
9451        l_nsegments        BINARY_INTEGER;
9452        l_global_context   BINARY_INTEGER;
9453        v_index            NUMBER                := 1;
9454        l_chk_flag         NUMBER                := 0;
9455        l_char_count       NUMBER;
9456        l_num_count        NUMBER;
9457        l_date_count       NUMBER;
9458        l_wms_attr_chk     NUMBER                := 1;
9459        l_return_status    VARCHAR2(1);
9460        l_msg_count        NUMBER;
9461        l_msg_data         VARCHAR2(1000);
9462 
9463        /* Variables used for Validate_desccols procedure */
9464        error_segment      VARCHAR2(30);
9465        errors_received    EXCEPTION;
9466        error_msg          VARCHAR2(5000);
9467        s                  NUMBER;
9468        e                  NUMBER;
9469        l_null_char_val    VARCHAR2(1000);
9470        l_null_num_val     NUMBER;
9471        l_null_date_val    DATE;
9472        l_global_nsegments NUMBER := 0;
9473 
9474        col NUMBER;
9475 
9476        l_date DATE;
9477 
9478        TYPE char_tbl IS TABLE OF VARCHAR2(1500)
9479        INDEX BY BINARY_INTEGER;
9480 
9481        l_attributes_tbl char_tbl;
9482        l_organization_id NUMBER;
9483        l_shipment_num varchar2(150);
9484        l_attrib_num NUMBER;
9485 
9486 BEGIN
9487 
9488         l_shipment_num := p_shipment_num;
9489         l_organization_id := p_orgid;
9490 
9491         select
9492               attribute1,
9493               attribute2,
9494               attribute3,
9495               attribute4,
9496               attribute5,
9497               attribute6,
9498               attribute7,
9499               attribute8,
9500               attribute9,
9501               attribute10,
9502               attribute11,
9503               attribute12,
9504               attribute13,
9505               attribute14,
9506               attribute15,
9507               attribute_category
9508          into
9509               x_attribute1,
9510               x_attribute2,
9511               x_attribute3,
9512               x_attribute4,
9513               x_attribute5,
9514               x_attribute6,
9515               x_attribute7,
9516               x_attribute8,
9517               x_attribute9,
9518               x_attribute10,
9519               x_attribute11,
9520               x_attribute12,
9521               x_attribute13,
9522               x_attribute14,
9523               x_attribute15,
9524               x_attribute_category
9525         from  rcv_shipment_headers rsh
9526        where  rsh.shipment_num = l_shipment_num
9527          and  rsh.ship_to_org_id = l_organization_id;
9528 
9529 
9530 
9531   BEGIN
9532         l_attributes_tbl (1) := x_attribute1;
9533         l_attributes_tbl (2) := x_attribute2;
9534         l_attributes_tbl (3) := x_attribute3;
9535         l_attributes_tbl (4) := x_attribute4;
9536         l_attributes_tbl (5) := x_attribute5;
9537         l_attributes_tbl (6) := x_attribute6;
9538         l_attributes_tbl (7) := x_attribute7;
9539         l_attributes_tbl (8) := x_attribute8;
9540         l_attributes_tbl (9) := x_attribute9;
9541         l_attributes_tbl (10) := x_attribute10;
9542         l_attributes_tbl (11) := x_attribute11;
9543         l_attributes_tbl (12) := x_attribute12;
9544         l_attributes_tbl (13) := x_attribute13;
9545         l_attributes_tbl (14) := x_attribute14;
9546         l_attributes_tbl (15) := x_attribute15;
9547 
9548         l_dflex_r.application_id  := 201;
9549         l_dflex_r.flexfield_name  := 'RCV_SHIPMENT_HEADERS';
9550 
9551         print_debug('BEFORE SETTING THE ATTRIBUTES CONTEXT',4);
9552 
9553         l_dflex_r.application_id  := 201;
9554         l_dflex_r.flexfield_name  := 'RCV_SHIPMENT_HEADERS';
9555 
9556         print_debug('BEFORE SETTING THE ATTRIBUTES CONTEXT',4);
9557 
9558         /* Get all contexts */
9559         fnd_dflex.get_contexts(flexfield => l_dflex_r, contexts => l_contexts_dr);
9560 
9561         print_debug('Found contexts for the Flexfield MTL_LOT_NUMBERS',4);
9562 
9563          /* From the l_contexts_dr, get the position of the global context */
9564         l_global_context          := l_contexts_dr.global_context;
9565 
9566         print_debug('Found the position of the global context  ',4);
9567 
9568         /* Using the position get the segments in the global context which are enabled */
9569         l_context                 := l_contexts_dr.context_code(l_global_context);
9570 
9571         /* Prepare the context_r type for getting the segments associated with the global context */
9572 
9573         l_context_r.flexfield     := l_dflex_r;
9574         l_context_r.context_code  := l_context;
9575 
9576         fnd_dflex.get_segments(CONTEXT => l_context_r, segments => l_segments_dr, enabled_only => TRUE);
9577 
9578         print_debug('After successfully getting all the enabled segmenst for the Global Context ',4);
9579 
9580         /* read through the segments */
9581 
9582         l_nsegments               := l_segments_dr.nsegments;
9583         l_global_nsegments        := l_segments_dr.nsegments;
9584 
9585         print_debug('The number of enabled segments for the Global Context are ' || l_nsegments,4);
9586 
9587      FOR i IN 1 .. l_nsegments LOOP
9588           l_enabled_seg_name(v_index)  := l_segments_dr.application_column_name(i);
9589 
9590           IF l_attributes_tbl.EXISTS(SUBSTR(l_segments_dr.application_column_name(i)
9591                 , INSTR(l_segments_dr.application_column_name(i), 'ATTRIBUTE') + 9)) THEN
9592                print_debug('setting column values',4);
9593                print_debug('Actual Value is ' ||
9594                        l_attributes_tbl(SUBSTR(l_segments_dr.application_column_name(i)
9595                  , INSTR(l_segments_dr.application_column_name(i), 'ATTRIBUTE') + 9)), 4);
9596 
9597              fnd_flex_descval.set_column_value(
9598                l_segments_dr.application_column_name(i)
9599              , l_attributes_tbl(SUBSTR(l_segments_dr.application_column_name(i)
9600                  , INSTR(l_segments_dr.application_column_name(i), 'ATTRIBUTE') + 9))
9601              );
9602            ELSE
9603              fnd_flex_descval.set_column_value(l_segments_dr.application_column_name(i), l_null_char_val);
9604            END IF;
9605            v_index  := v_index + 1;
9606      END LOOP;
9607 
9608       IF l_enabled_seg_name.COUNT > 0 THEN
9609            FOR i IN l_enabled_seg_name.FIRST .. l_enabled_seg_name.LAST LOOP
9610                print_debug('The enabled segment : ' || l_enabled_seg_name(i), 4);
9611         END LOOP;
9612       END IF;
9613 
9614         /* Initialise the l_context_value to null */
9615          l_context                 := NULL;
9616          l_nsegments               := 0;
9617 
9618          /*Get the context for the item passed */
9619       IF x_attribute_category IS NOT NULL THEN
9620            l_context                 := x_attribute_category;
9621            /* Set flex context for validation of the value set */
9622            fnd_flex_descval.set_context_value(l_context);
9623            print_debug('The value of INV context is ' || l_context, 4);
9624 
9625            /* Prepare the context_r type */
9626            l_context_r.flexfield     := l_dflex_r;
9627            l_context_r.context_code  := l_context;
9628 
9629            fnd_dflex.get_segments(CONTEXT => l_context_r, segments => l_segments_dr, enabled_only => TRUE);
9630 
9631            /* read through the segments */
9632            l_nsegments               := l_segments_dr.nsegments;
9633 
9634            print_debug('No of segments enabled for context ' || l_context || ' are ' || l_nsegments, 4);
9635            print_debug('v_index is ' || v_index, 4);
9636 
9637            FOR i IN 1 .. l_nsegments LOOP
9638 
9639              l_enabled_seg_name(v_index)  := l_segments_dr.application_column_name(i);
9640 
9641              print_debug('The segment is ' || l_segments_dr.segment_name(i), 4);
9642 
9643              IF l_attributes_tbl.EXISTS(SUBSTR(l_segments_dr.application_column_name(i)
9644                   , INSTR(l_segments_dr.application_column_name(i), 'ATTRIBUTE') + 9)) THEN
9645 
9646                fnd_flex_descval.set_column_value(
9647                  l_segments_dr.application_column_name(i)
9648                , l_attributes_tbl(SUBSTR(l_segments_dr.application_column_name(i)
9649                    , INSTR(l_segments_dr.application_column_name(i), 'ATTRIBUTE') + 9))
9650                );
9651              ELSE
9652                fnd_flex_descval.set_column_value(l_segments_dr.application_column_name(i), l_null_char_val);
9653              END IF;
9654              v_index  := v_index + 1;
9655       END LOOP;
9656     END IF;
9657 
9658     IF (l_global_nsegments > 0 AND x_attribute_Category IS NULL ) THEN
9659              print_debug('global segments > 0', 4);
9660              l_context                 := l_contexts_dr.context_code(l_global_context);
9661              fnd_flex_descval.set_context_value(l_context);
9662     End if;
9663 
9664     IF fnd_flex_descval.validate_desccols(appl_short_name => 'PO',
9665                desc_flex_name => 'RCV_SHIPMENT_HEADERS', values_or_ids => 'I'
9666               , validation_date              => SYSDATE) THEN
9667                print_debug('Value set validation successful', 4);
9668     ELSE
9669                error_segment  := fnd_flex_descval.error_segment;
9670                print_debug('The error segment is : ' || fnd_flex_descval.error_segment, 4);
9671                RAISE errors_received;
9672     END IF;
9673 
9674     x_concatenated_val := fnd_flex_descval.concatenated_values;
9675     print_debug('The concatenated values is : ' || x_concatenated_val , 4);
9676 
9677        /** Retrun the VALUES to java */
9678        /** This Part of code is kept for future Use **********
9679        for i in 1..v_index
9680        Loop
9681           BEGIN
9682 
9683              l_attrib_num := SUBSTR(l_enabled_seg_name(i)
9684                    , INSTR(l_enabled_seg_name(i), 'ATTRIBUTE') + 9);
9685 
9686              if l_attrib_num = 1 then
9687                 x_val_attribute1 := fnd_flex_descval.Segment_Value(i);
9688              End if;
9689              if l_attrib_num = 2 then
9690                 x_val_attribute2 := fnd_flex_descval.Segment_Value(i);
9691              End if;
9692              if l_attrib_num = 3 then
9693                 x_val_attribute3 := fnd_flex_descval.Segment_Value(i);
9694              End if;
9695              if l_attrib_num = 4 then
9696                 x_val_attribute4 := fnd_flex_descval.Segment_Value(i);
9697              End if;
9698              if l_attrib_num = 5 then
9699                 x_val_attribute5 := fnd_flex_descval.Segment_Value(i);
9700              End if;
9701              if l_attrib_num =6  then
9702                 x_val_attribute6 := fnd_flex_descval.Segment_Value(i);
9703              End if;
9704              if l_attrib_num = 7 then
9705                 x_val_attribute7 := fnd_flex_descval.Segment_Value(i);
9706              End if;
9707              if l_attrib_num =8  then
9708                 x_val_attribute8 := fnd_flex_descval.Segment_Value(i);
9709              End if;
9710              if l_attrib_num = 9  then
9711                 x_val_attribute9 := fnd_flex_descval.Segment_Value(i);
9712              End if;
9713              if l_attrib_num = 10 then
9714                 x_val_attribute10 := fnd_flex_descval.Segment_Value(i);
9715              End if;
9716              if l_attrib_num = 11 then
9717                 x_val_attribute11 := fnd_flex_descval.Segment_Value(i);
9718              End if;
9719              if l_attrib_num = 12 then
9720                 x_val_attribute12 := fnd_flex_descval.Segment_Value(i);
9721              End if;
9722              if l_attrib_num = 13 then
9723                 x_val_attribute13 := fnd_flex_descval.Segment_Value(i);
9724              End if;
9725              if l_attrib_num = 14 then
9726                 x_val_attribute14 := fnd_flex_descval.Segment_Value(i);
9727              End if;
9728              if l_attrib_num = 15 then
9729                 x_val_attribute15 := fnd_flex_descval.Segment_Value(i);
9730              End if;
9731           EXCEPTION
9732               WHEN OTHERS THEN NULL;
9733           END;
9734         End Loop;
9735         *******************************************/
9736 
9737   EXCEPTION
9738     WHEN OTHERS THEN
9739       print_debug('Can not get the concatenatd values due to problem in flexfield data ' , 4);
9740       print_debug('OTHER EXCEPTION OCCURED AT GET_RCV_SHIP_FLEX_DETAILS' , 4);
9741   END;
9742 
9743 EXCEPTION
9744     WHEN OTHERS THEN
9745       print_debug('Can not Obtain the dff values for Shipment. Issue in shipment or org ' , 4);
9746       print_debug('Value of Shipment = ' || l_shipment_num  , 4);
9747       print_debug('Value of Org = ' || l_organization_id  , 4);
9748 END GET_RCV_SHP_FLEX_DETAILS;
9749 
9750 END INV_UI_RCV_LOVS;