DBA Data[Home] [Help]

PACKAGE BODY: APPS.INV_RCV_STD_RCPT_APIS

Source


1 PACKAGE BODY inv_rcv_std_rcpt_apis AS
2   /* $Header: INVSTDRB.pls 120.24.12010000.12 2009/02/06 08:05:14 vssrivat ship $*/
3 
4   --  Global constant holding the package name
5   g_pkg_name CONSTANT VARCHAR2(30) := 'INV_RCV_STD_RCPT_APIS';
6 
7   --g_rcpt_lot_qty_rec_tb rcpt_lot_qty_rec_tb_tp;
8   --g_prev_lot_number VARCHAR2(30) := NULL;
9 
10   PROCEDURE print_debug(p_err_msg VARCHAR2, p_level NUMBER DEFAULT 4) IS
11     l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
12   BEGIN
13     IF (l_debug = 1) THEN
14       inv_mobile_helper_functions.tracelog(
15             p_err_msg => p_err_msg
16           , p_module => 'INV_RCV_STD_RCPT_APIS'
17           , p_level => p_level);
18     END IF;
19   --   dbms_output.put_line(p_err_msg);
20   END print_debug;
21 
22   PROCEDURE get_project_task(
23     p_po_line_location_id  IN             NUMBER
24   , p_oe_order_line_id     IN             NUMBER
25   , x_project_id           OUT NOCOPY     NUMBER
26   , x_task_id              OUT NOCOPY     NUMBER
27   ) IS
28     l_project_id NUMBER := '';
29     l_task_id    NUMBER := '';
30     l_debug      NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
31   BEGIN
32     IF (l_debug = 1) THEN
33       print_debug('get_project_task: 10 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
34     END IF;
35 
36     IF p_po_line_location_id IS NOT NULL THEN
37        --BUG 3444210: Modify the query below for performance reason
38        SELECT
39    pod.project_id project_id
40    ,NVL(pod.task_id, '') task_id
41    INTO l_project_id
42            , l_task_id
43    FROM po_distributions_all pod
44    WHERE pod.line_location_id = p_po_line_location_id
45    AND ROWNUM = 1
46    AND pod.project_id IS NOT NULL
47    ORDER BY nvl(pod.task_id,-1) DESC;
48     ELSIF p_oe_order_line_id IS NOT NULL THEN
49       SELECT project_id
50            , task_id
51         INTO l_project_id
52            , l_task_id
53         FROM oe_order_lines_all
54        WHERE line_id = p_oe_order_line_id;
55     END IF;
56 
57     x_project_id := l_project_id;
58     x_task_id := l_task_id;
59 
60     IF (l_debug = 1) THEN
61       print_debug('project_id:' || x_project_id, 4);
62       print_debug('task_id:' || x_task_id, 4);
63     END IF;
64   EXCEPTION
65     WHEN NO_DATA_FOUND THEN
66       x_project_id := '';
67       x_task_id := '';
68   END get_project_task;
69 
70   FUNCTION insert_txn_interface(
71     p_rcv_transaction_rec  IN OUT NOCOPY  rcv_transaction_rec_tp
72   , p_rcv_rcpt_rec         IN OUT NOCOPY  rcv_enter_receipts_rec_tp
73   , p_group_id             IN             NUMBER
74   , p_transaction_type     IN             VARCHAR2
75   , p_organization_id      IN             NUMBER
76   , p_location_id          IN             NUMBER
77   , p_source_type          IN             VARCHAR2
78   , p_qa_routing_id        IN             NUMBER DEFAULT -1
79   , p_project_id           IN             NUMBER DEFAULT NULL
80   , p_task_id              IN             NUMBER DEFAULT NULL
81   , p_express_transaction  IN             VARCHAR2 DEFAULT NULL
82 
83   )
84     RETURN NUMBER IS
85     l_rcv_transaction_rec        rcv_transaction_rec_tp; -- rcv_transaction block
86     l_rti_rowid                  VARCHAR2(40);
87     l_interface_transaction_id   NUMBER;
88     l_sysdate                    DATE           := SYSDATE;
89     l_txn_date                   DATE           := Sysdate;
90     l_auto_transact_code         VARCHAR2(30);
91     l_shipment_line_id           NUMBER;
92     l_primary_uom                VARCHAR2(25);
93     l_source_type_code           VARCHAR2(30);
94     l_vendor_id                  NUMBER;
95     l_vendor_site_id             NUMBER;
96     l_from_org_id                NUMBER;
97     l_to_org_id                  NUMBER;
98     l_source_doc_code            VARCHAR2(30);
99     l_po_header_id               NUMBER;
100     l_po_release_id              NUMBER;
101     l_po_line_id                 NUMBER;
102     l_po_line_location_id        NUMBER;
103     l_po_distribution_id         NUMBER;
104     l_req_line_id                NUMBER;
105     l_sub_unordered_code         VARCHAR2(30);
106     l_deliver_to_person_id       NUMBER;
107     l_location_id                NUMBER;
108     l_deliver_to_location_id     NUMBER;
109     l_subinventory               VARCHAR2(10);
110     l_locator_id                 NUMBER;
111     l_wip_entity_id              NUMBER;
112     l_wip_line_id                NUMBER;
113     l_department_code            VARCHAR2(30);
114     l_wip_rep_sched_id           NUMBER;
115     l_wip_oper_seq_num           NUMBER;
116     l_wip_res_seq_num            NUMBER;
117     l_bom_resource_id            NUMBER;
118     l_oe_order_header_id         NUMBER;
119     l_oe_order_line_id           NUMBER;
120     l_customer_item_num          NUMBER;
121     l_customer_id                NUMBER;
122     l_customer_site_id           NUMBER;
123     l_rate                       NUMBER;
124     l_shipment_header_id         NUMBER;
125     --variables for defaulting rcv_transaction non-db items
126 
127     x_available_qty              NUMBER;
128     x_ordered_qty                NUMBER;
129     x_primary_qty                NUMBER;
130     x_tolerable_qty              NUMBER;
131     x_uom                        VARCHAR2(25);
132     x_primary_uom                VARCHAR2(25);
133     x_valid_ship_to_location     BOOLEAN;
134     x_num_of_distributions       NUMBER;
135     x_po_distribution_id         NUMBER;
136     x_destination_type_code      VARCHAR2(30);
137     x_destination_type_dsp       VARCHAR2(80);
138     x_deliver_to_location_id     NUMBER;
139     x_deliver_to_location        VARCHAR2(80);
140     x_deliver_to_person_id       NUMBER;
141     x_deliver_to_person          VARCHAR2(240);
142     x_deliver_to_sub             VARCHAR2(10);
143     x_deliver_to_locator_id      NUMBER;
144     x_wip_entity_id              NUMBER;
145     x_wip_repetitive_schedule_id NUMBER;
146     x_wip_line_id                NUMBER;
147     x_wip_operation_seq_num      NUMBER;
148     x_wip_resource_seq_num       NUMBER;
149     x_bom_resource_id            NUMBER;
150     x_to_organization_id         NUMBER;
151     x_job                        VARCHAR2(80);
152     x_line_num                   VARCHAR2(10);
153     x_sequence                   NUMBER;
154     x_department                 VARCHAR2(40);
155     x_enforce_ship_to_loc        VARCHAR2(30);
156     x_allow_substitutes          VARCHAR2(3);
157     x_routing_id                 NUMBER;
158     x_qty_rcv_tolerance          NUMBER;
159     x_qty_rcv_exception          VARCHAR2(30);
160     x_days_early_receipt         NUMBER;
161     x_days_late_receipt          NUMBER;
162     x_rcv_days_exception         VARCHAR2(30);
163     x_item_revision              VARCHAR2(3);
164     x_locator_control            NUMBER;
165     x_inv_destinations           BOOLEAN;
166     x_rate                       NUMBER;
167     x_rate_date                  DATE;
168     x_project_id                 NUMBER;
169     x_task_id                    NUMBER;
170     x_req_line_id                NUMBER;
171     x_pos                        NUMBER;
172     x_oe_order_line_id           NUMBER;
173     x_item_id                    NUMBER;
174     x_org_id                     NUMBER;
175     x_category_id                NUMBER;
176     x_category_set_id            NUMBER;
177     x_routing_name               VARCHAR2(240);
178     l_project_id                 NUMBER := p_project_id;
179     l_task_id                    NUMBER := p_task_id;
180     l_validation_flag            VARCHAR2(1);
181     l_lpn_group_id               NUMBER;
182     l_header_interface_id        NUMBER;
183     l_debug                      NUMBER  := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
184     --OPM Convergence
185     l_secondary_unit_of_measure              VARCHAR2(25);
186     l_secondary_uom_code         VARCHAR2(3);
187     l_secondary_quantity         NUMBER;
188     l_express_transaction        VARCHAR2(1) := NVL(p_express_transaction, 'N');
189 
190     t_sec_uom_code VARCHAR2(3);
191      t_sec_uom VARCHAR2(25); t_sec_qty NUMBER;
192 
193      l_operating_unit_id MO_GLOB_ORG_ACCESS_TMP.ORGANIZATION_ID%TYPE;   --<R12 MOAC>
194 
195      l_po_item_id MTL_SYSTEM_ITEMS.INVENTORY_ITEM_ID%TYPE; --bug 4697949
196      l_substitute_item_id MTL_SYSTEM_ITEMS.INVENTORY_ITEM_ID%TYPE; --bug 4697949
197 
198 -- For Bug 7440217
199      v_lcm_enabled_org  varchar2(1) := 'N';
200      v_pre_receive      varchar2(1) := 'N';
201      v_lcm_flag         varchar2(1) := 'N';
202      v_lcm_ship_line_id NUMBER;
203      v_unit_landed_cost NUMBER;
204 -- End for Bug 7440217
205 
206   BEGIN
207     IF (l_debug = 1) THEN
208       print_debug('Enter insert_txn_interface: 1   ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
209       print_debug('insert_txn_interface: p_express_transaction ' || p_express_transaction, 1);
210       print_debug('insert_txn_interface: l_express_transaction ' || l_express_transaction, 1);
211     END IF;
212 
213     IF (l_debug = 1) THEN
214       print_debug('insert_txn_interface 2 value of coutry of origin is ' || p_rcv_rcpt_rec.country_of_origin_code, 4);
215     END IF;
216 
217     IF (l_debug = 1) THEN
218       print_debug('insert_txn_interface: revision1  - ' || p_rcv_transaction_rec.item_revision, 4); -- revision needs to be taken care of by matching
219     END IF;
220 
221     print_debug('Rcpt source code ' || p_rcv_rcpt_rec.receipt_source_code);
222   --  print_debug('Rcv Sub ' || p_rcv_transaction_rec.destination_subinventory);
223   --  print_debug('Rcv Loc ' || p_rcv_transaction_rec.locator_id);
224     l_rcv_transaction_rec := p_rcv_transaction_rec;
225     -- populate DB items in rcv_transaction block
226     l_rcv_transaction_rec.line_chkbox := p_rcv_rcpt_rec.line_chkbox;
227     l_rcv_transaction_rec.source_type_code := p_rcv_rcpt_rec.source_type_code;
228     l_rcv_transaction_rec.receipt_source_code := p_rcv_rcpt_rec.receipt_source_code;
229     l_rcv_transaction_rec.order_type_code := p_rcv_rcpt_rec.order_type_code;
230     l_rcv_transaction_rec.order_type := p_rcv_rcpt_rec.order_type;
231     l_rcv_transaction_rec.po_header_id := p_rcv_rcpt_rec.po_header_id;
232     l_rcv_transaction_rec.po_number := p_rcv_rcpt_rec.po_number;
233     l_rcv_transaction_rec.po_line_id := p_rcv_rcpt_rec.po_line_id;
234     l_rcv_transaction_rec.po_line_location_id := p_rcv_rcpt_rec.po_line_location_id;
235     l_rcv_transaction_rec.po_line_number := p_rcv_rcpt_rec.po_line_number;
236     l_rcv_transaction_rec.po_shipment_number := p_rcv_rcpt_rec.po_shipment_number;
237     l_rcv_transaction_rec.po_release_id := p_rcv_rcpt_rec.po_release_id;
238     l_rcv_transaction_rec.po_release_number := p_rcv_rcpt_rec.po_release_number;
239     l_rcv_transaction_rec.req_header_id := p_rcv_rcpt_rec.req_header_id;
240     l_rcv_transaction_rec.req_number := p_rcv_rcpt_rec.req_number;
241     l_rcv_transaction_rec.req_line_id := p_rcv_rcpt_rec.req_line_id;
242     l_rcv_transaction_rec.req_line := p_rcv_rcpt_rec.req_line;
243     l_rcv_transaction_rec.req_distribution_id := p_rcv_rcpt_rec.req_distribution_id;
244     l_rcv_transaction_rec.rcv_shipment_header_id := p_rcv_rcpt_rec.rcv_shipment_header_id;
245     l_rcv_transaction_rec.rcv_shipment_number := p_rcv_rcpt_rec.rcv_shipment_number;
246     l_rcv_transaction_rec.rcv_shipment_line_id := p_rcv_rcpt_rec.rcv_shipment_line_id;
247     l_rcv_transaction_rec.rcv_line_number := p_rcv_rcpt_rec.rcv_line_number;
248     l_rcv_transaction_rec.from_organization_id := p_rcv_rcpt_rec.from_organization_id;
249     l_rcv_transaction_rec.to_organization_id := p_rcv_rcpt_rec.to_organization_id;
250     l_rcv_transaction_rec.vendor_id := p_rcv_rcpt_rec.vendor_id;
251     --    l_rcv_transaction_rec.source := p_rcv_rcpt_rec.source;
252     l_rcv_transaction_rec.vendor_site_id := p_rcv_rcpt_rec.vendor_site_id;
253     --    l_rcv_transaction_rec.outside_operation_flag := p_rcv_rcpt_rec.outside_operation_flag;
254     l_rcv_transaction_rec.item_id := p_rcv_rcpt_rec.item_id;
255     --OPM Convergence
256    /* l_rcv_transaction_rec.secondary_uom  := p_rcv_rcpt_rec.secondary_uom;
257     l_rcv_transaction_rec.secondary_uom_code  := p_rcv_rcpt_rec.secondary_uom_code;
258     l_rcv_transaction_rec .secondary_quantity := p_rcv_rcpt_rec.secondary_quantity; */
259     -- end of changes for OPM Convergence changes
260 
261 
262     IF (l_debug = 1) THEN
263       print_debug('l_rcv_transaction_rec.item_id - ' || l_rcv_transaction_rec.item_id, 4);
264       print_debug('l_rcv_transaction_rec.secondary_uom - ' || l_rcv_transaction_rec.secondary_uom, 4);
265       print_debug('l_rcv_transaction_rec .secondary_quantity - ' || l_rcv_transaction_rec .secondary_quantity, 4);
266     END IF;
267 
268     -- Bug 2073164
269     l_rcv_transaction_rec.uom_code := p_rcv_rcpt_rec.uom_code;
270     l_rcv_transaction_rec.primary_uom_class := p_rcv_rcpt_rec.primary_uom_class;
271     l_rcv_transaction_rec.serial_number_control_code := p_rcv_rcpt_rec.serial_number_control_code;
272     l_rcv_transaction_rec.lot_control_code := p_rcv_rcpt_rec.lot_control_code;
273     l_rcv_transaction_rec.item_rev_control_flag_to := p_rcv_rcpt_rec.item_rev_control_flag_to;
274     l_rcv_transaction_rec.item_rev_control_flag_from := p_rcv_rcpt_rec.item_rev_control_flag_from;
275     l_rcv_transaction_rec.item_number := p_rcv_rcpt_rec.item_number;
276     l_rcv_transaction_rec.item_description := p_rcv_rcpt_rec.item_description;
277     l_rcv_transaction_rec.item_category_id := p_rcv_rcpt_rec.item_category_id;
278     l_rcv_transaction_rec.vendor_item_number := p_rcv_rcpt_rec.vendor_item_number;
279     l_rcv_transaction_rec.ship_to_location_id := p_rcv_rcpt_rec.ship_to_location_id;
280     l_rcv_transaction_rec.packing_slip := p_rcv_rcpt_rec.packing_slip;
281     l_rcv_transaction_rec.routing_id := p_rcv_rcpt_rec.routing_id;
282     l_rcv_transaction_rec.need_by_date := p_rcv_rcpt_rec.need_by_date;
283     l_rcv_transaction_rec.expected_receipt_date := p_rcv_rcpt_rec.expected_receipt_date;
284     l_rcv_transaction_rec.ordered_uom := p_rcv_rcpt_rec.ordered_uom;
285     l_rcv_transaction_rec.ussgl_transaction_code := p_rcv_rcpt_rec.ussgl_transaction_code;
286     l_rcv_transaction_rec.government_context := p_rcv_rcpt_rec.government_context;
287     l_rcv_transaction_rec.inspection_required_flag := p_rcv_rcpt_rec.inspection_required_flag;
288     l_rcv_transaction_rec.receipt_required_flag := p_rcv_rcpt_rec.receipt_required_flag;
289     l_rcv_transaction_rec.enforce_ship_to_location_code := p_rcv_rcpt_rec.enforce_ship_to_location_code;
290     l_rcv_transaction_rec.unit_price := p_rcv_rcpt_rec.unit_price;
291     l_rcv_transaction_rec.currency_code := p_rcv_rcpt_rec.currency_code;
292     l_rcv_transaction_rec.currency_conversion_type := p_rcv_rcpt_rec.currency_conversion_type;
293     l_rcv_transaction_rec.note_to_receiver := p_rcv_rcpt_rec.note_to_receiver;
294     l_rcv_transaction_rec.destination_type_code := p_rcv_rcpt_rec.destination_type_code;
295     l_rcv_transaction_rec.deliver_to_location_id := p_rcv_rcpt_rec.deliver_to_location_id;
296     l_rcv_transaction_rec.attribute_category := p_rcv_rcpt_rec.attribute_category;
297     l_rcv_transaction_rec.attribute1 := p_rcv_rcpt_rec.attribute1;
298     l_rcv_transaction_rec.attribute2 := p_rcv_rcpt_rec.attribute2;
299     l_rcv_transaction_rec.attribute3 := p_rcv_rcpt_rec.attribute3;
300     l_rcv_transaction_rec.attribute4 := p_rcv_rcpt_rec.attribute4;
301     l_rcv_transaction_rec.attribute5 := p_rcv_rcpt_rec.attribute5;
302     l_rcv_transaction_rec.attribute6 := p_rcv_rcpt_rec.attribute6;
303     l_rcv_transaction_rec.attribute7 := p_rcv_rcpt_rec.attribute7;
304     l_rcv_transaction_rec.attribute8 := p_rcv_rcpt_rec.attribute8;
305     l_rcv_transaction_rec.attribute9 := p_rcv_rcpt_rec.attribute9;
306     l_rcv_transaction_rec.attribute10 := p_rcv_rcpt_rec.attribute10;
307     l_rcv_transaction_rec.attribute11 := p_rcv_rcpt_rec.attribute11;
308     l_rcv_transaction_rec.attribute12 := p_rcv_rcpt_rec.attribute12;
309     l_rcv_transaction_rec.attribute13 := p_rcv_rcpt_rec.attribute13;
310     l_rcv_transaction_rec.attribute14 := p_rcv_rcpt_rec.attribute14;
311     l_rcv_transaction_rec.attribute15 := p_rcv_rcpt_rec.attribute15;
312     l_rcv_transaction_rec.closed_code := p_rcv_rcpt_rec.closed_code;
313     l_rcv_transaction_rec.asn_type := p_rcv_rcpt_rec.asn_type;
314     l_rcv_transaction_rec.bill_of_lading := p_rcv_rcpt_rec.bill_of_lading;
315     l_rcv_transaction_rec.shipped_date := p_rcv_rcpt_rec.shipped_date;
316     l_rcv_transaction_rec.freight_carrier_code := p_rcv_rcpt_rec.freight_carrier_code;
317     l_rcv_transaction_rec.waybill_airbill_num := p_rcv_rcpt_rec.waybill_airbill_num;
318     l_rcv_transaction_rec.freight_bill_num := p_rcv_rcpt_rec.freight_bill_num;
319     l_rcv_transaction_rec.vendor_lot_num := p_rcv_rcpt_rec.vendor_lot_num;
320     l_rcv_transaction_rec.container_num := p_rcv_rcpt_rec.container_num;
321     l_rcv_transaction_rec.truck_num := p_rcv_rcpt_rec.truck_num;
322     l_rcv_transaction_rec.bar_code_label := p_rcv_rcpt_rec.bar_code_label;
323     l_rcv_transaction_rec.match_option := p_rcv_rcpt_rec.match_option;
324     l_rcv_transaction_rec.country_of_origin_code := p_rcv_rcpt_rec.country_of_origin_code;
325     l_rcv_transaction_rec.oe_order_header_id := p_rcv_rcpt_rec.oe_order_header_id;
326     l_rcv_transaction_rec.oe_order_num := p_rcv_rcpt_rec.oe_order_num;
327     l_rcv_transaction_rec.oe_order_line_id := p_rcv_rcpt_rec.oe_order_line_id;
328     l_rcv_transaction_rec.oe_order_line_num := p_rcv_rcpt_rec.oe_order_line_num;
329     l_rcv_transaction_rec.customer_id := p_rcv_rcpt_rec.customer_id;
330     l_rcv_transaction_rec.customer_site_id := p_rcv_rcpt_rec.customer_site_id;
331 
332     --    l_rcv_transaction_rec.customer_item_num := p_rcv_rcpt_rec.customer_item_num;
333     -- defaulting other non-db items
334     -- generate l_interface_transaction_id
335     -- QA Skip lot change
336     -- interface txn id is generated in create_po at times as we need to
337     -- pass that to quality. So using that if it is generated.
338     IF l_rcv_transaction_rec.interface_transaction_id IS NOT NULL THEN
339       l_interface_transaction_id := l_rcv_transaction_rec.interface_transaction_id;
340     ELSE
341       SELECT rcv_transactions_interface_s.NEXTVAL
342         INTO l_interface_transaction_id
343         FROM DUAL;
344     END IF;
345 
346     IF (l_debug = 1) THEN
347       print_debug('RTI interface id:' || l_interface_transaction_id, 4);
348       print_debug('insert_txn_interface: 2  before RCV_RECEIPTS_QUERY_SV.POST_QUERY ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
349       , 4);
350     END IF;
351 
352     -- call defaulting api
353     rcv_receipts_query_sv.post_query(
354       l_rcv_transaction_rec.po_line_location_id
355     , l_rcv_transaction_rec.rcv_shipment_line_id
356     , l_rcv_transaction_rec.receipt_source_code
357     , l_rcv_transaction_rec.to_organization_id
358     , l_rcv_transaction_rec.item_id
359     , l_rcv_transaction_rec.primary_uom_class
360     , l_rcv_transaction_rec.ship_to_location_id
361     , l_rcv_transaction_rec.vendor_id
362     , l_rcv_transaction_rec.customer_id
363     , l_rcv_transaction_rec.item_rev_control_flag_to
364     , x_available_qty
365     , x_primary_qty
366     , x_tolerable_qty
367     , x_uom
368     , x_primary_uom
369     , x_valid_ship_to_location
370     , x_num_of_distributions
371     , x_po_distribution_id
372     , x_destination_type_code
373     , x_destination_type_dsp
374     , x_deliver_to_location_id
375     , x_deliver_to_location
376     , x_deliver_to_person_id
377     , x_deliver_to_person
378     , x_deliver_to_sub
379     , x_deliver_to_locator_id
380     , x_wip_entity_id
381     , x_wip_repetitive_schedule_id
382     , x_wip_line_id
383     , x_wip_operation_seq_num
384     , x_wip_resource_seq_num
385     , x_bom_resource_id
386     , x_to_organization_id
387     , x_job
388     , x_line_num
389     , x_sequence
390     , x_department
391     , x_enforce_ship_to_loc
392     , x_allow_substitutes
393     , x_routing_id
394     , x_qty_rcv_tolerance
395     , x_qty_rcv_exception
396     , x_days_early_receipt
397     , x_days_late_receipt
398     , x_rcv_days_exception
399     , x_item_revision
400     , x_locator_control
401     , x_inv_destinations
402     , x_rate
403     , x_rate_date
404     , l_rcv_transaction_rec.asn_type
405     , l_rcv_transaction_rec.oe_order_header_id
406     , l_rcv_transaction_rec.oe_order_line_id
407     , l_rcv_transaction_rec.from_organization_id
408     );
409 
410     IF (l_debug = 1) THEN
411       print_debug('insert_txn_interface: 3  after RCV_RECEIPTS_QUERY_SV.POST_QUERY ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
412     END IF;
413 
414     l_rcv_transaction_rec.destination_type_code_hold := x_destination_type_code;
415 
416     IF l_rcv_transaction_rec.source_type_code = 'CUSTOMER' THEN
417       -- get the item category based on item_id, category_set_id and org_id
418 
419       IF l_rcv_transaction_rec.item_category_id IS NULL THEN
420         BEGIN
421           SELECT MAX(category_id)
422             INTO l_rcv_transaction_rec.item_category_id
423             FROM mtl_item_categories
424            WHERE inventory_item_id = l_rcv_transaction_rec.item_id
425              AND organization_id = p_organization_id
426              AND category_set_id = inv_rcv_common_apis.g_po_startup_value.category_set_id;
427         EXCEPTION
428           WHEN OTHERS THEN
429             IF (l_debug = 1) THEN
430               print_debug('insert_txn_interface: Exception in getting the item categories', 4);
431             END IF;
432         END;
433       END IF;
434 
435       IF NVL(l_rcv_transaction_rec.inspection_required_flag, 'N') = 'Y' THEN
436         x_routing_id := 2;
437       -- Bug 3124881 Get the default routing parameter from rcv_parameters
438       ELSIF ( l_rcv_transaction_rec.receipt_source_code = 'CUSTOMER' ) then
439           Begin
440             select rma_receipt_routing_id
441               into x_routing_id
442               from rcv_parameters
443              where organization_id = p_organization_id;
444 
445             IF (l_debug = 1) THEN
446               print_debug('insert_txn_interface: from rcv parameters: x_routing_id = '|| x_routing_id, 4);
447             END IF;
448 
449           Exception
450             WHEN OTHERS THEN
451               IF (l_debug = 1) THEN
452                 print_debug('insert_txn_interface: Exception in getting the routing id from rcv parameters', 4);
453                 print_debug('insert_txn_interface: routing id is set to what fetched from post_query : x_routing_id ='|| x_routing_id, 4);
454               END IF;
455           End;
456       END IF;
457 
458       /*
459              select routing_name
460           into l_rcv_transaction_rec.routing_name
461           from rcv_routing_headers
462          where routing_header_id = x_routing_id;
463       */
464       x_available_qty := l_rcv_transaction_rec.ordered_qty;
465     --       x_uom := l_rcv_transaction_rec.ordered_uom;
466 
467     END IF;
468 
469     -- using a nvl around p_qa_routing_id as calling apis pass null sometimes
470 
471     IF (Nvl(p_qa_routing_id,-1) = -1) THEN
472        --BUG 3346758: For Int Ship, if the intrasit shipment is set
473        --created with a routing id, then the user go and change it in the
474        --shipping network form.  Post_query above would return a different
475        --id then the one passed in UI.  So, the check below is used to
476        --bypass this scenario.
477        IF (l_rcv_transaction_rec.routing_id IS NULL) THEN
478     l_rcv_transaction_rec.routing_id := x_routing_id;
479        END IF;
480     ELSE
481       l_rcv_transaction_rec.routing_id := p_qa_routing_id;
482     END IF;
483 
484     IF inv_rcv_common_apis.g_po_startup_value.blind_receiving_flag = 'Y' THEN
485       x_available_qty := 0;
486       l_rcv_transaction_rec.ordered_qty := 0;
487     END IF;
488 
489     IF (NOT x_valid_ship_to_location) THEN
490       l_rcv_transaction_rec.ship_to_location_id := '';
491     --       l_rcv_transaction_rec.ship_to_location := '';
492     END IF;
493 
494     IF (NVL(l_rcv_transaction_rec.receipt_source_code, 'VENDOR') = 'CUSTOMER') THEN
495       -- Final destination for an RMA receiving trx. is always inventory.
496       SELECT displayed_field
497            , lookup_code
498         INTO x_destination_type_dsp
499            , x_destination_type_code
500         FROM po_lookup_codes
501        WHERE lookup_code = 'INVENTORY'
502          AND lookup_type = 'RCV DESTINATION TYPE';
503     END IF;
504 
505     l_rcv_transaction_rec.destination_type_code_hold := x_destination_type_code;
506 
507    --Bug #3792668
508    --Checking the conversion rate has been defined for a currency
509    --which is other than functional one for the transaction date.
510    --Taken out this portion of code from the check --> IF l_rcv_transaction_rec.routing_id IN('1', '2') THEN
511    --Changes Start
512 
513    IF l_rcv_transaction_rec.routing_id IN('1', '2') THEN
514      IF x_num_of_distributions <= 1 THEN
515         l_rcv_transaction_rec.currency_conversion_rate := x_rate;
516         l_rcv_transaction_rec.currency_conversion_date := x_rate_date;
517      END IF;
518    END IF;
519 
520      -- currency coversion info post query
521      -- copied from rcv_currency_c1.PostQuery (RCVRCCUR.pld)
522 
523      IF l_rcv_transaction_rec.match_option <> 'P' THEN
524        l_rcv_transaction_rec.currency_conversion_date := l_sysdate;
525 
526        IF (l_rcv_transaction_rec.currency_code <> inv_rcv_common_apis.g_po_startup_value.currency_code) THEN
527          l_rate := l_rcv_transaction_rec.currency_conversion_rate;
528 
529          IF (l_rcv_transaction_rec.currency_conversion_type <> 'User') THEN
530            BEGIN
531              l_rate :=
532                gl_currency_api.get_rate(
533                  inv_rcv_common_apis.g_po_startup_value.sob_id
534                , l_rcv_transaction_rec.currency_code
535                , l_rcv_transaction_rec.currency_conversion_date
536                , l_rcv_transaction_rec.currency_conversion_type
537                );
538 
539            EXCEPTION
540              WHEN gl_currency_api.no_rate THEN
541                l_rate := NULL;
542              WHEN gl_currency_api.invalid_currency THEN
543                l_rate := NULL;
544              WHEN OTHERS THEN
545                IF (l_debug = 1) THEN
546                   print_debug('insert_txn_interface: ERROR in getting the Conversion Rate' , 4);
547                END IF;
548 
549                RAISE fnd_api.g_exc_unexpected_error;
550            END;
551 
552            IF (l_debug = 1) THEN
553              print_debug('insert_txn_interface : l_rate :  ' || l_rate, 4);
554            END IF;
555 
556            -- Give error message to user that no rate has been found
557            IF l_rate IS NULL THEN
558              fnd_message.set_name('PO', 'PO_CPO_NO_RATE_FOR_DATE');
559              fnd_msg_pub.add;
560              IF (l_debug = 1) THEN
561                 print_debug('insert_txn_interface: No Conversion rate has been defined for the currency : ' || l_rcv_transaction_rec.currency_code || ' for the txn date :  ' || l_rcv_transaction_rec.currency_conversion_date , 4);
562              END IF;
563              RAISE FND_API.G_EXC_ERROR;
564           END IF;
565 
566          END IF;
567 
568          l_rcv_transaction_rec.currency_conversion_rate := l_rate;
569        END IF;
570      END IF;
571      --End of fix for the Bug #3792668
572 
573 
574     IF l_rcv_transaction_rec.routing_id IN('1', '2') THEN
575       l_rcv_transaction_rec.destination_type_code := 'RECEIVING';
576       -- following fields will be set at po_distribution level if
577       -- it has a direct routing
578       l_rcv_transaction_rec.po_distribution_id := x_po_distribution_id;
579       l_rcv_transaction_rec.deliver_to_location_id := x_deliver_to_location_id;
580  --     l_rcv_transaction_rec.locator_id := x_deliver_to_locator_id;
581       l_rcv_transaction_rec.deliver_to_person_id := x_deliver_to_person_id;
582   --  l_rcv_transaction_rec.locator_id := x_deliver_to_locator_id; --RCVCLOCSSUPPORT
583 
584   --    IF x_deliver_to_sub IS NOT NULL THEN
585  --       l_rcv_transaction_rec.destination_subinventory := x_deliver_to_sub;
586  --     END IF; RCVLOCSSUPPORT --RCVLOCSSUPPORT
587 
588       IF (x_wip_entity_id > 0) THEN
589         l_rcv_transaction_rec.wip_entity_id := x_wip_entity_id;
590         l_rcv_transaction_rec.wip_line_id := x_wip_line_id;
591         l_rcv_transaction_rec.wip_repetitive_schedule_id := x_wip_repetitive_schedule_id;
592         l_rcv_transaction_rec.wip_operation_seq_num := x_wip_operation_seq_num;
593         l_rcv_transaction_rec.wip_resource_seq_num := x_wip_resource_seq_num;
594         l_rcv_transaction_rec.bom_resource_id := x_bom_resource_id;
595       END IF;
596 
597       IF (l_debug = 1) THEN
598         print_debug('insert_txn_interface: revision2  - ' || x_item_revision, 4);
599       END IF;
600 
601       -- revision needs to be taken care of by matching
602 
603       IF x_item_revision IS NOT NULL THEN
604         l_rcv_transaction_rec.item_revision := x_item_revision;
605       END IF;
606 
607       IF (
608           x_req_line_id IS NOT NULL
609           AND x_deliver_to_locator_id IS NOT NULL
610           AND NVL(l_rcv_transaction_rec.receipt_source_code, 'VENDOR') <> 'VENDOR'
611          ) THEN
612         SELECT project_id
613              , task_id
614           INTO x_project_id
615              , x_task_id
616           FROM po_req_distributions
617          WHERE requisition_line_id = x_req_line_id;
618       END IF;
619 
620       IF (
621           l_rcv_transaction_rec.receipt_source_code = 'CUSTOMER'
622           AND x_oe_order_line_id IS NOT NULL
623           AND x_deliver_to_locator_id IS NOT NULL
624          ) THEN
625         SELECT project_id
626              , task_id
627           INTO x_project_id
628              , x_task_id
629           FROM oe_order_lines_all
630          WHERE line_id = x_oe_order_line_id;
631       END IF;
632 
633       IF x_project_id IS NOT NULL THEN
634         pjm_project_locator.get_defaultprojectlocator(
635               p_organization_id
636             , x_deliver_to_locator_id
637             , x_project_id
638             , x_task_id
639             , x_deliver_to_locator_id);
640       END IF;
641 
642     --  l_rcv_transaction_rec.locator_id := x_deliver_to_locator_id;
643     ELSE
644       IF (NVL(l_rcv_transaction_rec.receipt_source_code, 'VENDOR') = 'CUSTOMER') THEN
645         SELECT lookup_code
646           INTO l_rcv_transaction_rec.destination_type_code
647           FROM po_lookup_codes
648          WHERE lookup_code = 'INVENTORY'
649            AND lookup_type = 'RCV DESTINATION TYPE';
650       END IF;
651     END IF;
652 
653     IF l_rcv_transaction_rec.destination_type_code = 'RECEIVING'
654        AND p_location_id IS NOT NULL THEN
655       l_rcv_transaction_rec.ship_to_location_id := p_location_id;
656     ELSE
657       l_rcv_transaction_rec.deliver_to_location_id := p_location_id;
658     END IF;
659     -- end defaulting
660 
661     -- prepare other values before inserting into RTI
662     -- this part of code is replicating RCV_RECEIPTS_TH.insert_transaction (RCVRCERL.pld)
663     l_primary_uom := l_rcv_transaction_rec.primary_uom;
664     l_source_type_code := l_rcv_transaction_rec.receipt_source_code;
665     l_source_doc_code := l_rcv_transaction_rec.order_type_code;
666     l_to_org_id := l_rcv_transaction_rec.to_organization_id;
667     l_sub_unordered_code := l_rcv_transaction_rec.substitute_receipt;
668     --OPM Convergence
669     l_secondary_unit_of_measure := l_rcv_transaction_rec.secondary_uom;
670     l_secondary_uom_code := l_rcv_transaction_rec.secondary_uom_code;
671     l_secondary_quantity := l_rcv_transaction_rec .secondary_quantity;
672     --end of changes for OPM Convergence
673 
674     print_debug('l_secondary_quantity ' || l_secondary_quantity,4);
675     print_debug('l_secondary_uom_code ' || l_secondary_uom_code,4);
676     print_debug('l_secondary_unit_of_measure ' || l_secondary_unit_of_measure,4);
677 
678 
679 -- For Bug 7440217 added LCM Doc type along with ASN
680     IF l_rcv_transaction_rec.source_type_code IN('VENDOR', 'ASN', 'LCM') THEN
681 -- End for Bug 7440217
682       l_vendor_id := l_rcv_transaction_rec.vendor_id;
683       l_vendor_site_id := l_rcv_transaction_rec.vendor_site_id;
684       l_po_header_id := l_rcv_transaction_rec.po_header_id;
685       l_po_release_id := l_rcv_transaction_rec.po_release_id;
686       l_po_line_id := l_rcv_transaction_rec.po_line_id;
687       l_po_line_location_id := l_rcv_transaction_rec.po_line_location_id;
688     ELSIF l_rcv_transaction_rec.source_type_code = 'CUSTOMER' THEN
689       l_customer_id := l_rcv_transaction_rec.customer_id;
690       l_customer_site_id := l_rcv_transaction_rec.customer_site_id;
691       l_oe_order_header_id := l_rcv_transaction_rec.oe_order_header_id;
692       l_oe_order_line_id := l_rcv_transaction_rec.oe_order_line_id;
693     ELSIF l_rcv_transaction_rec.source_type_code = 'INTERNAL' THEN
694       l_req_line_id := l_rcv_transaction_rec.req_line_id;
695       l_from_org_id := l_rcv_transaction_rec.from_organization_id;
696       l_shipment_line_id := l_rcv_transaction_rec.rcv_shipment_line_id;
697     END IF;
698 
699 -- For Bug 7440217 added LCM Doc type along with ASN
700     IF l_rcv_transaction_rec.source_type_code IN ('ASN', 'LCM') THEN
701 -- End for Bug 7440217
702       l_shipment_line_id := l_rcv_transaction_rec.rcv_shipment_line_id;
703     END IF;
704 
705     IF l_rcv_transaction_rec.destination_type_code = 'RECEIVING' THEN
706       l_auto_transact_code := 'RECEIVE';
707       l_location_id  := l_rcv_transaction_rec.ship_to_location_id;
708       l_subinventory := l_rcv_transaction_rec.destination_subinventory; --RCVLOCSSUPPORT
709       l_locator_id   := l_rcv_transaction_rec.locator_id;
710     ELSE
711       l_auto_transact_code := 'DELIVER';
712       l_po_distribution_id := l_rcv_transaction_rec.po_distribution_id;
713       l_deliver_to_person_id := l_rcv_transaction_rec.deliver_to_person_id;
714       l_deliver_to_location_id := l_rcv_transaction_rec.deliver_to_location_id;
715       l_subinventory := l_rcv_transaction_rec.destination_subinventory;
716       l_locator_id := l_rcv_transaction_rec.locator_id;
717       l_location_id := l_rcv_transaction_rec.deliver_to_location_id;
718 
719 -- For Bug 7440217 added LCM Doc type along with ASN
720       IF l_rcv_transaction_rec.source_type_code IN('VENDOR', 'ASN', 'LCM') THEN
721 -- End for Bug 7440217
722         l_wip_entity_id := l_rcv_transaction_rec.wip_entity_id;
723         l_wip_line_id := l_rcv_transaction_rec.wip_line_id;
724         l_department_code := l_rcv_transaction_rec.department_code;
725         l_wip_rep_sched_id := l_rcv_transaction_rec.wip_repetitive_schedule_id;
726         l_wip_oper_seq_num := l_rcv_transaction_rec.wip_operation_seq_num;
727         l_wip_res_seq_num := l_rcv_transaction_rec.wip_resource_seq_num;
728         l_bom_resource_id := l_rcv_transaction_rec.bom_resource_id;
729       END IF;
730     END IF;
731 
732     l_sub_unordered_code := l_rcv_transaction_rec.substitute_receipt;
733 
734     IF l_rcv_transaction_rec.receipt_source_code = 'CUSTOMER' THEN
735       l_source_doc_code := 'RMA';
736     END IF;
737 
738     -- insert this record into RTI
739     -- Insert the row into the interface table using
740     -- the table handler call for the
741     -- rcv_transactions_interface table
742 
743     -- For inter-org shipment and ASN receipt, shipment header id is set already
744     -- For Normal PO, we generate a shipment header id at this point,
745     -- then use the same when actually inserting record into RSH.
746     -- If it is to receive a PO that belongs to an ASN,
747     -- we need to create a new shipment header for it
748 
749     -- If patchset J since the g_shipment_header_id is cleared from
750     -- rcv_clear_global in INVRCVCB.pls and not g_header_intf_id
751     -- we look at g_shipment_header_id to figure out if we need
752     -- to generate a new value for header_intf_id to insert in RTI.
753     IF g_shipment_header_id IS NULL THEN
754       SELECT rcv_headers_interface_s.NEXTVAL
755       INTO g_header_intf_id
756       FROM dual;
757     END IF;
758 
759     IF l_rcv_transaction_rec.source_type_code = 'INTERNAL'
760 -- For Bug 7440217
761        OR(l_rcv_transaction_rec.source_type_code IN ('ASN', 'LCM')
762 -- End for Bug 7440217
763           AND p_source_type <> 'VENDOR') THEN
764       g_shipment_header_id := l_rcv_transaction_rec.rcv_shipment_header_id;
765     END IF;
766 
767     IF g_shipment_header_id IS NULL THEN
768       SELECT rcv_shipment_headers_s.NEXTVAL
769         INTO g_shipment_header_id
770         FROM DUAL;
771     END IF;
772 
773     IF (l_debug = 1) THEN
774       print_debug('insert_txn_interface: 4  before rcv_trx_interface_insert_pkg.insert_row '
775         || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
776       , 4);
777     END IF;
778 
779     IF (l_debug = 1) THEN
780       print_debug('insert_txn_interface: revision3 - ' || l_rcv_transaction_rec.item_revision, 4);
781     END IF;
782 
783     IF (l_debug = 1) THEN
784       print_debug('insert_txn_interface: rcv sub loc - ' || l_subinventory ||' , '|| l_locator_id, 4);
785     END IF;
786 
787     IF (l_debug = 1) THEN
788       print_debug('insert_txn_interface before insert row  value of coutry of origin is '
789         || l_rcv_transaction_rec.country_of_origin_code
790       , 4);
791     END IF;
792 
793     /* If INV and PO J are installed, :
794      *    -> shipment_header_id should be inserted as null but header_interface_id
795      *       should be inserted. Header_interface_id will be non null only if INV
796      *       and  PO J are installed (or higher).
797      *    -> Populate values for three new columns lpn_group_id, validation_flag
798      *       and header_interface_id_id
799      *    -> Populate project_id and task_id in RTI from inputs
800      */
801     IF ((inv_rcv_common_apis.g_inv_patch_level >= inv_rcv_common_apis.g_patchset_j) AND
802         (inv_rcv_common_apis.g_po_patch_level  >= inv_rcv_common_apis.g_patchset_j_po)) THEN
803       IF ((l_rcv_transaction_rec.source_type_code = 'INTERNAL') OR
804 -- For Bug 7440217
805          (l_rcv_transaction_rec.source_type_code IN ('ASN', 'LCM') AND p_source_type <> 'VENDOR')) THEN
806 -- End for Bug 7440217
807         IF (l_debug = 1) THEN
808           print_debug('Setting the shipment_header_id as this may be a INTSHIP/ASN Receive TXN', 4);
809         END IF;
810         l_shipment_header_id := g_shipment_header_id;
811       ELSE
812         IF (l_debug = 1) THEN
813           print_debug('Nulling the shipment_header_id to insert for J code', 4);
814         END IF;
815         l_shipment_header_id := NULL;
816       END IF;
817 
818       --Set the values of the new columns to be populated in RTI
819       l_lpn_group_id := p_group_id;
820       l_validation_flag := 'Y';
821       l_header_interface_id := g_header_intf_id;
822 
823       IF p_project_id = -9999 THEN
824         l_project_id := NULL;
825       END IF;
826 
827       IF p_task_id = -9999 THEN
828         l_task_id := NULL;
829       END IF;
830 
831     --If INV or PO patch levels are lower than J
832     ELSE
833       l_shipment_header_id := g_shipment_header_id;
834       l_header_interface_id := NULL;
835       l_lpn_group_id := NULL;
836       l_validation_flag := NULL;
837       l_project_id := NULL;
838       l_task_id := NULL;
839     END IF;
840 
841     -- bug 3452845
842     IF ((inv_rcv_common_apis.g_inv_patch_level >= inv_rcv_common_apis.g_patchset_j) AND
843         (inv_rcv_common_apis.g_po_patch_level  >= inv_rcv_common_apis.g_patchset_j_po)) THEN
844        l_txn_date := Sysdate;
845      ELSE
846        l_txn_date := Trunc(Sysdate);
847     END IF;
848 
849     --BUG 4730474: populate the document number column when receiving
850     --against INTSHP/INTREQ so that the receiving preprocessor can
851     --match to the right line
852     IF (p_rcv_rcpt_rec.receipt_source_code = 'INVENTORY') then --bug 5483231
853        l_rcv_transaction_rec.rcv_line_number := p_rcv_rcpt_rec.rcv_line_number;
854      ELSE
855        l_rcv_transaction_rec.rcv_line_number := NULL;
856     END IF;
857 
858  print_debug('b4 inserting l_secondary_quantity ' || l_secondary_quantity,4);
859     print_debug('b4 insertingl_secondary_uom_code ' || l_secondary_uom_code,4);
860     print_debug('b4 insertingl_secondary_unit_of_measure ' || l_secondary_unit_of_measure,4);
861 
862     --<R12 MOAC>
863     l_operating_unit_id := inv_rcv_common_apis.get_operating_unit_id(
864                                      l_rcv_transaction_rec.receipt_source_code,
865                                      l_rcv_transaction_rec.po_header_id,
866                                      l_rcv_transaction_rec.req_line_id,
867                                      l_rcv_transaction_rec.oe_order_header_id );
868 
869     --Using the direct insert statement here rather than table handler
870 
871     /*bug 4697949.Populating the rti.item with item_id from po_line
872       and populating substitute_item_id with item_id so that the transaction
873       passes the validation.also nulling out description so that it can bedefaulted
874       correctly later on*/
875 
876     /** Bug: 5598511
877       * Added the following conditions rcv_shipment_header_id not null and
878       * item_id not null.
879       */
880     IF     l_po_line_id IS NOT null
881        and l_rcv_transaction_rec.rcv_shipment_header_id IS NULL
882        and l_rcv_transaction_rec.item_id IS NOT NULL  THEN
883       SELECT item_id
884       INTO   l_po_item_id
885       FROM   po_lines_all pol
886       WHERE  pol.po_line_id = l_po_line_id;
887 
888       IF (l_po_item_id <> l_rcv_transaction_rec.item_id) THEN
889         l_substitute_item_id := l_rcv_transaction_rec.item_id;
890         l_rcv_transaction_rec.item_id := l_po_item_id;
891 	l_rcv_transaction_rec.item_description := null;
892       END IF;
893     END IF;
894     print_debug('l_express_transaction: ' || l_express_transaction,4);
895     -- bug 4697949 end
896     INSERT INTO rcv_transactions_interface
897               (
898                interface_transaction_id
899              , GROUP_ID
900              , last_update_date
901              , last_updated_by
902              , creation_date
903              , created_by
904              , last_update_login
905              , transaction_type
906              , transaction_date
907              , processing_status_code
908              , processing_mode_code
909              , processing_request_id
910              , transaction_status_code
911              , category_id
912              , quantity
913              , unit_of_measure
914              , interface_source_code
915              , interface_source_line_id
916              , inv_transaction_id
917              , item_id
918              , item_description
919              , item_revision
920              , uom_code
921              , employee_id
922              , auto_transact_code
923              , shipment_header_id
924              , shipment_line_id
925              , ship_to_location_id
926              , primary_quantity
927              , primary_unit_of_measure
928              , receipt_source_code
929              , vendor_id
930              , vendor_site_id
931              , from_organization_id
932              , to_organization_id
933              , routing_header_id
934              , routing_step_id
935              , source_document_code
936              , parent_transaction_id
937              , po_header_id
938              , po_revision_num
939              , po_release_id
940              , po_line_id
941              , po_line_location_id
942              , po_unit_price
943              , currency_code
944              , currency_conversion_type
945              , currency_conversion_rate
946              , currency_conversion_date
947              , po_distribution_id
948              , requisition_line_id
949              , req_distribution_id
950              , charge_account_id
951              , substitute_unordered_code
952              , receipt_exception_flag
953              , accrual_status_code
954              , inspection_status_code
955              , inspection_quality_code
956              , destination_type_code
957              , deliver_to_person_id
958              , location_id
959              , deliver_to_location_id
960              , subinventory
961              , locator_id
962              , wip_entity_id
963              , wip_line_id
964              , department_code
965              , wip_repetitive_schedule_id
966              , wip_operation_seq_num
967              , wip_resource_seq_num
968              , bom_resource_id
969              , shipment_num
970              , freight_carrier_code
971              , bill_of_lading
972              , packing_slip
973              , shipped_date
974              , expected_receipt_date
975              , actual_cost
976              , transfer_cost
977              , transportation_cost
978              , transportation_account_id
979              , num_of_containers
980              , waybill_airbill_num
981              , vendor_item_num
982              , vendor_lot_num
983              , rma_reference
984              , comments
985              , attribute_category
986              , attribute1
987              , attribute2
988              , attribute3
989              , attribute4
990              , attribute5
991              , attribute6
992              , attribute7
993              , attribute8
994              , attribute9
995              , attribute10
996              , attribute11
997              , attribute12
998              , attribute13
999              , attribute14
1000              , attribute15
1001              , ship_head_attribute_category
1002              , ship_head_attribute1
1003              , ship_head_attribute2
1004              , ship_head_attribute3
1005              , ship_head_attribute4
1006              , ship_head_attribute5
1007              , ship_head_attribute6
1008              , ship_head_attribute7
1009              , ship_head_attribute8
1010              , ship_head_attribute9
1011              , ship_head_attribute10
1012              , ship_head_attribute11
1013              , ship_head_attribute12
1014              , ship_head_attribute13
1015              , ship_head_attribute14
1016              , ship_head_attribute15
1017              , ship_line_attribute_category
1018              , ship_line_attribute1
1019              , ship_line_attribute2
1020              , ship_line_attribute3
1021              , ship_line_attribute4
1022              , ship_line_attribute5
1023              , ship_line_attribute6
1024              , ship_line_attribute7
1025              , ship_line_attribute8
1026              , ship_line_attribute9
1027              , ship_line_attribute10
1028              , ship_line_attribute11
1029              , ship_line_attribute12
1030              , ship_line_attribute13
1031              , ship_line_attribute14
1032              , ship_line_attribute15
1033              , ussgl_transaction_code
1034              , government_context
1035              , reason_id
1036              , destination_context
1037              , source_doc_quantity
1038              , source_doc_unit_of_measure
1039              , use_mtl_lot
1040              , use_mtl_serial
1041              , qa_collection_id
1042              , country_of_origin_code
1043              , oe_order_header_id
1044              , oe_order_line_id
1045              , customer_item_num
1046              , customer_id
1047              , customer_site_id
1048              , put_away_rule_id
1049              , put_away_strategy_id
1050              , lpn_id
1051              , transfer_lpn_id
1052              , cost_group_id
1053              , mmtt_temp_id
1054              , mobile_txn
1055              , transfer_cost_group_id
1056              , lpn_group_id
1057              , validation_flag
1058              , header_interface_id
1059              , project_id
1060              , task_id
1061              , secondary_unit_of_measure --OPM Convergence
1062              , secondary_quantity --OPM Convergence
1063              , secondary_uom_code --OPM Convergence
1064 	     , org_id              --<R12 MOAC>
1065              , document_line_num  --BUG 4730474
1066 	     , substitute_item_id --bug 4697949
1067 	     , express_transaction --bug 5550783
1068               )
1069        VALUES (
1070                l_interface_transaction_id
1071              , p_group_id
1072              , l_sysdate
1073              , inv_rcv_common_apis.g_po_startup_value.user_id  /* Last Updated By */
1074              , l_sysdate  /* Created Date */
1075              , inv_rcv_common_apis.g_po_startup_value.user_id  /* Created By */
1076              , inv_rcv_common_apis.g_po_startup_value.user_id  /* last Update Login */
1077              , p_transaction_type  /* transaction type */
1078              , l_txn_date  /* transaction date */
1079              , 'PENDING'  /* Processing status code */
1080              , inv_rcv_common_apis.g_po_startup_value.transaction_mode
1081              , NULL
1082              , 'PENDING'  /* Transaction status code */
1083              , l_rcv_transaction_rec.item_category_id
1084              , l_rcv_transaction_rec.transaction_qty
1085              , l_rcv_transaction_rec.transaction_uom
1086              , 'RCV'  /* interface source code */
1087              , NULL  /* interface source line id */
1088              , NULL  /* inv_transaction id */
1089              , l_rcv_transaction_rec.item_id
1090              , l_rcv_transaction_rec.item_description
1091              , l_rcv_transaction_rec.item_revision
1092              , l_rcv_transaction_rec.uom_code
1093              , inv_rcv_common_apis.g_po_startup_value.employee_id -- Fix for bug 2073164
1094              , l_auto_transact_code  /* Auto transact code */
1095              , l_shipment_header_id  /* shipment header id */
1096              , l_shipment_line_id  /* shipment line id */
1097              , l_rcv_transaction_rec.ship_to_location_id
1098              , l_rcv_transaction_rec.primary_quantity  /* primary quantity */
1099              , l_primary_uom  /* primary uom */
1100              , l_source_type_code  /* receipt source code */
1101              , l_vendor_id
1102              , l_vendor_site_id
1103              , l_from_org_id  /* from org id */
1104              , l_to_org_id  /* to org id */
1105              , l_rcv_transaction_rec.routing_id
1106              , 1  /* routing step id */
1107              , l_source_doc_code  /* source document code */
1108              , NULL  /* Parent trx id */
1109              , l_po_header_id
1110              , NULL  /* PO Revision number */
1111              , l_po_release_id
1112              , l_po_line_id
1113              , l_po_line_location_id
1114              , l_rcv_transaction_rec.unit_price
1115              , l_rcv_transaction_rec.currency_code  /* Currency_Code */
1116              , l_rcv_transaction_rec.currency_conversion_type
1117              , l_rcv_transaction_rec.currency_conversion_rate
1118              , TRUNC(l_rcv_transaction_rec.currency_conversion_date)
1119              , l_po_distribution_id
1120              , l_req_line_id
1121              , l_rcv_transaction_rec.req_distribution_id
1122              , NULL  /* Charge_Account_Id */
1123              , l_sub_unordered_code  /* Substitute_Unordered_Code */
1124              , l_rcv_transaction_rec.receipt_exception  /* Receipt_Exception_Flag  forms check box?*/
1125              , NULL  /* Accrual_Status_Code */
1126              , 'NOT INSPECTED'  /* Inspection_Status_Code */
1127              , NULL  /* Inspection_Quality_Code */
1128              , l_rcv_transaction_rec.destination_type_code  /* Destination_Type_Code */
1129              , l_deliver_to_person_id  /* Deliver_To_Person_Id */
1130              , l_location_id  /* Location_Id */
1131              , l_deliver_to_location_id  /* Deliver_To_Location_Id */
1132              , l_subinventory  /* Subinventory */
1133              , l_locator_id  /* Locator_Id */
1134              , l_wip_entity_id  /* Wip_Entity_Id */
1135              , l_wip_line_id  /* Wip_Line_Id */
1136              , l_department_code  /* Department_Code */
1137              , l_wip_rep_sched_id  /* Wip_Repetitive_Schedule_Id */
1138              , l_wip_oper_seq_num  /* Wip_Operation_Seq_Num */
1139              , l_wip_res_seq_num  /* Wip_Resource_Seq_Num */
1140              , l_bom_resource_id  /* Bom_Resource_Id */
1141              , l_rcv_transaction_rec.rcv_shipment_number
1142              , NULL
1143              , NULL  /* Bill_Of_Lading */
1144              , NULL  /* Packing_Slip */
1145              , TRUNC(l_rcv_transaction_rec.shipped_date)
1146              , TRUNC(l_rcv_transaction_rec.expected_receipt_date)  /* Expected_Receipt_Date */
1147              , NULL  /* Actual_Cost */
1148              , NULL  /* Transfer_Cost */
1149              , NULL  /* Transportation_Cost */
1150              , NULL  /* Transportation_Account_Id */
1151              , NULL  /* Num_Of_Containers */
1152              , NULL  /* Waybill_Airbill_Num */
1153              , l_rcv_transaction_rec.vendor_item_number  /* Vendor_Item_Num */
1154              , l_rcv_transaction_rec.vendor_lot_num  /* Vendor_Lot_Num */
1155              , NULL  /* Rma_Reference */
1156              , l_rcv_transaction_rec.comments  /* Comments  ? from form*/
1157              , l_rcv_transaction_rec.attribute_category  /* Attribute_Category */
1158              , l_rcv_transaction_rec.attribute1  /* Attribute1 */
1159              , l_rcv_transaction_rec.attribute2  /* Attribute2 */
1160              , l_rcv_transaction_rec.attribute3  /* Attribute3 */
1161              , l_rcv_transaction_rec.attribute4  /* Attribute4 */
1162              , l_rcv_transaction_rec.attribute5  /* Attribute5 */
1163              , l_rcv_transaction_rec.attribute6  /* Attribute6 */
1164              , l_rcv_transaction_rec.attribute7  /* Attribute7 */
1165              , l_rcv_transaction_rec.attribute8  /* Attribute8 */
1166              , l_rcv_transaction_rec.attribute9  /* Attribute9 */
1167              , l_rcv_transaction_rec.attribute10  /* Attribute10 */
1168              , l_rcv_transaction_rec.attribute11  /* Attribute11 */
1169              , l_rcv_transaction_rec.attribute12  /* Attribute12 */
1170              , l_rcv_transaction_rec.attribute13  /* Attribute13 */
1171              , l_rcv_transaction_rec.attribute14  /* Attribute14 */
1172              , l_rcv_transaction_rec.attribute15  /* Attribute15 */
1173              , NULL  /* Ship_Head_Attribute_Category */
1174              , NULL  /* Ship_Head_Attribute1 */
1175              , NULL  /* Ship_Head_Attribute2 */
1176              , NULL  /* Ship_Head_Attribute3 */
1177              , NULL  /* Ship_Head_Attribute4 */
1178              , NULL  /* Ship_Head_Attribute5 */
1179              , NULL  /* Ship_Head_Attribute6 */
1180              , NULL  /* Ship_Head_Attribute7 */
1181              , NULL  /* Ship_Head_Attribute8 */
1182              , NULL  /* Ship_Head_Attribute9 */
1183              , NULL  /* Ship_Head_Attribute10 */
1184              , NULL  /* Ship_Head_Attribute11 */
1185              , NULL  /* Ship_Head_Attribute12 */
1186              , NULL  /* Ship_Head_Attribute13 */
1187              , NULL  /* Ship_Head_Attribute14 */
1188              , NULL  /* Ship_Head_Attribute15 */
1189              , NULL  /* Ship_Line_Attribute_Category */
1190              , NULL  /* Ship_Line_Attribute1 */
1191              , NULL  /* Ship_Line_Attribute2 */
1192              , NULL  /* Ship_Line_Attribute3 */
1193              , NULL  /* Ship_Line_Attribute4 */
1194              , NULL  /* Ship_Line_Attribute5 */
1195              , NULL  /* Ship_Line_Attribute6 */
1196              , NULL  /* Ship_Line_Attribute7 */
1197              , NULL  /* Ship_Line_Attribute8 */
1198              , NULL  /* Ship_Line_Attribute9 */
1199              , NULL  /* Ship_Line_Attribute10 */
1200              , NULL  /* Ship_Line_Attribute11 */
1201              , NULL  /* Ship_Line_Attribute12 */
1202              , NULL  /* Ship_Line_Attribute13 */
1203              , NULL  /* Ship_Line_Attribute14 */
1204              , NULL  /* Ship_Line_Attribute15 */
1205              , l_rcv_transaction_rec.ussgl_transaction_code  /* Ussgl_Transaction_Code */
1206              , l_rcv_transaction_rec.government_context  /* Government_Context */
1207              , l_rcv_transaction_rec.reason_id  /* ? */
1208              , l_rcv_transaction_rec.destination_type_code  /* Destination_Context */
1209              , l_rcv_transaction_rec.transaction_qty
1210              , l_rcv_transaction_rec.transaction_uom
1211              , l_rcv_transaction_rec.lot_control_code
1212              , l_rcv_transaction_rec.serial_number_control_code
1213              , NULL
1214              , l_rcv_transaction_rec.country_of_origin_code
1215              , l_oe_order_header_id
1216              , l_oe_order_line_id
1217              , l_customer_item_num
1218              , l_customer_id
1219              , l_customer_site_id
1220              , NULL  /* PUT_AWAY_RULE_ID */
1221              , NULL  /* PUT_AWAY_STRATEGY_ID */
1222              , l_rcv_transaction_rec.lpn_id  /* LPN_ID */
1223              , l_rcv_transaction_rec.transfer_lpn_id  /* Transfer LPN ID */
1224              , l_rcv_transaction_rec.cost_group_id  /* cost_group_id */
1225              , NULL  /* mmtt_temp_id */
1226              , 'Y'  /* mobile_txn */
1227              , l_rcv_transaction_rec.transfer_cost_group_id  /* xfer_cost_group_id*/
1228              , l_lpn_group_id
1229              , l_validation_flag
1230              , l_header_interface_id
1231              , l_project_id
1232              , l_task_id
1233              , l_secondary_unit_of_measure
1234              , l_secondary_quantity
1235              , l_secondary_uom_code
1236 	     , l_operating_unit_id  --<R12 MOAC>
1237              , l_rcv_transaction_rec.rcv_line_number--BUG 4730474
1238 	     , l_substitute_item_id --bug 4697949
1239 	     , l_express_transaction --bug 5550783
1240               );
1241 
1242 -- For Bug 7440217 added the following code to update RTI with the status as PENDING so that it gets picked up for processing
1243 
1244 IF l_po_line_location_id IS NOT NULL THEN
1245   SELECT  LCM_FLAG
1246   INTO    v_lcm_flag
1247   FROM    PO_LINE_LOCATIONS_ALL
1248   WHERE   LINE_LOCATION_ID = l_po_line_location_id;
1249 END IF;
1250 
1251 IF nvl(v_lcm_flag, 'N') = 'Y' THEN
1252   SELECT  mp.lcm_enabled_flag
1253   INTO    v_lcm_enabled_org
1254   FROM    mtl_parameters mp
1255   WHERE	  mp.organization_id = l_to_org_id;
1256 
1257   SELECT  rp.pre_receive
1258   INTO    v_pre_receive
1259   FROM    rcv_parameters rp
1260   WHERE	  rp.organization_id = l_to_org_id;
1261 
1262 /*  SELECT  LCM_FLAG
1263   INTO    v_lcm_flag
1264   FROM    PO_LINE_LOCATIONS_ALL
1265   WHERE   LINE_LOCATION_ID = l_po_line_location_id;
1266 */
1267 
1268   IF	nvl(v_lcm_enabled_org, 'N') = 'Y' THEN
1269 	IF	nvl(v_pre_receive, 'N') = 'Y'   THEN
1270 
1271 		  SELECT	LCM_SHIPMENT_LINE_ID, UNIT_LANDED_COST
1272 		  INTO		v_lcm_ship_line_id, v_unit_landed_cost
1273 		  FROM		rcv_shipment_lines
1274 		  WHERE		shipment_line_id = l_shipment_line_id;
1275 
1276 		  UPDATE	rcv_transactions_interface
1277 		  SET		lcm_shipment_line_id = v_lcm_ship_line_id,
1278 				    unit_landed_cost = v_unit_landed_cost
1279 		  WHERE		interface_transaction_id = l_interface_transaction_id
1280 		  AND		to_organization_id = l_to_org_id;
1281 
1282 	ELSE
1283 		  UPDATE	rcv_transactions_interface
1284 		  SET		processing_status_code = 'LC_PENDING',
1285                     PROCESSING_MODE_CODE = 'BATCH'
1286 		  WHERE		interface_transaction_id = l_interface_transaction_id
1287 		  AND		to_organization_id = l_to_org_id;
1288 
1289 	END IF;
1290  END IF;
1291 END IF;
1292 -- End for Bug 7440217
1293 
1294 BEGIN
1295     SELECT secondary_uom_code, secondary_unit_of_measure,
1296        secondary_quantity
1297        INTO t_sec_uom_code, t_sec_uom, t_sec_qty
1298        FROM rcv_transactions_interface
1299        WHERE interface_transaction_id = l_interface_transaction_id;
1300     print_debug('t_sec_uom_code ' || t_sec_uom_code, 1);
1301     print_debug('t_sec_uom ' || t_sec_uom, 1);
1302     print_debug('t_sec_qty ' || t_sec_qty, 1);
1303 EXCEPTION
1304    WHEN OTHERS THEN
1305 print_debug('other error ' || SQLERRM,1);
1306 END;
1307     IF (l_debug = 1) THEN
1308       print_debug('About exit insert_txn_interface: 5  after rcv_trx_interface_insert_pkg.insert_row '
1309         || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1310     END IF;
1311 
1312     RETURN l_interface_transaction_id;
1313   END insert_txn_interface;
1314 
1315   /****************************************************
1316   *  This procedure populates the data structure that
1317   *  stores received lot quantity.
1318   *  It retrieves this info  from wms_LPN_contents table
1319   ****************************************************/
1320   PROCEDURE populate_lot_rec(
1321     p_lot_number    IN  VARCHAR2
1322   , p_primary_qty   IN  NUMBER
1323   , p_txn_uom_code  IN  VARCHAR2
1324   , p_org_id            NUMBER
1325   , p_item_id       IN  NUMBER
1326   , p_secondary_quantity  IN NUMBER
1327   ) IS
1328     l_primary_uom VARCHAR2(3);
1329     l_txn_qty     NUMBER;
1330     l_counter     NUMBER;
1331     l_create_new  NUMBER      := 1;
1332     l_debug       NUMBER      := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1333     --OPM Convergence
1334     l_sec_txn_qty NUMBER;
1335   BEGIN
1336     IF (l_debug = 1) THEN
1337       print_debug('Enter populate_lot_rec: 1  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1338     END IF;
1339 
1340     SELECT primary_uom_code
1341       INTO l_primary_uom
1342       FROM mtl_system_items_kfv
1343      WHERE inventory_item_id = p_item_id
1344        AND organization_id = p_org_id;
1345 
1346     IF (l_debug = 1) THEN
1347       print_debug('populate_lot_rec: 2  p_primary_qty = ' || p_primary_qty || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
1348       print_debug('p_item_id = ' || p_item_id || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
1349       print_debug('l_primary_uom = ' || l_primary_uom || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
1350       print_debug('p_txn_uom_code = ' || p_txn_uom_code || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
1351     END IF;
1352 
1353     -- it is txn qty in primary uom passed from PackUnpack
1354        -- need to convert it to txn uom qty here
1355     IF (l_primary_uom <> p_txn_uom_code) THEN
1356        l_txn_qty := inv_rcv_cache.convert_qty
1357 	             (p_inventory_item_id    => p_item_id
1358 		      ,p_from_qty            => p_primary_qty
1359 		      ,p_from_uom_code       => l_primary_uom
1360 		      ,p_to_uom_code         => p_txn_uom_code);
1361      ELSE
1362        l_txn_qty := p_primary_qty;
1363     END IF;
1364 
1365     --OPM Convergence
1366     l_sec_txn_qty := p_secondary_quantity;
1367 
1368     FOR i IN 1 .. g_rcpt_lot_qty_rec_tb.COUNT LOOP
1369       IF g_rcpt_lot_qty_rec_tb(i).lot_number = p_lot_number THEN
1370         g_rcpt_lot_qty_rec_tb(i).txn_quantity := g_rcpt_lot_qty_rec_tb(i).txn_quantity + l_txn_qty;
1371         --OPM Convergence
1372         g_rcpt_lot_qty_rec_tb(i).sec_txn_quantity := g_rcpt_lot_qty_rec_tb(i).sec_txn_quantity + l_sec_txn_qty;
1373         l_create_new := 0;
1374         EXIT;
1375       END IF;
1376     END LOOP;
1377 
1378     IF l_create_new = 1 THEN
1379       l_counter := g_rcpt_lot_qty_rec_tb.COUNT + 1;
1380       g_rcpt_lot_qty_rec_tb(l_counter).txn_quantity := l_txn_qty;
1381       --OPM Convergence
1382       g_rcpt_lot_qty_rec_tb(l_counter).sec_txn_quantity := l_sec_txn_qty;
1383       g_rcpt_lot_qty_rec_tb(l_counter).lot_number := p_lot_number;
1384     END IF;
1385 
1386     IF (l_debug = 1) THEN
1387       print_debug('populate_lot_rec: 3  l_txn_qty = ' || l_txn_qty || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1388       print_debug('p_lot_number = ' || p_lot_number || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
1389     END IF;
1390   END populate_lot_rec;
1391 
1392   /****************************************************
1393   *  This procedure splits the input transaction qty
1394   *  based on received lot qty
1395   *  It retrieves this info  from global variable g_rcpt_lot_qty_rec_tb
1396   ****************************************************/
1397   PROCEDURE split_qty_for_lot(p_txn_qty IN NUMBER, p_splitted_qty_rec_tb OUT NOCOPY rcpt_lot_qty_rec_tb_tp) IS
1398     l_new_txn_quantity NUMBER; -- the quanity user wants to split
1399     l_new_counter      NUMBER := 0;
1400     l_debug            NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1401   BEGIN
1402     IF (l_debug = 1) THEN
1403       print_debug('Enter split_qty_for_lot: 1  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1404     END IF;
1405 
1406     l_new_txn_quantity := p_txn_qty;
1407 
1408     IF (l_debug = 1) THEN
1409       print_debug('split_qty_for_lot: 1.1 txn qty :' || l_new_txn_quantity, 4);
1410     END IF;
1411 
1412     FOR i IN 1 .. g_rcpt_lot_qty_rec_tb.COUNT LOOP -- Loop through all the transaction lines need to be splitted
1413       IF (l_debug = 1) THEN
1414         print_debug('split_qty_for_lot: 1.2 lot_number - ' || g_rcpt_lot_qty_rec_tb(i).lot_number, 4);
1415         print_debug('split_qty_for_lot: 1.3 lot_txn_qty - ' || g_rcpt_lot_qty_rec_tb(i).txn_quantity, 4);
1416       END IF;
1417 
1418       IF l_new_txn_quantity > g_rcpt_lot_qty_rec_tb(i).txn_quantity
1419          AND g_rcpt_lot_qty_rec_tb(i).txn_quantity > 0 THEN
1420         -- reduce input qty
1421         l_new_txn_quantity := l_new_txn_quantity - g_rcpt_lot_qty_rec_tb(i).txn_quantity;
1422         -- create a record in output table
1423         l_new_counter := l_new_counter + 1;
1424         p_splitted_qty_rec_tb(l_new_counter).txn_quantity := g_rcpt_lot_qty_rec_tb(i).txn_quantity;
1425         p_splitted_qty_rec_tb(l_new_counter).lot_number := g_rcpt_lot_qty_rec_tb(i).lot_number;
1426         -- set lot record table quantity
1427         g_rcpt_lot_qty_rec_tb(i).txn_quantity := 0;
1428       ELSIF l_new_txn_quantity < g_rcpt_lot_qty_rec_tb(i).txn_quantity THEN
1429         -- create a record in output table
1430         l_new_counter := l_new_counter + 1;
1431         p_splitted_qty_rec_tb(l_new_counter).txn_quantity := l_new_txn_quantity;
1432         p_splitted_qty_rec_tb(l_new_counter).lot_number := g_rcpt_lot_qty_rec_tb(i).lot_number;
1433         -- set lot record table quantity
1434         g_rcpt_lot_qty_rec_tb(i).txn_quantity := g_rcpt_lot_qty_rec_tb(i).txn_quantity - l_new_txn_quantity;
1435         -- exit loop
1436         EXIT;
1437       ELSIF l_new_txn_quantity = g_rcpt_lot_qty_rec_tb(i).txn_quantity THEN
1438         -- create a record in output table
1439         l_new_counter := l_new_counter + 1;
1440         p_splitted_qty_rec_tb(l_new_counter).txn_quantity := l_new_txn_quantity;
1441         p_splitted_qty_rec_tb(l_new_counter).lot_number := g_rcpt_lot_qty_rec_tb(i).lot_number;
1442         -- set lot record table quantity
1443         g_rcpt_lot_qty_rec_tb(i).txn_quantity := g_rcpt_lot_qty_rec_tb(i).txn_quantity - l_new_txn_quantity;
1444       END IF;
1445     END LOOP;
1446 
1447     IF (l_debug = 1) THEN
1448       print_debug('About Exit split_qty_for_lot: 2  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1449     END IF;
1450   END split_qty_for_lot;
1451 
1452   /** Bug #4147209 -
1453     * New procedure added to populate the attribute_category
1454     * and attributes 1-15 columns of the enter receipts record type
1455     * with the values passed from the Mobile Receipt UI
1456     */
1457   PROCEDURE set_attribute_vals (
1458       p_rcv_rcpt_rec         IN OUT NOCOPY  rcv_enter_receipts_rec_tp
1459     , p_attribute_category   IN             VARCHAR2  DEFAULT NULL
1460     , p_attribute1           IN             VARCHAR2  DEFAULT NULL
1461     , p_attribute2           IN             VARCHAR2  DEFAULT NULL
1462     , p_attribute3           IN             VARCHAR2  DEFAULT NULL
1463     , p_attribute4           IN             VARCHAR2  DEFAULT NULL
1464     , p_attribute5           IN             VARCHAR2  DEFAULT NULL
1465     , p_attribute6           IN             VARCHAR2  DEFAULT NULL
1466     , p_attribute7           IN             VARCHAR2  DEFAULT NULL
1467     , p_attribute8           IN             VARCHAR2  DEFAULT NULL
1468     , p_attribute9           IN             VARCHAR2  DEFAULT NULL
1469     , p_attribute10          IN             VARCHAR2  DEFAULT NULL
1470     , p_attribute11          IN             VARCHAR2  DEFAULT NULL
1471     , p_attribute12          IN             VARCHAR2  DEFAULT NULL
1472     , p_attribute13          IN             VARCHAR2  DEFAULT NULL
1473     , p_attribute14          IN             VARCHAR2  DEFAULT NULL
1474     , p_attribute15          IN             VARCHAR2  DEFAULT NULL) IS
1475   BEGIN
1476     p_rcv_rcpt_rec.attribute_category := p_attribute_category;
1477     p_rcv_rcpt_rec.attribute1         := p_attribute1;
1478     p_rcv_rcpt_rec.attribute2         := p_attribute2;
1479     p_rcv_rcpt_rec.attribute3         := p_attribute3;
1480     p_rcv_rcpt_rec.attribute4         := p_attribute4;
1481     p_rcv_rcpt_rec.attribute5         := p_attribute5;
1482     p_rcv_rcpt_rec.attribute6         := p_attribute6;
1483     p_rcv_rcpt_rec.attribute7         := p_attribute7;
1484     p_rcv_rcpt_rec.attribute8         := p_attribute8;
1485     p_rcv_rcpt_rec.attribute9         := p_attribute9;
1486     p_rcv_rcpt_rec.attribute10        := p_attribute10;
1487     p_rcv_rcpt_rec.attribute11        := p_attribute11;
1488     p_rcv_rcpt_rec.attribute12        := p_attribute12;
1489     p_rcv_rcpt_rec.attribute13        := p_attribute13;
1490     p_rcv_rcpt_rec.attribute14        := p_attribute14;
1491     p_rcv_rcpt_rec.attribute15        := p_attribute15;
1492   END set_attribute_vals;
1493 
1494 
1495   PROCEDURE create_po_rcpt_intf_rec(
1496     p_move_order_header_id   IN OUT NOCOPY  NUMBER
1497   , p_organization_id        IN             NUMBER
1498   , p_po_header_id           IN             NUMBER
1499   , p_po_release_number_id   IN             NUMBER
1500   , p_po_line_id             IN             NUMBER
1501   , p_item_id                IN             NUMBER
1502   , p_location_id            IN             NUMBER
1503   , p_rcv_qty                IN             NUMBER
1504   , p_rcv_uom                IN             VARCHAR2
1505   , p_rcv_uom_code           IN             VARCHAR2
1506   , p_source_type            IN             VARCHAR2
1507   , p_lpn_id                 IN             NUMBER
1508   , p_lot_control_code       IN             NUMBER
1509   , p_revision               IN             VARCHAR2
1510   , p_inspect                IN             NUMBER
1511   , x_status                 OUT NOCOPY     VARCHAR2
1512   , x_message                OUT NOCOPY     VARCHAR2
1513   , p_inv_item_id            IN             NUMBER    DEFAULT NULL
1514   , p_item_desc              IN             VARCHAR2  DEFAULT NULL
1515   , p_project_id             IN             NUMBER    DEFAULT NULL
1516   , p_task_id                IN             NUMBER    DEFAULT NULL
1517   , p_country_code           IN             VARCHAR2  DEFAULT NULL
1518   , p_rcv_subinventory_code  IN             VARCHAR2  DEFAULT NULL -- RCVLOCATORSSUPPORT
1519   , p_rcv_locator_id         IN             NUMBER    DEFAULT NULL
1520   , p_original_rti_id        IN             NUMBER    DEFAULT NULL  --Lot/Serial Support
1521   --OPM convergence
1522   , p_secondary_uom          IN             VARCHAR2 DEFAULT NULL
1523   , p_secondary_uom_code     IN             VARCHAR2 DEFAULT NULL
1524   , p_secondary_quantity          IN             NUMBER   DEFAULT NULL
1525   , p_attribute_category     IN             VARCHAR2  DEFAULT NULL  --Bug #4147209 - Added DFF columns
1526   , p_attribute1             IN             VARCHAR2  DEFAULT NULL
1527   , p_attribute2             IN             VARCHAR2  DEFAULT NULL
1528   , p_attribute3             IN             VARCHAR2  DEFAULT NULL
1529   , p_attribute4             IN             VARCHAR2  DEFAULT NULL
1530   , p_attribute5             IN             VARCHAR2  DEFAULT NULL
1531   , p_attribute6             IN             VARCHAR2  DEFAULT NULL
1532   , p_attribute7             IN             VARCHAR2  DEFAULT NULL
1533   , p_attribute8             IN             VARCHAR2  DEFAULT NULL
1534   , p_attribute9             IN             VARCHAR2  DEFAULT NULL
1535   , p_attribute10            IN             VARCHAR2  DEFAULT NULL
1536   , p_attribute11            IN             VARCHAR2  DEFAULT NULL
1537   , p_attribute12            IN             VARCHAR2  DEFAULT NULL
1538   , p_attribute13            IN             VARCHAR2  DEFAULT NULL
1539   , p_attribute14            IN             VARCHAR2  DEFAULT NULL
1540   , p_attribute15            IN             VARCHAR2  DEFAULT NULL
1541   ) IS
1542     l_rcpt_match_table_detail  inv_rcv_common_apis.cascaded_trans_tab_type; -- output for matching algorithm
1543     l_rcv_transaction_rec      rcv_transaction_rec_tp; -- rcv_transaction block
1544     l_interface_transaction_id NUMBER                                      := NULL;
1545     -- this is used to keep track of the id used to insert the row in rti
1546 
1547     l_transaction_type         VARCHAR2(20) := 'RECEIVE';
1548     l_total_primary_qty        NUMBER       := 0;
1549     l_return_status            VARCHAR2(1)  := fnd_api.g_ret_sts_success;
1550     l_msg_count                NUMBER;
1551     l_msg_data                 VARCHAR2(4000);
1552     l_progress                 VARCHAR2(10);
1553     l_err_message              VARCHAR2(100);
1554     l_temp_message             VARCHAR2(100);
1555     l_msg_prod                 VARCHAR2(5);
1556     l_group_id                 NUMBER;
1557     l_inspect                  NUMBER;
1558     l_qa_availability          VARCHAR2(30) := fnd_api.g_false;
1559     l_qa_routing_id            NUMBER       := -1;
1560     l_evaluation_result        VARCHAR2(20);
1561     -- bug 2797704
1562     -- changed the defaulting from null to the passed values
1563     l_project_id               NUMBER       := p_project_id;
1564     l_task_id                  NUMBER       := p_task_id;
1565     --Bug 4699085
1566     l_item_revision						 VARCHAR2(10);
1567 
1568     CURSOR l_curs_rcpt_detail(v_po_line_location_id NUMBER) IS
1569       SELECT 'N' line_chkbox
1570            , 'VENDOR' source_type_code
1571            , 'VENDOR' receipt_source_code
1572            , 'PO' order_type_code
1573            , '' order_type
1574            , poll.po_header_id po_header_id
1575            , poh.segment1 po_number
1576            , poll.po_line_id po_line_id
1577            , pol.line_num po_line_number
1578            , poll.line_location_id po_line_location_id
1579            , poll.shipment_num po_shipment_number
1580            , poll.po_release_id po_release_id
1581            , por.release_num po_release_number
1582            , TO_NUMBER(NULL) req_header_id
1583            , NULL req_number
1584            , TO_NUMBER(NULL) req_line_id
1585            , TO_NUMBER(NULL) req_line
1586            , TO_NUMBER(NULL) req_distribution_id
1587            --Passing the values as NULL   --Bug #3878174
1588            , TO_NUMBER(NULL) rcv_shipment_header_id
1589            , NULL rcv_shipment_number
1590            , TO_NUMBER(NULL) rcv_shipment_line_id
1591            , TO_NUMBER(NULL) rcv_line_number
1592            , TO_NUMBER(NULL) from_organization_id
1593 /*
1594            , poh.po_header_id rcv_shipment_header_id
1595            , poh.segment1 rcv_shipment_number
1596            , pol.po_line_id rcv_shipment_line_id
1597            , pol.line_num rcv_line_number
1598            , poh.po_header_id from_organization_id
1599 */
1600            , poll.ship_to_organization_id to_organization_id
1601            , poh.vendor_id vendor_id
1602            , '' SOURCE
1603            , poh.vendor_site_id vendor_site_id
1604            , '' outside_operation_flag
1605            , pol.item_id item_id
1606            , -- Bug 2073164
1607              NULL uom_code
1608 --         , pol.unit_meas_lookup_code primary_uom
1609 	   , msi.primary_unit_of_measure primary_uom /* Bug 5665041:Primary UOM should be taken from MSI*/
1610            , mum.uom_class primary_uom_class
1611            , NULL item_allowed_units_lookup_code
1612            , NULL item_locator_control
1613            , '' restrict_locators_code
1614            , '' restrict_subinventories_code
1615            , NULL shelf_life_code
1616            , NULL shelf_life_days
1617            , msi.serial_number_control_code serial_number_control_code
1618            , msi.lot_control_code lot_control_code
1619            , DECODE(msi.revision_qty_control_code, 1, 'N', 2, 'Y', 'N') item_rev_control_flag_to
1620            , NULL item_rev_control_flag_from
1621            , NULL item_number
1622            , pol.item_revision item_revision
1623            , pol.item_description item_description
1624            , pol.category_id item_category_id
1625            , '' hazard_class
1626            , '' un_number
1627            , pol.vendor_product_num vendor_item_number
1628            , poll.ship_to_location_id ship_to_location_id
1629            , '' ship_to_location
1630            , NULL packing_slip
1631            , poll.receiving_routing_id routing_id
1632            , '' routing_name
1633            , poll.need_by_date need_by_date
1634            , NVL(poll.promised_date, poll.need_by_date) expected_receipt_date
1635            , poll.quantity ordered_qty
1636            , pol.unit_meas_lookup_code ordered_uom
1637            , NULL ussgl_transaction_code
1638            , poll.government_context government_context
1639            , poll.inspection_required_flag inspection_required_flag
1640            , poll.receipt_required_flag receipt_required_flag
1641            , poll.enforce_ship_to_location_code enforce_ship_to_location_code
1642            , NVL(poll.price_override, pol.unit_price) unit_price
1643            , poh.currency_code currency_code
1644            , poh.rate_type currency_conversion_type
1645            , poh.rate_date currency_conversion_date
1646            , poh.rate currency_conversion_rate
1647            , poh.note_to_receiver note_to_receiver
1648            , NULL destination_type_code
1649            , TO_NUMBER(NULL) deliver_to_person_id
1650            , TO_NUMBER(NULL) deliver_to_location_id
1651            , NULL destination_subinventory
1652            , poll.attribute_category attribute_category
1653            , poll.attribute1 attribute1
1654            , poll.attribute2 attribute2
1655            , poll.attribute3 attribute3
1656            , poll.attribute4 attribute4
1657            , poll.attribute5 attribute5
1658            , poll.attribute6 attribute6
1659            , poll.attribute7 attribute7
1660            , poll.attribute8 attribute8
1661            , poll.attribute9 attribute9
1662            , poll.attribute10 attribute10
1663            , poll.attribute11 attribute11
1664            , poll.attribute12 attribute12
1665            , poll.attribute13 attribute13
1666            , poll.attribute14 attribute14
1667            , poll.attribute15 attribute15
1668            , poll.closed_code closed_code
1669            , NULL asn_type
1670            , NULL bill_of_lading
1671            , TO_DATE(NULL) shipped_date
1672            , NULL freight_carrier_code
1673            , NULL waybill_airbill_num
1674            , NULL freight_bill_num
1675            , NULL vendor_lot_num
1676            , NULL container_num
1677            , NULL truck_num
1678            , NULL bar_code_label
1679            , '' rate_type_display
1680            , poll.match_option match_option
1681            , poll.country_of_origin_code country_of_origin_code
1682            , TO_NUMBER(NULL) oe_order_header_id
1683            , TO_NUMBER(NULL) oe_order_num
1684            , TO_NUMBER(NULL) oe_order_line_id
1685            , TO_NUMBER(NULL) oe_order_line_num
1686            , TO_NUMBER(NULL) customer_id
1687            , TO_NUMBER(NULL) customer_site_id
1688            , NULL customer_item_num
1689            , NULL pll_note_to_receiver
1690            , --POLL.NOTE_TO_RECEIVER PLL_NOTE_TO_RECEIVER,
1691              NULL po_distribution_id
1692            , NULL qty_ordered
1693            , NULL wip_entity_id
1694            , NULL wip_operation_seq_num
1695            , NULL wip_resource_seq_num
1696            , NULL wip_repetitive_schedule_id
1697            , NULL wip_line_id
1698            , NULL bom_resource_id
1699            , '' destination_type
1700            , '' LOCATION
1701            , NULL currency_conversion_rate_pod
1702            , NULL currency_conversion_date_pod
1703            , NULL project_id
1704            , NULL task_id
1705            , pol.secondary_uom secondary_uom --OPM Convergence
1706            , NULL secondary_uom_code --OPM Convergence
1707            , pol.secondary_qty secondary_quantity --OPM Convergence* commented out temp
1708         FROM po_headers poh
1709             , po_line_locations poll
1710             , po_lines pol
1711             , po_releases por
1712             , mtl_system_items msi
1713             , mtl_units_of_measure mum
1714        WHERE poll.line_location_id = v_po_line_location_id
1715          AND poh.po_header_id = poll.po_header_id
1716          AND pol.po_line_id = poll.po_line_id
1717          AND poll.po_release_id = por.po_release_id(+)
1718          AND mum.unit_of_measure(+) = pol.unit_meas_lookup_code
1719          AND NVL(msi.organization_id, poll.ship_to_organization_id) = poll.ship_to_organization_id
1720          AND msi.inventory_item_id(+) = pol.item_id
1721          AND poll.line_location_id IN(
1722               SELECT pod.line_location_id
1723                 FROM po_distributions_all pod
1724                WHERE (
1725                       p_project_id IS NULL
1726                       OR(p_project_id = -9999
1727                          AND pod.project_id IS NULL) --bug#2669021
1728                       OR pod.project_id = p_project_id
1729                      )
1730                  AND(p_task_id IS NULL
1731                      OR pod.task_id = p_task_id)
1732                  AND pod.po_header_id = poll.po_header_id
1733                  AND pod.po_line_id = poll.po_line_id
1734                  AND pod.line_location_id = poll.line_location_id);
1735 
1736     l_rcv_rcpt_rec             rcv_enter_receipts_rec_tp;
1737     l_debug                    NUMBER       := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1738 
1739     --table to store all RTId, quantity and original_rti_id for lot/serial splits
1740     l_new_rti_info            inv_rcv_integration_apis.child_rec_tb_tp;
1741     l_split_lot_serial_ok     BOOLEAN;   --Return status of lot_serial_split API
1742     l_msni_count              NUMBER := 0;
1743     l_line_id NUMBER;
1744   BEGIN
1745     IF (l_debug = 1) THEN
1746       print_debug('Enter create_po_rcpt_intf_rec: 10   ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1747       print_debug(p_secondary_uom,1);
1748 print_debug(p_secondary_uom_code,1);
1749 print_debug(p_secondary_quantity,1);
1750     END IF;
1751 
1752     l_progress := '10';
1753     SAVEPOINT crt_po_rti_sp;
1754     x_status := fnd_api.g_ret_sts_success;
1755     l_split_lot_serial_ok := TRUE;
1756 
1757     -- query po_startup_value
1758     l_progress := '20';
1759 
1760     BEGIN
1761       inv_rcv_common_apis.init_startup_values(p_organization_id);
1762     EXCEPTION
1763       WHEN NO_DATA_FOUND THEN
1764         fnd_message.set_name('INV', 'INV_RCV_PARAM');
1765         fnd_msg_pub.ADD;
1766         RAISE fnd_api.g_exc_error;
1767     END;
1768 
1769     l_progress := '30';
1770 
1771     -- default header level non-DB items in rcv_transaction block
1772     -- and default other values need to be insert into RTI
1773     -- default l_group_id ? clear group id after done
1774     IF inv_rcv_common_apis.g_rcv_global_var.interface_group_id IS NULL THEN
1775       l_progress := '40';
1776 
1777       SELECT rcv_interface_groups_s.NEXTVAL
1778         INTO l_group_id
1779         FROM DUAL;
1780 
1781       l_progress := '50';
1782 
1783       IF (l_debug = 1) THEN
1784         print_debug(
1785              'Enter create_po_rcpt_intf_rec: 20 -  Create l_group_id - l_group_id = '
1786           || l_group_id
1787           || ' '
1788           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
1789         , 4
1790         );
1791       END IF;
1792 
1793       inv_rcv_common_apis.g_rcv_global_var.interface_group_id := l_group_id;
1794     ELSE
1795       l_group_id := inv_rcv_common_apis.g_rcv_global_var.interface_group_id;
1796 
1797       IF (l_debug = 1) THEN
1798         print_debug(
1799              'Enter create_po_rcpt_intf_rec: 30 -  l_group_id exists - l_group_id = '
1800           || l_group_id
1801           || ' '
1802           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
1803         , 4
1804         );
1805       END IF;
1806     END IF;
1807 
1808     -- initialize input record for matching algorithm
1809     g_rcpt_match_table_gross(g_receipt_detail_index).GROUP_ID := l_group_id;
1810     g_rcpt_match_table_gross(g_receipt_detail_index).transaction_type := 'RECEIVE';
1811     g_rcpt_match_table_gross(g_receipt_detail_index).quantity := p_rcv_qty;
1812     g_rcpt_match_table_gross(g_receipt_detail_index).unit_of_measure := p_rcv_uom;
1813     --OPM Convergence
1814    /* g_rcpt_match_table_gross(g_receipt_detail_index).secondary_quantity := p_secondary_quantity;
1815     g_rcpt_match_table_gross(g_receipt_detail_index).secondary_uom := p_secondary_uom;*/
1816 
1817     IF (l_debug = 1) THEN
1818       print_debug(
1819         'create_po_rcpt_intf_rec: 40-S - p_inv_item_id' || TO_CHAR(p_inv_item_id) || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
1820       , 4
1821       );
1822     END IF;
1823 
1824     IF p_inv_item_id IS NOT NULL THEN -- p_item_id has substitute item id
1825       g_rcpt_match_table_gross(g_receipt_detail_index).item_id := p_inv_item_id;
1826     ELSE
1827       IF p_item_id IS NOT NULL THEN
1828         g_rcpt_match_table_gross(g_receipt_detail_index).item_id := p_item_id;
1829       ELSE
1830         IF (l_debug = 1) THEN
1831           print_debug('create_po_rcpt_intf_rec: Item id is null - One time item', 4);
1832         END IF;
1833 
1834         g_rcpt_match_table_gross(g_receipt_detail_index).item_id := NULL;
1835         g_rcpt_match_table_gross(g_receipt_detail_index).item_desc := p_item_desc;
1836       END IF;
1837     END IF;
1838 
1839     g_rcpt_match_table_gross(g_receipt_detail_index).revision := p_revision;
1840     g_rcpt_match_table_gross(g_receipt_detail_index).po_header_id := p_po_header_id;
1841     g_rcpt_match_table_gross(g_receipt_detail_index).po_release_id := p_po_release_number_id;
1842     g_rcpt_match_table_gross(g_receipt_detail_index).po_line_id := p_po_line_id;
1843     g_rcpt_match_table_gross(g_receipt_detail_index).expected_receipt_date := SYSDATE; --?
1844     g_rcpt_match_table_gross(g_receipt_detail_index).ship_to_location_id := p_location_id; -- for tolerance checks in matching.
1845     g_rcpt_match_table_gross(g_receipt_detail_index).tax_amount := 0; -- ?
1846     g_rcpt_match_table_gross(g_receipt_detail_index).error_status := 'S'; -- ?
1847     g_rcpt_match_table_gross(g_receipt_detail_index).to_organization_id := p_organization_id;
1848     -- bug 2797704
1849     g_rcpt_match_table_gross(g_receipt_detail_index).project_id := p_project_id;
1850     g_rcpt_match_table_gross(g_receipt_detail_index).task_id := p_task_id;
1851     l_progress := '60';
1852 
1853     IF p_item_id IS NOT NULL THEN
1854       BEGIN
1855         SELECT primary_unit_of_measure
1856           INTO g_rcpt_match_table_gross(g_receipt_detail_index).primary_unit_of_measure
1857           FROM mtl_system_items
1858          WHERE mtl_system_items.inventory_item_id = p_item_id
1859            AND mtl_system_items.organization_id = p_organization_id;
1860       EXCEPTION
1861         WHEN OTHERS THEN
1862           IF (l_debug = 1) THEN
1863             print_debug('Primary_uom is null should not be null', 4);
1864           END IF;
1865 
1866           l_progress := '65';
1867           RAISE fnd_api.g_exc_error;
1868       END;
1869     ELSE
1870       g_rcpt_match_table_gross(g_receipt_detail_index).primary_unit_of_measure := NULL;
1871       --OPM Convergence..should this be unit_of_measure????
1872      -- g_rcpt_match_table_gross(g_receipt_detail_index).secondary_uom := NULL;
1873     END IF;
1874 
1875     l_progress := '70';
1876 
1877     IF (l_debug = 1) THEN
1878       print_debug('create_po_rcpt_intf_rec: 35 - p_inspect = '||p_inspect, 4);
1879     END IF;
1880 
1881     -- BUG 3325627: Pass inspection status to matching logic
1882     IF p_inspect IS NOT NULL AND p_inspect = 1 THEN
1883        g_rcpt_match_table_gross(g_receipt_detail_index).inspection_status_code := 'Y';
1884      ELSE
1885        g_rcpt_match_table_gross(g_receipt_detail_index).inspection_status_code := 'N';
1886     END IF;
1887 
1888     IF (l_debug = 1) THEN
1889       print_debug('create_po_rcpt_intf_rec: 40 - before matching  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
1890     END IF;
1891 
1892     inv_rcv_txn_interface.matching_logic(
1893       x_return_status          => l_return_status
1894     , --?
1895       x_msg_count              => l_msg_count
1896     , x_msg_data               => l_msg_data
1897     , x_cascaded_table         => g_rcpt_match_table_gross
1898     , n                        => g_receipt_detail_index
1899     , temp_cascaded_table      => l_rcpt_match_table_detail
1900     , p_receipt_num            => NULL
1901     , p_shipment_header_id     => NULL
1902     , p_lpn_id                 => NULL
1903     );
1904 
1905     IF (l_debug = 1) THEN
1906       print_debug('create_po_rcpt_intf_rec: 50 - after matching  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
1907       print_debug('create_po_rcpt_intf_rec: 50.1 - after matching  l_return_status = ' || l_return_status, 4);
1908       print_debug('create_po_rcpt_intf_rec: 50.2 - after matching  l_msg_count = ' || l_msg_count, 4);
1909       print_debug('create_po_rcpt_intf_rec: 50.3 - after matching  l_msg_data = ' || l_msg_data, 4);
1910     END IF;
1911 
1912     -- x_status is not successful if there is any execution error in matching.
1913     IF l_return_status = fnd_api.g_ret_sts_error THEN
1914       fnd_message.set_name('INV', 'INV_RCV_MATCH_ERROR');
1915       fnd_msg_pub.ADD;
1916 
1917       IF (l_debug = 1) THEN
1918         print_debug('create_po_rcpt_intf_rec 60.1: error calling matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1919       END IF;
1920 
1921       RAISE fnd_api.g_exc_error;
1922     END IF;
1923 
1924     IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
1925       fnd_message.set_name('INV', 'INV_RCV_MATCH_ERROR');
1926       fnd_msg_pub.ADD;
1927 
1928       IF (l_debug = 1) THEN
1929         print_debug('Exiting create_po_rcpt_intf_rec 60.2: Unexpect error calling matching'
1930           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
1931         , 1);
1932       END IF;
1933 
1934       RAISE fnd_api.g_exc_unexpected_error;
1935     END IF;
1936 
1937     IF g_rcpt_match_table_gross(g_receipt_detail_index).error_status = 'E' THEN
1938       l_err_message := g_rcpt_match_table_gross(g_receipt_detail_index).error_message;
1939       fnd_message.set_name('INV', l_err_message);
1940       fnd_msg_pub.ADD;
1941 
1942       IF (l_debug = 1) THEN
1943         print_debug('create_po_rcpt_intf_rec 70: error calling matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
1944       END IF;
1945 
1946       RAISE fnd_api.g_exc_error;
1947     END IF;
1948 
1949     l_err_message := '@@@';
1950 
1951     FOR i IN g_receipt_detail_index ..(g_receipt_detail_index + l_rcpt_match_table_detail.COUNT - 1) LOOP
1952       IF l_rcpt_match_table_detail(i - g_receipt_detail_index + 1).error_status = 'W' THEN
1953         x_status := 'W';
1954         l_temp_message := l_rcpt_match_table_detail(i - g_receipt_detail_index + 1).error_message;
1955 
1956         IF l_temp_message IS NULL THEN
1957           l_err_message := 'INV_RCV_GEN_TOLERANCE_EXCEED';
1958           l_msg_prod := 'INV';
1959           EXIT;
1960         END IF;
1961 
1962         IF l_err_message = '@@@' THEN
1963           l_err_message := l_temp_message;
1964           l_msg_prod := 'INV';
1965         ELSIF l_temp_message <> l_err_message THEN
1966           l_msg_prod := 'INV';
1967           l_err_message := 'INV_RCV_GEN_TOLERANCE_EXCEED';
1968           EXIT;
1969         END IF;
1970       END IF;
1971     END LOOP;
1972 
1973     IF l_err_message <> '@@@' THEN
1974       fnd_message.set_name(l_msg_prod, l_err_message);
1975       fnd_msg_pub.ADD;
1976 
1977       IF (l_debug = 1) THEN
1978         print_debug(
1979              'create_po_rcpt_intf_rec 80: adding tolerance message - l_msg_prod = '
1980           || l_msg_prod
1981           || ' l_err_message = '
1982           || l_err_message
1983           || ' '
1984           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
1985         , 1
1986         );
1987       END IF;
1988     END IF;
1989 
1990     -- load the matching algorithm result into input data structure
1991 
1992     -- based on return from matching algorithm,
1993     -- determine which line in rcv_transaction block to be inserted into RTI
1994 
1995 
1996     IF (l_debug = 1) THEN
1997       print_debug('create_po_rcpt_intf_rec: 90 - before macthing result loop  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
1998     END IF;
1999 
2000     -- loop through results returned by matching algorithm
2001     FOR match_result_count IN 1 .. l_rcpt_match_table_detail.COUNT LOOP
2002       l_progress := 72;
2003 
2004       IF (l_debug = 1) THEN
2005         print_debug(
2006              'create_po_rcpt_intf_rec: 90.1 - after matching  po_line_location_id = '
2007           || l_rcpt_match_table_detail(match_result_count).po_line_location_id
2008         , 4
2009         );
2010         print_debug(
2011           'create_po_rcpt_intf_rec: 90.2 - after matching  txn_quantity = '
2012           || l_rcpt_match_table_detail(match_result_count).quantity
2013         , 4
2014         );
2015 
2016       END IF;
2017 
2018       OPEN l_curs_rcpt_detail(l_rcpt_match_table_detail(match_result_count).po_line_location_id);
2019       l_progress := 74;
2020       FETCH l_curs_rcpt_detail INTO l_rcv_rcpt_rec;
2021       -- Earlier item_id was filled with PO Line Item ID if the parameter p_inv_item_id
2022       -- is not null, so that matching logic finds shipments. Now, in order to actually
2023       -- insert RTI, replace item_id with a new value which is nothing but the substitute
2024       -- item.
2025       l_rcv_rcpt_rec.item_id := p_item_id;
2026       l_progress := 76;
2027       CLOSE l_curs_rcpt_detail;
2028       l_progress := 78;
2029       --Bug 6978466 Substitute Value should be there when we are doing substitute receipts through mobile.
2030       IF p_inv_item_id IS NOT NULL THEN
2031          l_rcv_transaction_rec.substitute_receipt:='SUBSTITUTE';
2032       END IF;
2033       --End of 6978466
2034 
2035       l_rcv_transaction_rec.po_line_location_id := l_rcpt_match_table_detail(match_result_count).po_line_location_id;
2036       -- update following fields from matching algorithm return value
2037       l_rcv_transaction_rec.transaction_qty := l_rcpt_match_table_detail(match_result_count).quantity;
2038       l_rcv_transaction_rec.transaction_uom := l_rcpt_match_table_detail(match_result_count).unit_of_measure;
2039       l_rcv_transaction_rec.primary_quantity := l_rcpt_match_table_detail(match_result_count).primary_quantity;
2040       l_rcv_transaction_rec.primary_uom := l_rcpt_match_table_detail(match_result_count).primary_unit_of_measure;
2041       --OPM Convergence
2042       --l_rcv_transaction_rec.secondary_quantity := l_rcpt_match_table_detail(match_result_count).secondary_quantity;
2043        l_rcv_transaction_rec.secondary_quantity := (l_rcpt_match_table_detail(match_result_count).quantity/p_rcv_qty) * p_secondary_quantity;
2044        l_rcv_transaction_rec.secondary_uom := p_secondary_uom; --OPM Convergence
2045        l_rcv_transaction_rec.secondary_uom_code := p_secondary_uom_code; --OPM Convergence
2046     print_debug(l_rcv_transaction_rec.secondary_quantity,1);
2047     print_debug( l_rcv_transaction_rec.secondary_uom,1);
2048     print_debug(l_rcv_transaction_rec.secondary_uom_code,1);
2049 
2050     l_rcv_transaction_rec.destination_subinventory := p_rcv_subinventory_code;
2051     l_rcv_transaction_rec.locator_id := p_rcv_locator_id;
2052 
2053 
2054     l_rcv_transaction_rec.transfer_lpn_id := p_lpn_id;
2055 
2056       l_rcv_transaction_rec.item_revision := p_revision;
2057       l_total_primary_qty := l_total_primary_qty + l_rcv_transaction_rec.primary_quantity;
2058       -- following fileds can have distribution level values
2059       -- therefore they are set here instead of in the common insert code
2060       l_rcv_transaction_rec.ordered_qty := l_rcv_rcpt_rec.ordered_qty;
2061       --Bug 2073164
2062       l_rcv_rcpt_rec.uom_code := p_rcv_uom_code;
2063       l_rcv_rcpt_rec.secondary_uom_code := p_secondary_uom_code;--OPM Convergence
2064       print_debug('l_rcv_rcpt_rec.secondary_uom_code ' || l_rcv_rcpt_rec.secondary_uom_code,4);
2065       print_debug('l_rcv_rcpt_rec.secondary_uom ' || l_rcv_rcpt_rec.secondary_uom,4);
2066 
2067       IF (l_debug = 1) THEN
2068         print_debug('create_po_rcpt_intf_rec: 100 - within cursor loop - before insert RTI  '
2069           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
2070         , 4);
2071       END IF;
2072 
2073       --Begin bug 4699085
2074       --If the item is not revision controlled ie l_rcv_rcpt_rec.item_rev_control_flag_to = 'N'
2075       --and l_rcv_transaction_rec.item_revision is null, ie p_revision is passed NULL to this
2076       --API, then check if there is a item revision stamped on the po lines table and use that
2077       --revision to pass to QA skip lot API and to the interface record created in RTI to
2078       --process the PO receipt.
2079       IF (l_debug = 1) THEN
2080         print_debug('create_po_rcpt_intf_rec: 100.1 l_rcv_rcpt_rec.item_rev_control_flag_to='||l_rcv_rcpt_rec.item_rev_control_flag_to, 4);
2081         print_debug('create_po_rcpt_intf_rec: 100.2 l_rcv_transaction_rec.item_revision='||l_rcv_transaction_rec.item_revision, 4);
2082       END IF;
2083 
2084       IF ((l_rcv_rcpt_rec.item_rev_control_flag_to = 'N') AND
2085           (l_rcv_transaction_rec.item_revision IS NULL)) THEN
2086 
2087         BEGIN
2088           SELECT nvl(item_revision, '@@@@')
2089           INTO l_item_revision
2090           FROM po_lines_all
2091           WHERE po_line_id = l_rcv_rcpt_rec.po_line_id;
2092 
2093           IF (l_debug = 1) THEN
2094                   print_debug('create_po_rcpt_intf_rec: 100.5 l_item_revision='||l_item_revision, 4);
2095           END IF;
2096         EXCEPTION
2097           WHEN NO_DATA_FOUND THEN
2098             l_item_revision := '@@@@';
2099           WHEN OTHERS THEN
2100             l_item_revision := '@@@@';
2101         END;
2102 
2103         IF (l_debug = 1) THEN
2104           print_debug('create_po_rcpt_intf_rec: 100.6 l_item_revision='||l_item_revision, 4);
2105         END IF;
2106 
2107         IF (l_item_revision <> '@@@@') THEN
2108           l_rcv_transaction_rec.item_revision := l_item_revision;
2109         END IF;
2110 
2111         IF (l_debug = 1) THEN
2112           print_debug('create_po_rcpt_intf_rec: 100.7 l_rcv_transaction_rec.item_revision='||l_rcv_transaction_rec.item_revision, 4);
2113         END IF;
2114       END IF;
2115       --End bug 4699085
2116 
2117       l_progress := '80';
2118 
2119       -- check if the routing_id = 2 (Inspection required) then call
2120       -- QA_SKIPLOT_RCV_GRP.CHECK_AVAILABILITY
2121       -- to check if Quaility Skip Lot function is available for current org.
2122       -- returns fnd_api.g_true/false
2123       IF l_rcv_rcpt_rec.routing_id = 2 THEN
2124         BEGIN
2125           l_progress := '81';
2126           qa_skiplot_rcv_grp.check_availability(
2127             p_api_version          => 1.0
2128           , p_init_msg_list        => fnd_api.g_false
2129           , p_commit               => fnd_api.g_false
2130           , p_validation_level     => fnd_api.g_valid_level_full
2131           , p_organization_id      => p_organization_id
2132           , x_qa_availability      => l_qa_availability
2133           , x_return_status        => l_return_status
2134           , x_msg_count            => l_msg_count
2135           , x_msg_data             => l_msg_data
2136           );
2137           l_progress := '82';
2138         EXCEPTION
2139           WHEN OTHERS THEN
2140             IF (l_debug = 1) THEN
2141               print_debug(
2142                    'create_po_rcpt_intf_rec: 102 - Exception in calling QA_SKIPLOT_RCV_GRP.CHECK_AVAILABILITY'
2143                 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
2144               , 4
2145               );
2146             END IF;
2147 
2148             RAISE fnd_api.g_exc_error;
2149         END;
2150 
2151         IF NVL(l_return_status, fnd_api.g_ret_sts_success) = fnd_api.g_ret_sts_success THEN
2152           -- If the Quaility Skip Lot function is available, then gets the interface transaction id and
2153           -- calls QA_SKIPLOT_RCV_GRP.EVALUATE_LOT
2154           -- returns 'Standard' or 'Inspect' to x_evaluation_result.
2155           IF NVL(l_qa_availability, fnd_api.g_false) = fnd_api.g_true THEN
2156             l_qa_routing_id := 2;
2157 
2158             BEGIN
2159               SELECT rcv_transactions_interface_s.NEXTVAL
2160                 INTO l_rcv_transaction_rec.interface_transaction_id
2161                 FROM DUAL;
2162 
2163               l_progress := '83';
2164               /*
2165                  We get the project /task from create_std..rec itself and it in turns
2166                  gets it from java code (rcptflistener)
2167                       get_project_task(p_po_line_location_id   =>  l_rcv_transaction_rec.po_line_location_id,
2168                              p_oe_order_line_id      =>  NULL,
2169                              x_project_id            =>  l_project_id,
2170                              x_task_id               =>  l_task_id);
2171               */
2172               l_project_id := p_project_id;
2173               l_task_id := p_task_id;
2174 
2175               IF l_project_id = '' THEN
2176                 l_project_id := NULL;
2177               END IF;
2178 
2179               IF l_task_id = '' THEN
2180                 l_task_id := NULL;
2181               END IF;
2182 
2183               --Begin bug 4699085
2184               --Added following debug messages
2185               IF (l_debug = 1) THEN
2186               	print_debug('create_po_rcpt_intf_rec 84 calling qa_skiplot_rcv_grp.evaluate_lot', 4);
2187               	print_debug('create_po_rcpt_intf_rec 84 with l_rcv_rcpt_rec.item_revision='||l_rcv_rcpt_rec.item_revision, 4);
2188               END IF;
2189               --End bug 4699085
2190 
2191               l_progress := '84';
2192               qa_skiplot_rcv_grp.evaluate_lot(
2193                 p_api_version             => 1.0
2194               , p_init_msg_list           => fnd_api.g_false
2195               , p_commit                  => fnd_api.g_false
2196               , p_validation_level        => fnd_api.g_valid_level_full
2197               , p_interface_txn_id        => l_rcv_transaction_rec.interface_transaction_id
2198               , p_organization_id         => p_organization_id
2199               , p_vendor_id               => l_rcv_rcpt_rec.vendor_id
2200               , p_vendor_site_id          => l_rcv_rcpt_rec.vendor_site_id
2201               , p_item_id                 => l_rcv_rcpt_rec.item_id
2202               , p_item_revision           => l_rcv_rcpt_rec.item_revision
2203               , p_item_category_id        => l_rcv_rcpt_rec.item_category_id
2204               , p_project_id              => l_project_id
2205               , p_task_id                 => l_task_id
2206               , p_manufacturer_id         => NULL
2207               , p_source_inspected        => NULL
2208               , p_receipt_qty             => l_rcv_transaction_rec.transaction_qty
2209               , p_receipt_date            => SYSDATE
2210               , p_primary_uom             => l_rcv_transaction_rec.primary_uom
2211               , p_transaction_uom         => l_rcv_transaction_rec.transaction_uom
2212               , p_po_header_id            => l_rcv_rcpt_rec.po_header_id
2213               , p_po_line_id              => l_rcv_rcpt_rec.po_line_id
2214               , p_po_line_location_id     => l_rcv_transaction_rec.po_line_location_id
2215               , p_po_distribution_id      => l_rcv_rcpt_rec.po_distribution_id
2216               , p_lpn_id                  => p_lpn_id
2217               , p_wms_flag                => 'Y'
2218               , x_evaluation_result       => l_evaluation_result
2219               , x_return_status           => l_return_status
2220               , x_msg_count               => l_msg_count
2221               , x_msg_data                => l_msg_data
2222               );
2223 
2224               IF l_return_status = fnd_api.g_ret_sts_error THEN
2225                 IF (l_debug = 1) THEN
2226                   print_debug('create_po_rcpt_intf_rec 84.1: QA CALL RAISE  FND_API.G_EXC_ERROR;' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2227                 END IF;
2228 
2229                 RAISE fnd_api.g_exc_error;
2230               END IF;
2231 
2232               IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2233                 IF (l_debug = 1) THEN
2234                   print_debug('create_po_rcpt_intf_rec 135.2: QA CALL RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'|| TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2235                 END IF;
2236                 RAISE fnd_api.g_exc_unexpected_error;
2237               END IF;
2238 
2239               -- If QA_SKIPLOT_RCV_GRP returns 'Standard', sets the routing id to 1.
2240               -- If QA_SKIPLOT_RCV_GRP returns 'Inspect', leaves the routing id as 2.
2241               IF l_evaluation_result = 'STANDARD' THEN
2242                 l_rcv_rcpt_rec.routing_id := 1;
2243                 l_qa_routing_id := 1;
2244               END IF;
2245             EXCEPTION
2246               WHEN OTHERS THEN
2247                 IF (l_debug = 1) THEN
2248                   print_debug('create_po_rcpt_intf_rec: 104 - Exception in calling QA_SKIPLOT_RCV_GRP.EVALUATE_LOT'|| TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2249                 END IF;
2250                 RAISE fnd_api.g_exc_error;
2251             END;
2252           END IF;
2253         END IF;
2254       END IF;
2255 
2256       l_return_status := fnd_api.g_ret_sts_success;
2257       l_progress := '85';
2258 
2259       IF p_country_code IS NOT NULL THEN
2260         l_rcv_rcpt_rec.country_of_origin_code := p_country_code;
2261       END IF;
2262 
2263       --Bug #4147209 - Populate the record type with the DFF attribute category
2264       --and segment values passed from the mobile UI
2265       set_attribute_vals(
2266           p_rcv_rcpt_rec        =>  l_rcv_rcpt_rec
2267         , p_attribute_category  => p_attribute_category
2268         , p_attribute1          => p_attribute1
2269         , p_attribute2          => p_attribute2
2270         , p_attribute3          => p_attribute3
2271         , p_attribute4          => p_attribute4
2272         , p_attribute5          => p_attribute5
2273         , p_attribute6          => p_attribute6
2274         , p_attribute7          => p_attribute7
2275         , p_attribute8          => p_attribute8
2276         , p_attribute9          => p_attribute9
2277         , p_attribute10         => p_attribute10
2278         , p_attribute11         => p_attribute11
2279         , p_attribute12         => p_attribute12
2280         , p_attribute13         => p_attribute13
2281         , p_attribute14         => p_attribute14
2282         , p_attribute15         => p_attribute15);
2283 
2284       l_interface_transaction_id :=
2285         insert_txn_interface(
2286           l_rcv_transaction_rec
2287         , l_rcv_rcpt_rec
2288         , l_group_id
2289         , l_transaction_type
2290         , p_organization_id
2291         , p_location_id
2292         , p_source_type
2293         , l_qa_routing_id
2294         , p_project_id
2295         , p_task_id
2296         );
2297       l_progress := '90';
2298 
2299       IF (l_debug = 1) THEN
2300         print_debug('create_po_rcpt_intf_rec: 110 - within cursor loop - after insert RTI '|| TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2301       END IF;
2302 
2303       IF (l_debug = 1) THEN
2304 	 print_debug('create_po_rcpt_intf_rec 130.5: INV J and PO J are installed. No Move Order creation from UI', 4);
2305       END IF;
2306       /* Populate the table to store the information of the RTIs created*/
2307       l_new_rti_info(match_result_count).orig_interface_trx_id := p_original_rti_id;
2308       l_new_rti_info(match_result_count).new_interface_trx_id := l_interface_transaction_id;
2309       l_new_rti_info(match_result_count).quantity := l_rcv_transaction_rec.transaction_qty;
2310     END LOOP;   -- loop through results returned by matching algorithm
2311 
2312     --BUG 3326408,3346758,3405320
2313     --If there are any serials confirmed from the UI for an item that is
2314     --lot controlled and serial control dynamic at SO issue,
2315     --do not NULL out serial_transaction_temp_id. In other cases,
2316     --NULL OUT serial_temp_id so that split_lot_serial does not look at MSNI
2317     IF (l_rcv_rcpt_rec.lot_control_code = 2 AND
2318 	l_rcv_rcpt_rec.serial_number_control_code IN (1,6)) THEN
2319        IF (l_debug = 1) THEN
2320           print_debug('create_po_rcpt_intf_rec 130.6: serial_control_code IS 6, need TO NULL OUT mtli', 4);
2321        END IF;
2322        BEGIN
2323           UPDATE mtl_transaction_lots_interface
2324 	    SET  serial_transaction_temp_id = NULL
2325 	    WHERE product_transaction_id = p_original_rti_id
2326 	    AND   product_code = 'RCV';
2327        EXCEPTION
2328           WHEN OTHERS THEN
2329 	     IF (l_debug = 1) THEN
2330 		print_debug('create_po_rcpt_intf_rec 130.7: Error nulling serial temp id OF MTLI', 4);
2331 	     END IF;
2332        END ;
2333     END IF;--IF (l_rcv_rcpt_rec.serial_number_control_code = 6) THEN
2334 
2335     l_split_lot_serial_ok := inv_rcv_integration_apis.split_lot_serial(
2336               p_api_version   => 1.0
2337             , p_init_msg_lst  => FND_API.G_FALSE
2338             , x_return_status =>  l_return_status
2339             , x_msg_count     =>  l_msg_count
2340             , x_msg_data      =>  x_message
2341             , p_new_rti_info  =>  l_new_rti_info);
2342     IF ( NOT l_split_lot_serial_ok) THEN
2343 	 IF (l_debug = 1) THEN
2344 	    print_debug('create_po_rcpt_intf_rec 132: Failure in split_lot_serial', 4);
2345 	 END IF;
2346 	 RAISE FND_API.G_EXC_ERROR;
2347     END IF;
2348 
2349     IF (l_debug = 1) THEN
2350        print_debug('create_po_rcpt_intf_rec 133: Call split_lot_serial is OK', 4);
2351     END IF;
2352 
2353     IF l_curs_rcpt_detail%ISOPEN THEN
2354       CLOSE l_curs_rcpt_detail;
2355     END IF;
2356 
2357     -- append index in input table where the line to be detailed needs to be inserted
2358     --g_receipt_detail_index := l_rcpt_match_table_detail.COUNT + g_receipt_detail_index;
2359 
2360     -- clear the lot/qty data structure
2361     g_rcpt_lot_qty_rec_tb.DELETE;
2362     l_progress := '90';
2363 
2364     IF p_item_id IS NOT NULL THEN
2365       inv_rcv_common_apis.do_check(
2366         p_organization_id         => p_organization_id
2367       , p_inventory_item_id       => p_item_id
2368       , p_transaction_type_id     => 18
2369       , p_primary_quantity        => l_total_primary_qty
2370       , x_return_status           => l_return_status
2371       , x_msg_count               => l_msg_count
2372       , x_msg_data                => x_message
2373       );
2374     END IF;
2375 
2376     IF l_return_status <> fnd_api.g_ret_sts_success THEN
2377       x_status := l_return_status;
2378     END IF;
2379 
2380     l_progress := '100';
2381 
2382     IF (l_debug = 1) THEN
2383       print_debug('About exiting create_po_rcpt_intf_rec: 140 - after cursor loop  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2384     END IF;
2385   EXCEPTION
2386     WHEN fnd_api.g_exc_error THEN
2387       ROLLBACK TO crt_po_rti_sp;
2388       x_status := fnd_api.g_ret_sts_error;
2389 
2390       IF l_curs_rcpt_detail%ISOPEN THEN
2391         CLOSE l_curs_rcpt_detail;
2392       END IF;
2393 
2394       fnd_msg_pub.count_and_get(
2395           p_encoded => fnd_api.g_false
2396         , p_count => l_msg_count
2397         , p_data => x_message);
2398 
2399       IF (l_debug = 1) THEN
2400         print_debug('create_po_rcpt_intf_rec:  FND_API.g_exc_error ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2401       END IF;
2402     WHEN fnd_api.g_exc_unexpected_error THEN
2403       ROLLBACK TO crt_po_rti_sp;
2404       x_status := fnd_api.g_ret_sts_unexp_error;
2405 
2406       IF l_curs_rcpt_detail%ISOPEN THEN
2407         CLOSE l_curs_rcpt_detail;
2408       END IF;
2409 
2410       fnd_msg_pub.count_and_get(
2411           p_encoded => fnd_api.g_false
2412         , p_count => l_msg_count
2413         , p_data => x_message);
2414 
2415       IF (l_debug = 1) THEN
2416         print_debug('create_po_rcpt_intf_rec: fnd_api.g_exc_unexpected_error ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2417       END IF;
2418     WHEN OTHERS THEN
2419       ROLLBACK TO crt_po_rti_sp;
2420       x_status := fnd_api.g_ret_sts_unexp_error;
2421 
2422       IF l_curs_rcpt_detail%ISOPEN THEN
2423         CLOSE l_curs_rcpt_detail;
2424       END IF;
2425 
2426       IF SQLCODE IS NOT NULL THEN
2427         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.create_po_rcpt_intf_rec', l_progress, SQLCODE);
2428       END IF;
2429 
2430       fnd_msg_pub.count_and_get(
2431           p_encoded => fnd_api.g_false
2432         , p_count => l_msg_count
2433         , p_data => x_message);
2434 
2435       IF (l_debug = 1) THEN
2436         print_debug('create_po_rcpt_intf_rec: Other exception ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2437       END IF;
2438   END create_po_rcpt_intf_rec;
2439 
2440   -- Added one more parameter p_from_lpn_id
2441   PROCEDURE create_intship_rcpt_intf_rec(
2442     p_move_order_header_id   IN OUT NOCOPY  NUMBER
2443   , p_organization_id        IN             NUMBER
2444   , p_shipment_header_id     IN             NUMBER
2445   , p_req_header_id          IN             NUMBER
2446   , p_item_id                IN             NUMBER
2447   , p_location_id            IN             NUMBER
2448   , p_rcv_qty                IN             NUMBER
2449   , p_rcv_uom                IN             VARCHAR2
2450   , p_rcv_uom_code           IN             VARCHAR2
2451   , p_source_type            IN             VARCHAR2
2452   , p_from_lpn_id            IN             NUMBER
2453   , p_lpn_id                 IN             NUMBER
2454   , p_lot_control_code       IN             NUMBER
2455   , p_revision               IN             VARCHAR2
2456   , p_inspect                IN             NUMBER
2457   , x_status                 OUT NOCOPY     VARCHAR2
2458   , x_message                OUT NOCOPY     VARCHAR2
2459   , p_project_id             IN             NUMBER    DEFAULT NULL
2460   , p_task_id                IN             NUMBER    DEFAULT NULL
2461   , p_country_code           IN             VARCHAR2  DEFAULT NULL
2462   , p_rcv_subinventory_code  IN             VARCHAR2  DEFAULT NULL -- RCVLOCATORSSUPPORT
2463   , p_rcv_locator_id         IN             NUMBER    DEFAULT NULL
2464   , p_original_rti_id        IN             NUMBER    DEFAULT NULL  --Lot/Serial Support
2465    , p_secondary_uom          IN             VARCHAR2  DEFAULT NULL-- OPM Convergence
2466   , p_secondary_uom_code     IN             VARCHAR2  DEFAULT NULL-- OPM Convergence
2467   , p_secondary_quantity          IN             NUMBER    DEFAULT NULL --OPM Convergence
2468   , p_attribute_category     IN             VARCHAR2  DEFAULT NULL  --Bug #4147209 - Added DFF cols
2469   , p_attribute1             IN             VARCHAR2  DEFAULT NULL
2470   , p_attribute2             IN             VARCHAR2  DEFAULT NULL
2471   , p_attribute3             IN             VARCHAR2  DEFAULT NULL
2472   , p_attribute4             IN             VARCHAR2  DEFAULT NULL
2473   , p_attribute5             IN             VARCHAR2  DEFAULT NULL
2474   , p_attribute6             IN             VARCHAR2  DEFAULT NULL
2475   , p_attribute7             IN             VARCHAR2  DEFAULT NULL
2476   , p_attribute8             IN             VARCHAR2  DEFAULT NULL
2477   , p_attribute9             IN             VARCHAR2  DEFAULT NULL
2478   , p_attribute10            IN             VARCHAR2  DEFAULT NULL
2479   , p_attribute11            IN             VARCHAR2  DEFAULT NULL
2480   , p_attribute12            IN             VARCHAR2  DEFAULT NULL
2481   , p_attribute13            IN             VARCHAR2  DEFAULT NULL
2482   , p_attribute14            IN             VARCHAR2  DEFAULT NULL
2483   , p_attribute15            IN             VARCHAR2  DEFAULT NULL
2484   ) IS
2485     l_rcpt_match_table_detail  inv_rcv_common_apis.cascaded_trans_tab_type; -- output for matching algorithm
2486     l_rcv_transaction_rec      rcv_transaction_rec_tp; -- rcv_transaction block
2487     l_interface_transaction_id NUMBER       := NULL;
2488     -- this is used to keep track of the id used to insert the row in rti
2489 
2490     l_transaction_type         VARCHAR2(20) := 'RECEIVE';
2491     l_total_primary_qty        NUMBER       := 0;
2492     l_return_status            VARCHAR2(1)  := fnd_api.g_ret_sts_success;
2493     l_msg_count                NUMBER;
2494     l_msg_data                 VARCHAR2(4000);
2495     l_progress                 VARCHAR2(10);
2496     l_err_message              VARCHAR2(100);
2497     l_temp_message             VARCHAR2(100);
2498     l_msg_prod                 VARCHAR2(5);
2499     l_group_id                 NUMBER;
2500     l_rcv_rcpt_rec             rcv_enter_receipts_rec_tp;
2501     l_inspect                  NUMBER;
2502     l_receipt_num              VARCHAR2(30);
2503 
2504     CURSOR l_curs_rcpt_detail(v_shipment_line_id NUMBER) IS
2505       SELECT 'N' line_chkbox
2506            , 'INTERNAL' source_type_code
2507            , DECODE(rsl.source_document_code, 'INVENTORY', 'INVENTORY', 'REQ', 'INTERNAL ORDER') receipt_source_code
2508            , rsl.source_document_code order_type_code
2509            , '' order_type
2510            --Passing as NULL for the columns for which value is not known.  --Bug #3878174
2511            , TO_NUMBER(NULL) po_header_id
2512            , NULL po_number
2513            , TO_NUMBER(NULL) po_line_id
2514            , TO_NUMBER(NULL) po_line_number
2515            , TO_NUMBER(NULL) po_line_location_id
2516            , NULL po_shipment_number
2517            , TO_NUMBER(NULL) po_release_id
2518            , TO_NUMBER(NULL) po_release_number
2519 /*
2520            , rsh.shipment_header_id po_header_id
2521            , rsh.shipment_num po_number
2522            , rsl.shipment_line_id po_line_id
2523            , rsl.line_num po_line_number
2524            , rsl.shipment_line_id po_line_location_id
2525            , rsl.line_num po_shipment_number
2526            , rsh.shipment_header_id po_release_id
2527            , rsh.shipment_header_id po_release_number
2528 */
2529            , porh.requisition_header_id req_header_id
2530            , porh.segment1 req_number
2531            , porl.requisition_line_id req_line_id
2532            , porl.line_num req_line
2533            , rsl.req_distribution_id req_distribution_id
2534            , rsl.shipment_header_id rcv_shipment_header_id
2535            , rsh.shipment_num rcv_shipment_number
2536            , rsl.shipment_line_id rcv_shipment_line_id
2537            , rsl.line_num rcv_line_number
2538            , rsl.from_organization_id from_organization_id
2539            , rsl.to_organization_id to_organization_id
2540            , rsl.shipment_line_id vendor_id
2541            , '' SOURCE
2542            , TO_NUMBER(NULL) vendor_site_id
2543            , 'N' outside_operation_flag
2544            , rsl.item_id item_id
2545            , -- Bug 2073164
2546              NULL uom_code
2547            , rsl.unit_of_measure primary_uom
2548            , mum.uom_class primary_uom_class
2549            , NVL(msi.allowed_units_lookup_code, 2) item_allowed_units_lookup_code
2550            , NVL(msi.location_control_code, 1) item_locator_control
2551            , DECODE(msi.restrict_locators_code, 1, 'Y', 'N') restrict_locators_code
2552            , DECODE(msi.restrict_subinventories_code, 1, 'Y', 'N') restrict_subinventories_code
2553            , NVL(msi.shelf_life_code, 1) shelf_life_code
2554            , NVL(msi.shelf_life_days, 0) shelf_life_days
2555            , msi.serial_number_control_code serial_number_control_code
2556            , msi.lot_control_code lot_control_code
2557            , DECODE(msi.revision_qty_control_code, 1, 'N', 2, 'Y', 'N') item_rev_control_flag_to
2558            , DECODE(msi1.revision_qty_control_code, 1, 'N', 2, 'Y', 'N') item_rev_control_flag_from
2559            , NULL item_number
2560            , rsl.item_revision item_revision
2561            , rsl.item_description item_description
2562            , rsl.category_id item_category_id
2563            , '' hazard_class
2564            , '' un_number
2565            , rsl.vendor_item_num vendor_item_number
2566            , rsh.ship_to_location_id ship_to_location_id
2567            , '' ship_to_location
2568            , rsh.packing_slip packing_slip
2569            , rsl.routing_header_id routing_id
2570            , '' routing_name
2571            , porl.need_by_date need_by_date
2572            , rsh.expected_receipt_date expected_receipt_date
2573            , rsl.quantity_shipped ordered_qty
2574            , rsl.primary_unit_of_measure ordered_uom
2575            , rsh.ussgl_transaction_code ussgl_transaction_code
2576            , rsh.government_context government_context
2577            , NULL inspection_required_flag
2578            , NULL receipt_required_flag
2579            , NULL enforce_ship_to_location_code
2580            , TO_NUMBER(NULL) unit_price
2581            , NULL currency_code
2582            , NULL currency_conversion_type
2583            , TO_DATE(NULL) currency_conversion_date
2584            , TO_NUMBER(NULL) currency_conversion_rate
2585            , NULL note_to_receiver
2586            , --PORL.NOTE_TO_RECEIVER       NOTE_TO_RECEIVER,
2587              rsl.destination_type_code destination_type_code
2588            , rsl.deliver_to_person_id deliver_to_person_id
2589            , rsl.deliver_to_location_id deliver_to_location_id
2590            , rsl.to_subinventory destination_subinventory
2591            , rsl.attribute_category attribute_category
2592            , rsl.attribute1 attribute1
2593            , rsl.attribute2 attribute2
2594            , rsl.attribute3 attribute3
2595            , rsl.attribute4 attribute4
2596            , rsl.attribute5 attribute5
2597            , rsl.attribute6 attribute6
2598            , rsl.attribute7 attribute7
2599            , rsl.attribute8 attribute8
2600            , rsl.attribute9 attribute9
2601            , rsl.attribute10 attribute10
2602            , rsl.attribute11 attribute11
2603            , rsl.attribute12 attribute12
2604            , rsl.attribute13 attribute13
2605            , rsl.attribute14 attribute14
2606            , rsl.attribute15 attribute15
2607            , 'OPEN' closed_code
2608            , NULL asn_type
2609            , rsh.bill_of_lading bill_of_lading
2610            , rsh.shipped_date shipped_date
2611            , rsh.freight_carrier_code freight_carrier_code
2612            , rsh.waybill_airbill_num waybill_airbill_num
2613            , rsh.freight_bill_number freight_bill_num
2614            , rsl.vendor_lot_num vendor_lot_num
2615            , rsl.container_num container_num
2616            , rsl.truck_num truck_num
2617            , rsl.bar_code_label bar_code_label
2618            , NULL rate_type_display
2619            , 'P' match_option
2620            , NULL country_of_origin_code
2621            , TO_NUMBER(NULL) oe_order_header_id
2622            , TO_NUMBER(NULL) oe_order_num
2623            , TO_NUMBER(NULL) oe_order_line_id
2624            , TO_NUMBER(NULL) oe_order_line_num
2625            , TO_NUMBER(NULL) customer_id
2626            , TO_NUMBER(NULL) customer_site_id
2627            , NULL customer_item_num
2628            , NULL pll_note_to_receiver
2629            , --PORL.NOTE_TO_RECEIVER       PLL_NOTE_TO_RECEIVER,
2630              NULL po_distribution_id
2631            , NULL qty_ordered
2632            , NULL wip_entity_id
2633            , NULL wip_operation_seq_num
2634            , NULL wip_resource_seq_num
2635            , NULL wip_repetitive_schedule_id
2636            , NULL wip_line_id
2637            , NULL bom_resource_id
2638            , '' destination_type
2639            , '' LOCATION
2640            , NULL currency_conversion_rate_pod
2641            , NULL currency_conversion_date_pod
2642            , NULL project_id
2643            , NULL task_id
2644            , NULL secondary_uom --OPM Convergence
2645            , NULL secondary_uom_code --OPM Convergence
2646            , NULL secondary_quantity --OPM Convergence temp
2647         FROM rcv_shipment_headers rsh
2648            , rcv_shipment_lines rsl
2649            , po_requisition_headers porh
2650            , po_requisition_lines porl
2651            , mtl_system_items msi
2652            , mtl_system_items msi1
2653            , mtl_units_of_measure mum
2654        WHERE rsh.receipt_source_code <> 'VENDOR'
2655          AND rsl.requisition_line_id = porl.requisition_line_id(+)
2656          AND porl.requisition_header_id = porh.requisition_header_id(+)
2657          AND rsh.shipment_header_id = rsl.shipment_header_id
2658          AND mum.unit_of_measure(+) = rsl.unit_of_measure
2659          AND msi.organization_id(+) = rsl.to_organization_id
2660          AND msi.inventory_item_id(+) = rsl.item_id
2661          AND msi1.organization_id(+) = rsl.from_organization_id
2662          AND msi1.inventory_item_id(+) = rsl.item_id
2663          AND rsl.shipment_line_id = v_shipment_line_id
2664          AND(
2665              (
2666               rsl.source_document_code = 'REQ'
2667               AND EXISTS(
2668                    SELECT '1'
2669                      FROM po_req_distributions_all prd
2670                     WHERE prd.requisition_line_id = rsl.requisition_line_id
2671                       AND Nvl(rsl.req_distribution_id,Nvl(prd.distribution_id,-999)) = Nvl(prd.distribution_id,-999)--BUG 4946182
2672                       AND(
2673                           p_project_id IS NULL
2674                           OR(p_project_id = -9999
2675                              AND prd.project_id IS NULL) --bug#2669021
2676                           OR NVL(prd.project_id, -99) = p_project_id
2677                          ))
2678              )
2679              OR rsl.source_document_code <> 'REQ'
2680             );
2681 
2682     l_debug                    NUMBER       := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2683     --table to store all RTId, quantity and original_rti_id for lot/serial splits
2684     l_new_rti_info            inv_rcv_integration_apis.child_rec_tb_tp;
2685     l_split_lot_serial_ok      BOOLEAN;   --Return status of lot_serial_split API
2686     l_msni_count               NUMBER := 0;
2687     l_line_id                  NUMBER;
2688   BEGIN
2689     IF (l_debug = 1) THEN
2690       print_debug('create_intship_rcpt_intf_rec: 10   ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2691     END IF;
2692 
2693     SAVEPOINT crt_intship_rti_sp;
2694     x_status := fnd_api.g_ret_sts_success;
2695     l_progress := '10';
2696 
2697     -- query po_startup_value
2698     BEGIN
2699       /* Bug #2516729
2700        * Fetch rcv_shipment_headers.receipt_number for the given shipment_header_id.
2701        * If it exists , assign it to the global variable for receipt # (g_rcv_global_var.receipt_num)
2702        * in order that a new receipt # is not created everytime and the existing receipt # is used
2703        */
2704       BEGIN
2705         SELECT receipt_num
2706           INTO l_receipt_num
2707           FROM rcv_shipment_headers
2708          WHERE shipment_header_id = p_shipment_header_id
2709            AND ship_to_org_id = p_organization_id;
2710 
2711 	--Bug 4252372
2712   	--We should set inv_rcv_common_apis.g_rcv_global_var.receipt_num to
2713 	--l_receipt_num only if l_receipt_num is not null. It it is null and
2714 	--we set the value then we will end up generating extra receipt numbers.
2715 	IF (l_receipt_num IS NOT NULL) THEN
2716 	   inv_rcv_common_apis.g_rcv_global_var.receipt_num := l_receipt_num;
2717 	END IF;
2718 
2719         IF (l_debug = 1) THEN
2720           print_debug('create_intship_rcpt_intf_rec: 10.1 ' || inv_rcv_common_apis.g_rcv_global_var.receipt_num, 1);
2721         END IF;
2722       EXCEPTION
2723         WHEN NO_DATA_FOUND THEN
2724           l_receipt_num := NULL;
2725       END;
2726 
2727       inv_rcv_common_apis.init_startup_values(p_organization_id);
2728     EXCEPTION
2729       WHEN NO_DATA_FOUND THEN
2730         fnd_message.set_name('INV', 'INV_RCV_PARAM');
2731         fnd_msg_pub.ADD;
2732         RAISE fnd_api.g_exc_error;
2733     END;
2734 
2735     -- default header level non-DB items in rcv_transaction block
2736     -- and default other values need to be insert into RTI
2737 
2738     IF (l_debug = 1) THEN
2739       print_debug('create_intship_rcpt_intf_rec: 20   ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2740     END IF;
2741 
2742     l_progress := '20';
2743 
2744     -- default l_group_id ? clear group id after done
2745     IF inv_rcv_common_apis.g_rcv_global_var.interface_group_id IS NULL THEN
2746       SELECT rcv_interface_groups_s.NEXTVAL
2747         INTO l_group_id
2748         FROM DUAL;
2749 
2750       inv_rcv_common_apis.g_rcv_global_var.interface_group_id := l_group_id;
2751     ELSE
2752       l_group_id := inv_rcv_common_apis.g_rcv_global_var.interface_group_id;
2753     END IF;
2754 
2755     l_progress := '30';
2756     /* We'll get shipment_header_id for req at front end
2757        IF p_shipment_header_id IS NULL THEN
2758           SELECT DISTINCT rsl.shipment_header_id
2759        INTO l_shipment_header_id
2760        FROM rcv_shipment_lines rsl,
2761        po_requisition_lines prl
2762        WHERE
2763        prl.requisition_header_id = p_req_header_id
2764        AND prl.requisition_line_id = rsl.requisition_line_id;
2765         ELSE
2766           l_shipment_header_id := p_shipment_header_id;
2767        END IF;
2768 
2769       */
2770     l_progress := '40';
2771     -- call matching algorithm   ?
2772 
2773     -- initialize input record for matching algorithm
2774     g_rcpt_match_table_gross(g_receipt_detail_index).GROUP_ID := l_group_id;
2775     g_rcpt_match_table_gross(g_receipt_detail_index).transaction_type := 'RECEIVE';
2776     g_rcpt_match_table_gross(g_receipt_detail_index).quantity := p_rcv_qty;
2777     g_rcpt_match_table_gross(g_receipt_detail_index).unit_of_measure := p_rcv_uom;
2778     g_rcpt_match_table_gross(g_receipt_detail_index).item_id := p_item_id;
2779     --Need to use revision also in matching if entered by user.bug 3368197
2780     g_rcpt_match_table_gross(g_receipt_detail_index).revision := p_revision;
2781     g_rcpt_match_table_gross(g_receipt_detail_index).shipment_header_id := p_shipment_header_id;
2782     g_rcpt_match_table_gross(g_receipt_detail_index).expected_receipt_date := SYSDATE; --?
2783     g_rcpt_match_table_gross(g_receipt_detail_index).ship_to_location_id := p_location_id; -- for tolerance checks in matching.
2784     g_rcpt_match_table_gross(g_receipt_detail_index).tax_amount := 0; -- ?
2785     g_rcpt_match_table_gross(g_receipt_detail_index).error_status := 'S'; -- ?
2786     g_rcpt_match_table_gross(g_receipt_detail_index).to_organization_id := p_organization_id;
2787     g_rcpt_match_table_gross(g_receipt_detail_index).project_id := p_project_id;
2788     g_rcpt_match_table_gross(g_receipt_detail_index).task_id := p_task_id;
2789     l_progress := '60';
2790 
2791     SELECT primary_unit_of_measure
2792       INTO g_rcpt_match_table_gross(g_receipt_detail_index).primary_unit_of_measure
2793       FROM mtl_system_items
2794      WHERE mtl_system_items.inventory_item_id = p_item_id
2795        AND mtl_system_items.organization_id = p_organization_id;
2796 
2797     l_progress := '70';
2798 
2799     IF (l_debug = 1) THEN
2800       print_debug('create_intship_rcpt_intf_rec: 30 before matching   ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2801     END IF;
2802 
2803     inv_rcv_txn_match.matching_logic(
2804       x_return_status         => l_return_status
2805     , --?
2806       x_msg_count             => l_msg_count
2807     , x_msg_data              => l_msg_data
2808     , x_cascaded_table        => g_rcpt_match_table_gross
2809     , n                       => g_receipt_detail_index
2810     , temp_cascaded_table     => l_rcpt_match_table_detail
2811     , p_receipt_num           => NULL
2812     , p_match_type            => 'INTRANSIT SHIPMENT'
2813     , p_lpn_id                => p_from_lpn_id
2814     );
2815 
2816     IF (l_debug = 1) THEN
2817       print_debug('create_intship_rcpt_intf_rec: 40 after matching   ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2818       print_debug('create_intship_rcpt_intf_rec: 40.1 - after matching  l_return_status = ' || l_return_status, 4);
2819       print_debug('create_intship_rcpt_intf_rec: 40.2 - after matching  l_msg_count = ' || l_msg_count, 4);
2820       print_debug('create_intship_rcpt_intf_rec: 40.3 - after matching  l_msg_data = ' || l_msg_data, 4);
2821     END IF;
2822 
2823     -- x_status is not successful if there is any execution error in matching.
2824     IF l_return_status = fnd_api.g_ret_sts_error THEN
2825       fnd_message.set_name('INV', 'INV_RCV_MATCH_ERROR');
2826       fnd_msg_pub.ADD;
2827 
2828       IF (l_debug = 1) THEN
2829         print_debug('create_intship_rcpt_intf_rec 60.1: error calling matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2830       END IF;
2831 
2832       RAISE fnd_api.g_exc_error;
2833     END IF;
2834 
2835     IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
2836       fnd_message.set_name('INV', 'INV_RCV_MATCH_ERROR');
2837       fnd_msg_pub.ADD;
2838 
2839       IF (l_debug = 1) THEN
2840         print_debug('create_intship_rcpt_intf_rec 60.2: Unexpect error calling matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
2841         , 1);
2842       END IF;
2843 
2844       RAISE fnd_api.g_exc_unexpected_error;
2845     END IF;
2846 
2847     IF g_rcpt_match_table_gross(g_receipt_detail_index).error_status = 'E' THEN
2848       l_err_message := g_rcpt_match_table_gross(g_receipt_detail_index).error_message;
2849       fnd_message.set_name('INV', l_err_message);
2850       fnd_msg_pub.ADD;
2851 
2852       IF (l_debug = 1) THEN
2853         print_debug('create_intship_rcpt_intf_rec 70: error calling matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2854       END IF;
2855 
2856       RAISE fnd_api.g_exc_error;
2857     END IF;
2858 
2859     l_err_message := '@@@';
2860 
2861     FOR i IN g_receipt_detail_index ..(g_receipt_detail_index + l_rcpt_match_table_detail.COUNT - 1) LOOP
2862       IF l_rcpt_match_table_detail(i - g_receipt_detail_index + 1).error_status = 'W' THEN
2863         x_status := 'W';
2864         l_temp_message := l_rcpt_match_table_detail(i - g_receipt_detail_index + 1).error_message;
2865 
2866         IF l_temp_message IS NULL THEN
2867           l_err_message := 'INV_RCV_GEN_TOLERANCE_EXCEED';
2868           l_msg_prod := 'INV';
2869           EXIT;
2870         END IF;
2871 
2872         IF l_err_message = '@@@' THEN
2873           l_err_message := l_temp_message;
2874           l_msg_prod := 'INV';
2875         ELSIF l_temp_message <> l_err_message THEN
2876           l_msg_prod := 'INV';
2877           l_err_message := 'INV_RCV_GEN_TOLERANCE_EXCEED';
2878           EXIT;
2879         END IF;
2880       END IF;
2881     END LOOP;
2882 
2883     IF l_err_message <> '@@@' THEN
2884       fnd_message.set_name(l_msg_prod, l_err_message);
2885       fnd_msg_pub.ADD;
2886 
2887       IF (l_debug = 1) THEN
2888         print_debug('create_intship_rcpt_intf_rec 80: adding tolerance message ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
2889       END IF;
2890     END IF;
2891 
2892     -- load the matching algorithm result into input data structure
2893 
2894 
2895 
2896     -- based on return from matching algorithm,
2897     -- determine which line in rcv_transaction block to be inserted into RTI
2898 
2899 
2900 
2901     --loop through results returned by matching algorithm
2902     FOR match_result_count IN 1 .. l_rcpt_match_table_detail.COUNT LOOP
2903       l_progress := '72';
2904       OPEN l_curs_rcpt_detail(l_rcpt_match_table_detail(match_result_count).shipment_line_id);
2905       l_progress := '74';
2906       FETCH l_curs_rcpt_detail INTO l_rcv_rcpt_rec;
2907       l_progress := '76';
2908       CLOSE l_curs_rcpt_detail;
2909       l_progress := '78';
2910       l_rcv_transaction_rec.rcv_shipment_line_id := l_rcpt_match_table_detail(match_result_count).shipment_line_id;
2911       -- update following fields from matching algorithm return value
2912       l_rcv_transaction_rec.transaction_qty := l_rcpt_match_table_detail(match_result_count).quantity;
2913       l_rcv_transaction_rec.transaction_uom := l_rcpt_match_table_detail(match_result_count).unit_of_measure;
2914       l_rcv_transaction_rec.primary_quantity := l_rcpt_match_table_detail(match_result_count).primary_quantity;
2915       l_rcv_transaction_rec.primary_uom := l_rcpt_match_table_detail(match_result_count).primary_unit_of_measure;
2916       l_total_primary_qty := l_total_primary_qty + l_rcv_transaction_rec.primary_quantity;
2917 
2918       l_rcv_transaction_rec.destination_subinventory := p_rcv_subinventory_code;
2919       l_rcv_transaction_rec.locator_id := p_rcv_locator_id;
2920 
2921       l_rcv_transaction_rec.lpn_id := p_from_lpn_id;
2922       l_rcv_transaction_rec.transfer_lpn_id := p_lpn_id;
2923 
2924 
2925       -- following fileds can have distribution level values
2926       -- therefore they are set here instead of in the common insert code
2927       l_rcv_transaction_rec.ordered_qty := l_rcv_rcpt_rec.ordered_qty;
2928       --Bug 2073164
2929       l_rcv_rcpt_rec.uom_code := p_rcv_uom_code;
2930 
2931       --bug 3368197. Need to pass revision to insert_txn_interface
2932       l_rcv_transaction_rec.item_revision := p_revision;
2933 
2934       IF (l_debug = 1) THEN
2935         print_debug('create_intship_rcpt_intf_rec: 90 before insert_txn_interface ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2936       END IF;
2937 
2938       l_progress := '80';
2939 
2940       IF p_country_code IS NOT NULL THEN
2941         l_rcv_rcpt_rec.country_of_origin_code := p_country_code;
2942       END IF;
2943 
2944       --Bug #4147209 - Populate the record type with the DFF attribute category
2945       --and segment values passed from the mobile UI
2946       set_attribute_vals(
2947           p_rcv_rcpt_rec        =>  l_rcv_rcpt_rec
2948         , p_attribute_category  => p_attribute_category
2949         , p_attribute1          => p_attribute1
2950         , p_attribute2          => p_attribute2
2951         , p_attribute3          => p_attribute3
2952         , p_attribute4          => p_attribute4
2953         , p_attribute5          => p_attribute5
2954         , p_attribute6          => p_attribute6
2955         , p_attribute7          => p_attribute7
2956         , p_attribute8          => p_attribute8
2957         , p_attribute9          => p_attribute9
2958         , p_attribute10         => p_attribute10
2959         , p_attribute11         => p_attribute11
2960         , p_attribute12         => p_attribute12
2961         , p_attribute13         => p_attribute13
2962         , p_attribute14         => p_attribute14
2963         , p_attribute15         => p_attribute15);
2964 
2965       l_interface_transaction_id := insert_txn_interface(
2966             l_rcv_transaction_rec
2967           , l_rcv_rcpt_rec
2968           , l_group_id
2969           , l_transaction_type
2970           , p_organization_id
2971           , p_location_id
2972           , p_source_type
2973           , NULL  --p_qa_routing_id
2974           , p_project_id
2975           , p_task_id);
2976       l_progress := '90';
2977 
2978       IF (l_debug = 1) THEN
2979         print_debug('create_intship_rcpt_intf_rec: 100 after insert_txn_interface ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
2980       END IF;
2981 
2982       IF (l_debug = 1) THEN
2983 	 print_debug('create_intship_rcpt_intf_rec 135.5: INV J and PO J are installed. No Move Order creation from UI', 4);
2984       END IF;
2985       /* Populate the table to store the information of the RTIs created*/
2986       l_new_rti_info(match_result_count).orig_interface_trx_id := p_original_rti_id;
2987       l_new_rti_info(match_result_count).new_interface_trx_id := l_interface_transaction_id;
2988       l_new_rti_info(match_result_count).quantity := l_rcv_transaction_rec.transaction_qty;
2989     END LOOP;  --END LOOP through results returned by matching algorithm
2990 
2991     l_progress := '100';
2992 
2993     --BUG 3326408,3346758,3405320
2994     --If there are any serials confirmed from the UI for an item that is
2995     --lot controlled and serial control dynamic at SO issue,
2996     --do not NULL out serial_transaction_temp_id. In other cases,
2997     --NULL OUT serial_temp_id so that split_lot_serial does not look at MSNI
2998     l_msni_count := 0;
2999     IF (l_rcv_rcpt_rec.lot_control_code = 2 AND
3000 	l_rcv_rcpt_rec.serial_number_control_code IN (1,6)) THEN
3001        IF (l_debug = 1) THEN
3002           print_debug('create_intship_rcpt_intf_rec 135.6: serial_control_code IS 6, need TO NULL OUT mtli', 4);
3003        END IF;
3004 
3005        BEGIN
3006 	  IF (l_rcv_rcpt_rec.serial_number_control_code = 6) THEN
3007 	     SELECT count(1)
3008 	       INTO   l_msni_count
3009 	       FROM   mtl_serial_numbers_interface
3010 	       WHERE  product_transaction_id = p_original_rti_id
3011 	       AND    product_code = 'RCV';
3012           END IF;
3013 
3014           IF l_msni_count = 0 THEN
3015 	     UPDATE mtl_transaction_lots_interface
3016 	       SET  serial_transaction_temp_id = NULL
3017 	       WHERE product_transaction_id = p_original_rti_id
3018 	       AND   product_code = 'RCV';
3019           END IF;
3020 
3021        EXCEPTION
3022           WHEN OTHERS THEN
3023 	     IF (l_debug = 1) THEN
3024 		print_debug('create_intship_rcpt_intf_rec 135.7: Error nulling serial temp id OF MTLI', 4);
3025 	     END IF;
3026        END ;
3027     END IF;--IF (l_rcv_rcpt_rec.serial_number_control_code = 6) THEN
3028 
3029     l_split_lot_serial_ok := inv_rcv_integration_apis.split_lot_serial(
3030               p_api_version   => 1.0
3031             , p_init_msg_lst  => FND_API.G_FALSE
3032             , x_return_status =>  l_return_status
3033             , x_msg_count     =>  l_msg_count
3034             , x_msg_data      =>  x_message
3035             , p_new_rti_info  =>  l_new_rti_info);
3036     IF ( NOT l_split_lot_serial_ok) THEN
3037        IF (l_debug = 1) THEN
3038           print_debug('create_intship_rcpt_intf_rec 100.1: Failure in split_lot_serial', 4);
3039        END IF;
3040        RAISE FND_API.G_EXC_ERROR;
3041     END IF;
3042 
3043     IF (l_debug = 1) THEN
3044        print_debug('create_intship_rcpt_intf_rec 100.2: Call split_lot_serial is OK', 4);
3045     END IF;
3046 
3047     l_progress := '110';
3048 
3049     IF l_curs_rcpt_detail%ISOPEN THEN
3050       CLOSE l_curs_rcpt_detail;
3051     END IF;
3052 
3053     -- append index in input table where the line to be detailed needs to be inserted
3054     --g_receipt_detail_index := l_rcpt_match_table_detail.COUNT + g_receipt_detail_index;
3055 
3056     -- clear the lot/qty data structure
3057     g_rcpt_lot_qty_rec_tb.DELETE;
3058     l_progress := '120';
3059     inv_rcv_common_apis.do_check(
3060       p_organization_id         => p_organization_id
3061     , p_inventory_item_id       => p_item_id
3062     , p_transaction_type_id     => 61
3063     , p_primary_quantity        => l_total_primary_qty
3064     , x_return_status           => l_return_status
3065     , x_msg_count               => l_msg_count
3066     , x_msg_data                => x_message
3067     );
3068 
3069     IF l_return_status <> fnd_api.g_ret_sts_success THEN
3070       x_status := l_return_status;
3071     END IF;
3072 
3073     l_progress := '130';
3074 
3075     IF (l_debug = 1) THEN
3076       print_debug('About exiting create_intship_rcpt_intf_rec: 140 - after cursor loop  '
3077         || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
3078       , 1);
3079     END IF;
3080   EXCEPTION
3081     WHEN fnd_api.g_exc_error THEN
3082       ROLLBACK TO crt_intship_rti_sp;
3083       x_status := fnd_api.g_ret_sts_error;
3084 
3085       IF l_curs_rcpt_detail%ISOPEN THEN
3086         CLOSE l_curs_rcpt_detail;
3087       END IF;
3088 
3089       fnd_msg_pub.count_and_get(
3090           p_encoded => fnd_api.g_false
3091         , p_count => l_msg_count
3092         , p_data => x_message);
3093 
3094       IF (l_debug = 1) THEN
3095         print_debug('create_intship_rcpt_intf_rec:  FND_API.g_exc_error ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3096       END IF;
3097     WHEN fnd_api.g_exc_unexpected_error THEN
3098       ROLLBACK TO crt_intship_rti_sp;
3099       x_status := fnd_api.g_ret_sts_unexp_error;
3100 
3101       IF l_curs_rcpt_detail%ISOPEN THEN
3102         CLOSE l_curs_rcpt_detail;
3103       END IF;
3104 
3105       fnd_msg_pub.count_and_get(
3106           p_encoded => fnd_api.g_false
3107         , p_count => l_msg_count
3108         , p_data => x_message);
3109 
3110       IF (l_debug = 1) THEN
3111         print_debug('create_intship_rcpt_intf_rec: fnd_api.g_exc_unexpected_error ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3112       END IF;
3113     WHEN OTHERS THEN
3114       ROLLBACK TO crt_intship_rti_sp;
3115       x_status := fnd_api.g_ret_sts_unexp_error;
3116 
3117       IF l_curs_rcpt_detail%ISOPEN THEN
3118         CLOSE l_curs_rcpt_detail;
3119       END IF;
3120 
3121       IF SQLCODE IS NOT NULL THEN
3122         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.create_intship_rcpt_intf_rec', l_progress, SQLCODE);
3123       END IF;
3124 
3125       fnd_msg_pub.count_and_get(
3126           p_encoded => fnd_api.g_false
3127         , p_count => l_msg_count
3128         , p_data => x_message);
3129 
3130       IF (l_debug = 1) THEN
3131         print_debug('create_intship_rcpt_intf_rec: Other exception ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3132       END IF;
3133   END create_intship_rcpt_intf_rec;
3134 
3135   PROCEDURE create_rma_rcpt_intf_rec(
3136     p_move_order_header_id   IN OUT NOCOPY  NUMBER
3137   , p_organization_id        IN             NUMBER
3138   , p_oe_order_header_id     IN             NUMBER
3139   , p_item_id                IN             NUMBER
3140   , p_location_id            IN             NUMBER
3141   , p_rcv_qty                IN             NUMBER
3142   , p_rcv_uom                IN             VARCHAR2
3143   , p_rcv_uom_code           IN             VARCHAR2
3144   , p_source_type            IN             VARCHAR2
3145   , p_lpn_id                 IN             NUMBER
3146   , p_lot_control_code       IN             NUMBER
3147   , p_revision               IN             VARCHAR2
3148   , p_inspect                IN             NUMBER
3149   , x_status                 OUT NOCOPY     VARCHAR2
3150   , x_message                OUT NOCOPY     VARCHAR2
3151   , p_project_id             IN             NUMBER    DEFAULT NULL
3152   , p_task_id                IN             NUMBER    DEFAULT NULL
3153   , p_country_code           IN             VARCHAR2  DEFAULT NULL
3154   , p_rcv_subinventory_code  IN             VARCHAR2  DEFAULT NULL -- RCVLOCATORSSUPPORT
3155   , p_rcv_locator_id         IN             NUMBER    DEFAULT NULL
3156   , p_original_rti_id        IN             NUMBER    DEFAULT NULL  --Lot/Serial Support
3157   , p_secondary_uom          IN             VARCHAR2  DEFAULT NULL-- OPM Convergence
3158   , p_secondary_uom_code     IN             VARCHAR2  DEFAULT NULL-- OPM Convergence
3159   , p_secondary_quantity          IN             NUMBER    DEFAULT NULL --OPM Convergence
3160   , p_attribute_category     IN             VARCHAR2  DEFAULT NULL  --Bug #4147209 - Added DFF cols
3161   , p_attribute1             IN             VARCHAR2  DEFAULT NULL
3162   , p_attribute2             IN             VARCHAR2  DEFAULT NULL
3163   , p_attribute3             IN             VARCHAR2  DEFAULT NULL
3164   , p_attribute4             IN             VARCHAR2  DEFAULT NULL
3165   , p_attribute5             IN             VARCHAR2  DEFAULT NULL
3166   , p_attribute6             IN             VARCHAR2  DEFAULT NULL
3167   , p_attribute7             IN             VARCHAR2  DEFAULT NULL
3168   , p_attribute8             IN             VARCHAR2  DEFAULT NULL
3169   , p_attribute9             IN             VARCHAR2  DEFAULT NULL
3170   , p_attribute10            IN             VARCHAR2  DEFAULT NULL
3171   , p_attribute11            IN             VARCHAR2  DEFAULT NULL
3172   , p_attribute12            IN             VARCHAR2  DEFAULT NULL
3173   , p_attribute13            IN             VARCHAR2  DEFAULT NULL
3174   , p_attribute14            IN             VARCHAR2  DEFAULT NULL
3175   , p_attribute15            IN             VARCHAR2  DEFAULT NULL
3176   ) IS
3177     l_rcpt_match_table_detail  inv_rcv_common_apis.cascaded_trans_tab_type; -- output for matching algorithm
3178     l_rcv_transaction_rec      rcv_transaction_rec_tp; -- rcv_transaction block
3179     l_interface_transaction_id NUMBER       := NULL;
3180     -- this is used to keep track of the id used to insert the row in rti
3181 
3182     l_transaction_type         VARCHAR2(20) := 'RECEIVE';
3183     l_total_primary_qty        NUMBER       := 0;
3184     l_return_status            VARCHAR2(1)  := fnd_api.g_ret_sts_success;
3185     l_msg_count                NUMBER;
3186     l_msg_data                 VARCHAR2(4000);
3187     l_progress                 VARCHAR2(10);
3188     l_err_message              VARCHAR2(100);
3189     l_temp_message             VARCHAR2(100);
3190     l_msg_prod                 VARCHAR2(5);
3191     l_group_id                 NUMBER;
3192     l_rcv_rcpt_rec             rcv_enter_receipts_rec_tp;
3193     l_inspect                  NUMBER;
3194     l_default_routing_id       NUMBER;
3195 
3196     CURSOR l_curs_rcpt_detail(v_oe_order_line_id NUMBER) IS
3197       SELECT 'N' line_chkbox
3198            , 'CUSTOMER' source_type_code
3199            , 'CUSTOMER' receipt_source_code
3200            , '' order_type_code
3201            , '' order_type
3202            , TO_NUMBER(NULL) po_header_id
3203            , NULL po_number
3204            , TO_NUMBER(NULL) po_line_id
3205            , TO_NUMBER(NULL) po_line_number
3206            , TO_NUMBER(NULL) po_line_location_id
3207            , TO_NUMBER(NULL) po_shipment_number
3208            , TO_NUMBER(NULL) po_release_id
3209            , TO_NUMBER(NULL) po_release_number
3210            , TO_NUMBER(NULL) req_header_id
3211            , NULL req_number
3212            , TO_NUMBER(NULL) req_line_id
3213            , TO_NUMBER(NULL) req_line
3214            , TO_NUMBER(NULL) req_distribution_id
3215            , TO_NUMBER(NULL) rcv_shipment_header_id
3216            , NULL rcv_shipment_number
3217            , TO_NUMBER(NULL) rcv_shipment_line_id
3218            , TO_NUMBER(NULL) rcv_line_number
3219            , NVL(oel.ship_to_org_id, oeh.ship_to_org_id) from_organization_id
3220            , NVL(oel.ship_from_org_id, oeh.ship_from_org_id) to_organization_id
3221            , TO_NUMBER(NULL) vendor_id
3222            , '' SOURCE
3223            , TO_NUMBER(NULL) vendor_site_id
3224            , NULL outside_operation_flag
3225            , oel.inventory_item_id item_id
3226            , -- Bug 2073164
3227              NULL uom_code
3228            , mum.unit_of_measure primary_uom
3229            , mum.uom_class primary_uom_class
3230            , NVL(msi.allowed_units_lookup_code, 2) item_allowed_units_lookup_code
3231            , NVL(msi.location_control_code, 1) item_locator_control
3232            , DECODE(msi.restrict_locators_code, 1, 'Y', 'N') restrict_locators_code
3233            , DECODE(msi.restrict_subinventories_code, 1, 'Y', 'N') restrict_subinventories_code
3234            , NVL(msi.shelf_life_code, 1) shelf_life_code
3235            , NVL(msi.shelf_life_days, 0) shelf_life_days
3236            , msi.serial_number_control_code serial_number_control_code
3237            , msi.lot_control_code lot_control_code
3238            , DECODE(msi.revision_qty_control_code, 1, 'N', 2, 'Y', 'N') item_rev_control_flag_to
3239            , NULL item_rev_control_flag_from
3240            , msi.segment1 item_number
3241            , oel.item_revision item_revision
3242            , msi.description item_description
3243            , TO_NUMBER(NULL) item_category_id
3244            , NULL hazard_class
3245            , NULL un_number
3246            , NULL vendor_item_number
3247            , oel.ship_from_org_id ship_to_location_id
3248            , '' ship_to_location
3249            , NULL packing_slip
3250            , TO_NUMBER(NULL) routing_id
3251            , NULL routing_name
3252            , oel.request_date need_by_date
3253            , NVL(oel.promise_date, oel.request_date) expected_receipt_date
3254            , oel.ordered_quantity ordered_qty
3255            , '' ordered_uom
3256            , NULL ussgl_transaction_code
3257            , NULL government_context
3258            , DECODE(msi.return_inspection_requirement, 1, 'Y', 'N') inspection_required_flag
3259            , 'Y' receipt_required_flag
3260            , 'N' enforce_ship_to_location_code
3261            , oel.unit_selling_price unit_price
3262            , oeh.transactional_curr_code currency_code
3263            , oeh.conversion_type_code currency_conversion_type
3264            , oeh.conversion_rate_date currency_conversion_date
3265            , oeh.conversion_rate currency_conversion_rate
3266            , NULL note_to_receiver
3267            , NULL destination_type_code
3268            , oel.deliver_to_contact_id deliver_to_person_id
3269            , oel.deliver_to_org_id deliver_to_location_id
3270            , NULL destination_subinventory
3271            , oel.CONTEXT attribute_category
3272            , oel.attribute1 attribute1
3273            , oel.attribute2 attribute2
3274            , oel.attribute3 attribute3
3275            , oel.attribute4 attribute4
3276            , oel.attribute5 attribute5
3277            , oel.attribute6 attribute6
3278            , oel.attribute7 attribute7
3279            , oel.attribute8 attribute8
3280            , oel.attribute9 attribute9
3281            , oel.attribute10 attribute10
3282            , oel.attribute11 attribute11
3283            , oel.attribute12 attribute12
3284            , oel.attribute13 attribute13
3285            , oel.attribute14 attribute14
3286            , oel.attribute15 attribute15
3287            , NULL closed_code
3288            , NULL asn_type
3289            , NULL bill_of_lading
3290            , TO_DATE(NULL) shipped_date
3291            , NULL freight_carrier_code
3292            , NULL waybill_airbill_num
3293            , NULL freight_bill_num
3294            , NULL vendor_lot_num
3295            , NULL container_num
3296            , NULL truck_num
3297            , NULL bar_code_label
3298            , NULL rate_type_display
3299            , NULL match_option
3300            , NULL country_of_origin_code
3301            , oel.header_id oe_order_header_id
3302            , oeh.order_number oe_order_num
3303            , oel.line_id oe_order_line_id
3304            , oel.line_number oe_order_line_num
3305            , oel.sold_to_org_id customer_id
3306            , NVL(oel.ship_to_org_id, oeh.ship_to_org_id) customer_site_id
3307            , '' customer_item_num
3308            , '' pll_note_to_receiver
3309            , NULL po_distribution_id
3310            , NULL qty_ordered
3311            , NULL wip_entity_id
3312            , NULL wip_operation_seq_num
3313            , NULL wip_resource_seq_num
3314            , NULL wip_repetitive_schedule_id
3315            , NULL wip_line_id
3316            , NULL bom_resource_id
3317            , '' destination_type
3318            , '' LOCATION
3319            , NULL currency_conversion_rate_pod
3320            , NULL currency_conversion_date_pod
3321            , project_id project_id
3322            , task_id task_id
3323            , NULL secondary_uom --OPM Convergence
3324            , NULL secondary_uom_code --OPM Convergence
3325            , NULL secondary_quantity --OPM Convergence
3326         FROM  oe_order_lines_all oel
3327             , oe_order_headers_all oeh
3328             , mtl_system_items msi
3329             , mtl_units_of_measure mum
3330        WHERE oel.line_category_code = 'RETURN'
3331          AND oel.header_id = oeh.header_id
3332          AND oel.inventory_item_id = msi.inventory_item_id
3333          AND oel.ship_from_org_id = msi.organization_id
3334          AND msi.primary_uom_code = mum.uom_code
3335          AND oel.booked_flag = 'Y'
3336          AND oel.ordered_quantity > NVL(oel.shipped_quantity, 0)
3337          AND msi.mtl_transactions_enabled_flag = 'Y'
3338          AND oel.line_id = v_oe_order_line_id
3339          AND(
3340              (p_project_id IS NULL
3341               OR(p_project_id = -9999
3342                  AND oel.project_id IS NULL) --bug#2669021
3343               OR oel.project_id = p_project_id)
3344              AND(p_task_id IS NULL
3345                  OR oel.task_id = p_task_id)
3346             );
3347     -- don't need from and to org for the query since both have 1-to-1 relationship to shipment header
3348 
3349     l_debug  NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3350     --table to store all RTId, quantity and original_rti_id for lot/serial splits
3351     l_new_rti_info            inv_rcv_integration_apis.child_rec_tb_tp;
3352     l_split_lot_serial_ok      BOOLEAN;   --Return status of lot_serial_split API
3353     l_line_id NUMBER;
3354   BEGIN
3355     IF (l_debug = 1) THEN
3356       print_debug('create_rma_rcpt_intf_rec: 10 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3357     END IF;
3358 
3359     --   print_debug('project id ' || p_project_id);
3360     --   print_debug('task_id ' || p_task_id);
3361     SAVEPOINT crt_rma_rti_sp;
3362     x_status := fnd_api.g_ret_sts_success;
3363     l_progress := '10';
3364 
3365     -- query po_startup_value
3366     BEGIN
3367       inv_rcv_common_apis.init_startup_values(p_organization_id);
3368     EXCEPTION
3369       WHEN NO_DATA_FOUND THEN
3370         fnd_message.set_name('INV', 'INV_RCV_PARAM');
3371         fnd_msg_pub.ADD;
3372         RAISE fnd_api.g_exc_error;
3373     END;
3374 
3375     IF (l_debug = 1) THEN
3376       print_debug('create_rma_rcpt_intf_rec: 20 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
3377     END IF;
3378 
3379     -- default header level non-DB items in rcv_transaction block
3380     -- and default other values need to be insert into RTI
3381 
3382     l_progress := '20';
3383 
3384     -- default l_group_id ? clear group id after done
3385     IF inv_rcv_common_apis.g_rcv_global_var.interface_group_id IS NULL THEN
3386       SELECT rcv_interface_groups_s.NEXTVAL
3387         INTO l_group_id
3388         FROM DUAL;
3389 
3390       inv_rcv_common_apis.g_rcv_global_var.interface_group_id := l_group_id;
3391     ELSE
3392       l_group_id := inv_rcv_common_apis.g_rcv_global_var.interface_group_id;
3393     END IF;
3394 
3395     l_progress := '30';
3396     -- call matching algorithm   ?
3397 
3398     -- initialize input record for matching algorithm
3399     g_rcpt_match_table_gross(g_receipt_detail_index).GROUP_ID := l_group_id;
3400     g_rcpt_match_table_gross(g_receipt_detail_index).transaction_type := 'RECEIVE';
3401     g_rcpt_match_table_gross(g_receipt_detail_index).quantity := p_rcv_qty;
3402     g_rcpt_match_table_gross(g_receipt_detail_index).unit_of_measure := p_rcv_uom;
3403     g_rcpt_match_table_gross(g_receipt_detail_index).item_id := p_item_id;
3404     g_rcpt_match_table_gross(g_receipt_detail_index).oe_order_header_id := p_oe_order_header_id;
3405     g_rcpt_match_table_gross(g_receipt_detail_index).expected_receipt_date := SYSDATE; --?
3406     g_rcpt_match_table_gross(g_receipt_detail_index).ship_to_location_id := p_location_id; -- for tolerance checks in matching.
3407     g_rcpt_match_table_gross(g_receipt_detail_index).tax_amount := 0; -- ?
3408     g_rcpt_match_table_gross(g_receipt_detail_index).error_status := 'S'; -- ?
3409     g_rcpt_match_table_gross(g_receipt_detail_index).to_organization_id := p_organization_id;
3410     g_rcpt_match_table_gross(g_receipt_detail_index).project_id := p_project_id;
3411     g_rcpt_match_table_gross(g_receipt_detail_index).task_id := p_task_id;
3412     l_progress := '60';
3413 
3414     SELECT primary_unit_of_measure
3415       INTO g_rcpt_match_table_gross(g_receipt_detail_index).primary_unit_of_measure
3416       FROM mtl_system_items
3417      WHERE mtl_system_items.inventory_item_id = p_item_id
3418        AND mtl_system_items.organization_id = p_organization_id;
3419 
3420     l_progress := '70';
3421 
3422     IF (l_debug = 1) THEN
3423       print_debug('create_rma_rcpt_intf_rec: 30 before matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
3424     END IF;
3425 
3426     inv_rcv_txn_match.matching_logic(
3427       x_return_status         => l_return_status
3428     , --?
3429       x_msg_count             => l_msg_count
3430     , x_msg_data              => l_msg_data
3431     , x_cascaded_table        => g_rcpt_match_table_gross
3432     , n                       => g_receipt_detail_index
3433     , temp_cascaded_table     => l_rcpt_match_table_detail
3434     , p_receipt_num           => NULL
3435     , p_match_type            => 'RMA'
3436     , p_lpn_id                => NULL
3437     );
3438 
3439     IF (l_debug = 1) THEN
3440       print_debug('create_rma_rcpt_intf_rec: 40 after matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
3441       print_debug('create_rma_rcpt_intf_rec: 40.1 - after matching  l_return_status = ' || l_return_status, 4);
3442       print_debug('create_rma_rcpt_intf_rec: 40.2 - after matching  l_msg_count = ' || l_msg_count, 4);
3443       print_debug('create_rma_rcpt_intf_rec: 40.3 - after matching  l_msg_data = ' || l_msg_data, 4);
3444     END IF;
3445 
3446     IF l_return_status = fnd_api.g_ret_sts_error THEN
3447       fnd_message.set_name('INV', 'INV_RCV_MATCH_ERROR');
3448       fnd_msg_pub.ADD;
3449 
3450       IF (l_debug = 1) THEN
3451         print_debug('create_rma_rcpt_intf_rec 60.1: error calling matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3452       END IF;
3453 
3454       RAISE fnd_api.g_exc_error;
3455     END IF;
3456 
3457     IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
3458       fnd_message.set_name('INV', 'INV_RCV_MATCH_ERROR');
3459       fnd_msg_pub.ADD;
3460 
3461       IF (l_debug = 1) THEN
3462         print_debug('create_rma_rcpt_intf_rec 60.2: Unexpect error calling matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3463       END IF;
3464 
3465       RAISE fnd_api.g_exc_unexpected_error;
3466     END IF;
3467 
3468     IF g_rcpt_match_table_gross(g_receipt_detail_index).error_status = 'E' THEN
3469       l_err_message := g_rcpt_match_table_gross(g_receipt_detail_index).error_message;
3470       fnd_message.set_name('INV', l_err_message);
3471       fnd_msg_pub.ADD;
3472 
3473       IF (l_debug = 1) THEN
3474         print_debug('create_rma_rcpt_intf_rec 70: error calling matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3475       END IF;
3476 
3477       RAISE fnd_api.g_exc_error;
3478     END IF;
3479 
3480     l_err_message := '@@@';
3481 
3482     FOR i IN g_receipt_detail_index ..(g_receipt_detail_index + l_rcpt_match_table_detail.COUNT - 1) LOOP
3483       IF l_rcpt_match_table_detail(i - g_receipt_detail_index + 1).error_status = 'W' THEN
3484         x_status := 'W';
3485         l_temp_message := l_rcpt_match_table_detail(i - g_receipt_detail_index + 1).error_message;
3486 
3487         IF l_temp_message IS NULL THEN
3488           l_err_message := 'INV_RCV_GEN_TOLERANCE_EXCEED';
3489           l_msg_prod := 'INV';
3490           EXIT;
3491         END IF;
3492 
3493         IF l_err_message = '@@@' THEN
3494           l_err_message := l_temp_message;
3495           l_msg_prod := 'INV';
3496         ELSIF l_temp_message <> l_err_message THEN
3497           l_msg_prod := 'INV';
3498           l_err_message := 'INV_RCV_GEN_TOLERANCE_EXCEED';
3499           EXIT;
3500         END IF;
3501       END IF;
3502     END LOOP;
3503 
3504     IF l_err_message <> '@@@' THEN
3505       fnd_message.set_name(l_msg_prod, l_err_message);
3506       fnd_msg_pub.ADD;
3507 
3508       IF (l_debug = 1) THEN
3509         print_debug('create_rma_rcpt_intf_rec 80: adding tolerance message ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3510       END IF;
3511     END IF;
3512 
3513     -- load the matching algorithm result into input data structure
3514     -- based on return from matching algorithm,
3515     -- determine which line in rcv_transaction block to be inserted into RTI
3516     -- loop through results returned by matching algorithm
3517     FOR match_result_count IN 1 .. l_rcpt_match_table_detail.COUNT LOOP
3518       l_progress := '72';
3519       OPEN l_curs_rcpt_detail(l_rcpt_match_table_detail(match_result_count).oe_order_line_id);
3520       l_progress := '74';
3521       FETCH l_curs_rcpt_detail INTO l_rcv_rcpt_rec;
3522       l_progress := '76';
3523       --     print_debug('receipt source code before passing ' || l_rcv_rcpt_rec.source_type_code,4);
3524       --     print_debug('OE project id = ' || l_rcv_rcpt_rec.project_id,4);
3525       --     print_debug('OE task id = ' || l_rcv_rcpt_rec.task_id,4);
3526       CLOSE l_curs_rcpt_detail;
3527       l_progress := '78';
3528       l_rcv_transaction_rec.oe_order_line_id := l_rcpt_match_table_detail(match_result_count).oe_order_line_id;
3529       -- update following fields from matching algorithm return value
3530 
3531       l_rcv_transaction_rec.transaction_qty := l_rcpt_match_table_detail(match_result_count).quantity;
3532       l_rcv_transaction_rec.transaction_uom := l_rcpt_match_table_detail(match_result_count).unit_of_measure;
3533       l_rcv_transaction_rec.primary_quantity := l_rcpt_match_table_detail(match_result_count).primary_quantity;
3534       l_rcv_transaction_rec.primary_uom := l_rcpt_match_table_detail(match_result_count).primary_unit_of_measure;
3535       --BUG 3308727 issue 129
3536       l_rcv_transaction_rec.item_revision := p_revision;
3537       l_total_primary_qty := l_total_primary_qty + l_rcv_transaction_rec.primary_quantity;
3538 
3539       l_rcv_transaction_rec.destination_subinventory := p_rcv_subinventory_code;
3540       l_rcv_transaction_rec.locator_id := p_rcv_locator_id;
3541 
3542       l_rcv_transaction_rec.transfer_lpn_id := p_lpn_id;
3543 
3544       -- following fileds can have distribution level values
3545       -- therefore they are set here instead of in the common insert code
3546       l_rcv_transaction_rec.ordered_qty := l_rcv_rcpt_rec.ordered_qty;
3547       --Bug 2073164
3548       l_rcv_rcpt_rec.uom_code := p_rcv_uom_code;
3549 
3550       IF (l_debug = 1) THEN
3551         print_debug('create_rma_rcpt_intf_rec: 90 before insert_txn_interface' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
3552       END IF;
3553 
3554       l_progress := '80';
3555 
3556       IF p_country_code IS NOT NULL THEN
3557         l_rcv_rcpt_rec.country_of_origin_code := p_country_code;
3558       END IF;
3559 
3560       --Bug #4147209 - Populate the record type with the DFF attribute category
3561       --and segment values passed from the mobile UI
3562       set_attribute_vals(
3563           p_rcv_rcpt_rec        =>  l_rcv_rcpt_rec
3564         , p_attribute_category  => p_attribute_category
3565         , p_attribute1          => p_attribute1
3566         , p_attribute2          => p_attribute2
3567         , p_attribute3          => p_attribute3
3568         , p_attribute4          => p_attribute4
3569         , p_attribute5          => p_attribute5
3570         , p_attribute6          => p_attribute6
3571         , p_attribute7          => p_attribute7
3572         , p_attribute8          => p_attribute8
3573         , p_attribute9          => p_attribute9
3574         , p_attribute10         => p_attribute10
3575         , p_attribute11         => p_attribute11
3576         , p_attribute12         => p_attribute12
3577         , p_attribute13         => p_attribute13
3578         , p_attribute14         => p_attribute14
3579         , p_attribute15         => p_attribute15);
3580 
3581 l_interface_transaction_id := insert_txn_interface(
3582             l_rcv_transaction_rec
3583           , l_rcv_rcpt_rec
3584           , l_group_id
3585           , l_transaction_type
3586           , p_organization_id
3587           , p_location_id
3588           , p_source_type
3589                 , NULL -- p_qa_routing_id
3590                 , p_project_id
3591                 , p_task_id);
3592       l_progress := '90';
3593 
3594       IF (l_debug = 1) THEN
3595         print_debug('create_rma_rcpt_intf_rec: 100 after insert_txn_interface' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
3596       END IF;
3597 
3598       IF (l_debug = 1) THEN
3599 	 print_debug('create_rma_rcpt_intf_rec 135.5: INV J and PO J are installed. No Move Order creation from UI', 4);
3600       END IF;
3601       /* Populate the table to store the information of the RTIs created*/
3602       l_new_rti_info(match_result_count).orig_interface_trx_id := p_original_rti_id;
3603       l_new_rti_info(match_result_count).new_interface_trx_id := l_interface_transaction_id;
3604       l_new_rti_info(match_result_count).quantity := l_rcv_transaction_rec.transaction_qty;
3605     END LOOP; --END LOOP through results returned by matching algorithm
3606 
3607     --Call the split_lot API to split the lots and serials inserted from the UI
3608     --based on the quantity of each RTI record
3609     l_split_lot_serial_ok := inv_rcv_integration_apis.split_lot_serial(
3610               p_api_version   => 1.0
3611             , p_init_msg_lst  => FND_API.G_FALSE
3612             , x_return_status =>  l_return_status
3613             , x_msg_count     =>  l_msg_count
3614             , x_msg_data      =>  x_message
3615             , p_new_rti_info  =>  l_new_rti_info);
3616     IF ( NOT l_split_lot_serial_ok) THEN
3617        IF (l_debug = 1) THEN
3618           print_debug('create_rama_rcpt_intf_rec 110.1: Failure in split_lot_serial', 4);
3619        END IF;
3620        RAISE FND_API.G_EXC_ERROR;
3621     END IF;
3622 
3623     IF (l_debug = 1) THEN
3624        print_debug('create_rma_rcpt_intf_rec 110.2: Call split_lot_serial is OK', 4);
3625     END IF;
3626 
3627     IF l_curs_rcpt_detail%ISOPEN THEN
3628       CLOSE l_curs_rcpt_detail;
3629     END IF;
3630 
3631     -- append index in input table where the line to be detailed needs to be inserted
3632     --g_receipt_detail_index := l_rcpt_match_table_detail.COUNT + g_receipt_detail_index;
3633 
3634     -- clear the lot/qty data structure
3635     g_rcpt_lot_qty_rec_tb.DELETE;
3636     l_progress := '120';
3637     inv_rcv_common_apis.do_check(
3638       p_organization_id         => p_organization_id
3639     , p_inventory_item_id       => p_item_id
3640     , p_transaction_type_id     => 15
3641     , p_primary_quantity        => l_total_primary_qty
3642     , x_return_status           => l_return_status
3643     , x_msg_count               => l_msg_count
3644     , x_msg_data                => x_message
3645     );
3646 
3647     IF l_return_status <> fnd_api.g_ret_sts_success THEN
3648       x_status := l_return_status;
3649     END IF;
3650 
3651     l_progress := '130';
3652 
3653     IF (l_debug = 1) THEN
3654       print_debug('About exit create_rma_rcpt_intf_rec: 140 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3655     END IF;
3656   EXCEPTION
3657     WHEN fnd_api.g_exc_error THEN
3658       ROLLBACK TO crt_rma_rti_sp;
3659       x_status := fnd_api.g_ret_sts_error;
3660 
3661       IF l_curs_rcpt_detail%ISOPEN THEN
3662         CLOSE l_curs_rcpt_detail;
3663       END IF;
3664 
3665       fnd_msg_pub.count_and_get(
3666           p_encoded => fnd_api.g_false
3667         , p_count => l_msg_count
3668         , p_data => x_message);
3669 
3670       IF (l_debug = 1) THEN
3671         print_debug('create_rma_rcpt_intf_rec:  FND_API.g_exc_error ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3672       END IF;
3673     WHEN fnd_api.g_exc_unexpected_error THEN
3674       ROLLBACK TO crt_rma_rti_sp;
3675       x_status := fnd_api.g_ret_sts_unexp_error;
3676 
3677       IF l_curs_rcpt_detail%ISOPEN THEN
3678         CLOSE l_curs_rcpt_detail;
3679       END IF;
3680 
3681       fnd_msg_pub.count_and_get(
3682           p_encoded => fnd_api.g_false
3683         , p_count => l_msg_count
3684         , p_data => x_message);
3685 
3686       IF (l_debug = 1) THEN
3687         print_debug('create_rma_rcpt_intf_rec: fnd_api.g_exc_unexpected_error ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3688       END IF;
3689     WHEN OTHERS THEN
3690       ROLLBACK TO crt_rma_rti_sp;
3691       x_status := fnd_api.g_ret_sts_unexp_error;
3692 
3693       IF l_curs_rcpt_detail%ISOPEN THEN
3694         CLOSE l_curs_rcpt_detail;
3695       END IF;
3696 
3697       IF SQLCODE IS NOT NULL THEN
3698         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.create_rma_rcpt_intf_rec', l_progress, SQLCODE);
3699       END IF;
3700 
3701       fnd_msg_pub.count_and_get(
3702           p_encoded => fnd_api.g_false
3703         , p_count => l_msg_count
3704         , p_data => x_message);
3705 
3706       IF (l_debug = 1) THEN
3707         print_debug('create_rma_rcpt_intf_rec: Other exception ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
3708       END IF;
3709   END create_rma_rcpt_intf_rec;
3710 
3711   PROCEDURE create_asn_con_rcpt_intf_rec(
3712     p_move_order_header_id   IN OUT NOCOPY  NUMBER
3713   , p_organization_id        IN             NUMBER
3714   , p_shipment_header_id     IN             NUMBER
3715   , p_po_header_id           IN             NUMBER
3716   , p_item_id                IN             NUMBER
3717   , p_location_id            IN             NUMBER
3718   , p_rcv_qty                IN             NUMBER
3719   , p_rcv_uom                IN             VARCHAR2
3720   , p_rcv_uom_code           IN             VARCHAR2
3721   , p_source_type            IN             VARCHAR2
3722   , p_from_lpn_id            IN             NUMBER
3723   , p_lpn_id                 IN             NUMBER
3724   , p_lot_control_code       IN             NUMBER
3725   , p_revision               IN             VARCHAR2
3726   , p_inspect                IN             NUMBER
3727   , x_status                 OUT NOCOPY     VARCHAR2
3728   , x_message                OUT NOCOPY     VARCHAR2
3729   , p_item_desc              IN             VARCHAR2  DEFAULT NULL
3730   , p_project_id             IN             NUMBER    DEFAULT NULL
3731   , p_task_id                IN             NUMBER    DEFAULT NULL
3732   , p_country_code           IN             VARCHAR2  DEFAULT NULL
3733   , p_rcv_subinventory_code  IN             VARCHAR2  DEFAULT NULL -- RCVLOCATORSSUPPORT
3734   , p_rcv_locator_id         IN             NUMBER    DEFAULT NULL
3735   , p_original_rti_id        IN             NUMBER    DEFAULT NULL  --Lot/Serial Support
3736   , p_secondary_uom          IN             VARCHAR2  DEFAULT NULL-- OPM Convergence
3737   , p_secondary_uom_code     IN             VARCHAR2  DEFAULT NULL-- OPM Convergence
3738   , p_secondary_quantity          IN             NUMBER    DEFAULT NULL --OPM Convergence
3739   , p_attribute_category     IN             VARCHAR2  DEFAULT NULL  --Bug #4147209 - Added DFF cols
3740   , p_attribute1             IN             VARCHAR2  DEFAULT NULL
3741   , p_attribute2             IN             VARCHAR2  DEFAULT NULL
3742   , p_attribute3             IN             VARCHAR2  DEFAULT NULL
3743   , p_attribute4             IN             VARCHAR2  DEFAULT NULL
3744   , p_attribute5             IN             VARCHAR2  DEFAULT NULL
3745   , p_attribute6             IN             VARCHAR2  DEFAULT NULL
3746   , p_attribute7             IN             VARCHAR2  DEFAULT NULL
3747   , p_attribute8             IN             VARCHAR2  DEFAULT NULL
3748   , p_attribute9             IN             VARCHAR2  DEFAULT NULL
3749   , p_attribute10            IN             VARCHAR2  DEFAULT NULL
3750   , p_attribute11            IN             VARCHAR2  DEFAULT NULL
3751   , p_attribute12            IN             VARCHAR2  DEFAULT NULL
3752   , p_attribute13            IN             VARCHAR2  DEFAULT NULL
3753   , p_attribute14            IN             VARCHAR2  DEFAULT NULL
3754   , p_attribute15            IN             VARCHAR2  DEFAULT NULL
3755   , p_express_transaction    IN             VARCHAR2  DEFAULT NULL
3756   ) IS
3757     l_rcpt_match_table_detail  inv_rcv_common_apis.cascaded_trans_tab_type; -- output for matching algorithm
3758     l_rcv_transaction_rec      rcv_transaction_rec_tp; -- rcv_transaction block
3759     l_interface_transaction_id NUMBER       := NULL;
3760     -- this is used to keep track of the id used to insert the row in rti
3761 
3762     l_transaction_type         VARCHAR2(20) := 'RECEIVE';
3763     l_total_primary_qty        NUMBER       := 0;
3764     l_return_status            VARCHAR2(1)  := fnd_api.g_ret_sts_success;
3765     l_msg_count                NUMBER;
3766     l_msg_data                 VARCHAR2(4000);
3767     l_progress                 VARCHAR2(10);
3768     l_err_message              VARCHAR2(100);
3769     l_temp_message             VARCHAR2(100);
3770     l_msg_prod                 VARCHAR2(5);
3771     l_group_id                 NUMBER;
3772     l_rcv_rcpt_rec             rcv_enter_receipts_rec_tp;
3773     l_inspect                  NUMBER;
3774     l_match_type               VARCHAR2(30);
3775     l_receipt_num              VARCHAR2(30);
3776     -- Added for bug# 6967549
3777     l_qa_availability          VARCHAR2(30) := fnd_api.g_false;
3778     l_evaluation_result        VARCHAR2(20);
3779     l_project_id               NUMBER       := p_project_id;
3780     l_task_id                  NUMBER       := p_task_id;
3781 
3782     CURSOR l_curs_rcpt_detail(v_shipment_line_id NUMBER) IS
3783       SELECT 'N' line_chkbox
3784 -- For Bug 7440217
3785            , p_source_type source_type_code
3786 -- End for Bug 7440217
3787            , 'VENDOR' receipt_source_code
3788            , 'PO' order_type_code
3789            , '' order_type
3790            , poll.po_header_id po_header_id
3791            , poh.segment1 po_number
3792            , poll.po_line_id po_line_id
3793            , pol.line_num po_line_number
3794            , poll.line_location_id po_line_location_id
3795            , poll.shipment_num po_shipment_number
3796            , poll.po_release_id po_release_id
3797            , por.release_num po_release_number
3798            , TO_NUMBER(NULL) req_header_id
3799            , NULL req_number
3800            , TO_NUMBER(NULL) req_line_id
3801            , TO_NUMBER(NULL) req_line
3802            , TO_NUMBER(NULL) req_distribution_id
3803            , rsh.shipment_header_id rcv_shipment_header_id
3804            , rsh.shipment_num rcv_shipment_number
3805            , rsl.shipment_line_id rcv_shipment_line_id
3806            , rsl.line_num rcv_line_number
3807            , rsl.from_organization_id from_organization_id  --Bug #3878174
3808 /*
3809            , NVL(rsl.from_organization_id, poh.po_header_id) from_organization_id
3810 */
3811            , rsl.to_organization_id to_organization_id
3812            , rsh.vendor_id vendor_id
3813            , '' SOURCE
3814            , poh.vendor_site_id vendor_site_id -- Bug 6403165
3815            , '' outside_operation_flag
3816            , rsl.item_id item_id
3817            , -- Bug 2073164
3818              NULL uom_code
3819            , rsl.unit_of_measure primary_uom
3820            , mum.uom_class primary_uom_class
3821            , NVL(msi.allowed_units_lookup_code, 2) item_allowed_units_lookup_code
3822            , NVL(msi.location_control_code, 1) item_locator_control
3823            , DECODE(msi.restrict_locators_code, 1, 'Y', 'N') restrict_locators_code
3824            , DECODE(msi.restrict_subinventories_code, 1, 'Y', 'N') restrict_subinventories_code
3825            , NVL(msi.shelf_life_code, 1) shelf_life_code
3826            , NVL(msi.shelf_life_days, 0) shelf_life_days
3827            , msi.serial_number_control_code serial_number_control_code
3828            , msi.lot_control_code lot_control_code
3829            , DECODE(msi.revision_qty_control_code, 1, 'N', 2, 'Y', 'N') item_rev_control_flag_to
3830            , NULL item_rev_control_flag_from
3831            , NULL item_number
3832            , rsl.item_revision item_revision
3833            , rsl.item_description item_description
3834            , rsl.category_id item_category_id
3835            , '' hazard_class
3836            , '' un_number
3837            , rsl.vendor_item_num vendor_item_number
3838            , rsl.ship_to_location_id ship_to_location_id
3839            , '' ship_to_location
3840            , rsl.packing_slip packing_slip
3841            , rsl.routing_header_id routing_id
3842            , '' routing_name
3843            , poll.need_by_date need_by_date
3844            , rsh.expected_receipt_date expected_receipt_date
3845            , poll.quantity ordered_qty
3846            , pol.unit_meas_lookup_code ordered_uom
3847            , rsl.ussgl_transaction_code ussgl_transaction_code
3848            , rsl.government_context government_context
3849            , poll.inspection_required_flag inspection_required_flag
3850            , poll.receipt_required_flag receipt_required_flag
3851            , poll.enforce_ship_to_location_code enforce_ship_to_location_code
3852            , NVL(poll.price_override, pol.unit_price) unit_price
3853            , poh.currency_code currency_code
3854            , poh.rate_type currency_conversion_type
3855            , poh.rate_date currency_conversion_date
3856            , poh.rate currency_conversion_rate
3857            , poh.note_to_receiver note_to_receiver
3858            , rsl.destination_type_code destination_type_code
3859            , rsl.deliver_to_person_id deliver_to_person_id
3860            , rsl.deliver_to_location_id deliver_to_location_id
3861            , rsl.to_subinventory destination_subinventory
3862            , rsl.attribute_category attribute_category
3863            , rsl.attribute1 attribute1
3864            , rsl.attribute2 attribute2
3865            , rsl.attribute3 attribute3
3866            , rsl.attribute4 attribute4
3867            , rsl.attribute5 attribute5
3868            , rsl.attribute6 attribute6
3869            , rsl.attribute7 attribute7
3870            , rsl.attribute8 attribute8
3871            , rsl.attribute9 attribute9
3872            , rsl.attribute10 attribute10
3873            , rsl.attribute11 attribute11
3874            , rsl.attribute12 attribute12
3875            , rsl.attribute13 attribute13
3876            , rsl.attribute14 attribute14
3877            , rsl.attribute15 attribute15
3878            , poll.closed_code closed_code
3879            , rsh.asn_type asn_type
3880            , rsh.bill_of_lading bill_of_lading
3881            , rsh.shipped_date shipped_date
3882            , rsh.freight_carrier_code freight_carrier_code
3883            , rsh.waybill_airbill_num waybill_airbill_num
3884            , rsh.freight_bill_number freight_bill_num
3885            , rsl.vendor_lot_num vendor_lot_num
3886            , rsl.container_num container_num
3887            , rsl.truck_num truck_num
3888            , rsl.bar_code_label bar_code_label
3889            , '' rate_type_display
3890            , poll.match_option match_option
3891            , rsl.country_of_origin_code country_of_origin_code
3892            , TO_NUMBER(NULL) oe_order_header_id
3893            , TO_NUMBER(NULL) oe_order_num
3894            , TO_NUMBER(NULL) oe_order_line_id
3895            , TO_NUMBER(NULL) oe_order_line_num
3896            , TO_NUMBER(NULL) customer_id
3897            , TO_NUMBER(NULL) customer_site_id
3898            , NULL customer_item_num
3899            , NULL pll_note_to_receiver
3900            , --POLL.NOTE_TO_RECEIVER       PLL_NOTE_TO_RECEIVER,
3901              NULL po_distribution_id
3902            , NULL qty_ordered
3903            , NULL wip_entity_id
3904            , NULL wip_operation_seq_num
3905            , NULL wip_resource_seq_num
3906            , NULL wip_repetitive_schedule_id
3907            , NULL wip_line_id
3908            , NULL bom_resource_id
3909            , '' destination_type
3910            , '' LOCATION
3911            , NULL currency_conversion_rate_pod
3912            , NULL currency_conversion_date_pod
3913            , NULL project_id
3914            , NULL task_id
3915            , NULL secondary_uom --OPM Convergence
3916            , NULL secondary_uom_code --OPM Convergence
3917            , NULL secondary_quantity --OPM Convergence
3918         FROM rcv_shipment_lines rsl
3919            , rcv_shipment_headers rsh
3920            , po_headers poh
3921            , po_line_locations poll
3922            , po_lines pol
3923            , po_releases por
3924            , mtl_system_items msi
3925            , mtl_units_of_measure mum
3926        WHERE NVL(poll.approved_flag, 'N') = 'Y'
3927          AND NVL(poll.cancel_flag, 'N') = 'N'
3928          AND NVL(poll.closed_code, 'OPEN') <> 'FINALLY CLOSED'
3929          AND poll.shipment_type IN('STANDARD', 'BLANKET', 'SCHEDULED')
3930          AND poh.po_header_id = poll.po_header_id
3931          AND pol.po_line_id = poll.po_line_id
3932          AND poll.po_release_id = por.po_release_id(+)
3933          AND mum.unit_of_measure(+) = rsl.unit_of_measure
3934          AND NVL(msi.organization_id, rsl.to_organization_id) = rsl.to_organization_id
3935          AND msi.inventory_item_id(+) = rsl.item_id
3936          AND poll.line_location_id = rsl.po_line_location_id
3937          AND rsl.shipment_header_id = rsh.shipment_header_id
3938 -- For Bug 7440217  Added type LCM also
3939          AND rsh.asn_type IN('ASN', 'ASBN', 'LCM')
3940 -- End for Bug 7440217
3941          AND rsl.shipment_line_status_code <> 'CANCELLED'
3942          AND rsl.shipment_line_id = v_shipment_line_id
3943          AND poll.line_location_id IN(
3944               SELECT pod.line_location_id
3945                 FROM po_distributions_all pod
3946                WHERE (
3947                       p_project_id IS NULL
3948                       OR(p_project_id = -9999
3949                          AND pod.project_id IS NULL)
3950                       OR --bug#2669021
3951                          NVL(pod.project_id, -9999) = p_project_id
3952                      )
3953                  AND(p_task_id IS NULL
3954                      OR NVL(pod.task_id, -9999) = p_task_id)
3955                  AND pod.po_header_id = poll.po_header_id
3956                  AND pod.po_line_id = poll.po_line_id
3957                  AND pod.line_location_id = poll.line_location_id)
3958       UNION
3959       SELECT 'N' line_chkbox
3960            , 'INTERNAL' source_type_code
3961            , DECODE(rsl.source_document_code, 'INVENTORY', 'INVENTORY', 'REQ', 'INTERNAL ORDER') receipt_source_code
3962            , rsl.source_document_code order_type_code
3963            , '' order_type
3964            , rsh.shipment_header_id po_header_id
3965            , rsh.shipment_num po_number
3966            , rsl.shipment_line_id po_line_id
3967            , rsl.line_num po_line_number
3968            , rsl.shipment_line_id po_line_location_id
3969            , rsl.line_num po_shipment_number
3970            , rsh.shipment_header_id po_release_id
3971            , rsh.shipment_header_id po_release_number
3972            , porh.requisition_header_id req_header_id
3973            , porh.segment1 req_number
3974            , porl.requisition_line_id req_line_id
3975            , porl.line_num req_line
3976            , rsl.req_distribution_id req_distribution_id
3977            , rsl.shipment_header_id rcv_shipment_header_id
3978            , rsh.shipment_num rcv_shipment_number
3979            , rsl.shipment_line_id rcv_shipment_line_id
3980            , rsl.line_num rcv_line_number
3981            , rsl.from_organization_id from_organization_id
3982            , rsl.to_organization_id to_organization_id
3983            , rsl.shipment_line_id vendor_id
3984            , '' SOURCE
3985            , TO_NUMBER(NULL) vendor_site_id
3986            , 'N' outside_operation_flag
3987            , rsl.item_id item_id
3988            , -- Bug 2073164
3989              NULL uom_code
3990            , rsl.unit_of_measure primary_uom
3991            , mum.uom_class primary_uom_class
3992            , NVL(msi.allowed_units_lookup_code, 2) item_allowed_units_lookup_code
3993            , NVL(msi.location_control_code, 1) item_locator_control
3994            , DECODE(msi.restrict_locators_code, 1, 'Y', 'N') restrict_locators_code
3995            , DECODE(msi.restrict_subinventories_code, 1, 'Y', 'N') restrict_subinventories_code
3996            , NVL(msi.shelf_life_code, 1) shelf_life_code
3997            , NVL(msi.shelf_life_days, 0) shelf_life_days
3998            , msi.serial_number_control_code serial_number_control_code
3999            , msi.lot_control_code lot_control_code
4000            , DECODE(msi.revision_qty_control_code, 1, 'N', 2, 'Y', 'N') item_rev_control_flag_to
4001            , DECODE(msi1.revision_qty_control_code, 1, 'N', 2, 'Y', 'N') item_rev_control_flag_from
4002            , NULL item_number
4003            , rsl.item_revision item_revision
4004            , rsl.item_description item_description
4005            , rsl.category_id item_category_id
4006            , '' hazard_class
4007            , '' un_number
4008            , rsl.vendor_item_num vendor_item_number
4009            , rsh.ship_to_location_id ship_to_location_id
4010            , '' ship_to_location
4011            , rsh.packing_slip packing_slip
4012            , rsl.routing_header_id routing_id
4013            , '' routing_name
4014            , porl.need_by_date need_by_date
4015            , rsh.expected_receipt_date expected_receipt_date
4016            , rsl.quantity_shipped ordered_qty
4017            , rsl.primary_unit_of_measure ordered_uom
4018            , rsh.ussgl_transaction_code ussgl_transaction_code
4019            , rsh.government_context government_context
4020            , NULL inspection_required_flag
4021            , NULL receipt_required_flag
4022            , NULL enforce_ship_to_location_code
4023            , TO_NUMBER(NULL) unit_price
4024            , NULL currency_code
4025            , NULL currency_conversion_type
4026            , TO_DATE(NULL) currency_conversion_date
4027            , TO_NUMBER(NULL) currency_conversion_rate
4028            , NULL note_to_receiver
4029            , --PORL.NOTE_TO_RECEIVER       NOTE_TO_RECEIVER,
4030              rsl.destination_type_code destination_type_code
4031            , rsl.deliver_to_person_id deliver_to_person_id
4032            , rsl.deliver_to_location_id deliver_to_location_id
4033            , rsl.to_subinventory destination_subinventory
4034            , rsl.attribute_category attribute_category
4035            , rsl.attribute1 attribute1
4036            , rsl.attribute2 attribute2
4037            , rsl.attribute3 attribute3
4038            , rsl.attribute4 attribute4
4039            , rsl.attribute5 attribute5
4040            , rsl.attribute6 attribute6
4041            , rsl.attribute7 attribute7
4042            , rsl.attribute8 attribute8
4043            , rsl.attribute9 attribute9
4044            , rsl.attribute10 attribute10
4045            , rsl.attribute11 attribute11
4046            , rsl.attribute12 attribute12
4047            , rsl.attribute13 attribute13
4048            , rsl.attribute14 attribute14
4049            , rsl.attribute15 attribute15
4050            , 'OPEN' closed_code
4051            , NULL asn_type
4052            , rsh.bill_of_lading bill_of_lading
4053            , rsh.shipped_date shipped_date
4054            , rsh.freight_carrier_code freight_carrier_code
4055            , rsh.waybill_airbill_num waybill_airbill_num
4056            , rsh.freight_bill_number freight_bill_num
4057            , rsl.vendor_lot_num vendor_lot_num
4058            , rsl.container_num container_num
4059            , rsl.truck_num truck_num
4060            , rsl.bar_code_label bar_code_label
4061            , NULL rate_type_display
4062            , 'P' match_option
4063            , NULL country_of_origin_code
4064            , TO_NUMBER(NULL) oe_order_header_id
4065            , TO_NUMBER(NULL) oe_order_num
4066            , TO_NUMBER(NULL) oe_order_line_id
4067            , TO_NUMBER(NULL) oe_order_line_num
4068            , TO_NUMBER(NULL) customer_id
4069            , TO_NUMBER(NULL) customer_site_id
4070            , NULL customer_item_num
4071            , NULL pll_note_to_receiver
4072            , --PORL.NOTE_TO_RECEIVER       PLL_NOTE_TO_RECEIVER,
4073              NULL po_distribution_id
4074            , NULL qty_ordered
4075            , NULL wip_entity_id
4076            , NULL wip_operation_seq_num
4077            , NULL wip_resource_seq_num
4078            , NULL wip_repetitive_schedule_id
4079            , NULL wip_line_id
4080            , NULL bom_resource_id
4081            , '' destination_type
4082            , '' LOCATION
4083            , NULL currency_conversion_rate_pod
4084            , NULL currency_conversion_date_pod
4085            , NULL project_id
4086            , NULL task_id
4087            , NULL secondary_uom --OPM Convergence
4088            , NULL secondary_uom_code --OPM Convergence
4089            , NULL secondary_quantity --OPM Convergence temp
4090         FROM rcv_shipment_headers rsh
4091            , rcv_shipment_lines rsl
4092            , po_requisition_headers porh
4093            , po_requisition_lines porl
4094            , mtl_system_items msi
4095            , mtl_system_items msi1
4096            , mtl_units_of_measure mum
4097        WHERE rsh.receipt_source_code <> 'VENDOR'
4098          AND rsl.requisition_line_id = porl.requisition_line_id(+)
4099          AND porl.requisition_header_id = porh.requisition_header_id(+)
4100          AND rsh.shipment_header_id = rsl.shipment_header_id
4101          AND mum.unit_of_measure(+) = rsl.unit_of_measure
4102          AND msi.organization_id(+) = rsl.to_organization_id
4103          AND msi.inventory_item_id(+) = rsl.item_id
4104          AND msi1.organization_id(+) = rsl.from_organization_id
4105          AND msi1.inventory_item_id(+) = rsl.item_id
4106          AND rsh.asn_type IS NULL
4107          AND rsl.shipment_line_id = v_shipment_line_id;
4108     -- dont need from and to org for the query since both have 1-to-1 relationship to shipment header
4109 
4110     l_debug                    NUMBER       := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4111     --table to store all RTId, quantity and original_rti_id for lot/serial splits
4112     l_new_rti_info            inv_rcv_integration_apis.child_rec_tb_tp;
4113     l_split_lot_serial_ok      BOOLEAN;   --Return status of lot_serial_split API
4114     l_lpn_id                   NUMBER       := p_lpn_id;
4115     l_msni_count               NUMBER := 0;
4116     l_line_id                  NUMBER;
4117   BEGIN
4118     IF (l_debug = 1) THEN
4119       print_debug('create_asn_con_rcpt_intf_rec: 10 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4120       print_debug('p_move_order_header_id = ' || p_move_order_header_id, 4);
4121       print_debug('p_organization_id = ' || p_organization_id, 4);
4122       print_debug('p_shipment_header_id = ' || p_shipment_header_id, 4);
4123       print_debug('p_po_header_id = ' || p_po_header_id, 4);
4124       print_debug('p_item_id = ' || p_item_id, 4);
4125       print_debug('p_location_id = ' || p_location_id, 4);
4126       print_debug('p_rcv_qty = ' || p_rcv_qty, 4);
4127       print_debug('p_rcv_uom = ' || p_rcv_uom, 4);
4128       print_debug('p_rcv_uom_code = ' || p_rcv_uom_code, 4);
4129       print_debug('p_source_type = ' || p_source_type, 4);
4130       print_debug('p_from_lpn_id = ' || p_from_lpn_id, 4);
4131       print_debug('p_lpn_id = ' || p_lpn_id, 4);
4132       print_debug('p_lot_control_code = ' || p_lot_control_code, 4);
4133       print_debug('p_revision = ' || p_revision, 4);
4134       print_debug('p_inspect = ' || p_inspect, 4);
4135       print_debug('p_item_desc = ' || p_item_desc, 4);
4136       print_debug('p_project_id = ' || p_project_id, 4);
4137       print_debug('p_task_id = ' || p_task_id, 4);
4138     END IF;
4139 
4140     SAVEPOINT crt_asn_con_rti_sp;
4141     x_status := fnd_api.g_ret_sts_success;
4142     l_progress := '10';
4143 
4144     -- query po_startup_value
4145     BEGIN
4146       /* Bug #2516729
4147        * Fetch rcv_shipment_headers.receipt_number for the given shipment_header_id.
4148        * If it exists , assign it to the global variable for receipt # (g_rcv_global_var.receipt_num)
4149        * in order that a new receipt # is not created everytime and the existing receipt # is used
4150        */
4151       BEGIN
4152         SELECT receipt_num
4153           INTO l_receipt_num
4154           FROM rcv_shipment_headers
4155          WHERE shipment_header_id = p_shipment_header_id
4156            AND ship_to_org_id = p_organization_id;
4157 
4158 	/* Bug# 6339752 the global variable inv_rcv_common_apis.g_rcv_global_var.receipt_num is to be set only if
4159          * there is non-null value from RSH.
4160 	 */
4161 
4162 	IF (l_receipt_num IS NOT NULL) THEN
4163 	  inv_rcv_common_apis.g_rcv_global_var.receipt_num := l_receipt_num;
4164 	END IF;
4165 
4166 	 IF (l_debug = 1) THEN
4167           print_debug('create_asn_con_rcpt_intf_rec: 10.1 ' || inv_rcv_common_apis.g_rcv_global_var.receipt_num, 1);
4168         END IF;
4169       EXCEPTION
4170         WHEN NO_DATA_FOUND THEN
4171           l_receipt_num := NULL;
4172       END;
4173 
4174       inv_rcv_common_apis.init_startup_values(p_organization_id);
4175     EXCEPTION
4176       WHEN NO_DATA_FOUND THEN
4177         fnd_message.set_name('INV', 'INV_RCV_PARAM');
4178         fnd_msg_pub.ADD;
4179         RAISE fnd_api.g_exc_error;
4180     END;
4181 
4182     -- default header level non-DB items in rcv_transaction block
4183     -- and default other values need to be insert into RTI
4184 
4185     IF (l_debug = 1) THEN
4186       print_debug('create_asn_con_rcpt_intf_rec: 20 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
4187     END IF;
4188 
4189     l_progress := '20';
4190 
4191     -- default l_group_id ? clear group id after done
4192     IF inv_rcv_common_apis.g_rcv_global_var.interface_group_id IS NULL THEN
4193       SELECT rcv_interface_groups_s.NEXTVAL
4194         INTO l_group_id
4195         FROM DUAL;
4196 
4197       inv_rcv_common_apis.g_rcv_global_var.interface_group_id := l_group_id;
4198     ELSE
4199       l_group_id := inv_rcv_common_apis.g_rcv_global_var.interface_group_id;
4200     END IF;
4201 
4202     l_progress := '30';
4203     -- call matching algorithm   ?
4204 
4205     -- initialize input record for matching algorithm
4206     g_rcpt_match_table_gross(g_receipt_detail_index).GROUP_ID := l_group_id;
4207     g_rcpt_match_table_gross(g_receipt_detail_index).transaction_type := 'RECEIVE';
4208     g_rcpt_match_table_gross(g_receipt_detail_index).quantity := p_rcv_qty;
4209     g_rcpt_match_table_gross(g_receipt_detail_index).unit_of_measure := p_rcv_uom;
4210 
4211     IF p_item_id IS NOT NULL THEN
4212       g_rcpt_match_table_gross(g_receipt_detail_index).item_id := p_item_id;
4213     ELSE
4214       g_rcpt_match_table_gross(g_receipt_detail_index).item_id := NULL;
4215       g_rcpt_match_table_gross(g_receipt_detail_index).item_desc := p_item_desc;
4216     END IF;
4217 
4218     g_rcpt_match_table_gross(g_receipt_detail_index).to_organization_id := p_organization_id;
4219     g_rcpt_match_table_gross(g_receipt_detail_index).shipment_header_id := p_shipment_header_id;
4220     g_rcpt_match_table_gross(g_receipt_detail_index).po_header_id := p_po_header_id;
4221     g_rcpt_match_table_gross(g_receipt_detail_index).expected_receipt_date := SYSDATE; --?
4222     g_rcpt_match_table_gross(g_receipt_detail_index).ship_to_location_id := p_location_id; -- for tolerance checks in matching.
4223     g_rcpt_match_table_gross(g_receipt_detail_index).tax_amount := 0; -- ?
4224     g_rcpt_match_table_gross(g_receipt_detail_index).error_status := 'S'; -- ?
4225     g_rcpt_match_table_gross(g_receipt_detail_index).project_id := p_project_id; --BUG# 2794612
4226     g_rcpt_match_table_gross(g_receipt_detail_index).task_id := p_task_id; --BUG# 2794612
4227     l_progress := '60';
4228 
4229     IF p_item_id IS NOT NULL THEN
4230       BEGIN
4231         SELECT primary_unit_of_measure
4232           INTO g_rcpt_match_table_gross(g_receipt_detail_index).primary_unit_of_measure
4233           FROM mtl_system_items
4234          WHERE mtl_system_items.inventory_item_id = p_item_id
4235            AND mtl_system_items.organization_id = p_organization_id;
4236       EXCEPTION
4237         WHEN OTHERS THEN
4238           IF (l_debug = 1) THEN
4239             print_debug('Primary_uom is null should not be null', 4);
4240           END IF;
4241 
4242           l_progress := '65';
4243           RAISE fnd_api.g_exc_error;
4244       END;
4245     ELSE
4246       g_rcpt_match_table_gross(g_receipt_detail_index).primary_unit_of_measure := NULL;
4247     END IF;
4248 
4249     l_progress := '70';
4250 
4251     IF (l_debug = 1) THEN
4252       print_debug('create_asn_con_rcpt_intf_rec: 30 before matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
4253     END IF;
4254 
4255 -- For Bug 7440217 Added LCM Type also
4256     IF p_source_type IN ('ASN', 'LCM') THEN
4257       l_match_type := p_source_type;
4258 -- End for Bug 7440217
4259 
4260       ELSE
4261       l_match_type := 'INTRANSIT SHIPMENT';
4262 
4263       BEGIN
4264         SELECT cost_group_id
4265           INTO l_rcv_transaction_rec.cost_group_id
4266           FROM wms_lpn_contents wlpnc
4267          WHERE organization_id = p_organization_id
4268            AND parent_lpn_id = p_lpn_id
4269            AND wlpnc.inventory_item_id = p_item_id
4270            AND EXISTS(SELECT 1
4271                         FROM cst_cost_group_accounts
4272                        WHERE organization_id = p_organization_id
4273                          AND cost_group_id = wlpnc.cost_group_id);
4274       EXCEPTION
4275         WHEN OTHERS THEN
4276           l_rcv_transaction_rec.cost_group_id := NULL;
4277       END;
4278 
4279       IF l_rcv_transaction_rec.cost_group_id IS NULL THEN
4280         UPDATE wms_lpn_contents wlpnc
4281            SET cost_group_id = NULL
4282          WHERE organization_id = p_organization_id
4283            AND parent_lpn_id = p_from_lpn_id
4284            AND wlpnc.inventory_item_id = p_item_id
4285            AND NOT EXISTS(SELECT 1
4286                             FROM cst_cost_group_accounts
4287                            WHERE organization_id = p_organization_id
4288                              AND cost_group_id = wlpnc.cost_group_id);
4289       END IF;
4290     END IF;
4291 
4292     l_lpn_id := p_from_lpn_id;
4293 
4294     inv_rcv_txn_match.matching_logic(
4295       x_return_status         => l_return_status
4296     , --?
4297       x_msg_count             => l_msg_count
4298     , x_msg_data              => l_msg_data
4299     , x_cascaded_table        => g_rcpt_match_table_gross
4300     , n                       => g_receipt_detail_index
4301     , temp_cascaded_table     => l_rcpt_match_table_detail
4302     , p_receipt_num           => NULL
4303     , p_match_type            => l_match_type
4304     , p_lpn_id                => l_lpn_id
4305     );
4306 
4307     IF (l_debug = 1) THEN
4308       print_debug('create_asn_con_rcpt_intf_rec: 40 after matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
4309       print_debug('create_asn_con_rcpt_intf_rec: 40.1 - after matching  l_return_status = ' || l_return_status, 4);
4310       print_debug('create_asn_con_rcpt_intf_rec: 40.2 - after matching  l_msg_count = ' || l_msg_count, 4);
4311       print_debug('create_asn_con_rcpt_intf_rec: 40.3 - after matching  l_msg_data = ' || l_msg_data, 4);
4312     END IF;
4313 
4314     IF l_return_status = fnd_api.g_ret_sts_error THEN
4315       fnd_message.set_name('INV', 'INV_RCV_MATCH_ERROR');
4316       fnd_msg_pub.ADD;
4317 
4318       IF (l_debug = 1) THEN
4319         print_debug('create_asn_con_rcpt_intf_rec 60.1: error calling matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4320       END IF;
4321 
4322       RAISE fnd_api.g_exc_error;
4323     END IF;
4324 
4325     IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
4326       fnd_message.set_name('INV', 'INV_RCV_MATCH_ERROR');
4327       fnd_msg_pub.ADD;
4328 
4329       IF (l_debug = 1) THEN
4330         print_debug('create_asn_con_rcpt_intf_rec 60.2: Unexpect error calling matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
4331         , 1);
4332       END IF;
4333 
4334       RAISE fnd_api.g_exc_unexpected_error;
4335     END IF;
4336 
4337     IF g_rcpt_match_table_gross(g_receipt_detail_index).error_status = 'E' THEN
4338       l_err_message := g_rcpt_match_table_gross(g_receipt_detail_index).error_message;
4339       fnd_message.set_name('INV', l_err_message);
4340       fnd_msg_pub.ADD;
4341 
4342       IF (l_debug = 1) THEN
4343         print_debug('create_asn_con_rcpt_intf_rec 70: error calling matching' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4344       END IF;
4345 
4346       RAISE fnd_api.g_exc_error;
4347     END IF;
4348 
4349     l_err_message := '@@@';
4350 
4351     FOR i IN g_receipt_detail_index ..(g_receipt_detail_index + l_rcpt_match_table_detail.COUNT - 1) LOOP
4352       IF l_rcpt_match_table_detail(i - g_receipt_detail_index + 1).error_status = 'W' THEN
4353         x_status := 'W';
4354         l_temp_message := l_rcpt_match_table_detail(i - g_receipt_detail_index + 1).error_message;
4355 
4356         IF l_temp_message IS NULL THEN
4357           l_err_message := 'INV_RCV_GEN_TOLERANCE_EXCEED';
4358           l_msg_prod := 'INV';
4359           EXIT;
4360         END IF;
4361 
4362         IF l_err_message = '@@@' THEN
4363           l_err_message := l_temp_message;
4364           l_msg_prod := 'INV';
4365         ELSIF l_temp_message <> l_err_message THEN
4366           l_msg_prod := 'INV';
4367           l_err_message := 'INV_RCV_GEN_TOLERANCE_EXCEED';
4368           EXIT;
4369         END IF;
4370       END IF;
4371     END LOOP;
4372 
4373     IF l_err_message <> '@@@' THEN
4374       fnd_message.set_name(l_msg_prod, l_err_message);
4375       fnd_msg_pub.ADD;
4376 
4377       IF (l_debug = 1) THEN
4378         print_debug('create_asn_con_rcpt_intf_rec 80: adding tolerance message ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4379       END IF;
4380     END IF;
4381 
4382     -- load the matching algorithm result into input data structure
4383     -- based on return from matching algorithm,
4384     -- determine which line in rcv_transaction block to be inserted into RTI
4385 
4386     -- loop through results returned by matching algorithm
4387     FOR match_result_count IN 1 .. l_rcpt_match_table_detail.COUNT LOOP
4388       l_progress := '72';
4389       OPEN l_curs_rcpt_detail(l_rcpt_match_table_detail(match_result_count).shipment_line_id);
4390       l_progress := '74';
4391       FETCH l_curs_rcpt_detail INTO l_rcv_rcpt_rec;
4392       l_progress := '76';
4393       CLOSE l_curs_rcpt_detail;
4394       l_progress := '78';
4395       l_rcv_transaction_rec.rcv_shipment_line_id := l_rcpt_match_table_detail(match_result_count).shipment_line_id;
4396 
4397       IF (l_debug = 1) THEN
4398         print_debug(
4399              'create_asn_con_rcpt_intf_rec: 90.1 - the '
4400           || match_result_count
4401           || 'th record of matching results - rcv_shipment_line_id = '
4402           || l_rcpt_match_table_detail(match_result_count).shipment_line_id
4403         , 4
4404         );
4405       END IF;
4406 
4407       -- update following fields from matching algorithm return value
4408       l_rcv_transaction_rec.transaction_qty := l_rcpt_match_table_detail(match_result_count).quantity;
4409       l_rcv_transaction_rec.transaction_uom := l_rcpt_match_table_detail(match_result_count).unit_of_measure;
4410       l_rcv_transaction_rec.primary_quantity := l_rcpt_match_table_detail(match_result_count).primary_quantity;
4411       l_rcv_transaction_rec.primary_uom := l_rcpt_match_table_detail(match_result_count).primary_unit_of_measure;
4412 
4413       -- Nested LPN changes pass p_from_lpn_id
4414       -- are at J then pass From_lpn_id as lpn_id otherwise use old code.
4415       -- IF p_from_lpn_id IS NOT NULL
4416       l_rcv_transaction_rec.lpn_id := p_from_lpn_id;
4417       l_rcv_transaction_rec.transfer_lpn_id := p_lpn_id;
4418 
4419       l_total_primary_qty := l_total_primary_qty + l_rcv_transaction_rec.primary_quantity;
4420       -- following fileds can have distribution level values
4421       -- therefore they are set here instead of in the common insert code
4422       l_rcv_transaction_rec.ordered_qty := l_rcv_rcpt_rec.ordered_qty;
4423       --Bug 2073164
4424       l_rcv_rcpt_rec.uom_code := p_rcv_uom_code;
4425 
4426       IF (l_debug = 1) THEN
4427         print_debug('create_asn_con_rcpt_intf_rec: 100 before insert_txn_interface' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
4428       END IF;
4429 
4430       l_progress := '80';
4431 
4432       l_rcv_transaction_rec.destination_subinventory := p_rcv_subinventory_code;
4433       l_rcv_transaction_rec.locator_id := p_rcv_locator_id;
4434       -- Bug 3211452
4435       -- Putting the Revision also
4436       l_rcv_transaction_rec.item_revision := p_revision;
4437 
4438       IF p_country_code IS NOT NULL THEN
4439         l_rcv_transaction_rec.country_of_origin_code := p_country_code;
4440       END IF;
4441 
4442       IF (p_inspect IS NOT NULL AND p_inspect = 1) THEN
4443 
4444         -- Bug# 6967549, Check to see if Skip Lot functionality is enabled for the
4445         -- current org or not and activate the same only for ASN receipts.
4446         IF p_source_type = 'ASN' THEN
4447 
4448           -- Calling function QA_SKIPLOT_RCV_GRP.CHECK_AVAILABILITY to check if Skip/Lot
4449           -- is enabled for the given org or not.
4450           -- returns fnd_api.g_true/false
4451           BEGIN
4452             l_progress := '81';
4453             qa_skiplot_rcv_grp.check_availability(
4454               p_api_version            => 1.0
4455               , p_init_msg_list        => fnd_api.g_false
4456               , p_commit               => fnd_api.g_false
4457               , p_validation_level     => fnd_api.g_valid_level_full
4458               , p_organization_id      => p_organization_id
4459               , x_qa_availability      => l_qa_availability
4460               , x_return_status        => l_return_status
4461               , x_msg_count            => l_msg_count
4462               , x_msg_data             => l_msg_data
4463             );
4464             l_progress := '82';
4465           EXCEPTION
4466             WHEN OTHERS THEN
4467               IF (l_debug = 1) THEN
4468                 print_debug( 'create_asn_con_rcpt_intf_rec: 101 - Exception in calling QA_SKIPLOT_RCV_GRP.CHECK_AVAILABILITY'
4469                   || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
4470               END IF;
4471               RAISE fnd_api.g_exc_error;
4472           END;
4473 
4474           IF NVL(l_return_status, fnd_api.g_ret_sts_success) = fnd_api.g_ret_sts_success THEN
4475 
4476             -- If the Quaility Skip Lot function is available, then gets the interface transaction id and
4477             -- call QA_SKIPLOT_RCV_GRP.EVALUATE_LOT
4478             -- returns 'Standard' or 'Inspect' to x_evaluation_result.
4479             IF NVL(l_qa_availability, fnd_api.g_false) = fnd_api.g_true THEN
4480               l_rcv_rcpt_rec.inspection_required_flag := 'Y';
4481               l_rcv_rcpt_rec.routing_id := 2;
4482 
4483               BEGIN
4484                 SELECT rcv_transactions_interface_s.NEXTVAL
4485                 INTO l_rcv_transaction_rec.interface_transaction_id
4486                 FROM DUAL;
4487 
4488                 l_progress := '83';
4489                 l_project_id := p_project_id;
4490                 l_task_id := p_task_id;
4491 
4492                 IF l_project_id = '' THEN
4493                   l_project_id := NULL;
4494                 END IF;
4495 
4496                 IF l_task_id = '' THEN
4497                   l_task_id := NULL;
4498                 END IF;
4499 
4500                 IF (l_debug = 1) THEN
4501                   print_debug('create_asn_con_rcpt_intf_rec 101 calling qa_skiplot_rcv_grp.evaluate_lot', 4);
4502                   print_debug('create_asn_con_rcpt_intf_rec 101 with l_rcv_rcpt_rec.item_revision = '|| l_rcv_rcpt_rec.item_revision, 4);
4503                 END IF;
4504 
4505                 -- Bug# 6967549, Same as previous version except now passing p_lpn_id directly
4506                 -- to the p_lpn_id parameter in the qa_skiplot_rcv_grp.evaluate_lot() API call.
4507 
4508                 l_progress := '84';
4509                 qa_skiplot_rcv_grp.evaluate_lot(
4510                   p_api_version               => 1.0
4511                   , p_init_msg_list           => fnd_api.g_false
4512                   , p_commit                  => fnd_api.g_false
4513                   , p_validation_level        => fnd_api.g_valid_level_full
4514                   , p_interface_txn_id        => l_rcv_transaction_rec.interface_transaction_id
4515                   , p_organization_id         => p_organization_id
4516                   , p_vendor_id               => l_rcv_rcpt_rec.vendor_id
4517                   , p_vendor_site_id          => l_rcv_rcpt_rec.vendor_site_id
4518                   , p_item_id                 => l_rcv_rcpt_rec.item_id
4519                   , p_item_revision           => l_rcv_rcpt_rec.item_revision
4520                   , p_item_category_id        => l_rcv_rcpt_rec.item_category_id
4521                   , p_project_id              => l_project_id
4522                   , p_task_id                 => l_task_id
4523                   , p_manufacturer_id         => NULL
4524                   , p_source_inspected        => NULL
4525                   , p_receipt_qty             => l_rcv_transaction_rec.transaction_qty
4526                   , p_receipt_date            => SYSDATE
4527                   , p_primary_uom             => l_rcv_transaction_rec.primary_uom
4528                   , p_transaction_uom         => l_rcv_transaction_rec.transaction_uom
4529                   , p_po_header_id            => l_rcv_rcpt_rec.po_header_id
4530                   , p_po_line_id              => l_rcv_rcpt_rec.po_line_id
4531                   , p_po_line_location_id     => l_rcv_rcpt_rec.po_line_location_id
4532                   , p_po_distribution_id      => l_rcv_rcpt_rec.po_distribution_id
4533                   , p_lpn_id                  => p_lpn_id
4534                   , p_wms_flag                => 'Y'
4535                   , x_evaluation_result       => l_evaluation_result
4536                   , x_return_status           => l_return_status
4537                   , x_msg_count               => l_msg_count
4538                   , x_msg_data                => l_msg_data
4539                 );
4540 
4541                 IF l_return_status = fnd_api.g_ret_sts_error THEN
4542                   IF (l_debug = 1) THEN
4543                     print_debug('create_asn_con_rcpt_intf_rec 84.1: QA CALL RAISE FND_API.G_EXC_ERROR;' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
4544                   END IF;
4545                   RAISE fnd_api.g_exc_error;
4546                 END IF;
4547 
4548                 IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
4549                   IF (l_debug = 1) THEN
4550                     print_debug('create_asn_con_rcpt_intf_rec 135.2: QA CALL RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'|| TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
4551                   END IF;
4552                   RAISE fnd_api.g_exc_unexpected_error;
4553                 END IF;
4554 
4555                 -- If QA_SKIPLOT_RCV_GRP returns 'Standard', sets the routing id to 1.
4556                 -- If QA_SKIPLOT_RCV_GRP returns 'Inspect', leaves the routing id as 2.
4557                 IF l_evaluation_result = 'STANDARD' THEN
4558                   l_rcv_rcpt_rec.inspection_required_flag := 'N';
4559                   l_rcv_rcpt_rec.routing_id := 1;
4560                 END IF;
4561 
4562               EXCEPTION
4563                 WHEN OTHERS THEN
4564                   IF (l_debug = 1) THEN
4565                     print_debug('create_asn_con_rcpt_intf_rec: 135.3 - Exception in calling QA_SKIPLOT_RCV_GRP.EVALUATE_LOT'|| TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
4566                   END IF;
4567                   RAISE fnd_api.g_exc_error;
4568               END;
4569 
4570             END IF;
4571           END IF;
4572 
4573         ELSE -- p_source_type is <> ASN
4574           l_rcv_rcpt_rec.inspection_required_flag := 'Y';
4575           l_rcv_rcpt_rec.routing_id := 2;
4576         END IF;
4577 
4578       ELSE
4579         l_rcv_rcpt_rec.routing_id := 1;
4580       END IF;
4581 
4582       --Bug #4147209 - Populate the record type with the DFF attribute category
4583       --and segment values passed from the mobile UI
4584       set_attribute_vals(
4585           p_rcv_rcpt_rec        =>  l_rcv_rcpt_rec
4586         , p_attribute_category  => p_attribute_category
4587         , p_attribute1          => p_attribute1
4588         , p_attribute2          => p_attribute2
4589         , p_attribute3          => p_attribute3
4590         , p_attribute4          => p_attribute4
4591         , p_attribute5          => p_attribute5
4592         , p_attribute6          => p_attribute6
4593         , p_attribute7          => p_attribute7
4594         , p_attribute8          => p_attribute8
4595         , p_attribute9          => p_attribute9
4596         , p_attribute10         => p_attribute10
4597         , p_attribute11         => p_attribute11
4598         , p_attribute12         => p_attribute12
4599         , p_attribute13         => p_attribute13
4600         , p_attribute14         => p_attribute14
4601         , p_attribute15         => p_attribute15);
4602 
4603       l_interface_transaction_id := insert_txn_interface(
4604           l_rcv_transaction_rec
4605         , l_rcv_rcpt_rec
4606         , l_group_id
4607         , l_transaction_type
4608         , p_organization_id
4609         , p_location_id
4610         , p_source_type
4611         , l_rcv_rcpt_rec.routing_id
4612         , p_project_id
4613         , p_task_id
4614         , p_express_transaction
4615         );
4616       l_progress := '90';
4617 
4618       IF (l_debug = 1) THEN
4619         print_debug('create_asn_con_rcpt_intf_rec: 110 after insert_txn_interface' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
4620       END IF;
4621 
4622       IF (l_debug = 1) THEN
4623 	 print_debug('create_asn_con_rcpt_intf_rec 135.5: INV J and PO J are installed. No Move Order creation from UI', 4);
4624       END IF;
4625       /* Populate the table to store the information of the RTIs created*/
4626       l_new_rti_info(match_result_count).orig_interface_trx_id := p_original_rti_id;
4627       l_new_rti_info(match_result_count).new_interface_trx_id := l_interface_transaction_id;
4628       l_new_rti_info(match_result_count).quantity := l_rcv_transaction_rec.transaction_qty;
4629     END LOOP; --END LOOP through results returned by matching algorithm
4630 
4631     --Call the split_lot API to split the lots and serials inserted from the UI
4632     --based on the quantity of each RTI record
4633 
4634     --BUG 3326408,3346758,3405320
4635     --If there are any serials confirmed from the UI for an item that is
4636     --lot controlled and serial control dynamic at SO issue,
4637     --do not NULL out serial_transaction_temp_id. In other cases,
4638     --NULL OUT serial_temp_id so that split_lot_serial does not look at MSNI
4639     l_msni_count := 0;
4640     IF (l_rcv_rcpt_rec.lot_control_code = 2 AND
4641 	l_rcv_rcpt_rec.serial_number_control_code IN (1,6)) THEN
4642        IF (l_debug = 1) THEN
4643           print_debug('create_asn_con_rcpt_intf_rec 135.6: serial_control_code IS 6, need TO NULL OUT mtli', 4);
4644        END IF;
4645 
4646        BEGIN
4647           IF (l_rcv_rcpt_rec.serial_number_control_code = 6) THEN
4648             SELECT count(1)
4649             INTO   l_msni_count
4650             FROM   mtl_serial_numbers_interface
4651             WHERE  product_transaction_id = p_original_rti_id
4652             AND    product_code = 'RCV';
4653           END IF;
4654 
4655           IF l_msni_count = 0 THEN
4656             UPDATE mtl_transaction_lots_interface
4657             SET  serial_transaction_temp_id = NULL
4658             WHERE product_transaction_id = p_original_rti_id
4659             AND   product_code = 'RCV';
4660           END IF;
4661        EXCEPTION
4662           WHEN OTHERS THEN
4663 	     IF (l_debug = 1) THEN
4664 		print_debug('create_asn_con_rcpt_intf_rec 135.7: Error nulling serial temp id OF MTLI', 4);
4665 	     END IF;
4666        END ;
4667     END IF;--IF (l_rcv_rcpt_rec.serial_number_control_code = 6) THEN
4668 
4669     l_split_lot_serial_ok := inv_rcv_integration_apis.split_lot_serial(
4670               p_api_version   => 1.0
4671             , p_init_msg_lst  => FND_API.G_FALSE
4672             , x_return_status =>  l_return_status
4673             , x_msg_count     =>  l_msg_count
4674             , x_msg_data      =>  x_message
4675             , p_new_rti_info  =>  l_new_rti_info);
4676     IF ( NOT l_split_lot_serial_ok) THEN
4677        IF (l_debug = 1) THEN
4678           print_debug('create_asn_con_rcpt_intf_rec 95.1: Failure in split_lot_serial', 4);
4679        END IF;
4680        RAISE FND_API.G_EXC_ERROR;
4681     END IF;
4682 
4683     IF (l_debug = 1) THEN
4684        print_debug('create_asn_con_rcpt_intf_rec 05.2: Call split_lot_serial is OK', 4);
4685     END IF;
4686 
4687     IF l_curs_rcpt_detail%ISOPEN THEN
4688       CLOSE l_curs_rcpt_detail;
4689     END IF;
4690 
4691     -- append index in input table where the line to be detailed needs to be inserted
4692     --g_receipt_detail_index := l_rcpt_match_table_detail.COUNT + g_receipt_detail_index;
4693 
4694     l_progress := '110';
4695     -- clear the lot/qty data structure
4696     -- Called after Calling the INV_CR_ASN_DETAILS
4697     -- g_rcpt_lot_qty_rec_tb.DELETE;
4698 
4699     l_progress := '120';
4700 
4701     IF p_item_id IS NOT NULL THEN
4702       inv_rcv_common_apis.do_check(
4703         p_organization_id         => p_organization_id
4704       , p_inventory_item_id       => p_item_id
4705       , p_transaction_type_id     => 18
4706       , p_primary_quantity        => l_total_primary_qty
4707       , x_return_status           => l_return_status
4708       , x_msg_count               => l_msg_count
4709       , x_msg_data                => x_message
4710       );
4711     END IF;
4712 
4713     IF l_return_status <> fnd_api.g_ret_sts_success THEN
4714       x_status := l_return_status;
4715     END IF;
4716 
4717     l_progress := '130';
4718 
4719     -- Calling The ASN Discrepnacy  Details
4720     IF (l_debug = 1) THEN
4721       print_debug('Before Calling ASN Ddetails ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4722     END IF;
4723 
4724     inv_cr_asn_details.create_asn_details(
4725       p_organization_id
4726     , l_group_id
4727     , l_rcv_rcpt_rec
4728     , l_rcv_transaction_rec
4729     , g_rcpt_lot_qty_rec_tb
4730     , l_interface_transaction_id
4731     , l_return_status
4732     , l_msg_data
4733     );
4734 
4735     IF l_return_status <> fnd_api.g_ret_sts_success THEN
4736       x_status := l_return_status;
4737     END IF;
4738 
4739     g_rcpt_lot_qty_rec_tb.DELETE;
4740 
4741     IF (l_debug = 1) THEN
4742       print_debug('About exit create_asn_con_rcpt_intf_rec: 140' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4743     END IF;
4744   EXCEPTION
4745     WHEN fnd_api.g_exc_error THEN
4746       ROLLBACK TO crt_asn_con_rti_sp;
4747       x_status := fnd_api.g_ret_sts_error;
4748 
4749       IF l_curs_rcpt_detail%ISOPEN THEN
4750         CLOSE l_curs_rcpt_detail;
4751       END IF;
4752 
4753       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => l_msg_count, p_data => x_message);
4754 
4755       IF (l_debug = 1) THEN
4756         print_debug('create_asn_con_rcpt_intf_rec:  FND_API.g_exc_error ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4757       END IF;
4758     WHEN fnd_api.g_exc_unexpected_error THEN
4759       ROLLBACK TO crt_asn_con_rti_sp;
4760       x_status := fnd_api.g_ret_sts_unexp_error;
4761 
4762       IF l_curs_rcpt_detail%ISOPEN THEN
4763         CLOSE l_curs_rcpt_detail;
4764       END IF;
4765 
4766       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => l_msg_count, p_data => x_message);
4767 
4768       IF (l_debug = 1) THEN
4769         print_debug('create_asn_con_rcpt_intf_rec: fnd_api.g_exc_unexpected_error ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4770       END IF;
4771     WHEN OTHERS THEN
4772       ROLLBACK TO crt_asn_con_rti_sp;
4773       x_status := fnd_api.g_ret_sts_unexp_error;
4774 
4775       IF l_curs_rcpt_detail%ISOPEN THEN
4776         CLOSE l_curs_rcpt_detail;
4777       END IF;
4778 
4779       IF SQLCODE IS NOT NULL THEN
4780         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.create_asn_con_rcpt_intf_rec', l_progress, SQLCODE);
4781       END IF;
4782 
4783       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => l_msg_count, p_data => x_message);
4784 
4785       IF (l_debug = 1) THEN
4786         print_debug(
4787              'create_asn_con_rcpt_intf_rec: Other exception - l_progress = '
4788           || l_progress
4789           || ' '
4790           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
4791         , 1
4792         );
4793       END IF;
4794   END create_asn_con_rcpt_intf_rec;
4795 
4796   PROCEDURE create_asn_exp_rcpt_intf_rec(
4797     p_move_order_header_id  IN OUT NOCOPY  NUMBER
4798   , p_organization_id       IN             NUMBER
4799   , p_shipment_header_id    IN             NUMBER
4800   , p_po_header_id          IN             NUMBER
4801   , p_location_id           IN             NUMBER
4802   , p_source_type           IN             VARCHAR2
4803   , p_lpn_id                IN             NUMBER
4804   , p_inspect               IN             NUMBER
4805   , x_status                OUT NOCOPY     VARCHAR2
4806   , x_message               OUT NOCOPY     VARCHAR2
4807   , p_project_id            IN             NUMBER DEFAULT NULL
4808   , p_task_id               IN             NUMBER DEFAULT NULL
4809   , p_rcv_subinventory_code IN             VARCHAR2 DEFAULT NULL
4810   , p_rcv_locator_id        IN             NUMBER DEFAULT NULL
4811   , p_original_rti_id       IN             NUMBER DEFAULT NULL
4812   , p_secondary_quantity          IN             NUMBER    DEFAULT NULL --OPM Convergence
4813   , p_attribute_category     IN             VARCHAR2  DEFAULT NULL  --Bug #4147209 - Added DFF cols
4814   , p_attribute1             IN             VARCHAR2  DEFAULT NULL
4815   , p_attribute2             IN             VARCHAR2  DEFAULT NULL
4816   , p_attribute3             IN             VARCHAR2  DEFAULT NULL
4817   , p_attribute4             IN             VARCHAR2  DEFAULT NULL
4818   , p_attribute5             IN             VARCHAR2  DEFAULT NULL
4819   , p_attribute6             IN             VARCHAR2  DEFAULT NULL
4820   , p_attribute7             IN             VARCHAR2  DEFAULT NULL
4821   , p_attribute8             IN             VARCHAR2  DEFAULT NULL
4822   , p_attribute9             IN             VARCHAR2  DEFAULT NULL
4823   , p_attribute10            IN             VARCHAR2  DEFAULT NULL
4824   , p_attribute11            IN             VARCHAR2  DEFAULT NULL
4825   , p_attribute12            IN             VARCHAR2  DEFAULT NULL
4826   , p_attribute13            IN             VARCHAR2  DEFAULT NULL
4827   , p_attribute14            IN             VARCHAR2  DEFAULT NULL
4828   , p_attribute15            IN             VARCHAR2  DEFAULT NULL
4829   ) IS
4830     -- get unit_of_measure in a later query because of some
4831     -- SQL problem, ???
4832 
4833     /* FP-J Lot/Serial Support Enhancement
4834      * Fetch the item's serial control code and item's primary uom code
4835      */
4836     CURSOR l_curs_asn_lpn_content IS
4837       SELECT lpn.lpn_id
4838            , lpnc.inventory_item_id
4839            , lpnc.revision
4840            , lpnc.quantity
4841            , lpnc.uom_code
4842            , msi.lot_control_code
4843            , ''
4844            , --uom.unit_of_measure,
4845              p_po_header_id
4846            , lpnc.lot_number
4847            , lpn.organization_id
4848            , msi.serial_number_control_code
4849            , msi.primary_uom_code
4850         FROM wms_lpn_contents lpnc, wms_license_plate_numbers lpn, mtl_system_items_b msi, rcv_shipment_headers rsh
4851        WHERE rsh.shipment_header_id = p_shipment_header_id
4852          AND(lpn.source_header_id = rsh.shipment_header_id
4853              OR lpn.source_name = rsh.shipment_num)
4854          AND lpn.lpn_context IN(6, 7) -- only those pre-ASN receiving ones
4855                                       -- Nested LPN changes to explode the LPN
4856                                       -- AND wlpnc.parent_lpn_id = Nvl(p_lpn_id, wlpn.lpn_id)
4857                                       -- In case user tries to to ASN reciept by giving only PO Number
4858                                       -- LPN id will be NULL, In this case we should not expand the LPN
4859                                       -- in which case start with lpn_id = p_lpn_id will fail.
4860          AND(lpn.lpn_id = NVL(p_lpn_id, lpn.lpn_id)
4861              OR lpn.lpn_id IN(SELECT     lpn_id
4862                                     FROM wms_license_plate_numbers
4863                               START WITH lpn_id = p_lpn_id
4864                               CONNECT BY parent_lpn_id = PRIOR lpn_id))
4865          --AND    lpn.lpn_id = nvl(p_lpn_id, lpn.lpn_id)
4866          AND lpn.lpn_id = lpnc.parent_lpn_id
4867          AND lpnc.inventory_item_id = msi.inventory_item_id
4868          AND msi.organization_id = p_organization_id
4869          AND(
4870              lpnc.source_line_id IN(SELECT pola.po_line_id
4871                                       FROM po_lines_all pola
4872                                      WHERE pola.po_header_id = NVL(p_po_header_id, pola.po_header_id))
4873              OR lpnc.source_line_id IS NULL
4874             );
4875 
4876     /* FP-J Lot/Serial Support Enhancement
4877      * Cursor to create MSNI records for serials in the LPN
4878      */
4879     CURSOR l_curs_serial_number(v_inventory_item_id NUMBER, v_revision VARCHAR2
4880                 , v_lot_number VARCHAR2, v_lpn_id NUMBER) IS
4881        SELECT serial_number,
4882               status_id
4883         FROM mtl_serial_numbers
4884        WHERE inventory_item_id = v_inventory_item_id
4885          AND(revision = v_revision
4886              OR(revision IS NULL
4887                 AND v_revision IS NULL))
4888          AND(lot_number = v_lot_number
4889              OR(lot_number IS NULL
4890                 AND v_lot_number IS NULL))
4891          AND lpn_id = v_lpn_id;
4892 
4893     l_lpn_id            NUMBER;
4894     l_inventory_item_id   NUMBER;
4895     l_revision            VARCHAR2(30);
4896     l_quantity            NUMBER;
4897     l_uom_code            VARCHAR2(3);
4898     l_lot_control_code    NUMBER;
4899     l_unit_of_measure     VARCHAR2(25);
4900     l_po_header_id        NUMBER;
4901 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
4902     l_lot_number          VARCHAR2(80);
4903     l_lpn_org             NUMBER;
4904     l_expiration_date     DATE;
4905     l_object_id           NUMBER;
4906     l_return_status       VARCHAR2(1)  := fnd_api.g_ret_sts_success;
4907     l_msg_count           NUMBER;
4908     l_msg_data            VARCHAR2(4000);
4909     l_progress            VARCHAR2(10);
4910     l_label_status        VARCHAR2(500);
4911     l_debug               NUMBER       := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4912 
4913     l_serial_control_code         NUMBER;
4914     l_transaction_interface_id    NUMBER;
4915     l_product_transaction_id      NUMBER;
4916     l_serial_transaction_temp_id  NUMBER;
4917     l_serial_number              mtl_serial_numbers.serial_number%type;
4918     l_primary_uom_code            mtl_system_items.primary_uom_code%TYPE;
4919     l_lot_prm_quantity            NUMBER; --lot quantity in primary uom
4920     l_lot_status_id               NUMBER;
4921     l_serial_status_id            NUMBER;
4922     l_from_org_id                 NUMBER;
4923 
4924   BEGIN
4925     IF (l_debug = 1) THEN
4926       print_debug('create_asn_exp_rcpt_intf_rec: 10 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
4927       print_debug('p_move_order_header_id = ' || p_move_order_header_id, 4);
4928       print_debug('p_organization_id = ' || p_organization_id, 4);
4929       print_debug('p_shipment_header_id = ' || p_shipment_header_id, 4);
4930       print_debug('p_po_header_id = ' || p_po_header_id, 4);
4931       print_debug('p_location_id = ' || p_location_id, 4);
4932       print_debug('p_source_type = ' || p_source_type, 4);
4933       print_debug('p_lpn_id = ' || p_lpn_id, 4);
4934       print_debug('p_inspect = ' || p_inspect, 4);
4935     END IF;
4936 
4937     x_status := fnd_api.g_ret_sts_success;
4938     l_progress := '10';
4939     OPEN l_curs_asn_lpn_content;
4940     l_progress := '20';
4941 
4942     LOOP
4943       FETCH l_curs_asn_lpn_content INTO
4944        l_lpn_id
4945      , l_inventory_item_id
4946      , l_revision
4947      , l_quantity
4948      , l_uom_code
4949      , l_lot_control_code
4950      , l_unit_of_measure
4951      , l_po_header_id
4952      , l_lot_number
4953      , l_lpn_org
4954      , l_serial_control_code
4955      , l_primary_uom_code;
4956       EXIT WHEN l_curs_asn_lpn_content%NOTFOUND;
4957       l_progress := '30';
4958 
4959       --Reset the variables that store interface Ids
4960       l_transaction_interface_id    := NULL;
4961       l_serial_transaction_temp_id  := NULL;
4962       l_product_transaction_id      := NULL;
4963 
4964       IF (p_source_type = 'INTERNAL'
4965           AND l_lot_control_code = 2) THEN
4966         BEGIN
4967           SELECT expiration_date
4968             INTO l_expiration_date
4969             FROM mtl_lot_numbers
4970            WHERE inventory_item_id = l_inventory_item_id
4971              AND organization_id = l_lpn_org
4972              AND lot_number = l_lot_number;
4973         EXCEPTION
4974           WHEN OTHERS THEN
4975             l_expiration_date := NULL;
4976         END;
4977 
4978         inv_rcv_common_apis.insert_dynamic_lot(
4979           p_api_version           => 1.0
4980         , --p_init_msg_list            => p_init_msg_list,
4981           --p_commit                   => p_commit,
4982           --p_validation_level         => p_validation_level,
4983           p_inventory_item_id     => l_inventory_item_id
4984         , p_organization_id       => p_organization_id
4985         , p_lot_number            => l_lot_number
4986         , p_expiration_date       => l_expiration_date
4987         , --p_transaction_temp_id      => p_transaction_temp_id,
4988           --p_transaction_action_id    => p_transaction_action_id,
4989           p_transfer_organization_id => l_lpn_org,  --uncommenting and setting the transfer_org_id to l_lpn_org_id to
4990                                                     --populate lot attributes bug3368089
4991           p_status_id             => ''
4992         , p_update_status         => 'FALSE'
4993         , x_object_id             => l_object_id
4994         , x_return_status         => l_return_status
4995         , x_msg_count             => l_msg_count
4996         , x_msg_data              => l_msg_data
4997         );
4998 
4999         IF l_return_status = fnd_api.g_ret_sts_error THEN
5000           fnd_message.set_name('INV', 'INV_RCV_CREATE_ASNEXP_RTI_FAIL');
5001           fnd_msg_pub.ADD;
5002 
5003           IF (l_debug = 1) THEN
5004             print_debug(
5005                  'create_asn_exp_rcpt_intf_rec 30.1:create_asn_con_rcpt_intf_rec  RAISE FND_API.G_EXC_ERROR;'
5006               || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5007             , 4
5008             );
5009           END IF;
5010           RAISE fnd_api.g_exc_error;
5011         END IF;
5012 
5013         IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5014           fnd_message.set_name('INV', 'INV_RCV_CREATE_ASNEXP_RTI_FAIL');
5015           fnd_msg_pub.ADD;
5016 
5017           IF (l_debug = 1) THEN
5018             print_debug(
5019                  'create_asn_exp_rcpt_intf_rec 30.2: create_asn_con_rcpt_intf_rec RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
5020               || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5021             , 4
5022             );
5023           END IF;
5024 
5025           RAISE fnd_api.g_exc_unexpected_error;
5026         END IF;
5027       END IF;
5028 
5029       l_progress := '33';
5030 
5031       -- should we be updating the org for the lpn here instead of in the lpnexit??????
5032       l_progress := '35';
5033 
5034       SELECT unit_of_measure
5035         INTO l_unit_of_measure
5036         FROM mtl_item_uoms_view
5037        WHERE uom_code = l_uom_code
5038          AND organization_id = p_organization_id
5039          AND inventory_item_id = l_inventory_item_id;
5040 
5041       l_progress := '40';
5042 
5043       IF (l_debug = 1) THEN
5044         print_debug('create_asn_exp_rcpt_intf_rec: 20.1 before populate_lot_rec : ', 4);
5045         print_debug('l_lot_number => ' || l_lot_number, 4);
5046         print_debug('l_quantity => ' || l_quantity, 4);
5047         print_debug('l_uom_code => ' || l_uom_code, 4);
5048         print_debug('p_organization_id => ' || p_organization_id, 4);
5049         print_debug('l_inventory_item_id => ' || l_inventory_item_id, 4);
5050       END IF;
5051 
5052       populate_lot_rec(
5053         p_lot_number       => l_lot_number
5054       , p_primary_qty      => l_quantity
5055       , p_txn_uom_code     => l_uom_code
5056       , p_org_id           => p_organization_id
5057       , p_item_id          => l_inventory_item_id
5058       );
5059       l_progress := '50';
5060 
5061       --Create the MTLI and MSNI records for the lots and serials in the LPN
5062         IF l_lot_control_code > 1 THEN
5063           IF l_lot_number IS NOT NULL THEN
5064             --Convert the lot quantity into Item's Primary UOM code
5065             IF l_uom_code <> l_primary_uom_code THEN
5066 	       l_lot_prm_quantity := inv_rcv_cache.convert_qty
5067 		                        (p_inventory_item_id  => l_inventory_item_id
5068 					 ,p_from_qty          => l_quantity
5069 					 ,p_from_uom_code     => l_uom_code
5070 					 ,p_to_uom_code       => l_primary_uom_code);
5071 
5072 	      --Check for failure
5073               IF l_lot_prm_quantity = -99999 THEN
5074                 fnd_message.set_name('INV', 'INV_INT_UOMCONVCODE');
5075                 fnd_msg_pub.ADD;
5076                 IF (l_debug = 1) THEN
5077                   print_debug('create_asn_exp_rcpt_intf_rec: 20.2 - txn/primary uom conversion failed', 4);
5078                 END IF;
5079                 RAISE fnd_api.g_exc_error;
5080               END IF;   --END IF check for failure
5081 
5082             ELSE
5083               l_lot_prm_quantity := l_quantity;
5084             END IF;
5085 
5086             --Get the lot expiration date
5087             SELECT  expiration_date
5088                    , status_id
5089             INTO     l_expiration_date
5090                    , l_lot_status_id
5091             FROM mtl_lot_numbers
5092             WHERE inventory_item_id = l_inventory_item_id
5093             AND organization_id = l_lpn_org
5094             AND lot_number = l_lot_number;
5095 
5096             IF ((p_source_type = 'INTERNAL') AND (l_lpn_org <> p_organization_id)) THEN
5097               l_from_org_id := l_lpn_org;
5098             ELSE
5099               l_from_org_id := p_organization_id;
5100             END IF;
5101 
5102             --Create MTLI record for the lot and the lot quantity for this content
5103             --Set the flag for the API to populate the lot attributes
5104             inv_rcv_integration_apis.insert_mtli(
5105                 p_api_version                 =>  1.0
5106               , p_init_msg_lst                =>  FND_API.G_FALSE
5107               , x_return_status               =>  l_return_status
5108               , x_msg_count                   =>  l_msg_count
5109               , x_msg_data                    =>  l_msg_data
5110               , p_transaction_interface_id    =>  l_transaction_interface_id
5111               , p_lot_number                  =>  l_lot_number
5112               , p_transaction_quantity        =>  l_quantity
5113               , p_primary_quantity            =>  l_lot_prm_quantity
5114               , p_organization_id             =>  l_from_org_id
5115               , p_inventory_item_id           =>  l_inventory_item_id
5116               , p_expiration_date             =>  l_expiration_date
5117               , p_status_id                   =>  l_lot_status_id
5118               , x_serial_transaction_temp_id  =>  l_serial_transaction_temp_id
5119               , p_product_transaction_id      =>  l_product_transaction_id
5120               , p_product_code                =>  'RCV'
5121               , p_att_exist                   =>  'Y'
5122               , p_update_mln                  =>  'N'
5123             );
5124 
5125             IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5126               IF (l_debug = 1) THEN
5127                 print_debug('create_asn_exp_rcpt_intf_rec 20.3: Error in MTLI creation', 4);
5128               END IF;
5129               RAISE FND_API.G_EXC_ERROR;
5130             END IF;
5131 
5132             IF (l_debug = 1) THEN
5133               print_debug('create_asn_exp_rcpt_intf_rec 20.4 : txn i/f id: ' || l_transaction_interface_id
5134                             || ' serial temp : ' || l_serial_transaction_temp_id || ' prod txn id: ' || l_product_transaction_id, 4);
5135             END IF;
5136           END IF;   --END IF l_lot_number IS NOT NULL
5137 
5138           --Create MSNI records for the serials within lots
5139           --Bug #3405320
5140           --Create MSNI records even if serial control code is dynamic at SO Issue in
5141           --receiving org if there are serials shipped
5142           IF ((l_serial_control_code IN (2, 5)) OR
5143               (l_serial_control_code = 6 AND p_source_type = 'INTERNAL')) THEN
5144             -- bug 3196554
5145             OPEN l_curs_serial_number(l_inventory_item_id, l_revision, l_lot_number, l_lpn_id);
5146             --Loop through the serials in the lot
5147             LOOP
5148               FETCH l_curs_serial_number INTO l_serial_number, l_serial_status_id;
5149               EXIT WHEN l_curs_serial_number%NOTFOUND;
5150               --For each serial number in the lot create one MSNI record. The
5151               --serial attributes would be populated by the API
5152               IF (l_debug = 1) THEN
5153                 print_debug('create_asn_exp_rcpt_intf_rec 20.4.1: Before MSNI creation', 4);
5154               END IF;
5155               inv_rcv_integration_apis.insert_msni(
5156                   p_api_version                 =>  1.0
5157                 , p_init_msg_lst                =>  FND_API.G_FALSE
5158                 , x_return_status               =>  l_return_status
5159                 , x_msg_count                   =>  l_msg_count
5160                 , x_msg_data                    =>  l_msg_data
5161                 , p_transaction_interface_id    =>  l_serial_transaction_temp_id
5162                 , p_fm_serial_number            =>  l_serial_number
5163                 , p_to_serial_number            =>  l_serial_number
5164                 , p_organization_id             =>  p_organization_id
5165                 , p_inventory_item_id           =>  l_inventory_item_id
5166                 , p_status_id                   =>  l_serial_status_id
5167                 , p_product_transaction_id      =>  l_product_transaction_id
5168                 , p_product_code                =>  'RCV'
5169                 , p_att_exist                   =>  'Y'
5170                 , p_update_msn                  =>  'N'
5171               );
5172 
5173               IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5174                 IF (l_debug = 1) THEN
5175                   print_debug('create_asn_exp_rcpt_intf_rec 20.5: Error in MSNI creation', 4);
5176                 END IF;
5177                 RAISE FND_API.G_EXC_ERROR;
5178               END IF;
5179             END LOOP;   --END LOOP through serials for the lot
5180 
5181             --Close the serial cursor
5182             IF l_curs_serial_number%ISOPEN THEN
5183               CLOSE l_curs_serial_number;
5184             END IF;
5185           END IF;   --END IF item is lot and serial controlled
5186 
5187         --If the item is serial controlled, loop through the serials within
5188         --the LPN and create one MSNI record for each serial number
5189         --The attributes for each serial number would be fetched by the API
5190         ELSIF (l_serial_control_code IN (2, 5) OR
5191                (l_serial_control_code = 6 AND p_source_type = 'INTERNAL')) THEN
5192           -- bug 3196554
5193           OPEN l_curs_serial_number(l_inventory_item_id, l_revision, l_lot_number, l_lpn_id);
5194           --Loop through the serials in the lot
5195           LOOP
5196             FETCH l_curs_serial_number INTO l_serial_number, l_serial_status_id;
5197             EXIT WHEN l_curs_serial_number%NOTFOUND;
5198             --For each serial number in the lot create one MSNI record. The
5199             --serial attributes would be populated by the API
5200             IF (l_debug = 1) THEN
5201               print_debug('create_asn_exp_rcpt_intf_rec 20.5.1: Before MSNI creation', 4);
5202             END IF;
5203             inv_rcv_integration_apis.insert_msni(
5204                 p_api_version                 =>  1.0
5205               , p_init_msg_lst                =>  FND_API.G_FALSE
5206               , x_return_status               =>  l_return_status
5207               , x_msg_count                   =>  l_msg_count
5208               , x_msg_data                    =>  l_msg_data
5209               , p_transaction_interface_id    =>  l_transaction_interface_id
5210               , p_fm_serial_number            =>  l_serial_number
5211               , p_to_serial_number            =>  l_serial_number
5212               , p_organization_id             =>  p_organization_id
5213               , p_inventory_item_id           =>  l_inventory_item_id
5214               , p_status_id                   =>  l_serial_status_id
5215               , p_product_transaction_id      =>  l_product_transaction_id
5216               , p_product_code                =>  'RCV'
5217               , p_att_exist                   =>  'Y'
5218               , p_update_msn                  =>  'N'
5219             );
5220 
5221             IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5222               IF (l_debug = 1) THEN
5223                 print_debug('create_asn_exp_rcpt_intf_rec 20.6: Error in MSNI creation', 4);
5224               END IF;
5225               RAISE FND_API.G_EXC_ERROR;
5226             END IF;
5227             IF (l_debug = 1) THEN
5228               print_debug('create_asn_exp_rcpt_intf_rec 20.7 : txn i/f id: ' || l_transaction_interface_id || ' prod txn id: ' || l_product_transaction_id, 4);
5229             END IF;
5230           END LOOP;   --END LOOP through serials for the lot
5231 
5232           --Close the serial cursor
5233           IF l_curs_serial_number%ISOPEN THEN
5234             CLOSE l_curs_serial_number;
5235           END IF;
5236         END IF;    --END IF check lot and serial control codes
5237 
5238       IF (l_debug = 1) THEN
5239         print_debug('create_asn_exp_rcpt_intf_rec: 30 before create_asn_con_rcpt_intf_rec'
5240           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5241         , 4);
5242       END IF;
5243 
5244       create_asn_con_rcpt_intf_rec(
5245         p_move_order_header_id     => p_move_order_header_id
5246       , p_organization_id          => p_organization_id
5247       , p_shipment_header_id       => p_shipment_header_id
5248       , p_po_header_id             => l_po_header_id
5249       , p_item_id                  => l_inventory_item_id
5250       , p_location_id              => p_location_id
5251       , p_rcv_qty                  => l_quantity
5252       , p_rcv_uom                  => l_unit_of_measure
5253       , p_rcv_uom_code             => l_uom_code
5254       , p_source_type              => p_source_type
5255       , p_from_lpn_id              => l_lpn_id
5256       , p_lpn_id                   => l_lpn_id
5257       , p_lot_control_code         => l_lot_control_code
5258       , p_revision                 => l_revision
5259       , p_inspect                  => p_inspect
5260       , x_status                   => l_return_status
5261       , x_message                  => l_msg_data
5262       , p_item_desc                => NULL
5263       , p_project_id               => p_project_id
5264       , p_task_id                  => p_task_id
5265       , p_rcv_subinventory_code    => p_rcv_subinventory_code -- RCVLOCATORSSUPPORT
5266       , p_rcv_locator_id           => p_rcv_locator_id
5267       , p_original_rti_id          => l_product_transaction_id
5268       , p_attribute_category        => p_attribute_category  --Bug #4147209
5269       , p_attribute1                => p_attribute1
5270       , p_attribute2                => p_attribute2
5271       , p_attribute3                => p_attribute3
5272       , p_attribute4                => p_attribute4
5273       , p_attribute5                => p_attribute5
5274       , p_attribute6                => p_attribute6
5275       , p_attribute7                => p_attribute7
5276       , p_attribute8                => p_attribute8
5277       , p_attribute9                => p_attribute9
5278       , p_attribute10               => p_attribute10
5279       , p_attribute11               => p_attribute11
5280       , p_attribute12               => p_attribute12
5281       , p_attribute13               => p_attribute13
5282       , p_attribute14               => p_attribute14
5283       , p_attribute15               => p_attribute15
5284       , p_express_transaction       => 'Y'
5285       );
5286 
5287       IF l_return_status = fnd_api.g_ret_sts_error THEN
5288         fnd_message.set_name('INV', 'INV_RCV_CREATE_ASNEXP_RTI_FAIL');
5289         fnd_msg_pub.ADD;
5290 
5291         IF (l_debug = 1) THEN
5292           print_debug(
5293                'create_asn_exp_rcpt_intf_rec 40.1:create_asn_con_rcpt_intf_rec  RAISE FND_API.G_EXC_ERROR;'
5294             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5295           , 4
5296           );
5297         END IF;
5298 
5299         RAISE fnd_api.g_exc_error;
5300       END IF;
5301 
5302       IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5303         fnd_message.set_name('INV', 'INV_RCV_CREATE_ASNEXP_RTI_FAIL');
5304         fnd_msg_pub.ADD;
5305 
5306         IF (l_debug = 1) THEN
5307           print_debug(
5308                'create_asn_exp_rcpt_intf_rec 40.2: create_asn_con_rcpt_intf_rec RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
5309             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5310           , 4
5311           );
5312         END IF;
5313 
5314         RAISE fnd_api.g_exc_unexpected_error;
5315       END IF;
5316 
5317       IF (l_debug = 1) THEN
5318         print_debug('create_asn_exp_rcpt_intf_rec: 50 after create_asn_con_rcpt_intf_rec'
5319           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5320         , 4);
5321       END IF;
5322     END LOOP;   --END LOOP fetch LPN contents
5323 
5324     -- insert WLPNI for FromLPN with parent as NULL.
5325       IF (l_debug = 1) THEN
5326         print_debug(
5327              'create_asn_exp_dd_intf_rec: 50.1 - Before inserting into wlpni for p_lpn_id with parent NULL '
5328           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5329         , 4
5330         );
5331       END IF;
5332 
5333       IF ((p_source_type = 'INTERNAL') AND (l_lpn_org <> p_organization_id)) THEN
5334         l_from_org_id := l_lpn_org;
5335       ELSE
5336         l_from_org_id := p_organization_id;
5337       END IF;
5338 
5339       -- Nested LPN changes. Insert WLPNI
5340       inv_rcv_integration_apis.insert_wlpni(
5341           p_api_version           => 1.0
5342          ,x_return_status         => l_return_status
5343          ,x_msg_count             => l_msg_count
5344          ,x_msg_data              => l_msg_data
5345          ,p_organization_id       => l_from_org_id --BUG 4096028: Should use from org_id
5346          ,p_lpn_id                => p_lpn_id
5347          ,p_license_plate_number  => NULL
5348          ,p_lpn_group_id          => inv_rcv_common_apis.g_rcv_global_var.interface_group_id
5349          ,p_parent_lpn_id         => NULL
5350          );
5351 
5352       IF l_return_status = fnd_api.g_ret_sts_error THEN
5353         fnd_message.set_name('INV', 'INV_RCV_CREATE_ASNEXP_RTI_FAIL');
5354         fnd_msg_pub.ADD;
5355 
5356         IF (l_debug = 1) THEN
5357           print_debug('create_asn_exp_dd_intf_rec 50.2:create_asn_con_dd_intf_rec -  RAISE FND_API.G_EXC_ERROR after insert_wlpni;'|| TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
5358         END IF;
5359 
5360         RAISE fnd_api.g_exc_error;
5361       END IF;
5362 
5363       IF (l_debug = 1) THEN
5364         print_debug(
5365              'create_asn_exp_dd_intf_rec: 50.3 - After inserting into wlpni for p_lpn_id with parent NULL '
5366           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5367         , 4
5368         );
5369       END IF;
5370 
5371     l_progress := '60';
5372 
5373     IF l_curs_asn_lpn_content%ISOPEN THEN
5374       CLOSE l_curs_asn_lpn_content;
5375     END IF;
5376 
5377     l_progress := '70';
5378 
5379     IF (l_debug = 1) THEN
5380       print_debug('Exit create_asn_exp_rcpt_intf_rec: 70 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
5381     END IF;
5382   EXCEPTION
5383     WHEN fnd_api.g_exc_error THEN
5384       x_status := fnd_api.g_ret_sts_error;
5385 
5386       IF l_curs_asn_lpn_content%ISOPEN THEN
5387         CLOSE l_curs_asn_lpn_content;
5388       END IF;
5389 
5390       IF l_curs_serial_number%ISOPEN THEN
5391         CLOSE l_curs_serial_number;
5392       END IF;
5393 
5394       fnd_msg_pub.count_and_get(
5395           p_encoded => fnd_api.g_false
5396         , p_count => l_msg_count
5397         , p_data => x_message);
5398 
5399       IF (l_debug = 1) THEN
5400         print_debug('create_asn_exp_rcpt_intf_rec:  FND_API.g_exc_error ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5401       END IF;
5402     WHEN fnd_api.g_exc_unexpected_error THEN
5403       x_status := fnd_api.g_ret_sts_unexp_error;
5404 
5405       IF l_curs_asn_lpn_content%ISOPEN THEN
5406         CLOSE l_curs_asn_lpn_content;
5407       END IF;
5408 
5409       IF l_curs_serial_number%ISOPEN THEN
5410         CLOSE l_curs_serial_number;
5411       END IF;
5412 
5413       fnd_msg_pub.count_and_get(
5414           p_encoded => fnd_api.g_false
5415         , p_count => l_msg_count
5416         , p_data => x_message);
5417 
5418       IF (l_debug = 1) THEN
5419         print_debug('create_asn_exp_rcpt_intf_rec: fnd_api.g_exc_unexpected_error ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5420       END IF;
5421     WHEN OTHERS THEN
5422       x_status := fnd_api.g_ret_sts_unexp_error;
5423 
5424       IF l_curs_asn_lpn_content%ISOPEN THEN
5425         CLOSE l_curs_asn_lpn_content;
5426       END IF;
5427 
5428       IF l_curs_serial_number%ISOPEN THEN
5429         CLOSE l_curs_serial_number;
5430       END IF;
5431 
5432       IF SQLCODE IS NOT NULL THEN
5433         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.create_asn_exp_rcpt_intf_rec', l_progress, SQLCODE);
5434       END IF;
5435 
5436       fnd_msg_pub.count_and_get(
5437           p_encoded => fnd_api.g_false
5438         , p_count => l_msg_count
5439         , p_data => x_message);
5440 
5441       IF (l_debug = 1) THEN
5442         print_debug('create_asn_exp_rcpt_intf_rec: Other exception ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5443       END IF;
5444   END create_asn_exp_rcpt_intf_rec;
5445 
5446   /* FP-J Lot/Serial Support
5447    * Added a new parameter p_original_rti_id to store the product_transaction_id
5448    * passed from the UI to split the lots and serials based on RTI quantity
5449    */
5450   PROCEDURE create_std_rcpt_intf_rec(
5451     p_move_order_header_id   IN OUT NOCOPY  NUMBER
5452   , p_organization_id        IN             NUMBER
5453   , p_po_header_id           IN             NUMBER
5454   , p_po_release_number_id   IN             NUMBER
5455   , p_po_line_id             IN             NUMBER
5456   , p_shipment_header_id     IN             NUMBER
5457   , p_req_header_id          IN             NUMBER
5458   , p_oe_order_header_id     IN             NUMBER
5459   , p_item_id                IN             NUMBER
5460   , p_location_id            IN             NUMBER
5461   , p_rcv_qty                IN             NUMBER
5462   , p_rcv_uom                IN             VARCHAR2
5463   , p_rcv_uom_code           IN             VARCHAR2
5464   , p_source_type            IN             VARCHAR2
5465   , p_from_lpn_id            IN             NUMBER
5466   , p_lpn_id                 IN             NUMBER
5467   , p_lot_control_code       IN             NUMBER
5468   , p_revision               IN             VARCHAR2
5469   , p_inspect                IN             NUMBER
5470   , x_status                 OUT NOCOPY     VARCHAR2
5471   , x_message                OUT NOCOPY     VARCHAR2
5472   , p_inv_item_id            IN             NUMBER    DEFAULT NULL
5473   , p_item_desc              IN             VARCHAR2  DEFAULT NULL
5474   , p_project_id             IN             NUMBER    DEFAULT NULL
5475   , p_task_id                IN             NUMBER    DEFAULT NULL
5476   , p_country_code           IN             VARCHAR2  DEFAULT NULL
5477   , p_rcv_subinventory_code  IN             VARCHAR2  DEFAULT NULL --RCVLOCATORSSUPPORT
5478   , p_rcv_locator_id         IN             NUMBER    DEFAULT NULL
5479   , p_original_rti_id        IN             NUMBER    DEFAULT NULL
5480   --OPM convergence
5481   , p_secondary_uom          IN             VARCHAR2 DEFAULT NULL
5482   , p_secondary_uom_code     IN             VARCHAR2 DEFAULT NULL
5483   , p_secondary_quantity          IN             NUMBER   DEFAULT NULL
5484  , p_attribute_category     IN             VARCHAR2  DEFAULT NULL  --Bug #4147209 - Added DFF cols
5485   , p_attribute1             IN             VARCHAR2  DEFAULT NULL
5486   , p_attribute2             IN             VARCHAR2  DEFAULT NULL
5487   , p_attribute3             IN             VARCHAR2  DEFAULT NULL
5488   , p_attribute4             IN             VARCHAR2  DEFAULT NULL
5489   , p_attribute5             IN             VARCHAR2  DEFAULT NULL
5490   , p_attribute6             IN             VARCHAR2  DEFAULT NULL
5491   , p_attribute7             IN             VARCHAR2  DEFAULT NULL
5492   , p_attribute8             IN             VARCHAR2  DEFAULT NULL
5493   , p_attribute9             IN             VARCHAR2  DEFAULT NULL
5494   , p_attribute10            IN             VARCHAR2  DEFAULT NULL
5495   , p_attribute11            IN             VARCHAR2  DEFAULT NULL
5496   , p_attribute12            IN             VARCHAR2  DEFAULT NULL
5497   , p_attribute13            IN             VARCHAR2  DEFAULT NULL
5498   , p_attribute14            IN             VARCHAR2  DEFAULT NULL
5499   , p_attribute15            IN             VARCHAR2  DEFAULT NULL
5500   ) IS
5501     l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
5502     l_msg_count     NUMBER;
5503     l_msg_data      VARCHAR2(4000);
5504     l_progress      VARCHAR2(10);
5505     l_label_status  VARCHAR2(500);
5506     l_txn_id_tbl    inv_label.transaction_id_rec_type;
5507     l_counter       NUMBER                            := 0;
5508 
5509 -- For LCM
5510     l_tx_type       VARCHAR2(40);
5511 -- END FOR LCM
5512 
5513     /* Bug 2200851 */
5514     /* Changed min to max */
5515     /* Group BY LPN_ID is changed for Express Receipts */
5516     /* Also  duplicate print of LPN labels is avoided */
5517     CURSOR c_rti_txn_id IS
5518       SELECT   MAX(rti.interface_transaction_id)
5519           FROM rcv_transactions_interface rti
5520          WHERE rti.GROUP_ID = inv_rcv_common_apis.g_rcv_global_var.interface_group_id
5521       GROUP BY DECODE(p_source_type,
5522                           'ASNEXP', rti.interface_transaction_id
5523                         , 'SHIPMENTEXP', rti.interface_transaction_id, NULL);
5524 
5525     -- GROUP BY rti.lpn_id;
5526     l_debug         NUMBER   := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5527   BEGIN
5528     x_status := fnd_api.g_ret_sts_success;
5529     l_progress := '10';
5530 
5531     IF (l_debug = 1) THEN
5532       print_debug('create_std_rcpt_intf_rec: 1' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5533       print_debug('original_rti_id: ' || p_original_rti_id, 4);
5534 print_debug(p_secondary_uom,1);
5535 print_debug(p_secondary_uom_code,1);
5536 print_debug(p_secondary_quantity,1);
5537     END IF;
5538 
5539     IF inv_rcv_common_apis.g_po_startup_value.sob_id IS NULL THEN
5540        --BUG 3444210: For performance reason, use the follow query
5541        --instead of gl_sets_of_books
5542        SELECT TO_NUMBER(hoi.org_information1)
5543    INTO inv_rcv_common_apis.g_po_startup_value.sob_id
5544    FROM hr_organization_information hoi
5545    WHERE hoi.organization_id = p_organization_id
5546    AND (hoi.org_information_context || '') = 'Accounting Information';
5547     END IF;
5548 
5549     l_progress := '15';
5550     -- first check if the transaction date satisfies the validation.
5551     inv_rcv_common_apis.validate_trx_date(
5552       p_trx_date            => SYSDATE
5553     , p_organization_id     => p_organization_id
5554     , p_sob_id              => inv_rcv_common_apis.g_po_startup_value.sob_id
5555     , x_return_status       => x_status
5556     , x_error_code          => x_message
5557     );
5558 
5559     IF x_status <> fnd_api.g_ret_sts_success THEN
5560       RETURN;
5561     END IF;
5562 
5563     x_status := fnd_api.g_ret_sts_success;
5564     IF p_source_type = 'VENDOR' THEN
5565       IF (l_debug = 1) THEN
5566         print_debug('create_std_rcpt_intf_rec: 2 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5567       END IF;
5568 
5569       l_progress := '20';
5570       create_po_rcpt_intf_rec(
5571         p_move_order_header_id      => p_move_order_header_id
5572       , p_organization_id           => p_organization_id
5573       , p_po_header_id              => p_po_header_id
5574       , p_po_release_number_id      => p_po_release_number_id
5575       , p_po_line_id                => p_po_line_id
5576       , p_item_id                   => p_item_id
5577       , p_location_id               => p_location_id
5578       , p_rcv_qty                   => p_rcv_qty
5579       , p_rcv_uom                   => p_rcv_uom
5580       , p_rcv_uom_code              => p_rcv_uom_code
5581       , p_source_type               => p_source_type
5582       , p_lpn_id                    => p_lpn_id
5583       , p_lot_control_code          => p_lot_control_code
5584       , p_revision                  => p_revision
5585       , p_inspect                   => p_inspect
5586       , x_status                    => l_return_status
5587       , x_message                   => l_msg_data
5588       , p_inv_item_id               => p_inv_item_id
5589       , p_item_desc                 => p_item_desc
5590       , p_project_id                => p_project_id
5591       , p_task_id                   => p_task_id
5592       , p_country_code              => p_country_code
5593       , p_rcv_subinventory_code     => p_rcv_subinventory_code --RCVLOCATORSSUPPORT
5594       , p_rcv_locator_id            => p_rcv_locator_id
5595       , p_original_rti_id           => p_original_rti_id  --Lot/Serial Support
5596       --OPM convergence
5597       , p_secondary_uom             => p_secondary_uom
5598       , p_secondary_uom_code        => p_secondary_uom_code
5599       , p_secondary_quantity             => p_secondary_quantity
5600       , p_attribute_category        => p_attribute_category  --Bug #4147209
5601       , p_attribute1                => p_attribute1
5602       , p_attribute2                => p_attribute2
5603       , p_attribute3                => p_attribute3
5604       , p_attribute4                => p_attribute4
5605       , p_attribute5                => p_attribute5
5606       , p_attribute6                => p_attribute6
5607       , p_attribute7                => p_attribute7
5608       , p_attribute8                => p_attribute8
5609       , p_attribute9                => p_attribute9
5610       , p_attribute10               => p_attribute10
5611       , p_attribute11               => p_attribute11
5612       , p_attribute12               => p_attribute12
5613       , p_attribute13               => p_attribute13
5614       , p_attribute14               => p_attribute14
5615       , p_attribute15               => p_attribute15
5616       );
5617 
5618       IF l_return_status = fnd_api.g_ret_sts_error THEN
5619         fnd_message.set_name('INV', 'INV_RCV_CREATE_PO_RTI_FAIL'); -- MSGTBD
5620         fnd_msg_pub.ADD;
5621 
5622         IF (l_debug = 1) THEN
5623           print_debug(
5624                'create_std_rcpt_intf_rec 2.1:  create_po_rcpt_intf_rec RAISE FND_API.G_EXC_ERROR;'
5625             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5626           , 4
5627           );
5628         END IF;
5629 
5630         RAISE fnd_api.g_exc_error;
5631       END IF;
5632 
5633       IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5634         fnd_message.set_name('INV', 'INV_RCV_CREATE_PO_RTI_FAIL'); -- MSGTBD
5635         fnd_msg_pub.ADD;
5636 
5637         IF (l_debug = 1) THEN
5638           print_debug(
5639                'create_std_rcpt_intf_rec 2.2: create_po_rcpt_intf_rec FND_API.G_EXC_UNEXPECTED_ERROR;'
5640             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5641           , 4
5642           );
5643         END IF;
5644 
5645         RAISE fnd_api.g_exc_unexpected_error;
5646       END IF;
5647     ELSIF p_source_type = 'INTERNAL' THEN
5648       l_progress := '30';
5649 
5650       IF (l_debug = 1) THEN
5651         print_debug('create_std_rcpt_intf_rec: 3 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5652       END IF;
5653 
5654       create_intship_rcpt_intf_rec(
5655         p_move_order_header_id      => p_move_order_header_id
5656       , p_organization_id           => p_organization_id
5657       , p_shipment_header_id        => p_shipment_header_id
5658       , p_req_header_id             => p_req_header_id
5659       , p_item_id                   => p_item_id
5660       , p_location_id               => p_location_id
5661       , p_rcv_qty                   => p_rcv_qty
5662       , p_rcv_uom                   => p_rcv_uom
5663       , p_rcv_uom_code              => p_rcv_uom_code
5664       , p_source_type               => p_source_type
5665       , p_from_lpn_id               => p_from_lpn_id
5666       , p_lpn_id                    => p_lpn_id
5667       , p_lot_control_code          => p_lot_control_code
5668       , p_revision                  => p_revision
5669       , p_inspect                   => p_inspect
5670       , x_status                    => l_return_status
5671       , x_message                   => l_msg_data
5672       , p_project_id                => p_project_id
5673       , p_task_id                   => p_task_id
5674       , p_country_code              => p_country_code
5675       , p_rcv_subinventory_code     => p_rcv_subinventory_code -- RCVLOCATORSSUPPORT
5676       , p_rcv_locator_id            => p_rcv_locator_id
5677       , p_original_rti_id           => p_original_rti_id  --Lot/Serial Support
5678       --OPM convergence
5679       , p_secondary_uom             => p_secondary_uom
5680       , p_secondary_uom_code        => p_secondary_uom_code
5681       , p_secondary_quantity             => p_secondary_quantity
5682       , p_attribute_category        => p_attribute_category  --Bug #4147209
5683       , p_attribute1                => p_attribute1
5684       , p_attribute2                => p_attribute2
5685       , p_attribute3                => p_attribute3
5686       , p_attribute4                => p_attribute4
5687       , p_attribute5                => p_attribute5
5688       , p_attribute6                => p_attribute6
5689       , p_attribute7                => p_attribute7
5690       , p_attribute8                => p_attribute8
5691       , p_attribute9                => p_attribute9
5692       , p_attribute10               => p_attribute10
5693       , p_attribute11               => p_attribute11
5694       , p_attribute12               => p_attribute12
5695       , p_attribute13               => p_attribute13
5696       , p_attribute14               => p_attribute14
5697       , p_attribute15               => p_attribute15
5698       );
5699 
5700       IF l_return_status = fnd_api.g_ret_sts_error THEN
5701         fnd_message.set_name('INV', 'INV_RCV_CRT_INSHP_RTI_FAIL'); -- MSGTBD
5702         fnd_msg_pub.ADD;
5703 
5704         IF (l_debug = 1) THEN
5705           print_debug(
5706                'create_std_rcpt_intf_rec 3.1:  create_intship_rcpt_intf_rec RAISE FND_API.G_EXC_ERROR;'
5707             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5708           , 4
5709           );
5710         END IF;
5711 
5712         RAISE fnd_api.g_exc_error;
5713       END IF;
5714 
5715       IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5716         fnd_message.set_name('INV', 'INV_RCV_CRT_INSHP_RTI_FAIL'); -- MSGTBD
5717         fnd_msg_pub.ADD;
5718 
5719         IF (l_debug = 1) THEN
5720           print_debug(
5721                'create_std_rcpt_intf_rec 3.2: create_intship_rcpt_intf_rec FND_API.G_EXC_UNEXPECTED_ERROR;'
5722             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5723           , 4
5724           );
5725         END IF;
5726 
5727         RAISE fnd_api.g_exc_unexpected_error;
5728       END IF;
5729     ELSIF p_source_type = 'CUSTOMER' THEN
5730       l_progress := '40';
5731 
5732       IF (l_debug = 1) THEN
5733         print_debug('create_std_rcpt_intf_rec: 4 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5734       END IF;
5735 
5736       create_rma_rcpt_intf_rec(
5737         p_move_order_header_id      => p_move_order_header_id
5738       , p_organization_id           => p_organization_id
5739       , p_oe_order_header_id        => p_oe_order_header_id
5740       , p_item_id                   => p_item_id
5741       , p_location_id               => p_location_id
5742       , p_rcv_qty                   => p_rcv_qty
5743       , p_rcv_uom                   => p_rcv_uom
5744       , p_rcv_uom_code              => p_rcv_uom_code
5745       , p_source_type               => p_source_type
5746       , p_lpn_id                    => p_lpn_id
5747       , p_lot_control_code          => p_lot_control_code
5748       , p_revision                  => p_revision
5749       , p_inspect                   => p_inspect
5750       , x_status                    => l_return_status
5751       , x_message                   => l_msg_data
5752       , p_project_id                => p_project_id
5753       , p_task_id                   => p_task_id
5754       , p_country_code              => p_country_code
5755       , p_rcv_subinventory_code     => p_rcv_subinventory_code -- RCVLOCATORSSUPPORT
5756       , p_rcv_locator_id            => p_rcv_locator_id
5757       , p_original_rti_id           => p_original_rti_id  --Lot/Serial Support
5758       --OPM convergence
5759       , p_secondary_uom             => p_secondary_uom
5760       , p_secondary_uom_code        => p_secondary_uom_code
5761       , p_secondary_quantity             => p_secondary_quantity
5762       , p_attribute_category        => p_attribute_category  --Bug #4147209
5763       , p_attribute1                => p_attribute1
5764       , p_attribute2                => p_attribute2
5765       , p_attribute3                => p_attribute3
5766       , p_attribute4                => p_attribute4
5767       , p_attribute5                => p_attribute5
5768       , p_attribute6                => p_attribute6
5769       , p_attribute7                => p_attribute7
5770       , p_attribute8                => p_attribute8
5771       , p_attribute9                => p_attribute9
5772       , p_attribute10               => p_attribute10
5773       , p_attribute11               => p_attribute11
5774       , p_attribute12               => p_attribute12
5775       , p_attribute13               => p_attribute13
5776       , p_attribute14               => p_attribute14
5777       , p_attribute15               => p_attribute15
5778       );
5779 
5780       IF l_return_status = fnd_api.g_ret_sts_error THEN
5781         fnd_message.set_name('INV', 'INV_RCV_CREATE_RMA_RTI_FAIL'); -- MSGTBD
5782         fnd_msg_pub.ADD;
5783 
5784         IF (l_debug = 1) THEN
5785           print_debug(
5786                'create_std_rcpt_intf_rec 4.1: create_rma_rcpt_intf_rec  RAISE FND_API.G_EXC_ERROR;'
5787             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5788           , 4
5789           );
5790         END IF;
5791 
5792         RAISE fnd_api.g_exc_error;
5793       END IF;
5794 
5795       IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5796         fnd_message.set_name('INV', 'INV_RCV_CREATE_RMA_RTI_FAIL'); -- MSGTBD
5797         fnd_msg_pub.ADD;
5798 
5799         IF (l_debug = 1) THEN
5800           print_debug(
5801                'create_std_rcpt_intf_rec 4.2: create_rma_rcpt_intf_rec  FND_API.G_EXC_UNEXPECTED_ERROR;'
5802             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5803           , 4
5804           );
5805         END IF;
5806 
5807         RAISE fnd_api.g_exc_unexpected_error;
5808       END IF;
5809     ELSIF p_source_type = 'ASNEXP'
5810           OR p_source_type = 'SHIPMENTEXP'
5811           OR p_source_type = 'SHIPMENT'
5812           OR p_source_type = 'REQEXP' THEN
5813       IF p_source_type = 'ASNEXP' THEN
5814         l_progress := '50';
5815 
5816         IF (l_debug = 1) THEN
5817           print_debug(
5818             'create_std_rcpt_intf_rec: 5 - calling  create_asn_exp_rcpt_intf_rec for ASN' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5819           , 1
5820           );
5821         END IF;
5822 
5823         create_asn_exp_rcpt_intf_rec(
5824           p_move_order_header_id     => p_move_order_header_id
5825         , p_organization_id          => p_organization_id
5826         , p_shipment_header_id       => p_shipment_header_id
5827         , p_po_header_id             => p_po_header_id
5828         , p_location_id              => p_location_id
5829         , p_source_type              => 'ASN'
5830         , p_lpn_id                   => p_from_lpn_id
5831         , p_inspect                  => p_inspect
5832         , x_status                   => l_return_status
5833         , x_message                  => l_msg_data
5834         , p_project_id               => p_project_id
5835         , p_task_id                  => p_task_id
5836         , p_rcv_subinventory_code    => p_rcv_subinventory_code -- RCVLOCATORSSUPPORT
5837         , p_rcv_locator_id           => p_rcv_locator_id
5838         , p_attribute_category        => p_attribute_category  --Bug #4147209
5839         , p_attribute1                => p_attribute1
5840         , p_attribute2                => p_attribute2
5841         , p_attribute3                => p_attribute3
5842         , p_attribute4                => p_attribute4
5843         , p_attribute5                => p_attribute5
5844         , p_attribute6                => p_attribute6
5845         , p_attribute7                => p_attribute7
5846         , p_attribute8                => p_attribute8
5847         , p_attribute9                => p_attribute9
5848         , p_attribute10               => p_attribute10
5849         , p_attribute11               => p_attribute11
5850         , p_attribute12               => p_attribute12
5851         , p_attribute13               => p_attribute13
5852         , p_attribute14               => p_attribute14
5853         , p_attribute15               => p_attribute15
5854         );
5855 
5856         IF l_return_status = fnd_api.g_ret_sts_error THEN
5857           fnd_message.set_name('INV', 'INV_RCV_CREATE_ASNEXP_RTI_FAIL'); -- MSGTBD
5858           fnd_msg_pub.ADD;
5859 
5860           IF (l_debug = 1) THEN
5861             print_debug(
5862                  'create_std_rcpt_intf_rec 5.1: create_asn_exp_rcpt_intf_rec  RAISE FND_API.G_EXC_ERROR;'
5863               || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5864             , 4
5865             );
5866           END IF;
5867 
5868           RAISE fnd_api.g_exc_error;
5869         END IF;
5870 
5871         IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5872           fnd_message.set_name('INV', 'INV_RCV_CREATE_ASNEXP_RTI_FAIL'); -- MSGTBD
5873           fnd_msg_pub.ADD;
5874 
5875           IF (l_debug = 1) THEN
5876             print_debug(
5877                  'create_std_rcpt_intf_rec 5.2: create_asn_exp_rcpt_intf_rec  FND_API.G_EXC_UNEXPECTED_ERROR;'
5878               || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5879             , 4
5880             );
5881           END IF;
5882 
5883           RAISE fnd_api.g_exc_unexpected_error;
5884         END IF;
5885       ELSE
5886         l_progress := '50';
5887 
5888         IF (l_debug = 1) THEN
5889           print_debug(
5890                'create_std_rcpt_intf_rec: 6 - calling  create_asn_exp_rcpt_intf_rec for intransit shipment'
5891             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5892           , 1
5893           );
5894         END IF;
5895 
5896         create_asn_exp_rcpt_intf_rec(
5897           p_move_order_header_id     => p_move_order_header_id
5898         , p_organization_id          => p_organization_id
5899         , p_shipment_header_id       => p_shipment_header_id
5900         , p_po_header_id             => p_po_header_id
5901         , p_location_id              => p_location_id
5902         , p_source_type              => 'INTERNAL'
5903         , p_lpn_id                   => p_from_lpn_id
5904         , p_inspect                  => p_inspect
5905         , x_status                   => l_return_status
5906         , x_message                  => l_msg_data
5907         , p_project_id               => p_project_id
5908         , p_task_id                  => p_task_id
5909         , p_rcv_subinventory_code    => p_rcv_subinventory_code -- RCVLOCATORSSUPPORT
5910         , p_rcv_locator_id           => p_rcv_locator_id
5911         );
5912 
5913         IF l_return_status = fnd_api.g_ret_sts_error THEN
5914           fnd_message.set_name('INV', 'INV_RCV_CRT_INSHP_RTI_FAIL'); -- MSGTBD
5915           fnd_msg_pub.ADD;
5916 
5917           IF (l_debug = 1) THEN
5918             print_debug(
5919                  'create_std_rcpt_intf_rec 6.1: create_asn_exp_rcpt_intf_rec for IntShip RAISE FND_API.G_EXC_ERROR;'
5920               || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5921             , 4
5922             );
5923           END IF;
5924 
5925           RAISE fnd_api.g_exc_error;
5926         END IF;
5927 
5928         IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
5929           fnd_message.set_name('INV', 'INV_RCV_CRT_INSHP_RTI_FAIL'); -- MSGTBD
5930           fnd_msg_pub.ADD;
5931 
5932           IF (l_debug = 1) THEN
5933             print_debug(
5934                  'create_std_rcpt_intf_rec 6.2: create_asn_exp_rcpt_intf_rec for IntShip RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
5935               || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
5936             , 4
5937             );
5938           END IF;
5939 
5940           RAISE fnd_api.g_exc_unexpected_error;
5941         END IF;
5942       END IF;
5943 
5944 -- For Bug 7440217 added LCMCONFM also
5945     ELSIF p_source_type IN ('ASNCONFM', 'LCMCONFM') THEN
5946 -- End for Bug 7440217
5947 
5948       l_progress := '60';
5949 
5950 -- For Bug 7440217 added code to handle LCM Doc also
5951       IF p_source_type = 'ASNCONFM' THEN
5952            l_tx_type := 'ASN';
5953       ELSIF p_source_type = 'LCMCONFM' THEN
5954            l_tx_type := 'LCM';
5955       END IF;
5956 -- End for Bug 7440217
5957 
5958       IF (l_debug = 1) THEN
5959         print_debug('create_std_rcpt_intf_rec: 7  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
5960       END IF;
5961 
5962       create_asn_con_rcpt_intf_rec(
5963         p_move_order_header_id      => p_move_order_header_id
5964       , p_organization_id           => p_organization_id
5965       , p_shipment_header_id        => p_shipment_header_id
5966       , p_po_header_id              => p_po_header_id
5967       , p_item_id                   => p_item_id
5968       , p_location_id               => p_location_id
5969       , p_rcv_qty                   => p_rcv_qty
5970       , p_rcv_uom                   => p_rcv_uom
5971       , p_rcv_uom_code              => p_rcv_uom_code
5972 -- For Bug 7440217 Modified code to handle LCM Doc also
5973       , p_source_type               => l_tx_type
5974 -- End for Bug 7440217
5975       , p_from_lpn_id               => p_from_lpn_id
5976       , p_lpn_id                    => p_lpn_id
5977       , p_lot_control_code          => p_lot_control_code
5978       , p_revision                  => p_revision
5979       , p_inspect                   => p_inspect
5980       , x_status                    => l_return_status
5981       , x_message                   => l_msg_data
5982       , p_item_desc                 => p_item_desc
5983       , p_project_id                => p_project_id
5984       , p_task_id                   => p_task_id
5985       , p_country_code              => p_country_code
5986       , p_rcv_subinventory_code     => p_rcv_subinventory_code -- RCVLOCATORSSUPPORT
5987       , p_rcv_locator_id            => p_rcv_locator_id
5988       , p_original_rti_id           => p_original_rti_id  --Lot/Serial Support
5989    /*   --OPM convergence
5990       , p_secondary_uom             => p_secondary_uom
5991       , p_secondary_uom_code        => p_secondary_uom_code
5992       , p_secondary_quantity             => p_secondary_quantity */
5993       , p_attribute_category        => p_attribute_category  --Bug #4147209
5994       , p_attribute1                => p_attribute1
5995       , p_attribute2                => p_attribute2
5996       , p_attribute3                => p_attribute3
5997       , p_attribute4                => p_attribute4
5998       , p_attribute5                => p_attribute5
5999       , p_attribute6                => p_attribute6
6000       , p_attribute7                => p_attribute7
6001       , p_attribute8                => p_attribute8
6002       , p_attribute9                => p_attribute9
6003       , p_attribute10               => p_attribute10
6004       , p_attribute11               => p_attribute11
6005       , p_attribute12               => p_attribute12
6006       , p_attribute13               => p_attribute13
6007       , p_attribute14               => p_attribute14
6008       , p_attribute15               => p_attribute15
6009       , p_express_transaction       => NULL--Bug 5550783
6010       );
6011 
6012       IF l_return_status = fnd_api.g_ret_sts_error THEN
6013         fnd_message.set_name('INV', 'INV_RCV_CRT_ASNCON_RTI_FAIL'); -- MSGTBD
6014         fnd_msg_pub.ADD;
6015 
6016         IF (l_debug = 1) THEN
6017           print_debug(
6018                'create_std_rcpt_intf_rec 7.1: create_asn_con_rcpt_intf_rec RAISE FND_API.G_EXC_ERROR;'
6019             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6020           , 4
6021           );
6022         END IF;
6023 
6024         RAISE fnd_api.g_exc_error;
6025       END IF;
6026 
6027       IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6028         fnd_message.set_name('INV', 'INV_RCV_CRT_INSHP_RTI_FAIL'); -- MSGTBD
6029         fnd_msg_pub.ADD;
6030 
6031         IF (l_debug = 1) THEN
6032           print_debug(
6033                'create_std_rcpt_intf_rec 7.2: create_asn_con_rcpt_intf_rec RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
6034             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6035           , 4
6036           );
6037         END IF;
6038 
6039         RAISE fnd_api.g_exc_unexpected_error;
6040       END IF;
6041     END IF;
6042 
6043     IF (l_debug = 1) THEN
6044       print_debug('create_std_rcpt_intf_rec: 8 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6045     END IF;
6046 
6047     l_progress := '70';
6048     x_status := l_return_status; -- l_return_status can be 'W', we want to carry that over
6049 
6050                                  -- calling label printing API
6051 
6052     IF l_return_status <> fnd_api.g_ret_sts_error THEN
6053       l_progress := '80';
6054 
6055       IF (l_debug = 1) THEN
6056         print_debug('create_std_rcpt_intf_rec: 8.1 before  inv_label.print_label ', 4);
6057       END IF;
6058 
6059       /* FP-J Lot/Serial Support Enhancement
6060        * If INV J and PO J are installed, do not call label printing API at this stage
6061        */
6062       IF ((inv_rcv_common_apis.g_po_patch_level < inv_rcv_common_apis.g_patchset_j_po) OR
6063           (inv_rcv_common_apis.g_inv_patch_level < inv_rcv_common_apis.g_patchset_j))  THEN
6064         IF (p_source_type <> 'VENDOR') THEN    --bug 3630412 for normal PO receipt moved the code to rcv_insert_update_header
6065         l_counter := 1;
6066         OPEN c_rti_txn_id;
6067 
6068         LOOP
6069           FETCH c_rti_txn_id INTO l_txn_id_tbl(l_counter);
6070           EXIT WHEN c_rti_txn_id%NOTFOUND;
6071 
6072           IF (l_debug = 1) THEN
6073             print_debug('create_std_rcpt_intf_rec calling printing for:' || l_txn_id_tbl(l_counter)||'p_source_type'||p_source_type, 4);
6074           END IF;
6075 
6076           l_counter := l_counter + 1;
6077         END LOOP;
6078 
6079         CLOSE c_rti_txn_id;
6080 
6081         inv_label.print_label(
6082           x_return_status          => l_return_status
6083         , x_msg_count              => l_msg_count
6084         , x_msg_data               => l_msg_data
6085         , x_label_status           => l_label_status
6086         , p_api_version            => 1.0
6087         , p_print_mode             => 1
6088         , p_business_flow_code     => 1
6089         , p_transaction_id         => l_txn_id_tbl
6090         );
6091 
6092         IF (l_debug = 1) THEN
6093           print_debug('create_std_rcpt_intf_rec: 8.15 after inv_label.print_label ', 4);
6094         END IF;
6095 
6096         IF l_return_status <> fnd_api.g_ret_sts_success THEN
6097           fnd_message.set_name('INV', 'INV_RCV_CRT_PRINT_LAB_FAIL'); -- MSGTBD
6098           fnd_msg_pub.ADD;
6099           x_status := 'W';
6100 
6101           IF (l_debug = 1) THEN
6102             print_debug('create_std_rcpt_intf_rec 8.2: inv_label.print_label FAILED;' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
6103           END IF;
6104          END IF;
6105   END IF; --bug3630412
6106       ELSE
6107         IF (l_debug = 1) THEN
6108           print_debug('INV J and PO J are installed. NO label printing from UI', 4);
6109         END IF;
6110       END IF;   --END IF check INV J and PO J installed
6111     END IF;
6112 
6113     l_progress := '90';
6114 
6115     IF (l_debug = 1) THEN
6116       print_debug('create_std_rcpt_intf_rec exitting: 9' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6117     END IF;
6118   EXCEPTION
6119     WHEN fnd_api.g_exc_error THEN
6120       x_status := fnd_api.g_ret_sts_error;
6121       IF c_rti_txn_id%ISOPEN THEN
6122         CLOSE c_rti_txn_id;
6123       END IF;
6124       fnd_msg_pub.count_and_get(
6125           p_encoded => fnd_api.g_false
6126         , p_count => l_msg_count
6127         , p_data => x_message);
6128     WHEN fnd_api.g_exc_unexpected_error THEN
6129       x_status := fnd_api.g_ret_sts_unexp_error;
6130       IF c_rti_txn_id%ISOPEN THEN
6131         CLOSE c_rti_txn_id;
6132       END IF;
6133       fnd_msg_pub.count_and_get(
6134           p_encoded => fnd_api.g_false
6135         , p_count => l_msg_count
6136         , p_data => x_message);
6137     WHEN OTHERS THEN
6138       x_status := fnd_api.g_ret_sts_unexp_error;
6139       IF c_rti_txn_id%ISOPEN THEN
6140         CLOSE c_rti_txn_id;
6141       END IF;
6142       IF SQLCODE IS NOT NULL THEN
6143         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.create_std_rcpt_intf_rec', l_progress, SQLCODE);
6144       END IF;
6145       fnd_msg_pub.count_and_get(
6146           p_encoded => fnd_api.g_false
6147         , p_count => l_msg_count
6148         , p_data => x_message);
6149   END create_std_rcpt_intf_rec;
6150 
6151   PROCEDURE create_mo_for_correction(
6152     p_move_order_header_id  IN OUT NOCOPY  NUMBER
6153   , p_po_line_location_id   IN             NUMBER   DEFAULT NULL
6154   , p_po_distribution_id    IN             NUMBER   DEFAULT NULL
6155   , p_shipment_line_id      IN             NUMBER   DEFAULT NULL
6156   , p_oe_order_line_id      IN             NUMBER   DEFAULT NULL
6157   , p_routing               IN             NUMBER
6158   , p_lot_control_code      IN             NUMBER
6159   , p_org_id                IN             NUMBER
6160   , p_item_id               IN             NUMBER
6161   , p_qty                   IN             NUMBER
6162   , p_uom_code              IN             VARCHAR2
6163   , p_lpn                   IN             NUMBER
6164   , p_revision              IN             VARCHAR2 DEFAULT NULL
6165   , p_inspect               IN             NUMBER
6166   , p_txn_source_id         IN             NUMBER
6167   , x_status                OUT NOCOPY     VARCHAR2
6168   , x_message               OUT NOCOPY     VARCHAR2
6169   , p_transfer_org_id       IN             NUMBER   DEFAULT NULL
6170   , p_wms_process_flag      IN             NUMBER   DEFAULT NULL
6171   , p_secondary_qty         IN             NUMBER  DEFAULT NULL --OPM Convergence
6172   , p_secondary_uom         IN             VARCHAR2 DEFAULT NULL --OPM Convergence
6173   ) IS
6174     l_dummy     VARCHAR2(5);
6175     l_object_id NUMBER;
6176     l_msg_count NUMBER;
6177 
6178     CURSOR c_mlt IS
6179       SELECT lot_number
6180            , transaction_quantity
6181            , primary_quantity   -- 3648908
6182            , lot_expiration_date
6183            , transaction_temp_id
6184            , secondary_quantity --OPM Convergence
6185         FROM mtl_transaction_lots_temp
6186        WHERE transaction_temp_id = p_txn_source_id
6187       UNION ALL
6188       SELECT mtln.lot_number
6189            , mtln.transaction_quantity
6190            , mtln.primary_quantity
6191            , TO_DATE(NULL)
6192            , TO_NUMBER(NULL)
6193            , mtln.secondary_transaction_quantity --OPM Convergence
6194         FROM mtl_material_transactions mmt
6195            , mtl_transaction_lot_numbers mtln
6196            , rcv_transactions rt
6197            , rcv_shipment_lines rsl
6198            , mtl_system_items msi
6199        WHERE rt.interface_transaction_id = p_txn_source_id
6200          AND mmt.rcv_transaction_id = rt.transaction_id
6201          AND mmt.transaction_id = mtln.transaction_id
6202          AND(rt.transaction_type = 'RETURN TO RECEIVING'
6203              OR(rt.transaction_type = 'CORRECT'
6204                 AND rt.quantity < 0))
6205          AND msi.lot_control_code = 2
6206          AND EXISTS(SELECT 1
6207                       FROM rcv_transactions rt1
6208                      WHERE rt1.transaction_id = rt.parent_transaction_id
6209                        AND rt1.transaction_type = 'DELIVER')
6210          AND rt.user_entered_flag = 'Y'
6211          AND rsl.shipment_line_id = rt.shipment_line_id
6212          AND msi.inventory_item_id = rsl.item_id
6213          AND msi.organization_id = rt.organization_id;
6214 
6215     /*******************************************************************************
6216      * Bug # : 1922526
6217      * Description:
6218      * Cursor c_mlt in procedure
6219      * create_mo_for_correction is modified
6220      * so that it selects the lot and qty
6221      * from mtln instead of mtlt, if the txn
6222      * is post-inv txn processing, because
6223      * mtlt records will not exist post-inv
6224      * txn processing.
6225      ******************************************************************************/
6226     l_debug     NUMBER      := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6227     l_line_id NUMBER;
6228   BEGIN
6229     IF p_lot_control_code = 2 THEN
6230       g_rcpt_lot_qty_rec_tb.DELETE;
6231 
6232       IF (l_debug = 1) THEN
6233         print_debug('Opening Lots loop ', 1);
6234       END IF;
6235 
6236       FOR i IN c_mlt LOOP
6237         IF (l_debug = 1) THEN
6238           print_debug('Checking if ' || i.lot_number || ' exists', 1);
6239         END IF;
6240 
6241         /* Before creating move orders, lot numbers should exist in
6242         ** mtl_lot_numbers. So, insert the lot number from
6243         ** mtl_transactions_lot_temp into mtl_lot_numbers
6244         ** by calling API INV_LOT_API_PUB.insertLot.
6245         ** This API takes care of populating attributes also.
6246         */
6247         BEGIN
6248           SELECT '1'
6249             INTO l_dummy
6250             FROM mtl_lot_numbers
6251            WHERE lot_number = i.lot_number
6252              AND inventory_item_id = p_item_id
6253        AND organization_id   = p_org_id;  --Added bug3466942
6254 
6255         EXCEPTION
6256           WHEN NO_DATA_FOUND THEN
6257             IF (l_debug = 1) THEN
6258               print_debug('Lot insertion ' || i.lot_number, 1);
6259             END IF;
6260 
6261             inv_lot_api_pub.insertlot(
6262               p_api_version                  => 1.0
6263             , p_init_msg_list                => fnd_api.g_false
6264             , p_commit                       => fnd_api.g_false
6265             , p_validation_level             => fnd_api.g_valid_level_full
6266             , p_inventory_item_id            => p_item_id
6267             , p_organization_id              => p_org_id
6268             , p_lot_number                   => i.lot_number
6269             , p_expiration_date              => i.lot_expiration_date
6270             , p_transaction_temp_id          => i.transaction_temp_id
6271             , p_transaction_action_id        => NULL
6272             , p_transfer_organization_id     => NULL
6273             , x_object_id                    => l_object_id
6274             , x_return_status                => x_status
6275             , x_msg_count                    => l_msg_count
6276             , x_msg_data                     => x_message
6277             );
6278 
6279             IF x_status <> fnd_api.g_ret_sts_success THEN
6280               IF (l_debug = 1) THEN
6281                 print_debug('maintain move order - unable to insert lot ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6282               END IF;
6283 
6284               RETURN;
6285             END IF;
6286 
6287             IF (l_debug = 1) THEN
6288               print_debug('Lot inserted ', 1);
6289             END IF;
6290         END;
6291 
6292          IF (l_debug = 1) THEN
6293             print_debug('p_primary_qty : '|| i.primary_quantity || ' txn_uom : '|| p_uom_code, 1);
6294          END IF;
6295 
6296         populate_lot_rec(
6297           p_lot_number       => i.lot_number
6298         , p_primary_qty      => ABS(i.primary_quantity)
6299         , p_txn_uom_code     => p_uom_code
6300         , p_org_id           => p_org_id
6301         , p_item_id          => p_item_id
6302         , p_secondary_quantity => i.secondary_quantity --OPM Convergence
6303         );
6304       END LOOP;
6305     END IF;
6306 
6307     IF (l_debug = 1) THEN
6308       print_debug('Calling create_move_order ', 1);
6309     END IF;
6310 
6311     create_move_order(
6312       p_move_order_header_id     => p_move_order_header_id
6313     , p_po_line_location_id      => p_po_line_location_id
6314     , p_po_distribution_id       => p_po_distribution_id
6315     , p_shipment_line_id         => p_shipment_line_id
6316     , p_oe_order_line_id         => p_oe_order_line_id
6317     , p_routing                  => p_routing
6318     , p_lot_control_code         => p_lot_control_code
6319     , p_org_id                   => p_org_id
6320     , p_item_id                  => p_item_id
6321     , p_qty                      => p_qty
6322     , p_uom_code                 => p_uom_code
6323     , p_lpn                      => p_lpn
6324     , p_project_id               => NULL
6325     , p_task_id                  => NULL
6326     , p_revision                 => p_revision
6327     , p_inspect                  => p_inspect
6328     , p_txn_source_id            => p_txn_source_id
6329     , x_status                   => x_status
6330     , x_message                  => x_message
6331     , p_transfer_org_id          => p_transfer_org_id
6332     , p_wms_process_flag         => p_wms_process_flag
6333     , p_secondary_quantity       => p_secondary_qty --OPM Convergence
6334     , p_secondary_uom            => p_secondary_uom --OPM Convergence
6335     , x_line_id                  => l_line_id
6336     );
6337     g_rcpt_lot_qty_rec_tb.DELETE;
6338   END create_mo_for_correction;
6339 
6340 
6341 -- For LCM Project  BUG 7702666
6342 PROCEDURE lcm_call_rcv_rtp(
6343     p_lcmOrgID                IN             NUMBER
6344   , p_lcmReceiptNum           IN             VARCHAR2
6345   , x_lcmvalid_status         OUT NOCOPY     VARCHAR2
6346   , x_return_status           OUT NOCOPY     VARCHAR2
6347   , x_msg_data                OUT NOCOPY     VARCHAR2
6348   ) IS
6349 
6350    v_processing_status_code  varchar2(10);
6351 
6352   BEGIN
6353 
6354   SELECT  PROCESSING_STATUS_CODE
6355   INTO    v_processing_status_code
6356   FROM    RCV_TRANSACTIONS_INTERFACE
6357   WHERE   HEADER_INTERFACE_ID in
6358       (SELECT HEADER_INTERFACE_ID
6359        FROM   RCV_HEADERS_INTERFACE
6360        WHERE  receipt_num = p_lcmReceiptNum
6361        AND   SHIP_TO_ORGANIZATION_ID = p_lcmOrgID)
6362   AND     ROWNUM < 2;
6363 
6364    IF nvl(v_processing_status_code, '@@@') = 'LC_PENDING' THEN
6365          x_lcmvalid_status := 'true';
6366          x_return_status := '';
6367          x_msg_data := '';
6368    ELSE
6369          x_lcmvalid_status := 'false';
6370          x_return_status := '';
6371          x_msg_data := '';
6372    END IF;
6373 END lcm_call_rcv_rtp;
6374 -- For LCM Project  BUG 7702666
6375 
6376 
6377   PROCEDURE create_move_order(
6378     p_move_order_header_id  IN OUT NOCOPY  NUMBER
6379   , p_po_line_location_id   IN             NUMBER
6380   , p_po_distribution_id    IN             NUMBER
6381   , p_shipment_line_id      IN             NUMBER
6382   , p_oe_order_line_id      IN             NUMBER
6383   , p_routing               IN             VARCHAR2
6384   , p_lot_control_code      IN             NUMBER
6385   , p_org_id                IN             NUMBER
6386   , p_item_id               IN             NUMBER
6387   , p_qty                   IN             NUMBER
6388   , p_uom_code              IN             VARCHAR2
6389   , p_lpn                   IN             NUMBER
6390   , p_project_id            IN             NUMBER   DEFAULT NULL
6391   , p_task_id               IN             NUMBER   DEFAULT NULL
6392   , p_revision              IN             VARCHAR2 DEFAULT NULL
6393   , p_inspect               IN             NUMBER
6394   , p_txn_source_id         IN             NUMBER
6395   , x_status                OUT NOCOPY     VARCHAR2
6396   , x_message               OUT NOCOPY     VARCHAR2
6397   , p_transfer_org_id       IN             NUMBER   DEFAULT NULL
6398   , p_wms_process_flag      IN             NUMBER   DEFAULT NULL
6399   , p_lot_number            IN             VARCHAR2     DEFAULT NULL
6400   , p_secondary_quantity    IN             NUMBER DEFAULT NULL --OPM Convergence
6401   , p_secondary_uom         IN             VARCHAR2 DEFAULT NULL --OPM Convergence
6402   , x_line_id               OUT NOCOPY     NUMBER
6403     ) IS
6404     l_project_id          NUMBER     := '';
6405     l_task_id             NUMBER     := '';
6406     l_lot_qty_rec_tb      rcpt_lot_qty_rec_tb_tp;
6407     l_line_id             NUMBER;
6408     l_reference           VARCHAR2(2000);
6409     l_reference_type_code NUMBER;
6410     l_reference_id        NUMBER;
6411     l_count               NUMBER;
6412     l_from_cost_group_id  NUMBER;
6413     l_return_status       VARCHAR2(1):= fnd_api.g_ret_sts_success;
6414     l_msg_count           NUMBER;
6415     l_msg_data            VARCHAR2(4000);
6416     l_progress            VARCHAR2(10);
6417     l_wms_process_flag    NUMBER     := 2;
6418     l_debug               NUMBER     := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6419     --Added for bug #3989521
6420     l_po_line_location_id NUMBER := NULL;
6421     l_po_distribution_id  NUMBER := NULL;
6422     l_is_asn              VARCHAR2(1);
6423     l_is_req              VARCHAR2(1) := 'N'; -- Bug 5460505
6424     l_source_document_code  rcv_shipment_lines.source_document_code%TYPE;
6425   BEGIN
6426     IF (l_debug = 1) THEN
6427       print_debug('create_move_order: 1 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6428     END IF;
6429 
6430     x_status := fnd_api.g_ret_sts_success;
6431     l_progress := '10';
6432 
6433     IF p_project_id <> -9999 THEN
6434       l_project_id := p_project_id;
6435       l_task_id := p_task_id;
6436     END IF;
6437 
6438     SAVEPOINT rcv_crt_mo_sp;
6439 
6440     IF p_wms_process_flag IS NOT NULL THEN
6441       l_wms_process_flag := p_wms_process_flag;
6442     END IF;
6443 
6444     --R12: If Shipment_line_id is passed, first checked if it is an ASN
6445     --If it is ASN, then REFERENCE should be SHIPMENT_LINE_ID.  If not,
6446     --Reference should be PO_LINE_LOCATION_ID
6447     IF (p_shipment_line_id IS NOT NULL) THEN
6448        BEGIN
6449 	  SELECT rsl.po_line_location_id,rsl.po_distribution_id,
6450 	    decode(rsh.asn_type,'ASN','Y','N'),Decode(rsh.receipt_source_code,'INTERNAL ORDER','Y','N')
6451           INTO l_po_line_location_id,l_po_distribution_id,l_is_asn,l_is_req
6452           FROM rcv_shipment_lines rsl, rcv_shipment_headers rsh
6453 	  WHERE rsl.shipment_line_id = p_shipment_line_id
6454 	  AND   rsl.shipment_header_id = rsh.shipment_header_id;
6455        EXCEPTION
6456 	  WHEN OTHERS THEN
6457 	     IF (l_debug = 1) THEN
6458 		print_debug( 'create_move_order 4.1: RAISE FND_API.G_EXC_ERROR - ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS') , 4 );
6459 	     END IF;
6460 	     RAISE fnd_api.g_exc_error;
6461        END;
6462 
6463        print_debug( 'create_move_order 4.2 : PLL ID : '||l_po_line_location_id ||
6464 		    '  POD ID : ' || l_po_distribution_id ||
6465 		    '  IS ASN?: ' || l_is_asn,4);
6466 
6467     END IF;
6468 
6469     IF (p_po_line_location_id IS NOT NULL AND l_is_asn = 'N') THEN
6470       IF (l_debug = 1) THEN
6471         print_debug('create_move_order: 2 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
6472       END IF;
6473 
6474       IF p_project_id IS NULL THEN
6475         get_project_task(
6476           p_po_line_location_id     => p_po_line_location_id
6477         , p_oe_order_line_id        => NULL
6478         , x_project_id              => l_project_id
6479         , x_task_id                 => l_task_id
6480         );
6481       END IF;
6482 
6483       l_reference_id := p_po_line_location_id;
6484       l_reference := 'PO_LINE_LOCATION_ID';
6485       l_reference_type_code := 4; -- for purchase orders
6486 
6487       IF (l_debug = 1) THEN
6488         print_debug('create_move_order: 3 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
6489       END IF;
6490     ELSIF p_po_distribution_id IS NOT NULL THEN
6491       --    l_project_id := p_project_id;
6492       --    l_task_id := p_task_id;
6493       l_reference_id := p_po_distribution_id;
6494       l_reference := 'PO_DISTRIBUTION_ID';
6495       l_reference_type_code := 4; -- for purchase orders
6496     ELSIF p_oe_order_line_id IS NOT NULL AND l_is_req = 'N' THEN
6497       IF (l_debug = 1) THEN
6498         print_debug('create_move_order: 5 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
6499       END IF;
6500 
6501       l_reference_id := p_oe_order_line_id;
6502       l_reference_type_code := 7; -- for RMA
6503       get_project_task(
6504         p_po_line_location_id     => NULL
6505       , p_oe_order_line_id        => p_oe_order_line_id
6506       , x_project_id              => l_project_id
6507       , x_task_id                 => l_task_id
6508       );
6509 
6510       IF p_routing = 'DIRECT' THEN
6511         l_reference := 'DIRECT ORDER_LINE_ID';
6512       ELSE
6513         l_reference := 'ORDER_LINE_ID';
6514       END IF;
6515     ELSIF p_shipment_line_id IS NOT NULL THEN
6516       IF (l_debug = 1) THEN
6517         print_debug('create_move_order: 4 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
6518       END IF;
6519 
6520       l_reference_id := p_shipment_line_id;
6521 
6522     BEGIN
6523 	  SELECT po_line_location_id, po_distribution_id, source_document_code
6524           INTO l_po_line_location_id, l_po_distribution_id, l_source_document_code
6525           FROM rcv_shipment_lines
6526           WHERE shipment_line_id = p_shipment_line_id;
6527     EXCEPTION
6528        WHEN OTHERS THEN
6529           IF (l_debug = 1) THEN
6530             print_debug( 'create_move_order 4.1: RAISE FND_API.G_EXC_ERROR - ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS') , 4 );
6531          END IF;
6532 
6533     END;
6534     print_debug( 'create_move_order 4.2 : PLL ID : ' || l_po_line_location_id || '  POD ID : ' || l_po_distribution_id || '  p_shipment_line_id ' || p_shipment_line_id || '  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS') , 4 );
6535 
6536      IF l_po_line_location_id IS NOT NULL OR l_po_distribution_id IS NOT NULL THEN
6537         l_reference_type_code := 4; --Considering the ASN
6538 
6539      ELSIF l_source_document_code = 'INVENTORY' THEN
6540         l_reference_type_code := 6;
6541      ELSE
6542         l_reference_type_code := 8;
6543      END IF;
6544       --End of fix for Bug #3989521
6545 
6546       -- for internal reqs
6547       --???????????????????????????????? Ans:
6548       -- how to populate the project and task ids
6549 
6550       IF p_routing = 'DIRECT' THEN
6551         l_reference := 'DIRECT SHIPMENT_LINE_ID';
6552       ELSE
6553         l_reference := 'SHIPMENT_LINE_ID';
6554       END IF;
6555     END IF;
6556 
6557     l_progress := '20';
6558 
6559     IF p_lot_control_code = 2 THEN
6560       IF (l_debug = 1) THEN
6561         print_debug('create_move_order: 6 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
6562       END IF;
6563 
6564       l_progress := '30';
6565       --If INV and PO J are installed,
6566       -- execute the old split logic else just update the local table
6567       IF ((inv_rcv_common_apis.g_inv_patch_level >= inv_rcv_common_apis.g_patchset_j) AND
6568     (inv_rcv_common_apis.g_po_patch_level  >= inv_rcv_common_apis.g_patchset_j_po)) THEN
6569    IF (l_debug = 1) THEN
6570       print_debug('Calling to insert RHI for J code', 4);
6571    END IF;
6572    l_lot_qty_rec_tb(1).lot_number := p_lot_number;
6573    l_lot_qty_rec_tb(1).txn_quantity := p_qty;
6574        ELSE
6575    split_qty_for_lot(p_qty, l_lot_qty_rec_tb);
6576       END IF;
6577       l_progress := '40';
6578 
6579       FOR i IN 1 .. l_lot_qty_rec_tb.COUNT LOOP
6580         IF (l_debug = 1) THEN
6581           print_debug(
6582             'create_move_order 7: before calling wms_task_dispatch_put_away.create_mo ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6583           , 4
6584           );
6585         END IF;
6586 
6587         IF p_shipment_line_id IS NOT NULL THEN
6588      IF p_lpn IS NOT NULL THEN
6589         BEGIN
6590      SELECT cost_group_id
6591        INTO   l_from_cost_group_id
6592        FROM   wms_lpn_contents wlpnc
6593        WHERE  organization_id = p_org_id
6594        AND    parent_lpn_id = p_lpn
6595        AND    wlpnc.inventory_item_id = p_item_id
6596        AND    Nvl(wlpnc.lot_number,'@@@') = Nvl(l_lot_qty_rec_tb(i).lot_number,Nvl(wlpnc.lot_number,'@@@'))
6597        AND    EXISTS(
6598          SELECT 1
6599          FROM   cst_cost_group_accounts
6600          WHERE  organization_id = p_org_id
6601          AND    cost_group_id = wlpnc.cost_group_id);
6602         EXCEPTION
6603      WHEN OTHERS THEN
6604         l_from_cost_group_id                      := NULL;
6605         END;
6606       ELSE
6607       BEGIN
6608          SELECT cost_group_id
6609            INTO l_from_cost_group_id
6610            FROM rcv_shipment_lines rsl
6611            WHERE shipment_line_id = p_shipment_line_id
6612            AND exists (
6613            SELECT 1
6614            FROM   cst_cost_group_accounts
6615            WHERE  organization_id = p_org_id
6616            AND    cost_group_id = rsl.cost_group_id)
6617            AND ROWNUM = 1;
6618       EXCEPTION
6619          WHEN OTHERS THEN
6620       l_from_cost_group_id := NULL;
6621       END;
6622      END IF;
6623         END IF;
6624 
6625         IF p_project_id = -9999 THEN
6626           l_project_id := NULL;
6627           l_task_id := NULL;
6628         END IF;
6629 
6630         IF (l_debug = 1) THEN
6631           print_debug('create_move_order 7.1 parameters organization -' || p_org_id, 4);
6632           print_debug('create_move_order 7.1 parameters p_item_id -' || p_item_id, 4);
6633           print_debug('create_move_order 7.1 parameters txn_quantity -' || l_lot_qty_rec_tb(i).txn_quantity, 4);
6634           print_debug('create_move_order 7.1 parameters p_uom_code -' || p_uom_code, 4);
6635           print_debug('create_move_order 7.1 parameters p_lpn -' || p_lpn, 4);
6636           print_debug('create_move_order 7.1 parameters l_project_id -' || l_project_id, 4);
6637           print_debug('create_move_order 7.1 parameters l_task_id -' || l_task_id, 4);
6638           print_debug('create_move_order 7.1 parameters l_reference -' || l_reference, 4);
6639           print_debug('create_move_order 7.1 parameters l_reference_type_code -' || l_reference_type_code, 4);
6640           print_debug('create_move_order 7.1 parameters l_reference_id -' || l_reference_id, 4);
6641           print_debug('create_move_order 7.1 parameters lot_number -' || l_lot_qty_rec_tb(i).lot_number, 4);
6642           print_debug('create_move_order 7.1 parameters p_revision -' || p_revision, 4);
6643           print_debug('create_move_order 7.1 parameters p_move_order_header_id -' || p_move_order_header_id, 4);
6644           print_debug('create_move_order 7.1 parameters p_inspect -' || p_inspect, 4);
6645           print_debug('create_move_order 7.1 parameters p_txn_source_id -' || p_txn_source_id, 4);
6646           print_debug('create_move_order 7.1 parameters l_from_cost_group_id -' || l_from_cost_group_id, 4);
6647           print_debug('create_move_order 7.1 parameters p_transfer_org_id -' || p_transfer_org_id, 4);
6648         END IF;
6649 
6650         wms_task_dispatch_put_away.create_mo(
6651           p_org_id                  => p_org_id
6652         , p_inventory_item_id       => p_item_id
6653         , p_qty                     => l_lot_qty_rec_tb(i).txn_quantity
6654         , p_uom                     => p_uom_code
6655         , p_lpn                     => p_lpn
6656         , p_project_id              => l_project_id
6657         , p_task_id                 => l_task_id
6658         , p_reference               => l_reference
6659         , p_reference_type_code     => l_reference_type_code
6660         , p_reference_id            => l_reference_id
6661         , p_lot_number              => l_lot_qty_rec_tb(i).lot_number
6662         , p_revision                => p_revision
6663         , p_header_id               => p_move_order_header_id
6664         , x_line_id                 => l_line_id
6665         , x_return_status           => l_return_status
6666         , x_msg_count               => l_count
6667         , x_msg_data                => l_msg_data
6668         , p_inspection_status       => p_inspect
6669         , p_txn_source_id           => p_txn_source_id
6670         , p_wms_process_flag        => l_wms_process_flag
6671         , p_from_cost_group_id      => l_from_cost_group_id
6672         , p_transfer_org_id         => p_transfer_org_id
6673         , p_sec_qty                 => p_secondary_quantity --OPM Convergence
6674         , p_sec_uom                 => p_secondary_uom --OPM Convergence
6675         );
6676 
6677         IF (l_debug = 1) THEN
6678           print_debug(
6679             'create_move_order 7: after calling wms_task_dispatch_put_away.create_mo ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6680           , 4
6681           );
6682         END IF;
6683 
6684         IF l_return_status = fnd_api.g_ret_sts_error THEN
6685           IF (l_debug = 1) THEN
6686             print_debug(
6687                  'create_move_order 7.1: wms_task_dispatch_put_away.create_mo RAISE FND_API.G_EXC_ERROR;'
6688               || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6689             , 4
6690             );
6691           END IF;
6692 
6693           RAISE fnd_api.g_exc_error;
6694         END IF;
6695 
6696         IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6697           IF (l_debug = 1) THEN
6698             print_debug(
6699                  'create_move_order 7.2: wms_task_dispatch_put_away.create_mo RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
6700               || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6701             , 4
6702             );
6703           END IF;
6704 
6705           RAISE fnd_api.g_exc_unexpected_error;
6706         END IF;
6707       -- Should set wms_process_flag to 2 (do not allocate), then
6708       -- rcvtp will call rcv_txn_clean_up to update this flag to 1,
6709       -- if receipt transaction goes through successfully.
6710       -- We set this flag to 1 right now for testing purpose since
6711       -- rcvtp is not calling our code yet.
6712       END LOOP;
6713     ELSE
6714       IF (l_debug = 1) THEN
6715         print_debug('create_move_order 8: before calling wms_task_dispatch_put_away.create_mo '
6716           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6717         , 4);
6718       END IF;
6719 
6720       IF p_shipment_line_id IS NOT NULL THEN
6721    IF p_lpn IS NOT NULL THEN
6722         BEGIN
6723      SELECT cost_group_id
6724        INTO   l_from_cost_group_id
6725        FROM   wms_lpn_contents wlpnc
6726        WHERE  organization_id = p_org_id
6727        AND    parent_lpn_id = p_lpn
6728        AND    wlpnc.inventory_item_id = p_item_id
6729        AND    EXISTS(
6730          SELECT 1
6731          FROM   cst_cost_group_accounts
6732          WHERE  organization_id = p_org_id
6733          AND    cost_group_id = wlpnc.cost_group_id);
6734         EXCEPTION
6735      WHEN OTHERS THEN
6736         l_from_cost_group_id                      := NULL;
6737         END;
6738     ELSE
6739       BEGIN
6740          SELECT cost_group_id
6741            INTO l_from_cost_group_id
6742            FROM rcv_shipment_lines rsl
6743            WHERE shipment_line_id = p_shipment_line_id
6744            AND exists (
6745            SELECT 1
6746            FROM   cst_cost_group_accounts
6747            WHERE  organization_id = p_org_id
6748            AND    cost_group_id = rsl.cost_group_id)
6749            AND ROWNUM = 1;
6750       EXCEPTION
6751          WHEN OTHERS THEN
6752       l_from_cost_group_id := NULL;
6753       END;
6754    END IF;
6755       END IF;
6756 
6757       IF (l_debug = 1) THEN
6758         print_debug('create_move_order 8.1 parameters organization -' || p_org_id, 4);
6759         print_debug('create_move_order 8.1 parameters p_item_id -' || p_item_id, 4);
6760         print_debug('create_move_order 8.1 parameters p_uom_code -' || p_uom_code, 4);
6761         print_debug('create_move_order 8.1 parameters p_lpn -' || p_lpn, 4);
6762         print_debug('create_move_order 8.1 parameters l_project_id -' || l_project_id, 4);
6763         print_debug('create_move_order 8.1 parameters l_task_id -' || l_task_id, 4);
6764         print_debug('create_move_order 8.1 parameters l_reference -' || l_reference, 4);
6765         print_debug('create_move_order 8.1 parameters l_reference_type_code -' || l_reference_type_code, 4);
6766         print_debug('create_move_order 8.1 parameters l_reference_id -' || l_reference_id, 4);
6767         print_debug('create_move_order 8.1 parameters p_revision -' || p_revision, 4);
6768         print_debug('create_move_order 8.1 parameters p_move_order_header_id -' || p_move_order_header_id, 4);
6769         print_debug('create_move_order 8.1 parameters p_inspect -' || p_inspect, 4);
6770         print_debug('create_move_order 8.1 parameters p_txn_source_id -' || p_txn_source_id, 4);
6771         print_debug('create_move_order 8.1 parameters l_from_cost_group_id -' || l_from_cost_group_id, 4);
6772         print_debug('create_move_order 8.1 parameters p_transfer_org_id -' || p_transfer_org_id, 4);
6773       END IF;
6774 
6775       wms_task_dispatch_put_away.create_mo(
6776         p_org_id                  => p_org_id
6777       , p_inventory_item_id       => p_item_id
6778       , p_qty                     => p_qty
6779       , p_uom                     => p_uom_code
6780       , p_lpn                     => p_lpn
6781       , p_project_id              => l_project_id
6782       , p_task_id                 => l_task_id
6783       , p_reference               => l_reference
6784       , p_reference_type_code     => l_reference_type_code
6785       , p_reference_id            => l_reference_id
6786       , p_lot_number              => NULL
6787       , p_revision                => p_revision
6788       , p_header_id               => p_move_order_header_id
6789       , x_line_id                 => l_line_id
6790       , x_return_status           => l_return_status
6791       , x_msg_count               => l_count
6792       , x_msg_data                => l_msg_data
6793       , p_inspection_status       => p_inspect
6794       , p_txn_source_id           => p_txn_source_id
6795       , p_wms_process_flag        => l_wms_process_flag
6796       , p_from_cost_group_id      => l_from_cost_group_id
6797       , p_transfer_org_id         => p_transfer_org_id
6798      /*, p_secondary_qty           => p_secondary_quantity --OPM Convergence
6799       , p_secondary_uom           => p_secondary_uom --OPM Convergence*/
6800       );
6801 
6802       IF (l_debug = 1) THEN
6803         print_debug('create_move_order 8: after calling wms_task_dispatch_put_away.create_mo '
6804           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6805         , 1);
6806       END IF;
6807 
6808       IF l_return_status = fnd_api.g_ret_sts_error THEN
6809         IF (l_debug = 1) THEN
6810           print_debug(
6811                'create_move_order 8.1: wms_task_dispatch_put_away.create_mo RAISE FND_API.G_EXC_ERROR;'
6812             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6813           , 4
6814           );
6815         END IF;
6816 
6817         RAISE fnd_api.g_exc_error;
6818       END IF;
6819 
6820       IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
6821         IF (l_debug = 1) THEN
6822           print_debug(
6823                'create_move_order 8.2: wms_task_dispatch_put_away.create_mo RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
6824             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6825           , 4
6826           );
6827         END IF;
6828 
6829         RAISE fnd_api.g_exc_unexpected_error;
6830       END IF;
6831     END IF;
6832 
6833     x_line_id := l_line_id;
6834 
6835     IF (l_debug = 1) THEN
6836           print_debug(
6837                'create_move_order returns with success'
6838             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
6839           , 4
6840           );
6841     END IF;
6842 
6843   EXCEPTION
6844     WHEN fnd_api.g_exc_error THEN
6845       ROLLBACK TO rcv_crt_mo_sp;
6846       x_status := fnd_api.g_ret_sts_error;
6847       fnd_msg_pub.count_and_get(
6848           p_encoded => fnd_api.g_false
6849         , p_count => l_msg_count
6850         , p_data => x_message);
6851 
6852       IF (l_debug = 1) THEN
6853         print_debug('create_move_order:  FND_API.g_exc_error ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6854       END IF;
6855     WHEN fnd_api.g_exc_unexpected_error THEN
6856       ROLLBACK TO rcv_crt_mo_sp;
6857       x_status := fnd_api.g_ret_sts_unexp_error;
6858       fnd_msg_pub.count_and_get(
6859           p_encoded => fnd_api.g_false
6860         , p_count => l_msg_count
6861         , p_data => x_message);
6862 
6863       IF (l_debug = 1) THEN
6864         print_debug('create_move_order: fnd_api.g_exc_unexpected_error ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6865       END IF;
6866     WHEN OTHERS THEN
6867       ROLLBACK TO rcv_crt_mo_sp;
6868       x_status := fnd_api.g_ret_sts_unexp_error;
6869 
6870       IF SQLCODE IS NOT NULL THEN
6871         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.create_move_order', l_progress, SQLCODE);
6872       END IF;
6873 
6874       fnd_msg_pub.count_and_get(
6875           p_encoded => fnd_api.g_false
6876         , p_count => l_msg_count
6877         , p_data => x_message);
6878 
6879       IF (l_debug = 1) THEN
6880         print_debug('create_move_order: Other exception ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6881       END IF;
6882   END create_move_order;
6883 
6884   PROCEDURE rcv_update_rti_from_header(
6885     p_shipment_num                      VARCHAR
6886   , p_freight_carrier_code              VARCHAR2
6887   , p_bill_of_lading                    VARCHAR2
6888   , p_packing_slip                      VARCHAR2
6889   , p_num_of_containers                 NUMBER
6890   , p_waybill_airbill_num               VARCHAR2
6891   , x_return_status         OUT NOCOPY  VARCHAR2
6892   , x_msg_count             OUT NOCOPY  NUMBER
6893   , x_msg_data              OUT NOCOPY  VARCHAR2
6894   ) IS
6895     l_return_status  VARCHAR2(1)    := fnd_api.g_ret_sts_success;
6896     l_msg_count      NUMBER;
6897     l_msg_data       VARCHAR2(4000);
6898     l_progress       VARCHAR2(10);
6899     l_process_status VARCHAR2(10);
6900     l_debug          NUMBER         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6901   BEGIN
6902     l_progress := '10';
6903     x_return_status := fnd_api.g_ret_sts_success;
6904 
6905     IF (l_debug = 1) THEN
6906       print_debug('rcv_update_rti_from_header 5:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6907     END IF;
6908 
6909     BEGIN
6910       --If INV and PO J are installed,
6911       -- then query using the group_id as RTI is not stamped with shipment_header_id
6912       IF ((inv_rcv_common_apis.g_inv_patch_level >= inv_rcv_common_apis.g_patchset_j) AND
6913     (inv_rcv_common_apis.g_po_patch_level  >= inv_rcv_common_apis.g_patchset_j_po)) THEN
6914    IF (l_debug = 1) THEN
6915       print_debug('Calling to insert RHI for J code', 4);
6916    END IF;
6917 
6918    SELECT transaction_status_code
6919      INTO l_process_status
6920      FROM rcv_transactions_interface
6921     WHERE group_id = inv_rcv_common_apis.g_rcv_global_var.interface_group_id
6922       AND ROWNUM = 1;
6923        ELSE
6924    SELECT transaction_status_code
6925      INTO l_process_status
6926      FROM rcv_transactions_interface
6927      WHERE shipment_header_id = g_shipment_header_id
6928      AND ROWNUM < 2;
6929       END IF;
6930 
6931       IF (l_process_status = 'ERROR') THEN
6932         x_return_status := fnd_api.g_ret_sts_error;
6933         fnd_message.set_name('INV', 'INV_FAILED');
6934         fnd_msg_pub.ADD;
6935         RAISE fnd_api.g_exc_error;
6936       END IF;
6937     EXCEPTION
6938       WHEN NO_DATA_FOUND THEN
6939         x_return_status := fnd_api.g_ret_sts_error;
6940         fnd_message.set_name('INV', 'INV_FAILED');
6941         fnd_msg_pub.ADD;
6942         RAISE fnd_api.g_exc_error;
6943     END;
6944 
6945     IF (l_debug = 1) THEN
6946       print_debug('rcv_update_rti_from_header 10:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6947     END IF;
6948 
6949     --If INV and PO J are installed,
6950     -- then query using the group_id as RTI is not stamped with shipment_header_id
6951     IF ((inv_rcv_common_apis.g_inv_patch_level >= inv_rcv_common_apis.g_patchset_j) AND
6952   (inv_rcv_common_apis.g_po_patch_level  >= inv_rcv_common_apis.g_patchset_j_po)) THEN
6953        IF (l_debug = 1) THEN
6954     print_debug('Calling to insert RHI for J code', 4);
6955        END IF;
6956        UPDATE rcv_transactions_interface
6957     SET shipment_num = p_shipment_num
6958             , freight_carrier_code = p_freight_carrier_code
6959             , bill_of_lading = p_bill_of_lading
6960             , packing_slip = p_packing_slip
6961             , num_of_containers = p_num_of_containers
6962             , waybill_airbill_num = p_waybill_airbill_num
6963   WHERE group_id = inv_rcv_common_apis.g_rcv_global_var.interface_group_id;
6964      ELSE
6965        UPDATE rcv_transactions_interface
6966     SET shipment_num = p_shipment_num
6967             , freight_carrier_code = p_freight_carrier_code
6968             , bill_of_lading = p_bill_of_lading
6969             , packing_slip = p_packing_slip
6970             , num_of_containers = p_num_of_containers
6971             , waybill_airbill_num = p_waybill_airbill_num
6972   WHERE shipment_header_id = g_shipment_header_id;
6973     END IF;
6974     l_progress := '20';
6975 
6976     IF (l_debug = 1) THEN
6977       print_debug('rcv_update_rti_from_header 20:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
6978     END IF;
6979   EXCEPTION
6980     WHEN fnd_api.g_exc_error THEN
6981       x_return_status := fnd_api.g_ret_sts_error;
6982       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6983     WHEN fnd_api.g_exc_unexpected_error THEN
6984       x_return_status := fnd_api.g_ret_sts_unexp_error;
6985       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6986     WHEN OTHERS THEN
6987       x_return_status := fnd_api.g_ret_sts_unexp_error;
6988 
6989       IF SQLCODE IS NOT NULL THEN
6990         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.rcv_update_rti_from_header', l_progress, SQLCODE);
6991       END IF;
6992 
6993       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
6994   END rcv_update_rti_from_header;
6995 
6996   -- Only called if patchset J or higher from rcv_insert_update_header
6997   -- This is called instead of rcv_insert_header
6998   PROCEDURE rcv_insert_header_interface(
6999     p_organization_id                     NUMBER
7000   , p_source_type                         VARCHAR2
7001   , p_receipt_num             OUT NOCOPY  VARCHAR2
7002   , p_vendor_id                           NUMBER
7003   , p_vendor_site_id                      NUMBER
7004   , p_shipment_num                        VARCHAR2
7005   , p_ship_to_location_id                 NUMBER
7006   , p_bill_of_lading                      VARCHAR2
7007   , p_packing_slip                        VARCHAR2
7008   , p_shipped_date                        DATE
7009   , p_freight_carrier_code                VARCHAR2
7010   , p_expected_receipt_date               DATE
7011   , p_num_of_containers                   NUMBER
7012   , p_waybill_airbill_num                 VARCHAR2
7013   , p_comments                            VARCHAR2
7014   , p_ussgl_transaction_code              VARCHAR2
7015   , p_government_context                  VARCHAR2
7016   , p_request_id                          NUMBER
7017   , p_program_application_id              NUMBER
7018   , p_program_id                          NUMBER
7019   , p_program_update_date                 DATE
7020   , p_customer_id                         NUMBER
7021   , p_customer_site_id                    NUMBER
7022   , x_return_status           OUT NOCOPY  VARCHAR2
7023   , x_msg_count               OUT NOCOPY  NUMBER
7024   , x_msg_data                OUT NOCOPY  VARCHAR2
7025   , p_attribute_category      IN          VARCHAR2  DEFAULT NULL  --Bug #4147209 - Added DFF cols
7026   , p_attribute1              IN          VARCHAR2  DEFAULT NULL
7027   , p_attribute2              IN          VARCHAR2  DEFAULT NULL
7028   , p_attribute3              IN          VARCHAR2  DEFAULT NULL
7029   , p_attribute4              IN          VARCHAR2  DEFAULT NULL
7030   , p_attribute5              IN          VARCHAR2  DEFAULT NULL
7031   , p_attribute6              IN          VARCHAR2  DEFAULT NULL
7032   , p_attribute7              IN          VARCHAR2  DEFAULT NULL
7033   , p_attribute8              IN          VARCHAR2  DEFAULT NULL
7034   , p_attribute9              IN          VARCHAR2  DEFAULT NULL
7035   , p_attribute10             IN          VARCHAR2  DEFAULT NULL
7036   , p_attribute11             IN          VARCHAR2  DEFAULT NULL
7037   , p_attribute12             IN          VARCHAR2  DEFAULT NULL
7038   , p_attribute13             IN          VARCHAR2  DEFAULT NULL
7039   , p_attribute14             IN          VARCHAR2  DEFAULT NULL
7040   , p_attribute15             IN          VARCHAR2  DEFAULT NULL
7041   ) IS
7042     l_header        rcv_headers_interface%ROWTYPE;
7043     l_rowid         VARCHAR2(40);
7044     l_sysdate       DATE                           := SYSDATE;
7045     l_return_status VARCHAR2(1)                    := fnd_api.g_ret_sts_success;
7046     l_msg_count     NUMBER;
7047     l_msg_data      VARCHAR2(4000);
7048     l_progress      VARCHAR2(10);
7049     l_debug         NUMBER                         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7050   BEGIN
7051     IF (l_debug = 1) THEN
7052       print_debug('rcv_insert_header_interface 10:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
7053     END IF;
7054 
7055     l_progress := '10';
7056     x_return_status := fnd_api.g_ret_sts_success;
7057     SAVEPOINT rcv_insert_ship_header_sp;
7058     l_header.last_update_date := l_sysdate;
7059     l_header.creation_date := l_sysdate;
7060     l_header.last_update_login := inv_rcv_common_apis.g_po_startup_value.user_id;
7061     l_header.created_by := inv_rcv_common_apis.g_po_startup_value.user_id;
7062     l_header.last_updated_by := inv_rcv_common_apis.g_po_startup_value.user_id;
7063     -- Bug 3443989 for Internal Requition we have to enter receipt_source_code as INTERNAL ORDER
7064     -- According to PO
7065 
7066     IF p_source_type = 'CUSTOMER' THEN
7067       l_header.receipt_source_code := 'CUSTOMER';
7068     elsif p_source_type = 'INVENTORY' THEN
7069       l_header.receipt_source_code := 'INVENTORY';
7070     elsif p_source_type = 'INTERNAL ORDER' THEN
7071       l_header.receipt_source_code := 'INTERNAL ORDER';
7072     END IF;
7073 
7074     l_progress := '13';
7075     l_header.receipt_num := inv_rcv_common_apis.g_rcv_global_var.receipt_num;
7076     IF l_header.receipt_num IS NULL THEN
7077       RAISE fnd_api.g_exc_error;
7078     END IF;
7079 
7080     l_progress := '15';
7081     l_header.vendor_id := p_vendor_id;
7082     l_header.vendor_site_id := p_vendor_site_id;
7083     l_header.ship_to_organization_id := p_organization_id;
7084     l_header.shipment_num := p_shipment_num;
7085     l_header.bill_of_lading := p_bill_of_lading;
7086     l_header.packing_slip := p_packing_slip;
7087     l_header.shipped_date := p_shipped_date;
7088     l_header.freight_carrier_code := p_freight_carrier_code;
7089     l_header.expected_receipt_date := Nvl(p_expected_receipt_date,l_sysdate);
7090     l_header.employee_id := inv_rcv_common_apis.g_po_startup_value.employee_id;
7091     l_header.num_of_containers := p_num_of_containers;
7092     l_header.waybill_airbill_num := p_waybill_airbill_num;
7093     l_header.comments := p_comments;
7094     l_header.usggl_transaction_code := p_ussgl_transaction_code;
7095     l_header.processing_request_id := p_request_id;
7096     l_header.customer_id := p_customer_id;
7097     l_header.customer_site_id := p_customer_site_id;
7098 
7099     --Bug #4147209 - Populate the header record with the DFF attribute category
7100     --and segment values passed from the mobile UI
7101     l_header.attribute_category := p_attribute_category;
7102     l_header.attribute1         := p_attribute1;
7103     l_header.attribute2         := p_attribute2;
7104     l_header.attribute3         := p_attribute3;
7105     l_header.attribute4         := p_attribute4;
7106     l_header.attribute5         := p_attribute5;
7107     l_header.attribute6         := p_attribute6;
7108     l_header.attribute7         := p_attribute7;
7109     l_header.attribute8         := p_attribute8;
7110     l_header.attribute9         := p_attribute9;
7111     l_header.attribute10        := p_attribute10;
7112     l_header.attribute10        := p_attribute10;
7113     l_header.attribute11        := p_attribute11;
7114     l_header.attribute12        := p_attribute12;
7115     l_header.attribute13        := p_attribute13;
7116     l_header.attribute14        := p_attribute14;
7117     l_header.attribute15        := p_attribute15;
7118 
7119     IF (l_debug = 1) THEN
7120       print_debug('rcv_insert_header_interface 20: before rcv_shipment_headers_pkg.insert_row ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7121       , 1);
7122     END IF;
7123 
7124     l_progress := '20';
7125 
7126     IF g_header_intf_id IS NULL THEN
7127       SELECT rcv_headers_interface_s.NEXTVAL
7128         INTO g_header_intf_id
7129         FROM SYS.DUAL;
7130     END IF;
7131 
7132     l_progress := '25';
7133 
7134     INSERT INTO rcv_headers_interface
7135                 (
7136                  header_interface_id
7137                , group_id
7138                , processing_status_code
7139                , transaction_type
7140                , validation_flag
7141                , auto_transact_code
7142                , last_update_date
7143                , last_updated_by
7144                , creation_date
7145                , created_by
7146                , last_update_login
7147                , receipt_source_code
7148                , vendor_id
7149                , vendor_site_id
7150                , ship_to_organization_id
7151                , shipment_num
7152                , receipt_num
7153                , bill_of_lading
7154                , packing_slip
7155                , shipped_date
7156                , freight_carrier_code
7157                , expected_receipt_date
7158                , employee_id
7159                , num_of_containers
7160                , waybill_airbill_num
7161                , comments
7162                , attribute_category
7163                , attribute1
7164                , attribute2
7165                , attribute3
7166                , attribute4
7167                , attribute5
7168                , attribute6
7169                , attribute7
7170                , attribute8
7171                , attribute9
7172                , attribute10
7173                , attribute11
7174                , attribute12
7175                , attribute13
7176                , attribute14
7177                , attribute15
7178                , usggl_transaction_code
7179                , processing_request_id
7180                , customer_id
7181                , customer_site_id
7182                 )
7183          VALUES (
7184                  g_header_intf_id
7185                , inv_rcv_common_apis.g_rcv_global_var.interface_group_id
7186                , 'PENDING' -- processing_status_code
7187                , 'NEW' -- transaction_type
7188                , 'Y' -- validation_flag
7189                , 'RECEIVE' -- auto_transact_code
7190                , l_header.last_update_date
7191                , l_header.last_updated_by
7192                , l_header.creation_date
7193                , l_header.created_by
7194                , l_header.last_update_login
7195                , NVL(l_header.receipt_source_code, 'VENDOR')
7196                , l_header.vendor_id
7197                , l_header.vendor_site_id
7198                , l_header.ship_to_organization_id
7199                , l_header.shipment_num
7200                , l_header.receipt_num
7201                , l_header.bill_of_lading
7202                , l_header.packing_slip
7203                , l_header.shipped_date
7204                , l_header.freight_carrier_code
7205                , l_header.expected_receipt_date
7206                , l_header.employee_id
7207                , l_header.num_of_containers
7208                , l_header.waybill_airbill_num
7209                , l_header.comments
7210                , l_header.attribute_category
7211                , l_header.attribute1
7212                , l_header.attribute2
7213                , l_header.attribute3
7214                , l_header.attribute4
7215                , l_header.attribute5
7216                , l_header.attribute6
7217                , l_header.attribute7
7218                , l_header.attribute8
7219                , l_header.attribute9
7220                , l_header.attribute10
7221                , l_header.attribute11
7222                , l_header.attribute12
7223                , l_header.attribute13
7224                , l_header.attribute14
7225                , l_header.attribute15
7226                , l_header.usggl_transaction_code
7227                , l_header.processing_request_id
7228                , l_header.customer_id
7229                , l_header.customer_site_id
7230                 );
7231 
7232     l_progress := '30';
7233 
7234     IF (l_debug = 1) THEN
7235       print_debug('rcv_insert_header_interface 30: after insert_row ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
7236     END IF;
7237 
7238     p_receipt_num := l_header.receipt_num;
7239 
7240     IF (l_debug = 1) THEN
7241       print_debug('rcv_insert_header_interface 40: before rcv_update_rti_from_header ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
7242     END IF;
7243 
7244   EXCEPTION
7245     WHEN fnd_api.g_exc_error THEN
7246       ROLLBACK TO rcv_insert_ship_header_sp;
7247       x_return_status := fnd_api.g_ret_sts_error;
7248 
7249       IF (l_debug = 1) THEN
7250         print_debug('INV_RCV_STD_RCPT_APIS.rcv_insert_header_interface 50.1:  RAISE FND_API.G_EXC_ERROR;' || l_progress, 4);
7251       END IF;
7252 
7253       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7254     WHEN fnd_api.g_exc_unexpected_error THEN
7255       ROLLBACK TO rcv_insert_ship_header_sp;
7256       x_return_status := fnd_api.g_ret_sts_unexp_error;
7257 
7258       IF (l_debug = 1) THEN
7259         print_debug('INV_RCV_STD_RCPT_APIS.rcv_insert_header_interface 50.2:  RAISE FND_API.G_EXC_ERROR;' || l_progress, 4);
7260       END IF;
7261 
7262       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7263     WHEN OTHERS THEN
7264       ROLLBACK TO rcv_insert_ship_header_sp;
7265       x_return_status := fnd_api.g_ret_sts_unexp_error;
7266 
7267       IF SQLCODE IS NOT NULL THEN
7268         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.rcv_insert_header_interface', l_progress, SQLCODE);
7269       END IF;
7270 
7271       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7272   END rcv_insert_header_interface;
7273 
7274   PROCEDURE rcv_update_header_interface(
7275     p_organization_id                     NUMBER
7276   , p_header_intf_id                      NUMBER
7277   , p_source_type                         VARCHAR2
7278   , p_receipt_num                         VARCHAR2
7279   , p_vendor_id                           NUMBER
7280   , p_vendor_site_id                      NUMBER
7281   , p_shipment_num                        VARCHAR2
7282   , p_ship_to_location_id                 NUMBER
7283   , p_bill_of_lading                      VARCHAR2
7284   , p_packing_slip                        VARCHAR2
7285   , p_shipped_date                        DATE
7286   , p_freight_carrier_code                VARCHAR2
7287   , p_expected_receipt_date               DATE
7288   , p_num_of_containers                   NUMBER
7289   , p_waybill_airbill_num                 VARCHAR2
7290   , p_comments                            VARCHAR2
7291   , p_ussgl_transaction_code              VARCHAR2
7292   , p_program_request_id                  NUMBER
7293   , p_customer_id                         NUMBER
7294   , p_customer_site_id                    NUMBER
7295   , x_return_status           OUT NOCOPY  VARCHAR2
7296   , x_msg_count               OUT NOCOPY  NUMBER
7297   , x_msg_data                OUT NOCOPY  VARCHAR2
7298   , p_attribute_category      IN          VARCHAR2  DEFAULT NULL  --Bug #4147209
7299   , p_attribute1              IN          VARCHAR2  DEFAULT NULL
7300   , p_attribute2              IN          VARCHAR2  DEFAULT NULL
7301   , p_attribute3              IN          VARCHAR2  DEFAULT NULL
7302   , p_attribute4              IN          VARCHAR2  DEFAULT NULL
7303   , p_attribute5              IN          VARCHAR2  DEFAULT NULL
7304   , p_attribute6              IN          VARCHAR2  DEFAULT NULL
7305   , p_attribute7              IN          VARCHAR2  DEFAULT NULL
7306   , p_attribute8              IN          VARCHAR2  DEFAULT NULL
7307   , p_attribute9              IN          VARCHAR2  DEFAULT NULL
7308   , p_attribute10             IN          VARCHAR2  DEFAULT NULL
7309   , p_attribute11             IN          VARCHAR2  DEFAULT NULL
7310   , p_attribute12             IN          VARCHAR2  DEFAULT NULL
7311   , p_attribute13             IN          VARCHAR2  DEFAULT NULL
7312   , p_attribute14             IN          VARCHAR2  DEFAULT NULL
7313   , p_attribute15             IN          VARCHAR2  DEFAULT NULL
7314   ) IS
7315 
7316     l_sysdate       DATE                           := SYSDATE;
7317     l_return_status VARCHAR2(1)                    := fnd_api.g_ret_sts_success;
7318     l_msg_count     NUMBER;
7319     l_msg_data      VARCHAR2(4000);
7320     l_progress      VARCHAR2(10);
7321     l_check_asn     VARCHAR2(25);--Bug 4551595
7322 
7323     l_debug         NUMBER                         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7324   BEGIN
7325     -- receving api is using row_id in where clause
7326     -- so query row_id based on shipment_header_id
7327     IF (l_debug = 1) THEN
7328       print_debug('rcv_update_header_interface 10:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
7329     END IF;
7330 
7331     l_progress := '10';
7332     x_return_status := fnd_api.g_ret_sts_success;
7333     SAVEPOINT rcv_update_ship_header_sp;
7334     l_progress := '20';
7335 
7336     IF (l_debug = 1) THEN
7337       print_debug('rcv_update_header_interface 20: before update_row ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7338       , 4);
7339     END IF;
7340     l_progress := '40';
7341     UPDATE rcv_headers_interface
7342        SET customer_id = Nvl(p_customer_id, customer_id)
7343          , last_update_date = l_sysdate
7344          , last_update_login = NVL(inv_rcv_common_apis.g_po_startup_value.user_id, last_update_login)
7345          , last_updated_by = NVL(inv_rcv_common_apis.g_po_startup_value.user_id, last_updated_by)
7346          , vendor_id = NVL(p_vendor_id, vendor_id)
7347          , vendor_site_id = NVL(p_vendor_site_id, vendor_site_id)
7348          , ship_to_organization_id = NVL(p_organization_id, ship_to_organization_id)
7349          , receipt_num = NVL(p_receipt_num, receipt_num)
7350          , bill_of_lading = p_bill_of_lading
7351          , waybill_airbill_num = Nvl(p_waybill_airbill_num,waybill_airbill_num)--BUG 5111375 (FP of BUG 4500055)
7352          , packing_slip = p_packing_slip
7353          , shipped_date = NVL(p_shipped_date, shipped_date)
7354          , freight_carrier_code = p_freight_carrier_code
7355          , expected_receipt_date = NVL(p_expected_receipt_date, expected_receipt_date)
7356          , employee_id = NVL(inv_rcv_common_apis.g_po_startup_value.employee_id, employee_id)
7357          , num_of_containers = NVL(p_num_of_containers, num_of_containers)
7358          , comments = p_comments
7359          , attribute_category = p_attribute_category
7360          , attribute1 = p_attribute1
7361          , attribute2 = p_attribute2
7362          , attribute3 = p_attribute3
7363          , attribute4 = p_attribute4
7364          , attribute5 = p_attribute5
7365          , attribute6 = p_attribute6
7366          , attribute7 = p_attribute7
7367          , attribute8 = p_attribute8
7368          , attribute9 = p_attribute9
7369          , attribute10 = p_attribute10
7370          , attribute11 = p_attribute11
7371          , attribute12 = p_attribute12
7372          , attribute13 = p_attribute13
7373          , attribute14 = p_attribute14
7374          , attribute15 = p_attribute15
7375      WHERE header_interface_id = p_header_intf_id;
7376 
7377     l_progress := '50';
7378 
7379     IF (l_debug = 1) THEN
7380       print_debug(
7381            'rcv_update_header_interface 30: after update_row  before rcv_update_rti_from_header '
7382         || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7383       , 4
7384       );
7385     END IF;
7386 
7387     rcv_update_rti_from_header(
7388       p_shipment_num             => p_shipment_num
7389     , p_freight_carrier_code     => p_freight_carrier_code
7390     , p_bill_of_lading           => p_bill_of_lading
7391     , p_packing_slip             => p_packing_slip
7392     , p_num_of_containers        => p_num_of_containers
7393     , p_waybill_airbill_num      => p_waybill_airbill_num
7394     , x_return_status            => l_return_status
7395     , x_msg_count                => l_msg_count
7396     , x_msg_data                 => l_msg_data
7397     );
7398 
7399     IF l_return_status = fnd_api.g_ret_sts_error THEN
7400       fnd_message.set_name('INV', 'INV_RCV_UPDATE_RTI_FAIL');
7401       fnd_msg_pub.ADD;
7402 
7403       IF (l_debug = 1) THEN
7404         print_debug(
7405           'rcv_update_header_interface 30.1: rcv_update_rti_from_header RAISE FND_API.G_EXC_ERROR;' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7406         , 4
7407         );
7408       END IF;
7409 
7410       RAISE fnd_api.g_exc_error;
7411     END IF;
7412 
7413     IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
7414       fnd_message.set_name('INV', 'INV_RCV_UPDATE_RTI_FAIL');
7415       fnd_msg_pub.ADD;
7416 
7417       IF (l_debug = 1) THEN
7418         print_debug(
7419              'rcv_update_header_interface 30.2: rcv_update_rti_from_header RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
7420           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7421         , 4
7422         );
7423       END IF;
7424 
7425       RAISE fnd_api.g_exc_unexpected_error;
7426     END IF;
7427 
7428     IF (l_debug = 1) THEN
7429       print_debug('rcv_update_header_interface 40: after rcv_update_rti_from_header ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
7430     END IF;
7431 
7432     --BUG 4563411:Added the call to the new procedure to update
7433     --wms_asn_Details for the item
7434     BEGIN
7435        SELECT NVL(ASN_TYPE,'@@@')
7436 	 INTO l_check_asn
7437 	 FROM rcv_shipment_headers
7438 	 WHERE shipment_header_id = g_shipment_header_id;
7439     EXCEPTION
7440        WHEN OTHERS THEN
7441 	  IF (l_debug = 1) THEN
7442 	     print_debug('No RSH found. SQLCODE:'||SQLCODE||' SQLERRM:'||Sqlerrm,4);
7443 	  END IF;
7444 	  l_check_asn := '@@@';
7445     END;
7446 
7447     IF l_check_asn ='ASN' THEN
7448 
7449        IF (l_debug = 1) THEN
7450 	  print_debug('In type ASN before call to new procedure', 4);
7451 	  print_debug('group_id:'||inv_rcv_common_apis.g_rcv_global_var.interface_group_id,4);
7452        END IF;
7453 
7454        --Calling the procedure
7455        INV_CR_ASN_DETAILS.update_asn_item_details
7456 	 (p_group_id=>inv_rcv_common_apis.g_rcv_global_var.interface_group_id);
7457 
7458        IF (l_debug = 1) THEN
7459 	  print_debug('In type ASN after call to new procedure.', 4);
7460 	  print_debug('# of WAD updated:'||SQL%rowcount,4);
7461        END IF;
7462    END IF;
7463    --End of fix for Bug 4563411
7464 
7465   EXCEPTION
7466     WHEN fnd_api.g_exc_error THEN
7467       ROLLBACK TO rcv_update_ship_header_sp;
7468 
7469       x_return_status := fnd_api.g_ret_sts_error;
7470       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7471     WHEN fnd_api.g_exc_unexpected_error THEN
7472       ROLLBACK TO rcv_update_ship_header_sp;
7473 
7474       x_return_status := fnd_api.g_ret_sts_unexp_error;
7475       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7476     WHEN OTHERS THEN
7477       ROLLBACK TO rcv_update_ship_header_sp;
7478       x_return_status := fnd_api.g_ret_sts_unexp_error;
7479 
7480       IF SQLCODE IS NOT NULL THEN
7481         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.rcv_update_header_interface', l_progress, SQLCODE);
7482       END IF;
7483 
7484       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7485   END rcv_update_header_interface;
7486 
7487   PROCEDURE rcv_insert_update_header(
7488     p_organization_id         IN             NUMBER
7489   , p_shipment_header_id      IN OUT NOCOPY  NUMBER
7490   , p_source_type             IN             VARCHAR2
7491   , p_receipt_num             IN OUT NOCOPY  VARCHAR2
7492   , p_vendor_id               IN             NUMBER
7493   , p_vendor_site_id          IN             NUMBER
7494   , p_shipment_num            IN             VARCHAR2
7495   , p_ship_to_location_id     IN             NUMBER
7496   , p_bill_of_lading          IN             VARCHAR2
7497   , p_packing_slip            IN             VARCHAR2
7498   , p_shipped_date            IN             DATE
7499   , p_freight_carrier_code    IN             VARCHAR2
7500   , p_expected_receipt_date   IN             DATE
7501   , p_num_of_containers       IN             NUMBER
7502   , p_waybill_airbill_num     IN             VARCHAR2
7503   , p_comments                IN             VARCHAR2
7504   , p_ussgl_transaction_code  IN             VARCHAR2
7505   , p_government_context      IN             VARCHAR2
7506   , p_request_id              IN             NUMBER
7507   , p_program_application_id  IN             NUMBER
7508   , p_program_id              IN             NUMBER
7509   , p_program_update_date     IN             DATE
7510   , p_customer_id             IN             NUMBER
7511   , p_customer_site_id        IN             NUMBER
7512   , x_return_status           OUT NOCOPY     VARCHAR2
7513   , x_msg_count               OUT NOCOPY     NUMBER
7514   , x_msg_data                OUT NOCOPY     VARCHAR2
7515   , p_attribute_category     IN             VARCHAR2  DEFAULT NULL  --Bug #4147209 - Added DFF cols
7516   , p_attribute1             IN             VARCHAR2  DEFAULT NULL
7517   , p_attribute2             IN             VARCHAR2  DEFAULT NULL
7518   , p_attribute3             IN             VARCHAR2  DEFAULT NULL
7519   , p_attribute4             IN             VARCHAR2  DEFAULT NULL
7520   , p_attribute5             IN             VARCHAR2  DEFAULT NULL
7521   , p_attribute6             IN             VARCHAR2  DEFAULT NULL
7522   , p_attribute7             IN             VARCHAR2  DEFAULT NULL
7523   , p_attribute8             IN             VARCHAR2  DEFAULT NULL
7524   , p_attribute9             IN             VARCHAR2  DEFAULT NULL
7525   , p_attribute10            IN             VARCHAR2  DEFAULT NULL
7526   , p_attribute11            IN             VARCHAR2  DEFAULT NULL
7527   , p_attribute12            IN             VARCHAR2  DEFAULT NULL
7528   , p_attribute13            IN             VARCHAR2  DEFAULT NULL
7529   , p_attribute14            IN             VARCHAR2  DEFAULT NULL
7530   , p_attribute15            IN             VARCHAR2  DEFAULT NULL
7531   ) IS
7532     l_return_status VARCHAR2(1)    := fnd_api.g_ret_sts_success;
7533     l_msg_count     NUMBER;
7534     l_msg_data      VARCHAR2(4000);
7535     l_progress      VARCHAR2(10);
7536     l_debug         NUMBER         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7537     -- Changes for BUG 3630412
7538       l_label_status VARCHAR2(500);
7539       l_txn_id_tbl inv_label.transaction_id_rec_type;
7540       l_counter NUMBER := 0;
7541       l_receipt_number VARCHAR2(30);
7542          CURSOR c_rti_txn_id(p_shipment_header_id NUMBER) IS
7543          SELECT rti.interface_transaction_id
7544            FROM rcv_transactions_interface rti
7545           WHERE rti.shipment_header_id = p_shipment_header_id;
7546   BEGIN
7547     l_progress := '10';
7548     l_receipt_number := p_receipt_num; --bug 3630412
7549     x_return_status := fnd_api.g_ret_sts_success;
7550 
7551     IF p_shipment_header_id IS NULL THEN
7552       IF (l_debug = 1) THEN
7553         print_debug('rcv_insert_update_header 10: before calling rcv_insert_header ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
7554       END IF;
7555 
7556       -- insert RHI else insert RSH
7557    IF (l_debug = 1) THEN
7558       print_debug('Calling to insert RHI for J code', 4);
7559    END IF;
7560         rcv_insert_header_interface(
7561             p_organization_id            => p_organization_id
7562       , p_source_type                => p_source_type
7563       , p_receipt_num                => p_receipt_num
7564       , p_vendor_id                  => p_vendor_id
7565       , p_vendor_site_id             => p_vendor_site_id
7566       , p_shipment_num               => p_shipment_num
7567       , p_ship_to_location_id        => p_ship_to_location_id
7568       , p_bill_of_lading             => p_bill_of_lading
7569       , p_packing_slip               => p_packing_slip
7570       , p_shipped_date               => p_shipped_date
7571       , p_freight_carrier_code       => p_freight_carrier_code
7572       , p_expected_receipt_date      => p_expected_receipt_date
7573       , p_num_of_containers          => p_num_of_containers
7574       , p_waybill_airbill_num        => p_waybill_airbill_num
7575       , p_comments                   => p_comments
7576       , p_ussgl_transaction_code     => p_ussgl_transaction_code
7577       , p_government_context         => p_government_context
7578       , p_request_id                 => p_request_id
7579      , p_program_application_id     => p_program_application_id
7580      , p_program_id                 => p_program_id
7581      , p_program_update_date        => p_program_update_date
7582      , p_customer_id                => p_customer_id
7583      , p_customer_site_id           => p_customer_site_id
7584      , x_return_status              => l_return_status
7585      , x_msg_count                  => l_msg_count
7586      , x_msg_data                   => l_msg_data
7587           , p_attribute_category         => p_attribute_category  --Bug #4147209
7588           , p_attribute1                 => p_attribute1
7589           , p_attribute2                 => p_attribute2
7590           , p_attribute3                 => p_attribute3
7591           , p_attribute4                 => p_attribute4
7592           , p_attribute5                 => p_attribute5
7593           , p_attribute6                 => p_attribute6
7594           , p_attribute7                 => p_attribute7
7595           , p_attribute8                 => p_attribute8
7596           , p_attribute9                 => p_attribute9
7597           , p_attribute10                => p_attribute10
7598           , p_attribute11                => p_attribute11
7599           , p_attribute12                => p_attribute12
7600           , p_attribute13                => p_attribute13
7601           , p_attribute14                => p_attribute14
7602           , p_attribute15                => p_attribute15
7603      );
7604 
7605       IF (l_debug = 1) THEN
7606         print_debug('rcv_insert_update_header 20: after calling rcv_insert_header ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
7607       END IF;
7608 
7609       IF l_return_status = fnd_api.g_ret_sts_error THEN
7610         fnd_message.set_name('INV', 'INV_RCV_INS_SHIP_HDR_FAIL');
7611         fnd_msg_pub.ADD;
7612 
7613         IF (l_debug = 1) THEN
7614           print_debug(
7615             'rcv_insert_update_header 20.1: rcv_insert_header RAISE FND_API.G_EXC_ERROR;' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7616           , 4
7617           );
7618         END IF;
7619 
7620         RAISE fnd_api.g_exc_error;
7621       END IF;
7622 
7623       IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
7624         fnd_message.set_name('INV', 'INV_RCV_INS_SHIP_HDR_FAIL');
7625         fnd_msg_pub.ADD;
7626 
7627         IF (l_debug = 1) THEN
7628           print_debug(
7629                'rcv_insert_update_header 20.2: rcv_insert_header RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
7630             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7631           , 4
7632           );
7633         END IF;
7634 
7635         RAISE fnd_api.g_exc_unexpected_error;
7636       END IF;
7637 
7638       -- to pass back the shipment header id that was created.
7639 
7640       --The header_interface_id should be passed back to the UI as
7641       --the ui will always INSERT a rhi ON pageentered which should be always
7642       --updated ON processtxn FROM rcptInfoPage
7643    IF (l_debug = 1) THEN
7644       print_debug('Setting the lpn_group_id and validation_flag for J code', 4);
7645    END IF;
7646    p_shipment_header_id := g_header_intf_id;
7647 
7648       l_progress := '20';
7649     ELSE
7650       IF (l_debug = 1) THEN
7651         print_debug('rcv_insert_update_header 30: before calling rcv_update_header ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
7652       END IF;
7653 
7654       --If INV and PO J are installed,
7655       -- then update RHI else update RSH
7656    IF (l_debug = 1) THEN
7657       print_debug('Calling to insert RHI for J code', 4);
7658    END IF;
7659    rcv_update_header_interface
7660      (
7661         p_organization_id            => p_organization_id
7662       , p_header_intf_id             => p_shipment_header_id
7663       , p_source_type                => p_source_type
7664       , p_receipt_num                => p_receipt_num
7665       , p_vendor_id                  => p_vendor_id
7666       , p_vendor_site_id             => p_vendor_site_id
7667       , p_shipment_num               => p_shipment_num
7668       , p_ship_to_location_id        => p_ship_to_location_id
7669       , p_bill_of_lading             => p_bill_of_lading
7670       , p_packing_slip               => p_packing_slip
7671       , p_shipped_date               => p_shipped_date
7672       , p_freight_carrier_code       => p_freight_carrier_code
7673       , p_expected_receipt_date      => p_expected_receipt_date
7674       , p_num_of_containers          => p_num_of_containers
7675       , p_waybill_airbill_num        => p_waybill_airbill_num
7676       , p_comments                   => p_comments
7677       , p_ussgl_transaction_code     => p_ussgl_transaction_code
7678       , p_program_request_id         => p_request_id
7679      , p_customer_id                => p_customer_id
7680      , p_customer_site_id           => p_customer_site_id
7681      , x_return_status              => l_return_status
7682      , x_msg_count                  => l_msg_count
7683      , x_msg_data                   => l_msg_data
7684           , p_attribute_category         => p_attribute_category  --Bug #4147209
7685           , p_attribute1                 => p_attribute1
7686           , p_attribute2                 => p_attribute2
7687           , p_attribute3                 => p_attribute3
7688           , p_attribute4                 => p_attribute4
7689           , p_attribute5                 => p_attribute5
7690           , p_attribute6                 => p_attribute6
7691           , p_attribute7                 => p_attribute7
7692           , p_attribute8                 => p_attribute8
7693           , p_attribute9                 => p_attribute9
7694           , p_attribute10                => p_attribute10
7695           , p_attribute11                => p_attribute11
7696           , p_attribute12                => p_attribute12
7697           , p_attribute13                => p_attribute13
7698           , p_attribute14                => p_attribute14
7699           , p_attribute15                => p_attribute15
7700      );
7701 
7702       IF (l_debug = 1) THEN
7703         print_debug('rcv_insert_update_header 40: after calling rcv_update_header ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
7704       END IF;
7705 
7706       IF l_return_status = fnd_api.g_ret_sts_error THEN
7707         fnd_message.set_name('INV', 'INV_RCV_UPD_SHIP_HDR_FAIL');
7708         fnd_msg_pub.ADD;
7709 
7710         IF (l_debug = 1) THEN
7711           print_debug(
7712             'rcv_insert_update_header 40.1: rcv_update_header RAISE FND_API.G_EXC_ERROR;' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7713           , 4
7714           );
7715         END IF;
7716 
7717         RAISE fnd_api.g_exc_error;
7718       END IF;
7719 
7720       IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
7721         fnd_message.set_name('INV', 'INV_RCV_UPD_SHIP_HDR_FAIL');
7722         fnd_msg_pub.ADD;
7723 
7724         IF (l_debug = 1) THEN
7725           print_debug(
7726                'rcv_insert_update_header 40.2: rcv_update_header RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
7727             || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7728           , 4
7729           );
7730         END IF;
7731 
7732         RAISE fnd_api.g_exc_unexpected_error;
7733       END IF;
7734 
7735       l_progress := '30';
7736     END IF;
7737     IF (l_debug = 1) THEN
7738       print_debug('Exit rcv_insert_update_header 50: ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
7739     END IF;
7740   EXCEPTION
7741     WHEN fnd_api.g_exc_error THEN
7742       x_return_status := fnd_api.g_ret_sts_error;
7743       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7744     WHEN fnd_api.g_exc_unexpected_error THEN
7745       x_return_status := fnd_api.g_ret_sts_unexp_error;
7746       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7747     WHEN OTHERS THEN
7748       x_return_status := fnd_api.g_ret_sts_unexp_error;
7749 
7750       IF SQLCODE IS NOT NULL THEN
7751         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.rcv_update_insert_header', l_progress, SQLCODE);
7752       END IF;
7753 
7754       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
7755   END rcv_insert_update_header;
7756 
7757   PROCEDURE packunpack_container(
7758     p_api_version             IN             NUMBER
7759   , p_init_msg_list           IN             VARCHAR2 := fnd_api.g_false
7760   , p_commit                  IN             VARCHAR2 := fnd_api.g_false
7761   , x_return_status           OUT NOCOPY     VARCHAR2
7762   , x_msg_count               OUT NOCOPY     NUMBER
7763   , x_msg_data                OUT NOCOPY     VARCHAR2
7764   , p_from_lpn_id             IN             NUMBER   := NULL
7765   , p_lpn_id                  IN             NUMBER
7766   , p_content_lpn_id          IN             NUMBER   := NULL
7767   , p_content_item_id         IN             NUMBER   := NULL
7768   , p_content_item_desc       IN             VARCHAR2 := NULL
7769   , p_revision                IN             VARCHAR2 := NULL
7770   , p_lot_number              IN             VARCHAR2 := NULL
7771   , p_from_serial_number      IN             VARCHAR2 := NULL
7772   , p_to_serial_number        IN             VARCHAR2 := NULL
7773   , p_quantity                IN             NUMBER   := NULL
7774   , p_uom                     IN             VARCHAR2 := NULL
7775   , p_organization_id         IN             NUMBER
7776   , p_subinventory            IN             VARCHAR2 := NULL
7777   , p_locator_id              IN             NUMBER   := NULL
7778   , p_enforce_wv_constraints  IN             NUMBER   := 2
7779   , p_operation               IN             NUMBER
7780   , p_cost_group_id           IN             NUMBER   := NULL
7781   , p_source_type_id          IN             NUMBER   := NULL
7782   , p_source_header_id        IN             NUMBER   := NULL
7783   , p_source_name             IN             VARCHAR2 := NULL
7784   , p_source_line_id          IN             NUMBER   := NULL
7785   , p_source_line_detail_id   IN             NUMBER   := NULL
7786   , p_homogeneous_container   IN             NUMBER   := 2
7787   , p_match_locations         IN             NUMBER   := 2
7788   , p_match_lpn_context       IN             NUMBER   := 2
7789   , p_match_lot               IN             NUMBER   := 2
7790   , p_match_cost_groups       IN             NUMBER   := 2
7791   , p_match_mtl_status        IN             NUMBER   := 2
7792   ) IS
7793     l_to_lpn_id     NUMBER;
7794     l_to_lpn        VARCHAR2(30);
7795     l_process_id    NUMBER;
7796     l_lpn_rec       wms_container_pub.lpn;
7797     l_quantity      NUMBER;
7798     l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
7799     l_msg_count     NUMBER;
7800     l_msg_data      VARCHAR2(4000);
7801     l_progress      VARCHAR2(10);
7802     l_debug         NUMBER      := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7803   BEGIN
7804     IF (l_debug = 1) THEN
7805       print_debug('PackUnpack_Container 10: ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
7806       print_debug('Parameters passed : 10.1: p_from_lpn_id - ' || p_from_lpn_id, 4);
7807       print_debug('Parameters passed : 10.2: p_lpn_id - ' || p_lpn_id, 4);
7808       print_debug('Parameters passed : 10.3: p_content_item_id - ' || p_content_item_id, 4);
7809       print_debug('Parameters passed : 10.4: p_revision - ' || p_revision, 4);
7810       print_debug('Parameters passed : 10.5: p_lot_number - ' || p_lot_number, 4);
7811       print_debug('Parameters passed : 10.6: p_from_serial_number - ' || p_from_serial_number, 4);
7812       print_debug('Parameters passed : 10.7: p_to_serial_number - ' || p_to_serial_number, 4);
7813       print_debug('Parameters passed : 10.8: p_organization_id - ' || p_organization_id, 4);
7814       print_debug('Parameters passed : 10.9: p_quantity - ' || p_quantity, 4);
7815     END IF;
7816 
7817     l_progress := '10';
7818     x_return_status := fnd_api.g_ret_sts_success;
7819     SAVEPOINT rcv_pack_unpack_sp;
7820     /* comment out unpack from LPN and generate dummy LPN code,
7821     since we are not doing discrepancy check at realy time any more. */
7822 
7823     /*   IF p_from_lpn_id = p_lpn_id
7824          AND g_dummy_lpn_id IS NULL THEN
7825           IF (l_debug = 1) THEN
7826              print_debug('PackUnpack_Container 2: generate dummy LPN '|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 4);
7827           END IF;
7828           -- generate a dummy lpn
7829           wms_container_pub.generate_lpn
7830        (p_api_version  => 1.0,
7831         x_return_status => l_return_status,
7832         x_msg_count => l_msg_count,
7833         x_msg_data => l_msg_data,
7834         p_organization_id => p_organization_id,
7835         p_lpn_out => l_to_lpn,
7836         p_lpn_id_out => l_to_lpn_id,
7837         p_process_id => l_process_id,
7838              p_validation_level => FND_API.G_VALID_LEVEL_NONE
7839             );
7840 
7841           l_progress := '20';
7842 
7843           g_dummy_lpn_id := l_to_lpn_id;
7844 
7845           IF l_return_status = FND_API.g_ret_sts_error THEN
7846         FND_MESSAGE.SET_NAME('WMS', 'WMS_LPN_GENERATION_FAIL');
7847         FND_MSG_PUB.ADD;
7848         IF (l_debug = 1) THEN
7849            print_debug('PackUnpack_Container 2.1: generate dummy LPN RAISE FND_API.G_EXC_ERROR;'|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 4);
7850         END IF;
7851         RAISE FND_API.G_EXC_ERROR;
7852           END IF;
7853 
7854           IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
7855         FND_MESSAGE.SET_NAME('WMS', 'WMS_LPN_GENERATION_FAIL');
7856         FND_MSG_PUB.ADD;
7857         IF (l_debug = 1) THEN
7858            print_debug('PackUnpack_Container 2.2: generate dummy LPN RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 4);
7859         END IF;
7860         RAISE FND_API.g_exc_unexpected_error;
7861           END IF;
7862 
7863 
7864 
7865         ELSIF g_dummy_lpn_id IS NOT NULL THEN
7866           IF (l_debug = 1) THEN
7867              print_debug('PackUnpack_Container 3: g_dummy_lpn_id = '|| g_dummy_lpn_id || ' ' || to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 4);
7868           END IF;
7869           l_to_lpn_id := g_dummy_lpn_id;
7870         ELSE
7871           IF (l_debug = 1) THEN
7872              print_debug('PackUnpack_Container 4: l_to_lpn_id = '|| l_to_lpn_id || ' ' || to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 4);
7873           END IF;
7874           l_to_lpn_id := p_lpn_id;
7875        END IF;
7876 
7877     */
7878     l_to_lpn_id := p_lpn_id;
7879     l_progress := '30';
7880 
7881     IF (l_debug = 1) THEN
7882       print_debug(
7883         'PackUnpack_Container 5: before calling WMS_Container_PUB.PackUnpack_Container ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7884       , 4
7885       );
7886     END IF;
7887 
7888     IF p_from_serial_number IS NULL THEN
7889       l_quantity := p_quantity;
7890     ELSE
7891       l_quantity := NULL;
7892     END IF;
7893 
7894     IF (l_debug = 1) THEN
7895       print_debug('PackUnpack_Container 5.1: qty - ' || l_quantity, 4);
7896     END IF;
7897 
7898     wms_container_pub.packunpack_container(
7899       p_api_version                => p_api_version
7900     , p_init_msg_list              => p_init_msg_list
7901     , p_commit                     => p_commit
7902     , x_return_status              => l_return_status
7903     , x_msg_count                  => l_msg_count
7904     , x_msg_data                   => l_msg_data
7905     , p_lpn_id                     => l_to_lpn_id
7906     , p_content_lpn_id             => p_content_lpn_id
7907     , p_content_item_id            => p_content_item_id
7908     , p_content_item_desc          => p_content_item_desc
7909     , p_revision                   => p_revision
7910     , p_lot_number                 => p_lot_number
7911     , p_from_serial_number         => p_from_serial_number
7912     , p_to_serial_number           => p_to_serial_number
7913     , p_quantity                   => l_quantity
7914     , p_uom                        => p_uom
7915     , p_organization_id            => p_organization_id
7916     , p_subinventory               => p_subinventory
7917     , p_locator_id                 => p_locator_id
7918     , p_enforce_wv_constraints     => p_enforce_wv_constraints
7919     , p_operation                  => p_operation
7920     , p_cost_group_id              => p_cost_group_id
7921     , p_source_type_id             => p_source_type_id
7922     , p_source_header_id           => inv_rcv_common_apis.g_rcv_global_var.interface_group_id
7923     , p_source_name                => p_source_name
7924     , p_source_line_id             => p_source_line_id
7925     , p_source_line_detail_id      => p_source_line_detail_id
7926     , p_homogeneous_container      => p_homogeneous_container
7927     , p_match_locations            => p_match_locations
7928     , p_match_lpn_context          => p_match_lpn_context
7929     , p_match_lot                  => p_match_lot
7930     , p_match_cost_groups          => p_match_cost_groups
7931     , p_match_mtl_status           => p_match_mtl_status
7932     , p_validation_level           => fnd_api.g_valid_level_none
7933     , p_concurrent_pack            => 1
7934 /* uncomment after changes to WMSCONTB.pls are complete
7935     , p_secondary_qty              => p_secondary_qty --OPM Convergence
7936     , p_secondary_uom              => p_secondary_uom --OPM Convergence */
7937     );
7938     l_progress := '40';
7939 
7940     IF l_return_status = fnd_api.g_ret_sts_error THEN
7941       fnd_message.set_name('WMS', 'WMS_PACK_CONTAINER_FAIL'); -- cannot pack LPN MSGTBD
7942       fnd_msg_pub.ADD;
7943 
7944       IF (l_debug = 1) THEN
7945         print_debug(
7946              'PackUnpack_Container 5.1: WMS_Container_PUB.PackUnpack_Container RAISE FND_API.G_EXC_ERROR;'
7947           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7948         , 4
7949         );
7950       END IF;
7951 
7952       RAISE fnd_api.g_exc_error;
7953     END IF;
7954 
7955     IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
7956       fnd_message.set_name('WMS', 'WMS_PACK_CONTAINER_FAIL');
7957       fnd_msg_pub.ADD;
7958 
7959       IF (l_debug = 1) THEN
7960         print_debug(
7961              'PackUnpack_Container 5.2: WMS_Container_PUB.PackUnpack_Container FND_API.G_EXC_UNEXPECTED_ERROR;'
7962           || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7963         , 4
7964         );
7965       END IF;
7966 
7967       RAISE fnd_api.g_exc_unexpected_error;
7968     END IF;
7969 
7970     IF (l_debug = 1) THEN
7971       print_debug(
7972         'PackUnpack_Container 6: after calling WMS_Container_PUB.PackUnpack_Container ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
7973       , 4
7974       );
7975     END IF;
7976 
7977     /*
7978     IF l_return_status = fnd_api.g_ret_sts_success
7979       AND p_from_lpn_id IS NOT NULL
7980         AND p_from_lpn_id <> 0 THEN
7981        -- unpack the from lpn
7982 
7983        IF (l_debug = 1) THEN
7984           print_debug('PackUnpack_Container 7: before calling WMS_Container_PUB.PackUnpack_Container for unpack - lpn_id = ' || p_from_lpn_id ||'  '  || to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 4);
7985        END IF;
7986 
7987 
7988        WMS_Container_PUB.PackUnpack_Container
7989        (p_api_version => p_api_version,
7990         p_init_msg_list => p_init_msg_list,
7991         p_commit => p_commit,
7992         x_return_status => l_return_status,
7993         x_msg_count => l_msg_count,
7994         x_msg_data => l_msg_data,
7995         p_lpn_id => p_from_lpn_id,
7996         p_content_lpn_id => p_content_lpn_id,
7997         p_content_item_id => p_content_item_id,
7998         p_content_item_desc => p_content_item_desc,
7999         p_revision => p_revision,
8000         p_lot_number => p_lot_number,
8001         p_from_serial_number => p_from_serial_number,
8002         p_to_serial_number => p_to_serial_number,
8003         p_quantity => l_quantity,
8004         p_uom => p_uom,
8005         p_organization_id => p_organization_id,
8006         p_subinventory => p_subinventory,
8007         p_locator_id => p_locator_id,
8008         p_enforce_wv_constraints => p_enforce_wv_constraints,
8009         p_operation => 2,   -- unpack flag
8010         p_cost_group_id => p_cost_group_id,
8011         p_source_type_id => p_source_type_id,
8012         p_source_header_id => p_source_header_id,
8013         p_source_name => p_source_name,
8014         p_source_line_id => p_source_line_id,
8015         p_source_line_detail_id => p_source_line_detail_id,
8016         p_homogeneous_container => p_homogeneous_container,
8017         p_match_locations => p_match_locations,
8018         p_match_lpn_context => p_match_lpn_context,
8019         p_match_lot => p_match_lot,
8020         p_match_cost_groups => p_match_cost_groups,
8021         p_match_mtl_status => p_match_mtl_status,
8022              p_validation_level => FND_API.G_VALID_LEVEL_NONE
8023        );
8024 
8025      l_progress := '50';
8026 
8027      IF (l_debug = 1) THEN
8028         print_debug('PackUnpack_Container 8: after calling WMS_Container_PUB.PackUnpack_Container x_msg_data = '|| x_msg_data || ' ' || to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 4);
8029      END IF;
8030 
8031      IF l_return_status = FND_API.g_ret_sts_error THEN
8032         FND_MESSAGE.SET_NAME('WMS', 'WMS_PACK_CONTAINER_FAIL');  -- cannot pack LPN MSGTBD
8033         FND_MSG_PUB.ADD;
8034         IF (l_debug = 1) THEN
8035            print_debug('PackUnpack_Container 8.1: - Unpack - WMS_Container_PUB.PackUnpack_Container RAISE FND_API.G_EXC_ERROR;'|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 4);
8036         END IF;
8037         RAISE FND_API.G_EXC_ERROR;
8038      END IF;
8039 
8040 
8041      IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
8042         FND_MESSAGE.SET_NAME('WMS', 'WMS_PACK_CONTAINER_FAIL');
8043         FND_MSG_PUB.ADD;
8044         IF (l_debug = 1) THEN
8045            print_debug('PackUnpack_Container 8.2: - Unpack - WMS_Container_PUB.PackUnpack_Container FND_API.G_EXC_UNEXPECTED_ERROR;'|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 4);
8046         END IF;
8047         RAISE FND_API.g_exc_unexpected_error;
8048      END IF;
8049 
8050        END IF;
8051       */
8052 
8053 
8054     /*   move populating global record to process_lot
8055          -- populate the lot/qty data structure for lot split
8056          IF (p_lot_number IS NOT NULL AND Nvl(g_prev_lot_number,'@@@') <> p_lot_number) THEN
8057        IF (l_debug = 1) THEN
8058           print_debug('PackUnpack_Container 9: before calling populate_lot_rec '|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 4);
8059        END IF;
8060        g_prev_lot_number := p_lot_number;
8061 
8062        l_progress := '60';
8063 
8064        populate_lot_rec(p_lot_number => p_lot_number,
8065               p_primary_qty => p_quantity,
8066               p_txn_uom_code => p_uom,
8067               p_org_id => p_organization_id,
8068               p_item_id => p_content_item_id);
8069 
8070        l_progress := '70';
8071 
8072 
8073        IF (l_debug = 1) THEN
8074           print_debug('PackUnpack_Container 10: after calling populate_lot_rec '|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 1);
8075        END IF;
8076          END IF;
8077 
8078      */
8079     IF l_return_status <> fnd_api.g_ret_sts_success THEN
8080       ROLLBACK TO rcv_pack_unpack_sp;
8081     END IF;
8082   EXCEPTION
8083     WHEN fnd_api.g_exc_error THEN
8084       ROLLBACK TO rcv_pack_unpack_sp;
8085       x_return_status := fnd_api.g_ret_sts_error;
8086       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8087     WHEN fnd_api.g_exc_unexpected_error THEN
8088       ROLLBACK TO rcv_pack_unpack_sp;
8089       x_return_status := fnd_api.g_ret_sts_unexp_error;
8090       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8091     WHEN OTHERS THEN
8092       ROLLBACK TO rcv_pack_unpack_sp;
8093       x_return_status := fnd_api.g_ret_sts_unexp_error;
8094 
8095       IF SQLCODE IS NOT NULL THEN
8096         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.packunpack_container', l_progress, SQLCODE);
8097       END IF;
8098 
8099       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8100   END packunpack_container;
8101 
8102   PROCEDURE detect_asn_discrepancy(
8103     p_shipment_header_id              NUMBER
8104   , p_lpn_id                          NUMBER
8105   , p_po_header_id                    NUMBER
8106   , x_discrepancy_flag    OUT NOCOPY  NUMBER
8107   , x_return_status       OUT NOCOPY  VARCHAR2
8108   , x_msg_count           OUT NOCOPY  NUMBER
8109   , x_msg_data            OUT NOCOPY  VARCHAR2
8110   ) IS
8111     CURSOR l_curs_remaining_asn IS --modified for bug 4951745
8112       SELECT 1
8113         FROM wms_lpn_contents_v lpnc, wms_license_plate_numbers lpn, rcv_shipment_headers rsh
8114        WHERE (lpn.source_header_id = rsh.shipment_header_id
8115               OR lpn.source_name = rsh.shipment_num)
8116          AND rsh.shipment_header_id = p_shipment_header_id
8117          AND (p_lpn_id IS NULL OR lpn.lpn_id=p_lpn_id)
8118          AND lpn.lpn_id = lpnc.parent_lpn_id
8119          AND(
8120              lpnc.source_line_id IN(SELECT pola.po_line_id
8121                                       FROM po_lines_all pola
8122                                      WHERE (p_po_header_id IS NULL  OR  pola.po_header_id=p_po_header_id)
8123                                     )
8124              OR lpnc.source_line_id IS NULL
8125             );
8126 
8127      --Added for Bug 4951745
8128      CURSOR l_curs_remaining_asn_has_lpn IS
8129       SELECT 1
8130         FROM wms_lpn_contents_v lpnc, wms_license_plate_numbers lpn, rcv_shipment_headers rsh
8131        WHERE (lpn.source_header_id = rsh.shipment_header_id
8132               OR lpn.source_name = rsh.shipment_num)
8133          AND rsh.shipment_header_id = p_shipment_header_id
8134          AND lpn.lpn_id = p_lpn_id
8135          AND lpn.lpn_id = lpnc.parent_lpn_id
8136          AND(
8137              lpnc.source_line_id IN(SELECT pola.po_line_id
8138                                       FROM po_lines_all pola
8139                                      WHERE (p_po_header_id IS NULL  OR  pola.po_header_id=p_po_header_id)
8140                                     )
8141              OR lpnc.source_line_id IS NULL
8142             );
8143 
8144     l_remaining_asn_line NUMBER;
8145     l_return_status      VARCHAR2(1)    := fnd_api.g_ret_sts_success;
8146     l_msg_count          NUMBER;
8147     l_msg_data           VARCHAR2(4000);
8148     l_progress           VARCHAR2(10);
8149     l_debug              NUMBER         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
8150   BEGIN
8151     IF (l_debug = 1) THEN
8152       print_debug('Enter detect_ASN_discrepancy 10 ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
8153       print_debug('p_lpn_id ' || p_lpn_id , 1);
8154     END IF;
8155 
8156     x_return_status := fnd_api.g_ret_sts_success;
8157     x_discrepancy_flag := 0;
8158     l_progress := '10';
8159 
8160     IF p_lpn_id IS NULL THEN
8161         OPEN l_curs_remaining_asn;
8162         FETCH l_curs_remaining_asn INTO l_remaining_asn_line;
8163         l_progress := '20';
8164        CLOSE l_curs_remaining_asn;
8165     ELSE
8166         OPEN  l_curs_remaining_asn_has_lpn;
8167         FETCH l_curs_remaining_asn_has_lpn INTO l_remaining_asn_line;
8168         l_progress := '30';
8169         CLOSE l_curs_remaining_asn_has_lpn;
8170     END IF;
8171 
8172 
8173     IF nvl(l_remaining_asn_line,0) > 0 THEN
8174       x_discrepancy_flag := 1;
8175     END IF;
8176 
8177 
8178     l_progress := '40';
8179 
8180     IF (l_debug = 1) THEN
8181       print_debug(
8182            'About exit detect_ASN_discrepancy 20 - x_discrepancy_flag = '
8183         || x_discrepancy_flag
8184         || ' '
8185         || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
8186       , 1
8187       );
8188     END IF;
8189   EXCEPTION
8190     WHEN fnd_api.g_exc_error THEN
8191       IF l_curs_remaining_asn%ISOPEN THEN
8192         CLOSE l_curs_remaining_asn;
8193       END IF;
8194       IF l_curs_remaining_asn_has_lpn%ISOPEN THEN
8195         CLOSE l_curs_remaining_asn_has_lpn;
8196       END IF;
8197 
8198       x_return_status := fnd_api.g_ret_sts_error;
8199       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8200     WHEN fnd_api.g_exc_unexpected_error THEN
8201       ROLLBACK TO rcv_insert_ship_header_sp;
8202 
8203       IF l_curs_remaining_asn%ISOPEN THEN
8204         CLOSE l_curs_remaining_asn;
8205       END IF;
8206       IF l_curs_remaining_asn_has_lpn%ISOPEN THEN
8207         CLOSE l_curs_remaining_asn_has_lpn;
8208       END IF;
8209 
8210       x_return_status := fnd_api.g_ret_sts_unexp_error;
8211       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8212     WHEN OTHERS THEN
8213       ROLLBACK TO rcv_insert_ship_header_sp;
8214 
8215       IF l_curs_remaining_asn%ISOPEN THEN
8216         CLOSE l_curs_remaining_asn;
8217       END IF;
8218       IF l_curs_remaining_asn_has_lpn%ISOPEN THEN
8219         CLOSE l_curs_remaining_asn_has_lpn;
8220       END IF;
8221 
8222       x_return_status := fnd_api.g_ret_sts_unexp_error;
8223 
8224       IF SQLCODE IS NOT NULL THEN
8225         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.detect_ASN_discrepancy', l_progress, SQLCODE);
8226       END IF;
8227 
8228       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8229   END detect_asn_discrepancy;
8230 
8231   PROCEDURE remove_lpn_contents(
8232     p_lpn_id         IN             NUMBER
8233   , x_return_status  OUT NOCOPY     VARCHAR2
8234   , x_msg_count      OUT NOCOPY     NUMBER
8235   , x_msg_data       OUT NOCOPY     VARCHAR2
8236   , p_routing_id     IN             NUMBER DEFAULT NULL
8237   ) IS
8238     l_return_status VARCHAR2(1)    := fnd_api.g_ret_sts_success;
8239     l_msg_count     NUMBER;
8240     l_msg_data      VARCHAR2(4000);
8241     l_progress      VARCHAR2(10);
8242     l_debug         NUMBER         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
8243   BEGIN
8244     IF (l_debug = 1) THEN
8245       print_debug('remove_lpn_contents 10:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
8246     END IF;
8247 
8248     l_progress := '10';
8249     x_return_status := fnd_api.g_ret_sts_success;
8250     SAVEPOINT rcv_remove_lpn_cont_sp;
8251 
8252     -- delete the contents of the putaway LPN
8253     DELETE      wms_lpn_contents
8254           WHERE parent_lpn_id = p_lpn_id;
8255 
8256     -- clear serial numbers table
8257     UPDATE mtl_serial_numbers
8258        SET lpn_id = NULL
8259      WHERE lpn_id = p_lpn_id;
8260 
8261     l_progress := '20';
8262 
8263     -- update LPN context to receiving
8264     UPDATE wms_license_plate_numbers
8265        SET lpn_context = 5
8266      WHERE lpn_id = p_lpn_id;
8267 
8268     l_progress := '30';
8269 
8270     IF (l_debug = 1) THEN
8271       print_debug('remove_lpn_contents 20:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
8272     END IF;
8273   EXCEPTION
8274     WHEN OTHERS THEN
8275       ROLLBACK TO rcv_remove_lpn_cont_sp;
8276       x_return_status := fnd_api.g_ret_sts_unexp_error;
8277 
8278       IF SQLCODE IS NOT NULL THEN
8279         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.remove_lpn_contents', l_progress, SQLCODE);
8280       END IF;
8281 
8282       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8283   END remove_lpn_contents;
8284 
8285   PROCEDURE clear_lpn_for_ship(
8286     p_organization_id     IN             NUMBER
8287   , p_shipment_header_id  IN             NUMBER
8288   , x_return_status       OUT NOCOPY     VARCHAR2
8289   , x_msg_count           OUT NOCOPY     NUMBER
8290   , x_msg_data            OUT NOCOPY     VARCHAR2
8291   , p_routing_id          IN             NUMBER DEFAULT NULL
8292   ) IS
8293     l_return_status VARCHAR2(1)    := fnd_api.g_ret_sts_success;
8294     l_msg_count     NUMBER;
8295     l_msg_data      VARCHAR2(4000);
8296     l_progress      VARCHAR2(10);
8297     l_asn_type      VARCHAR2(10);
8298     l_lpn_id        NUMBER;
8299     l_wms_enabled   VARCHAR2(1);
8300 
8301     CURSOR l_curs_lpn_for_ship IS
8302       SELECT lpn_id
8303         FROM wms_license_plate_numbers
8304        WHERE source_name = (SELECT shipment_num
8305                               FROM rcv_shipment_headers
8306                              WHERE shipment_header_id = p_shipment_header_id);
8307 
8308     CURSOR l_curs_lpn_for_asn IS
8309       SELECT lpn_id
8310         FROM wms_license_plate_numbers
8311        WHERE source_header_id = p_shipment_header_id;
8312 
8313     l_debug         NUMBER         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
8314   BEGIN
8315     IF (l_debug = 1) THEN
8316       print_debug('clear_LPN_for_ship 10:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
8317     END IF;
8318 
8319     l_progress := '10';
8320     x_return_status := fnd_api.g_ret_sts_success;
8321     SAVEPOINT rcv_clear_lpn_cont_sp;
8322 
8323     IF (l_debug = 1) THEN
8324       print_debug('clear_LPN_for_ship 10.1:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
8325     END IF;
8326 
8327     SELECT SUBSTR(asn_type, 1, 3)
8328       INTO l_asn_type
8329       FROM rcv_shipment_headers
8330      WHERE shipment_header_id = p_shipment_header_id;
8331 
8332     IF (l_debug = 1) THEN
8333       print_debug('clear_LPN_for_ship 10.2 ASN_TYPE =:  ' || l_asn_type, 1);
8334     END IF;
8335 
8336     SELECT wms_enabled_flag
8337       INTO l_wms_enabled
8338       FROM mtl_parameters
8339      WHERE organization_id = p_organization_id;
8340 
8341     IF (l_debug = 1) THEN
8342       print_debug('clear_LPN_for_ship 10.3 WMS_ENABLED_FLAG : ' || l_wms_enabled, 1);
8343     END IF;
8344 
8345     IF UPPER(l_asn_type) = 'ASN' THEN
8346       OPEN l_curs_lpn_for_asn;
8347 
8348       LOOP
8349         FETCH l_curs_lpn_for_asn INTO l_lpn_id;
8350         EXIT WHEN l_curs_lpn_for_asn%NOTFOUND;
8351 
8352         IF (l_debug = 1) THEN
8353           print_debug('clear_LPN_for_ASN 20:  - calling update_lpn_org for:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
8354           print_debug('lpn_id => ' || l_lpn_id, 4);
8355           print_debug('org_id => ' || p_organization_id, 4);
8356         END IF;
8357 
8358         l_progress := '20';
8359 
8360         IF (l_wms_enabled = 'Y') THEN --Update lpn org only if the current org is wms enabled
8361           update_lpn_org(
8362             p_organization_id     => p_organization_id
8363           , p_lpn_id              => l_lpn_id
8364           , x_return_status       => l_return_status
8365           , x_msg_count           => l_msg_count
8366           , x_msg_data            => l_msg_data
8367           );
8368 
8369           IF l_return_status = fnd_api.g_ret_sts_error THEN
8370             IF (l_debug = 1) THEN
8371               print_debug('clear_LPN_for_ASN 20.1 : update_lpn_org RAISE FND_API.G_EXC_ERROR;'
8372                 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
8373               , 4);
8374             END IF;
8375 
8376             RAISE fnd_api.g_exc_error;
8377           END IF;
8378 
8379           IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
8380             IF (l_debug = 1) THEN
8381               print_debug(
8382                    'clear_LPN_for_ASN 20.2: update_lpn_org RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
8383                 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
8384               , 4
8385               );
8386             END IF;
8387 
8388             RAISE fnd_api.g_exc_unexpected_error;
8389           END IF;
8390         END IF;
8391 
8392         IF (l_debug = 1) THEN
8393           print_debug('clear_LPN_for_ASN 30:  - calling remove_lpn_contents' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
8394         END IF;
8395 
8396         l_progress := '30';
8397         remove_lpn_contents(
8398           p_lpn_id            => l_lpn_id
8399         , x_return_status     => l_return_status
8400         , x_msg_count         => l_msg_count
8401         , x_msg_data          => l_msg_data
8402         , p_routing_id        => p_routing_id
8403         );
8404 
8405         IF l_return_status = fnd_api.g_ret_sts_error THEN
8406           IF (l_debug = 1) THEN
8407             print_debug(
8408               'clear_LPN_for_ASN 30.1 : remove_lpn_contents RAISE FND_API.G_EXC_ERROR;' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
8409             , 4
8410             );
8411           END IF;
8412 
8413           RAISE fnd_api.g_exc_error;
8414         END IF;
8415 
8416         IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
8417           IF (l_debug = 1) THEN
8418             print_debug(
8419                  'clear_LPN_for_ASN 30.2: remove_lpn_contents RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
8420               || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
8421             , 4
8422             );
8423           END IF;
8424 
8425           RAISE fnd_api.g_exc_unexpected_error;
8426         END IF;
8427       END LOOP;
8428 
8429       CLOSE l_curs_lpn_for_asn;
8430     ELSE
8431       OPEN l_curs_lpn_for_ship;
8432 
8433       LOOP
8434         FETCH l_curs_lpn_for_ship INTO l_lpn_id;
8435         EXIT WHEN l_curs_lpn_for_ship%NOTFOUND;
8436 
8437         IF (l_debug = 1) THEN
8438           print_debug('clear_LPN_for_ship 20:  - calling update_lpn_org for:' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
8439           print_debug('lpn_id => ' || l_lpn_id, 4);
8440           print_debug('org_id => ' || p_organization_id, 4);
8441         END IF;
8442 
8443         l_progress := '20';
8444 
8445         IF (l_wms_enabled = 'Y') THEN --Update lpn org only if the current org is wms enabled
8446           update_lpn_org(
8447             p_organization_id     => p_organization_id
8448           , p_lpn_id              => l_lpn_id
8449           , x_return_status       => l_return_status
8450           , x_msg_count           => l_msg_count
8451           , x_msg_data            => l_msg_data
8452           );
8453 
8454           IF l_return_status = fnd_api.g_ret_sts_error THEN
8455             IF (l_debug = 1) THEN
8456               print_debug('clear_LPN_for_ship 20.1 : update_lpn_org RAISE FND_API.G_EXC_ERROR;'
8457                 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
8458               , 4);
8459             END IF;
8460 
8461             RAISE fnd_api.g_exc_error;
8462           END IF;
8463 
8464           IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
8465             IF (l_debug = 1) THEN
8466               print_debug(
8467                    'clear_LPN_for_ship 20.2: update_lpn_org RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
8468                 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
8469               , 4
8470               );
8471             END IF;
8472 
8473             RAISE fnd_api.g_exc_unexpected_error;
8474           END IF;
8475         END IF;
8476 
8477         IF (l_debug = 1) THEN
8478           print_debug('clear_LPN_for_ship 30:  - calling remove_lpn_contents' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 4);
8479         END IF;
8480 
8481         l_progress := '30';
8482         remove_lpn_contents(
8483           p_lpn_id            => l_lpn_id
8484         , x_return_status     => l_return_status
8485         , x_msg_count         => l_msg_count
8486         , x_msg_data          => l_msg_data
8487         , p_routing_id        => p_routing_id
8488         );
8489 
8490         IF l_return_status = fnd_api.g_ret_sts_error THEN
8491           IF (l_debug = 1) THEN
8492             print_debug(
8493               'clear_LPN_for_ship 30.1 : remove_lpn_contents RAISE FND_API.G_EXC_ERROR;' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
8494             , 4
8495             );
8496           END IF;
8497 
8498           RAISE fnd_api.g_exc_error;
8499         END IF;
8500 
8501         IF l_return_status = fnd_api.g_ret_sts_unexp_error THEN
8502           IF (l_debug = 1) THEN
8503             print_debug(
8504                  'clear_LPN_for_ship 30.2: remove_lpn_contents RAISE FND_API.G_EXC_UNEXPECTED_ERROR;'
8505               || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
8506             , 4
8507             );
8508           END IF;
8509 
8510           RAISE fnd_api.g_exc_unexpected_error;
8511         END IF;
8512       END LOOP;
8513 
8514       CLOSE l_curs_lpn_for_ship;
8515     END IF;
8516 
8517     IF (l_debug = 1) THEN
8518       print_debug('clear_LPN_for_ship 20:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
8519     END IF;
8520   EXCEPTION
8521     WHEN OTHERS THEN
8522       ROLLBACK TO rcv_clear_lpn_cont_sp;
8523 
8524       IF l_curs_lpn_for_ship%ISOPEN THEN
8525         CLOSE l_curs_lpn_for_ship;
8526       END IF;
8527 
8528       IF l_curs_lpn_for_asn%ISOPEN THEN
8529         CLOSE l_curs_lpn_for_asn;
8530       END IF;
8531 
8532       x_return_status := fnd_api.g_ret_sts_unexp_error;
8533 
8534       IF SQLCODE IS NOT NULL THEN
8535         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.clear_LPN_for_ship', l_progress, SQLCODE);
8536       END IF;
8537 
8538       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8539   END clear_lpn_for_ship;
8540 
8541   -- Check if there are LPNs on this shipment
8542   -- If theres LPN on this shipment, lpn_flag = 1, else lpn_flag = 0
8543 
8544   PROCEDURE check_lpn_on_shipment(
8545     p_shipment_number       IN             VARCHAR2
8546   , p_from_organization_id  IN             NUMBER
8547   , p_to_organization_id    IN             NUMBER
8548   , x_lpn_flag              OUT NOCOPY     NUMBER
8549   , x_return_status         OUT NOCOPY     VARCHAR2
8550   , x_msg_count             OUT NOCOPY     NUMBER
8551   , x_msg_data              OUT NOCOPY     VARCHAR2
8552   ) IS
8553     l_lpn_count       NUMBER         := 0;
8554     l_lot_serial_flag NUMBER         := 1;
8555     l_return_status   VARCHAR2(1)    := fnd_api.g_ret_sts_success;
8556     l_msg_count       NUMBER;
8557     l_msg_data        VARCHAR2(4000);
8558     l_progress        VARCHAR2(10);
8559     l_debug           NUMBER         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
8560   BEGIN
8561     IF (l_debug = 1) THEN
8562       print_debug('check_lpn_on_shipment 10:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
8563     END IF;
8564 
8565     l_progress := '10';
8566     x_return_status := fnd_api.g_ret_sts_success;
8567     x_lpn_flag := 0;
8568 
8569       SELECT COUNT(*)
8570         INTO l_lpn_count
8571         FROM wms_license_plate_numbers
8572        WHERE organization_id = p_from_organization_id
8573          AND lpn_context = 6
8574          AND source_name = p_shipment_number;
8575 
8576     l_progress := '20';
8577 
8578     /* bug# 2783559
8579           We dont need to check for incompatible serial/lot/revision codes here,
8580           but in individual lpns
8581        IF l_lpn_count > 0 THEN
8582           -- fix for bug 2403033
8583           BEGIN
8584         SELECT 1
8585           INTO l_lot_serial_flag
8586           FROM rcv_shipment_lines rsl
8587              , rcv_shipment_headers rsh
8588              , mtl_system_items msi1
8589              , mtl_system_items msi2
8590          WHERE rsh.shipment_num = p_shipment_number
8591           AND rsl.shipment_header_id = rsh.shipment_header_id
8592           AND rsl.item_id = msi1.inventory_item_id
8593           AND msi1.organization_id = p_from_organization_id
8594           AND (Nvl(msi1.lot_control_code,1) <> Nvl(msi2.lot_control_code,1)
8595           OR (Nvl(msi1.serial_number_control_code,1) in (1,6)
8596               AND Nvl(msi2.serial_number_control_code,1) IN (2,5))
8597           OR (Nvl(msi1.serial_number_control_code,1) in (2,5)
8598               AND Nvl(msi2.serial_number_control_code,1) IN (1,6)))
8599           AND rsl.item_id = msi2.inventory_item_id
8600           AND msi2.organization_id = rsl.to_organization_id
8601           AND ROWNUM = 1;
8602         l_lot_serial_flag := 2;
8603           EXCEPTION
8604         WHEN no_data_found THEN
8605            l_lot_serial_flag := 0;
8606         WHEN OTHERS THEN
8607            l_lot_serial_flag := 1;
8608           END;
8609           IF l_lot_serial_flag = 0 THEN
8610         x_lpn_flag := 1;
8611            ELSIF l_lot_serial_flag = 2 THEN
8612         x_lpn_flag := 2;
8613            ELSE
8614         x_lpn_flag := 0;
8615           END IF;
8616        END IF;
8617     */
8618     IF l_lpn_count > 0 THEN
8619       x_lpn_flag := 1;
8620     END IF;
8621 
8622     IF (l_debug = 1) THEN
8623       print_debug('Exit check_lpn_on_shipment 20: l_lpn_count =  ' || l_lpn_count || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
8624       , 1);
8625     END IF;
8626   EXCEPTION
8627     WHEN NO_DATA_FOUND THEN
8628       x_lpn_flag := 0;
8629     WHEN OTHERS THEN
8630       x_return_status := fnd_api.g_ret_sts_unexp_error;
8631 
8632       IF SQLCODE IS NOT NULL THEN
8633         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.check_lpn_on_shipment', l_progress, SQLCODE);
8634       END IF;
8635 
8636       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8637   END check_lpn_on_shipment;
8638 
8639   PROCEDURE check_lpn_on_asn(
8640     p_shipment_header_id  IN             VARCHAR2
8641   , x_lpn_flag            OUT NOCOPY     NUMBER
8642   , x_return_status       OUT NOCOPY     VARCHAR2
8643   , x_msg_count           OUT NOCOPY     NUMBER
8644   , x_msg_data            OUT NOCOPY     VARCHAR2
8645   ) IS
8646     l_lpn_count       NUMBER         := 0;
8647     l_lot_serial_flag NUMBER         := 1;
8648     l_return_status   VARCHAR2(1)    := fnd_api.g_ret_sts_success;
8649     l_msg_count       NUMBER;
8650     l_msg_data        VARCHAR2(4000);
8651     l_progress        VARCHAR2(10);
8652     l_debug           NUMBER         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
8653   BEGIN
8654     IF (l_debug = 1) THEN
8655       print_debug('check_lpn_on_ASN 10:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
8656     END IF;
8657 
8658     l_progress := '10';
8659     x_lpn_flag := 0;
8660     x_return_status := fnd_api.g_ret_sts_success;
8661 
8662     SELECT COUNT(*)
8663       INTO l_lpn_count
8664       FROM wms_license_plate_numbers
8665      WHERE lpn_context = 7
8666        AND source_header_id = p_shipment_header_id;
8667 
8668     l_progress := '20';
8669 
8670     /* bug# 2783559
8671        We dont need to check for incompatible serial/lot/revision codes here,
8672        but in individual lpns
8673 
8674     IF l_lpn_count > 0 THEN
8675        -- fix for bug 2403033
8676        BEGIN
8677      SELECT 1
8678        INTO l_lot_serial_flag
8679        FROM rcv_shipment_lines rsl
8680           , rcv_shipment_headers rsh
8681           , mtl_system_items msi1
8682           , mtl_system_items msi2
8683       WHERE rsh.shipment_header_id = p_shipment_header_id
8684        AND rsl.shipment_header_id = rsh.shipment_header_id
8685        AND rsl.item_id = msi1.inventory_item_id
8686        AND msi1.organization_id = rsl.from_organization_id
8687        AND (Nvl(msi1.lot_control_code,1) <> Nvl(msi2.lot_control_code,1)
8688        OR (Nvl(msi1.serial_number_control_code,1) in (1,6)
8689            AND Nvl(msi2.serial_number_control_code,1) IN (2,5))
8690        OR (Nvl(msi1.serial_number_control_code,1) in (2,5)
8691            AND Nvl(msi2.serial_number_control_code,1) IN (1,6)))
8692        AND rsl.item_id = msi2.inventory_item_id
8693        AND msi2.organization_id = rsl.to_organization_id
8694        AND ROWNUM = 1;
8695      l_lot_serial_flag := 1;
8696        EXCEPTION
8697      WHEN no_data_found THEN
8698         l_lot_serial_flag := 0;
8699      WHEN OTHERS THEN
8700         l_lot_serial_flag := 1;
8701        END;
8702        IF l_lot_serial_flag = 0 THEN
8703      x_lpn_flag := 1;
8704         ELSE
8705      x_lpn_flag := 0;
8706        END IF;
8707     END IF;
8708     */
8709     IF l_lpn_count > 0 THEN
8710       x_lpn_flag := 1;
8711     ELSE
8712       x_lpn_flag := 0;
8713     END IF;
8714 
8715     IF (l_debug = 1) THEN
8716       print_debug('Exit check_lpn_on_ASN 20: l_lpn_count =  ' || l_lpn_count || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
8717     END IF;
8718   EXCEPTION
8719     WHEN NO_DATA_FOUND THEN
8720       x_lpn_flag := 0;
8721     WHEN OTHERS THEN
8722       x_return_status := fnd_api.g_ret_sts_unexp_error;
8723 
8724       IF SQLCODE IS NOT NULL THEN
8725         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.check_lpn_on_ASN', l_progress, SQLCODE);
8726       END IF;
8727 
8728       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8729   END check_lpn_on_asn;
8730 
8731   -- Express Int Req Receiving
8732   PROCEDURE check_lpn_on_req(
8733     p_req_num        IN             VARCHAR2
8734   , x_lpn_flag       OUT NOCOPY     NUMBER
8735   , x_return_status  OUT NOCOPY     VARCHAR2
8736   , x_msg_count      OUT NOCOPY     NUMBER
8737   , x_msg_data       OUT NOCOPY     VARCHAR2
8738   ) IS
8739     l_lpn_flag        NUMBER      := 0;
8740     l_lpn_id          NUMBER      := NULL;
8741     l_order_header_id NUMBER;
8742     l_order_line_id   NUMBER;
8743     l_return_status   VARCHAR2(1) := fnd_api.g_ret_sts_success;
8744     l_msg_count       NUMBER;
8745     l_msg_data        VARCHAR2(4000);
8746     l_progress        VARCHAR2(10);
8747     l_shipping_org    NUMBER;
8748     l_lpn_org         NUMBER;
8749     l_lpn_context     NUMBER;
8750     l_exit_outer      BOOLEAN     := FALSE;
8751     CURSOR c_order_lines IS
8752       SELECT line_id
8753         FROM oe_order_lines_all
8754        WHERE header_id = l_order_header_id;
8755 
8756     l_debug           NUMBER      := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
8757 
8758     -- bug 3209246
8759     CURSOR c_delivery_details(v_order_header_id NUMBER, v_order_line_id NUMBER) IS
8760       SELECT wdd1.lpn_id
8761            , wdd1.organization_id
8762         FROM wsh_delivery_details_ob_grp_v wdd, wsh_delivery_assignments_v wda
8763      , wsh_delivery_details_ob_grp_v wdd1
8764        WHERE wdd.source_header_id = v_order_header_id
8765          AND wdd.source_line_id = v_order_line_id
8766          AND wdd.delivery_detail_id = wda.delivery_detail_id
8767          AND wdd1.delivery_detail_id = wda.parent_delivery_detail_id;
8768   BEGIN
8769     l_progress := '10';
8770     SELECT header_id
8771       INTO l_order_header_id
8772       FROM oe_order_headers_all
8773      WHERE orig_sys_document_ref = p_req_num
8774        AND order_source_id = 10;
8775     --and    order_type_id    = 1023;
8776 
8777     IF (l_debug = 1) THEN
8778       print_debug('header_id: ' || TO_CHAR(l_order_header_id), 1);
8779     END IF;
8780 
8781     OPEN c_order_lines;
8782     l_progress := '20';
8783 
8784     LOOP
8785       FETCH c_order_lines INTO l_order_line_id;
8786       EXIT WHEN c_order_lines%NOTFOUND;
8787       l_progress := '30';
8788 
8789       /* Exp Int Req */
8790       IF (l_debug = 1) THEN
8791         print_debug('line_id: ' || TO_CHAR(l_order_line_id), 1);
8792       END IF;
8793 
8794       /* Bug #2778747
8795        * To check if the requisition contains a valid LPN, check for:
8796        * -> Get the lpn_id and org_id FROM wsh_delivery_details
8797        * -> If there is an LPN which belongs to the shipping org and the LPN context
8798        *    is "Resides in Intransit", then set the lpn_flag to 1 to indicate that the
8799        *    req contains a valid LPN that can be received and break out of the loop
8800        * -> If the LPN org is different from the shipping org, set the lpn_flag to 0
8801        *    and check for the next wsh_delivery_detail record.
8802        * -> If the LPN context is not "Resides in Intransit", i.e., the LPN was not
8803        *    shipped, set the lpn_flag to 0 and check for the next wsh_delivery_detail record
8804        */
8805       BEGIN
8806         l_exit_outer := FALSE;
8807         OPEN c_delivery_details(l_order_header_id, l_order_line_id);
8808 
8809         LOOP
8810           FETCH c_delivery_details INTO l_lpn_id, l_shipping_org;
8811           EXIT WHEN c_delivery_details%NOTFOUND;
8812           l_progress := 35;
8813           IF l_lpn_id IS NOT NULL THEN
8814             -- Nested LPN changes. Check whether the given LPN has content.
8815             IF inv_rcv_common_apis.g_po_patch_level < inv_rcv_common_apis.g_patchset_j_po
8816                OR inv_rcv_common_apis.g_inv_patch_level < inv_rcv_common_apis.g_patchset_j
8817                OR inv_rcv_common_apis.g_wms_patch_level < inv_rcv_common_apis.g_patchset_j THEN
8818               SELECT organization_id
8819                    , lpn_context
8820                 INTO l_lpn_org
8821                    , l_lpn_context
8822                 FROM wms_license_plate_numbers
8823                WHERE lpn_id = l_lpn_id;
8824             ELSE
8825               SELECT organization_id
8826                    , lpn_context
8827                 INTO l_lpn_org
8828                    , l_lpn_context
8829                 FROM wms_license_plate_numbers
8830                WHERE lpn_id = l_lpn_id
8831                  AND lpn_id IN(SELECT parent_lpn_id
8832                                  FROM wms_lpn_contents
8833                                 WHERE parent_lpn_id = l_lpn_id);
8834             END IF;
8835             IF (l_debug = 1) THEN
8836               print_debug('lpn_id: ' || TO_CHAR(l_lpn_id), 1);
8837               print_debug('lpn_org: ' || TO_CHAR(l_lpn_org), 1);
8838               print_debug('lpn_context: ' || TO_CHAR(l_lpn_context), 1);
8839             END IF;
8840 
8841             IF l_lpn_org <> l_shipping_org THEN
8842               l_lpn_flag := 0;
8843 
8844               IF (l_debug = 1) THEN
8845                 print_debug('lpn org and shipping org do not match', 1);
8846               END IF;
8847             ELSIF l_lpn_org = l_shipping_org
8848                   AND l_lpn_context <> 6 THEN
8849               l_lpn_flag := 0;
8850 
8851               IF (l_debug = 1) THEN
8852                 print_debug('lpn context is not resides in intransit', 1);
8853               END IF;
8854             ELSE
8855               l_lpn_flag := 1;
8856               l_exit_outer := TRUE;
8857 
8858               IF (l_debug = 1) THEN
8859                 print_debug('Found a valid LPN. Should come out of the loop', 1);
8860               END IF;
8861 
8862               EXIT;
8863             END IF;
8864           END IF;
8865         END LOOP;
8866 
8867         CLOSE c_delivery_details;
8868       EXCEPTION
8869         WHEN NO_DATA_FOUND THEN
8870           l_lpn_flag := 0;
8871 
8872           IF c_delivery_details%ISOPEN THEN
8873             CLOSE c_delivery_details;
8874           END IF;
8875       END;
8876 
8877       IF (l_debug = 1) THEN
8878         print_debug('lpn_id: ' || TO_CHAR(l_lpn_id), 1);
8879       END IF;
8880 
8881       IF l_lpn_flag = 1 THEN
8882         EXIT;
8883       END IF;
8884 
8885       /* Exp Int Req */
8886       l_progress := '40';
8887     END LOOP;
8888 
8889     CLOSE c_order_lines;
8890     l_progress := '50';
8891     /* bug 2783559 Dont need to check it here but, in individual lpn
8892        FOR ASN,Int Req and Int Shipment
8893 
8894     IF l_lpn_flag = 1 THEN
8895 
8896        BEGIN
8897      SELECT 2
8898        INTO l_lpn_flag
8899        FROM po_requisition_headers prh
8900        , po_requisition_lines prl
8901        , rcv_shipment_lines rsl
8902        , mtl_system_items msi1
8903        , mtl_system_items msi2
8904        WHERE prh.segment1 = p_req_num
8905        AND prl.requisition_header_id = prh.requisition_header_id
8906        AND rsl.requisition_line_id = prl.requisition_line_id
8907        AND rsl.item_id = msi1.inventory_item_id
8908        AND msi1.organization_id = rsl.from_organization_id
8909        AND (Nvl(msi1.lot_control_code,1) <> Nvl(msi2.lot_control_code,1)
8910        OR (Nvl(msi1.serial_number_control_code,1) in (1,6)
8911            AND Nvl(msi2.serial_number_control_code,1) IN (2,5))
8912        OR (Nvl(msi1.serial_number_control_code,1) in (2,5)
8913            AND Nvl(msi2.serial_number_control_code,1) IN (1,6)))
8914        AND rsl.item_id = msi2.inventory_item_id
8915        AND msi2.organization_id = rsl.to_organization_id
8916        AND ROWNUM = 1;
8917      l_lpn_flag := 2;
8918        EXCEPTION
8919      WHEN no_data_found THEN
8920         NULL;
8921        END;
8922    END IF;
8923    */
8924     x_lpn_flag := l_lpn_flag;
8925     x_return_status := l_return_status;
8926   EXCEPTION
8927     WHEN NO_DATA_FOUND THEN
8928       x_lpn_flag := 0;
8929       x_return_status := l_return_status;
8930     WHEN OTHERS THEN
8931       -- Nested LPN changes
8932       -- Close delivery detials cusror if it is open
8933       IF c_delivery_details%ISOPEN THEN
8934         CLOSE c_delivery_details;
8935       END IF;
8936 
8937       x_return_status := fnd_api.g_ret_sts_unexp_error;
8938 
8939       IF SQLCODE IS NOT NULL THEN
8940         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.check_lpn_on_REQ', l_progress, SQLCODE);
8941       END IF;
8942 
8943       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
8944   END;
8945 
8946   -- Express Int Req Receiving
8947 
8948   PROCEDURE update_lpn_org(
8949     p_organization_id  IN             NUMBER
8950   , p_lpn_id           IN             NUMBER
8951   , x_return_status    OUT NOCOPY     VARCHAR2
8952   , x_msg_count        OUT NOCOPY     NUMBER
8953   , x_msg_data         OUT NOCOPY     VARCHAR2
8954   ) IS
8955     l_return_status VARCHAR2(1)    := fnd_api.g_ret_sts_success;
8956     l_msg_count     NUMBER;
8957     l_msg_data      VARCHAR2(4000);
8958     l_progress      VARCHAR2(10);
8959     l_debug         NUMBER         := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
8960     --variables below are added for bug# 2814405
8961     l_serial_code   NUMBER;
8962     l_lot_code      NUMBER;
8963     l_item_id       NUMBER;
8964 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
8965     l_lot_number    VARCHAR2(80);
8966 
8967     CURSOR lpn_lot_items IS
8968       SELECT distinct inventory_item_id
8969         FROM wms_lpn_contents
8970        WHERE lot_number IS NOT NULL
8971          AND parent_lpn_id = p_lpn_id;
8972 
8973     CURSOR lpn_serial_items IS
8974       SELECT DISTINCT inventory_item_id
8975       FROM mtl_serial_numbers
8976       WHERE lpn_id = p_lpn_id;
8977   BEGIN
8978     IF (l_debug = 1) THEN
8979       print_debug('Enter update_LPN_Org 10:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
8980     END IF;
8981 
8982     x_return_status := fnd_api.g_ret_sts_success;
8983     SAVEPOINT rcv_update_lpn_org_sp;
8984     l_progress := '10';
8985 
8986     UPDATE wms_license_plate_numbers
8987        SET organization_id = p_organization_id
8988          , subinventory_code = ''
8989          , locator_id = NULL
8990      WHERE lpn_id = p_lpn_id;
8991 
8992     l_progress := '20';
8993     --bug# 2814405 start
8994     OPEN lpn_lot_items;
8995 
8996     LOOP
8997       FETCH lpn_lot_items INTO l_item_id;
8998       EXIT WHEN lpn_lot_items%NOTFOUND;
8999 
9000       BEGIN
9001         SELECT lot_control_code
9002           INTO l_lot_code
9003           FROM mtl_system_items
9004          WHERE inventory_item_id = l_item_id
9005            AND organization_id = p_organization_id;
9006 
9007         print_debug('item id ' || l_item_id || ' lot code ' || l_lot_code );
9008 
9009         IF (l_lot_code = 1) THEN
9010            UPDATE wms_lpn_contents
9011            SET lot_number = NULL   /* 3835398 */
9012            WHERE parent_lpn_id = p_lpn_id
9013      AND   inventory_item_id = l_item_id;
9014         END IF;
9015       EXCEPTION
9016         WHEN NO_DATA_FOUND THEN
9017           NULL;
9018           print_debug('Failed to get lot control codes ' || l_progress);
9019       END;
9020     END LOOP;
9021 
9022     OPEN lpn_serial_items;
9023 
9024     LOOP
9025       FETCH lpn_serial_items INTO l_item_id;
9026       EXIT WHEN lpn_serial_items%NOTFOUND;
9027 
9028       BEGIN
9029         l_progress := '25';
9030 
9031         SELECT serial_number_control_code
9032           INTO l_serial_code
9033           FROM mtl_system_items
9034          WHERE organization_id = p_organization_id
9035            AND inventory_item_id = l_item_id;
9036 
9037         IF l_serial_code IN(2, 5) THEN
9038           -- bug 2167174
9039           UPDATE mtl_serial_numbers
9040           SET    current_organization_id = p_organization_id
9041           WHERE  lpn_id = p_lpn_id
9042     AND    inventory_item_id = l_item_id; /* 3835398 */
9043 
9044   ELSIF (l_serial_code = 1 ) THEN
9045     UPDATE wms_lpn_contents
9046     SET    serial_summary_entry = 2
9047           WHERE  parent_lpn_id = p_lpn_id
9048     AND    inventory_item_id = l_item_id; /* 3835398 */
9049 
9050         END IF;
9051 
9052         l_progress := '30';
9053       EXCEPTION
9054         WHEN NO_DATA_FOUND THEN
9055           NULL;
9056           print_debug('Failed to get serial control codes ' || l_progress);
9057       END;
9058     END LOOP;
9059 
9060     -- bug# 2814405 end;
9061 
9062     UPDATE wms_lpn_contents
9063        SET organization_id = p_organization_id
9064      WHERE parent_lpn_id = p_lpn_id;
9065 
9066     l_progress := '40';
9067 
9068     IF (l_debug = 1) THEN
9069       print_debug('Exit update_LPN_Org 10:  ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
9070     END IF;
9071   EXCEPTION
9072     WHEN OTHERS THEN
9073       ROLLBACK TO rcv_update_lpn_org_sp;
9074       x_return_status := fnd_api.g_ret_sts_unexp_error;
9075 
9076       IF SQLCODE IS NOT NULL THEN
9077         inv_mobile_helper_functions.sql_error('INV_RCV_STD_RCPT_APIS.update_LPN_Org', l_progress, SQLCODE);
9078       END IF;
9079 
9080       fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
9081   END update_lpn_org;
9082 
9083 --Start of fix for the Bug #4037082
9084 --This procedure will validate the entered lot quantity
9085 --against the shipped lot quantity
9086 PROCEDURE validate_lot_qty(
9087                              p_lot_number         IN  VARCHAR2
9088                            , p_inventory_item_id  IN  NUMBER
9089                            , p_lot_txn_qty        IN  NUMBER
9090                            , p_lot_primary_qty    IN  NUMBER
9091                            , p_shipment_header_id IN  NUMBER
9092                            , p_rcv_org_id         IN  NUMBER
9093                            , x_return_status      OUT NOCOPY  VARCHAR2
9094                            )
9095 IS
9096 l_rlsu_quantity            RCV_LOTS_SUPPLY.QUANTITY%TYPE := 0;
9097 l_rlsu_primary_quantity    RCV_LOTS_SUPPLY.PRIMARY_QUANTITY%TYPE := 0;
9098 l_index                    NUMBER := 0;
9099 l_diff_txn_qty             NUMBER := 0;
9100 l_partial_rcpt             NUMBER := 0;
9101 l_rec_count                NUMBER := 0;
9102 l_debug                    NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
9103 
9104 BEGIN
9105 
9106   IF (l_debug = 1) THEN
9107      print_debug('validate_lot_qty: 10 Entering into Lot Qty Validation Procedure' , 4);
9108      print_debug('validate_lot_qty: 20 Validating for lot: ' || p_lot_number || ' Item: ' || p_inventory_item_id || ' shipment_hdr_id: '|| p_shipment_header_id  , 4);
9109      print_debug('validate_lot_qty: 30 txn_qty :' || p_lot_txn_qty || ' p_lot_primary_qty: ' || p_lot_primary_qty || ' p_rcv_org_id: ' || p_rcv_org_id , 4);
9110   END IF;
9111 
9112   x_return_status := fnd_api.g_ret_sts_success;
9113 
9114   BEGIN
9115     SELECT count(1)
9116       INTO l_partial_rcpt
9117       FROM dual
9118      WHERE EXISTS ( SELECT 1
9119                       FROM rcv_transactions
9120                      WHERE shipment_header_id = p_shipment_header_id
9121                        AND organization_id    = p_rcv_org_id
9122                   );
9123   EXCEPTION
9124     WHEN OTHERS THEN
9125       l_partial_rcpt := 0;
9126   END;
9127 
9128   IF l_partial_rcpt = 0 THEN
9129      BEGIN
9130        SELECT count(1)
9131        INTO l_partial_rcpt
9132        FROM dual
9133       WHERE EXISTS ( SELECT 1
9134                       FROM rcv_transactions_interface
9135                      WHERE shipment_header_id  = p_shipment_header_id
9136                        AND to_organization_id  = p_rcv_org_id
9137                   );
9138     EXCEPTION
9139      WHEN OTHERS THEN
9140        l_partial_rcpt := 0;
9141     END;
9142   END IF;
9143 
9144   IF l_partial_rcpt = 1 THEN
9145     print_debug('validate_lot_qty: 30.1 Not doing Qty Validation for Partial Receipts..Hence Returning..' , 4);
9146     RETURN;
9147   END IF;
9148 
9149   BEGIN
9150 
9151     SELECT NVL(SUM(rlsu.quantity),0) ,
9152            NVL(SUM(rlsu.primary_quantity),0)
9153      INTO  l_rlsu_quantity,
9154            l_rlsu_primary_quantity
9155      FROM  rcv_lots_supply rlsu,
9156            rcv_shipment_lines rsl
9157     WHERE  rlsu.shipment_line_id = rsl.shipment_line_id
9158       AND  rsl.item_id  = p_inventory_item_id
9159       AND  rsl.to_organization_id = p_rcv_org_id
9160       AND  rsl.shipment_header_id = p_shipment_header_id
9161       AND  rlsu.lot_num = p_lot_number
9162       AND  rlsu.supply_type_code = 'SHIPMENT' ;
9163   EXCEPTION
9164      WHEN OTHERS THEN
9165        IF (l_debug = 1) THEN
9166          print_debug('validate_lot_qty: 40  When Others Exception' , 4);
9167        END IF;
9168        l_rlsu_quantity := 0 ;
9169        l_rlsu_primary_quantity := 0 ;
9170   END;
9171 
9172   IF NVL(p_lot_primary_qty,0) <> 0 AND l_rlsu_primary_quantity <> 0 THEN
9173     IF p_lot_primary_qty > l_rlsu_primary_quantity THEN
9174       fnd_message.set_name('INV', 'INV_MAX_QTY');
9175       fnd_message.set_token('TOKEN', l_rlsu_primary_quantity);
9176       fnd_msg_pub.add;
9177       IF (l_debug = 1) THEN
9178          print_debug('validate_lot_qty: 50 Receiving Lot Qty : ' || p_lot_primary_qty || ' cannot be more than Shipped Qty : ' || l_rlsu_primary_quantity , 4);
9179       END IF;
9180 
9181       --Removing the errored Lot from g_rcpt_lot_qty_rec_tb table
9182       l_rec_count := g_rcpt_lot_qty_rec_tb.COUNT;
9183 
9184        FOR i IN 1 .. l_rec_count  LOOP
9185          IF g_rcpt_lot_qty_rec_tb(i).lot_number = p_lot_number THEN
9186            l_diff_txn_qty := g_rcpt_lot_qty_rec_tb(i).txn_quantity - p_lot_txn_qty ;
9187            l_index := i;
9188            EXIT;
9189          END IF;
9190        END LOOP;
9191 
9192        IF l_diff_txn_qty = 0 THEN
9193           IF l_rec_count = 1 THEN
9194             g_rcpt_lot_qty_rec_tb.DELETE;
9195           ELSE
9196             g_rcpt_lot_qty_rec_tb.DELETE(l_index);
9197           END IF;
9198        ELSE
9199          g_rcpt_lot_qty_rec_tb(l_index).txn_quantity := l_diff_txn_qty ;
9200        END IF;
9201 
9202       x_return_status := fnd_api.g_ret_sts_error;
9203       RETURN;
9204     END IF;
9205   END IF;
9206 
9207   IF (l_debug = 1) THEN
9208      print_debug('validate_lot_qty: 60  Exitting from Lot Qty Validation Procedure' , 4);
9209   END IF;
9210 
9211 END validate_lot_qty;
9212 --End of fix for the Bug #4037082
9213 
9214  --Added to fix the Bug #4086191
9215  --overload the procedure created above
9216  --with one more parameter, p_product_transaction_id
9217  PROCEDURE validate_lot_qty(
9218      p_lot_number         IN  VARCHAR2
9219   ,  p_inventory_item_id  IN  NUMBER
9220   ,  p_lot_txn_qty        IN  NUMBER
9221   ,  p_lot_primary_qty    IN  NUMBER
9222   ,  p_shipment_header_id IN  NUMBER
9223   ,  p_rcv_org_id         IN  NUMBER
9224   ,  p_product_txn_id     IN  NUMBER
9225   ,  x_return_status      OUT NOCOPY  VARCHAR2
9226   ) IS
9227      l_rlsu_primary_quantity    RCV_LOTS_SUPPLY.PRIMARY_QUANTITY%TYPE := 0;
9228      l_mtli_primary_quantity    NUMBER := 0;
9229      l_current_grp_prim_qty     NUMBER := 0;
9230      l_debug                    NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
9231 
9232  BEGIN
9233   IF (l_debug = 1) THEN
9234      print_debug('validate_lot_qty J: 10 Entering into Lot Qty Validation Procedure' , 4);
9235      print_debug('validate_lot_qty J: 20 Validating for lot: ' || p_lot_number || ' Item: ' || p_inventory_item_id || ' shipment_hdr_id: '|| p_shipment_header_id  , 4);
9236      print_debug('validate_lot_qty J: 30 txn_qty :' || p_lot_txn_qty || ' p_lot_primary_qty: ' || p_lot_primary_qty || ' p_rcv_org_id: ' || p_rcv_org_id , 4);
9237      print_debug('validate_lot_qty J: 31 p_shipment_header_id:' || p_shipment_header_id);
9238      print_debug('validate_lot_qty J: 31 p_prod_txn_id:' || p_product_txn_id);
9239   END IF;
9240 
9241   x_return_status := fnd_api.g_ret_sts_success;
9242 
9243   BEGIN
9244      SELECT  NVL(SUM(rlsu.primary_quantity),0)
9245        INTO  l_rlsu_primary_quantity
9246        FROM  rcv_lots_supply rlsu,
9247              rcv_shipment_lines rsl
9248        WHERE rlsu.shipment_line_id = rsl.shipment_line_id
9249        AND   rsl.item_id  = p_inventory_item_id
9250        AND   rsl.to_organization_id = p_rcv_org_id
9251        AND   rsl.shipment_header_id = p_shipment_header_id
9252        AND   rlsu.lot_num = p_lot_number
9253        AND   rlsu.supply_type_code = 'SHIPMENT' ;
9254   EXCEPTION
9255      WHEN OTHERS THEN
9256 	IF (l_debug = 1) THEN
9257 	   print_debug('validate_lot_qty: 31  When Others Exception' , 4);
9258 	END IF;
9259 	l_rlsu_primary_quantity := 0 ;
9260   END;
9261 
9262   BEGIN
9263      SELECT   NVL(SUM(mtli.primary_quantity),0)
9264        INTO   l_mtli_primary_quantity
9265        FROM   mtl_transaction_lots_interface mtli,
9266               rcv_transactions_interface rti
9267        WHERE  rti.processing_status_code <> 'ERROR'
9268        AND    rti.transaction_status_code <> 'ERROR'
9269        AND    rti.to_organization_id = p_rcv_org_id
9270        AND    rti.item_id = p_inventory_item_id
9271        AND    rti.shipment_header_id = p_shipment_header_id
9272        AND    rti.interface_transaction_id = mtli.product_transaction_id
9273        AND    mtli.lot_number = p_lot_number
9274        AND    mtli.product_code = 'RCV';
9275   EXCEPTION
9276      WHEN OTHERS THEN
9277 	IF (l_debug = 1) THEN
9278 	   print_debug('validate_lot_qty: 32  When Others Exception' , 4);
9279 	END IF;
9280 	l_mtli_primary_quantity := 0;
9281   END;
9282 
9283   IF (p_product_txn_id IS NOT NULL) THEN
9284      BEGIN
9285 	SELECT Nvl(SUM(primary_quantity),0)
9286 	  INTO l_current_grp_prim_qty
9287 	  FROM mtl_transaction_lots_interface
9288 	  WHERE product_transaction_id = p_product_txn_id
9289 	  AND   lot_number = p_lot_number
9290 	  AND   product_code = 'RCV';
9291      EXCEPTION
9292 	WHEN OTHERS THEN
9293 	   IF (l_debug = 1) THEN
9294 	      print_debug('validate_lot_qty: 32  When Others Exception' , 4);
9295 	   END IF;
9296 	   l_current_grp_prim_qty := 0;
9297      END;
9298    ELSE
9299 	   l_current_grp_prim_qty := 0;
9300   END IF;
9301 
9302   IF (l_debug = 1) THEN
9303      print_debug('validate_lot_qty: 33 RLS Qty : ' || l_rlsu_primary_quantity,4);
9304      print_debug('validate_lot_qty: 34 MTLI QTY : ' || l_mtli_primary_quantity,4);
9305      print_debug('validate_lot_qty: 34 l_current_grp_prim_qty : ' || l_current_grp_prim_qty,4);
9306   END IF;
9307 
9308   IF  (p_lot_primary_qty > (l_rlsu_primary_quantity - (l_mtli_primary_quantity + l_current_grp_prim_qty) )) THEN
9309      fnd_message.set_name('INV', 'INV_MAX_QTY');
9310      fnd_message.set_token('TOKEN', l_rlsu_primary_quantity - (l_mtli_primary_quantity + l_current_grp_prim_qty));
9311      fnd_msg_pub.add;
9312      x_return_status := fnd_api.g_ret_sts_error;
9313      IF (l_debug = 1) THEN
9314 	print_debug('validate_lot_qty: 33 Receiving Lot Qty : ' || p_lot_primary_qty || ' cannot be more than Shipped Qty : ' || l_rlsu_primary_quantity , 4);
9315      END IF;
9316    ELSE
9317      RETURN;
9318   END IF;
9319 
9320  EXCEPTION
9321     WHEN OTHERS THEN
9322        x_return_status := fnd_api.g_ret_sts_error;
9323        IF (l_debug = 1) THEN
9324 	  print_debug('validate_lot_qty: Exception occured!  Exiting...', 4);
9325       END IF;
9326  END validate_lot_qty;
9327 
9328   --Added to fix the Bug #6908946
9329  --overload the procedure created above
9330  --with one more parameter, p_from_lpn_id
9331  PROCEDURE validate_lot_qty(
9332      p_lot_number         IN  VARCHAR2
9333   ,  p_inventory_item_id  IN  NUMBER
9334   ,  p_lot_txn_qty        IN  NUMBER
9335   ,  p_lot_primary_qty    IN  NUMBER
9336   ,  p_shipment_header_id IN  NUMBER
9337   ,  p_rcv_org_id         IN  NUMBER
9338   ,  p_product_txn_id     IN  NUMBER
9339   ,  p_from_lpn_id        IN  NUMBER
9340   ,  x_return_status      OUT NOCOPY  VARCHAR2
9341   ) IS
9342      l_rlsu_primary_quantity    RCV_LOTS_SUPPLY.PRIMARY_QUANTITY%TYPE := 0;
9343      l_mtli_primary_quantity    NUMBER := 0;
9344      l_current_grp_prim_qty     NUMBER := 0;
9345      l_debug                    NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
9346 
9347  BEGIN
9348   IF (l_debug = 1) THEN
9349      print_debug('validate_lot_qty J: 10 Entering into Lot Qty Validation Procedure' , 4);
9350      print_debug('validate_lot_qty J: 20 Validating for lot: ' || p_lot_number || ' Item: ' || p_inventory_item_id || ' shipment_hdr_id: '|| p_shipment_header_id  , 4);
9351      print_debug('validate_lot_qty J: 30 txn_qty :' || p_lot_txn_qty || ' p_lot_primary_qty: ' || p_lot_primary_qty || ' p_rcv_org_id: ' || p_rcv_org_id , 4);
9352      print_debug('validate_lot_qty J: 31 p_shipment_header_id:' || p_shipment_header_id);
9353      print_debug('validate_lot_qty J: 32 p_prod_txn_id:' || p_product_txn_id);
9354      print_debug('validate_lot_qty J: 33 p_from_lpn_id:' || p_from_lpn_id);
9355   END IF;
9356 
9357   x_return_status := fnd_api.g_ret_sts_success;
9358 
9359   BEGIN
9360      SELECT  NVL(SUM(rlsu.primary_quantity),0)
9361        INTO  l_rlsu_primary_quantity
9362        FROM  rcv_lots_supply rlsu,
9363              rcv_shipment_lines rsl
9364        WHERE rlsu.shipment_line_id = rsl.shipment_line_id
9365        AND   rsl.item_id  = p_inventory_item_id
9366        AND   rsl.to_organization_id = p_rcv_org_id
9367        AND   rsl.shipment_header_id = p_shipment_header_id
9368        AND   rlsu.lot_num = p_lot_number
9369        AND   rlsu.supply_type_code = 'SHIPMENT'
9370        AND   Nvl(rsl.asn_lpn_id,-1)  = Nvl(decode(p_from_lpn_id,0,NULL,p_from_lpn_id),Nvl(rsl.asn_lpn_id,-1));
9371 
9372      print_debug('validate_lot_qty: 31 l_rlsu_primary_quantity' || l_rlsu_primary_quantity , 4);
9373   EXCEPTION
9374      WHEN OTHERS THEN
9375 	IF (l_debug = 1) THEN
9376 	   print_debug('validate_lot_qty: 31  When Others Exception' , 4);
9377 	END IF;
9378 	l_rlsu_primary_quantity := 0 ;
9379   END;
9380 
9381   BEGIN
9382      SELECT   NVL(SUM(mtli.primary_quantity),0)
9383        INTO   l_mtli_primary_quantity
9384        FROM   mtl_transaction_lots_interface mtli,
9385               rcv_transactions_interface rti
9386        WHERE  rti.processing_status_code <> 'ERROR'
9387        AND    rti.transaction_status_code <> 'ERROR'
9388        AND    rti.to_organization_id = p_rcv_org_id
9389        AND    rti.item_id = p_inventory_item_id
9390        AND    rti.shipment_header_id = p_shipment_header_id
9391        AND    rti.interface_transaction_id = mtli.product_transaction_id
9392        AND    mtli.lot_number = p_lot_number
9393        AND    mtli.product_code = 'RCV'
9394        AND    Nvl(rti.lpn_id,-1)  = Nvl(decode(p_from_lpn_id,0,NULL,p_from_lpn_id),Nvl(rti.lpn_id,-1));
9395   EXCEPTION
9396      WHEN OTHERS THEN
9397 	IF (l_debug = 1) THEN
9398 	   print_debug('validate_lot_qty: 32  When Others Exception' , 4);
9399 	END IF;
9400 	l_mtli_primary_quantity := 0;
9401   END;
9402 
9403   IF (p_product_txn_id IS NOT NULL) THEN
9404      BEGIN
9405 	SELECT Nvl(SUM(primary_quantity),0)
9406 	  INTO l_current_grp_prim_qty
9407 	  FROM mtl_transaction_lots_interface
9408 	  WHERE product_transaction_id = p_product_txn_id
9409 	  AND   lot_number = p_lot_number
9410 	  AND   product_code = 'RCV';
9411      EXCEPTION
9412 	WHEN OTHERS THEN
9413 	   IF (l_debug = 1) THEN
9414 	      print_debug('validate_lot_qty: 32  When Others Exception' , 4);
9415 	   END IF;
9416 	   l_current_grp_prim_qty := 0;
9417      END;
9418    ELSE
9419 	   l_current_grp_prim_qty := 0;
9420   END IF;
9421 
9422   IF (l_debug = 1) THEN
9423      print_debug('validate_lot_qty: 33 RLS Qty : ' || l_rlsu_primary_quantity,4);
9424      print_debug('validate_lot_qty: 34 MTLI QTY : ' || l_mtli_primary_quantity,4);
9425      print_debug('validate_lot_qty: 34 l_current_grp_prim_qty : ' || l_current_grp_prim_qty,4);
9426   END IF;
9427 
9428   IF  (p_lot_primary_qty > (l_rlsu_primary_quantity - (l_mtli_primary_quantity + l_current_grp_prim_qty) )) THEN
9429      fnd_message.set_name('INV', 'INV_MAX_QTY');
9430      fnd_message.set_token('TOKEN', l_rlsu_primary_quantity - (l_mtli_primary_quantity + l_current_grp_prim_qty));
9431      fnd_msg_pub.add;
9432      x_return_status := fnd_api.g_ret_sts_error;
9433      IF (l_debug = 1) THEN
9434 	print_debug('validate_lot_qty: 33 Receiving Lot Qty : ' || p_lot_primary_qty || ' cannot be more than Shipped Qty : ' || l_rlsu_primary_quantity , 4);
9435      END IF;
9436    ELSE
9437      RETURN;
9438   END IF;
9439 
9440  EXCEPTION
9441     WHEN OTHERS THEN
9442        x_return_status := fnd_api.g_ret_sts_error;
9443        IF (l_debug = 1) THEN
9444 	  print_debug('validate_lot_qty: Exception occured!  Exiting...', 4);
9445       END IF;
9446  END validate_lot_qty;
9447 
9448 END inv_rcv_std_rcpt_apis;