DBA Data[Home] [Help]

PACKAGE BODY: APPS.PO_PDOI_LINE_PROCESS_PVT

Source


1 PACKAGE BODY po_pdoi_line_process_pvt AS
2 /* $Header: PO_PDOI_LINE_PROCESS_PVT.plb 120.58.12020000.3 2013/02/10 17:03:50 vegajula ship $ */
3 
4 d_pkg_name CONSTANT VARCHAR2(50) :=
5   PO_LOG.get_package_base('PO_PDOI_LINE_PROCESS_PVT');
6 
7 --------------------------------------------------------------------------
8 ---------------------- PRIVATE PROCEDURES PROTOTYPE ----------------------
9 --------------------------------------------------------------------------
10 
11 -- bug5684695
12 -- removed derive_po_header_id procedure
13 
14 
15 PROCEDURE derive_item_id
16 (
17   p_key                    IN po_session_gt.key%TYPE,
18   p_index_tbl              IN DBMS_SQL.NUMBER_TABLE,
19   p_vendor_id_tbl          IN PO_TBL_NUMBER,
20   p_intf_header_id_tbl     IN PO_TBL_NUMBER,
21   p_intf_line_id_tbl       IN PO_TBL_NUMBER,
22   p_vendor_product_num_tbl IN PO_TBL_VARCHAR30,
23   p_category_id_tbl        IN PO_TBL_NUMBER,            --bug 7374337
24   p_item_tbl               IN PO_TBL_VARCHAR2000,
25   x_item_id_tbl            IN OUT NOCOPY PO_TBL_NUMBER,
26   x_error_flag_tbl         IN OUT NOCOPY PO_TBL_VARCHAR1
27 );
28 
29 PROCEDURE derive_item_revision
30 (
31   p_key                    IN po_session_gt.key%TYPE,
32   p_item_id_tbl            IN PO_TBL_NUMBER,
33   x_item_revision_tbl      IN OUT NOCOPY PO_TBL_VARCHAR5
34 );
35 
36 PROCEDURE derive_job_business_group_id
37 (
38   p_key                            IN po_session_gt.key%TYPE,
39   p_index_tbl                      IN DBMS_SQL.NUMBER_TABLE,
40   p_job_business_group_name_tbl    IN PO_TBL_VARCHAR2000,
41   x_job_business_group_id_tbl      IN OUT NOCOPY PO_TBL_NUMBER
42 );
43 
44 PROCEDURE derive_job_id
45 (
46   p_key                            IN po_session_gt.key%TYPE,
47   p_index_tbl                      IN DBMS_SQL.NUMBER_TABLE,
48   p_file_line_language_tbl         IN PO_TBL_VARCHAR5,
49   p_job_business_group_name_tbl    IN PO_TBL_VARCHAR2000,
50   p_job_name_tbl                   IN PO_TBL_VARCHAR2000,
51   x_job_business_group_id_tbl      IN OUT NOCOPY PO_TBL_NUMBER,
52   x_job_id_tbl                     IN OUT NOCOPY PO_TBL_NUMBER
53 );
54 
55 PROCEDURE derive_category_id
56 (
57   p_key                  IN po_session_gt.key%TYPE,
58   p_category_tbl         IN PO_TBL_VARCHAR2000,
59   x_category_id_tbl      IN OUT NOCOPY PO_TBL_NUMBER
60 );
61 
62 PROCEDURE derive_ip_category_id
63 (
64   p_key                    IN po_session_gt.key%TYPE,
65   p_index_tbl              IN DBMS_SQL.NUMBER_TABLE,
66   p_file_line_language_tbl IN PO_TBL_VARCHAR5,
67   p_ip_category_tbl        IN PO_TBL_VARCHAR2000,
68   x_ip_category_id_tbl     IN OUT NOCOPY PO_TBL_NUMBER
69 );
70 
71 PROCEDURE derive_unit_of_measure
72 (
73   p_key                  IN po_session_gt.key%TYPE,
74   p_index_tbl            IN DBMS_SQL.NUMBER_TABLE,
75   p_uom_code_tbl         IN PO_TBL_VARCHAR5,
76   x_unit_of_measure_tbl  IN OUT NOCOPY PO_TBL_VARCHAR30
77 );
78 
79 PROCEDURE derive_line_type_id
80 (
81   p_key                    IN po_session_gt.key%TYPE,
82   p_index_tbl              IN DBMS_SQL.NUMBER_TABLE,
83   p_file_line_language_tbl IN PO_TBL_VARCHAR5,
84   p_line_type_tbl          IN PO_TBL_VARCHAR30,
85   x_line_type_id_tbl       IN OUT NOCOPY PO_TBL_NUMBER
86 );
87 
88 PROCEDURE derive_un_number_id
89 (
90   p_key                  IN po_session_gt.key%TYPE,
91   p_index_tbl            IN DBMS_SQL.NUMBER_TABLE,
92   p_un_number_tbl        IN PO_TBL_VARCHAR30,
93   x_un_number_id_tbl     IN OUT NOCOPY PO_TBL_NUMBER
94 );
95 
96 PROCEDURE derive_hazard_class_id
97 (
98   p_key                  IN po_session_gt.key%TYPE,
99   p_index_tbl            IN DBMS_SQL.NUMBER_TABLE,
100   p_hazard_class_tbl     IN PO_TBL_VARCHAR100,
101   x_hazard_class_id_tbl  IN OUT NOCOPY PO_TBL_NUMBER
102 );
103 
104 PROCEDURE derive_template_id
105 (
106   p_key                  IN po_session_gt.key%TYPE,
107   p_index_tbl            IN DBMS_SQL.NUMBER_TABLE,
108   p_template_name_tbl    IN PO_TBL_VARCHAR30,
109   x_template_id_tbl      IN OUT NOCOPY PO_TBL_NUMBER
110 );
111 
112 PROCEDURE default_info_from_line_type
113 (
114   p_key                        IN po_session_gt.key%TYPE,
115   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
116   p_line_type_id_tbl           IN PO_TBL_NUMBER,
117   x_order_type_lookup_code_tbl IN OUT NOCOPY PO_TBL_VARCHAR30,
118   x_purchase_basis_tbl         IN OUT NOCOPY PO_TBL_VARCHAR30,
119   x_matching_basis_tbl         IN OUT NOCOPY PO_TBL_VARCHAR30,
120   x_category_id_tbl            OUT NOCOPY PO_TBL_NUMBER,
121   x_unit_of_measure_tbl        OUT NOCOPY PO_TBL_VARCHAR30,
122   x_unit_price_tbl             OUT NOCOPY PO_TBL_NUMBER
123 );
124 
125 PROCEDURE default_info_from_item
126 (
127   p_key                        IN po_session_gt.key%TYPE,
128   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
129   p_item_id_tbl                IN PO_TBL_NUMBER,
130   x_item_desc_tbl              OUT NOCOPY PO_TBL_VARCHAR2000,
131   x_unit_of_measure_tbl        OUT NOCOPY PO_TBL_VARCHAR30,
132   x_unit_price_tbl             OUT NOCOPY PO_TBL_NUMBER,
133   x_category_id_tbl            OUT NOCOPY PO_TBL_NUMBER,
134   x_un_number_id_tbl           OUT NOCOPY PO_TBL_NUMBER,
135   x_hazard_class_id_tbl        OUT NOCOPY PO_TBL_NUMBER,
136   x_market_price_tbl           OUT NOCOPY PO_TBL_NUMBER,
137   x_secondary_unit_of_meas_tbl OUT NOCOPY PO_TBL_VARCHAR30
138 );
139 
140 PROCEDURE default_info_from_job
141 (
142   p_key                        IN po_session_gt.key%TYPE,
143   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
144   p_job_id_tbl                 IN PO_TBL_NUMBER,
145   x_item_desc_tbl              OUT NOCOPY PO_TBL_VARCHAR2000,
146   x_category_id_tbl            OUT NOCOPY PO_TBL_NUMBER
147 );
148 
149 PROCEDURE default_po_cat_id_from_ip
150 (
151   p_key                        IN po_session_gt.key%TYPE,
152   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
153   p_ip_category_id_tbl         IN PO_TBL_NUMBER,
154   x_po_category_id_tbl         IN OUT NOCOPY PO_TBL_NUMBER
155 );
156 
157 PROCEDURE default_ip_cat_id_from_po
158 (
159   p_key                        IN po_session_gt.key%TYPE,
160   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
161   p_po_category_id_tbl         IN PO_TBL_NUMBER,
162   x_ip_category_id_tbl         IN OUT NOCOPY PO_TBL_NUMBER
163 );
164 
165 PROCEDURE default_hc_id_from_un_number
166 (
167   p_key                        IN po_session_gt.key%TYPE,
168   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
169   p_un_number_tbl              IN PO_TBL_VARCHAR30,
170   x_hazard_class_id_tbl        IN OUT NOCOPY PO_TBL_NUMBER
171 );
172 
173 PROCEDURE match_lines_on_line_num
174 (
175   p_index_tbl     IN DBMS_SQL.NUMBER_TABLE,
176   x_lines         IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
177 );
178 
179 PROCEDURE match_lines_on_item_info
180 (
181   x_lines         IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
182 );
183 
184 PROCEDURE copy_lines
185 (
186   p_source_lines     IN PO_PDOI_TYPES.lines_rec_type,
187   p_source_index_tbl IN DBMS_SQL.NUMBER_TABLE,
188   x_target_lines     IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
189 );
190 
191 PROCEDURE uniqueness_check_on_desc
192 (
193   p_key                 IN po_session_gt.key%TYPE,
194   p_group_num           IN NUMBER,
195   x_processing_row_tbl  IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
196   x_lines               IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
197 );
198 
199 PROCEDURE uniqueness_check_on_item
200 (
201   p_key                 IN po_session_gt.key%TYPE,
202   p_group_num           IN NUMBER,
203   x_processing_row_tbl  IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
204   x_lines               IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
205 );
206 
207 PROCEDURE uniqueness_check_on_vpn
208 (
209   p_key                 IN po_session_gt.key%TYPE,
210   p_group_num           IN NUMBER,
211   x_processing_row_tbl  IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
212   x_lines               IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
213 );
214 
215 PROCEDURE uniqueness_check_on_job
216 (
217   p_key                 IN po_session_gt.key%TYPE,
218   p_group_num           IN NUMBER,
219   x_processing_row_tbl  IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
220   x_lines               IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
221 );
222 
223 PROCEDURE uniqueness_check_on_line_num
224 (
225   p_key                 IN po_session_gt.key%TYPE,
226   p_group_num           IN NUMBER,
227   x_processing_row_tbl  IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
228   x_lines               IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
229 );
230 
231 
232 PROCEDURE set_action_add
233 (
234   p_key                   IN po_session_gt.key%TYPE,
235   p_group_num             IN NUMBER,
236   p_target_lines_index_tbl IN PO_TBL_NUMBER,
237   p_check_line_num_assign IN VARCHAR2,
238   x_processing_row_tbl    IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
239   x_lines                 IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
240 );
241 
242 
243 PROCEDURE validate_attr_tlp
244 (
245   x_lines IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
246 );
247 
248 PROCEDURE populate_error_flag
249 (
250   x_results           IN     po_validation_results_type,
251   x_lines             IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
252 );
253 
254 PROCEDURE handle_err_tolerance
255 (
256   x_lines       IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
257 );
258 
259 --CLM PDOI Integration Starts
260 PROCEDURE derive_contract_type
261 (
262   p_key                       IN po_session_gt.key%TYPE,
263   p_index_tbl                 IN DBMS_SQL.NUMBER_TABLE,
264   p_contract_type_display_tbl IN PO_TBL_VARCHAR240,
265   x_contract_type_tbl         IN OUT NOCOPY PO_TBL_VARCHAR240
266 );
267 
268 PROCEDURE derive_cost_constraint
269 (
270   p_key                                IN po_session_gt.key%TYPE,
271   p_index_tbl                          IN DBMS_SQL.NUMBER_TABLE,
272   p_cost_constraint_display_tbl IN PO_TBL_VARCHAR240,
273   x_cost_constraint_tbl         IN OUT NOCOPY PO_TBL_VARCHAR30
274 );
275 
276 PROCEDURE derive_clm_idc_type
277 (
278   p_key                      IN po_session_gt.key%TYPE,
279   p_index_tbl                IN DBMS_SQL.NUMBER_TABLE,
280   p_clm_idc_type_display_tbl IN PO_TBL_VARCHAR240,
281   x_clm_idc_type_tbl         IN OUT NOCOPY PO_TBL_VARCHAR240
282 );
283 
284 PROCEDURE derive_clm_base_line_num
285 (
286   p_key                        IN po_session_gt.key%TYPE,
287   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
288   p_clm_base_line_num_disp_tbl IN PO_TBL_VARCHAR240,
289   p_intf_line_id_tbl           IN PO_TBL_NUMBER,
290   p_intf_header_id_tbl         IN PO_TBL_NUMBER,
291   p_line_num_display_tbl       IN PO_TBL_VARCHAR100,
292   p_clm_option_indicator       IN PO_TBL_VARCHAR1,
293   x_clm_base_line_num_tbl      IN OUT NOCOPY PO_TBL_NUMBER
294 );
295 
296 PROCEDURE derive_from_line_id
297 (
298   p_key                        IN po_session_gt.key%TYPE,
299   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
300   p_from_line_disp_tbl         IN PO_TBL_VARCHAR240,
301   p_from_header_id_tbl         IN PO_TBL_NUMBER,
302   x_from_line_id_tbl           IN OUT NOCOPY PO_TBL_NUMBER
303 );
304 
305 PROCEDURE derive_from_header_id
306 (
307   p_key                        IN po_session_gt.key%TYPE,
308   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
309   p_from_header_disp_tbl       IN PO_TBL_VARCHAR240,
310   x_from_header_id_tbl         IN OUT NOCOPY PO_TBL_NUMBER
311 );
312 
313 PROCEDURE default_clm_option_indicator
314 (
315   p_key                        IN po_session_gt.key%TYPE,
316   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
317   p_intf_line_id_tbl           IN PO_TBL_NUMBER,
318   p_clm_base_line_num_tbl      IN PO_TBL_NUMBER,
319   x_clm_option_indicator_tbl   IN OUT NOCOPY PO_TBL_VARCHAR1
320 );
321 
322 PROCEDURE default_clm_option_num
323 (
324   p_key                        IN po_session_gt.key%TYPE,
325   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
326   p_intf_header_id_tbl         IN PO_TBL_NUMBER,
327   p_intf_line_id_tbl           IN PO_TBL_NUMBER,
328   p_clm_base_line_num_tbl      IN PO_TBL_NUMBER,
329   p_clm_option_indicator_tbl   IN PO_TBL_VARCHAR1,
330   x_clm_option_num_tbl         IN OUT NOCOPY PO_TBL_NUMBER
331 );
332 
333 PROCEDURE default_from_header_id
334 (
335   p_key                        IN po_session_gt.key%TYPE,
336   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
337   p_intf_header_id_tbl         IN PO_TBL_NUMBER,
338   p_intf_line_id_tbl           IN PO_TBL_NUMBER,
339   x_from_header_id_tbl         IN OUT NOCOPY PO_TBL_NUMBER
340 );
341 
342 --CLM PDOI Integration Ends
343 
344 --------------------------------------------------------------------------
345 ---------------------- PUBLIC PROCEDURES ---------------------------------
346 --------------------------------------------------------------------------
347 
348 -----------------------------------------------------------------------
349 --Start of Comments
350 --Name: reject_dup_lines_for_spo
351 --Function: standard po lines cannot be updated. So if the new line in
352 --          interface table has the same line num as existing lines in
353 --          same document, these new lines will be regarded as intention
354 --          to update existing standard po records thus rejected.
355 --Parameters:
356 --IN:
357 --IN OUT:
358 --OUT:
359 --End of Comments
360 ------------------------------------------------------------------------
361 PROCEDURE reject_dup_lines_for_spo IS
362 
363   d_api_name CONSTANT VARCHAR2(30) := 'reject_dup_lines_for_spo';
364   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
365   d_position NUMBER;
366 
367   -- select lines which have same line num as lines in txn table
368   CURSOR c_dup_lines_in_txn(p_request_processing_id NUMBER,
369                             p_request_processing_round_num NUMBER) IS
370   SELECT intf_headers.interface_header_id,
371          intf_lines.interface_line_id,
372          intf_lines.line_num
373   FROM   po_lines_interface intf_lines,
374          po_headers_interface intf_headers,
375          po_lines txn_lines
376   WHERE  intf_lines.interface_header_id = intf_headers.interface_header_id
377   AND    intf_headers.po_header_id = txn_lines.po_header_id
378   AND    intf_lines.processing_id = p_request_processing_id
379   AND    intf_headers.processing_round_num = p_request_processing_round_num
380   AND    intf_headers.processing_id = p_request_processing_id
381   AND    intf_lines.line_num = txn_lines.line_num
382   AND    intf_headers.action = PO_PDOI_CONSTANTS.g_ACTION_UPDATE;
383 
384   -- select lines which have same line num as lines in draft table
385   CURSOR c_dup_lines_in_draft(p_request_processing_id NUMBER,
386                               p_request_processing_round_num NUMBER) IS
387   SELECT intf_headers.interface_header_id,
388          intf_lines.interface_line_id,
389          intf_lines.line_num
390   FROM   po_headers_interface intf_headers,
391          po_lines_interface intf_lines,
392          po_lines_draft_all draft_lines
393   WHERE  intf_lines.interface_header_id = intf_headers.interface_header_id
394   AND    intf_headers.draft_id = draft_lines.draft_id
395   AND    intf_headers.po_header_id = draft_lines.po_header_id
396   AND    intf_lines.processing_id = p_request_processing_id
397   AND    intf_headers.processing_round_num = p_request_processing_round_num
398   AND    intf_headers.processing_id = p_request_processing_id
399   AND    intf_lines.line_num = draft_lines.line_num
400   AND    intf_headers.action = PO_PDOI_CONSTANTS.g_ACTION_UPDATE;
401 
402   -- duplicate lines in interface table
403   l_dup_intf_header_id_tbl PO_TBL_NUMBER;
404   l_dup_intf_line_id_tbl   PO_TBL_NUMBER;
405   l_dup_intf_line_num_tbl  PO_TBL_NUMBER;
406 
407   -- number of duplicate lines retrieved in each batch
408   l_count NUMBER;
409 BEGIN
410   d_position := 0;
411 
412   IF (PO_LOG.d_proc) THEN
413     PO_LOG.proc_begin(d_module);
414   END IF;
415 
416   -- first reject lines which are duplicate in txn table
417   OPEN c_dup_lines_in_txn(PO_PDOI_PARAMS.g_processing_id,
418                         PO_PDOI_PARAMS.g_current_round_num);
419 
420   d_position := 10;
421 
422   LOOP
423     -- retrieve identifiers of duplicate lines
424     FETCH c_dup_lines_in_txn
425     BULK COLLECT INTO
426       l_dup_intf_header_id_tbl,
427       l_dup_intf_line_id_tbl,
428       l_dup_intf_line_num_tbl
429     LIMIT PO_PDOI_CONSTANTS.g_DEF_BATCH_SIZE;
430 
431     d_position := 20;
432 
433     l_count := l_dup_intf_line_id_tbl.COUNT;
434 
435     IF (PO_LOG.d_stmt) THEN
436       PO_LOG.stmt(d_module, d_position, 'duplicate count against txn table', l_count);
437     END IF;
438 
439     EXIT WHEN l_count = 0;
440 
441     -- add error if a duplicate line is found
442     FOR i IN 1..l_count
443     LOOP
444       d_position := 30;
445 
446       IF (PO_LOG.d_stmt) THEN
447         PO_LOG.stmt(d_module, d_position, 'duplicate interface line id(txn)',
448                     l_dup_intf_line_id_tbl(i));
449       END IF;
450 
451       PO_PDOI_ERR_UTL.add_fatal_error
452       (
453         p_interface_header_id  => l_dup_intf_header_id_tbl(i),
454         p_interface_line_id    => l_dup_intf_line_id_tbl(i),
455         p_error_message_name   => 'PO_PDOI_STD_PO_LINE_NUM_EXISTS',
456         p_table_name           => 'PO_LINES_INTERFACE',
457         p_column_name          => 'LINE_NUM',
458         p_column_value         => l_dup_intf_line_num_tbl(i),
459         p_token1_name          => 'VALUE',
460         p_token1_value         => l_dup_intf_line_num_tbl(i)
461       );
462     END LOOP;
463 
464     d_position := 40;
465 
466     -- reject the lines and the lower level entities associated with it
467     PO_PDOI_UTL.reject_lines_intf
468     (
469       p_id_param_type           => PO_PDOI_CONSTANTS.g_INTERFACE_LINE_ID,
470       p_id_tbl                  => l_dup_intf_line_id_tbl,
471       p_cascade                 => FND_API.g_TRUE
472     );
473 
474     d_position := 50;
475 
476     IF (l_count < PO_PDOI_CONSTANTS.g_DEF_BATCH_SIZE) THEN
477       EXIT;
478     END IF;
479   END LOOP;
480 
481   CLOSE c_dup_lines_in_txn;
482 
483   d_position := 60;
484 
485   -- next, reject lines which are duplicate of lines in draft table
486   OPEN c_dup_lines_in_draft(PO_PDOI_PARAMS.g_processing_id,
487                           PO_PDOI_PARAMS.g_current_round_num);
488 
489   d_position := 70;
490 
491   LOOP
492     -- check duplicate lines in draft table
493     FETCH c_dup_lines_in_draft
494     BULK COLLECT INTO
495       l_dup_intf_header_id_tbl,
496       l_dup_intf_line_id_tbl,
497       l_dup_intf_line_num_tbl
498     LIMIT PO_PDOI_CONSTANTS.g_DEF_BATCH_SIZE;
499 
500     d_position := 80;
501 
502     l_count := l_dup_intf_line_id_tbl.COUNT;
503 
504     IF (PO_LOG.d_stmt) THEN
505       PO_LOG.stmt(d_module, d_position, 'duplicate count against draft table ', l_count);
506     END IF;
507 
508     EXIT WHEN l_count = 0;
509 
510     -- add error if a duplicate line is found
511     FOR i IN 1..l_count
512     LOOP
513       d_position := 90;
514 
515       IF (PO_LOG.d_stmt) THEN
516         PO_LOG.stmt(d_module, d_position, 'duplicate interface line id(draft)',
517                     l_dup_intf_line_id_tbl(i));
518       END IF;
519 
520       PO_PDOI_ERR_UTL.add_fatal_error
521       (
522         p_interface_header_id  => l_dup_intf_header_id_tbl(i),
523         p_interface_line_id    => l_dup_intf_line_id_tbl(i),
524         p_error_message_name   => 'PO_PDOI_STD_PO_LINE_NUM_EXISTS',
525         p_table_name           => 'PO_LINES_INTERFACE',
526         p_column_name          => 'LINE_NUM',
527         p_column_value         => l_dup_intf_line_num_tbl(i),
528         p_token1_name          => 'VALUE',
529         p_token1_value         => l_dup_intf_line_num_tbl(i)
530       );
531     END LOOP;
532 
533     d_position := 100;
534 
535     -- reject the lines and the lower level entities associated with it
536     PO_PDOI_UTL.reject_lines_intf
537     (
538       p_id_param_type           => PO_PDOI_CONSTANTS.g_INTERFACE_LINE_ID,
539       p_id_tbl                  => l_dup_intf_line_id_tbl,
540       p_cascade                 => FND_API.g_TRUE
541     );
542 
543     d_position := 110;
544 
545     IF (l_count < PO_PDOI_CONSTANTS.g_DEF_BATCH_SIZE) THEN
546       EXIT;
547     END IF;
548   END LOOP;
549 
550   CLOSE c_dup_lines_in_draft;
551 
552   d_position := 120;
553 
554   IF (PO_LOG.d_proc) THEN
555     PO_LOG.proc_end (d_module);
556   END IF;
557 
558 EXCEPTION
559   WHEN OTHERS THEN
560     PO_MESSAGE_S.add_exc_msg
561     (
562       p_pkg_name => d_pkg_name,
563       p_procedure_name => d_api_name || '.' || d_position
564     );
565     RAISE;
566 END reject_dup_lines_for_spo;
567 
568 -----------------------------------------------------------------------
569 --Start of Comments
570 --Name: reject_invalid_action_lines
571 --Function: The valid value of line level action is NULL or 'ADD' when
572 --          user issues a PDOI request. System will reject lines with
573 --          invalid action values.
574 --Parameters:
575 --IN:
576 --IN OUT:
577 --OUT:
578 --End of Comments
579 ------------------------------------------------------------------------
580 PROCEDURE reject_invalid_action_lines IS
581 
582   d_api_name CONSTANT VARCHAR2(30) := 'reject_invalid_action_lines';
583   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
584   d_position NUMBER;
585 
586   -- select lines with invalid line level action value
587   CURSOR c_invalid_action_lines(p_request_processing_id NUMBER,
588                                 p_request_processing_round_num NUMBER) IS
589   SELECT intf_lines.interface_line_id,
590          intf_headers.interface_header_id,
591          intf_lines.action
592   FROM   po_lines_interface intf_lines,
593          po_headers_interface intf_headers
594   WHERE  intf_lines.interface_header_id = intf_headers.interface_header_id
595   AND    intf_lines.processing_id = p_request_processing_id
596   AND    intf_headers.processing_round_num = p_request_processing_round_num
597   AND    intf_headers.processing_id = p_request_processing_id
598   AND    NVL(intf_lines.action, PO_PDOI_CONSTANTS.g_ACTION_ADD) <>
599          PO_PDOI_CONSTANTS.g_ACTION_ADD;
600 
601   -- interface line id of lines that need to be rejected
602   l_rej_intf_line_id_tbl   PO_TBL_NUMBER;
603   l_rej_intf_header_id_tbl PO_TBL_NUMBER;
604   l_rej_line_action_tbl    PO_TBL_VARCHAR30;
605 
606 BEGIN
607   d_position := 0;
608 
609   IF (PO_LOG.d_proc) THEN
610     PO_LOG.proc_begin(d_module);
611   END IF;
612 
613   -- get all invalid lines from cursor
614   OPEN c_invalid_action_lines(PO_PDOI_PARAMS.g_processing_id,
615                               PO_PDOI_PARAMS.g_current_round_num);
616 
617   d_position := 10;
618 
619   FETCH c_invalid_action_lines
620   BULK COLLECT INTO
621     l_rej_intf_line_id_tbl, l_rej_intf_header_id_tbl, l_rej_line_action_tbl;
622 
623   d_position := 20;
624 
625   IF (PO_LOG.d_stmt) THEN
626     PO_LOG.stmt(d_module, d_position, 'count of lines with invalid actions',
627               l_rej_intf_line_id_tbl.COUNT);
628   END IF;
629 
630   -- add error if an invalid line is found
631   FOR i IN 1..l_rej_intf_line_id_tbl.COUNT
632   LOOP
633     d_position := 30;
634 
635     IF (PO_LOG.d_stmt) THEN
636       PO_LOG.stmt(d_module, d_position, 'rejected interface line id',
637                   l_rej_intf_line_id_tbl(i));
638     END IF;
639 
640     PO_PDOI_ERR_UTL.add_fatal_error
641     (
642       p_interface_header_id  => l_rej_intf_header_id_tbl(i),
643       p_interface_line_id    => l_rej_intf_line_id_tbl(i),
644       p_error_message_name   => 'PO_PDOI_INVALID_ACTION',
645       p_table_name           => 'PO_LINES_INTERFACE',
646       p_column_name          => 'ACTION',
647       p_column_value         => l_rej_line_action_tbl(i),
648       p_token1_name          => 'VALUE',
649       p_token1_value         => l_rej_line_action_tbl(i)
650     );
651   END LOOP;
652 
653   d_position := 40;
654 
655   -- reject the lines and the lower level entities associated with it
656   PO_PDOI_UTL.reject_lines_intf
657   (
658     p_id_param_type           => PO_PDOI_CONSTANTS.g_INTERFACE_LINE_ID,
659     p_id_tbl                  => l_rej_intf_line_id_tbl,
660     p_cascade                 => FND_API.g_TRUE
661   );
662 
663   d_position := 50;
664 
665   CLOSE c_invalid_action_lines;
666 
667   IF (PO_LOG.d_proc) THEN
668     PO_LOG.proc_end (d_module);
669   END IF;
670 
671 EXCEPTION
672   WHEN OTHERS THEN
673     PO_MESSAGE_S.add_exc_msg
674     (
675       p_pkg_name => d_pkg_name,
676       p_procedure_name => d_api_name || '.' || d_position
677     );
678     RAISE;
679 END reject_invalid_action_lines;
680 
681 -----------------------------------------------------------------------
682 --Start of Comments
683 --Name: open_lines
684 --Function: open the correct cursor to retrieve line records
685 --Parameters:
686 --IN:
687 --  p_data_set_type
688 --    flag to indicate what kind of lines should be retrieved
689 --  p_max_intf_line_id
690 --    maximal interface_line_id processed in previous batches
691 --IN OUT:
692 --  x_lines_csr
693 --    cursor to point to the first record in the result batch
694 --OUT:
695 --End of Comments
696 ------------------------------------------------------------------------
697 PROCEDURE open_lines
698 (
699   p_data_set_type      IN NUMBER,
700   p_max_intf_line_id   IN NUMBER,
701   x_lines_csr          OUT NOCOPY PO_PDOI_TYPES.intf_cursor_type
702 ) IS
703 
704   d_api_name CONSTANT VARCHAR2(30) := 'open_lines';
705   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
706   d_position NUMBER;
707 
708 BEGIN
709   d_position := 0;
710 
711   IF (PO_LOG.d_proc) THEN
712     PO_LOG.proc_begin(d_module, 'p_data_set_type', p_data_set_type);
713     PO_LOG.proc_begin(d_module, 'p_max_intf_line_id', p_max_intf_line_id);
714   END IF;
715 
716   -- bug5107324
717   -- cursor now selects NULL into allow_desc_update_flag_tbl as well
718 
719   IF (p_data_set_type = PO_PDOI_CONSTANTS.g_LINE_CSR_ADD) THEN
720     d_position := 10;
721 
722     OPEN x_lines_csr FOR
723       SELECT intf_lines.interface_line_id,
724              intf_lines.interface_header_id,
725              intf_lines.po_header_id,
726              NULL, -- intf_lines.po_line_id,
727              intf_lines.action,
728              intf_lines.document_num,
729              intf_lines.item,
730              intf_lines.vendor_product_num,
731              intf_lines.supplier_part_auxid,
732              intf_lines.item_id,
733              intf_lines.item_revision,
734              intf_lines.job_business_group_name,
735              intf_lines.job_business_group_id,
736              intf_lines.job_name,
737              intf_lines.job_id,
738              intf_lines.category,
739              intf_lines.category_id,
740              intf_lines.ip_category_name,
741              intf_lines.ip_category_id,
742              intf_lines.uom_code,
743              intf_lines.unit_of_measure,
744              intf_lines.line_type,
745              intf_lines.line_type_id,
746              intf_lines.un_number,
747              intf_lines.un_number_id,
748              intf_lines.hazard_class,
749              intf_lines.hazard_class_id,
750              intf_lines.template_name,
751              intf_lines.template_id,
752              intf_lines.item_description,
753              intf_lines.unit_price,
754              intf_lines.base_unit_price,
755              intf_lines.from_header_id,
756              intf_lines.from_line_id,
757              intf_lines.list_price_per_unit,
758              intf_lines.market_price,
759              intf_lines.capital_expense_flag,
760              intf_lines.min_release_amount,
761              intf_lines.allow_price_override_flag,
762              intf_lines.price_type,
763              intf_lines.price_break_lookup_code,
764              intf_lines.closed_code,
765              intf_lines.quantity,
766              intf_lines.line_num,
767              intf_lines.shipment_num,
768              intf_lines.price_chg_accept_flag,
769              intf_lines.effective_date,
770              intf_lines.expiration_date,
771              intf_lines.line_attribute14,
772              intf_lines.price_update_tolerance,
773              intf_lines.line_loc_populated_flag,
774              -- << PDOI for Complex PO Project: Start >>
775              intf_lines.retainage_rate,
776              intf_lines.max_retainage_amount,
777              intf_lines.progress_payment_rate,
778              intf_lines.recoupment_rate,
779              intf_lines.advance_amount,
780              -- << PDOI for Complex PO Project: End >>
781              intf_lines.negotiated_by_preparer_flag,
782              intf_lines.amount,
783              intf_lines.contractor_last_name,
784              intf_lines.contractor_first_name,
785              intf_lines.over_tolerance_error_flag,
786              intf_lines.not_to_exceed_price,
787              intf_lines.po_release_id,
788              intf_lines.release_num,
789              intf_lines.source_shipment_id,
790              intf_lines.contract_num,
791              intf_lines.contract_id,
792              intf_lines.type_1099,
793              intf_lines.closed_by,
794              intf_lines.closed_date,
795              intf_lines.committed_amount,
796              intf_lines.qty_rcv_exception_code,
797              intf_lines.weight_uom_code,
798              intf_lines.volume_uom_code,
799              intf_lines.secondary_unit_of_measure,
800              intf_lines.secondary_quantity,
801              intf_lines.preferred_grade,
802              intf_lines.process_code,
803              NULL, -- parent_interface_line_id -- bug5149827
804              intf_lines.file_line_language, -- bug 5489942
805 
806              -- standard who columns
807              intf_lines.last_updated_by,
808              intf_lines.last_update_date,
809              intf_lines.last_update_login,
810              intf_lines.creation_date,
811              intf_lines.created_by,
812              intf_lines.request_id,
813              intf_lines.program_application_id,
814              intf_lines.program_id,
815              intf_lines.program_update_date,
816 
817              -- attributes read from headers
818              intf_headers.draft_id,
819              intf_headers.action,
820              intf_headers.po_header_id,
821              draft_headers.vendor_id,
822              draft_headers.min_release_amount,
823              draft_headers.start_date,
824              draft_headers.end_date,
825              draft_headers.global_agreement_flag,
826              draft_headers.currency_code,
827              draft_headers.created_language,
828              draft_headers.style_id,
829              draft_headers.rate_type,
830 	         draft_headers.rate,   -- bug 9194215
831 
832              -- txn table columns
833              NULL, -- order_type_lookup_code
834              NULL, -- purchase_basis
835              NULL, -- matching_basis
836              NULL, -- unordered_flag
837              NULL, -- cancel_flag
838              NULL, -- quantity_committed
839              NULL, -- tax_attribute_update_code
840              intf_lines.clm_info_flag,   /* 10354034 */
841              intf_lines.group_line_id, --PDOI CLM Integration
842 
843              DECODE(intf_lines.process_code,
844                     PO_PDOI_CONSTANTS.g_PROCESS_CODE_VAL_AND_REJECT,
845                     FND_API.g_TRUE, FND_API.g_FALSE), -- error_flag_tbl
846              FND_API.g_FALSE,                    -- need_to_reject_flag_tbl
847              FND_API.g_FALSE,                    -- create_line_loc_tbl
848              -1,                                 -- group_num
849              NULL,                               -- origin_line_num
850              FND_API.g_FALSE,                    -- match_line_found
851              NULL,                                -- allow_desc_update_flag_tbl
852              --CLM PDOI Integration
853              intf_lines.contract_type,
854              intf_lines.cost_constraint,
855              intf_lines.note_to_vendor,
856              intf_lines.oke_contract_version_id,
857              intf_lines.oke_contract_header_id,
858              intf_lines.clm_option_indicator,
859              intf_lines.clm_base_line_num,
860              intf_lines.clm_option_num,
861              intf_lines.clm_option_from_date,
862              intf_lines.clm_option_to_date,
863              Decode(PO_PDOI_PARAMS.g_request.document_type,
864                     PO_PDOI_CONSTANTS.g_DOC_TYPE_STANDARD, Nvl(intf_lines.clm_idc_type,'IDC_NA'),
865                     intf_lines.clm_idc_type),
866              intf_lines.line_num_display,
867              intf_lines.clm_funded_flag,
868              intf_lines.user_document_status,
869              intf_lines.clm_exercised_flag,
870              intf_lines.clm_exercised_date,
871              intf_lines.clm_min_total_amount,
872              intf_lines.clm_max_total_amount,
873              intf_lines.clm_min_total_quantity,
874              intf_lines.clm_max_total_quantity,
875              intf_lines.clm_min_order_amount,
876              intf_lines.clm_max_order_amount,
877              intf_lines.clm_min_order_quantity,
878              intf_lines.clm_max_order_quantity,
879              intf_lines.clm_total_amount_ordered,
880              intf_lines.clm_total_quantity_ordered,
881              intf_lines.clm_period_perf_end_date,
882              intf_lines.clm_period_perf_start_date,
883              intf_lines.contract_type_display,
884              intf_lines.cost_constraint_display,
885              intf_lines.clm_idc_type_display,
886              intf_lines.clm_base_line_num_disp,
887              intf_lines.from_header_disp,
888              intf_lines.from_line_disp
889 
890       FROM   po_lines_interface intf_lines,
891              po_headers_interface intf_headers,
892              po_headers_draft_all draft_headers
893       WHERE  intf_lines.interface_header_id = intf_headers.interface_header_id
894       AND    intf_headers.draft_id = draft_headers.draft_id
895       AND    intf_headers.po_header_id = draft_headers.po_header_id
896       AND    intf_lines.processing_id = PO_PDOI_PARAMS.g_processing_id
897       AND    intf_headers.processing_round_num = PO_PDOI_PARAMS.g_current_round_num
898       AND    intf_headers.processing_id = PO_PDOI_PARAMS.g_processing_id
899       AND    intf_lines.interface_line_id > p_max_intf_line_id
900       AND    intf_headers.action IN (PO_PDOI_CONSTANTS.g_ACTION_ORIGINAL,
901                                      PO_PDOI_CONSTANTS.g_ACTION_REPLACE)
902       --PDOI CLM Integration
903       --Process only priced lines which in commercial flow are normal lines
904       AND    Nvl(intf_lines.clm_info_flag,'N') = 'N'
905 
906       UNION ALL
907 
908       SELECT intf_lines.interface_line_id,
909              intf_lines.interface_header_id,
910              intf_lines.po_header_id,
911              NULL, -- intf_lines.po_line_id,
912              intf_lines.action,
913              intf_lines.document_num,
914              intf_lines.item,
915              intf_lines.vendor_product_num,
916              intf_lines.supplier_part_auxid,
917              intf_lines.item_id,
918              intf_lines.item_revision,
919              intf_lines.job_business_group_name,
920              intf_lines.job_business_group_id,
921              intf_lines.job_name,
922              intf_lines.job_id,
923              intf_lines.category,
924              intf_lines.category_id,
925              intf_lines.ip_category_name,
926              intf_lines.ip_category_id,
927              intf_lines.uom_code,
928              intf_lines.unit_of_measure,
929              intf_lines.line_type,
930              intf_lines.line_type_id,
931              intf_lines.un_number,
932              intf_lines.un_number_id,
933              intf_lines.hazard_class,
934              intf_lines.hazard_class_id,
935              intf_lines.template_name,
936              intf_lines.template_id,
937              intf_lines.item_description,
938              intf_lines.unit_price,
939              intf_lines.base_unit_price,
940              intf_lines.from_header_id,
941              intf_lines.from_line_id,
942              intf_lines.list_price_per_unit,
943              intf_lines.market_price,
944              intf_lines.capital_expense_flag,
945              intf_lines.min_release_amount,
946              intf_lines.allow_price_override_flag,
947              intf_lines.price_type,
948              intf_lines.price_break_lookup_code,
949              intf_lines.closed_code,
950              intf_lines.quantity,
951              intf_lines.line_num,
952              intf_lines.shipment_num,
953              intf_lines.price_chg_accept_flag,
954              intf_lines.effective_date,
955              intf_lines.expiration_date,
956              intf_lines.line_attribute14,
957              intf_lines.price_update_tolerance,
958              intf_lines.line_loc_populated_flag,
959              -- << PDOI for Complex PO Project: Start >>
960              intf_lines.retainage_rate,
961              intf_lines.max_retainage_amount,
962              intf_lines.progress_payment_rate,
963              intf_lines.recoupment_rate,
964              intf_lines.advance_amount,
965              -- << PDOI for Complex PO Project: End >>
966              intf_lines.negotiated_by_preparer_flag,
967              intf_lines.amount,
968              intf_lines.contractor_last_name,
969              intf_lines.contractor_first_name,
970              intf_lines.over_tolerance_error_flag,
971              intf_lines.not_to_exceed_price,
972              intf_lines.po_release_id,
973              intf_lines.release_num,
974              intf_lines.source_shipment_id,
975              intf_lines.contract_num,
976              intf_lines.contract_id,
977              intf_lines.type_1099,
978              intf_lines.closed_by,
979              intf_lines.closed_date,
980              intf_lines.committed_amount,
981              intf_lines.qty_rcv_exception_code,
982              intf_lines.weight_uom_code,
983              intf_lines.volume_uom_code,
984              intf_lines.secondary_unit_of_measure,
985              intf_lines.secondary_quantity,
986              intf_lines.preferred_grade,
987              intf_lines.process_code,
988              NULL, -- parent_interface_line_id -- bug5149827
989              intf_lines.file_line_language, -- bug 5489942
990 
991              -- standard who columns
992              intf_lines.last_updated_by,
993              intf_lines.last_update_date,
994              intf_lines.last_update_login,
995              intf_lines.creation_date,
996              intf_lines.created_by,
997              intf_lines.request_id,
998              intf_lines.program_application_id,
999              intf_lines.program_id,
1000              intf_lines.program_update_date,
1001 
1002              -- attributes read from header
1003              intf_headers.draft_id,
1004              intf_headers.action,
1005              intf_headers.po_header_id,
1006              txn_headers.vendor_id,
1007              txn_headers.min_release_amount,
1008              txn_headers.start_date,
1009              txn_headers.end_date,
1010              txn_headers.global_agreement_flag,
1011              txn_headers.currency_code,
1012              txn_headers.created_language,
1013              txn_headers.style_id,
1014              txn_headers.rate_type,
1015 	         txn_headers.rate,  -- bug 9194215
1016 
1017              -- txn table columns
1018              NULL, -- order_type_lookup_code
1019              NULL, -- purchase_basis
1020              NULL, -- matching_basis
1021              NULL, -- unordered_flag
1022              NULL, -- cancel_flag
1023              NULL, -- quantity_committed
1024              NULL, -- tax_attribute_update_code
1025              intf_lines.clm_info_flag, /* 10354034 */
1026              intf_lines.group_line_id, --CLM PDOI Integration
1027 
1028              DECODE(intf_lines.process_code, PO_PDOI_CONSTANTS.g_PROCESS_CODE_VAL_AND_REJECT,
1029                FND_API.g_TRUE, FND_API.g_FALSE),  -- error_flag_tbl
1030              FND_API.G_FALSE,                     -- need_to_reject_flag_tbl
1031              FND_API.g_FALSE,                     -- create_line_loc_tbl
1032              -1,                                  -- group_num
1033              NULL,                               -- origin_line_num
1034              FND_API.g_FALSE,                    -- match_line_found
1035              NULL,                                -- allow_desc_update_flag_tbl
1036              --CLM PDOI Integration
1037              intf_lines.contract_type,
1038              intf_lines.cost_constraint,
1039              intf_lines.note_to_vendor,
1040              intf_lines.oke_contract_version_id,
1041              intf_lines.oke_contract_header_id,
1042              intf_lines.clm_option_indicator,
1043              intf_lines.clm_base_line_num,
1044              intf_lines.clm_option_num,
1045              intf_lines.clm_option_from_date,
1046              intf_lines.clm_option_to_date,
1047              Decode(PO_PDOI_PARAMS.g_request.document_type,
1048                     PO_PDOI_CONSTANTS.g_DOC_TYPE_STANDARD, Nvl(intf_lines.clm_idc_type,'IDC_NA'),
1049                     intf_lines.clm_idc_type),
1050              intf_lines.line_num_display,
1051              intf_lines.clm_funded_flag,
1052              intf_lines.user_document_status,
1053              intf_lines.clm_exercised_flag,
1054              intf_lines.clm_exercised_date,
1055              intf_lines.clm_min_total_amount,
1056              intf_lines.clm_max_total_amount,
1057              intf_lines.clm_min_total_quantity,
1058              intf_lines.clm_max_total_quantity,
1059              intf_lines.clm_min_order_amount,
1060              intf_lines.clm_max_order_amount,
1061              intf_lines.clm_min_order_quantity,
1062              intf_lines.clm_max_order_quantity,
1063              intf_lines.clm_total_amount_ordered,
1064              intf_lines.clm_total_quantity_ordered,
1065              intf_lines.clm_period_perf_end_date,
1066              intf_lines.clm_period_perf_start_date,
1067              intf_lines.contract_type_display,
1068              intf_lines.cost_constraint_display,
1069              intf_lines.clm_idc_type_display,
1070              intf_lines.clm_base_line_num_disp,
1071              intf_lines.from_header_disp,
1072              intf_lines.from_line_disp
1073 
1074 
1075       FROM   po_lines_interface intf_lines,
1076              po_headers_interface intf_headers,
1077              po_headers txn_headers
1078       WHERE  intf_lines.interface_header_id = intf_headers.interface_header_id
1079       AND    intf_headers.po_header_id = txn_headers.po_header_id
1080       AND    intf_lines.processing_id = PO_PDOI_PARAMS.g_processing_id
1081       AND    intf_headers.processing_round_num = PO_PDOI_PARAMS.g_current_round_num
1082       AND    intf_headers.processing_id = PO_PDOI_PARAMS.g_processing_id
1083       AND    intf_lines.interface_line_id > p_max_intf_line_id
1084       AND    intf_headers.action = PO_PDOI_CONSTANTS.g_ACTION_UPDATE
1085       AND    PO_PDOI_PARAMS.g_request.document_type = PO_PDOI_CONSTANTS.g_DOC_TYPE_STANDARD
1086       --PDOI CLM Integration
1087       --Process only priced lines which in commercial flow are normal lines
1088       AND    Nvl(intf_lines.clm_info_flag,'N') = 'N'
1089       ORDER BY 1;
1090   ELSIF (p_data_set_type = PO_PDOI_CONSTANTS.g_LINE_CSR_FORCE_ADD) THEN
1091     d_position := 20;
1092 
1093     OPEN x_lines_csr FOR
1094       SELECT intf_lines.interface_line_id,
1095              intf_lines.interface_header_id,
1096              intf_lines.po_header_id,
1097              NULL, -- intf_lines.po_line_id,
1098              intf_lines.action,
1099              intf_lines.document_num,
1100              intf_lines.item,
1101              intf_lines.vendor_product_num,
1102              intf_lines.supplier_part_auxid,
1103              intf_lines.item_id,
1104              intf_lines.item_revision,
1105              intf_lines.job_business_group_name,
1106              intf_lines.job_business_group_id,
1107              intf_lines.job_name,
1108              intf_lines.job_id,
1109              intf_lines.category,
1110              intf_lines.category_id,
1111              intf_lines.ip_category_name,
1112              intf_lines.ip_category_id,
1113              intf_lines.uom_code,
1114              intf_lines.unit_of_measure,
1115              intf_lines.line_type,
1116              intf_lines.line_type_id,
1117              intf_lines.un_number,
1118              intf_lines.un_number_id,
1119              intf_lines.hazard_class,
1120              intf_lines.hazard_class_id,
1121              intf_lines.template_name,
1122              intf_lines.template_id,
1123              intf_lines.item_description,
1124              intf_lines.unit_price,
1125              intf_lines.base_unit_price,
1126              intf_lines.from_header_id,
1127              intf_lines.from_line_id,
1128              intf_lines.list_price_per_unit,
1129              intf_lines.market_price,
1130              intf_lines.capital_expense_flag,
1131              intf_lines.min_release_amount,
1132              intf_lines.allow_price_override_flag,
1133              intf_lines.price_type,
1134              intf_lines.price_break_lookup_code,
1135              intf_lines.closed_code,
1136              intf_lines.quantity,
1137              intf_lines.line_num,
1138              intf_lines.shipment_num,
1139              intf_lines.price_chg_accept_flag,
1140              intf_lines.effective_date,
1141              intf_lines.expiration_date,
1142              intf_lines.line_attribute14,
1143              intf_lines.price_update_tolerance,
1144              intf_lines.line_loc_populated_flag,
1145              -- << PDOI for Complex PO Project: Start >>
1146              intf_lines.retainage_rate,
1147              intf_lines.max_retainage_amount,
1148              intf_lines.progress_payment_rate,
1149              intf_lines.recoupment_rate,
1150              intf_lines.advance_amount,
1151              -- << PDOI for Complex PO Project: End >>
1152              intf_lines.negotiated_by_preparer_flag,
1153              intf_lines.amount,
1154              intf_lines.contractor_last_name,
1155              intf_lines.contractor_first_name,
1156              intf_lines.over_tolerance_error_flag,
1157              intf_lines.not_to_exceed_price,
1158              intf_lines.po_release_id,
1159              intf_lines.release_num,
1160              intf_lines.source_shipment_id,
1161              intf_lines.contract_num,
1162              intf_lines.contract_id,
1163              intf_lines.type_1099,
1164              intf_lines.closed_by,
1165              intf_lines.closed_date,
1166              intf_lines.committed_amount,
1167              intf_lines.qty_rcv_exception_code,
1168              intf_lines.weight_uom_code,
1169              intf_lines.volume_uom_code,
1170              intf_lines.secondary_unit_of_measure,
1171              intf_lines.secondary_quantity,
1172              intf_lines.preferred_grade,
1173              intf_lines.process_code,
1174              NULL, -- parent_interface_line_id -- bug5149827
1175              intf_lines.file_line_language, -- bug 5489942
1176 
1177              -- standard who columns
1178              intf_lines.last_updated_by,
1179              intf_lines.last_update_date,
1180              intf_lines.last_update_login,
1181              intf_lines.creation_date,
1182              intf_lines.created_by,
1183              intf_lines.request_id,
1184              intf_lines.program_application_id,
1185              intf_lines.program_id,
1186              intf_lines.program_update_date,
1187 
1188              -- attributes read from header
1189              intf_headers.draft_id,
1190              intf_headers.action,
1191              intf_headers.po_header_id,
1192              txn_headers.vendor_id,
1193              txn_headers.min_release_amount,
1194              txn_headers.start_date,
1195              txn_headers.end_date,
1196              txn_headers.global_agreement_flag,
1197              txn_headers.currency_code,
1198              txn_headers.created_language,
1199              txn_headers.style_id,
1200              txn_headers.rate_type,
1201 	         txn_headers.rate,  -- bug 9194215
1202 
1203              -- txn table columns
1204              NULL, -- order_type_lookup_code
1205              NULL, -- purchase_basis
1206              NULL, -- matching_basis
1207              NULL, -- unordered_flag
1208              NULL, -- cancel_flag
1209              NULL, -- quantity_committed
1210              NULL, -- tax_attribute_update_code
1211              intf_lines.clm_info_flag, /* 10354034 */
1212              intf_lines.group_line_id, --CLM PDOI Integration
1213 
1214              DECODE(intf_lines.process_code, PO_PDOI_CONSTANTS.g_PROCESS_CODE_VAL_AND_REJECT,
1215                FND_API.g_TRUE, FND_API.g_FALSE),   -- error_flag_tbl
1216              FND_API.G_FALSE,                      -- need_to_reject_flag_tbl
1217              FND_API.g_FALSE,                      -- create_line_loc_tbl
1218              -1,                                   -- group_num
1219              NULL,                                 -- origin_line_num
1220              FND_API.g_FALSE,                      -- match_line_found
1221              NULL,                                 -- allow_desc_update_flag_tbl
1222              --CLM PDOI Integration
1223              intf_lines.contract_type,
1224              intf_lines.cost_constraint,
1225              intf_lines.note_to_vendor,
1226              intf_lines.oke_contract_version_id,
1227              intf_lines.oke_contract_header_id,
1228              intf_lines.clm_option_indicator,
1229              intf_lines.clm_base_line_num,
1230              intf_lines.clm_option_num,
1231              intf_lines.clm_option_from_date,
1232              intf_lines.clm_option_to_date,
1233              Decode(PO_PDOI_PARAMS.g_request.document_type,
1234                     PO_PDOI_CONSTANTS.g_DOC_TYPE_STANDARD, Nvl(intf_lines.clm_idc_type,'IDC_NA'),
1235                     intf_lines.clm_idc_type),
1236              intf_lines.line_num_display,
1237              intf_lines.clm_funded_flag,
1238              intf_lines.user_document_status,
1239              intf_lines.clm_exercised_flag,
1240              intf_lines.clm_exercised_date,
1241              intf_lines.clm_min_total_amount,
1242              intf_lines.clm_max_total_amount,
1243              intf_lines.clm_min_total_quantity,
1244              intf_lines.clm_max_total_quantity,
1245              intf_lines.clm_min_order_amount,
1246              intf_lines.clm_max_order_amount,
1247              intf_lines.clm_min_order_quantity,
1248              intf_lines.clm_max_order_quantity,
1249              intf_lines.clm_total_amount_ordered,
1250              intf_lines.clm_total_quantity_ordered,
1251              intf_lines.clm_period_perf_end_date,
1252              intf_lines.clm_period_perf_start_date,
1253              intf_lines.contract_type_display,
1254              intf_lines.cost_constraint_display,
1255              intf_lines.clm_idc_type_display,
1256              intf_lines.clm_base_line_num_disp,
1257              intf_lines.from_header_disp,
1258              intf_lines.from_line_disp
1259 
1260       FROM   po_lines_interface intf_lines,
1261              po_headers_interface intf_headers,
1262              po_headers txn_headers
1263       WHERE  intf_lines.interface_header_id = intf_headers.interface_header_id
1264       AND    intf_headers.po_header_id = txn_headers.po_header_id
1265       AND    intf_lines.processing_id = PO_PDOI_PARAMS.g_processing_id
1266       AND    intf_headers.processing_round_num = PO_PDOI_PARAMS.g_current_round_num
1267       AND    intf_headers.processing_id = PO_PDOI_PARAMS.g_processing_id
1268       AND    intf_lines.interface_line_id > p_max_intf_line_id
1269       AND    intf_headers.action = PO_PDOI_CONSTANTS.g_ACTION_UPDATE
1270       AND    PO_PDOI_PARAMS.g_request.document_type IN
1271                (PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET,
1272                 PO_PDOI_CONSTANTS.g_DOC_TYPE_QUOTATION)
1273       AND    intf_lines.action = PO_PDOI_CONSTANTS.g_ACTION_ADD
1274       --PDOI CLM Integration
1275       --Process only priced lines which in commercial flow are normal lines
1276       AND    Nvl(intf_lines.clm_info_flag,'N') = 'N'
1277 
1278       ORDER BY intf_lines.interface_line_id;
1279   ELSIF (p_data_set_type = PO_PDOI_CONSTANTS.g_LINE_CSR_SYNC) THEN
1280     d_position := 30;
1281 
1282     OPEN x_lines_csr FOR
1283       SELECT intf_lines.interface_line_id,
1284              intf_lines.interface_header_id,
1285              intf_lines.po_header_id,
1286              NULL, -- intf_lines.po_line_id,
1287              intf_lines.action,
1288              intf_lines.document_num,
1289              intf_lines.item,
1290              intf_lines.vendor_product_num,
1291              intf_lines.supplier_part_auxid,
1292              intf_lines.item_id,
1293              intf_lines.item_revision,
1294              intf_lines.job_business_group_name,
1295              intf_lines.job_business_group_id,
1296              intf_lines.job_name,
1297              intf_lines.job_id,
1298              intf_lines.category,
1299              intf_lines.category_id,
1300              intf_lines.ip_category_name,
1301              intf_lines.ip_category_id,
1302              intf_lines.uom_code,
1303              intf_lines.unit_of_measure,
1304              intf_lines.line_type,
1305              intf_lines.line_type_id,
1306              intf_lines.un_number,
1307              intf_lines.un_number_id,
1308              intf_lines.hazard_class,
1309              intf_lines.hazard_class_id,
1310              intf_lines.template_name,
1311              intf_lines.template_id,
1312              intf_lines.item_description,
1313              intf_lines.unit_price,
1314              intf_lines.base_unit_price,
1315              intf_lines.from_header_id,
1316              intf_lines.from_line_id,
1317              intf_lines.list_price_per_unit,
1318              intf_lines.market_price,
1319              intf_lines.capital_expense_flag,
1320              intf_lines.min_release_amount,
1321              intf_lines.allow_price_override_flag,
1322              intf_lines.price_type,
1323              intf_lines.price_break_lookup_code,
1324              intf_lines.closed_code,
1325              intf_lines.quantity,
1326              intf_lines.line_num,
1327              intf_lines.shipment_num,
1328              intf_lines.price_chg_accept_flag,
1329              intf_lines.effective_date,
1330              intf_lines.expiration_date,
1331              intf_lines.line_attribute14,
1332              intf_lines.price_update_tolerance,
1333              intf_lines.line_loc_populated_flag,
1334              -- << PDOI for Complex PO Project: Start >>
1335              intf_lines.retainage_rate,
1336              intf_lines.max_retainage_amount,
1337              intf_lines.progress_payment_rate,
1338              intf_lines.recoupment_rate,
1339              intf_lines.advance_amount,
1340              -- << PDOI for Complex PO Project: End >>
1341              intf_lines.negotiated_by_preparer_flag,
1342              intf_lines.amount,
1343              intf_lines.contractor_last_name,
1344              intf_lines.contractor_first_name,
1345              intf_lines.over_tolerance_error_flag,
1346              intf_lines.not_to_exceed_price,
1347              intf_lines.po_release_id,
1348              intf_lines.release_num,
1349              intf_lines.source_shipment_id,
1350              intf_lines.contract_num,
1351              intf_lines.contract_id,
1352              intf_lines.type_1099,
1353              intf_lines.closed_by,
1354              intf_lines.closed_date,
1355              intf_lines.committed_amount,
1356              intf_lines.qty_rcv_exception_code,
1357              intf_lines.weight_uom_code,
1358              intf_lines.volume_uom_code,
1359              intf_lines.secondary_unit_of_measure,
1360              intf_lines.secondary_quantity,
1361              intf_lines.preferred_grade,
1362              intf_lines.process_code,
1363              NULL, -- parent_interface_line_id -- bug5149827
1364              intf_lines.file_line_language, -- bug 5489942
1365 
1366              -- standard who columns
1367              intf_lines.last_updated_by,
1368              intf_lines.last_update_date,
1369              intf_lines.last_update_login,
1370              intf_lines.creation_date,
1371              intf_lines.created_by,
1372              intf_lines.request_id,
1373              intf_lines.program_application_id,
1374              intf_lines.program_id,
1375              intf_lines.program_update_date,
1376 
1377              -- attributes read from header
1378              intf_headers.draft_id,
1379              intf_headers.action,
1380              intf_headers.po_header_id,
1381              txn_headers.vendor_id,
1382              txn_headers.min_release_amount,
1383              txn_headers.start_date,
1384              txn_headers.end_date,
1385              txn_headers.global_agreement_flag,
1386              txn_headers.currency_code,
1387              txn_headers.created_language,
1388              txn_headers.style_id,
1389              txn_headers.rate_type,
1390 	         txn_headers.rate,  -- bug 9194215
1391 
1392              -- txn table columns
1393              NULL, -- order_type_lookup_code
1394              NULL, -- purchase_basis
1395              NULL, -- matching_basis
1396              NULL, -- unordered_flag
1397              NULL, -- cancel_flag
1398              NULL, -- quantity_committed
1399              NULL, -- tax_attribute_update_code
1400              intf_lines.clm_info_flag,   /* 10354034 */
1401              intf_lines.group_line_id, --CLM PDOI Integration
1402 
1403 
1404              DECODE(intf_lines.process_code, PO_PDOI_CONSTANTS.g_PROCESS_CODE_VAL_AND_REJECT,
1405                FND_API.g_TRUE, FND_API.g_FALSE),   -- error_flag_tbl
1406              FND_API.G_FALSE,                      -- need_to_reject_flag_tbl
1407              FND_API.g_FALSE,                      -- create_line_loc_tbl
1408              -1,                                   -- group_num
1409              NULL,                                 -- origin_line_num
1410              FND_API.g_FALSE,                      -- match_line_found
1411              NULL,                                -- allow_desc_update_flag_tbl
1412              --clm pdoi integration
1413              intf_lines.contract_type,
1414              intf_lines.cost_constraint,
1415              intf_lines.note_to_vendor,
1416              intf_lines.oke_contract_version_id,
1417              intf_lines.oke_contract_header_id,
1418              intf_lines.clm_option_indicator,
1419              intf_lines.clm_base_line_num,
1420              intf_lines.clm_option_num,
1421              intf_lines.clm_option_from_date,
1422              intf_lines.clm_option_to_date,
1423              Decode(PO_PDOI_PARAMS.g_request.document_type,
1424                     PO_PDOI_CONSTANTS.g_DOC_TYPE_STANDARD, Nvl(intf_lines.clm_idc_type,'IDC_NA'),
1425                     intf_lines.clm_idc_type),
1426              intf_lines.line_num_display,
1427              intf_lines.clm_funded_flag,
1428              intf_lines.user_document_status,
1429              intf_lines.clm_exercised_flag,
1430              intf_lines.clm_exercised_date,
1431              intf_lines.clm_min_total_amount,
1432              intf_lines.clm_max_total_amount,
1433              intf_lines.clm_min_total_quantity,
1434              intf_lines.clm_max_total_quantity,
1435              intf_lines.clm_min_order_amount,
1436              intf_lines.clm_max_order_amount,
1437              intf_lines.clm_min_order_quantity,
1438              intf_lines.clm_max_order_quantity,
1439              intf_lines.clm_total_amount_ordered,
1440              intf_lines.clm_total_quantity_ordered,
1441              intf_lines.clm_period_perf_end_date,
1442              intf_lines.clm_period_perf_start_date,
1443              intf_lines.contract_type_display,
1444              intf_lines.cost_constraint_display,
1445              intf_lines.clm_idc_type_display,
1446              intf_lines.clm_base_line_num_disp,
1447              intf_lines.from_header_disp,
1448              intf_lines.from_line_disp
1449 
1450       FROM   po_lines_interface intf_lines,
1451              po_headers_interface intf_headers,
1452              po_headers txn_headers
1453       WHERE  intf_lines.interface_header_id = intf_headers.interface_header_id
1454       AND    intf_headers.po_header_id = txn_headers.po_header_id
1455       AND    intf_lines.processing_id = PO_PDOI_PARAMS.g_processing_id
1456       AND    intf_headers.processing_round_num = PO_PDOI_PARAMS.g_current_round_num
1457       AND    intf_headers.processing_id = PO_PDOI_PARAMS.g_processing_id
1458       AND    intf_lines.interface_line_id > p_max_intf_line_id
1459       AND    intf_headers.action = PO_PDOI_CONSTANTS.g_ACTION_UPDATE
1460       AND    PO_PDOI_PARAMS.g_request.document_type IN
1461                (PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET,
1462                 PO_PDOI_CONSTANTS.g_DOC_TYPE_QUOTATION)
1463       AND    intf_lines.action IS NULL
1464       AND    NOT (intf_lines.item IS NULL AND
1465                   intf_lines.vendor_product_num IS NULL AND
1466                   intf_lines.job_name IS NULL AND
1467                   intf_lines.item_description IS NOT NULL)
1468       --PDOI CLM Integration
1469       --Process only priced lines which in commercial flow are normal lines
1470       AND    Nvl(intf_lines.clm_info_flag,'N') = 'N'
1471 
1472       ORDER BY intf_lines.interface_line_id;
1473   ELSIF (p_data_set_type = PO_PDOI_CONSTANTS.g_LINE_CSR_SYNC_ON_DESC) THEN
1474     d_position := 40;
1475 
1476     OPEN x_lines_csr FOR
1477       SELECT intf_lines.interface_line_id,
1478              intf_lines.interface_header_id,
1479              intf_lines.po_header_id,
1480              NULL, -- intf_lines.po_line_id,
1481              intf_lines.action,
1482              intf_lines.document_num,
1483              intf_lines.item,
1484              intf_lines.vendor_product_num,
1485              intf_lines.supplier_part_auxid,
1486              intf_lines.item_id,
1487              intf_lines.item_revision,
1488              intf_lines.job_business_group_name,
1489              intf_lines.job_business_group_id,
1490              intf_lines.job_name,
1491              intf_lines.job_id,
1492              intf_lines.category,
1493              intf_lines.category_id,
1494              intf_lines.ip_category_name,
1495              intf_lines.ip_category_id,
1496              intf_lines.uom_code,
1497              intf_lines.unit_of_measure,
1498              intf_lines.line_type,
1499              intf_lines.line_type_id,
1500              intf_lines.un_number,
1501              intf_lines.un_number_id,
1502              intf_lines.hazard_class,
1503              intf_lines.hazard_class_id,
1504              intf_lines.template_name,
1505              intf_lines.template_id,
1506              intf_lines.item_description,
1507              intf_lines.unit_price,
1508              intf_lines.base_unit_price,
1509              intf_lines.from_header_id,
1510              intf_lines.from_line_id,
1511              intf_lines.list_price_per_unit,
1512              intf_lines.market_price,
1513              intf_lines.capital_expense_flag,
1514              intf_lines.min_release_amount,
1515              intf_lines.allow_price_override_flag,
1516              intf_lines.price_type,
1517              intf_lines.price_break_lookup_code,
1518              intf_lines.closed_code,
1519              intf_lines.quantity,
1520              intf_lines.line_num,
1521              intf_lines.shipment_num,
1522              intf_lines.price_chg_accept_flag,
1523              intf_lines.effective_date,
1524              intf_lines.expiration_date,
1525              intf_lines.line_attribute14,
1526              intf_lines.price_update_tolerance,
1527              intf_lines.line_loc_populated_flag,
1528              -- << PDOI for Complex PO Project: Start >>
1529              intf_lines.retainage_rate,
1530              intf_lines.max_retainage_amount,
1531              intf_lines.progress_payment_rate,
1532              intf_lines.recoupment_rate,
1533              intf_lines.advance_amount,
1534              -- << PDOI for Complex PO Project: End >>
1535              intf_lines.negotiated_by_preparer_flag,
1536              intf_lines.amount,
1537              intf_lines.contractor_last_name,
1538              intf_lines.contractor_first_name,
1539              intf_lines.over_tolerance_error_flag,
1540              intf_lines.not_to_exceed_price,
1541              intf_lines.po_release_id,
1542              intf_lines.release_num,
1543              intf_lines.source_shipment_id,
1544              intf_lines.contract_num,
1545              intf_lines.contract_id,
1546              intf_lines.type_1099,
1547              intf_lines.closed_by,
1548              intf_lines.closed_date,
1549              intf_lines.committed_amount,
1550              intf_lines.qty_rcv_exception_code,
1551              intf_lines.weight_uom_code,
1552              intf_lines.volume_uom_code,
1553              intf_lines.secondary_unit_of_measure,
1554              intf_lines.secondary_quantity,
1555              intf_lines.preferred_grade,
1556              intf_lines.process_code,
1557              NULL, -- parent_interface_line_id -- bug5149827
1558              intf_lines.file_line_language, -- bug 5489942
1559 
1560              -- standard who columns
1561              intf_lines.last_updated_by,
1562              intf_lines.last_update_date,
1563              intf_lines.last_update_login,
1564              intf_lines.creation_date,
1565              intf_lines.created_by,
1566              intf_lines.request_id,
1567              intf_lines.program_application_id,
1568              intf_lines.program_id,
1569              intf_lines.program_update_date,
1570 
1571              -- attributes read from header
1572              intf_headers.draft_id,
1573              intf_headers.action,
1574              intf_headers.po_header_id,
1575              txn_headers.vendor_id,
1576              txn_headers.min_release_amount,
1577              txn_headers.start_date,
1578              txn_headers.end_date,
1579              txn_headers.global_agreement_flag,
1580              txn_headers.currency_code,
1581              txn_headers.created_language,
1582              txn_headers.style_id,
1583              txn_headers.rate_type,
1584    	         txn_headers.rate,  -- bug 9194215
1585 
1586              -- txn table columns
1587              NULL, -- order_type_lookup_code
1588              NULL, -- purchase_basis
1589              NULL, -- matching_basis
1590              NULL, -- unordered_flag
1591              NULL, -- cancel_flag
1592              NULL, -- quantity_committed
1593              NULL, -- tax_attribute_update_code
1594              intf_lines.clm_info_flag,   /* 10354034 */
1595              intf_lines.group_line_id, --CLM PDOI Integration
1596 
1597              DECODE(intf_lines.process_code, PO_PDOI_CONSTANTS.g_PROCESS_CODE_VAL_AND_REJECT,
1598                FND_API.g_TRUE, FND_API.g_FALSE),   -- error_flag_tbl
1599              FND_API.G_FALSE,                      -- need_to_reject_flag_tbl
1600              FND_API.g_FALSE,                      -- create_line_loc_tbl
1601              -1,                                   -- group_num
1602              NULL,                                 -- origin_line_num
1603              FND_API.g_FALSE,                      -- match_line_found
1604              NULL,                                -- allow_desc_update_flag_tbl
1605              --clm pdoi integration
1606              intf_lines.contract_type,
1607              intf_lines.cost_constraint,
1608              intf_lines.note_to_vendor,
1609              intf_lines.oke_contract_version_id,
1610              intf_lines.oke_contract_header_id,
1611              intf_lines.clm_option_indicator,
1612              intf_lines.clm_base_line_num,
1613              intf_lines.clm_option_num,
1614              intf_lines.clm_option_from_date,
1615              intf_lines.clm_option_to_date,
1616              Decode(PO_PDOI_PARAMS.g_request.document_type,
1617                     PO_PDOI_CONSTANTS.g_DOC_TYPE_STANDARD, Nvl(intf_lines.clm_idc_type,'IDC_NA'),
1618                     intf_lines.clm_idc_type),
1619              intf_lines.line_num_display,
1620              intf_lines.clm_funded_flag,
1621              intf_lines.user_document_status,
1622              intf_lines.clm_exercised_flag,
1623              intf_lines.clm_exercised_date,
1624              intf_lines.clm_min_total_amount,
1625              intf_lines.clm_max_total_amount,
1626              intf_lines.clm_min_total_quantity,
1627              intf_lines.clm_max_total_quantity,
1628              intf_lines.clm_min_order_amount,
1629              intf_lines.clm_max_order_amount,
1630              intf_lines.clm_min_order_quantity,
1631              intf_lines.clm_max_order_quantity,
1632              intf_lines.clm_total_amount_ordered,
1633              intf_lines.clm_total_quantity_ordered,
1634              intf_lines.clm_period_perf_end_date,
1635              intf_lines.clm_period_perf_start_date,
1636              intf_lines.contract_type_display,
1637              intf_lines.cost_constraint_display,
1638              intf_lines.clm_idc_type_display,
1639              intf_lines.clm_base_line_num_disp,
1640              intf_lines.from_header_disp,
1641              intf_lines.from_line_disp
1642 
1643       FROM   po_lines_interface intf_lines,
1644              po_headers_interface intf_headers,
1645              po_headers txn_headers
1646       WHERE  intf_lines.interface_header_id = intf_headers.interface_header_id
1647       AND    intf_headers.po_header_id = txn_headers.po_header_id
1648       AND    intf_lines.processing_id = PO_PDOI_PARAMS.g_processing_id
1649       AND    intf_headers.processing_round_num = PO_PDOI_PARAMS.g_current_round_num
1650       AND    intf_headers.processing_id = PO_PDOI_PARAMS.g_processing_id
1651       AND    intf_lines.interface_line_id > p_max_intf_line_id
1652       AND    intf_headers.action = PO_PDOI_CONSTANTS.g_ACTION_UPDATE
1653       AND    PO_PDOI_PARAMS.g_request.document_type IN
1654                (PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET,
1655                 PO_PDOI_CONSTANTS.g_DOC_TYPE_QUOTATION)
1656       AND    intf_lines.action IS NULL
1657       AND    intf_lines.item IS NULL
1658       AND    intf_lines.vendor_product_num IS NULL
1659       AND    intf_lines.job_name IS NULL
1660       AND    intf_lines.item_description IS NOT NULL
1661       --PDOI CLM Integration
1662       --Process only priced lines which in commercial flow are normal lines
1663       AND    Nvl(intf_lines.clm_info_flag,'N') = 'N'
1664 
1665       ORDER BY intf_lines.interface_line_id;
1666 
1667 	  --PDOI CLM Integration
1668       --A new cursor added to process only Info lines
1669   ELSIF (p_data_set_type = PO_PDOI_CONSTANTS.g_LINE_CSR_INFO_LINE_ADD) THEN
1670    d_position := 45;
1671    OPEN x_lines_csr FOR
1672      SELECT intf_lines.interface_line_id,
1673              intf_lines.interface_header_id,
1674              intf_lines.po_header_id,
1675              NULL, -- intf_lines.po_line_id,
1676              intf_lines.action,
1677              intf_lines.document_num,
1678              NULL,--intf_lines.item,
1679              intf_lines.vendor_product_num,
1680              intf_lines.supplier_part_auxid,
1681              NULL,--intf_lines.item_id,
1682              intf_lines.item_revision,
1683              intf_lines.job_business_group_name,
1684              intf_lines.job_business_group_id,
1685              intf_lines.job_name,
1686              intf_lines.job_id,
1687              intf_lines.category,
1688              intf_lines.category_id,
1689              intf_lines.ip_category_name,
1690              intf_lines.ip_category_id,
1691              NULL,--intf_lines.uom_code,
1692              NULL,--intf_lines.unit_of_measure,
1693              NULL,--intf_lines.line_type,
1694              NULL,--intf_lines.line_type_id,
1695              intf_lines.un_number,
1696              intf_lines.un_number_id,
1697              intf_lines.hazard_class,
1698              intf_lines.hazard_class_id,
1699              intf_lines.template_name,
1700              intf_lines.template_id,
1701              intf_lines.item_description,
1702              NULL,--intf_lines.unit_price,
1703              NULL,--intf_lines.base_unit_price,
1704              intf_lines.from_header_id,
1705              intf_lines.from_line_id,
1706              intf_lines.list_price_per_unit,
1707              intf_lines.market_price,
1708              intf_lines.capital_expense_flag,
1709              intf_lines.min_release_amount,
1710              intf_lines.allow_price_override_flag,
1711              intf_lines.price_type,
1712              intf_lines.price_break_lookup_code,
1713              intf_lines.closed_code,
1714              NULL,--intf_lines.quantity,
1715              intf_lines.line_num,
1716              intf_lines.shipment_num,
1717              intf_lines.price_chg_accept_flag,
1718              intf_lines.effective_date,
1719              intf_lines.expiration_date,
1720              intf_lines.line_attribute14,
1721              intf_lines.price_update_tolerance,
1722              intf_lines.line_loc_populated_flag,
1723              -- << PDOI for Complex PO Project: Start >>
1724              intf_lines.retainage_rate,
1725              intf_lines.max_retainage_amount,
1726              intf_lines.progress_payment_rate,
1727              intf_lines.recoupment_rate,
1728              intf_lines.advance_amount,
1729              -- << PDOI for Complex PO Project: End >>
1730              intf_lines.negotiated_by_preparer_flag,
1731              intf_lines.amount,
1732              intf_lines.contractor_last_name,
1733              intf_lines.contractor_first_name,
1734              intf_lines.over_tolerance_error_flag,
1735              intf_lines.not_to_exceed_price,
1736              intf_lines.po_release_id,
1737              intf_lines.release_num,
1738              intf_lines.source_shipment_id,
1739              intf_lines.contract_num,
1740              intf_lines.contract_id,
1741              intf_lines.type_1099,
1742              intf_lines.closed_by,
1743              intf_lines.closed_date,
1744              intf_lines.committed_amount,
1745              intf_lines.qty_rcv_exception_code,
1746              intf_lines.weight_uom_code,
1747              intf_lines.volume_uom_code,
1748              intf_lines.secondary_unit_of_measure,
1749              intf_lines.secondary_quantity,
1750              intf_lines.preferred_grade,
1751              intf_lines.process_code,
1752              NULL, -- parent_interface_line_id
1753              intf_lines.file_line_language,
1754 
1755              -- standard who columns
1756              intf_lines.last_updated_by,
1757              intf_lines.last_update_date,
1758              intf_lines.last_update_login,
1759              intf_lines.creation_date,
1760              intf_lines.created_by,
1761              intf_lines.request_id,
1762              intf_lines.program_application_id,
1763              intf_lines.program_id,
1764              intf_lines.program_update_date,
1765 
1766              -- attributes read from headers
1767              intf_headers.draft_id,
1768              intf_headers.action,
1769              intf_headers.po_header_id,
1770              draft_headers.vendor_id,
1771              draft_headers.min_release_amount,
1772              draft_headers.start_date,
1773              draft_headers.end_date,
1774              draft_headers.global_agreement_flag,
1775              draft_headers.currency_code,
1776              draft_headers.created_language,
1777              draft_headers.style_id,
1778              draft_headers.rate_type,
1779 	         draft_headers.rate,
1780 
1781              -- txn table columns
1782              NULL, -- order_type_lookup_code
1783              NULL, -- purchase_basis
1784              NULL, -- matching_basis
1785              NULL, -- unordered_flag
1786              NULL, -- cancel_flag
1787              NULL, -- quantity_committed
1788              NULL, -- tax_attribute_update_code
1789              intf_lines.clm_info_flag,
1790              intf_lines.group_line_id,
1791 
1792              DECODE(intf_lines.process_code,
1793                     PO_PDOI_CONSTANTS.g_PROCESS_CODE_VAL_AND_REJECT,
1794                     FND_API.g_TRUE, FND_API.g_FALSE), -- error_flag_tbl
1795              FND_API.g_FALSE,                    -- need_to_reject_flag_tbl
1796              FND_API.g_FALSE,                    -- create_line_loc_tbl
1797              -1,                                 -- group_num
1798              NULL,                               -- origin_line_num
1799              FND_API.g_FALSE,                    -- match_line_found
1800              NULL,
1801              intf_lines.contract_type,
1802              intf_lines.cost_constraint,
1803              intf_lines.note_to_vendor,
1804              intf_lines.oke_contract_version_id,
1805              intf_lines.oke_contract_header_id,
1806              intf_lines.clm_option_indicator,
1807              intf_lines.clm_base_line_num,
1808              intf_lines.clm_option_num,
1809              intf_lines.clm_option_from_date,
1810              intf_lines.clm_option_to_date,
1811              intf_lines.clm_idc_type,
1812              intf_lines.line_num_display,
1813              intf_lines.clm_funded_flag,
1814              intf_lines.user_document_status,
1815              intf_lines.clm_exercised_flag,
1816              intf_lines.clm_exercised_date,
1817              intf_lines.clm_min_total_amount,
1818              intf_lines.clm_max_total_amount,
1819              intf_lines.clm_min_total_quantity,
1820              intf_lines.clm_max_total_quantity,
1821              intf_lines.clm_min_order_amount,
1822              intf_lines.clm_max_order_amount,
1823              intf_lines.clm_min_order_quantity,
1824              intf_lines.clm_max_order_quantity,
1825              intf_lines.clm_total_amount_ordered,
1826              intf_lines.clm_total_quantity_ordered,
1827              intf_lines.clm_period_perf_end_date,
1828              intf_lines.clm_period_perf_start_date,
1829              intf_lines.contract_type_display,
1830              intf_lines.cost_constraint_display,
1831              intf_lines.clm_idc_type_display,
1832              intf_lines.clm_base_line_num_disp,
1833              intf_lines.from_header_disp,
1834              intf_lines.from_line_disp
1835 
1836       FROM   po_lines_interface intf_lines,
1837              po_headers_interface intf_headers,
1838              po_headers_draft_all draft_headers
1839       WHERE  intf_lines.interface_header_id = intf_headers.interface_header_id
1840       AND    intf_headers.draft_id = draft_headers.draft_id
1841       AND    intf_headers.po_header_id = draft_headers.po_header_id
1842       AND    intf_lines.processing_id = PO_PDOI_PARAMS.g_processing_id
1843       AND    intf_headers.processing_round_num = PO_PDOI_PARAMS.g_current_round_num
1844       AND    intf_headers.processing_id = PO_PDOI_PARAMS.g_processing_id
1845       AND    intf_lines.interface_line_id > p_max_intf_line_id
1846       AND    intf_headers.action IN (PO_PDOI_CONSTANTS.g_ACTION_ORIGINAL,
1847                                      PO_PDOI_CONSTANTS.g_ACTION_REPLACE)
1848       and    nvl(intf_lines.clm_info_flag,'N') = 'Y'
1849       ORDER BY intf_lines.interface_line_id;
1850   ELSE
1851     d_position := 50;
1852 
1853     NULL;
1854   END IF;
1855 
1856   IF (PO_LOG.d_proc) THEN
1857     PO_LOG.proc_end (d_module);
1858   END IF;
1859 
1860 EXCEPTION
1861   WHEN OTHERS THEN
1862     PO_MESSAGE_S.add_exc_msg
1863     (
1864       p_pkg_name => d_pkg_name,
1865       p_procedure_name => d_api_name || '.' || d_position
1866     );
1867     RAISE;
1868 END open_lines;
1869 
1870 -----------------------------------------------------------------------
1871 --Start of Comments
1872 --Name: fetch_lines
1873 --Function: fetch the line records based on batch size
1874 --Parameters:
1875 --IN:
1876 --IN OUT:
1877 --  x_lines_csr
1878 --    cursor to point to the first record in the result batch
1879 --  x_lines
1880 --    record to store all the line rows within the batch
1881 --OUT:
1882 --End of Comments
1883 ------------------------------------------------------------------------
1884 PROCEDURE fetch_lines
1885 (
1886   x_lines_csr   IN OUT NOCOPY PO_PDOI_TYPES.intf_cursor_type,
1887   x_lines       OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
1888 ) IS
1889 
1890   d_api_name CONSTANT VARCHAR2(30) := 'fetch_lines';
1891   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
1892   d_position NUMBER;
1893 
1894 BEGIN
1895   d_position := 0;
1896 
1897   IF (PO_LOG.d_proc) THEN
1898     PO_LOG.proc_begin(d_module);
1899   END IF;
1900 
1901   FETCH x_lines_csr BULK COLLECT INTO
1902     x_lines.intf_line_id_tbl,
1903     x_lines.intf_header_id_tbl,
1904     x_lines.po_header_id_tbl,
1905     x_lines.po_line_id_tbl,
1906     x_lines.action_tbl,
1907     x_lines.document_num_tbl,
1908     x_lines.item_tbl,
1909     x_lines.vendor_product_num_tbl,
1910     x_lines.supplier_part_auxid_tbl,
1911     x_lines.item_id_tbl,
1912     x_lines.item_revision_tbl,
1913     x_lines.job_business_group_name_tbl,
1914     x_lines.job_business_group_id_tbl,
1915     x_lines.job_name_tbl,
1916     x_lines.job_id_tbl,
1917     x_lines.category_tbl,
1918     x_lines.category_id_tbl,
1919     x_lines.ip_category_tbl,
1920     x_lines.ip_category_id_tbl,
1921     x_lines.uom_code_tbl,
1922     x_lines.unit_of_measure_tbl,
1923     x_lines.line_type_tbl,
1924     x_lines.line_type_id_tbl,
1925     x_lines.un_number_tbl,
1926     x_lines.un_number_id_tbl,
1927     x_lines.hazard_class_tbl,
1928     x_lines.hazard_class_id_tbl,
1929     x_lines.template_name_tbl,
1930     x_lines.template_id_tbl,
1931     x_lines.item_desc_tbl,
1932     x_lines.unit_price_tbl,
1933     x_lines.base_unit_price_tbl,
1934     x_lines.from_header_id_tbl,
1935     x_lines.from_line_id_tbl,
1936     x_lines.list_price_per_unit_tbl,
1937     x_lines.market_price_tbl,
1938     x_lines.capital_expense_flag_tbl,
1939     x_lines.min_release_amount_tbl,
1940     x_lines.allow_price_override_flag_tbl,
1941     x_lines.price_type_tbl,
1942     x_lines.price_break_lookup_code_tbl,
1943     x_lines.closed_code_tbl,
1944     x_lines.quantity_tbl,
1945     x_lines.line_num_tbl,
1946     x_lines.shipment_num_tbl,
1947     x_lines.price_chg_accept_flag_tbl,
1948     x_lines.effective_date_tbl,
1949     x_lines.expiration_date_tbl,
1950     x_lines.attribute14_tbl,
1951     x_lines.price_update_tolerance_tbl,
1952     x_lines.line_loc_populated_flag_tbl,
1953     -- << PDOI for Complex PO Project: Start >>
1954     x_lines.retainage_rate_tbl,
1955     x_lines.max_retainage_amount_tbl,
1956     x_lines.progress_payment_rate_tbl,
1957     x_lines.recoupment_rate_tbl,
1958     x_lines.advance_amount_tbl,
1959     -- << PDOI for Complex PO Project: End >>
1960     x_lines.negotiated_flag_tbl,
1961     x_lines.amount_tbl,
1962     x_lines.contractor_last_name_tbl,
1963     x_lines.contractor_first_name_tbl,
1964     x_lines.over_tolerance_err_flag_tbl,
1965     x_lines.not_to_exceed_price_tbl,
1966     x_lines.po_release_id_tbl,
1967     x_lines.release_num_tbl,
1968     x_lines.source_shipment_id_tbl,
1969     x_lines.contract_num_tbl,
1970     x_lines.contract_id_tbl,
1971     x_lines.type_1099_tbl,
1972     x_lines.closed_by_tbl,
1973     x_lines.closed_date_tbl,
1974     x_lines.committed_amount_tbl,
1975     x_lines.qty_rcv_exception_code_tbl,
1976     x_lines.weight_uom_code_tbl,
1977     x_lines.volume_uom_code_tbl,
1978     x_lines.secondary_unit_of_meas_tbl,
1979     x_lines.secondary_quantity_tbl,
1980     x_lines.preferred_grade_tbl,
1981     x_lines.process_code_tbl,
1982     x_lines.parent_interface_line_id_tbl, -- bug5149827
1983     x_lines.file_line_language_tbl, -- bug 5489942
1984 
1985     -- standard who columns
1986     x_lines.last_updated_by_tbl,
1987     x_lines.last_update_date_tbl,
1988     x_lines.last_update_login_tbl,
1989     x_lines.creation_date_tbl,
1990     x_lines.created_by_tbl,
1991     x_lines.request_id_tbl,
1992     x_lines.program_application_id_tbl,
1993     x_lines.program_id_tbl,
1994     x_lines.program_update_date_tbl,
1995 
1996     -- attributes read from headers
1997     x_lines.draft_id_tbl,
1998     x_lines.hd_action_tbl,
1999     x_lines.hd_po_header_id_tbl,
2000     x_lines.hd_vendor_id_tbl,
2001     x_lines.hd_min_release_amount_tbl,
2002     x_lines.hd_start_date_tbl,
2003     x_lines.hd_end_date_tbl,
2004     x_lines.hd_global_agreement_flag_tbl,
2005     x_lines.hd_currency_code_tbl,
2006     x_lines.hd_created_language_tbl,
2007     x_lines.hd_style_id_tbl,
2008     x_lines.hd_rate_type_tbl,
2009     x_lines.hd_rate_tbl,     -- bug 9194215
2010 
2011     -- txn table columns
2012     x_lines.order_type_lookup_code_tbl,
2013     x_lines.purchase_basis_tbl,
2014     x_lines.matching_basis_tbl,
2015     x_lines.unordered_flag_tbl,
2016     x_lines.cancel_flag_tbl,
2017     x_lines.quantity_committed_tbl,
2018     x_lines.tax_attribute_update_code_tbl,
2019     x_lines.clm_info_flag_tbl,   /* 10354034 */
2020     x_lines.group_line_id_tbl, --CLM PDOI Integration Project
2021     x_lines.error_flag_tbl,
2022     x_lines.need_to_reject_flag_tbl,
2023     x_lines.create_line_loc_tbl,
2024     x_lines.group_num_tbl,
2025     x_lines.origin_line_num_tbl,
2026     x_lines.match_line_found_tbl,
2027     x_lines.allow_desc_update_flag_tbl,   -- bug5107324
2028     --CLM PDOI Integration Starts
2029     x_lines.contract_type_tbl,
2030     x_lines.cost_constraint_tbl,
2031     x_lines.note_to_vendor_tbl,
2032     x_lines.oke_contract_version_id_tbl,
2033     x_lines.oke_contract_header_id_tbl,
2034     x_lines.clm_option_indicator_tbl,
2035     x_lines.clm_base_line_num_tbl,
2036     x_lines.clm_option_num_tbl,
2037     x_lines.clm_option_from_date_tbl,
2038     x_lines.clm_option_to_date_tbl,
2039     x_lines.clm_idc_type_tbl,
2040     x_lines.line_num_display_tbl,
2041     x_lines.clm_funded_flag_tbl,
2042     x_lines.user_document_status_tbl,
2043     x_lines.clm_exercised_flag_tbl,
2044     x_lines.clm_exercised_date_tbl,
2045     x_lines.clm_min_total_amount_tbl,
2046     x_lines.clm_max_total_amount_tbl,
2047     x_lines.clm_min_total_quantity_tbl,
2048     x_lines.clm_max_total_quantity_tbl,
2049     x_lines.clm_min_order_amount_tbl,
2050     x_lines.clm_max_order_amount_tbl,
2051     x_lines.clm_min_order_quantity_tbl,
2052     x_lines.clm_max_order_quantity_tbl,
2053     x_lines.clm_total_amount_ordered_tbl,
2054     x_lines.clm_total_quantity_ordered_tbl,
2055     x_lines.clm_period_perf_end_date_tbl,
2056     x_lines.clm_period_perf_start_date_tbl,
2057     x_lines.contract_type_display_tbl,
2058     x_lines.cost_constraint_display_tbl,
2059     x_lines.clm_idc_type_display_tbl,
2060     x_lines.clm_base_line_num_disp_tbl,
2061     x_lines.from_header_disp_tbl,
2062     x_lines.from_line_disp_tbl
2063     --CLM PDOI Integration Ends
2064   LIMIT PO_PDOI_CONSTANTS.g_DEF_BATCH_SIZE;
2065 
2066   IF (PO_LOG.d_proc) THEN
2067     PO_LOG.proc_end (d_module);
2068   END IF;
2069 
2070 EXCEPTION
2071   WHEN OTHERS THEN
2072     PO_MESSAGE_S.add_exc_msg
2073     (
2074       p_pkg_name => d_pkg_name,
2075       p_procedure_name => d_api_name || '.' || d_position
2076     );
2077     RAISE;
2078 END fetch_lines;
2079 
2080 -----------------------------------------------------------------------
2081 --Start of Comments
2082 --Name: derive_lines
2083 --Function: peform derivation logic on line attributes
2084 --Parameters:
2085 --IN:
2086 --IN OUT:
2087 --  x_lines
2088 --    record to store all the line rows within the batch;
2089 --    Derivation are performed for certain attributes only
2090 --    if their name value is populated but id value is not.
2091 --OUT:
2092 --End of Comments
2093 ------------------------------------------------------------------------
2094 PROCEDURE derive_lines
2095 (
2096   x_lines       IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
2097 ) IS
2098 
2099   d_api_name CONSTANT VARCHAR2(30) := 'derive_lines';
2100   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
2101   d_position NUMBER;
2102 
2103   -- key of temp table used to identify the derived result
2104   l_key po_session_gt.key%TYPE;
2105 
2106   -- table used to save the index of the each row
2107   l_index_tbl DBMS_SQL.NUMBER_TABLE;
2108 BEGIN
2109   d_position := 0;
2110 
2111   IF (PO_LOG.d_proc) THEN
2112     PO_LOG.proc_begin(d_module, 'line counts', x_lines.rec_count);
2113   END IF;
2114 
2115   PO_TIMING_UTL.start_time(PO_PDOI_CONSTANTS.g_T_LINE_DERIVE);
2116 
2117   -- assign a new key used in temporary table
2118   l_key := PO_CORE_S.get_session_gt_nextval;
2119 
2120   -- initialize table containing the row number(index)
2121   PO_PDOI_UTL.generate_ordered_num_list
2122   (
2123     p_size     => x_lines.rec_count,
2124     x_num_list => l_index_tbl
2125   );
2126 
2127   d_position := 10;
2128 
2129   -- bug5684695
2130   -- The call to derive_po_header_id has been removed
2131 
2132   -- bug 7374337
2133   -- The call to derive category id has been moved from
2134   -- bottom to top so that it can be used in deriving item id
2135   -- when vendor_product_num is passed.
2136   -- derive PO category_id from PO category_name
2137   derive_category_id
2138   (
2139     p_key                  => l_key,
2140     p_category_tbl         => x_lines.category_tbl,
2141     x_category_id_tbl      => x_lines.category_id_tbl
2142   );
2143 
2144   d_position := 20;
2145 
2146   -- derive item_id from item_num
2147   derive_item_id
2148   (
2149     p_key                    => l_key,
2150     p_index_tbl              => l_index_tbl,
2151     p_vendor_id_tbl          => x_lines.hd_vendor_id_tbl,
2152     p_intf_header_id_tbl     => x_lines.intf_header_id_tbl,
2153     p_intf_line_id_tbl       => x_lines.intf_line_id_tbl,
2154     p_vendor_product_num_tbl => x_lines.vendor_product_num_tbl,
2155     p_category_id_tbl        => x_lines.category_id_tbl,
2156 	p_item_tbl               => x_lines.item_tbl,
2157     x_item_id_tbl            => x_lines.item_id_tbl,
2158     x_error_flag_tbl         => x_lines.error_flag_tbl
2159   );
2160 
2161   d_position := 30;
2162 
2163   -- derive item_revision from item_id
2164   derive_item_revision
2165   (
2166     p_key                    => l_key,
2167     p_item_id_tbl            => x_lines.item_id_tbl,
2168     x_item_revision_tbl      => x_lines.item_revision_tbl
2169   );
2170 
2171   d_position := 40;
2172 
2173   -- derive job_business_group_id from job_business_group_name
2174   derive_job_business_group_id
2175   (
2176     p_key                            => l_key,
2177     p_index_tbl                      => l_index_tbl,
2178     p_job_business_group_name_tbl    => x_lines.job_business_group_name_tbl,
2179     x_job_business_group_id_tbl      => x_lines.job_business_group_id_tbl
2180   );
2181 
2182   d_position := 50;
2183 
2184   -- derive job_id from job_name
2185   derive_job_id
2186   (
2187     p_key                            => l_key,
2188     p_index_tbl                      => l_index_tbl,
2189     p_file_line_language_tbl         => x_lines.file_line_language_tbl,
2190     p_job_business_group_name_tbl    => x_lines.job_business_group_name_tbl,
2191     p_job_name_tbl                   => x_lines.job_name_tbl,
2192     x_job_business_group_id_tbl      => x_lines.job_business_group_id_tbl,
2193     x_job_id_tbl                     => x_lines.job_id_tbl
2194   );
2195 
2196   d_position := 60;
2197 
2198   -- derive PO category_id from PO category_name
2199   -- bug 7374337 moved above to derive item id call
2200 
2201 
2202   d_position := 70;
2203 
2204   IF (PO_PDOI_PARAMS.g_request.document_type IN
2205       (PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET,
2206        PO_PDOI_CONSTANTS.g_DOC_TYPE_QUOTATION)) THEN
2207     -- derive IP category_id from IP category_name
2208     derive_ip_category_id
2209     (
2210       p_key                    => l_key,
2211       p_index_tbl              => l_index_tbl,
2212       p_file_line_language_tbl => x_lines.file_line_language_tbl,
2213       p_ip_category_tbl        => x_lines.ip_category_tbl,
2214       x_ip_category_id_tbl     => x_lines.ip_category_id_tbl
2215     );
2216   END IF;
2217 
2218   d_position := 80;
2219 
2220   -- derive unit_of_measure from uom_code
2221   derive_unit_of_measure
2222   (
2223     p_key                  => l_key,
2224     p_index_tbl            => l_index_tbl,
2225     p_uom_code_tbl         => x_lines.uom_code_tbl,
2226     x_unit_of_measure_tbl  => x_lines.unit_of_measure_tbl
2227   );
2228 
2229   d_position := 90;
2230 
2231   -- derive line_type_id from line_type
2232   derive_line_type_id
2233   (
2234     p_key                    => l_key,
2235     p_index_tbl              => l_index_tbl,
2236     p_file_line_language_tbl => x_lines.file_line_language_tbl,
2237     p_line_type_tbl          => x_lines.line_type_tbl,
2238     x_line_type_id_tbl       => x_lines.line_type_id_tbl
2239   );
2240 
2241   d_position := 100;
2242 
2243   -- derive un_number_id from un_number
2244   derive_un_number_id
2245   (
2246     p_key                  => l_key,
2247     p_index_tbl            => l_index_tbl,
2248     p_un_number_tbl        => x_lines.un_number_tbl,
2249     x_un_number_id_tbl     => x_lines.un_number_id_tbl
2250   );
2251 
2252   d_position := 110;
2253 
2254   -- derive hazard_calss_id from hazard_class
2255   derive_hazard_class_id
2256   (
2257     p_key                  => l_key,
2258     p_index_tbl            => l_index_tbl,
2259     p_hazard_class_tbl     => x_lines.hazard_class_tbl,
2260     x_hazard_class_id_tbl  => x_lines.hazard_class_id_tbl
2261   );
2262 
2263   d_position := 120;
2264 
2265   -- derive template_id from template_name
2266   derive_template_id
2267   (
2268     p_key                  => l_key,
2269     p_index_tbl            => l_index_tbl,
2270     p_template_name_tbl    => x_lines.template_name_tbl,
2271     x_template_id_tbl      => x_lines.template_id_tbl
2272   );
2273   --CLM PDOI Integration Starts
2274   IF Nvl(PO_PDOI_PARAMS.g_request.clm_flag,'N') = 'Y'
2275   THEN
2276     derive_contract_type
2277     (
2278       p_key                       => l_key,
2279       p_index_tbl                 => l_index_tbl,
2280       p_contract_type_display_tbl => x_lines.contract_type_display_tbl,
2281       x_contract_type_tbl         => x_lines.contract_type_tbl
2282     );
2283 
2284     derive_cost_constraint
2285     (
2286       p_key                         => l_key,
2287       p_index_tbl                   => l_index_tbl,
2288       p_cost_constraint_display_tbl => x_lines.cost_constraint_display_tbl,
2289       x_cost_constraint_tbl         => x_lines.cost_constraint_tbl
2290     );
2291 
2292     derive_clm_idc_type
2293     (
2294       p_key                      => l_key,
2295       p_index_tbl                => l_index_tbl,
2296       p_clm_idc_type_display_tbl => x_lines.clm_idc_type_display_tbl,
2297       x_clm_idc_type_tbl         => x_lines.clm_idc_type_tbl
2298     );
2299 
2300     derive_clm_base_line_num
2301     (
2302       p_key                        => l_key,
2303       p_index_tbl                  => l_index_tbl,
2304       p_clm_base_line_num_disp_tbl => x_lines.clm_base_line_num_disp_tbl,
2305       p_intf_line_id_tbl           => x_lines.intf_line_id_tbl,
2306       p_intf_header_id_tbl         => x_lines.intf_header_id_tbl,
2307       p_line_num_display_tbl       => x_lines.line_num_display_tbl,
2308       p_clm_option_indicator       => x_lines.clm_option_indicator_tbl,
2309       x_clm_base_line_num_tbl      => x_lines.clm_base_line_num_tbl
2310     );
2311 
2312     derive_from_header_id
2313     (
2314       p_key                        => l_key,
2315       p_index_tbl                  => l_index_tbl,
2316       p_from_header_disp_tbl       => x_lines.from_header_disp_tbl,
2317       x_from_header_id_tbl         => x_lines.from_header_id_tbl
2318     );
2319 
2320     derive_from_line_id
2321     (
2322       p_key                        => l_key,
2323       p_index_tbl                  => l_index_tbl,
2324       p_from_line_disp_tbl         => x_lines.from_line_disp_tbl,
2325       p_from_header_id_tbl         => x_lines.from_header_id_tbl,
2326       x_from_line_id_tbl           => x_lines.from_line_id_tbl
2327     );
2328   END IF;
2329   --CLM PDOI Integration Ends
2330 
2331 
2332   d_position := 130;
2333 
2334   -- handle all derivation errors
2335   FOR i IN 1..x_lines.rec_count
2336   LOOP
2337     d_position := 140;
2338 
2339     IF (PO_LOG.d_stmt) THEN
2340       PO_LOG.stmt(d_module, d_position, 'index', i);
2341     END IF;
2342 
2343     -- bug5684695
2344     -- Removed validation for po_header_id at line level. Simply copy the
2345     -- po_header_id from whatever's set for the header
2346     x_lines.po_header_id_tbl(i) := x_lines.hd_po_header_id_tbl(i);
2347 
2348     -- derivation error for item_id
2349     IF (x_lines.item_tbl(i) IS NOT NULL AND
2350         x_lines.item_id_tbl(i) IS NULL AND
2351         PO_PDOI_PARAMS.g_request.create_items = 'N') THEN
2352       IF (PO_LOG.d_stmt) THEN
2353         PO_LOG.stmt(d_module, d_position, 'item id derivation failed');
2354         PO_LOG.stmt(d_module, d_position, 'item', x_lines.item_tbl(i));
2355       END IF;
2356 
2357       PO_PDOI_ERR_UTL.add_fatal_error
2358       (
2359         p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2360         p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2361         p_error_message_name   => 'PO_PDOI_DERV_PART_NUM_ERROR',
2362         p_table_name           => 'PO_LINES_INTERFACE',
2363         p_column_name          => NULL,
2364         p_column_value         => NULL,
2365         p_validation_id        => PO_VAL_CONSTANTS.c_part_num_derv,
2366         p_lines                => x_lines
2367       );
2368 
2369         x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2370     END IF;
2371 
2372     -- derivation error for job_business_group_id
2373     IF (x_lines.job_business_group_name_tbl(i) IS NOT NULL AND
2374         x_lines.job_business_group_id_tbl(i) IS NULL) THEN
2375       IF (PO_LOG.d_stmt) THEN
2376         PO_LOG.stmt(d_module, d_position, 'job business group id derivation failed');
2377         PO_LOG.stmt(d_module, d_position, 'job business group name',
2378                     x_lines.job_business_group_name_tbl(i));
2379       END IF;
2380 
2381       PO_PDOI_ERR_UTL.add_fatal_error
2382       (
2383         p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2384         p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2385         p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2386         p_table_name           => 'PO_LINES_INTERFACE',
2387         p_column_name          => 'JOB_BUSINESS_GROUP_ID',
2388         p_column_value         => x_lines.job_business_group_id_tbl(i),
2389         p_token1_name          => 'COLUMN_NAME',
2390         p_token1_value         => 'JOB_BUSINESS_GROUP_NAME',
2391         p_token2_name          => 'VALUE',
2392         p_token2_value         => x_lines.job_business_group_name_tbl(i)
2393       );
2394 
2395       x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2396     ELSIF (x_lines.job_name_tbl(i) IS NOT NULL AND  -- derivation error for job_id
2397            x_lines.job_id_tbl(i) IS NULL) THEN
2398       IF (PO_LOG.d_stmt) THEN
2399         PO_LOG.stmt(d_module, d_position, 'job id derivation failed');
2400         PO_LOG.stmt(d_module, d_position, 'job name',
2401                     x_lines.job_name_tbl(i));
2402       END IF;
2403 
2404       PO_PDOI_ERR_UTL.add_fatal_error
2405       (
2406         p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2407         p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2408         p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2409         p_table_name           => 'PO_LINES_INTERFACE',
2410         p_column_name          => 'JOB_ID',
2411         p_column_value         => x_lines.job_id_tbl(i),
2412         p_token1_name          => 'COLUMN_NAME',
2413         p_token1_value         => 'JOB_NAME',
2414         p_token2_name          => 'VALUE',
2415         p_token2_value         => x_lines.job_name_tbl(i),
2416         p_validation_id        => PO_VAL_CONSTANTS.c_job_name_derv,
2417         p_lines                => x_lines
2418       );
2419 
2420       x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2421     END IF;
2422 
2423     -- derivation error for category_id
2424     IF (x_lines.category_tbl(i) IS NOT NULL AND
2425         x_lines.category_id_tbl(i) IS NULL) THEN
2426       IF (PO_LOG.d_stmt) THEN
2427         PO_LOG.stmt(d_module, d_position, 'category id derivation failed');
2428         PO_LOG.stmt(d_module, d_position, 'category name',
2429                     x_lines.category_tbl(i));
2430       END IF;
2431 
2432       PO_PDOI_ERR_UTL.add_fatal_error
2433       (
2434         p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2435         p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2436         p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2437         p_table_name           => 'PO_LINES_INTERFACE',
2438         p_column_name          => 'CATEGORY_ID',
2439         p_column_value         => x_lines.category_id_tbl(i),
2440         p_token1_name          => 'COLUMN_NAME',
2441         p_token1_value         => 'CATEGORY',
2442         p_token2_name          => 'VALUE',
2443         p_token2_value         => x_lines.category_tbl(i),
2444         p_validation_id        => PO_VAL_CONSTANTS.c_category_derv,
2445         p_lines                => x_lines
2446       );
2447 
2448       x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2449     END IF;
2450 
2451     -- derivation error for ip_category_id
2452     IF (PO_PDOI_PARAMS.g_request.document_type IN
2453         (PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET,
2454          PO_PDOI_CONSTANTS.g_DOC_TYPE_QUOTATION)) THEN
2455       IF (x_lines.ip_category_tbl(i) IS NOT NULL AND
2456           x_lines.ip_category_id_tbl(i) IS NULL) THEN
2457         IF (PO_LOG.d_stmt) THEN
2458           PO_LOG.stmt(d_module, d_position, 'ip category id derivation failed');
2459           PO_LOG.stmt(d_module, d_position, 'ip category name',
2460                       x_lines.ip_category_tbl(i));
2461         END IF;
2462 
2463         PO_PDOI_ERR_UTL.add_fatal_error
2464         (
2465           p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2466           p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2467           p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2468           p_table_name           => 'PO_LINES_INTERFACE',
2469           p_column_name          => 'IP_CATEGORY_ID',
2470           p_column_value         => x_lines.ip_category_id_tbl(i),
2471           p_token1_name          => 'COLUMN_NAME',
2472           p_token1_value         => 'IP_CATEGORY',
2473           p_token2_name          => 'VALUE',
2474           p_token2_value         => x_lines.ip_category_tbl(i),
2475           p_validation_id        => PO_VAL_CONSTANTS.c_ip_category_derv,
2476           p_lines                => x_lines
2477         );
2478 
2479         x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2480       END IF;
2481     END IF;
2482 
2483     -- derivation error for unit_of_measure
2484     IF (x_lines.uom_code_tbl(i) IS NOT NULL AND
2485         x_lines.unit_of_measure_tbl(i) IS NULL) THEN
2486       IF (PO_LOG.d_stmt) THEN
2487         PO_LOG.stmt(d_module, d_position, 'unit of measure derivation failed');
2488         PO_LOG.stmt(d_module, d_position, 'uom code',
2489                     x_lines.uom_code_tbl(i));
2490       END IF;
2491 
2492       PO_PDOI_ERR_UTL.add_fatal_error
2493       (
2494         p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2495         p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2496         p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2497         p_table_name           => 'PO_LINES_INTERFACE',
2498         p_column_name          => 'UNIT_OF_MEASURE',
2499         p_column_value         => x_lines.unit_of_measure_tbl(i),
2500         p_token1_name          => 'COLUMN_NAME',
2501         p_token1_value         => 'UOM_CODE',
2502         p_token2_name          => 'VALUE',
2503         p_token2_value         => x_lines.uom_code_tbl(i),
2504         p_validation_id        => PO_VAL_CONSTANTS.c_uom_code_derv,
2505         p_lines                => x_lines
2506       );
2507 
2508       x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2509     END IF;
2510 
2511     -- derivation error for line_type_id
2512     IF (x_lines.line_type_tbl(i) IS NOT NULL AND
2513         x_lines.line_type_id_tbl(i) IS NULL) THEN
2514       IF (PO_LOG.d_stmt) THEN
2515         PO_LOG.stmt(d_module, d_position, 'line type id derivation failed');
2516         PO_LOG.stmt(d_module, d_position, 'line type',
2517                     x_lines.line_type_tbl(i));
2518       END IF;
2519 
2520       PO_PDOI_ERR_UTL.add_fatal_error
2521       (
2522         p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2523         p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2524         p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2525         p_table_name           => 'PO_LINES_INTERFACE',
2526         p_column_name          => 'LINE_TYPE_ID',
2527         p_column_value         => x_lines.line_type_id_tbl(i),
2528         p_token1_name          => 'COLUMN_NAME',
2529         p_token1_value         => 'LINE_TYPE',
2530         p_token2_name          => 'VALUE',
2531         p_token2_value         => x_lines.line_type_tbl(i),
2532         p_validation_id        => PO_VAL_CONSTANTS.c_line_type_derv,
2533         p_lines                => x_lines
2534       );
2535 
2536       x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2537     END IF;
2538 
2539     -- derivation error for un_number_id
2540     IF (x_lines.un_number_tbl(i) IS NOT NULL AND
2541         x_lines.un_number_id_tbl(i) IS NULL) THEN
2542       IF (PO_LOG.d_stmt) THEN
2543         PO_LOG.stmt(d_module, d_position, 'un number id derivation failed');
2544         PO_LOG.stmt(d_module, d_position, 'un number',
2545                     x_lines.un_number_tbl(i));
2546       END IF;
2547 
2548       PO_PDOI_ERR_UTL.add_fatal_error
2549       (
2550         p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2551         p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2552         p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2553         p_table_name           => 'PO_LINES_INTERFACE',
2554         p_column_name          => 'UN_NUMBER_ID',
2555         p_column_value         => x_lines.un_number_id_tbl(i),
2556         p_token1_name          => 'COLUMN_NAME',
2557         p_token1_value         => 'UN_NUMBER',
2558         p_token2_name          => 'VALUE',
2559         p_token2_value         => x_lines.un_number_tbl(i)
2560       );
2561 
2562       x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2563     END IF;
2564 
2565     -- derivation error for hazard_class_id
2566     IF (x_lines.hazard_class_tbl(i) IS NOT NULL AND
2567         x_lines.hazard_class_id_tbl(i) IS NULL) THEN
2568       IF (PO_LOG.d_stmt) THEN
2569         PO_LOG.stmt(d_module, d_position, 'hazard class id derivation failed');
2570         PO_LOG.stmt(d_module, d_position, 'hazard class',
2571                     x_lines.hazard_class_tbl(i));
2572       END IF;
2573 
2574       PO_PDOI_ERR_UTL.add_fatal_error
2575       (
2576         p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2577         p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2578         p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2579         p_table_name           => 'PO_LINES_INTERFACE',
2580         p_column_name          => 'HAZARD_CLASS_ID',
2581         p_column_value         => x_lines.hazard_class_id_tbl(i),
2582         p_token1_name          => 'COLUMN_NAME',
2583         p_token1_value         => 'HAZARD_CLASS',
2584         p_token2_name          => 'VALUE',
2585         p_token2_value         => x_lines.hazard_class_tbl(i)
2586       );
2587 
2588       x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2589     END IF;
2590 
2591     -- derivation error for template_id
2592     IF (x_lines.template_name_tbl(i) IS NOT NULL AND
2593         x_lines.template_id_tbl(i) IS NULL) THEN
2594       IF (PO_LOG.d_stmt) THEN
2595         PO_LOG.stmt(d_module, d_position, 'template id derivation failed');
2596         PO_LOG.stmt(d_module, d_position, 'template name',
2597                     x_lines.template_name_tbl(i));
2598       END IF;
2599 
2600       PO_PDOI_ERR_UTL.add_fatal_error
2601       (
2602         p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2603         p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2604         p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2605         p_table_name           => 'PO_LINES_INTERFACE',
2606         p_column_name          => 'TEMPLATE_ID',
2607         p_column_value         => x_lines.template_id_tbl(i),
2608         p_token1_name          => 'COLUMN_NAME',
2609         p_token1_value         => 'TEMPLATE_NAME',
2610         p_token2_name          => 'VALUE',
2611         p_token2_value         => x_lines.template_name_tbl(i)
2612       );
2613 
2614       x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2615     END IF;
2616 
2617     --CLM PDOI Integration Stsrts
2618     IF Nvl(PO_PDOI_PARAMS.g_request.clm_flag,'N') = 'Y'
2619     THEN
2620       -- derivation error for contract_type
2621       IF (x_lines.contract_type_display_tbl(i) IS NOT NULL AND
2622           x_lines.contract_type_tbl(i) IS NULL) THEN
2623         IF (PO_LOG.d_stmt) THEN
2624           PO_LOG.stmt(d_module, d_position, 'contract type derivation failed');
2625           PO_LOG.stmt(d_module, d_position, 'contract type',
2626                       x_lines.contract_type_display_tbl(i));
2627         END IF;
2628 
2629         PO_PDOI_ERR_UTL.add_fatal_error
2630         (
2631           p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2632           p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2633           p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2634           p_table_name           => 'PO_LINES_INTERFACE',
2635           p_column_name          => 'CONTRACT_TYPE',
2636           p_column_value         => x_lines.contract_type_tbl(i),
2637           p_token1_name          => 'COLUMN_NAME',
2638           p_token1_value         => 'CONTRACT_TYPE_DISPLAY',
2639           p_token2_name          => 'VALUE',
2640           p_token2_value         => x_lines.contract_type_display_tbl(i)
2641         );
2642 
2643         x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2644       END IF;
2645 
2646       -- derivation error for cost constraint
2647       IF (x_lines.cost_constraint_display_tbl(i) IS NOT NULL AND
2648           x_lines.cost_constraint_tbl(i) IS NULL) THEN
2649         IF (PO_LOG.d_stmt) THEN
2650           PO_LOG.stmt(d_module, d_position, 'cost constraint derivation failed');
2651           PO_LOG.stmt(d_module, d_position, 'cost constraint',
2652                       x_lines.cost_constraint_display_tbl(i));
2653         END IF;
2654 
2655         PO_PDOI_ERR_UTL.add_fatal_error
2656         (
2657           p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2658           p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2659           p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2660           p_table_name           => 'PO_LINES_INTERFACE',
2661           p_column_name          => 'COST_CONSTRAINT',
2662           p_column_value         => x_lines.cost_constraint_tbl(i),
2663           p_token1_name          => 'COLUMN_NAME',
2664           p_token1_value         => 'COST_CONSTRAINT_DISPLAY',
2665           p_token2_name          => 'VALUE',
2666           p_token2_value         => x_lines.cost_constraint_display_tbl(i)
2667         );
2668 
2669         x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2670       END IF;
2671 
2672       -- derivation error for clm_idc_type
2673       IF (x_lines.clm_idc_type_display_tbl(i) IS NOT NULL AND
2674           x_lines.clm_idc_type_tbl(i) IS NULL) THEN
2675         IF (PO_LOG.d_stmt) THEN
2676           PO_LOG.stmt(d_module, d_position, 'clm_idc_type derivation failed');
2677           PO_LOG.stmt(d_module, d_position, 'clm_idc_type',
2678                       x_lines.clm_idc_type_display_tbl(i));
2679         END IF;
2680 
2681         PO_PDOI_ERR_UTL.add_fatal_error
2682         (
2683           p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2684           p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2685           p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2686           p_table_name           => 'PO_LINES_INTERFACE',
2687           p_column_name          => 'CLM_IDC_TYPE',
2688           p_column_value         => x_lines.clm_idc_type_tbl(i),
2689           p_token1_name          => 'COLUMN_NAME',
2690           p_token1_value         => 'CLM_IDC_TYPE_DISPLAY',
2691           p_token2_name          => 'VALUE',
2692           p_token2_value         => x_lines.clm_idc_type_display_tbl(i)
2693         );
2694 
2695         x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2696       END IF;
2697 
2698       -- derivation error for clm_base_line_num
2699       IF (x_lines.clm_base_line_num_disp_tbl(i) IS NOT NULL AND
2700           x_lines.clm_base_line_num_tbl(i) IS NULL) THEN
2701         IF (PO_LOG.d_stmt) THEN
2702           PO_LOG.stmt(d_module, d_position, 'clm_base_line_num derivation failed');
2703           PO_LOG.stmt(d_module, d_position, 'clm_base_line_num',
2704                       x_lines.clm_base_line_num_disp_tbl(i));
2705         END IF;
2706 
2707         PO_PDOI_ERR_UTL.add_fatal_error
2708         (
2709           p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2710           p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2711           p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2712           p_table_name           => 'PO_LINES_INTERFACE',
2713           p_column_name          => 'CLM_BASE_LINE_NUM',
2714           p_column_value         => x_lines.clm_base_line_num_tbl(i),
2715           p_token1_name          => 'COLUMN_NAME',
2716           p_token1_value         => 'CLM_BASE_LINE_NUM_DISPLAY',
2717           p_token2_name          => 'VALUE',
2718           p_token2_value         => x_lines.clm_base_line_num_disp_tbl(i)
2719         );
2720 
2721         x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2722       END IF;
2723 
2724       -- derivation error for from_header_id
2725       IF (x_lines.from_header_disp_tbl(i) IS NOT NULL AND
2726           x_lines.from_header_id_tbl(i) IS NULL) THEN
2727         IF (PO_LOG.d_stmt) THEN
2728           PO_LOG.stmt(d_module, d_position, 'from_header_id derivation failed');
2729           PO_LOG.stmt(d_module, d_position, 'from_header_id',
2730                       x_lines.from_header_disp_tbl(i));
2731         END IF;
2732 
2733         PO_PDOI_ERR_UTL.add_fatal_error
2734         (
2735           p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2736           p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2737           p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2738           p_table_name           => 'PO_LINES_INTERFACE',
2739           p_column_name          => 'FROM_HEADER_ID',
2740           p_column_value         => x_lines.from_header_id_tbl(i),
2741           p_token1_name          => 'COLUMN_NAME',
2742           p_token1_value         => 'FROM_HEADER_ID_DISPLAY',
2743           p_token2_name          => 'VALUE',
2744           p_token2_value         => x_lines.from_header_disp_tbl(i)
2745         );
2746 
2747         x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2748       END IF;
2749 
2750       -- derivation error for from_line_id
2751       IF (x_lines.from_line_disp_tbl(i) IS NOT NULL AND
2752           x_lines.from_line_id_tbl(i) IS NULL) THEN
2753         IF (PO_LOG.d_stmt) THEN
2754           PO_LOG.stmt(d_module, d_position, 'from_line_id derivation failed');
2755           PO_LOG.stmt(d_module, d_position, 'from_line_id',
2756                       x_lines.from_line_disp_tbl(i));
2757         END IF;
2758 
2759         PO_PDOI_ERR_UTL.add_fatal_error
2760         (
2761           p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2762           p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2763           p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2764           p_table_name           => 'PO_LINES_INTERFACE',
2765           p_column_name          => 'FROM_LINE_ID',
2766           p_column_value         => x_lines.from_line_id_tbl(i),
2767           p_token1_name          => 'COLUMN_NAME',
2768           p_token1_value         => 'FROM_LINE_ID_DISPLAY',
2769           p_token2_name          => 'VALUE',
2770           p_token2_value         => x_lines.from_line_disp_tbl(i)
2771         );
2772 
2773         x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2774       END IF;
2775 
2776     END IF; --PO_PDOI_PARAMS.g_request.clm_flag='Y'
2777     --CLM PDOI Integration Ends
2778   END LOOP;
2779 
2780   PO_TIMING_UTL.stop_time(PO_PDOI_CONSTANTS.g_T_LINE_DERIVE);
2781 
2782   IF (PO_LOG.d_proc) THEN
2783     PO_LOG.proc_end (d_module);
2784   END IF;
2785 
2786 EXCEPTION
2787   WHEN OTHERS THEN
2788     PO_MESSAGE_S.add_exc_msg
2789     (
2790       p_pkg_name => d_pkg_name,
2791       p_procedure_name => d_api_name || '.' || d_position
2792     );
2793     RAISE;
2794 END derive_lines;
2795 
2796 -----------------------------------------------------------------------
2797 --Start of Comments
2798 --Name: derive_lines_for_update
2799 --Function: peform derivation logic on line attributes when the
2800 --          line level action is 'UPDATE'. The attributes include
2801 --          unit_of_measure, po_category_id and ip_category_id
2802 --Parameters:
2803 --IN:
2804 --IN OUT:
2805 --  x_lines
2806 --    record to store all the line rows within the batch;
2807 --    Derivation are performed for certain attributes only
2808 --    if their name value is populated but id value is not.
2809 --OUT:
2810 --End of Comments
2811 ------------------------------------------------------------------------
2812 PROCEDURE derive_lines_for_update
2813 (
2814   x_lines       IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
2815 ) IS
2816 
2817   d_api_name CONSTANT VARCHAR2(30) := 'derive_lines_for_update';
2818   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
2819   d_position NUMBER;
2820 
2821   -- key of temp table used to identify the derived result
2822   l_key po_session_gt.key%TYPE;
2823 
2824   -- table used to save the index of the each row
2825   l_index_tbl DBMS_SQL.NUMBER_TABLE;
2826 BEGIN
2827   d_position := 0;
2828 
2829   IF (PO_LOG.d_proc) THEN
2830     PO_LOG.proc_begin(d_module, 'line counts', x_lines.rec_count);
2831   END IF;
2832 
2833   PO_TIMING_UTL.start_time(PO_PDOI_CONSTANTS.g_T_LINE_DERIVE);
2834 
2835   -- assign a new key used in temporary table
2836   l_key := PO_CORE_S.get_session_gt_nextval;
2837 
2838   -- initialize table containing the row number(index)
2839   PO_PDOI_UTL.generate_ordered_num_list
2840   (
2841     p_size     => x_lines.rec_count,
2842     x_num_list => l_index_tbl
2843   );
2844 
2845   d_position := 10;
2846 
2847   -- derive PO category_id from PO category_name
2848   derive_category_id
2849   (
2850     p_key                  => l_key,
2851     p_category_tbl         => x_lines.category_tbl,
2852     x_category_id_tbl      => x_lines.category_id_tbl
2853   );
2854 
2855  /* Bug 13506679: un number id and hazard class id were not derived when the
2856  	                    action is update for updatable attributes */
2857 
2858     -- derive un_number_id from un_number
2859   derive_un_number_id
2860   (
2861     p_key                  => l_key,
2862     p_index_tbl            => l_index_tbl,
2863     p_un_number_tbl        => x_lines.un_number_tbl,
2864     x_un_number_id_tbl     => x_lines.un_number_id_tbl
2865   );
2866 
2867 
2868 
2869   -- derive hazard_calss_id from hazard_class
2870   derive_hazard_class_id
2871   (
2872     p_key                  => l_key,
2873     p_index_tbl            => l_index_tbl,
2874     p_hazard_class_tbl     => x_lines.hazard_class_tbl,
2875     x_hazard_class_id_tbl  => x_lines.hazard_class_id_tbl
2876   );
2877 
2878 -- Bug 13506679
2879 
2880 
2881   d_position := 20;
2882 
2883   IF (PO_PDOI_PARAMS.g_request.document_type IN
2884       (PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET,
2885        PO_PDOI_CONSTANTS.g_DOC_TYPE_QUOTATION)) THEN
2886     -- derive IP category_id from IP category_name
2887     derive_ip_category_id
2888     (
2889       p_key                    => l_key,
2890       p_index_tbl              => l_index_tbl,
2891       p_file_line_language_tbl => x_lines.file_line_language_tbl,
2892       p_ip_category_tbl        => x_lines.ip_category_tbl,
2893       x_ip_category_id_tbl     => x_lines.ip_category_id_tbl
2894     );
2895 
2896     d_position := 22;
2897 
2898     -- Bug 7577670: Derive ip_category_id from po_category_id
2899     -- if ip_category_id is null and po_category_id is not null
2900     default_ip_cat_id_from_po(p_key                 => l_key,
2901                               p_index_tbl           => l_index_tbl,
2902                               p_po_category_id_tbl  => x_lines.category_id_tbl,
2903                               x_ip_category_id_tbl  => x_lines.ip_category_id_tbl);
2904 
2905     d_position := 25;
2906 
2907     -- Bug 7577670: Derive po_category_id from ip_category_id
2908     -- if po_category_id is null and ip_category_id is not null
2909     default_po_cat_id_from_ip(p_key                 => l_key,
2910                               p_index_tbl           => l_index_tbl,
2911                               p_ip_category_id_tbl  => x_lines.ip_category_id_tbl,
2912                               x_po_category_id_tbl  => x_lines.category_id_tbl);
2913   END IF;
2914 
2915   d_position := 30;
2916 
2917   -- derive unit_of_measure from uom_code
2918   derive_unit_of_measure
2919   (
2920     p_key                  => l_key,
2921     p_index_tbl            => l_index_tbl,
2922     p_uom_code_tbl         => x_lines.uom_code_tbl,
2923     x_unit_of_measure_tbl  => x_lines.unit_of_measure_tbl
2924   );
2925 
2926   d_position := 40;
2927 
2928   -- handle all derivation errors
2929   FOR i IN 1..x_lines.rec_count
2930   LOOP
2931     d_position := 50;
2932 
2933     IF (PO_LOG.d_stmt) THEN
2934       PO_LOG.stmt(d_module, d_position, 'index', i);
2935     END IF;
2936 
2937     -- derivation error for category_id
2938     IF (x_lines.category_tbl(i) IS NOT NULL AND
2939         x_lines.category_id_tbl(i) IS NULL) THEN
2940       IF (PO_LOG.d_stmt) THEN
2941         PO_LOG.stmt(d_module, d_position, 'category id derivation failed');
2942         PO_LOG.stmt(d_module, d_position, 'category name',
2943                     x_lines.category_tbl(i));
2944       END IF;
2945 
2946       PO_PDOI_ERR_UTL.add_fatal_error
2947       (
2948         p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2949         p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2950         p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2951         p_table_name           => 'PO_LINES_INTERFACE',
2952         p_column_name          => 'CATEGORY_ID',
2953         p_column_value         => x_lines.category_id_tbl(i),
2954         p_token1_name          => 'COLUMN_NAME',
2955         p_token1_value         => 'CATEGORY',
2956         p_token2_name          => 'VALUE',
2957         p_token2_value         => x_lines.category_tbl(i)
2958       );
2959 
2960       x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2961     END IF;
2962 
2963     -- derivation error for ip_category_id
2964     IF (PO_PDOI_PARAMS.g_request.document_type IN
2965         (PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET,
2966          PO_PDOI_CONSTANTS.g_DOC_TYPE_QUOTATION)) THEN
2967       IF (x_lines.ip_category_tbl(i) IS NOT NULL AND
2968           x_lines.ip_category_id_tbl(i) IS NULL) THEN
2969         IF (PO_LOG.d_stmt) THEN
2970           PO_LOG.stmt(d_module, d_position, 'ip category id derivation failed');
2971           PO_LOG.stmt(d_module, d_position, 'ip category name',
2972                       x_lines.ip_category_tbl(i));
2973         END IF;
2974 
2975         PO_PDOI_ERR_UTL.add_fatal_error
2976         (
2977           p_interface_header_id  => x_lines.intf_header_id_tbl(i),
2978           p_interface_line_id    => x_lines.intf_line_id_tbl(i),
2979           p_error_message_name   => 'PO_PDOI_DERV_ERROR',
2980           p_table_name           => 'PO_LINES_INTERFACE',
2981           p_column_name          => 'IP_CATEGORY_ID',
2982           p_column_value         => x_lines.ip_category_id_tbl(i),
2983           p_token1_name          => 'COLUMN_NAME',
2984           p_token1_value         => 'IP_CATEGORY',
2985           p_token2_name          => 'VALUE',
2986           p_token2_value         => x_lines.ip_category_tbl(i)
2987         );
2988 
2989         x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
2990       END IF;
2991     END IF;
2992 
2993     -- derivation error for unit_of_measure
2994     IF (x_lines.uom_code_tbl(i) IS NOT NULL AND
2995         x_lines.unit_of_measure_tbl(i) IS NULL) THEN
2996       IF (PO_LOG.d_stmt) THEN
2997         PO_LOG.stmt(d_module, d_position, 'unit of measure derivation failed');
2998         PO_LOG.stmt(d_module, d_position, 'uom code',
2999                     x_lines.uom_code_tbl(i));
3000       END IF;
3001 
3002       PO_PDOI_ERR_UTL.add_fatal_error
3003       (
3004         p_interface_header_id  => x_lines.intf_header_id_tbl(i),
3005         p_interface_line_id    => x_lines.intf_line_id_tbl(i),
3006         p_error_message_name   => 'PO_PDOI_DERV_ERROR',
3007         p_table_name           => 'PO_LINES_INTERFACE',
3008         p_column_name          => 'UNIT_OF_MEASURE',
3009         p_column_value         => x_lines.unit_of_measure_tbl(i),
3010         p_token1_name          => 'COLUMN_NAME',
3011         p_token1_value         => 'UOM_CODE',
3012         p_token2_name          => 'VALUE',
3013         p_token2_value         => x_lines.uom_code_tbl(i)
3014       );
3015 
3016       x_lines.error_flag_tbl(i) := FND_API.g_TRUE;
3017     END IF;
3018   END LOOP;
3019 
3020   PO_TIMING_UTL.stop_time(PO_PDOI_CONSTANTS.g_T_LINE_DERIVE);
3021 
3022   IF (PO_LOG.d_proc) THEN
3023     PO_LOG.proc_end (d_module);
3024   END IF;
3025 
3026 EXCEPTION
3027   WHEN OTHERS THEN
3028     PO_MESSAGE_S.add_exc_msg
3029     (
3030       p_pkg_name => d_pkg_name,
3031       p_procedure_name => d_api_name || '.' || d_position
3032     );
3033     RAISE;
3034 END derive_lines_for_update;
3035 -----------------------------------------------------------------------
3036 --Start of Comments
3037 --Name: default_lines
3038 --Function: perform defaulting logic on line attributes
3039 --Parameters:
3040 --IN:
3041 --IN OUT:
3042 --  x_lines
3043 --    record to store all the line rows within the batch;
3044 --    defaulting are performed for certain attributes only
3045 --    if their value is empty.
3046 --OUT:
3047 --End of Comments
3048 ------------------------------------------------------------------------
3049 PROCEDURE default_lines
3050 (
3051   x_lines IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
3052 ) IS
3053 
3054   d_api_name CONSTANT VARCHAR2(30) := 'default_lines';
3055   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
3056   d_position NUMBER;
3057 
3058   -- key of temp table used to identify the derived result
3059   l_key po_session_gt.key%TYPE;
3060 
3061   -- table used to save the index of the each row
3062   l_index_tbl DBMS_SQL.NUMBER_TABLE;
3063 
3064   -- information defaulted from line type
3065   l_li_category_id_tbl     PO_TBL_NUMBER;
3066   l_li_unit_of_measure_tbl PO_TBL_VARCHAR30;
3067   l_li_unit_price_tbl      PO_TBL_NUMBER;
3068 
3069   -- information defaulted from item
3070   l_it_item_desc_tbl       PO_TBL_VARCHAR2000;
3071   l_it_unit_of_measure_tbl PO_TBL_VARCHAR30;
3072   l_it_unit_price_tbl      PO_TBL_NUMBER;
3073   l_it_category_id_tbl     PO_TBL_NUMBER;
3074   l_it_un_number_id_tbl    PO_TBL_NUMBER;
3075   l_it_hazard_class_id_tbl PO_TBL_NUMBER;
3076   l_it_market_price_tbl    PO_TBL_NUMBER;
3077   l_it_secondary_uom_tbl   PO_TBL_VARCHAR30;
3078 
3079   -- information defaulted from job
3080   l_job_item_desc_tbl      PO_TBL_VARCHAR2000;
3081   l_job_category_id_tbl    PO_TBL_NUMBER;
3082 
3083   -- information defaulted from ip category
3084   l_ic_category_id_tbl     PO_TBL_NUMBER; -- bug5130037
3085 
3086 	   -- bug 9194215 <start>
3087  	   x_currency_unit_price   NUMBER  := null;
3088  	   x_precision             NUMBER  := null;
3089  	   x_ext_precision         NUMBER  := null;
3090  	   x_min_acct_unit         NUMBER  := null;
3091  	   -- bug 9194215 <end>
3092 
3093 BEGIN
3094   d_position := 0;
3095 
3096   IF (PO_LOG.d_proc) THEN
3097     PO_LOG.proc_begin(d_module);
3098   END IF;
3099 
3100   PO_TIMING_UTL.start_time(PO_PDOI_CONSTANTS.g_T_LINE_DEFAULT);
3101 
3102   -- get key value to identify rows in po_session_gt table
3103   l_key := PO_CORE_S.get_session_gt_nextval;
3104 
3105   -- default line_type_id that will be used in other defaulting logic;
3106   -- l_index_tbl table is initialized as well
3107   FOR i IN 1..x_lines.rec_count
3108   LOOP
3109     d_position := 10;
3110 
3111     -- set default value for line_type_id
3112     IF (x_lines.line_type_id_tbl(i) IS NULL) THEN
3113       IF (PO_LOG.d_stmt) THEN
3114         PO_LOG.stmt(d_module, d_position, 'set default line type id on line index', i);
3115       END IF;
3116 
3117       x_lines.line_type_id_tbl(i) := PO_PDOI_PARAMS.g_sys.line_type_id;
3118     END IF;
3119 
3120     -- initialize l_index_tbl
3121     l_index_tbl(i) := i;
3122   END LOOP;
3123 
3124   -- get default info from line type definition,
3125   -- the attributes we can default from line type include:
3126   -- order_type_lookup_code, purchasing_basis, matching_basis, category_id,
3127   -- unit_of_measure, unit_price
3128   default_info_from_line_type
3129   (
3130     p_key                        => l_key,
3131     p_index_tbl                  => l_index_tbl,
3132     p_line_type_id_tbl           => x_lines.line_type_id_tbl,
3133     x_order_type_lookup_code_tbl => x_lines.order_type_lookup_code_tbl,
3134     x_purchase_basis_tbl         => x_lines.purchase_basis_tbl,
3135     x_matching_basis_tbl         => x_lines.matching_basis_tbl,
3136     x_category_id_tbl            => l_li_category_id_tbl,
3137     x_unit_of_measure_tbl        => l_li_unit_of_measure_tbl,
3138     x_unit_price_tbl             => l_li_unit_price_tbl
3139   );
3140 
3141   d_position := 20;
3142 
3143   -- get default info from item definition
3144   -- the attributes we can default from item include:
3145   -- item_description, unit_of_measure, unit_price, category_id,
3146   -- un_number_id, hazard_class_id, market_price, secondary_unit_of_measure
3147   default_info_from_item
3148   (
3149     p_key                        => l_key,
3150     p_index_tbl                  => l_index_tbl,
3151     p_item_id_tbl                => x_lines.item_id_tbl,
3152     x_item_desc_tbl              => l_it_item_desc_tbl,
3153     x_unit_of_measure_tbl        => l_it_unit_of_measure_tbl,
3154     x_unit_price_tbl             => l_it_unit_price_tbl,
3155     x_category_id_tbl            => l_it_category_id_tbl,
3156     x_un_number_id_tbl           => l_it_un_number_id_tbl,
3157     x_hazard_class_id_tbl        => l_it_hazard_class_id_tbl,
3158     x_market_price_tbl           => l_it_market_price_tbl,
3159     x_secondary_unit_of_meas_tbl => l_it_secondary_uom_tbl
3160   );
3161 
3162   d_position := 30;
3163 
3164   -- get default info from job
3165   -- the attributes we can default from job include:
3166   -- item_description, and category_id
3167   default_info_from_job
3168   (
3169     p_key                        => l_key,
3170     p_index_tbl                  => l_index_tbl,
3171     p_job_id_tbl                 => x_lines.job_id_tbl,
3172     x_item_desc_tbl              => l_job_item_desc_tbl,
3173     x_category_id_tbl            => l_job_category_id_tbl
3174   );
3175 
3176   d_position := 40;
3177 
3178   l_ic_category_id_tbl := PO_TBL_NUMBER();
3179   l_ic_category_id_tbl.EXTEND(x_lines.rec_count);
3180 
3181   IF (PO_PDOI_PARAMS.g_request.document_type IN
3182       (PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET,
3183        PO_PDOI_CONSTANTS.g_DOC_TYPE_QUOTATION)) THEN
3184 
3185     d_position := 50;
3186 
3187     -- get default po category ids from ip category ids
3188     default_po_cat_id_from_ip
3189     (
3190       p_key                        => l_key,
3191       p_index_tbl                  => l_index_tbl,
3192       p_ip_category_id_tbl         => x_lines.ip_category_id_tbl,
3193       x_po_category_id_tbl         => l_ic_category_id_tbl -- bug5130037
3194     );
3195   END IF;
3196 
3197 
3198   -- default attributes for each line
3199   FOR i IN 1..x_lines.rec_count
3200   LOOP
3201     d_position := 60;
3202 
3203     IF (PO_LOG.d_stmt) THEN
3204       PO_LOG.stmt(d_module, d_position, 'index', i);
3205     END IF;
3206 
3207     -- bug5307208
3208     -- Effective and Expiration date should get truncated.
3209     x_lines.effective_date_tbl(i) := TRUNC(x_lines.effective_date_tbl(i));
3210     x_lines.expiration_date_tbl(i) := TRUNC(x_lines.expiration_date_tbl(i));
3211 
3212 
3213     -- default item_description
3214     x_lines.item_desc_tbl(i) :=
3215       COALESCE(x_lines.item_desc_tbl(i), l_it_item_desc_tbl(i),
3216                l_job_item_desc_tbl(i));
3217 
3218     -- default unit_of_measure
3219     x_lines.unit_of_measure_tbl(i) :=
3220       COALESCE(x_lines.unit_of_measure_tbl(i), l_it_unit_of_measure_tbl(i),
3221                l_li_unit_of_measure_tbl(i));
3222 
3223     -- default unit_price when:
3224     -- 1. unit_price value is null and
3225     -- 2. order_type_lookup_code is not 'FIXED PRICE' and
3226     IF (x_lines.unit_price_tbl(i) IS NULL AND
3227         x_lines.order_type_lookup_code_tbl(i) <> 'FIXED PRICE') THEN
3228       IF (x_lines.order_type_lookup_code_tbl(i) = 'AMOUNT') THEN
3229         IF (PO_LOG.d_stmt) THEN
3230           PO_LOG.stmt(d_module, d_position, 'set price when order type is AMOUNT',
3231                       l_li_unit_price_tbl(i));
3232         END IF;
3233 
3234         x_lines.unit_price_tbl(i) := l_li_unit_price_tbl(i);
3235       ELSE
3236         IF (x_lines.item_id_tbl(i) IS NOT NULL) THEN
3237           IF (PO_LOG.d_stmt) THEN
3238             PO_LOG.stmt(d_module, d_position, 'set price when item id is not empty',
3239                         l_it_unit_price_tbl(i));
3240           END IF;
3241 
3242           x_lines.unit_price_tbl(i) := l_it_unit_price_tbl(i);
3243         ELSE
3244           IF (PO_LOG.d_stmt) THEN
3245             PO_LOG.stmt(d_module, d_position, 'set price when item id is empty',
3246                         NVL(l_li_unit_price_tbl(i), 0));
3247           END IF;
3248 
3249           x_lines.unit_price_tbl(i) := NVL(l_li_unit_price_tbl(i), 0);
3250         END IF;
3251       END IF;
3252 
3253    -- bug 9194215 <start>
3254  	       If x_lines.hd_currency_code_tbl(i) is not null and (x_lines.unit_price_tbl(i) is not null and x_lines.unit_price_tbl(i) <> 0) THEN
3255  	          fnd_currency.get_info (x_lines.hd_currency_code_tbl(i),
3256  	                                 x_precision,
3257  	                                 x_ext_precision,
3258  	                                 x_min_acct_unit);
3259  	                                 x_currency_unit_price := round(x_lines.unit_price_tbl(i) / nvl(x_lines.hd_rate_tbl(i),1),x_ext_precision);
3260  	                                 x_lines.unit_price_tbl(i)      := x_currency_unit_price;
3261  	       END IF;
3262  	       -- bug 9194215 <end>
3263     END IF;
3264 
3265     -- default base_unit_price
3266     IF (x_lines.base_unit_price_tbl(i) IS NULL AND
3267         x_lines.order_type_lookup_code_tbl(i) <> 'FIXED PRICE') THEN
3268       x_lines.base_unit_price_tbl(i) := x_lines.unit_price_tbl(i);
3269     END IF;
3270 
3271     -- default po category_id
3272     x_lines.category_id_tbl(i) :=
3273         COALESCE(x_lines.category_id_tbl(i), l_it_category_id_tbl(i),
3274                  l_job_category_id_tbl(i), l_ic_category_id_tbl(i),
3275                  l_li_category_id_tbl(i),
3276                  PO_PDOI_PARAMS.g_sys.def_category_id);
3277 
3278     IF (PO_LOG.d_stmt) THEN
3279       PO_LOG.stmt(d_module, d_position, 'default category id',
3280                   x_lines.category_id_tbl(i));
3281     END IF;
3282 
3283     -- default un_number_id and hazard_class_id from item
3284     x_lines.un_number_id_tbl(i) :=
3285         NVL(x_lines.un_number_id_tbl(i), l_it_un_number_id_tbl(i));
3286     x_lines.hazard_class_id_tbl(i) :=
3287         NVL(x_lines.hazard_class_id_tbl(i), l_it_hazard_class_id_tbl(i));
3288 
3289     -- set from_header_id and from_line_id to NULL
3290 	--CLM PDOI Integration
3291 	IF Nvl(PO_PDOI_PARAMS.g_request.clm_flag,'N') = 'N' THEN
3292       x_lines.from_header_id_tbl(i) := NULL;
3293       x_lines.from_line_id_tbl(i) := NULL;
3294 	END IF;
3295 
3296     d_position := 70;
3297 
3298     -- the following default logic is for BLANKET/STANDARD only
3299     IF (PO_PDOI_PARAMS.g_request.document_type IN
3300         (PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET,
3301          PO_PDOI_CONSTANTS.g_DOC_TYPE_STANDARD)) THEN
3302       d_position := 80;
3303 
3304       IF (PO_LOG.d_stmt) THEN
3305         PO_LOG.stmt(d_module, d_position, 'set default value for blanket/spo');
3306       END IF;
3307 
3308       -- default list_price_per_unit
3309       IF (x_lines.list_price_per_unit_tbl(i) IS NULL) THEN
3310         IF (x_lines.item_id_tbl(i) IS NULL) THEN
3311           x_lines.list_price_per_unit_tbl(i) := x_lines.unit_price_tbl(i);
3312 	  IF (PO_PDOI_PARAMS.g_request.document_type =
3313            PO_PDOI_CONSTANTS.g_DOC_TYPE_STANDARD) THEN -- bug 9374205
3314    -- bug 9194215 <start>
3315  	           If x_lines.hd_currency_code_tbl(i) is not null and (x_lines.list_price_per_unit_tbl(i) is not null and x_lines.list_price_per_unit_tbl(i) <> 0) THEN
3316  	              fnd_currency.get_info (x_lines.hd_currency_code_tbl(i),
3317  	                                     x_precision,
3318  	                                     x_ext_precision,
3319  	                                     x_min_acct_unit);
3320  	                                     x_currency_unit_price := round(x_lines.list_price_per_unit_tbl(i) * nvl(x_lines.hd_rate_tbl(i),1),x_ext_precision);
3321  	                                     x_lines.list_price_per_unit_tbl(i)      := x_currency_unit_price;
3322  	           END IF;
3323  	           -- bug 9194215 <end>
3324              END IF;
3325         ELSE
3326           x_lines.list_price_per_unit_tbl(i) := l_it_unit_price_tbl(i);
3327         END IF;
3328       END IF;
3329 
3330       -- default market_price
3331       IF (x_lines.market_price_tbl(i) IS NULL AND
3332           x_lines.item_id_tbl(i) IS NOT NULL) THEN
3333         x_lines.market_price_tbl(i) := l_it_unit_price_tbl(i);
3334       END IF;
3335 
3336       -- default capital_expense_flag,
3337       x_lines.capital_expense_flag_tbl(i) :=
3338           NVL(x_lines.capital_expense_flag_tbl(i), 'N');
3339 
3340       -- default min_release_amount, negotiated_flag and
3341       -- price_break_lookup_code for blanket
3342       IF (PO_PDOI_PARAMS.g_request.document_type =
3343           PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET) THEN
3344         d_position := 90;
3345 
3346         IF (PO_LOG.d_stmt) THEN
3347           PO_LOG.stmt(d_module, d_position, 'set default value for blanket');
3348         END IF;
3349 
3350         -- min_release_amount
3351         x_lines.min_release_amount_tbl(i) :=
3352             NVL(x_lines.min_release_amount_tbl(i),
3353             x_lines.hd_min_release_amount_tbl(i));
3354 
3355         -- negotiated_by_preparer_flag
3356         x_lines.negotiated_flag_tbl(i) :=
3357           NVL(x_lines.negotiated_flag_tbl(i), 'Y');
3358 
3359         -- price_break_lookup_code
3360 
3361         -- bug5129112
3362         -- Do not default price break lookup code for global agreements
3363         IF (x_lines.price_break_lookup_code_tbl(i) IS NULL) THEN
3364           IF (x_lines.hd_global_agreement_flag_tbl(i) = 'Y'
3365               OR
3366               ( x_lines.order_type_lookup_code_tbl(i) = 'FIXED PRICE' AND
3367                 x_lines.purchase_basis_tbl(i) = 'SERVICES')) THEN
3368             x_lines.price_break_lookup_code_tbl(i) := NULL;
3369           ELSE
3370             x_lines.price_break_lookup_code_tbl(i) :=
3371               PO_PDOI_PARAMS.g_sys.price_break_lookup_code;
3372           END IF;
3373         END IF;
3374       ELSE
3375         -- default tax_attribute_update_code for SPO
3376         x_lines.tax_attribute_update_code_tbl(i) := 'CREATE';
3377 
3378         -- negotiated_by_preparer_flag
3379         x_lines.negotiated_flag_tbl(i) :=
3380           NVL(x_lines.negotiated_flag_tbl(i), 'N');
3381       END IF;
3382 
3383       d_position := 100;
3384 
3385       -- default allow_price_override_flag
3386       x_lines.allow_price_override_flag_tbl(i) :=
3387           NVL(x_lines.allow_price_override_flag_tbl(i), 'N');
3388 
3389       -- default price_type
3390       x_lines.price_type_tbl(i) :=
3391           NVL(x_lines.price_type_tbl(i), PO_PDOI_PARAMS.g_sys.price_type_lookup_code);
3392 
3393       -- default closed_code
3394       x_lines.closed_code_tbl(i) :=
3395           NVL(x_lines.closed_code_tbl(i), 'OPEN');
3396 
3397       -- set unordered_flag, cancel_flag
3398       x_lines.unordered_flag_tbl(i) := 'N';
3399       x_lines.cancel_flag_tbl(i) := 'N';
3400 
3401       -- set quantity_committed from quantity
3402       x_lines.quantity_committed_tbl(i) := x_lines.quantity_tbl(i);
3403 
3404       -- default secondary_unit_of_measure from item definition
3405       x_lines.secondary_unit_of_meas_tbl(i) :=
3406         NVL(x_lines.secondary_unit_of_meas_tbl(i), l_it_secondary_uom_tbl(i));
3407     END IF;
3408   END LOOP;
3409 
3410 
3411   IF (PO_PDOI_PARAMS.g_request.document_type IN
3412       (PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET,
3413        PO_PDOI_CONSTANTS.g_DOC_TYPE_QUOTATION)) THEN
3414 
3415     -- default ip category id from po category ids after all other defaulting
3416     -- for po category ids have happened
3417 
3418     d_position := 105;
3419 
3420     -- get default ip category ids from po category ids
3421     default_ip_cat_id_from_po
3422     (
3423       p_key                        => l_key,
3424       p_index_tbl                  => l_index_tbl,
3425       p_po_category_id_tbl         => x_lines.category_id_tbl,
3426       x_ip_category_id_tbl         => x_lines.ip_category_id_tbl
3427     );
3428 
3429 
3430     -- If ip category id cannot be defaulted, set the value to -2.
3431     FOR i IN 1..x_lines.rec_count LOOP
3432 
3433       x_lines.ip_category_id_tbl(i) := NVL(x_lines.ip_category_id_tbl(i), -2);
3434 
3435     END LOOP;
3436 
3437   END IF;
3438 
3439   -- default hazard_class_id from un_number
3440   default_hc_id_from_un_number
3441   (
3442     p_key                      => l_key,
3443     p_index_tbl                => l_index_tbl,
3444     p_un_number_tbl            => x_lines.un_number_tbl,
3445     x_hazard_class_id_tbl      => x_lines.hazard_class_id_tbl
3446   );
3447 
3448   d_position := 110;
3449 
3450   -- call utility method to default standard who columns
3451   PO_PDOI_MAINPROC_UTL_PVT.default_who_columns
3452   (
3453     x_last_update_date_tbl       => x_lines.last_update_date_tbl,
3454     x_last_updated_by_tbl        => x_lines.last_updated_by_tbl,
3455     x_last_update_login_tbl      => x_lines.last_update_login_tbl,
3456     x_creation_date_tbl          => x_lines.creation_date_tbl,
3457     x_created_by_tbl             => x_lines.created_by_tbl,
3458     x_request_id_tbl             => x_lines.request_id_tbl,
3459     x_program_application_id_tbl => x_lines.program_application_id_tbl,
3460     x_program_id_tbl             => x_lines.program_id_tbl,
3461     x_program_update_date_tbl    => x_lines.program_update_date_tbl
3462   );
3463 
3464   --CLM PDOI Integration Starts
3465 
3466   IF Nvl(PO_PDOI_PARAMS.g_request.clm_flag,'N') = 'Y'
3467   THEN
3468     --default clm_option_indicator flag for base lines
3469     default_clm_option_indicator
3470     (
3471       p_key                      => l_key,
3472       p_index_tbl                => l_index_tbl,
3473       p_intf_line_id_tbl         => x_lines.intf_line_id_tbl,
3474       p_clm_base_line_num_tbl    => x_lines.clm_base_line_num_tbl,
3475       x_clm_option_indicator_tbl => x_lines.clm_option_indicator_tbl
3476     );
3477 
3478     default_clm_option_num
3479     (
3480       p_key                      => l_key,
3481       p_index_tbl                => l_index_tbl,
3482       p_intf_header_id_tbl       => x_lines.intf_header_id_tbl,
3483       p_intf_line_id_tbl         => x_lines.intf_line_id_tbl,
3484       p_clm_base_line_num_tbl    => x_lines.clm_base_line_num_tbl,
3485       p_clm_option_indicator_tbl => x_lines.clm_option_indicator_tbl,
3486       x_clm_option_num_tbl       => x_lines.clm_option_num_tbl
3487     );
3488 
3489     default_from_header_id
3490     (
3491       p_key                      => l_key,
3492       p_index_tbl                => l_index_tbl,
3493       p_intf_header_id_tbl       => x_lines.intf_header_id_tbl,
3494       p_intf_line_id_tbl         => x_lines.intf_line_id_tbl,
3495       x_from_header_id_tbl       => x_lines.from_header_id_tbl
3496     );
3497 
3498   END IF; --PO_PDOI_PARAMS.g_request.clm_flag='Y'
3499   --CLM PDOI Integration Ends
3500 
3501   PO_TIMING_UTL.stop_time(PO_PDOI_CONSTANTS.g_T_LINE_DEFAULT);
3502 
3503   IF (PO_LOG.d_proc) THEN
3504     PO_LOG.proc_end (d_module);
3505   END IF;
3506 
3507 EXCEPTION
3508   WHEN OTHERS THEN
3509     PO_MESSAGE_S.add_exc_msg
3510     (
3511       p_pkg_name => d_pkg_name,
3512       p_procedure_name => d_api_name || '.' || d_position
3513     );
3514     RAISE;
3515 END default_lines;
3516 
3517 -----------------------------------------------------------------------
3518 --Start of Comments
3519 --Name: default_lines_for_update
3520 --Function: default certain attribute values from draft or txn tables;
3521 --          These attributes are used in internal processing;
3522 --          The attributes include:
3523 --          order_type_lookup_code, item_id, job_id
3524 --Parameters:
3525 --IN:
3526 --IN OUT:
3527 --  x_lines
3528 --    record to store all the line rows within the batch;
3529 --    Defaulting is performed for certain attributes only.
3530 --OUT:
3531 --End of Comments
3532 ------------------------------------------------------------------------
3533 PROCEDURE default_lines_for_update
3534 (
3535   x_lines       IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
3536 ) IS
3537 
3538   d_api_name CONSTANT VARCHAR2(30) := 'default_lines_for_update';
3539   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
3540   d_position NUMBER;
3541 
3542   -- key of temp table used to identify the derived result
3543   l_key                    po_session_gt.key%TYPE;
3544 
3545   -- table used to save the index of the each row
3546   l_num_list               DBMS_SQL.NUMBER_TABLE;
3547 
3548   -- information defaulted from existing po line
3549   l_index_tbl              PO_TBL_NUMBER;
3550   l_order_type_tbl         PO_TBL_VARCHAR30;
3551   l_item_id_tbl            PO_TBL_NUMBER;
3552   l_job_id_tbl             PO_TBL_NUMBER;
3553 
3554   l_index                  NUMBER;
3555   --vegajula--bugno:9531925
3556 
3557   l_po_header_id_tbl       PO_TBL_NUMBER;
3558 
3559 BEGIN
3560   d_position := 0;
3561 
3562   IF (PO_LOG.d_proc) THEN
3563     PO_LOG.proc_begin(d_module, 'po_line_id', x_lines.po_line_id_tbl);
3564     PO_LOG.proc_begin(d_module, 'draft_id', x_lines.draft_id_tbl);
3565   END IF;
3566 
3567   PO_TIMING_UTL.start_time(PO_PDOI_CONSTANTS.g_T_LINE_DERIVE);
3568 
3569   -- assign a new key used in temporary table
3570   l_key := PO_CORE_S.get_session_gt_nextval;
3571 
3572   -- initialize table containing the row number(index)
3573   PO_PDOI_UTL.generate_ordered_num_list
3574   (
3575     p_size     => x_lines.rec_count,
3576     x_num_list => l_num_list
3577   );
3578 
3579   d_position := 10;
3580 
3581   -- get values from draft tables
3582   FORALL i IN 1..l_num_list.COUNT
3583     INSERT INTO po_session_gt(key, num1, char1, num2, num3, num4) --num4 is added by vegajula for bugno:9531925
3584     SELECT l_key,
3585            l_num_list(i),
3586            order_type_lookup_code,
3587            item_id,
3588            job_id,
3589 	   po_header_id  --vegajula  bugno:9531925
3590     FROM   po_lines_draft_all
3591     WHERE  po_line_id = x_lines.po_line_id_tbl(i)
3592     AND    draft_id = x_lines.draft_id_tbl(i);
3593 
3594   d_position := 20;
3595 
3596   -- get values from txn table if no draft line exist
3597   FORALL i IN 1..l_num_list.COUNT
3598      INSERT INTO po_session_gt(key, num1, char1, num2, num3, num4)  --num4 is added by vegajula for bugno:9531925
3599     SELECT l_key,
3600            l_num_list(i),
3601            order_type_lookup_code,
3602            item_id,
3603            job_id,
3604 	   po_header_id  --vegajula  bugno:9531925
3605     FROM   po_lines_all
3606     WHERE  po_line_id = x_lines.po_line_id_tbl(i)
3607     AND    NOT EXISTS (SELECT 1
3608                        FROM   po_lines_draft_all
3609                        WHERE  po_line_id = x_lines.po_line_id_tbl(i)
3610                        AND    draft_id = x_lines.draft_id_tbl(i));
3611 
3612   d_position := 30;
3613 
3614   DELETE FROM po_session_gt
3615   WHERE key = l_key
3616   RETURNING num1, char1, num2, num3, num4 BULK COLLECT INTO   ---num4 added by vegajula for bugno:9531925
3617    l_index_tbl, l_order_type_tbl, l_item_id_tbl, l_job_id_tbl, l_po_header_id_tbl ; --l_po_header_id_tbl added by vegajula for bugno:9531925
3618 
3619   d_position := 40;
3620 
3621   IF (PO_LOG.d_stmt) THEN
3622     PO_LOG.stmt(d_module, d_position, 'l_index_tbl', l_index_tbl);
3623     PO_LOG.stmt(d_module, d_position, 'l_order_type_tbl', l_order_type_tbl);
3624     PO_LOG.stmt(d_module, d_position, 'l_item_id_tbl', l_item_id_tbl);
3625     PO_LOG.stmt(d_module, d_position, 'l_job_id_tbl', l_job_id_tbl);
3626   END IF;
3627 
3628   FOR i IN 1..l_index_tbl.COUNT
3629   LOOP
3630     l_index := l_index_tbl(i);
3631     x_lines.po_header_id_tbl(l_index) := l_po_header_id_tbl(i); --------vegajula for bugno:9531925
3632     x_lines.order_type_lookup_code_tbl(l_index) := l_order_type_tbl(i);
3633     x_lines.item_id_tbl(l_index) := l_item_id_tbl(i);
3634     x_lines.job_id_tbl(l_index) := l_job_id_tbl(i);
3635   END LOOP;
3636 
3637   PO_TIMING_UTL.stop_time(PO_PDOI_CONSTANTS.g_T_LINE_DERIVE);
3638 
3639   IF (PO_LOG.d_proc) THEN
3640     PO_LOG.proc_end (d_module);
3641   END IF;
3642 
3643 EXCEPTION
3644   WHEN OTHERS THEN
3645     PO_MESSAGE_S.add_exc_msg
3646     (
3647       p_pkg_name => d_pkg_name,
3648       p_procedure_name => d_api_name || '.' || d_position
3649     );
3650     RAISE;
3651 END default_lines_for_update;
3652 
3653 -----------------------------------------------------------------------
3654 --Start of Comments
3655 --Name: match_lines
3656 --Function: perform matching logic on line num and item related info;
3657 --          This procedure is called only when the document action is
3658 --          'ORIGINAL' or 'REPLACE' or 'UPDATE Standard PO'
3659 --Parameters:
3660 --IN:
3661 --IN OUT:
3662 --  x_lines
3663 --    record to store all the line rows within the batch;
3664 --OUT:
3665 --End of Comments
3666 ------------------------------------------------------------------------
3667 PROCEDURE match_lines
3668 (
3669   p_data_set_type IN NUMBER,  -- bug5129752
3670   x_lines         IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
3671 ) IS
3672 
3673   d_api_name CONSTANT VARCHAR2(30) := 'match_lines';
3674   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
3675   d_position NUMBER;
3676 
3677   l_index_tbl   DBMS_SQL.NUMBER_TABLE;
3678 
3679   l_create_lines PO_PDOI_TYPES.lines_rec_type;
3680   l_update_lines PO_PDOI_TYPES.lines_rec_type;
3681 
3682   l_rej_intf_line_id_tbl PO_TBL_NUMBER := PO_TBL_NUMBER();
3683 BEGIN
3684   d_position := 0;
3685 
3686   IF (PO_LOG.d_proc) THEN
3687     PO_LOG.proc_begin(d_module);
3688   END IF;
3689 
3690   PO_TIMING_UTL.start_time(PO_PDOI_CONSTANTS.g_T_LINE_MATCH);
3691 
3692   -- initialize index table
3693   PO_PDOI_UTL.generate_ordered_num_list
3694   (
3695     p_size     => x_lines.rec_count,
3696     x_num_list => l_index_tbl
3697   );
3698 
3699   d_position := 10;
3700 
3701   IF (PO_LOG.d_stmt) THEN
3702     PO_LOG.stmt(d_module, d_position, 'start to match lines based on line num');
3703   END IF;
3704 
3705   -- bug5129752
3706   -- For FORCE ALL, simply set all line action to 'ADD'
3707 
3708   IF (p_data_set_type = PO_PDOI_CONSTANTS.g_LINE_CSR_FORCE_ADD) THEN
3709     d_position := 15;
3710 
3711     FOR i IN 1..x_lines.rec_count LOOP
3712       x_lines.po_line_id_tbl(i) :=
3713         PO_PDOI_MAINPROC_UTL_PVT.get_next_po_line_id;
3714 
3715       IF (x_lines.line_num_tbl(i) IS NULL) THEN
3716         x_lines.line_num_tbl(i) :=
3717           PO_PDOI_MAINPROC_UTL_PVT.get_next_line_num
3718           (x_lines.po_header_id_tbl(i));
3719       END IF;
3720 
3721       x_lines.action_tbl(i) := PO_PDOI_CONSTANTS.g_ACTION_ADD;
3722 
3723     END LOOP;
3724 
3725   ELSE
3726 
3727     -- match lines based on line_num
3728     match_lines_on_line_num
3729     (
3730       p_index_tbl   => l_index_tbl,
3731       x_lines       => x_lines
3732     );
3733 
3734     d_position := 20;
3735 
3736     IF (PO_LOG.d_stmt) THEN
3737       PO_LOG.stmt(d_module, d_position, 'start to match lines based on item info');
3738     END IF;
3739 
3740     -- match lines based on item related info
3741     match_lines_on_item_info
3742     (
3743       x_lines       => x_lines
3744     );
3745 
3746     d_position := 30;
3747 
3748   END IF;
3749 
3750   -- check whether line location needs to be created for the line
3751   check_line_locations
3752   (
3753     x_lines       => x_lines
3754   );
3755 
3756   d_position := 40;
3757 
3758   -- split lines based on action
3759   -- all lines with action = 'UPDATE' are location lines
3760   split_lines
3761   (
3762     p_group_num      => NULL,
3763     p_lines          => x_lines,
3764     x_create_lines   => l_create_lines,
3765     x_update_lines   => l_update_lines
3766   );
3767 
3768   IF (PO_LOG.d_stmt) THEN
3769     PO_LOG.stmt(d_module, d_position, 'num of created lines', l_create_lines.rec_count);
3770     PO_LOG.stmt(d_module, d_position, 'num of updated lines', l_update_lines.rec_count);
3771   END IF;
3772 
3773   d_position := 50;
3774 
3775   -- assign l_create_lines to x_lines since it contains
3776   -- all the lines that need to be created
3777   x_lines := l_create_lines;
3778 
3779   -- update location only lines with new po_line_id and price_break_flag
3780   FORALL i IN 1..l_update_lines.rec_count
3781     UPDATE po_lines_interface
3782     SET    po_line_id = l_update_lines.po_line_id_tbl(i),
3783            price_break_flag = 'Y'
3784     WHERE  interface_line_id = l_update_lines.intf_line_id_tbl(i);
3785 
3786   d_position := 60;
3787 
3788   -- reject lines that has action=UPDATE and create_line_loc=N
3789   -- insert error message if the line is neither a po line or location
3790   FOR i IN 1..l_update_lines.rec_count
3791   LOOP
3792     IF (PO_LOG.d_stmt) THEN
3793       PO_LOG.stmt(d_module, d_position, 'index', i);
3794       PO_LOG.stmt(d_module, d_position, 'create location flag',
3795                   l_update_lines.create_line_loc_tbl(i));
3796 
3797     END IF;
3798 
3799     IF (l_update_lines.create_line_loc_tbl(i) = FND_API.g_FALSE) THEN
3800       PO_PDOI_ERR_UTL.add_fatal_error
3801       (
3802         p_interface_header_id  => l_update_lines.intf_header_id_tbl(i),
3803         p_interface_line_id    => l_update_lines.intf_line_id_tbl(i),
3804         p_error_message_name   => 'PO_PDOI_INVALID_INTER_LINE_REC',
3805         p_table_name           => 'PO_LINES_INTERFACE',
3806         p_column_name          => 'CREATE_PO_LINES_FLAG',
3807         p_column_value         => 'N',
3808         p_token1_name          => 'COLUMN_NAME',
3809         p_token1_value         => 'CREATE_PO_LINES_FLAG',
3810         p_token2_name          => 'VALUE',
3811         p_token2_value         => 'N'
3812       );
3813 
3814       l_rej_intf_line_id_tbl.EXTEND;
3815       l_rej_intf_line_id_tbl(l_rej_intf_line_id_tbl.COUNT) := l_update_lines.intf_line_id_tbl(i);
3816       IF (PO_LOG.d_stmt) THEN
3817         PO_LOG.stmt(d_module, d_position, 'to be rejected intf line id',
3818                     l_update_lines.intf_line_id_tbl(i));
3819 
3820       END IF;
3821     END IF;
3822   END LOOP;
3823 
3824   d_position := 70;
3825 
3826   PO_PDOI_UTL.reject_lines_intf
3827   (
3828     p_id_param_type   => PO_PDOI_CONSTANTS.g_INTERFACE_LINE_ID,
3829     p_id_tbl          => l_rej_intf_line_id_tbl,
3830     p_cascade         => FND_API.g_TRUE
3831   );
3832 
3833   PO_TIMING_UTL.stop_time(PO_PDOI_CONSTANTS.g_T_LINE_MATCH);
3834 
3835   IF (PO_LOG.d_proc) THEN
3836     PO_LOG.proc_end (d_module);
3837   END IF;
3838 
3839 EXCEPTION
3840   WHEN OTHERS THEN
3841     PO_MESSAGE_S.add_exc_msg
3842     (
3843       p_pkg_name => d_pkg_name,
3844       p_procedure_name => d_api_name || '.' || d_position
3845     );
3846     RAISE;
3847 END match_lines;
3848 
3849 -----------------------------------------------------------------------
3850 --Start of Comments
3851 --Name: check_line_locations
3852 --Function: At the beginning of PDOI process, if line_loc_populated_flag
3853 --          is not set, we will create a row in line_location_interface
3854 --          table and copy over the line location related attributes on
3855 --          that line no matter whether user wants to create a location
3856 --          for that po line.
3857 --          In this procedure, we will check the real intention of user
3858 --          and obsolete location lines that should not be save to txn table.
3859 --Parameters:
3860 --IN:
3861 --IN OUT:
3862 --  x_lines
3863 --    record to store all the line rows within the batch;
3864 --OUT:
3865 --End of Comments
3866 ------------------------------------------------------------------------
3867 PROCEDURE check_line_locations
3868 (
3869   x_lines       IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
3870 ) IS
3871 
3872   d_api_name CONSTANT VARCHAR2(30) := 'check_line_locations';
3873   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
3874   d_position NUMBER;
3875 
3876   -- table to mark which line location needs to rejected in
3877   -- line location interface table
3878   l_obsoleted_loc_tbl  PO_TBL_NUMBER := PO_TBL_NUMBER();
3879   l_obsolete_rec_count              NUMBER := 0;
3880 
3881 BEGIN
3882   d_position := 0;
3883 
3884   IF (PO_LOG.d_proc) THEN
3885     PO_LOG.proc_begin(d_module);
3886   END IF;
3887 
3888   l_obsoleted_loc_tbl.EXTEND(x_lines.rec_count);
3889 
3890   -- check whether location should be created on each line
3891   FOR i IN 1..x_lines.rec_count
3892   LOOP
3893     d_position := 10;
3894 
3895     IF (PO_LOG.d_stmt) THEN
3896       PO_LOG.stmt(d_module, d_position, 'index', i);
3897       PO_LOG.stmt(d_module, d_position, 'loc populated flag',
3898                   x_lines.line_loc_populated_flag_tbl(i));
3899     END IF;
3900 
3901     IF (x_lines.line_loc_populated_flag_tbl(i) = 'S') THEN
3902       IF (PO_LOG.d_stmt) THEN
3903         PO_LOG.stmt(d_module, d_position, 'document type',
3904                     PO_PDOI_PARAMS.g_request.document_type);
3905         PO_LOG.stmt(d_module, d_position, 'order_type_lookup_code',
3906                     x_lines.order_type_lookup_code_tbl(i));
3907         PO_LOG.stmt(d_module, d_position, 'action',
3908                     x_lines.action_tbl(i));
3909         PO_LOG.stmt(d_module, d_position, 'quantity',
3910                     x_lines.quantity_tbl(i));
3911         PO_LOG.stmt(d_module, d_position, 'shipment_num',
3912                     x_lines.shipment_num_tbl(i));
3913       END IF;
3914       -- set to TRUE in certain conditions
3915       IF (PO_PDOI_PARAMS.g_request.document_type =
3916           PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET) THEN
3917         IF (x_lines.order_type_lookup_code_tbl(i) IN ('QUANTITY', 'RATE') AND
3918             x_lines.action_tbl(i) = PO_PDOI_CONSTANTS.g_ACTION_UPDATE AND
3919             (x_lines.quantity_tbl(i) > 0 OR x_lines.shipment_num_tbl(i) IS NOT NULL)) THEN
3920           x_lines.create_line_loc_tbl(i) := FND_API.g_TRUE;
3921         END IF;
3922       ELSIF (PO_PDOI_PARAMS.g_request.document_type =
3923              PO_PDOI_CONSTANTS.g_DOC_TYPE_STANDARD) THEN
3924         IF (x_lines.order_type_lookup_code_tbl(i) IN ('FIXED PRICE', 'RATE') OR
3925             x_lines.quantity_tbl(i) > 0) THEN
3926           x_lines.create_line_loc_tbl(i) := FND_API.g_TRUE;
3927         END IF;
3928       ELSIF (PO_PDOI_PARAMS.g_request.document_type =
3929              PO_PDOI_CONSTANTS.g_DOC_TYPE_QUOTATION) THEN
3930         IF (x_lines.order_type_lookup_code_tbl(i) = 'QUANTITY' AND
3931             (x_lines.quantity_tbl(i) > 0 OR x_lines.shipment_num_tbl(i) IS NOT NULL)) THEN
3932           x_lines.create_line_loc_tbl(i) := FND_API.g_TRUE;
3933         END IF;
3934       END IF;
3935 
3936       IF (PO_LOG.d_stmt) THEN
3937         PO_LOG.stmt(d_module, d_position, 'create_line_loc',
3938                     x_lines.create_line_loc_tbl(i));
3939       END IF;
3940 
3941       d_position := 20;
3942 
3943       -- mark down locations that need to be obsoleted after the looping
3944 
3945       IF (x_lines.create_line_loc_tbl(i) = FND_API.g_FALSE) THEN
3946         l_obsolete_rec_count := l_obsolete_rec_count + 1;
3947         l_obsoleted_loc_tbl(l_obsolete_rec_count) := x_lines.intf_line_id_tbl(i);
3948       END IF;
3949 
3950     END IF;
3951   END LOOP;
3952 
3953   -- trim the entries that were not populated
3954   l_obsoleted_loc_tbl.TRIM (l_obsoleted_loc_tbl.COUNT - l_obsolete_rec_count);
3955 
3956 
3957   d_position := 30;
3958 
3959   -- obsolete the location lines that have been marked
3960   FORALL i IN 1..l_obsoleted_loc_tbl.COUNT
3961     UPDATE po_line_locations_interface
3962     SET    process_code = PO_PDOI_CONSTANTS.g_PROCESS_CODE_OBSOLETE
3963     WHERE interface_line_id = l_obsoleted_loc_tbl(i);
3964 
3965 /*
3966   PO_PDOI_UTL.reject_line_locations_intf
3967   (
3968     p_id_param_type           => PO_PDOI_CONSTANTS.g_INTERFACE_LINE_ID,
3969     p_id_tbl                  => l_obsoleted_loc_tbl,
3970     p_cascade                 => FND_API.g_TRUE
3971   );
3972 */
3973   IF (PO_LOG.d_proc) THEN
3974     PO_LOG.proc_end (d_module);
3975   END IF;
3976 
3977 EXCEPTION
3978   WHEN OTHERS THEN
3979     PO_MESSAGE_S.add_exc_msg
3980     (
3981       p_pkg_name => d_pkg_name,
3982       p_procedure_name => d_api_name || '.' || d_position
3983     );
3984     RAISE;
3985 END check_line_locations;
3986 
3987 -----------------------------------------------------------------------
3988 --Start of Comments
3989 --Name: update_line_intf_tbl
3990 --Function: After line processing, set po_line_id, extracted line
3991 --          level action and price tolerance back to interface table
3992 --Parameters:
3993 --IN:
3994 --IN OUT:
3995 --  x_lines
3996 --    record which stores all the line rows within the batch;
3997 --OUT:
3998 --End of Comments
3999 ------------------------------------------------------------------------
4000 PROCEDURE update_line_intf_tbl
4001 (
4002   x_lines    IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
4003 ) IS
4004 
4005   d_api_name CONSTANT VARCHAR2(30) := 'update_line_intf_tbl';
4006   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
4007   d_position NUMBER;
4008 
4009 BEGIN
4010   d_position := 0;
4011 
4012   IF (PO_LOG.d_proc) THEN
4013     PO_LOG.proc_begin(d_module);
4014   END IF;
4015 
4016   d_position := 10;
4017 
4018   FOR i IN 1..x_lines.rec_count
4019   LOOP
4020     IF (NVL(x_lines.process_code_tbl(i), PO_PDOI_CONSTANTS.g_PROCESS_CODE_PENDING)
4021           = PO_PDOI_CONSTANTS.g_PROCESS_CODE_PENDING AND
4022         NVL(PO_PDOI_PARAMS.g_request.process_code, PO_PDOI_CONSTANTS.g_PROCESS_CODE_PENDING) =
4023           PO_PDOI_CONSTANTS.g_PROCESS_CODE_PENDING)
4024        OR
4025        (NVL(x_lines.process_code_tbl(i), PO_PDOI_CONSTANTS.g_PROCESS_CODE_PENDING)
4026           = PO_PDOI_CONSTANTS.g_PROCESS_CODE_PENDING AND
4027         NVL(PO_PDOI_PARAMS.g_request.process_code, PO_PDOI_CONSTANTS.g_PROCESS_CODE_PENDING) =
4028           PO_PDOI_CONSTANTS.g_PROCESS_CODE_NOTIFIED) THEN
4029 
4030       IF (x_lines.error_flag_tbl(i) = FND_API.g_FALSE AND
4031           x_lines.need_to_reject_flag_tbl(i) = FND_API.g_FALSE) THEN
4032         IF (PO_LOG.d_stmt) THEN
4033           PO_LOG.stmt(d_module, d_position, 'update line process code to ACCEPTED. Index = ', i);
4034         END IF;
4035 
4036         x_lines.process_code_tbl(i) := PO_PDOI_CONSTANTS.g_PROCESS_CODE_ACCEPTED;
4037       END IF;
4038     END IF;
4039   END LOOP;
4040 
4041   d_position := 20;
4042 
4043   FORALL i IN 1.. x_lines.rec_count
4044     UPDATE po_lines_interface
4045     SET    po_line_id = x_lines.po_line_id_tbl(i),
4046 	   po_header_id = x_lines.po_header_id_tbl(i),   --vegajula line for bug 9531925
4047            price_update_tolerance = x_lines.price_update_tolerance_tbl(i),
4048            action = x_lines.action_tbl(i),
4049            price_break_flag = DECODE(x_lines.action_tbl(i), 'UPDATE',
4050                                 DECODE(x_lines.create_line_loc_tbl(i), FND_API.g_TRUE, 'Y', NULL), NULL),
4051            process_code = x_lines.process_code_tbl(i),
4052            parent_interface_line_id = x_lines.parent_interface_line_id_tbl(i), -- bug5149827
4053            --CLM PDOI Integration
4054            clm_base_line_num = x_lines.clm_base_line_num_tbl(i)
4055     WHERE  interface_line_id = x_lines.intf_line_id_tbl(i);
4056     --AND    x_lines.error_flag_tbl(i) = FND_API.g_FALSE
4057     --AND    x_lines.need_to_reject_flag_tbl(i) = FND_API.g_FALSE;
4058 
4059   IF (PO_LOG.d_proc) THEN
4060     PO_LOG.proc_end (d_module);
4061   END IF;
4062 
4063 EXCEPTION
4064   WHEN OTHERS THEN
4065     PO_MESSAGE_S.add_exc_msg
4066     (
4067       p_pkg_name => d_pkg_name,
4068       p_procedure_name => d_api_name || '.' || d_position
4069     );
4070     RAISE;
4071 END update_line_intf_tbl;
4072 
4073 -----------------------------------------------------------------------
4074 --Start of Comments
4075 --Name: uniqueness_check
4076 --Function: If document level action is 'UPDATE' on Blanket and Quotation,
4077 --          uniqueness check needs to be performed on each line to
4078 --          determine the line level action if it is not specified as
4079 --          'ADD' by the customer.
4080 --Parameters:
4081 --IN:
4082 --  p_type
4083 --    flag to determine on which attributes the check will be performed
4084 --  p_group_num
4085 --    current group number in the batch
4086 --IN OUT:
4087 --  x_processing_row_tbl
4088 --    table to indicate whether action has been determined for each row
4089 --    within the batch
4090 --  x_lines
4091 --    record which stores all the line rows within the batch
4092 --  x_expire_line_id_tbl
4093 --    table to store list of lines that are going to be expired
4094 --OUT:
4095 --End of Comments
4096 ------------------------------------------------------------------------
4097 PROCEDURE uniqueness_check
4098 (
4099   p_type                  IN NUMBER,
4100   p_group_num             IN NUMBER,
4101   x_processing_row_tbl    IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
4102   x_lines                 IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type,
4103   x_expire_line_id_tbl    OUT NOCOPY DBMS_SQL.NUMBER_TABLE
4104 ) IS
4105 
4106   d_api_name CONSTANT VARCHAR2(30) := 'uniqueness_check';
4107   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
4108   d_position NUMBER;
4109 
4110   -- key of temp table used to identify the records
4111   l_key                   po_session_gt.key%TYPE;
4112 
4113   -- table storing the index of records within the batch
4114   l_index_tbl             DBMS_SQL.NUMBER_TABLE;
4115   l_index                 NUMBER;
4116 
4117   -- store the index of lines that need to be expired
4118   l_expire_line_index_tbl PO_TBL_NUMBER;
4119 
4120   -- counter
4121   l_count                 NUMBER := 0;
4122 BEGIN
4123   d_position := 0;
4124 
4125   IF (PO_LOG.d_proc) THEN
4126     PO_LOG.proc_begin(d_module, 'p_type', p_type);
4127     PO_LOG.proc_begin(d_module, 'p_group_num', p_group_num);
4128 
4129     l_index := x_processing_row_tbl.FIRST;
4130     WHILE (l_index IS NOT NULL)
4131     LOOP
4132       PO_LOG.proc_begin(d_module, 'to be processed index', l_index);
4133       l_index := x_processing_row_tbl.NEXT(l_index);
4134     END LOOP;
4135   END IF;
4136 
4137   PO_TIMING_UTL.start_time(PO_PDOI_CONSTANTS.g_T_LINE_UNIQUENESS_CHECK);
4138 
4139   -- get key value for po_session_gt table
4140   l_key := PO_CORE_S.get_session_gt_nextval;
4141 
4142   -- call individual uniqueness check procedure for each unique criteria
4143   IF (p_type = PO_PDOI_CONSTANTS.g_LINE_CSR_SYNC_ON_DESC) THEN
4144     d_position := 10;
4145 
4146     uniqueness_check_on_desc
4147     (
4148       p_key                 => l_key,
4149       p_group_num           => p_group_num,
4150       x_processing_row_tbl  => x_processing_row_tbl,
4151       x_lines               => x_lines
4152     );
4153   ELSE
4154     d_position := 20;
4155 
4156     -- uniqueness check on item + revision + vendor_product_num +
4157     -- supplier_part_auxid if item is not null
4158     uniqueness_check_on_item
4159     (
4160       p_key                 => l_key,
4161       p_group_num           => p_group_num,
4162       x_processing_row_tbl  => x_processing_row_tbl,
4163       x_lines               => x_lines
4164     );
4165 
4166     d_position := 30;
4167 
4168     -- uniquess check on vendor_product_num + supplier_part_auxid if item
4169     -- is null but vendor_product_num is not null
4170     uniqueness_check_on_vpn
4171     (
4172       p_key                 => l_key,
4173       p_group_num           => p_group_num,
4174       x_processing_row_tbl  => x_processing_row_tbl,
4175       x_lines               => x_lines
4176     );
4177 
4178     d_position := 40;
4179 
4180     -- uniquess check on job_name if both item and vendor_product_num are null
4181     uniqueness_check_on_job
4182     (
4183       p_key                 => l_key,
4184       p_group_num           => p_group_num,
4185       x_processing_row_tbl  => x_processing_row_tbl,
4186       x_lines               => x_lines
4187     );
4188 
4189     d_position := 50;
4190 
4191     -- uniquess check on line_num if item, vendor_product_num and job_name
4192     -- are all null
4193     uniqueness_check_on_line_num
4194     (
4195       p_key                 => l_key,
4196       p_group_num           => p_group_num,
4197       x_processing_row_tbl  => x_processing_row_tbl,
4198       x_lines               => x_lines
4199     );
4200 
4201     -- set action to ADD for lines that does not have any
4202     -- matching attributes specified
4203     FOR i IN 1..x_lines.rec_count
4204     LOOP
4205       d_position := 60;
4206 
4207       IF (x_lines.item_tbl(i) IS NULL AND
4208           x_lines.vendor_product_num_tbl(i) IS NULL AND
4209       x_lines.job_name_tbl(i) IS NULL AND
4210           x_lines.line_num_tbl(i) IS NULL) THEN
4211 
4212         x_lines.action_tbl(i) := PO_PDOI_CONSTANTS.g_ACTION_ADD;
4213         x_lines.group_num_tbl(i) := p_group_num;
4214         x_lines.po_line_id_tbl(i) := PO_PDOI_MAINPROC_UTL_PVT.get_next_po_line_id;
4215         x_lines.line_num_tbl(i) :=
4216           PO_PDOI_MAINPROC_UTL_PVT.get_next_line_num
4217           (
4218             p_po_header_id  => x_lines.hd_po_header_id_tbl(i)
4219           );
4220         x_processing_row_tbl.DELETE(i);
4221 
4222         IF (PO_LOG.d_stmt) THEN
4223           PO_LOG.stmt(d_module, d_position, 'set action to ADD '||
4224                       'since all uniqueness criteria are empty');
4225           PO_LOG.stmt(d_module, d_position, 'index', i);
4226           PO_LOG.stmt(d_module, d_position, 'new po line id',
4227                       x_lines.po_line_id_tbl(i));
4228           PO_LOG.stmt(d_module, d_position, 'new line num',
4229                       x_lines.line_num_tbl(i));
4230         END IF;
4231       END IF;
4232     END LOOP;
4233   END IF;
4234 
4235   d_position := 70;
4236 
4237   -- If there is release shipment for a blanket line, and uom is changed,
4238   -- the existing matching line will be expired and the new line's action
4239   --  will be ADD instead of UPDATE
4240   IF (PO_PDOI_PARAMS.g_request.document_type =
4241       PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET) THEN
4242     d_position := 80;
4243 
4244     -- derive unit_of_measure from uom_code
4245     PO_PDOI_UTL.generate_ordered_num_list
4246     (
4247       p_size     => x_lines.rec_count,
4248       x_num_list => l_index_tbl
4249     );
4250 
4251     derive_unit_of_measure
4252     (
4253       p_key                  => l_key,
4254       p_index_tbl            => l_index_tbl,
4255       p_uom_code_tbl         => x_lines.uom_code_tbl,
4256       x_unit_of_measure_tbl  => x_lines.unit_of_measure_tbl
4257     );
4258 
4259     d_position := 90;
4260 
4261     -- check whether uom changed for a line that has a release shipment
4262     FORALL i IN 1..x_lines.rec_count
4263       INSERT INTO po_session_gt(key, num1)
4264       SELECT l_key,
4265              l_index_tbl(i)
4266       FROM   po_lines txn_lines
4267       WHERE  txn_lines.po_line_id = x_lines.po_line_id_tbl(i)
4268       AND    x_lines.unit_of_measure_tbl(i) IS NOT NULL
4269       AND    txn_lines.unit_meas_lookup_code IS NOT NULL
4270       AND    txn_lines.unit_meas_lookup_code <>
4271              x_lines.unit_of_measure_tbl(i)
4272       AND    (EXISTS (SELECT 1
4273                       FROM   po_line_locations
4274                       WHERE  po_line_id = txn_lines.po_line_id
4275                       AND    shipment_type = 'BLANKET')
4276               OR
4277               EXISTS (SELECT 1
4278                       FROM   po_lines_all
4279                       WHERE  from_line_id = txn_lines.po_line_id)
4280              );
4281 
4282     DELETE FROM po_session_gt
4283     WHERE key = l_key
4284     RETURNING num1 BULK COLLECT INTO l_expire_line_index_tbl;
4285 
4286     FOR i IN 1..l_expire_line_index_tbl.COUNT
4287     LOOP
4288       l_index := l_expire_line_index_tbl(i);
4289 
4290       IF (PO_LOG.d_stmt) THEN
4291         PO_LOG.stmt(d_module, d_position, 'expire index', i);
4292         PO_LOG.stmt(d_module, d_position, 'expired line id',
4293                     x_lines.po_line_id_tbl(l_index));
4294       END IF;
4295 
4296       x_lines.action_tbl(l_index) := PO_PDOI_CONSTANTS.g_ACTION_ADD;
4297       l_count := l_count + 1;
4298       x_expire_line_id_tbl(l_count) := x_lines.po_line_id_tbl(l_index);
4299       x_lines.po_line_id_tbl(l_index) :=
4300         PO_PDOI_MAINPROC_UTL_PVT.get_next_po_line_id;
4301       IF (x_lines.origin_line_num_tbl(l_index) IS NULL OR
4302           x_lines.line_num_unique_tbl(l_index) = FND_API.g_FALSE) THEN
4303         x_lines.line_num_tbl(l_index) :=
4304           PO_PDOI_MAINPROC_UTL_PVT.get_next_line_num
4305           (
4306             p_po_header_id => x_lines.hd_po_header_id_tbl(i)
4307           );
4308 
4309         IF (PO_LOG.d_stmt) THEN
4310           PO_LOG.stmt(d_module, d_position, 'original line num',
4311                       x_lines.origin_line_num_tbl(l_index));
4312           PO_LOG.stmt(d_module, d_position, 'if line num unique',
4313                       x_lines.line_num_unique_tbl(l_index));
4314           PO_LOG.stmt(d_module, d_position, 'new line num',
4315                       x_lines.line_num_tbl(l_index));
4316         END IF;
4317       END IF;
4318     END LOOP;
4319   END IF;
4320 
4321   PO_TIMING_UTL.stop_time(PO_PDOI_CONSTANTS.g_T_LINE_UNIQUENESS_CHECK);
4322 
4323   IF (PO_LOG.d_proc) THEN
4324     PO_LOG.proc_end (d_module);
4325   END IF;
4326 
4327 EXCEPTION
4328   WHEN OTHERS THEN
4329     PO_MESSAGE_S.add_exc_msg
4330     (
4331       p_pkg_name => d_pkg_name,
4332       p_procedure_name => d_api_name || '.' || d_position
4333     );
4334     RAISE;
4335 END uniqueness_check;
4336 
4337 -----------------------------------------------------------------------
4338 --Start of Comments
4339 --Name: split_lines
4340 --Function: separate the lines within a group depending on action
4341 --Parameters:
4342 --IN:
4343 --  p_group_num
4344 --    current group number
4345 --  p_lines
4346 --    record containing all line info within the batch
4347 --IN OUT:
4348 --  x_create_lines
4349 --    record containging lines that are going to be created
4350 --  x_update_lines
4351 --    record containing lines that are going to be updated
4352 --OUT:
4353 --End of Comments
4354 ------------------------------------------------------------------------
4355 PROCEDURE split_lines
4356 (
4357   p_group_num             IN NUMBER,
4358   p_lines                 IN PO_PDOI_TYPES.lines_rec_type,
4359   x_create_lines          IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type,
4360   x_update_lines          IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
4361 ) IS
4362 
4363   d_api_name CONSTANT VARCHAR2(30) := 'split_lines';
4364   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
4365   d_position NUMBER;
4366 
4367   -- store index of rows to be copied to different records
4368   l_create_index_tbl   DBMS_SQL.NUMBER_TABLE;
4369   l_update_index_tbl   DBMS_SQL.NUMBER_TABLE;
4370 BEGIN
4371   d_position := 0;
4372 
4373   IF (PO_LOG.d_proc) THEN
4374     PO_LOG.proc_begin(d_module, 'p_group_num', p_group_num);
4375     PO_LOG.proc_begin(d_module, 'group_num_tbl', p_lines.group_num_tbl);
4376     PO_LOG.proc_begin(d_module, 'action_tbl', p_lines.action_tbl);
4377   END IF;
4378 
4379   FOR i IN 1..p_lines.rec_count
4380   LOOP
4381     d_position := 10;
4382 
4383     IF (p_group_num IS NULL OR p_lines.group_num_tbl(i) = p_group_num) THEN
4384       IF (p_lines.action_tbl(i) = PO_PDOI_CONSTANTS.g_ACTION_ADD) THEN
4385         IF (PO_LOG.d_stmt) THEN
4386           PO_LOG.stmt(d_module, d_position, 'lines to create', i);
4387         END IF;
4388 
4389         l_create_index_tbl(i) := i;
4390       ELSIF (p_lines.action_tbl(i) = PO_PDOI_CONSTANTS.g_ACTION_UPDATE) THEN
4391         IF (PO_LOG.d_stmt) THEN
4392           PO_LOG.stmt(d_module, d_position, 'lines to update', i);
4393         END IF;
4394 
4395         l_update_index_tbl(i) := i;
4396       END IF;
4397     END IF;
4398   END LOOP;
4399 
4400   d_position := 20;
4401 
4402   -- copy rows to insert record
4403   copy_lines
4404   (
4405     p_source_lines     => p_lines,
4406     p_source_index_tbl => l_create_index_tbl,
4407     x_target_lines     => x_create_lines
4408   );
4409 
4410   d_position := 30;
4411 
4412   -- copy rows to update record
4413   copy_lines
4414   (
4415     p_source_lines     => p_lines,
4416     p_source_index_tbl => l_update_index_tbl,
4417     x_target_lines     => x_update_lines
4418   );
4419 
4420   IF (PO_LOG.d_proc) THEN
4421     PO_LOG.proc_end(d_module);
4422   END IF;
4423 
4424 EXCEPTION
4425   WHEN OTHERS THEN
4426     PO_MESSAGE_S.add_exc_msg
4427     (
4428       p_pkg_name => d_pkg_name,
4429       p_procedure_name => d_api_name || '.' || d_position
4430     );
4431     RAISE;
4432 END split_lines;
4433 
4434 -----------------------------------------------------------------------
4435 --Start of Comments
4436 --Name: validate_lines
4437 --Function: validate line attributes; the validation of attribute values
4438 --          tlp table will be called here as well in order to track the
4439 --          number of error lines.
4440 --Parameters:
4441 --IN:
4442 --  p_action
4443 --    indicate whether the po lines are going to be created or updated;
4444 --    the values can be 'CREATE' or 'UPDATE'
4445 --IN OUT:
4446 --  x_lines
4447 --    record which stores all the line rows within the batch;
4448 --    If there is error(s) on any attribute of the location row,
4449 --    corresponding value in error_flag_tbl will be set with value
4450 --    FND_API.g_TRUE.
4451 --OUT:
4452 --End of Comments
4453 ------------------------------------------------------------------------
4454 PROCEDURE validate_lines
4455 (
4456   p_action      IN VARCHAR2 DEFAULT 'CREATE',
4457   x_lines       IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
4458 ) IS
4459 
4460   d_api_name CONSTANT VARCHAR2(30) := 'validate_lines';
4461   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
4462   d_position NUMBER;
4463 
4464   l_lines                 PO_LINES_VAL_TYPE := PO_LINES_VAL_TYPE();
4465   l_result_type           VARCHAR2(30);
4466   l_results               po_validation_results_type;
4467   l_parameter_name_tbl    PO_TBL_VARCHAR2000 := PO_TBL_VARCHAR2000();
4468   l_parameter_value_tbl   PO_TBL_VARCHAR2000 := PO_TBL_VARCHAR2000();
4469   l_inventory_org_id_tbl  PO_TBL_NUMBER := PO_TBL_NUMBER();
4470 
4471 BEGIN
4472   d_position := 0;
4473 
4474   IF (PO_LOG.d_proc) THEN
4475     PO_LOG.proc_begin(d_module, 'action', p_action);
4476   END IF;
4477 
4478   PO_TIMING_UTL.start_time(PO_PDOI_CONSTANTS.g_T_LINE_VALIDATE);
4479 
4480   l_lines.interface_id                    := x_lines.intf_line_id_tbl;
4481   l_lines.over_tolerance_error_flag       := x_lines.over_tolerance_err_flag_tbl;
4482   l_lines.expiration_date                 := x_lines.expiration_date_tbl;
4483   l_lines.hdr_start_date                  := x_lines.hd_start_date_tbl;
4484   l_lines.hdr_end_date                    := x_lines.hd_end_date_tbl;
4485   l_lines.global_agreement_flag           := x_lines.hd_global_agreement_flag_tbl;
4486   l_lines.purchase_basis                  := x_lines.purchase_basis_tbl;
4487   l_lines.line_type_id                    := x_lines.line_type_id_tbl;
4488   l_lines.amount                          := x_lines.amount_tbl;
4489   l_lines.contractor_last_name            := x_lines.contractor_last_name_tbl;
4490   l_lines.contractor_first_name           := x_lines.contractor_first_name_tbl;
4491   l_lines.job_id                          := x_lines.job_id_tbl;
4492   l_lines.job_business_group_id           := x_lines.job_business_group_id_tbl;
4493   l_lines.capital_expense_flag            := x_lines.capital_expense_flag_tbl;
4494   l_lines.un_number_id                    := x_lines.un_number_id_tbl;
4495   l_lines.hazard_class_id                 := x_lines.hazard_class_id_tbl;
4496   l_lines.item_id                         := x_lines.item_id_tbl;
4497   l_lines.order_type_lookup_code          := x_lines.order_type_lookup_code_tbl;
4498   l_lines.item_description                := x_lines.item_desc_tbl;
4499   l_lines.unit_meas_lookup_code           := x_lines.unit_of_measure_tbl;
4500   l_lines.item_revision                   := x_lines.item_revision_tbl;
4501   l_lines.category_id                     := x_lines.category_id_tbl;
4502   l_lines.ip_category_id                  := x_lines.ip_category_id_tbl;
4503   l_lines.unit_price                      := x_lines.unit_price_tbl;
4504   l_lines.quantity                        := x_lines.quantity_tbl;
4505   l_lines.po_header_id                    := x_lines.po_header_id_tbl;
4506   l_lines.po_line_id                      := x_lines.po_line_id_tbl;
4507   l_lines.line_num                        := x_lines.line_num_tbl;
4508   l_lines.price_type_lookup_code          := x_lines.price_type_tbl;
4509   l_lines.start_date                      := x_lines.effective_date_tbl;
4510   l_lines.expiration_date                 := x_lines.expiration_date_tbl;
4511   l_lines.not_to_exceed_price             := x_lines.not_to_exceed_price_tbl;
4512   l_lines.release_num                     := x_lines.release_num_tbl;
4513   l_lines.po_release_id                   := x_lines.po_release_id_tbl;
4514   l_lines.source_shipment_id              := x_lines.source_shipment_id_tbl;
4515   l_lines.contract_num                    := x_lines.contract_num_tbl;
4516   l_lines.contract_id                     := x_lines.contract_id_tbl;
4517   l_lines.type_1099                       := x_lines.type_1099_tbl;
4518   l_lines.closed_code                     := x_lines.closed_code_tbl;
4519   l_lines.closed_date                     := x_lines.closed_date_tbl;
4520   l_lines.closed_by                       := x_lines.closed_by_tbl;
4521   l_lines.market_price                    := x_lines.market_price_tbl;
4522   l_lines.committed_amount                := x_lines.committed_amount_tbl;
4523   l_lines.shipment_num                    := x_lines.shipment_num_tbl;
4524   l_lines.capital_expense_flag            := x_lines.capital_expense_flag_tbl;
4525   l_lines.min_release_amount              := x_lines.min_release_amount_tbl;
4526   l_lines.allow_price_override_flag       := x_lines.allow_price_override_flag_tbl;
4527   l_lines.negotiated_by_preparer_flag     := x_lines.negotiated_flag_tbl;
4528   l_lines.secondary_unit_of_measure       := x_lines.secondary_unit_of_meas_tbl;
4529   l_lines.secondary_quantity              := x_lines.secondary_quantity_tbl;
4530   l_lines.preferred_grade                 := x_lines.preferred_grade_tbl;
4531   l_lines.item                            := x_lines.item_tbl;
4532   l_lines.hdr_style_id                    := x_lines.hd_style_id_tbl;
4533   l_lines.price_break_lookup_code         := x_lines.price_break_lookup_code_tbl; -- bug5016163
4534   l_lines.draft_id                        := x_lines.draft_id_tbl; -- bug5258790
4535   l_lines.hdr_rate_type                   := x_lines.hd_rate_type_tbl; -- bug 5451908
4536   l_lines.clm_info_flag := x_lines.clm_info_flag_tbl;          /* 10354034 */
4537   -- << PDOI for Complex PO Project: Start >>
4538   l_lines.retainage_rate                  := x_lines.retainage_rate_tbl;
4539   l_lines.max_retainage_amount            := x_lines.max_retainage_amount_tbl;
4540   l_lines.progress_payment_rate           := x_lines.progress_payment_rate_tbl;
4541   l_lines.recoupment_rate                 := x_lines.recoupment_rate_tbl;
4542   l_lines.advance_amount                  := x_lines.advance_amount_tbl;
4543   -- << PDOI for Complex PO Project: End >>
4544   --CLM PDOI Integration Project Starts
4545   l_lines.interface_header_id             := x_lines.intf_header_id_tbl;
4546   l_lines.contract_type                   := x_lines.contract_type_tbl;
4547   l_lines.cost_constraint                 := x_lines.cost_constraint_tbl;
4548   l_lines.clm_option_indicator            := x_lines.clm_option_indicator_tbl;
4549   l_lines.clm_base_line_num               := x_lines.clm_base_line_num_tbl;
4550   l_lines.clm_option_num                  := x_lines.clm_option_num_tbl;
4551   l_lines.clm_idc_type                    := x_lines.clm_idc_type_tbl;
4552   l_lines.group_line_id                   := x_lines.group_line_id_tbl;
4553   l_lines.line_num_display                := x_lines.line_num_display_tbl;
4554   l_lines.clm_option_from_date            := x_lines.clm_option_from_date_tbl;
4555   l_lines.clm_option_to_date              := x_lines.clm_option_to_date_tbl;
4556   l_lines.clm_exercised_date              := x_lines.clm_exercised_date_tbl;
4557   l_lines.clm_exercised_flag              := x_lines.clm_exercised_flag_tbl;
4558   l_lines.from_header_id                  := x_lines.from_header_id_tbl;
4559   --CLM PDOI Integration Project Ends
4560   d_position := 10;
4561 
4562   l_inventory_org_id_tbl.EXTEND(x_lines.intf_line_id_tbl.COUNT);
4563 
4564   FOR i IN 1..x_lines.intf_line_id_tbl.COUNT LOOP
4565      l_inventory_org_id_tbl(i) := PO_PDOI_PARAMS.g_sys.master_inv_org_id;
4566   END LOOP;
4567   l_lines.inventory_org_id   := l_inventory_org_id_tbl;
4568 
4569   d_position := 20;
4570 
4571   l_parameter_name_tbl.EXTEND(3);
4572   l_parameter_value_tbl.EXTEND(3);
4573   l_parameter_name_tbl(1)                 := 'CREATE_OR_UPDATE_ITEM';
4574   l_parameter_value_tbl(1)                := PO_PDOI_PARAMS.g_request.create_items;
4575   l_parameter_name_tbl(2)                 := 'INVENTORY_ORG_ID';
4576   l_parameter_value_tbl(2)                := PO_PDOI_PARAMS.g_sys.def_inv_org_id; -- bug5601416
4577   l_parameter_name_tbl(3)                 := 'DOC_TYPE';
4578   l_parameter_value_tbl(3)                := PO_PDOI_PARAMS.g_request.document_type;
4579 
4580   d_position := 30;
4581 
4582   PO_VALIDATIONS.validate_pdoi
4583   (
4584     p_lines                => l_lines,
4585     p_doc_type             => PO_PDOI_PARAMS.g_request.document_type,
4586     p_action               => p_action,
4587     p_parameter_name_tbl   => l_parameter_name_tbl,
4588     p_parameter_value_tbl  => l_parameter_value_tbl,
4589     x_result_type          => l_result_type,
4590     x_results              => l_results
4591   );
4592 
4593   d_position := 40;
4594 
4595   IF (l_result_type = po_validations.c_result_type_failure) THEN
4596     IF (PO_LOG.d_stmt) THEN
4597       PO_LOG.stmt(d_module, d_position, 'vaidate lines return failure');
4598     END IF;
4599 
4600     PO_PDOI_ERR_UTL.process_val_type_errors
4601     (
4602       x_results    => l_results,
4603       p_table_name => 'PO_LINES_INTERFACE',
4604       p_lines      => x_lines
4605     );
4606 
4607     d_position := 50;
4608 
4609     populate_error_flag
4610     (
4611       x_results  => l_results,
4612       x_lines    => x_lines
4613     );
4614   END IF;
4615 
4616   d_position := 60;
4617 
4618   IF l_result_type = po_validations.c_result_type_fatal THEN
4619     IF (PO_LOG.d_stmt) THEN
4620       PO_LOG.stmt(d_module, d_position, 'vaidate lines return fatal');
4621     END IF;
4622 
4623     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4624   END IF;
4625 
4626   d_position := 70;
4627 
4628   -- validate tlp table in advance for tracking of num of error lines.
4629   IF (p_action = 'CREATE') THEN
4630     IF (PO_LOG.d_stmt) THEN
4631       PO_LOG.stmt(d_module, d_position, 'start to validate attribute tlp table');
4632     END IF;
4633 
4634     d_position := 80;
4635 
4636     validate_attr_tlp
4637     (
4638       x_lines => x_lines
4639     );
4640   END IF;
4641 
4642   d_position := 90;
4643 
4644   handle_err_tolerance
4645   (
4646     x_lines => x_lines
4647   );
4648 
4649   d_position := 100;
4650 
4651   PO_TIMING_UTL.stop_time(PO_PDOI_CONSTANTS.g_T_LINE_VALIDATE);
4652 
4653   IF (PO_LOG.d_proc) THEN
4654     PO_LOG.proc_end(d_module, 'result_type', l_result_type);
4655   END IF;
4656 
4657 EXCEPTION
4658   WHEN OTHERS THEN
4659     PO_MESSAGE_S.add_exc_msg
4660     (
4661       p_pkg_name => d_pkg_name,
4662       p_procedure_name => d_api_name || '.' || d_position
4663     );
4664     RAISE;
4665 END validate_lines;
4666 
4667 ------------------------------------------------------------------------
4668 -------------------- PRIVATE PROCEDURES --------------------------------
4669 ------------------------------------------------------------------------
4670 
4671 -- bug5684695
4672 -- removed the content for procedure derive_po_header_id
4673 
4674 -----------------------------------------------------------------------
4675 --Start of Comments
4676 --Name: derive_item_id
4677 --Function: derive item_id from item or vendor_product_num
4678 --Parameters:
4679 --IN:
4680 --  p_key
4681 --    key used to identify rows in po_session_gt
4682 --  p_index_tbl
4683 --    table containging the indexes of all rows
4684 --  p_vendor_id_tbl
4685 --    list of vendor_ids read from the header
4686 --  p_intf_header_id_tbl
4687 --    identifiers of interface headers
4688 --  p_intf_line_id_tbl
4689 --    identifiers of interface lines
4690 --  p_vendor_product_num_tbl
4691 --    list of vendor_product_nums read within the batch
4692 --  p_category_id_tbl
4693 --    list of category_ids read within the batch
4694 --  p_item_tbl
4695 --    list of items read within the batch
4696 --IN OUT:
4697 --  x_item_id_tbl
4698 --    list of item_ids read within the batch;
4699 --    derived result will be saved here as well;
4700 --  x_error_flag_tbl
4701 --    table to mark whether there is error on each row
4702 --OUT:
4703 --End of Comments
4704 ------------------------------------------------------------------------
4705 PROCEDURE derive_item_id
4706 (
4707   p_key                    IN po_session_gt.key%TYPE,
4708   p_index_tbl              IN DBMS_SQL.NUMBER_TABLE,
4709   p_vendor_id_tbl          IN PO_TBL_NUMBER,
4710   p_intf_header_id_tbl     IN PO_TBL_NUMBER,
4711   p_intf_line_id_tbl       IN PO_TBL_NUMBER,
4712   p_vendor_product_num_tbl IN PO_TBL_VARCHAR30,
4713   p_category_id_tbl        IN PO_TBL_NUMBER,            --bug 7374337
4714   p_item_tbl               IN PO_TBL_VARCHAR2000,
4715   x_item_id_tbl            IN OUT NOCOPY PO_TBL_NUMBER,
4716   x_error_flag_tbl         IN OUT NOCOPY PO_TBL_VARCHAR1
4717 ) IS
4718 
4719   d_api_name CONSTANT VARCHAR2(30) := 'derive_item_id';
4720   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
4721   d_position NUMBER;
4722 
4723   -- tables to store the derived result
4724   l_index_tbl        PO_TBL_NUMBER;
4725   l_result_tbl       PO_TBL_NUMBER;
4726 
4727   -- variable to hold index of the current processing row
4728   l_index            NUMBER;
4729 
4730   -- variables to indicate whether multiple_buyer_part error is already inserted
4731   l_error_exist_tbl  DBMS_SQL.NUMBER_TABLE;
4732 BEGIN
4733   d_position := 0;
4734 
4735   IF (PO_LOG.d_proc) THEN
4736     PO_LOG.proc_begin(d_module, 'p_vendor_id_tbl', p_vendor_id_tbl);
4737     PO_LOG.proc_begin(d_module, 'p_intf_header_id_tbl', p_intf_header_id_tbl);
4738     PO_LOG.proc_begin(d_module, 'p_intf_line_id_tbl', p_intf_line_id_tbl);
4739     PO_LOG.proc_begin(d_module, 'p_vendor_product_num_tbl', p_vendor_product_num_tbl);
4740     PO_LOG.proc_begin(d_module, 'p_category_id_tbl', p_category_id_tbl);
4741     PO_LOG.proc_begin(d_module, 'p_item_tbl', p_item_tbl);
4742     PO_LOG.proc_begin(d_module, 'x_item_id_tbl', x_item_id_tbl);
4743     PO_LOG.proc_begin(d_module, 'x_error_flag_tbl', x_error_flag_tbl);
4744   END IF;
4745 
4746   -- derive based on item_num
4747   FORALL i IN 1..p_index_tbl.COUNT
4748     INSERT INTO po_session_gt(key, num1, num2)
4749     SELECT p_key,
4750            p_index_tbl(i),
4751            inventory_item_id
4752     FROM   mtl_system_items_kfv
4753     WHERE  p_item_tbl(i) IS NOT NULL
4754     AND    x_item_id_tbl(i) IS NULL
4755     AND    concatenated_segments = p_item_tbl(i)
4756     AND    organization_id = PO_PDOI_PARAMS.g_sys.def_inv_org_id;
4757 
4758   d_position := 10;
4759 
4760   -- derive based on vendor_product_num
4761   -- bug 7374337 Added an AND condidtion in the below
4762   -- sql so that matched category for the vendor product number
4763   -- item id will be derived.
4764 
4765   FORALL i IN 1.. p_index_tbl.COUNT
4766     INSERT INTO po_session_gt(key, num1, num2)
4767     SELECT DISTINCT
4768            p_key,
4769            p_index_tbl(i),
4770            txn_lines.item_id
4771     FROM   po_headers txn_headers, po_lines txn_lines
4772     WHERE  txn_headers.po_header_id = txn_lines.po_header_id
4773     AND    p_item_tbl(i) IS NULL
4774     AND    x_item_id_tbl(i) IS NULL
4775     AND    p_vendor_product_num_tbl(i) IS NOT NULL
4776     AND    txn_lines.vendor_product_num = p_vendor_product_num_tbl(i)
4777     AND    txn_headers.vendor_id = p_vendor_id_tbl(i)
4778     AND    txn_lines.item_id IS NOT NULL
4779     AND    ( (p_category_id_tbl(i) IS NOT NULL                   --bug 7374337 <S>
4780             AND txn_lines.category_id = p_category_id_tbl(i))
4781             OR (p_category_id_tbl(i) IS NULL )                   --bug 7374337 <E>
4782            );
4783 
4784   d_position := 20;
4785 
4786   -- read result from temp table, and delete the records from temp table
4787   DELETE FROM po_session_gt
4788   WHERE  key = p_key
4789   RETURNING num1, num2 BULK COLLECT INTO l_index_tbl, l_result_tbl;
4790 
4791   d_position := 30;
4792 
4793   -- push the result back to x_item_ids
4794   FOR i IN 1..l_index_tbl.COUNT
4795   LOOP
4796     l_index := l_index_tbl(i);
4797 
4798     IF (PO_LOG.d_stmt) THEN
4799       PO_LOG.stmt(d_module, d_position, 'index', l_index);
4800       PO_LOG.stmt(d_module, d_position, 'result item id',
4801                   l_result_tbl(i));
4802     END IF;
4803 
4804     IF (NOT l_error_exist_tbl.EXISTS(l_index)) THEN
4805       IF (x_item_id_tbl(l_index) IS NULL) THEN
4806         x_item_id_tbl(l_index) := l_result_tbl(i);
4807       ELSE
4808         x_item_id_tbl(l_index) := NULL;
4809         x_error_flag_tbl(l_index) := FND_API.G_TRUE;
4810         l_error_exist_tbl(l_index) := l_index;
4811         -- insert error
4812         PO_PDOI_ERR_UTL.add_fatal_error
4813         (
4814           p_interface_header_id  => p_intf_header_id_tbl(l_index),
4815           p_interface_line_id    => p_intf_line_id_tbl(l_index),
4816           p_error_message_name   => 'PO_PDOI_MULT_BUYER_PART',
4817           p_table_name           => 'PO_LINES_INTERFACE',
4818           p_column_name          => 'VENDOR_PRODUCT_NUM',
4819           p_column_value         => p_vendor_product_num_tbl(l_index),
4820           p_token2_name          => 'VALUE',
4821           p_token2_value         => p_vendor_product_num_tbl(l_index)
4822         );
4823       END IF;
4824     END IF;
4825   END LOOP;
4826 
4827   IF (PO_LOG.d_proc) THEN
4828     PO_LOG.proc_end(d_module);
4829   END IF;
4830 
4831 EXCEPTION
4832   WHEN OTHERS THEN
4833     PO_MESSAGE_S.add_exc_msg
4834     (
4835       p_pkg_name => d_pkg_name,
4836       p_procedure_name => d_api_name || '.' || d_position
4837     );
4838     RAISE;
4839 END derive_item_id;
4840 
4841 -----------------------------------------------------------------------
4842 --Start of Comments
4843 --Name: derive_item_revision
4844 --Function: reset item_revision based on item_id
4845 --          and create_item parameter value
4846 --Parameters:
4847 --IN:
4848 --  p_key
4849 --    key used to identify rows in po_session_gt
4850 --  p_item_id_tbl
4851 --    list of item_ids read within the batch
4852 --IN OUT:
4853 --  x_item_revision_tbl
4854 --    list of item_revisions read within the batch;
4855 --    derived result will be saved here as well;
4856 --OUT:
4857 --End of Comments
4858 ------------------------------------------------------------------------
4859 PROCEDURE derive_item_revision
4860 (
4861   p_key                    IN po_session_gt.key%TYPE,
4862   p_item_id_tbl            IN PO_TBL_NUMBER,
4863   x_item_revision_tbl      IN OUT NOCOPY PO_TBL_VARCHAR5
4864 ) IS
4865 
4866   d_api_name CONSTANT VARCHAR2(30) := 'derive_item_revision';
4867   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
4868   d_position NUMBER;
4869 
4870 BEGIN
4871   d_position := 0;
4872 
4873   IF (PO_LOG.d_proc) THEN
4874     PO_LOG.proc_begin(d_module, 'p_item_id_tbl', p_item_id_tbl);
4875     PO_LOG.proc_begin(d_module, 'x_item_revision_tbl', x_item_revision_tbl);
4876   END IF;
4877 
4878   FOR i IN 1..p_item_id_tbl.COUNT
4879   LOOP
4880     IF (p_item_id_tbl(i) IS NULL AND
4881         X_item_revision_tbl(i) IS NOT NULL AND
4882         PO_PDOI_PARAMS.g_request.create_items = 'Y') THEN
4883       IF (PO_LOG.d_stmt) THEN
4884         PO_LOG.stmt(d_module, d_position, 'index', i);
4885         PO_LOG.stmt(d_module, d_position, 'new item revision set to empty');
4886       END IF;
4887 
4888       x_item_revision_tbl(i) := NULL;
4889     END IF;
4890   END LOOP;
4891 
4892   IF (PO_LOG.d_proc) THEN
4893     PO_LOG.proc_end(d_module);
4894   END IF;
4895 
4896 EXCEPTION
4897   WHEN OTHERS THEN
4898     PO_MESSAGE_S.add_exc_msg
4899     (
4900       p_pkg_name => d_pkg_name,
4901       p_procedure_name => d_api_name || '.' || d_position
4902     );
4903     RAISE;
4904 END derive_item_revision;
4905 
4906 -----------------------------------------------------------------------
4907 --Start of Comments
4908 --Name: derive_job_business_group_id
4909 --Function: derive job_business_group_id from
4910 --          job_business_group_name
4911 --Parameters:
4912 --IN:
4913 --  p_key
4914 --    key used to identify rows in po_session_gt
4915 --  p_index_tbl
4916 --    table containging the indexes of all rows
4917 --  p_job_business_group_name_tbl
4918 --    list of job_business_group_names read within the batch
4919 --IN OUT:
4920 --  x_job_business_group_id_tbl
4921 --    list of job_business_group_ids read within the batch;
4922 --    derived result will be saved here as well;
4923 --    derivation will only occur when job_business_group_name
4924 --    is provided but job_business_group_id is not;
4925 --OUT:
4926 --End of Comments
4927 ------------------------------------------------------------------------
4928 PROCEDURE derive_job_business_group_id
4929 (
4930   p_key                            IN po_session_gt.key%TYPE,
4931   p_index_tbl                      IN DBMS_SQL.NUMBER_TABLE,
4932   p_job_business_group_name_tbl    IN PO_TBL_VARCHAR2000,
4933   x_job_business_group_id_tbl      IN OUT NOCOPY PO_TBL_NUMBER
4934 ) IS
4935 
4936   d_api_name CONSTANT VARCHAR2(30) := 'derive_job_business_group_id';
4937   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
4938   d_position NUMBER;
4939 
4940   -- tables to store the derived result
4941   l_index_tbl        PO_TBL_NUMBER;
4942   l_result_tbl       PO_TBL_NUMBER;
4943 BEGIN
4944   d_position := 0;
4945 
4946   IF (PO_LOG.d_proc) THEN
4947     PO_LOG.proc_begin(d_module, 'p_job_business_group_name_tbl',
4948                       p_job_business_group_name_tbl);
4949     PO_LOG.proc_begin(d_module, 'x_job_business_group_id_tbl',
4950                       x_job_business_group_id_tbl);
4951   END IF;
4952 
4953   -- derive id from name
4954   FORALL i IN 1.. p_index_tbl.COUNT
4955     INSERT INTO po_session_gt(key, num1, num2)
4956     SELECT p_key,
4957            p_index_tbl(i),
4958            business_group_id
4959     FROM   per_business_groups_perf
4960     WHERE  p_job_business_group_name_tbl(i) IS NOT NULL
4961     AND    x_job_business_group_id_tbl(i) IS NULL
4962     AND    name = p_job_business_group_name_tbl(i)
4963     AND    TRUNC(sysdate) BETWEEN TRUNC(NVL(date_from, sysdate))
4964            AND TRUNC(NVL(date_to, sysdate));
4965 
4966   d_position := 10;
4967 
4968   -- read result from temp table, and delete the records from temp table
4969   DELETE FROM po_session_gt
4970   WHERE  key = p_key
4971   RETURNING num1, num2 BULK COLLECT INTO l_index_tbl, l_result_tbl;
4972 
4973   d_position := 20;
4974 
4975   -- push the result back to x_job_business_group_id_tbl
4976   FOR i IN 1..l_index_tbl.COUNT
4977   LOOP
4978     IF (PO_LOG.d_stmt) THEN
4979       PO_LOG.stmt(d_module, d_position, 'new business group id',
4980                   l_result_tbl(i));
4981     END IF;
4982 
4983     x_job_business_group_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
4984   END LOOP;
4985 
4986   IF (PO_LOG.d_proc) THEN
4987     PO_LOG.proc_end(d_module);
4988   END IF;
4989 
4990 EXCEPTION
4991   WHEN OTHERS THEN
4992     PO_MESSAGE_S.add_exc_msg
4993     (
4994       p_pkg_name => d_pkg_name,
4995       p_procedure_name => d_api_name || '.' || d_position
4996     );
4997     RAISE;
4998 END derive_job_business_group_id;
4999 
5000 -----------------------------------------------------------------------
5001 --Start of Comments
5002 --Name: derive_job_id
5003 --Function: derive job_id from job_business_group_name and job_name
5004 --Parameters:
5005 --IN:
5006 --  p_key
5007 --    key used to identify rows in po_session_gt
5008 --  p_index_tbl
5009 --    table containging the indexes of all rows
5010 --  p_file_line_language_tbl
5011 --    list of line level languages
5012 --  p_job_business_group_name_tbl
5013 --    list of job_business_group_names read within the batch
5014 --  p_job_name_tbl
5015 --    list of job_names read within the batch
5016 --IN OUT:
5017 --  x_job_business_group_id_tbl
5018 --    list of job_business_group_ids read within the batch;
5019 --    derived result will be saved here as well;
5020 --  x_job_id_tbl
5021 --    list of job_ids read within the batch;
5022 --    derived result will be saved here as well;
5023 --    derivation will only occur when job_name
5024 --    is provided but job_id is not;
5025 --OUT:
5026 --End of Comments
5027 ------------------------------------------------------------------------
5028 PROCEDURE derive_job_id
5029 (
5030   p_key                            IN po_session_gt.key%TYPE,
5031   p_index_tbl                      IN DBMS_SQL.NUMBER_TABLE,
5032   p_file_line_language_tbl         IN PO_TBL_VARCHAR5,
5033   p_job_business_group_name_tbl    IN PO_TBL_VARCHAR2000,
5034   p_job_name_tbl                   IN PO_TBL_VARCHAR2000,
5035   x_job_business_group_id_tbl      IN OUT NOCOPY PO_TBL_NUMBER,
5036   x_job_id_tbl                     IN OUT NOCOPY PO_TBL_NUMBER
5037 ) IS
5038 
5039   d_api_name CONSTANT VARCHAR2(30) := 'derive_job_id';
5040   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
5041   d_position NUMBER;
5042 
5043   -- tables to store the derived result
5044   l_index_tbl        PO_TBL_NUMBER;
5045   l_result_tbl       PO_TBL_NUMBER;
5046 
5047   -- debug variables
5048   d_group_id         NUMBER;
5049   d_job_id_tbl       PO_TBL_NUMBER;
5050   d_job_name_tbl     PO_TBL_VARCHAR2000;
5051   d_bg_id_tbl        PO_TBL_NUMBER;
5052 
5053 BEGIN
5054   d_position := 0;
5055 
5056   IF (PO_LOG.d_proc) THEN
5057     PO_LOG.proc_begin(d_module, 'p_file_line_language_tbl',
5058                       p_file_line_language_tbl);
5059     PO_LOG.proc_begin(d_module, 'p_job_business_group_name_tbl',
5060                       p_job_business_group_name_tbl);
5061     PO_LOG.proc_begin(d_module, 'p_job_name_tbl', p_job_name_tbl);
5062     PO_LOG.proc_begin(d_module, 'x_job_business_group_id_tbl',
5063                       x_job_business_group_id_tbl);
5064     PO_LOG.proc_begin(d_module, 'x_job_id_tbl', x_job_id_tbl);
5065   END IF;
5066 
5067   -- execute different queries to derive job_id depending on profile and
5068   -- value of job_business_group_id
5069   IF (PO_LOG.d_stmt) THEN
5070     PO_LOG.stmt(d_module, d_position, 'business group profile value',
5071                 PO_PDOI_PARAMS.g_profile.xbg);
5072     PO_LOG.stmt(d_module, d_position, 'fsp business_group_id',
5073                 PO_PDOI_PARAMS.g_sys.def_business_group_id);
5074   END IF;
5075 
5076   -- bug 5489942: derive job_id from job_name based on
5077   --              line level language
5078   IF (NVL(PO_PDOI_PARAMS.g_profile.xbg, 'N') = 'N') THEN
5079     d_position := 10;
5080 
5081     -- derive job_id from job_name
5082     FORALL i IN 1..p_index_tbl.COUNT
5083       INSERT INTO po_session_gt(key, num1, num2)
5084       SELECT p_key,
5085              p_index_tbl(i),
5086              jobs_b.job_id
5087       FROM   per_jobs jobs_b,
5088              per_jobs_tl jobs_tl
5089       WHERE  p_job_name_tbl(i) IS NOT NULL
5090       AND    x_job_id_tbl(i) IS NULL
5091       AND    jobs_b.job_id = jobs_tl.job_id
5092       AND    jobs_tl.language = NVL(p_file_line_language_tbl(i), userenv('LANG'))
5093       AND    jobs_tl.name = p_job_name_tbl(i)
5094       AND    jobs_b.business_group_id = PO_PDOI_PARAMS.g_sys.def_business_group_id
5095       AND    PO_PDOI_PARAMS.g_sys.def_business_group_id =
5096                DECODE(p_job_business_group_name_tbl(i), NULL,
5097                DECODE(x_job_business_group_id_tbl(i), NULL,
5098                PO_PDOI_PARAMS.g_sys.def_business_group_id,
5099                x_job_business_group_id_tbl(i)), x_job_business_group_id_tbl(i))
5100       AND    TRUNC(sysdate) BETWEEN TRUNC(NVL(jobs_b.date_from, sysdate))
5101              AND TRUNC(NVL(jobs_b.date_to, sysdate));
5102   ELSE
5103     d_position := 20;
5104 
5105     /*  -- START OF info added for debugging purpose
5106 
5107     select job_id, name, business_group_id
5108     bulk collect into d_job_id_tbl, d_job_name_tbl, d_bg_id_tbl
5109     from per_jobs_vl
5110     where TRUNC(sysdate) BETWEEN TRUNC(NVL(date_from, sysdate))
5111              AND TRUNC(NVL(date_to, sysdate));
5112 
5113     IF (PO_LOG.d_stmt) THEN
5114       PO_LOG.stmt(d_module, d_position, 'debug: d_job_id_tbl',
5115                   d_job_id_tbl);
5116       PO_LOG.stmt(d_module, d_position, 'debug: d_job_name_tbl',
5117                   d_job_name_tbl);
5118       PO_LOG.stmt(d_module, d_position, 'debug: d_bg_id_tbl',
5119                   d_bg_id_tbl);
5120       PO_LOG.stmt(d_module, d_position, 'debug: default bg id',
5121                   PO_PDOI_PARAMS.g_sys.def_business_group_id);
5122     END IF;
5123 
5124     -- END OF info added for debugging purpose */
5125 
5126     -- derive job_id for lines with job_business_group_id = null
5127     FORALL i IN 1..p_index_tbl.COUNT
5128       INSERT INTO po_session_gt(key, num1, num2)
5129       SELECT p_key,
5130              p_index_tbl(i),
5131              jobs_b.job_id
5132       FROM   per_jobs jobs_b,
5133              per_jobs_tl jobs_tl
5134       WHERE  p_job_name_tbl(i) IS NOT NULL
5135       AND    x_job_id_tbl(i) IS NULL
5136       AND    x_job_business_group_id_tbl(i) IS NULL
5137       AND    jobs_b.job_id = jobs_tl.job_id
5138       AND    jobs_tl.language = NVL(p_file_line_language_tbl(i), userenv('LANG'))
5139       AND    jobs_tl.name = p_job_name_tbl(i)
5140       AND    jobs_b.business_group_id = PO_PDOI_PARAMS.g_sys.def_business_group_id
5141       AND    PO_PDOI_PARAMS.g_sys.def_business_group_id =
5142                DECODE(p_job_business_group_name_tbl(i), NULL,
5143                PO_PDOI_PARAMS.g_sys.def_business_group_id,
5144                x_job_business_group_id_tbl(i))
5145       AND    TRUNC(sysdate) BETWEEN TRUNC(NVL(jobs_b.date_from, sysdate))
5146              AND TRUNC(NVL(jobs_b.date_to, sysdate));
5147 
5148     d_position := 30;
5149 
5150     -- derive job_id for lines with job_business_group_id <> null
5151     FORALL i IN 1..p_index_tbl.COUNT
5152       INSERT INTO po_session_gt(key, num1, num2)
5153       SELECT p_key,
5154              p_index_tbl(i),
5155              jobs_b.job_id
5156       FROM   per_jobs jobs_b,
5157              per_jobs_tl jobs_tl,
5158              per_business_groups_perf groups
5159       WHERE  p_job_name_tbl(i) IS NOT NULL
5160       AND    x_job_id_tbl(i) IS NULL
5161       AND    x_job_business_group_id_tbl(i) IS NOT NULL
5162       AND    jobs_b.job_id = jobs_tl.job_id
5163       AND    jobs_tl.language = NVL(p_file_line_language_tbl(i), userenv('LANG'))
5164       AND    jobs_tl.name = p_job_name_tbl(i)
5165       AND    jobs_b.business_group_id = x_job_business_group_id_tbl(i)
5166       AND    jobs_b.business_group_id = groups.business_group_id
5167       AND    TRUNC(sysdate) BETWEEN NVL(jobs_b.date_from, TRUNC(sysdate))
5168              AND NVL(jobs_b.date_to, TRUNC(sysdate))
5169       AND    TRUNC(sysdate) BETWEEN NVL(groups.date_from, TRUNC(sysdate))
5170              AND NVL(groups.date_to, TRUNC(sysdate));
5171   END IF;
5172 
5173   d_position := 40;
5174 
5175   -- retrive result from temp table and delete the records in temp table
5176   DELETE FROM po_session_gt
5177   WHERE  key = p_key
5178   RETURNING num1, num2 BULK COLLECT INTO l_index_tbl, l_result_tbl;
5179 
5180   d_position := 50;
5181 
5182   IF (PO_LOG.d_stmt) THEN
5183     PO_LOG.stmt(d_module, d_position, 'derived result: l_index_tbl',
5184                 l_index_tbl);
5185     PO_LOG.stmt(d_module, d_position, 'derived result: l_result_tbl',
5186                 l_result_tbl);
5187   END IF;
5188 
5189   -- set job_business_group_id if both job_business_group_id
5190   -- and job_business_group_name is empty
5191   FOR i IN 1..p_index_tbl.COUNT
5192   LOOP
5193     IF (p_job_name_tbl(i) IS NOT NULL AND
5194         X_job_id_tbl(i) IS NULL AND
5195         p_job_business_group_name_tbl(i) IS NULL AND
5196         x_job_business_group_id_tbl(i) IS NULL) THEN
5197       x_job_business_group_id_tbl(i) :=
5198              PO_PDOI_PARAMS.g_sys.def_business_group_id;
5199     END IF;
5200   END LOOP;
5201 
5202   d_position := 60;
5203 
5204   -- set job_id from derived values
5205   FOR i IN 1..l_index_tbl.COUNT
5206   LOOP
5207     IF (PO_LOG.d_stmt) THEN
5208       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
5209       PO_LOG.stmt(d_module, d_position, 'new job id', l_result_tbl(i));
5210     END IF;
5211 
5212     x_job_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
5213   END LOOP;
5214 
5215   IF (PO_LOG.d_proc) THEN
5216     PO_LOG.proc_end(d_module);
5217   END IF;
5218 
5219 EXCEPTION
5220   WHEN OTHERS THEN
5221     PO_MESSAGE_S.add_exc_msg
5222     (
5223       p_pkg_name => d_pkg_name,
5224       p_procedure_name => d_api_name || '.' || d_position
5225     );
5226     RAISE;
5227 END derive_job_id;
5228 
5229 -----------------------------------------------------------------------
5230 --Start of Comments
5231 --Name: derive_category_id
5232 --Function: derive po category_id from po category name
5233 --Parameters:
5234 --IN:
5235 --  p_key
5236 --    key used to identify rows in po_session_gt
5237 --  p_category_tbl
5238 --    list of categories read within the batch
5239 --IN OUT:
5240 --  x_category_id_tbl
5241 --    list of category_ids read within the batch;
5242 --    derived result will be saved here as well;
5243 --    derivation will only occur when category
5244 --    is provided but category_id is not;
5245 --OUT:
5246 --End of Comments
5247 ------------------------------------------------------------------------
5248 PROCEDURE derive_category_id
5249 (
5250   p_key                  IN po_session_gt.key%TYPE,
5251   p_category_tbl         IN PO_TBL_VARCHAR2000,
5252   x_category_id_tbl      IN OUT NOCOPY PO_TBL_NUMBER
5253 ) IS
5254 
5255   d_api_name CONSTANT VARCHAR2(30) := 'derive_category_id';
5256   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
5257   d_position NUMBER;
5258 
5259   l_result NUMBER;
5260 BEGIN
5261   d_position := 0;
5262 
5263   IF (PO_LOG.d_proc) THEN
5264     PO_LOG.proc_begin(d_module, 'p_category_tbl', p_category_tbl);
5265     PO_LOG.proc_begin(d_module, 'x_category_id_tbl', x_category_id_tbl);
5266   END IF;
5267 
5268   -- category id is derived by an API provided by FND.
5269   -- so we have to call the APPI multiple times
5270   FOR i IN 1.. p_category_tbl.COUNT
5271   LOOP
5272     IF (p_category_tbl(i) IS NOT NULL AND
5273         x_category_id_tbl(i) IS NULL) THEN
5274       d_position := 10;
5275 
5276       l_result :=
5277            FND_FLEX_EXT.GET_CCID('INV', 'MCAT',
5278                         PO_PDOI_PARAMS.g_sys.def_structure_id,
5279                         to_char(sysdate,'YYYY/MM/DD HH24:MI:SS'),
5280                         p_category_tbl(i));
5281 
5282       IF (PO_LOG.d_stmt) THEN
5283         PO_LOG.stmt(d_module, d_position, 'index', i);
5284         PO_LOG.stmt(d_module, d_position, 'result', l_result);
5285       END IF;
5286 
5287       IF (l_result IS NOT NULL AND l_result <> 0) THEN
5288         x_category_id_tbl(i) := l_result;
5289       END IF;
5290     END IF;
5291   END LOOP;
5292 
5293   IF (PO_LOG.d_proc) THEN
5294     PO_LOG.proc_end(d_module);
5295   END IF;
5296 
5297 EXCEPTION
5298   WHEN OTHERS THEN
5299     PO_MESSAGE_S.add_exc_msg
5300     (
5301       p_pkg_name => d_pkg_name,
5302       p_procedure_name => d_api_name || '.' || d_position
5303     );
5304     RAISE;
5305 END derive_category_id;
5306 
5307 -----------------------------------------------------------------------
5308 --Start of Comments
5309 --Name: derive_ip_category_id
5310 --Function: derive po category_id from po category name
5311 --Parameters:
5312 --IN:
5313 --  p_key
5314 --    key used to identify rows in po_session_gt
5315 --  p_index_tbl
5316 --    table containging the indexes of all rows
5317 --  p_file_line_language_tbl
5318 --    list of line level languages
5319 --  p_ip_category_tbl
5320 --    list of ip_categories read within the batch
5321 --IN OUT:
5322 --  x_ip_category_id_tbl
5323 --    list of ip_category_ids read within the batch;
5324 --    derived result will be saved here as well;
5325 --    derivation will only occur when ip_category
5326 --    is provided but ip_category_id is not;
5327 --OUT:
5328 --End of Comments
5329 ------------------------------------------------------------------------
5330 PROCEDURE derive_ip_category_id
5331 (
5332   p_key                    IN po_session_gt.key%TYPE,
5333   p_index_tbl              IN DBMS_SQL.NUMBER_TABLE,
5334   p_file_line_language_tbl IN PO_TBL_VARCHAR5,
5335   p_ip_category_tbl        IN PO_TBL_VARCHAR2000,
5336   x_ip_category_id_tbl     IN OUT NOCOPY PO_TBL_NUMBER
5337 ) IS
5338 
5339   d_api_name CONSTANT VARCHAR2(30) := 'derive_ip_category_id';
5340   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
5341   d_position NUMBER;
5342 
5343   -- tables to store the derived result
5344   l_index_tbl        PO_TBL_NUMBER;
5345   l_result_tbl       PO_TBL_NUMBER;
5346 BEGIN
5347   d_position := 0;
5348 
5349   IF (PO_LOG.d_proc) THEN
5350     PO_LOG.proc_begin(d_module, 'p_ip_category_tbl', p_ip_category_tbl);
5351     PO_LOG.proc_begin(d_module, 'p_file_line_language_tbl', p_file_line_language_tbl);
5352     PO_LOG.proc_begin(d_module, 'x_ip_category_id_tbl', x_ip_category_id_tbl);
5353   END IF;
5354 
5355   -- 1. derive ip_category_id based on category key
5356   FORALL i IN 1.. p_index_tbl.COUNT
5357     INSERT INTO po_session_gt(key, num1, char1)
5358     SELECT p_key,
5359            p_index_tbl(i),
5360            cat.rt_category_id
5361     FROM   icx_cat_categories_v cat
5362     WHERE  p_ip_category_tbl(i) IS NOT NULL
5363     AND    x_ip_category_id_tbl(i) IS NULL
5364     AND    cat.key = p_ip_category_tbl(i);
5365 
5366   d_position := 10;
5367 
5368   -- read result from temp table, and delete the records from temp table
5369   DELETE FROM po_session_gt
5370   WHERE  key = p_key
5371   RETURNING num1, char1 BULK COLLECT INTO l_index_tbl, l_result_tbl;
5372 
5373   d_position := 20;
5374 
5375   -- push the result back to x_unit_of_measure_tbl
5376   FOR i IN 1..l_index_tbl.COUNT
5377   LOOP
5378     IF (PO_LOG.d_stmt) THEN
5379       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
5380       PO_LOG.stmt(d_module, d_position, 'new ip category id',
5381                   l_result_tbl(i));
5382     END IF;
5383 
5384     x_ip_category_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
5385   END LOOP;
5386 
5387   d_position := 30;
5388 
5389   -- bug 5489942: derivation is based on line level language
5390   -- 2. derive ip_category_id based on category name,
5391   --    name is language specific
5392   FORALL i IN 1.. p_index_tbl.COUNT
5393     INSERT INTO po_session_gt(key, num1, char1)
5394     SELECT p_key,
5395            p_index_tbl(i),
5396            rt_category_id
5397     FROM   icx_cat_categories_v
5398     WHERE  p_ip_category_tbl(i) IS NOT NULL
5399     AND    x_ip_category_id_tbl(i) IS NULL
5400     AND    category_name = p_ip_category_tbl(i)
5401     AND    language = NVL(p_file_line_language_tbl(i),
5402                           userenv('LANG'));
5403 
5404   d_position := 40;
5405 
5406   -- read result from temp table, and delete the records from temp table
5407   DELETE FROM po_session_gt
5408   WHERE  key = p_key
5409   RETURNING num1, char1 BULK COLLECT INTO l_index_tbl, l_result_tbl;
5410 
5411   d_position := 50;
5412 
5413   -- push the result back to x_unit_of_measure_tbl
5414   FOR i IN 1..l_index_tbl.COUNT
5415   LOOP
5416     IF (PO_LOG.d_stmt) THEN
5417       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
5418       PO_LOG.stmt(d_module, d_position, 'new ip category id',
5419                   l_result_tbl(i));
5420     END IF;
5421 
5422     x_ip_category_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
5423   END LOOP;
5424 
5425   IF (PO_LOG.d_proc) THEN
5426     PO_LOG.proc_end(d_module);
5427   END IF;
5428 
5429 EXCEPTION
5430   WHEN OTHERS THEN
5431     PO_MESSAGE_S.add_exc_msg
5432     (
5433       p_pkg_name => d_pkg_name,
5434       p_procedure_name => d_api_name || '.' || d_position
5435     );
5436     RAISE;
5437 END derive_ip_category_id;
5438 
5439 -----------------------------------------------------------------------
5440 --Start of Comments
5441 --Name: derive_unit_of_measure
5442 --Function: derive unit_of_measure from uom_code
5443 --Parameters:
5444 --IN:
5445 --  p_key
5446 --    key used to identify rows in po_session_gt
5447 --  p_index_tbl
5448 --    table containging the indexes of all rows
5449 --  p_uom_code_tbl
5450 --    list of uom_codes read within the batch
5451 --IN OUT:
5452 --  x_unit_of_measure_tbl
5453 --    list of unit_of_measures read within the batch;
5454 --    derived result will be saved here as well;
5455 --    derivation will only occur when uom_code
5456 --    is provided but unit_of_measure is not;
5457 --OUT:
5458 --End of Comments
5459 ------------------------------------------------------------------------
5460 PROCEDURE derive_unit_of_measure
5461 (
5462   p_key                  IN po_session_gt.key%TYPE,
5463   p_index_tbl            IN DBMS_SQL.NUMBER_TABLE,
5464   p_uom_code_tbl         IN PO_TBL_VARCHAR5,
5465   x_unit_of_measure_tbl  IN OUT NOCOPY PO_TBL_VARCHAR30
5466 ) IS
5467 
5468   d_api_name CONSTANT VARCHAR2(30) := 'derive_unit_of_measure';
5469   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
5470   d_position NUMBER;
5471 
5472   -- tables to store the derived result
5473   l_index_tbl        PO_TBL_NUMBER;
5474   l_result_tbl       PO_TBL_VARCHAR30;
5475 BEGIN
5476   d_position := 0;
5477 
5478   IF (PO_LOG.d_proc) THEN
5479     PO_LOG.proc_begin(d_module, 'p_uom_code_tbl', p_uom_code_tbl);
5480     PO_LOG.proc_begin(d_module, 'x_unit_of_measure_tbl', x_unit_of_measure_tbl);
5481   END IF;
5482 
5483   -- derive unit_of_measure from uom_code
5484   FORALL i IN 1.. p_index_tbl.COUNT
5485     INSERT INTO po_session_gt(key, num1, char1)
5486     SELECT p_key,
5487            p_index_tbl(i),
5488            unit_of_measure
5489     FROM   po_units_of_measure_val_v
5490     WHERE  p_uom_code_tbl(i) IS NOT NULL
5491     AND    x_unit_of_measure_tbl(i) IS NULL
5492     AND    uom_code = p_uom_code_tbl(i);
5493 
5494   d_position := 10;
5495 
5496   -- read result from temp table, and delete the records from temp table
5497   DELETE FROM po_session_gt
5498   WHERE  key = p_key
5499   RETURNING num1, char1 BULK COLLECT INTO l_index_tbl, l_result_tbl;
5500 
5501   d_position := 20;
5502 
5503   -- push the result back to x_unit_of_measure_tbl
5504   FOR i IN 1..l_index_tbl.COUNT
5505   LOOP
5506     IF (PO_LOG.d_stmt) THEN
5507       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
5508       PO_LOG.stmt(d_module, d_position, 'new unit of measure',
5509                   l_result_tbl(i));
5510     END IF;
5511 
5512     x_unit_of_measure_tbl(l_index_tbl(i)) := l_result_tbl(i);
5513   END LOOP;
5514 
5515   IF (PO_LOG.d_proc) THEN
5516     PO_LOG.proc_end(d_module);
5517   END IF;
5518 
5519 EXCEPTION
5520   WHEN OTHERS THEN
5521     PO_MESSAGE_S.add_exc_msg
5522     (
5523       p_pkg_name => d_pkg_name,
5524       p_procedure_name => d_api_name || '.' || d_position
5525     );
5526     RAISE;
5527 END derive_unit_of_measure;
5528 
5529 -----------------------------------------------------------------------
5530 --Start of Comments
5531 --Name: derive_line_type_id
5532 --Function: derive line_type_id from line_type
5533 --Parameters:
5534 --IN:
5535 --  p_key
5536 --    key used to identify rows in po_session_gt
5537 --  p_index_tbl
5538 --    table containging the indexes of all rows
5539 --  p_file_line_language_tbl
5540 --    list of line level languages
5541 --  p_line_type_tbl
5542 --    list of line_types read within the batch
5543 --IN OUT:
5544 --  x_line_type_id_tbl
5545 --    list of line_type_ids read within the batch;
5546 --    derived result will be saved here as well;
5547 --    derivation will only occur when line_type
5548 --    is provided but line_type_id is not;
5549 --OUT:
5550 --End of Comments
5551 ------------------------------------------------------------------------
5552 PROCEDURE derive_line_type_id
5553 (
5554   p_key                    IN po_session_gt.key%TYPE,
5555   p_index_tbl              IN DBMS_SQL.NUMBER_TABLE,
5556   p_file_line_language_tbl IN PO_TBL_VARCHAR5,
5557   p_line_type_tbl          IN PO_TBL_VARCHAR30,
5558   x_line_type_id_tbl       IN OUT NOCOPY PO_TBL_NUMBER
5559 ) IS
5560 
5561   d_api_name CONSTANT VARCHAR2(30) := 'derive_line_type_id';
5562   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
5563   d_position NUMBER;
5564 
5565   -- tables to store the derived result
5566   l_index_tbl        PO_TBL_NUMBER;
5567   l_result_tbl       PO_TBL_NUMBER;
5568 BEGIN
5569   d_position := 0;
5570 
5571   IF (PO_LOG.d_proc) THEN
5572     PO_LOG.proc_begin(d_module, 'p_line_type_tbl', p_line_type_tbl);
5573     PO_LOG.proc_begin(d_module, 'p_file_line_language_tbl', p_file_line_language_tbl);
5574     PO_LOG.proc_begin(d_module, 'x_line_type_id_tbl', x_line_type_id_tbl);
5575   END IF;
5576 
5577   -- bug 5489942: derivation is based on line level language
5578   -- derive line_type_id from line_type
5579   FORALL i IN 1..p_index_tbl.COUNT
5580     INSERT INTO po_session_gt(key, num1, num2)
5581     SELECT p_key,
5582            p_index_tbl(i),
5583            b.line_type_id
5584     FROM   po_line_types_b b,
5585            po_line_types_tl tl
5586     WHERE  p_line_type_tbl(i) IS NOT NULL
5587     AND    x_line_type_id_tbl(i) IS NULL
5588     AND    b.line_type_id = tl.line_type_id
5589     AND    tl.language = NVL(p_file_line_language_tbl(i),
5590                              userenv('LANG'))
5591     AND    SYSDATE < NVL(b.inactive_date, SYSDATE +1)
5592     AND    tl.line_type = p_line_type_tbl(i);
5593 
5594   d_position := 10;
5595 
5596   -- read result from temp table, and delete the records from temp table
5597   DELETE FROM po_session_gt
5598   WHERE  key = p_key
5599   RETURNING num1, num2 BULK COLLECT INTO l_index_tbl, l_result_tbl;
5600 
5601   d_position := 20;
5602 
5603   -- push the result back to x_line_type_ids
5604   FOR i IN 1..l_index_tbl.COUNT
5605   LOOP
5606     IF (PO_LOG.d_stmt) THEN
5607       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
5608       PO_LOG.stmt(d_module, d_position, 'new line type id', l_result_tbl(i));
5609     END IF;
5610 
5611     x_line_type_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
5612   END LOOP;
5613 
5614   IF (PO_LOG.d_proc) THEN
5615     PO_LOG.proc_end(d_module);
5616   END IF;
5617 
5618 EXCEPTION
5619   WHEN OTHERS THEN
5620     PO_MESSAGE_S.add_exc_msg
5621     (
5622       p_pkg_name => d_pkg_name,
5623       p_procedure_name => d_api_name || '.' || d_position
5624     );
5625     RAISE;
5626 END derive_line_type_id;
5627 
5628 -----------------------------------------------------------------------
5629 --Start of Comments
5630 --Name: derive_un_number_id
5631 --Function: derive un_number_id from un_number
5632 --Parameters:
5633 --IN:
5634 --  p_key
5635 --    key used to identify rows in po_session_gt
5636 --  p_index_tbl
5637 --    table containging the indexes of all rows
5638 --  p_un_number_tbl
5639 --    list of un_numbers read within the batch
5640 --IN OUT:
5641 --  x_un_number_id_tbl
5642 --    list of un_number_ids read within the batch;
5643 --    derived result will be saved here as well;
5644 --    derivation will only occur when un_number
5645 --    is provided but un_number_id is not;
5646 --OUT:
5647 --End of Comments
5648 ------------------------------------------------------------------------
5649 PROCEDURE derive_un_number_id
5650 (
5651   p_key                  IN po_session_gt.key%TYPE,
5652   p_index_tbl            IN DBMS_SQL.NUMBER_TABLE,
5653   p_un_number_tbl        IN PO_TBL_VARCHAR30,
5654   x_un_number_id_tbl     IN OUT NOCOPY PO_TBL_NUMBER
5655 ) IS
5656 
5657   d_api_name CONSTANT VARCHAR2(30) := 'derive_un_number_id';
5658   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
5659   d_position NUMBER;
5660 
5661   -- tables to store the derived result
5662   l_index_tbl        PO_TBL_NUMBER;
5663   l_result_tbl       PO_TBL_NUMBER;
5664 BEGIN
5665   d_position := 0;
5666 
5667   IF (PO_LOG.d_proc) THEN
5668     PO_LOG.proc_begin(d_module, 'p_un_number_tbl', p_un_number_tbl);
5669     PO_LOG.proc_begin(d_module, 'x_un_number_id_tbl', x_un_number_id_tbl);
5670   END IF;
5671 
5672   -- derive un_number_id from un_number
5673   FORALL i IN 1.. p_index_tbl.COUNT
5674     INSERT INTO po_session_gt(key, num1, num2)
5675     SELECT p_key,
5676            p_index_tbl(i),
5677            un_number_id
5678     FROM   po_un_numbers_vl
5679     WHERE  p_un_number_tbl(i) IS NOT NULL
5680     AND    x_un_number_id_tbl(i) IS NULL
5681     AND    sysdate < nvl(inactive_date, sysdate +1)
5682     AND    un_number = p_un_number_tbl(i);
5683 
5684   d_position := 10;
5685 
5686   -- read result from temp table, and delete the records from temp table
5687   DELETE FROM po_session_gt
5688   WHERE  key = p_key
5689   RETURNING num1, num2 BULK COLLECT INTO l_index_tbl, l_result_tbl;
5690 
5691   d_position := 20;
5692 
5693   -- push the result back to x_lines
5694   FOR i IN 1..l_index_tbl.COUNT
5695   LOOP
5696     IF (PO_LOG.d_stmt) THEN
5697       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
5698       PO_LOG.stmt(d_module, d_position, 'new un number id', l_result_tbl(i));
5699     END IF;
5700 
5701     x_un_number_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
5702   END LOOP;
5703 
5704   IF (PO_LOG.d_proc) THEN
5705     PO_LOG.proc_end(d_module);
5706   END IF;
5707 
5708 EXCEPTION
5709   WHEN OTHERS THEN
5710     PO_MESSAGE_S.add_exc_msg
5711     (
5712       p_pkg_name => d_pkg_name,
5713       p_procedure_name => d_api_name || '.' || d_position
5714     );
5715     RAISE;
5716 END derive_un_number_id;
5717 
5718 -----------------------------------------------------------------------
5719 --Start of Comments
5720 --Name: derive_hazard_class_id
5721 --Function: derive hazard_class_id from hazard_class
5722 --Parameters:
5723 --IN:
5724 --  p_key
5725 --    key used to identify rows in po_session_gt
5726 --  p_index_tbl
5727 --    table containging the indexes of all rows
5728 --  p_hazard_class_tbl
5729 --    list of hazard_classes read within the batch
5730 --IN OUT:
5731 --  x_hazard_class_id_tbl
5732 --    list of hazard_class_ids read within the batch;
5733 --    derived result will be saved here as well;
5734 --    derivation will only occur when hazard_class
5735 --    is provided but hazard_class_id is not;
5736 --OUT:
5737 --End of Comments
5738 ------------------------------------------------------------------------
5739 PROCEDURE derive_hazard_class_id
5740 (
5741   p_key                  IN po_session_gt.key%TYPE,
5742   p_index_tbl            IN DBMS_SQL.NUMBER_TABLE,
5743   p_hazard_class_tbl     IN PO_TBL_VARCHAR100,
5744   x_hazard_class_id_tbl  IN OUT NOCOPY PO_TBL_NUMBER
5745 ) IS
5746 
5747   d_api_name CONSTANT VARCHAR2(30) := 'derive_hazard_class_id';
5748   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
5749   d_position NUMBER;
5750 
5751   -- tables to store the derived result
5752   l_index_tbl        PO_TBL_NUMBER;
5753   l_result_tbl       PO_TBL_NUMBER;
5754 BEGIN
5755   d_position := 0;
5756 
5757   IF (PO_LOG.d_proc) THEN
5758     PO_LOG.proc_begin(d_module, 'p_hazard_class_tbl', p_hazard_class_tbl);
5759     PO_LOG.proc_begin(d_module, 'x_hazard_class_id_tbl', x_hazard_class_id_tbl);
5760   END IF;
5761 
5762   -- derive hazard_class_id from hazard_class
5763   FORALL i IN 1..p_index_tbl.COUNT
5764     INSERT INTO po_session_gt(key, num1, num2)
5765     SELECT p_key,
5766            p_index_tbl(i),
5767            hazard_class_id
5768     FROM   po_hazard_classes_val_v
5769     WHERE  p_hazard_class_tbl(i) IS NOT NULL
5770     AND    x_hazard_class_id_tbl(i) IS NULL
5771     AND    hazard_class = p_hazard_class_tbl(i);
5772 
5773   d_position := 10;
5774 
5775   -- read result from temp table, and delete the records from temp table
5776   DELETE FROM po_session_gt
5777   WHERE  key = p_key
5778   RETURNING num1, num2 BULK COLLECT INTO l_index_tbl, l_result_tbl;
5779 
5780   d_position := 20;
5781 
5782   -- push the result back to x_hazard_class_ids
5783   FOR i IN 1..l_index_tbl.COUNT
5784   LOOP
5785     IF (PO_LOG.d_stmt) THEN
5786       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
5787       PO_LOG.stmt(d_module, d_position, 'new hazard class id', l_result_tbl(i));
5788     END IF;
5789 
5790     x_hazard_class_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
5791   END LOOP;
5792 
5793   IF (PO_LOG.d_proc) THEN
5794     PO_LOG.proc_end(d_module);
5795   END IF;
5796 
5797 EXCEPTION
5798   WHEN OTHERS THEN
5799     PO_MESSAGE_S.add_exc_msg
5800     (
5801       p_pkg_name => d_pkg_name,
5802       p_procedure_name => d_api_name || '.' || d_position
5803     );
5804     RAISE;
5805 END derive_hazard_class_id;
5806 
5807 -----------------------------------------------------------------------
5808 --Start of Comments
5809 --Name: derive_template_id
5810 --Function: derive template_id from template_name
5811 --Parameters:
5812 --IN:
5813 --  p_key
5814 --    key used to identify rows in po_session_gt
5815 --  p_index_tbl
5816 --    table containging the indexes of all rows
5817 --  p_template_name_tbl
5818 --    list of template_names read within the batch
5819 --IN OUT:
5820 --  x_template_id_tbl
5821 --    list of template_ids read within the batch;
5822 --    derived result will be saved here as well;
5823 --    derivation will only occur when template_name
5824 --    is provided but template_id is not;
5825 --OUT:
5826 --End of Comments
5827 ------------------------------------------------------------------------
5828 PROCEDURE derive_template_id
5829 (
5830   p_key                  IN po_session_gt.key%TYPE,
5831   p_index_tbl            IN DBMS_SQL.NUMBER_TABLE,
5832   p_template_name_tbl    IN PO_TBL_VARCHAR30,
5833   x_template_id_tbl      IN OUT NOCOPY PO_TBL_NUMBER
5834 ) IS
5835 
5836   d_api_name CONSTANT VARCHAR2(30) := 'derive_template_id';
5837   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
5838   d_position NUMBER;
5839 
5840   -- tables to store the derived result
5841   l_index_tbl        PO_TBL_NUMBER;
5842   l_result_tbl       PO_TBL_NUMBER;
5843 BEGIN
5844   d_position := 0;
5845 
5846   IF (PO_LOG.d_proc) THEN
5847     PO_LOG.proc_begin(d_module, 'p_template_name_tbl', p_template_name_tbl);
5848     PO_LOG.proc_begin(d_module, 'x_template_id_tbl', x_template_id_tbl);
5849   END IF;
5850 
5851   -- derive template_id from template_name
5852   FORALL i IN 1..p_index_tbl.COUNT
5853     INSERT INTO po_session_gt(key, num1, num2)
5854     SELECT p_key,
5855            p_index_tbl(i),
5856            template_id
5857     FROM   mtl_item_templates
5858     WHERE  p_template_name_tbl(i) IS NOT NULL
5859     AND    x_template_id_tbl(i) IS NULL
5860     AND    template_name = p_template_name_tbl(i)
5861     AND    NVL(context_organization_id,
5862            PO_PDOI_PARAMS.g_sys.def_inv_org_id) =
5863            PO_PDOI_PARAMS.g_sys.def_inv_org_id;
5864 
5865   d_position := 10;
5866 
5867   -- read result from temp table, and delete the records from temp table
5868   DELETE FROM po_session_gt
5869   WHERE  key = p_key
5870   RETURNING num1, num2 BULK COLLECT INTO l_index_tbl, l_result_tbl;
5871 
5872   d_position := 20;
5873 
5874   -- push the result back to x_lines
5875   FOR i IN 1..l_index_tbl.COUNT
5876   LOOP
5877     IF (PO_LOG.d_stmt) THEN
5878       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
5879       PO_LOG.stmt(d_module, d_position, 'new template id', l_result_tbl(i));
5880     END IF;
5881 
5882     x_template_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
5883   END LOOP;
5884 
5885   IF (PO_LOG.d_proc) THEN
5886     PO_LOG.proc_end(d_module);
5887   END IF;
5888 
5889 EXCEPTION
5890   WHEN OTHERS THEN
5891     PO_MESSAGE_S.add_exc_msg
5892     (
5893       p_pkg_name => d_pkg_name,
5894       p_procedure_name => d_api_name || '.' || d_position
5895     );
5896     RAISE;
5897 END derive_template_id;
5898 -----------------------------------------------------------------------
5899 --Start of Comments
5900 --Name: default_info_from_line_type
5901 --Function:
5902 --  default information from line types;
5903 --  the information can be defaulted from line type include:
5904 --  1. order_type_lookup_code
5905 --  2. purchase_basis
5906 --  3. matching_basis
5907 --  4. category_id
5908 --  5. unit_of_measure
5909 --  6. unit_price
5910 --Parameters:
5911 --IN:
5912 --  p_key
5913 --    key used to identify rows in po_session_gt
5914 --  p_index_tbl
5915 --    table containging the indexes of all rows
5916 --  p_line_type_id_tbl
5917 --    list of line_type_ids read within the batch
5918 --IN OUT:
5919 --  x_order_type_lookup_code_tbl
5920 --    list of default values from line_type_ids
5921 --  x_purchase_basis_tbl
5922 --    list of default values from line_type_ids
5923 --  x_matching_basis_tbl
5924 --    list of default values from line_type_ids
5925 --OUT:
5926 --  x_category_id_tbl
5927 --    list of default values from line_type_ids
5928 --  x_unit_of_measure_tbl
5929 --    list of default values from line_type_ids
5930 --  x_unit_price_tbl
5931 --    list of default values from line_type_ids
5932 --End of Comments
5933 ------------------------------------------------------------------------
5934 PROCEDURE default_info_from_line_type
5935 (
5936   p_key                        IN po_session_gt.key%TYPE,
5937   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
5938   p_line_type_id_tbl           IN PO_TBL_NUMBER,
5939   x_order_type_lookup_code_tbl IN OUT NOCOPY PO_TBL_VARCHAR30,
5940   x_purchase_basis_tbl         IN OUT NOCOPY PO_TBL_VARCHAR30,
5941   x_matching_basis_tbl         IN OUT NOCOPY PO_TBL_VARCHAR30,
5942   x_category_id_tbl            OUT NOCOPY PO_TBL_NUMBER,
5943   x_unit_of_measure_tbl        OUT NOCOPY PO_TBL_VARCHAR30,
5944   x_unit_price_tbl             OUT NOCOPY PO_TBL_NUMBER
5945 ) IS
5946 
5947   d_api_name CONSTANT VARCHAR2(30) := 'default_info_from_line_type';
5948   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
5949   d_position NUMBER;
5950 
5951   -- variables to hold result read from temp table
5952   l_index_tbl                  PO_TBL_NUMBER;
5953   l_order_type_lookup_code_tbl PO_TBL_VARCHAR30;
5954   l_purchase_basis_tbl         PO_TBL_VARCHAR30;
5955   l_matching_basis_tbl         PO_TBL_VARCHAR30;
5956   l_category_id_tbl            PO_TBL_NUMBER;
5957   l_unit_of_measure_tbl        PO_TBL_VARCHAR30;
5958   l_unit_price_tbl             PO_TBL_NUMBER;
5959 
5960   -- current accessing index in the loop
5961   l_index                      NUMBER;
5962 BEGIN
5963   d_position := 0;
5964 
5965   IF (PO_LOG.d_proc) THEN
5966     PO_LOG.proc_begin(d_module);
5967   END IF;
5968 
5969   x_category_id_tbl     := PO_TBL_NUMBER();
5970   x_unit_of_measure_tbl := PO_TBL_VARCHAR30();
5971   x_unit_price_tbl      := PO_TBL_NUMBER();
5972 
5973   x_category_id_tbl.EXTEND(p_index_tbl.COUNT);
5974   x_unit_of_measure_tbl.EXTEND(p_index_tbl.COUNT);
5975   x_unit_price_tbl.EXTEND(p_index_tbl.COUNT);
5976 
5977   -- retrieve the values based on line type id
5978   FORALL i IN 1..p_index_tbl.COUNT
5979     INSERT INTO po_session_gt(key, num1, char1, char2, char3, num2, char4, num3)
5980     SELECT p_key,
5981            p_index_tbl(i),
5982            order_type_lookup_code,
5983            purchase_basis,
5984            matching_basis,
5985            category_id,
5986            unit_of_measure,
5987            unit_price
5988     FROM   po_line_types_b
5989     WHERE  line_type_id = p_line_type_id_tbl(i);
5990 
5991   d_position := 10;
5992 
5993   -- read result from temp table and delete the records at the same time
5994   DELETE FROM po_session_gt
5995   WHERE  key = p_key
5996   RETURNING num1, char1, char2, char3, num2, char4, num3
5997   BULK COLLECT INTO
5998     l_index_tbl,
5999     l_order_type_lookup_code_tbl,
6000     l_purchase_basis_tbl,
6001     l_matching_basis_tbl,
6002     l_category_id_tbl,
6003     l_unit_of_measure_tbl,
6004     l_unit_price_tbl;
6005 
6006   d_position := 20;
6007 
6008   -- set the result in OUT parameters
6009   FOR i IN 1..l_index_tbl.COUNT
6010   LOOP
6011     l_index := l_index_tbl(i);
6012 
6013     IF (PO_LOG.d_stmt) THEN
6014       PO_LOG.stmt(d_module, d_position, 'index', l_index);
6015       PO_LOG.stmt(d_module, d_position, 'new order type',
6016                   l_order_type_lookup_code_tbl(i));
6017       PO_LOG.stmt(d_module, d_position, 'new purchase basis',
6018                   l_purchase_basis_tbl(i));
6019       PO_LOG.stmt(d_module, d_position, 'new matching basis',
6020                   l_matching_basis_tbl(i));
6021       PO_LOG.stmt(d_module, d_position, 'new category id',
6022                   l_category_id_tbl(i));
6023       PO_LOG.stmt(d_module, d_position, 'new unit of measure',
6024                   l_unit_of_measure_tbl(i));
6025       PO_LOG.stmt(d_module, d_position, 'new unit price',
6026                   l_unit_price_tbl(i));
6027     END IF;
6028 
6029     x_order_type_lookup_code_tbl(l_index) := l_order_type_lookup_code_tbl(i);
6030     x_purchase_basis_tbl(l_index) := l_purchase_basis_tbl(i);
6031     x_matching_basis_tbl(l_index) := l_matching_basis_tbl(i);
6032     x_category_id_tbl(l_index) := l_category_id_tbl(i);
6033     x_unit_of_measure_tbl(l_index) := l_unit_of_measure_tbl(i);
6034     x_unit_price_tbl(l_index) := l_unit_price_tbl(i);
6035   END LOOP;
6036 
6037   IF (PO_LOG.d_proc) THEN
6038     PO_LOG.proc_end(d_module);
6039   END IF;
6040 
6041 EXCEPTION
6042   WHEN OTHERS THEN
6043     PO_MESSAGE_S.add_exc_msg
6044     (
6045       p_pkg_name => d_pkg_name,
6046       p_procedure_name => d_api_name || '.' || d_position
6047     );
6048     RAISE;
6049 END default_info_from_line_type;
6050 
6051 -----------------------------------------------------------------------
6052 --Start of Comments
6053 --Name: default_info_from_item
6054 --Function:
6055 --  default information from item;
6056 --  the information can be defaulted from item include:
6057 --  1. item_description
6058 --  2. unit_of_measure
6059 --  3. unit_price
6060 --  4. category_id
6061 --  5. un_number_id
6062 --  6. hazard_class_id
6063 --  7. market_price
6064 --  8. secondary_unit_of_measure
6065 --Parameters:
6066 --IN:
6067 --  p_key
6068 --    key used to identify rows in po_session_gt
6069 --  p_index_tbl
6070 --    table containging the indexes of all rows
6071 --  p_item_id_tbl
6072 --    list of item_ids read within the batch
6073 --IN OUT:
6074 --OUT:
6075 --  x_item_desc_tbl
6076 --    list of default values from item_desc
6077 --  x_unit_of_measure_tbl
6078 --    list of default values from unit_of_measure
6079 --  x_unit_price_tbl
6080 --    list of default values from unit_price
6081 --  x_category_id_tbl
6082 --    list of default values from category_id
6083 --  x_un_number_id_tbl
6084 --    list of default values from un_number_id
6085 --  x_hazard_class_id_tbl
6086 --    list of default values from hazard_class_id
6087 --  x_market_price_tbl
6088 --    list of default values from market_price
6089 --  x_secondary_unit_of_meas_tbl
6090 --    list of default values from secondary_unit_of_measure
6091 --End of Comments
6092 ------------------------------------------------------------------------
6093 PROCEDURE default_info_from_item
6094 (
6095   p_key                        IN po_session_gt.key%TYPE,
6096   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
6097   p_item_id_tbl                IN PO_TBL_NUMBER,
6098   x_item_desc_tbl              OUT NOCOPY PO_TBL_VARCHAR2000,
6099   x_unit_of_measure_tbl        OUT NOCOPY PO_TBL_VARCHAR30,
6100   x_unit_price_tbl             OUT NOCOPY PO_TBL_NUMBER,
6101   x_category_id_tbl            OUT NOCOPY PO_TBL_NUMBER,
6102   x_un_number_id_tbl           OUT NOCOPY PO_TBL_NUMBER,
6103   x_hazard_class_id_tbl        OUT NOCOPY PO_TBL_NUMBER,
6104   x_market_price_tbl           OUT NOCOPY PO_TBL_NUMBER,
6105   x_secondary_unit_of_meas_tbl OUT NOCOPY PO_TBL_VARCHAR30
6106 ) IS
6107 
6108   d_api_name CONSTANT VARCHAR2(30) := 'default_info_from_item';
6109   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
6110   d_position NUMBER;
6111 
6112   -- variables to hold result read from temp table
6113   l_index_tbl                  PO_TBL_NUMBER;
6114   l_item_desc_tbl              PO_TBL_VARCHAR2000;
6115   l_unit_of_measure_tbl        PO_TBL_VARCHAR30;
6116   l_unit_price_tbl             PO_TBL_NUMBER;
6117   l_category_id_tbl            PO_TBL_NUMBER;
6118   l_un_number_id_tbl           PO_TBL_NUMBER;
6119   l_hazard_class_id_tbl        PO_TBL_NUMBER;
6120   l_market_price_tbl           PO_TBL_NUMBER;
6121   l_secondary_unit_of_meas_tbl PO_TBL_VARCHAR30;
6122 
6123   -- current accessing index in the loop
6124   l_index                      NUMBER;
6125 BEGIN
6126   d_position := 0;
6127 
6128   IF (PO_LOG.d_proc) THEN
6129     PO_LOG.proc_begin(d_module);
6130   END IF;
6131 
6132   x_item_desc_tbl              := PO_TBL_VARCHAR2000();
6133   x_unit_of_measure_tbl        := PO_TBL_VARCHAR30();
6134   x_unit_price_tbl             := PO_TBL_NUMBER();
6135   x_category_id_tbl            := PO_TBL_NUMBER();
6136   x_un_number_id_tbl           := PO_TBL_NUMBER();
6137   x_hazard_class_id_tbl        := PO_TBL_NUMBER();
6138   x_market_price_tbl           := PO_TBL_NUMBER();
6139   x_secondary_unit_of_meas_tbl := PO_TBL_VARCHAR30();
6140 
6141   x_item_desc_tbl.EXTEND(p_index_tbl.COUNT);
6142   x_unit_of_measure_tbl.EXTEND(p_index_tbl.COUNT);
6143   x_unit_price_tbl.EXTEND(p_index_tbl.COUNT);
6144   x_category_id_tbl.EXTEND(p_index_tbl.COUNT);
6145   x_un_number_id_tbl.EXTEND(p_index_tbl.COUNT);
6146   x_hazard_class_id_tbl.EXTEND(p_index_tbl.COUNT);
6147   x_market_price_tbl.EXTEND(p_index_tbl.COUNT);
6148   x_secondary_unit_of_meas_tbl.EXTEND(p_index_tbl.COUNT);
6149 
6150   -- retrieve the values based on item id and default inv org id
6151   -- bug 4723323: get secondary_unit_of_measure value for dual-um
6152   --              control item, used in default logic
6153   FORALL i IN 1..p_index_tbl.COUNT
6154     INSERT INTO po_session_gt(key, num1, char1, char2, num2, num3,
6155                               num4, num5, num6, char3)
6156     SELECT p_key,
6157            p_index_tbl(i),
6158            item_tl.description,
6159            item.primary_unit_of_measure,
6160            item.list_price_per_unit,
6161            item_cat.category_id,
6162            item.un_number_id,
6163            item.hazard_class_id,
6164            item.market_price,
6165            decode(item.tracking_quantity_ind, 'PS', uom.unit_of_measure, NULL)
6166     FROM   mtl_item_categories item_cat,
6167            mtl_system_items item,
6168            mtl_system_items_tl item_tl,
6169            mtl_units_of_measure uom
6170     WHERE  item.inventory_item_id = p_item_id_tbl(i)
6171     AND    item_tl.inventory_item_id = item.inventory_item_id
6172     AND    item_cat.inventory_item_id = item.inventory_item_id
6173     AND    item.organization_id = PO_PDOI_PARAMS.g_sys.def_inv_org_id
6174     AND    item_tl.language = USERENV('LANG')
6175     AND    item_tl.organization_id = PO_PDOI_PARAMS.g_sys.def_inv_org_id
6176     AND    item_cat.category_set_id = PO_PDOI_PARAMS.g_sys.def_cat_set_id
6177     AND    item_cat.organization_id = PO_PDOI_PARAMS.g_sys.def_inv_org_id
6178     AND    item.secondary_uom_code = uom.uom_code(+);
6179 
6180   d_position := 10;
6181 
6182   -- read result from temp table and delete the records at the same time
6183   DELETE FROM po_session_gt
6184   WHERE  key = p_key
6185   RETURNING num1, char1, char2, num2, num3, num4, num5, num6, char3
6186   BULK COLLECT INTO
6187     l_index_tbl,
6188     l_item_desc_tbl,
6189     l_unit_of_measure_tbl,
6190     l_unit_price_tbl,
6191     l_category_id_tbl,
6192     l_un_number_id_tbl,
6193     l_hazard_class_id_tbl,
6194     l_market_price_tbl,
6195     l_secondary_unit_of_meas_tbl;
6196 
6197   d_position := 20;
6198 
6199   -- set the result in OUT parameters
6200   FOR i IN 1..l_index_tbl.COUNT
6201   LOOP
6202     l_index := l_index_tbl(i);
6203 
6204     IF (PO_LOG.d_stmt) THEN
6205       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
6206       PO_LOG.stmt(d_module, d_position, 'new item desc',
6207                   l_item_desc_tbl(i));
6208       PO_LOG.stmt(d_module, d_position, 'new unit of measure',
6209                   l_unit_of_measure_tbl(i));
6210       PO_LOG.stmt(d_module, d_position, 'new unit price',
6211                   l_unit_price_tbl(i));
6212       PO_LOG.stmt(d_module, d_position, 'new category id',
6213                   l_category_id_tbl(i));
6214       PO_LOG.stmt(d_module, d_position, 'new un number id',
6215                   l_un_number_id_tbl(i));
6216       PO_LOG.stmt(d_module, d_position, 'new hazard class id',
6217                   l_hazard_class_id_tbl(i));
6218       PO_LOG.stmt(d_module, d_position, 'new market price',
6219                   l_market_price_tbl(i));
6220       PO_LOG.stmt(d_module, d_position, 'new secondary unit of measure',
6221                   l_secondary_unit_of_meas_tbl(i));
6222     END IF;
6223 
6224     x_item_desc_tbl(l_index) := l_item_desc_tbl(i);
6225     x_unit_of_measure_tbl(l_index) := l_unit_of_measure_tbl(i);
6226     x_unit_price_tbl(l_index) := l_unit_price_tbl(i);
6227     x_category_id_tbl(l_index) := l_category_id_tbl(i);
6228     x_un_number_id_tbl(l_index) := l_un_number_id_tbl(i);
6229     x_hazard_class_id_tbl(l_index) := l_hazard_class_id_tbl(i);
6230     x_market_price_tbl(l_index) := l_market_price_tbl(i);
6231     x_secondary_unit_of_meas_tbl(l_index) := l_secondary_unit_of_meas_tbl(i);
6232   END LOOP;
6233 
6234   IF (PO_LOG.d_proc) THEN
6235     PO_LOG.proc_end(d_module);
6236   END IF;
6237 
6238 EXCEPTION
6239   WHEN OTHERS THEN
6240     PO_MESSAGE_S.add_exc_msg
6241     (
6242       p_pkg_name => d_pkg_name,
6243       p_procedure_name => d_api_name || '.' || d_position
6244     );
6245     RAISE;
6246 END default_info_from_item;
6247 
6248 -----------------------------------------------------------------------
6249 --Start of Comments
6250 --Name: default_info_from_job
6251 --Function:
6252 --  default information from job;
6253 --  the information can be defaulted from job include:
6254 --  1. item_description
6255 --  2. category_id
6256 --Parameters:
6257 --IN:
6258 --  p_key
6259 --    key used to identify rows in po_session_gt
6260 --  p_index_tbl
6261 --    table containging the indexes of all rows
6262 --  p_job_id_tbl
6263 --    list of job_ids read within the batch
6264 --IN OUT:
6265 --OUT:
6266 --  x_item_desc_tbl
6267 --    list of default values from job_ids
6268 --  x_category_id_tbl
6269 --    list of default values from job_ids
6270 --End of Comments
6271 ------------------------------------------------------------------------
6272 PROCEDURE default_info_from_job
6273 (
6274   p_key                        IN po_session_gt.key%TYPE,
6275   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
6276   p_job_id_tbl                 IN PO_TBL_NUMBER,
6277   x_item_desc_tbl              OUT NOCOPY PO_TBL_VARCHAR2000,
6278   x_category_id_tbl            OUT NOCOPY PO_TBL_NUMBER
6279 ) IS
6280 
6281   d_api_name CONSTANT VARCHAR2(30) := 'default_info_from_job';
6282   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
6283   d_position NUMBER;
6284 
6285   l_index                      NUMBER;
6286 
6287   -- variables to hold result read from temp table
6288   l_index_tbl                  PO_TBL_NUMBER;
6289   l_item_desc_tbl              PO_TBL_VARCHAR2000;
6290   l_category_id_tbl            PO_TBL_NUMBER;
6291 BEGIN
6292   d_position := 0;
6293 
6294   IF (PO_LOG.d_proc) THEN
6295     PO_LOG.proc_begin(d_module);
6296   END IF;
6297 
6298   x_item_desc_tbl              := PO_TBL_VARCHAR2000();
6299   x_category_id_tbl            := PO_TBL_NUMBER();
6300 
6301   x_item_desc_tbl.EXTEND(p_index_tbl.COUNT);
6302   x_category_id_tbl.EXTEND(p_index_tbl.COUNT);
6303 
6304   -- retrieve the values based on line type id
6305   FORALL i IN 1..p_index_tbl.COUNT
6306     INSERT INTO po_session_gt(key, num1, char1, num2)
6307     SELECT p_key,
6308            p_index_tbl(i),
6309            association.job_description,
6310            association.category_id
6311     FROM   po_job_associations association,
6312            per_jobs_vl job
6313     WHERE  job.job_id = p_job_id_tbl(i)
6314     AND    association.job_id = job.job_id
6315     AND    TRUNC(sysdate) < TRUNC(NVL(association.inactive_date, sysdate+1))
6316     AND    TRUNC(sysdate) BETWEEN TRUNC(NVL(job.date_from, sysdate))
6317            AND TRUNC(NVL(job.date_to, sysdate+1));
6318 
6319   d_position := 10;
6320 
6321   -- read result from temp table and delete the records at the same time
6322   DELETE FROM po_session_gt
6323   WHERE  key = p_key
6324   RETURNING num1, char1, num2
6325   BULK COLLECT INTO
6326     l_index_tbl,
6327     l_item_desc_tbl,
6328     l_category_id_tbl;
6329 
6330   d_position := 20;
6331 
6332   -- set the result in OUT parameters
6333   FOR i IN 1..l_index_tbl.COUNT
6334   LOOP
6335     l_index := l_index_tbl(i);
6336 
6337     IF (PO_LOG.d_stmt) THEN
6338       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
6339       PO_LOG.stmt(d_module, d_position, 'new item desc', l_item_desc_tbl(i));
6340       PO_LOG.stmt(d_module, d_position, 'new category id', l_category_id_tbl(i));
6341     END IF;
6342 
6343     x_item_desc_tbl(l_index) := l_item_desc_tbl(i);
6344     x_category_id_tbl(l_index) := l_category_id_tbl(i);
6345   END LOOP;
6346 
6347   IF (PO_LOG.d_proc) THEN
6348     PO_LOG.proc_end(d_module);
6349   END IF;
6350 
6351 EXCEPTION
6352   WHEN OTHERS THEN
6353     PO_MESSAGE_S.add_exc_msg
6354     (
6355       p_pkg_name => d_pkg_name,
6356       p_procedure_name => d_api_name || '.' || d_position
6357     );
6358     RAISE;
6359 END default_info_from_job;
6360 
6361 -----------------------------------------------------------------------
6362 --Start of Comments
6363 --Name: default_po_cat_id_from_ip
6364 --Function: default po category_id from ip_category_id
6365 --Parameters:
6366 --IN:
6367 --  p_key
6368 --    key used to identify rows in po_session_gt
6369 --  p_index_tbl
6370 --    table containging the indexes of all rows
6371 --  p_ip_category_id_tbl
6372 --    list of ip_category_ids read within the batch
6373 --IN OUT:
6374 --  x_po_category_id_tbl
6375 --    list of po_category_ids defaulted from ip_category_ids
6376 --OUT:
6377 --End of Comments
6378 ------------------------------------------------------------------------
6379 PROCEDURE default_po_cat_id_from_ip
6380 (
6381   p_key                        IN po_session_gt.key%TYPE,
6382   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
6383   p_ip_category_id_tbl         IN PO_TBL_NUMBER,
6384   x_po_category_id_tbl         IN OUT NOCOPY PO_TBL_NUMBER
6385 ) IS
6386 
6387   d_api_name CONSTANT VARCHAR2(30) := 'default_po_cat_id_from_ip';
6388   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
6389   d_position NUMBER;
6390 
6391   -- variables to hold result read from temp table
6392   l_index_tbl                  PO_TBL_NUMBER;
6393   l_result_tbl                 PO_TBL_NUMBER;
6394 BEGIN
6395   d_position := 0;
6396 
6397   IF (PO_LOG.d_proc) THEN
6398     PO_LOG.proc_begin(d_module, 'p_ip_category_id_tbl', p_ip_category_id_tbl);
6399     PO_LOG.proc_begin(d_module, 'x_po_category_id_tbl',
6400                       x_po_category_id_tbl);
6401   END IF;
6402 
6403   -- retrieve the values based on ip category id
6404   FORALL i IN 1..p_index_tbl.COUNT
6405     INSERT INTO po_session_gt(key, num1, num2)
6406     SELECT p_key,
6407            p_index_tbl(i),
6408            po_category_id
6409     FROM   icx_cat_shopping_cat_map_v
6410     WHERE  p_ip_category_id_tbl(i) IS NOT NULL
6411     AND    x_po_category_id_tbl(i) IS NULL
6412     AND    shopping_category_id = p_ip_category_id_tbl(i);
6413 
6414   d_position := 10;
6415 
6416   -- read result from temp table and delete the records at the same time
6417   DELETE FROM po_session_gt
6418   WHERE  key = p_key
6419   RETURNING num1, num2
6420   BULK COLLECT INTO l_index_tbl, l_result_tbl;
6421 
6422   d_position := 20;
6423 
6424   -- set the result in OUT parameters
6425   FOR i IN 1..l_index_tbl.COUNT
6426   LOOP
6427     IF (PO_LOG.d_stmt) THEN
6428       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
6429       PO_LOG.stmt(d_module, d_position, 'new po category id', l_result_tbl(i));
6430     END IF;
6431 
6432     x_po_category_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
6433   END LOOP;
6434 
6435   IF (PO_LOG.d_proc) THEN
6436     PO_LOG.proc_end(d_module);
6437   END IF;
6438 
6439 EXCEPTION
6440   WHEN OTHERS THEN
6441     PO_MESSAGE_S.add_exc_msg
6442     (
6443       p_pkg_name => d_pkg_name,
6444       p_procedure_name => d_api_name || '.' || d_position
6445     );
6446     RAISE;
6447 END default_po_cat_id_from_ip;
6448 
6449 -----------------------------------------------------------------------
6450 --Start of Comments
6451 --Name: default_ip_cat_id_from_po
6452 --Function: default ip_category_id from po category_id
6453 --Parameters:
6454 --IN:
6455 --  p_key
6456 --    key used to identify rows in po_session_gt
6457 --  p_index_tbl
6458 --    table containging the indexes of all rows
6459 --  p_po_category_id_tbl
6460 --    list of po_category_ids read within the batch
6461 --IN OUT:
6462 --  x_ip_category_id_tbl
6463 --    list of ip_category_ids defaulted from po_category_ids
6464 --OUT:
6465 --End of Comments
6466 ------------------------------------------------------------------------
6467 PROCEDURE default_ip_cat_id_from_po
6468 (
6469   p_key                        IN po_session_gt.key%TYPE,
6470   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
6471   p_po_category_id_tbl         IN PO_TBL_NUMBER,
6472   x_ip_category_id_tbl         IN OUT NOCOPY PO_TBL_NUMBER
6473 ) IS
6474 
6475   d_api_name CONSTANT VARCHAR2(30) := 'default_ip_cat_id_from_po';
6476   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
6477   d_position NUMBER;
6478 
6479   -- variables to hold result read from temp table
6480   l_index_tbl                  PO_TBL_NUMBER;
6481   l_result_tbl                 PO_TBL_NUMBER;
6482 BEGIN
6483   d_position := 0;
6484 
6485   IF (PO_LOG.d_proc) THEN
6486     PO_LOG.proc_begin(d_module, 'p_po_category_id_tbl', p_po_category_id_tbl);
6487     PO_LOG.proc_begin(d_module, 'x_ip_category_id_tbl',
6488                       x_ip_category_id_tbl);
6489   END IF;
6490 
6491   -- retrieve the values based on po category id
6492   FORALL i IN 1..p_index_tbl.COUNT
6493     INSERT INTO po_session_gt(key, num1, num2)
6494     SELECT p_key,
6495            p_index_tbl(i),
6496            shopping_category_id
6497     FROM   icx_cat_purchasing_cat_map_v
6498     WHERE  p_po_category_id_tbl(i) IS NOT NULL
6499     AND    x_ip_category_id_tbl(i) IS NULL
6500     AND    po_category_id = p_po_category_id_tbl(i);
6501 
6502   d_position := 10;
6503 
6504   -- read result from temp table and delete the records at the same time
6505   DELETE FROM po_session_gt
6506   WHERE  key = p_key
6507   RETURNING num1, num2
6508   BULK COLLECT INTO l_index_tbl, l_result_tbl;
6509 
6510   d_position := 20;
6511 
6512   -- set the result in OUT parameters
6513   FOR i IN 1..l_index_tbl.COUNT
6514   LOOP
6515     IF (PO_LOG.d_stmt) THEN
6516       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
6517       PO_LOG.stmt(d_module, d_position, 'new ip category id', l_result_tbl(i));
6518     END IF;
6519 
6520     x_ip_category_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
6521   END LOOP;
6522 
6523   IF (PO_LOG.d_proc) THEN
6524     PO_LOG.proc_end(d_module);
6525   END IF;
6526 
6527 EXCEPTION
6528   WHEN OTHERS THEN
6529     PO_MESSAGE_S.add_exc_msg
6530     (
6531       p_pkg_name => d_pkg_name,
6532       p_procedure_name => d_api_name || '.' || d_position
6533     );
6534     RAISE;
6535 END default_ip_cat_id_from_po;
6536 
6537 -----------------------------------------------------------------------
6538 --Start of Comments
6539 --Name: default_hc_id_from_un_number
6540 --Function: default hazard_class_id from un_number
6541 --Parameters:
6542 --IN:
6543 --  p_key
6544 --    key used to identify rows in po_session_gt
6545 --  p_index_tbl
6546 --    table containging the indexes of all rows
6547 --  p_un_number_tbl
6548 --    list of un_numbers read within the batch
6549 --IN OUT:
6550 --  x_hazard_class_id_tbl
6551 --    list of hazard_class_ids defaulted from un_numbers
6552 --OUT:
6553 --End of Comments
6554 ------------------------------------------------------------------------
6555 PROCEDURE default_hc_id_from_un_number
6556 (
6557   p_key                        IN po_session_gt.key%TYPE,
6558   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
6559   p_un_number_tbl              IN PO_TBL_VARCHAR30,
6560   x_hazard_class_id_tbl        IN OUT NOCOPY PO_TBL_NUMBER
6561 ) IS
6562 
6563   d_api_name CONSTANT VARCHAR2(30) := 'default_hc_id_from_un_number';
6564   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
6565   d_position NUMBER;
6566 
6567   -- variables to hold result read from temp table
6568   l_index_tbl                  PO_TBL_NUMBER;
6569   l_result_tbl                 PO_TBL_NUMBER;
6570 BEGIN
6571   d_position := 0;
6572 
6573   IF (PO_LOG.d_proc) THEN
6574     PO_LOG.proc_begin(d_module, 'p_un_number_tbl', p_un_number_tbl);
6575     PO_LOG.proc_begin(d_module, 'x_hazard_class_id_tbl',
6576                       x_hazard_class_id_tbl);
6577   END IF;
6578 
6579   -- retrieve the values based on line type id
6580   FORALL i IN 1..p_index_tbl.COUNT
6581     INSERT INTO po_session_gt(key, num1, num2)
6582     SELECT p_key,
6583            p_index_tbl(i),
6584            hazard_class_id
6585     FROM   po_un_numbers_vl
6586     WHERE  p_un_number_tbl(i) IS NOT NULL
6587     AND    x_hazard_class_id_tbl(i) IS NULL
6588     AND    sysdate < nvl(inactive_date, sysdate +1)
6589     AND    un_number = p_un_number_tbl(i);
6590 
6591   d_position := 10;
6592 
6593   -- read result from temp table and delete the records at the same time
6594   DELETE FROM po_session_gt
6595   WHERE  key = p_key
6596   RETURNING num1, num2
6597   BULK COLLECT INTO l_index_tbl, l_result_tbl;
6598 
6599   d_position := 20;
6600 
6601   -- set the result in OUT parameters
6602   FOR i IN 1..l_index_tbl.COUNT
6603   LOOP
6604     IF (PO_LOG.d_stmt) THEN
6605       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
6606       PO_LOG.stmt(d_module, d_position, 'new hazard class id', l_result_tbl(i));
6607     END IF;
6608 
6609     x_hazard_class_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
6610   END LOOP;
6611 
6612   IF (PO_LOG.d_proc) THEN
6613     PO_LOG.proc_end(d_module);
6614   END IF;
6615 
6616 EXCEPTION
6617   WHEN OTHERS THEN
6618     PO_MESSAGE_S.add_exc_msg
6619     (
6620       p_pkg_name => d_pkg_name,
6621       p_procedure_name => d_api_name || '.' || d_position
6622     );
6623     RAISE;
6624 END default_hc_id_from_un_number;
6625 
6626 -----------------------------------------------------------------------
6627 --Start of Comments
6628 --Name: match_lines_on_line_num
6629 --Function:
6630 --  If header action is 'ORIGINAL', 'REPLACE' or
6631 --  'UPDATE SPO', this procedure will be called
6632 --  to group the po lines and po line locations.
6633 --  The first criteria used is line_num
6634 --Parameters:
6635 --IN:
6636 --  p_index_tbl
6637 --    table containging the indexes of all rows
6638 --IN OUT:
6639 --  x_lines
6640 --    record containing line info within the batch
6641 --OUT:
6642 --End of Comments
6643 ------------------------------------------------------------------------
6644 PROCEDURE match_lines_on_line_num
6645 (
6646   p_index_tbl     DBMS_SQL.NUMBER_TABLE,
6647   x_lines         IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
6648 ) IS
6649 
6650   d_api_name CONSTANT VARCHAR2(30) := 'match_lines_on_line_num';
6651   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
6652   d_position NUMBER;
6653 
6654   -- hold the key value which is used to identify rows in temp table
6655   l_key           po_session_gt.key%TYPE;
6656 
6657   -- po line that has been found as a match for current line
6658   l_index_tbl          PO_TBL_NUMBER;
6659   l_result_tbl         PO_TBL_NUMBER;
6660 
6661   -- hash table of po_line_id based on po_header_id and line num
6662    --TYPE line_ref_type IS TABLE OF DBMS_SQL.NUMBER_TABLE INDEX BY PLS_INTEGER;
6663  	 -- Added as part of bug 8836290 to handle line_num's decimals also without grouping
6664  	   TYPE line_ref_internal_type IS TABLE OF NUMBER INDEX BY VARCHAR2(32);
6665  	   TYPE line_ref_type IS TABLE OF line_ref_internal_type INDEX BY PLS_INTEGER;
6666   l_line_reference_tbl line_ref_type;
6667   l_po_header_id   NUMBER;
6668   l_line_num       NUMBER;
6669 
6670   -- temp variable used in processing
6671   l_index          NUMBER;
6672   l_match_index    NUMBER;
6673 BEGIN
6674   d_position := 0;
6675 
6676   IF (PO_LOG.d_proc) THEN
6677     PO_LOG.proc_begin(d_module);
6678   END IF;
6679 
6680   -- get new key value for po_session_gt table
6681   l_key := PO_CORE_S.get_session_gt_nextval;
6682 
6683   -- match lines whose line_num is not null
6684   -- first, try to find matching line in draft table
6685   FORALL i IN 1..x_lines.rec_count
6686   INSERT INTO po_session_gt(key, num1, num2)
6687   SELECT l_key,
6688          p_index_tbl(i),
6689          po_line_id
6690   FROM   po_lines_draft_all
6691   WHERE  draft_id = x_lines.draft_id_tbl(i)
6692   AND    po_header_id = x_lines.po_header_id_tbl(i)
6693   AND    line_num = x_lines.line_num_tbl(i)
6694   AND    NVL(delete_flag, 'N') <> 'Y';
6695 
6696   d_position := 10;
6697 
6698   DELETE FROM po_session_gt
6699   WHERE  key = l_key
6700   RETURNING num1, num2
6701   BULK COLLECT INTO l_index_tbl, l_result_tbl;
6702 
6703   FOR i IN 1..l_index_tbl.COUNT
6704   LOOP
6705     l_index := l_index_tbl(i);
6706 
6707     IF (PO_LOG.d_stmt) THEN
6708       PO_LOG.stmt(d_module, d_position, 'index', l_index);
6709       PO_LOG.stmt(d_module, d_position, 'matched po line id', l_result_tbl(i));
6710     END IF;
6711 
6712     x_lines.po_line_id_tbl(l_index) := l_result_tbl(i);
6713     x_lines.action_tbl(l_index) := PO_PDOI_CONSTANTS.g_ACTION_UPDATE;
6714   END LOOP;
6715 
6716   d_position := 20;
6717 
6718   -- second, loop through the lines in batch to determine the matching
6719   FOR i IN 1..x_lines.rec_count
6720   LOOP
6721     IF (x_lines.line_num_tbl(i) IS NOT NULL AND
6722         x_lines.po_line_id_tbl(i) IS NULL) THEN
6723       l_po_header_id := x_lines.hd_po_header_id_tbl(i);
6724       l_line_num := x_lines.line_num_tbl(i);
6725 
6726       IF (PO_LOG.d_stmt) THEN
6727         PO_LOG.stmt(d_module, d_position, 'index', i);
6728         PO_LOG.stmt(d_module, d_position, 'po header id', l_po_header_id);
6729         PO_LOG.stmt(d_module, d_position, 'line num', l_line_num);
6730       END IF;
6731 
6732       IF (l_line_reference_tbl.EXISTS(l_po_header_id) AND
6733           l_line_reference_tbl(l_po_header_id).EXISTS(l_line_num)) THEN
6734         d_position := 30;
6735 
6736         x_lines.po_line_id_tbl(i) :=
6737           l_line_reference_tbl(l_po_header_id)(l_line_num);
6738         x_lines.action_tbl(i) := PO_PDOI_CONSTANTS.g_ACTION_UPDATE;
6739 
6740         IF (PO_LOG.d_stmt) THEN
6741           PO_LOG.stmt(d_module, d_position, 'match found for line num');
6742           PO_LOG.stmt(d_module, d_position, 'new po line id',
6743                       x_lines.po_line_id_tbl(i));
6744         END IF;
6745       ELSE
6746         d_position := 40;
6747 
6748         x_lines.po_line_id_tbl(i) :=
6749           PO_PDOI_MAINPROC_UTL_PVT.get_next_po_line_id;
6750         x_lines.action_tbl(i) := PO_PDOI_CONSTANTS.g_ACTION_ADD;
6751 
6752         l_line_reference_tbl(l_po_header_id)(l_line_num) :=
6753           x_lines.po_line_id_tbl(i);
6754 
6755         IF (PO_LOG.d_stmt) THEN
6756           PO_LOG.stmt(d_module, d_position, 'match not found for line num');
6757           PO_LOG.stmt(d_module, d_position, 'new po line id',
6758                       x_lines.po_line_id_tbl(i));
6759         END IF;
6760       END IF;
6761     END IF;
6762   END LOOP;
6763 
6764   IF (PO_LOG.d_proc) THEN
6765     PO_LOG.proc_end(d_module);
6766   END IF;
6767 
6768 EXCEPTION
6769   WHEN OTHERS THEN
6770     PO_MESSAGE_S.add_exc_msg
6771     (
6772       p_pkg_name => d_pkg_name,
6773       p_procedure_name => d_api_name || '.' || d_position
6774     );
6775     RAISE;
6776 END match_lines_on_line_num;
6777 
6778 -----------------------------------------------------------------------
6779 --Start of Comments
6780 --Name: match_lines_on_item_info
6781 --Function:
6782 --  If header action is 'ORIGINAL', or 'REPLACE',
6783 --  this procedure will be called to group the
6784 --  po lines and po line locations.
6785 --  this procedure match the lines based on
6786 --  item related info.
6787 --Parameters:
6788 --IN:
6789 --IN OUT:
6790 --  x_lines
6791 --    record containing line info within the batch
6792 --OUT:
6793 --End of Comments
6794 ------------------------------------------------------------------------
6795 PROCEDURE match_lines_on_item_info
6796 (
6797   x_lines         IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
6798 ) IS
6799 
6800   d_api_name CONSTANT VARCHAR2(30) := 'match_lines_on_item_info';
6801   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
6802   d_position NUMBER;
6803 
6804   -- hold the key value which is used to identify rows in temp table
6805   l_key           po_session_gt.key%TYPE;
6806   l_data_key      po_session_gt.key%TYPE;
6807 
6808   -- identify lines that are going to be processed
6809   l_processing_line_tbl DBMS_SQL.NUMBER_TABLE;
6810   l_num_list            DBMS_SQL.NUMBER_TABLE;
6811 
6812   -- po line that has been found as a match for current line
6813   l_index_tbl          PO_TBL_NUMBER;
6814   l_po_line_id_tbl     PO_TBL_NUMBER;
6815   l_line_num_tbl       PO_TBL_NUMBER;
6816   l_match_index_tbl    PO_TBL_NUMBER;
6817 
6818   -- temp variable used in processing
6819   l_index          NUMBER;
6820   l_match_index    NUMBER;
6821 BEGIN
6822   d_position := 0;
6823 
6824   IF (PO_LOG.d_proc) THEN
6825     PO_LOG.proc_begin(d_module);
6826   END IF;
6827 
6828   -- get key value for po_session_gt table
6829   l_key := PO_CORE_S.get_session_gt_nextval;
6830 
6831   -- First, get lines qualified. The qualified lines must satisfy the following conditions:
6832   -- 1. x_lines.line_num_tbl(i) IS NULL
6833   -- 2. x_lines.hd_actions(i) <> 'UPDATE'
6834   -- 3. x_lines.error_flag_tbl(i) = FND_API.G_FALSE
6835   -- 4. document is not AMOUNT based BLANKET
6836   FOR i IN 1..x_lines.rec_count
6837   LOOP
6838     IF (x_lines.line_num_tbl(i) IS NULL) THEN
6839       IF (x_lines.hd_action_tbl(i) <> PO_PDOI_CONSTANTS.g_ACTION_UPDATE AND
6840           x_lines.error_flag_tbl(i) = FND_API.g_FALSE AND
6841           NOT (x_lines.order_type_lookup_code_tbl(i) = 'AMOUNT' AND
6842                PO_PDOI_PARAMS.g_request.document_type =
6843                PO_PDOI_CONSTANTS.g_DOC_TYPE_BLANKET)) THEN
6844         IF (PO_LOG.d_stmt) THEN
6845           PO_LOG.stmt(d_module, d_position, 'processing index', i);
6846         END IF;
6847 
6848         l_processing_line_tbl(i) := i;
6849       ELSE
6850         -- all lines will be marked as 'ADD'
6851         x_lines.po_line_id_tbl(i) := PO_PDOI_MAINPROC_UTL_PVT.get_next_po_line_id;
6852         x_lines.line_num_tbl(i) :=
6853           PO_PDOI_MAINPROC_UTL_PVT.get_next_line_num(x_lines.po_header_id_tbl(i));
6854         x_lines.action_tbl(i) := PO_PDOI_CONSTANTS.g_ACTION_ADD;
6855 
6856         IF (PO_LOG.d_stmt) THEN
6857           PO_LOG.stmt(d_module, d_position, 'new po line id', x_lines.po_line_id_tbl(i));
6858           PO_LOG.stmt(d_module, d_position, 'new line num', x_lines.line_num_tbl(i));
6859         END IF;
6860       END IF;
6861     END IF;
6862   END LOOP;
6863 
6864   d_position := 10;
6865 
6866   -- perform matching logic for qualified lines
6867   -- a. match on draft table
6868   -- a.1 match on draft table when item_id is not null
6869   FORALL i IN INDICES OF l_processing_line_tbl
6870     INSERT INTO po_session_gt(key, num1, num2, num3)
6871     SELECT l_key,
6872            l_processing_line_tbl(i),
6873            po_line_id,
6874            line_num
6875     FROM   po_lines_draft_all
6876     WHERE  x_lines.item_id_tbl(i) IS NOT NULL
6877     AND    draft_id = x_lines.draft_id_tbl(i)
6878     AND    po_header_id = x_lines.po_header_id_tbl(i)
6879     AND    item_id = x_lines.item_id_tbl(i)
6880     AND    (item_revision = x_lines.item_revision_tbl(i) OR
6881             item_revision IS NULL OR
6882             x_Lines.item_revision_tbl(i) IS NULL)
6883     AND     unit_meas_lookup_code = x_lines.unit_of_measure_tbl(i)
6884     AND     line_type_id = x_lines.line_type_id_tbl(i)
6885     AND     category_id = x_lines.category_id_tbl(i)
6886     AND    NVL(delete_flag, 'N') <> 'Y';
6887 
6888   d_position := 20;
6889 
6890   -- a.2 match on draft table when item_id is null
6891   FORALL i IN INDICES OF l_processing_line_tbl
6892     INSERT INTO po_session_gt(key, num1, num2, num3)
6893     SELECT l_key,
6894            l_processing_line_tbl(i),
6895            po_line_id,
6896            line_num
6897     FROM   po_lines_draft_all
6898     WHERE  x_lines.item_id_tbl(i) IS NULL
6899     AND    draft_id = x_lines.draft_id_tbl(i)
6900     AND    po_header_id = x_lines.po_header_id_tbl(i)
6901     AND    item_description = x_lines.item_desc_tbl(i)
6902     AND    unit_meas_lookup_code = x_lines.unit_of_measure_tbl(i)
6903     AND    line_type_id = x_lines.line_type_id_tbl(i)
6904     AND    category_id = x_lines.category_id_tbl(i)
6905     AND    NVL(delete_flag, 'N') <> 'Y';
6906 
6907   d_position := 30;
6908 
6909   -- get result from temp table
6910   DELETE FROM po_session_gt
6911   WHERE key = l_key
6912   RETURNING num1, num2, num3
6913   BULK COLLECT INTO l_index_tbl, l_po_line_id_tbl, l_line_num_tbl;
6914 
6915   -- set the po_line_id and line_num from matching line
6916   -- so there is no new line created from this row
6917   FOR i IN 1..l_index_tbl.COUNT
6918   LOOP
6919     l_index := l_index_tbl(i);
6920 
6921     IF (PO_LOG.d_stmt) THEN
6922       PO_LOG.stmt(d_module, d_position, 'index', l_index);
6923       PO_LOG.stmt(d_module, d_position, 'matched po line id', l_po_line_id_tbl(i));
6924       PO_LOG.stmt(d_module, d_position, 'matched line num', l_line_num_tbl(i));
6925     END IF;
6926 
6927     x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
6928     x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
6929     x_lines.action_tbl(l_index) := PO_PDOI_CONSTANTS.g_ACTION_UPDATE;
6930     -- delete the corresponding node so the line won't be matched within batch
6931     l_processing_line_tbl.DELETE(i);
6932   END LOOP;
6933 
6934   d_position := 40;
6935 
6936   -- b. match within the same batch
6937   l_data_key := PO_CORE_S.get_session_gt_nextval;
6938   -- initialize table containing the row number(index)
6939   PO_PDOI_UTL.generate_ordered_num_list
6940   (
6941     p_size     => x_lines.rec_count,
6942     x_num_list => l_num_list
6943   );
6944 
6945   FORALL i IN 1..x_lines.rec_count
6946     INSERT INTO po_session_gt(key, num1, num2, num3, char1, char2,
6947                               num4, num5, char3, char4, num6)
6948     VALUES (l_data_key,
6949             x_lines.intf_line_id_tbl(i),           -- num1
6950             x_lines.po_header_id_tbl(i),           -- num2
6951             x_lines.item_id_tbl(i),                -- num3
6952             x_lines.item_revision_tbl(i),          -- char1
6953             x_lines.unit_of_measure_tbl(i),        -- char2
6954             x_lines.line_type_id_tbl(i),           -- num4
6955             x_lines.category_id_tbl(i),            -- num5
6956             x_lines.item_desc_tbl(i),              -- char3
6957             x_lines.order_type_lookup_code_tbl(i), -- char4
6958             l_num_list(i)                          -- num6
6959            );
6960 
6961   d_position := 50;
6962 
6963   -- find lines that cannot find a match in the batch
6964   -- a. check lines where item_id is not null
6965   FORALL i IN INDICES OF l_processing_line_tbl
6966     INSERT INTO po_session_gt(key, num1)
6967     SELECT l_key,
6968            l_processing_line_tbl(i)
6969     FROM   DUAL
6970     WHERE  x_lines.item_id_tbl(i) IS NOT NULL
6971     AND    NOT EXISTS(
6972             SELECT 1
6973             FROM   po_session_gt gt
6974             WHERE  gt.num2 = x_lines.po_header_id_tbl(i)
6975             AND    gt.num1 < x_lines.intf_line_id_tbl(i)
6976             AND    gt.num3 = x_lines.item_id_tbl(i)
6977             AND    (gt.char1 = x_lines.item_revision_tbl(i) OR
6978                     gt.char1 IS NULL OR
6979                     x_lines.item_revision_tbl(i) IS NULL)
6980             AND    gt.char2 = x_lines.unit_of_measure_tbl(i)
6981             AND    gt.num4 = x_lines.line_type_id_tbl(i)
6982             AND    gt.num5 = x_lines.category_id_tbl(i)
6983            );
6984 
6985   d_position := 60;
6986 
6987   -- b. check lines when item_id = null
6988   FORALL i IN INDICES OF l_processing_line_tbl
6989     INSERT INTO po_session_gt(key, num1)
6990     SELECT l_key,
6991            l_processing_line_tbl(i)
6992     FROM   DUAL
6993     WHERE  x_lines.item_id_tbl(i) IS NULL
6994     AND    NOT EXISTS(
6995             SELECT 1
6996             FROM   po_session_gt gt
6997             WHERE  gt.num2 = x_lines.po_header_id_tbl(i)
6998             AND    gt.num1 < x_lines.intf_line_id_tbl(i)
6999             AND    gt.char3 = x_lines.item_desc_tbl(i)
7000             AND    gt.char2 = x_lines.unit_of_measure_tbl(i)
7001             AND    gt.num4 = x_lines.line_type_id_tbl(i)
7002             AND    gt.num5 = x_lines.category_id_tbl(i)
7003            );
7004 
7005   d_position := 70;
7006 
7007   -- get result from temp table
7008   DELETE FROM po_session_gt
7009   WHERE key = l_key
7010   RETURNING num1 BULK COLLECT INTO l_index_tbl;
7011 
7012   -- assign a new po_line_id and line_num to these lines
7013   /* bug 8295593 changed the value from 'i' to 'l_index' in the below assignment statement and delete node statement.
7014    When 'i' value in place, the two statements where fix is done, fetching value for the next i value instead next index value*/
7015 
7016   FOR i IN 1..l_index_tbl.COUNT
7017   LOOP
7018     l_index := l_index_tbl(i);
7019 
7020     x_lines.po_line_id_tbl(l_index) := PO_PDOI_MAINPROC_UTL_PVT.get_next_po_line_id;
7021     x_lines.action_tbl(l_index) := PO_PDOI_CONSTANTS.g_ACTION_ADD;
7022     x_lines.line_num_tbl(l_index) := PO_PDOI_MAINPROC_UTL_PVT.get_next_line_num(x_lines.po_header_id_tbl(l_index));  --bug 8295593
7023     -- delete the corresponding node so the line won't be matched within batch
7024     l_processing_line_tbl.DELETE(l_index);  --bug 8295593
7025 
7026     IF (PO_LOG.d_stmt) THEN
7027       PO_LOG.stmt(d_module, d_position, 'index', l_index);
7028       PO_LOG.stmt(d_module, d_position, 'assigned po line id',
7029                   x_lines.po_line_id_tbl(l_index));
7030       PO_LOG.stmt(d_module, d_position, 'assigned line num', x_lines.line_num_tbl(l_index));
7031     END IF;
7032   END LOOP;
7033 
7034   d_position := 80;
7035 
7036   -- Last, for lines that can find at least one match in current batch,
7037   -- return one matching line that has the smallest interface_line_id
7038   FORALL i IN INDICES OF l_processing_line_tbl
7039     INSERT INTO po_session_gt(key, num1, num2)
7040     SELECT l_key,
7041            l_processing_line_tbl(i),
7042            v.min_index
7043     FROM   (SELECT min(num6) AS min_index
7044             FROM   po_session_gt
7045             WHERE  x_lines.item_id_tbl(i) IS NOT NULL
7046             AND    num2  = x_lines.po_header_id_tbl(i)
7047             AND    num1 < x_lines.intf_line_id_tbl(i)
7048             AND    num3 = x_lines.item_id_tbl(i)
7049             AND    (char1 = x_lines.item_revision_tbl(i) OR
7050                     char1 IS NULL OR
7051                     x_lines.item_revision_tbl(i) IS NULL)
7052             AND    char2 = x_lines.unit_of_measure_tbl(i)
7053             AND    num4 = x_lines.line_type_id_tbl(i)
7054             AND    num5 = x_lines.category_id_tbl(i)) v
7055     WHERE  v.min_index IS NOT NULL;
7056 
7057   d_position := 90;
7058 
7059   FORALL i IN INDICES OF l_processing_line_tbl
7060     INSERT INTO po_session_gt(key, num1, num2)
7061     SELECT l_key,
7062            l_processing_line_tbl(i),
7063            v.min_index
7064     FROM   (SELECT min(num6) AS min_index
7065             FROM   po_session_gt
7066             WHERE  x_lines.item_id_tbl(i) IS NULL
7067             AND    num2 = x_lines.po_header_id_tbl(i)
7068             AND    num1 < x_lines.intf_line_id_tbl(i)
7069             AND    char3 = x_lines.item_desc_tbl(i)
7070             AND    char2 = x_lines.unit_of_measure_tbl(i)
7071             AND    num4 = x_lines.line_type_id_tbl(i)
7072             AND    num5 = x_lines.category_id_tbl(i)) v
7073     WHERE   v.min_index IS NOT NULL;
7074 
7075   d_position := 100;
7076 
7077   DELETE FROM po_session_gt
7078   WHERE key = l_key
7079   RETURNING num1, num2 BULK COLLECT INTO l_index_tbl, l_match_index_tbl;
7080 
7081   IF (PO_LOG.d_stmt) THEN
7082     PO_LOG.stmt(d_module, d_position, 'l_index_tbl', l_index_tbl);
7083     PO_LOG.stmt(d_module, d_position, 'l_match_index_tbl', l_match_index_tbl);
7084   END IF;
7085 
7086   FOR i IN 1..l_index_tbl.COUNT
7087   LOOP
7088     l_index := l_index_tbl(i);
7089     l_match_index := l_match_index_tbl(i);
7090 
7091     x_lines.po_line_id_tbl(l_index) := x_lines.po_line_id_tbl(l_match_index);
7092     x_lines.line_num_tbl(l_index) := x_lines.line_num_tbl(l_match_index);
7093     x_lines.action_tbl(l_index) := PO_PDOI_CONSTANTS.g_ACTION_UPDATE;
7094 
7095     IF (PO_LOG.d_stmt) THEN
7096       PO_LOG.stmt(d_module, d_position, 'index', l_index);
7097       PO_LOG.stmt(d_module, d_position, 'match index', l_match_index);
7098       PO_LOG.stmt(d_module, d_position, 'matched po line id',
7099                   x_lines.po_line_id_tbl(l_index));
7100       PO_LOG.stmt(d_module, d_position, 'matched line num', x_lines.line_num_tbl(l_index));
7101     END IF;
7102   END LOOP;
7103 
7104   d_position := 110;
7105 
7106   -- clean up po_session_gt
7107   PO_PDOI_UTL.remove_session_gt_records
7108   ( p_key => l_data_key
7109   );
7110 
7111   IF (PO_LOG.d_proc) THEN
7112     PO_LOG.proc_end(d_module);
7113   END IF;
7114 
7115 EXCEPTION
7116   WHEN OTHERS THEN
7117     PO_MESSAGE_S.add_exc_msg
7118     (
7119       p_pkg_name => d_pkg_name,
7120       p_procedure_name => d_api_name || '.' || d_position
7121     );
7122     RAISE;
7123 END match_lines_on_item_info;
7124 
7125 -----------------------------------------------------------------------
7126 --Start of Comments
7127 --Name: copy_lines
7128 --Function:
7129 --  copy all the attribute values from one po_line to another
7130 --Parameters:
7131 --IN:
7132 --  p_source_lines
7133 --    source of copy action
7134 --  p_source_index_tbl
7135 --    the indexes of line to be copied
7136 --IN OUT:
7137 --  x_target_lines
7138 --    record containing lines copied from source line
7139 --OUT:
7140 --End of Comments
7141 ------------------------------------------------------------------------
7142 PROCEDURE copy_lines
7143 (
7144   p_source_lines     IN PO_PDOI_TYPES.lines_rec_type,
7145   p_source_index_tbl IN DBMS_SQL.NUMBER_TABLE,
7146   x_target_lines     IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
7147 ) IS
7148 
7149   d_api_name CONSTANT VARCHAR2(30) := 'copy_lines';
7150   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
7151   d_position NUMBER;
7152 
7153   l_source_index NUMBER;
7154   l_target_index NUMBER :=0;
7155 BEGIN
7156   d_position := 0;
7157 
7158   IF (PO_LOG.d_proc) THEN
7159     PO_LOG.proc_begin(d_module);
7160   END IF;
7161 
7162   -- bug5107324
7163   -- Refactored the code as PO_PDOI_TYPES.fill_all_lines_attr already does
7164   -- all the initialization work for all attributes in lines
7165 
7166   -- bug5129752
7167   -- Move the initialization up front
7168 
7169   -- initialize the tables
7170   PO_PDOI_TYPES.fill_all_lines_attr
7171   ( p_num_records => p_source_index_tbl.COUNT,
7172     x_lines       => x_target_lines
7173   );
7174 
7175   IF (p_source_index_tbl.COUNT = 0) THEN
7176 
7177     IF (PO_LOG.d_proc) THEN
7178       PO_LOG.proc_end(d_module, 'no line is copied', p_source_index_tbl.COUNT);
7179     END IF;
7180 
7181     RETURN;
7182   END IF;
7183 
7184   l_source_index := p_source_index_tbl.FIRST;
7185   WHILE (l_source_index IS NOT NULL)
7186   LOOP
7187     -- increase target index
7188     l_target_index := l_target_index + 1;
7189 
7190     d_position := 20;
7191 
7192     -- copy line interface attributes
7193     x_target_lines.intf_line_id_tbl(l_target_index) := p_source_lines.intf_line_id_tbl(l_source_index);
7194     x_target_lines.intf_header_id_tbl(l_target_index) := p_source_lines.intf_header_id_tbl(l_source_index);
7195     x_target_lines.po_header_id_tbl(l_target_index) := p_source_lines.po_header_id_tbl(l_source_index);
7196     x_target_lines.po_line_id_tbl(l_target_index) := p_source_lines.po_line_id_tbl(l_source_index);
7197     x_target_lines.action_tbl(l_target_index) := p_source_lines.action_tbl(l_source_index);
7198     x_target_lines.document_num_tbl(l_target_index) := p_source_lines.document_num_tbl(l_source_index);
7199     x_target_lines.item_tbl(l_target_index) := p_source_lines.item_tbl(l_source_index);
7200     x_target_lines.vendor_product_num_tbl(l_target_index) := p_source_lines.vendor_product_num_tbl(l_source_index);
7201     x_target_lines.supplier_part_auxid_tbl(l_target_index) := p_source_lines.supplier_part_auxid_tbl(l_source_index);
7202     x_target_lines.item_id_tbl(l_target_index) := p_source_lines.item_id_tbl(l_source_index);
7203     x_target_lines.item_revision_tbl(l_target_index) := p_source_lines.item_revision_tbl(l_source_index);
7204     x_target_lines.job_business_group_name_tbl(l_target_index) := p_source_lines.job_business_group_name_tbl(l_source_index);
7205     x_target_lines.job_business_group_id_tbl(l_target_index) := p_source_lines.job_business_group_id_tbl(l_source_index);
7206     x_target_lines.job_name_tbl(l_target_index) := p_source_lines.job_name_tbl(l_source_index);
7207     x_target_lines.job_id_tbl(l_target_index) := p_source_lines.job_id_tbl(l_source_index);
7208     x_target_lines.category_tbl(l_target_index) := p_source_lines.category_tbl(l_source_index);
7209     x_target_lines.category_id_tbl(l_target_index) := p_source_lines.category_id_tbl(l_source_index);
7210     x_target_lines.ip_category_tbl(l_target_index) := p_source_lines.ip_category_tbl(l_source_index);
7211     x_target_lines.ip_category_id_tbl(l_target_index) := p_source_lines.ip_category_id_tbl(l_source_index);
7212     x_target_lines.uom_code_tbl(l_target_index) := p_source_lines.uom_code_tbl(l_source_index);
7213     x_target_lines.unit_of_measure_tbl(l_target_index) := p_source_lines.unit_of_measure_tbl(l_source_index);
7214     x_target_lines.line_type_tbl(l_target_index) := p_source_lines.line_type_tbl(l_source_index);
7215     x_target_lines.line_type_id_tbl(l_target_index) := p_source_lines.line_type_id_tbl(l_source_index);
7216     x_target_lines.un_number_tbl(l_target_index) := p_source_lines.un_number_tbl(l_source_index);
7217     x_target_lines.un_number_id_tbl(l_target_index) := p_source_lines.un_number_id_tbl(l_source_index);
7218     x_target_lines.hazard_class_tbl(l_target_index) := p_source_lines.hazard_class_tbl(l_source_index);
7219     x_target_lines.hazard_class_id_tbl(l_target_index) := p_source_lines.hazard_class_id_tbl(l_source_index);
7220     x_target_lines.template_name_tbl(l_target_index) := p_source_lines.template_name_tbl(l_source_index);
7221     x_target_lines.template_id_tbl(l_target_index) := p_source_lines.template_id_tbl(l_source_index);
7222     x_target_lines.item_desc_tbl(l_target_index) := p_source_lines.item_desc_tbl(l_source_index);
7223     x_target_lines.unit_price_tbl(l_target_index) := p_source_lines.unit_price_tbl(l_source_index);
7224     x_target_lines.base_unit_price_tbl(l_target_index) := p_source_lines.base_unit_price_tbl(l_source_index);
7225     x_target_lines.from_header_id_tbl(l_target_index) := p_source_lines.from_header_id_tbl(l_source_index);
7226     x_target_lines.from_line_id_tbl(l_target_index) := p_source_lines.from_line_id_tbl(l_source_index);
7227     x_target_lines.list_price_per_unit_tbl(l_target_index) := p_source_lines.list_price_per_unit_tbl(l_source_index);
7228     x_target_lines.market_price_tbl(l_target_index) := p_source_lines.market_price_tbl(l_source_index);
7229     x_target_lines.capital_expense_flag_tbl(l_target_index) := p_source_lines.capital_expense_flag_tbl(l_source_index);
7230     x_target_lines.min_release_amount_tbl(l_target_index) := p_source_lines.min_release_amount_tbl(l_source_index);
7231     x_target_lines.allow_price_override_flag_tbl(l_target_index) := p_source_lines.allow_price_override_flag_tbl(l_source_index);
7232     x_target_lines.price_type_tbl(l_target_index) := p_source_lines.price_type_tbl(l_source_index);
7233     x_target_lines.price_break_lookup_code_tbl(l_target_index) := p_source_lines.price_break_lookup_code_tbl(l_source_index);
7234     x_target_lines.closed_code_tbl(l_target_index) := p_source_lines.closed_code_tbl(l_source_index);
7235     x_target_lines.quantity_tbl(l_target_index) := p_source_lines.quantity_tbl(l_source_index);
7236     x_target_lines.line_num_tbl(l_target_index) := p_source_lines.line_num_tbl(l_source_index);
7237     x_target_lines.shipment_num_tbl(l_target_index) := p_source_lines.shipment_num_tbl(l_source_index);
7238     x_target_lines.price_chg_accept_flag_tbl(l_target_index) := p_source_lines.price_chg_accept_flag_tbl(l_source_index);
7239     x_target_lines.effective_date_tbl(l_target_index) := p_source_lines.effective_date_tbl(l_source_index);
7240     x_target_lines.expiration_date_tbl(l_target_index) := p_source_lines.expiration_date_tbl(l_source_index);
7241     x_target_lines.attribute14_tbl(l_target_index) := p_source_lines.attribute14_tbl(l_source_index);
7242     x_target_lines.price_update_tolerance_tbl(l_target_index) := p_source_lines.price_update_tolerance_tbl(l_source_index);
7243     -- << PDOI for Complex PO Project: Start >>
7244     x_target_lines.retainage_rate_tbl(l_target_index) := p_source_lines.retainage_rate_tbl(l_source_index);
7245     x_target_lines.max_retainage_amount_tbl(l_target_index) := p_source_lines.max_retainage_amount_tbl(l_source_index);
7246     x_target_lines.progress_payment_rate_tbl(l_target_index) := p_source_lines.progress_payment_rate_tbl(l_source_index);
7247     x_target_lines.recoupment_rate_tbl(l_target_index) := p_source_lines.recoupment_rate_tbl(l_source_index);
7248     x_target_lines.advance_amount_tbl(l_target_index) := p_source_lines.advance_amount_tbl(l_source_index);
7249     -- << PDOI for Complex PO Project: End >>
7250     x_target_lines.error_flag_tbl(l_target_index) := p_source_lines.error_flag_tbl(l_source_index);
7251     x_target_lines.need_to_reject_flag_tbl(l_target_index) := p_source_lines.need_to_reject_flag_tbl(l_source_index);
7252     x_target_lines.line_loc_populated_flag_tbl(l_target_index) := p_source_lines.line_loc_populated_flag_tbl(l_source_index);
7253     x_target_lines.negotiated_flag_tbl(l_target_index) := p_source_lines.negotiated_flag_tbl(l_source_index);
7254     x_target_lines.amount_tbl(l_target_index) := p_source_lines.amount_tbl(l_source_index);
7255     x_target_lines.contractor_last_name_tbl(l_target_index) := p_source_lines.contractor_last_name_tbl(l_source_index);
7256     x_target_lines.contractor_first_name_tbl(l_target_index) := p_source_lines.contractor_first_name_tbl(l_source_index);
7257     x_target_lines.over_tolerance_err_flag_tbl(l_target_index) := p_source_lines.over_tolerance_err_flag_tbl(l_source_index);
7258     x_target_lines.not_to_exceed_price_tbl(l_target_index) := p_source_lines.not_to_exceed_price_tbl(l_source_index);
7259     x_target_lines.po_release_id_tbl(l_target_index) := p_source_lines.po_release_id_tbl(l_source_index);
7260     x_target_lines.release_num_tbl(l_target_index) := p_source_lines.release_num_tbl(l_source_index);
7261     x_target_lines.source_shipment_id_tbl(l_target_index) := p_source_lines.source_shipment_id_tbl(l_source_index);
7262     x_target_lines.contract_num_tbl(l_target_index) := p_source_lines.contract_num_tbl(l_source_index);
7263     x_target_lines.contract_id_tbl(l_target_index) := p_source_lines.contract_id_tbl(l_source_index);
7264     x_target_lines.type_1099_tbl(l_target_index) := p_source_lines.type_1099_tbl(l_source_index);
7265     x_target_lines.closed_by_tbl(l_target_index) := p_source_lines.closed_by_tbl(l_source_index);
7266     x_target_lines.closed_date_tbl(l_target_index) := p_source_lines.closed_date_tbl(l_source_index);
7267     x_target_lines.committed_amount_tbl(l_target_index) := p_source_lines.committed_amount_tbl(l_source_index);
7268     x_target_lines.qty_rcv_exception_code_tbl(l_target_index) := p_source_lines.qty_rcv_exception_code_tbl(l_source_index);
7269     x_target_lines.weight_uom_code_tbl(l_target_index) := p_source_lines.weight_uom_code_tbl(l_source_index);
7270     x_target_lines.volume_uom_code_tbl(l_target_index) := p_source_lines.volume_uom_code_tbl(l_source_index);
7271     x_target_lines.secondary_unit_of_meas_tbl(l_target_index) := p_source_lines.secondary_unit_of_meas_tbl(l_source_index);
7272     x_target_lines.secondary_quantity_tbl(l_target_index) := p_source_lines.secondary_quantity_tbl(l_source_index);
7273     x_target_lines.preferred_grade_tbl(l_target_index) := p_source_lines.preferred_grade_tbl(l_source_index);
7274     x_target_lines.process_code_tbl(l_target_index) := p_source_lines.process_code_tbl(l_source_index);
7275     x_target_lines.parent_interface_line_id_tbl(l_target_index) := p_source_lines.parent_interface_line_id_tbl(l_source_index); -- bug5149827
7276     x_target_lines.clm_info_flag_tbl(l_target_index) := p_source_lines.clm_info_flag_tbl(l_source_index); /* 10354034 */
7277 
7278     d_position := 30;
7279 
7280     -- copy standard who columns
7281     x_target_lines.last_updated_by_tbl(l_target_index) := p_source_lines.last_updated_by_tbl(l_source_index);
7282     x_target_lines.last_update_date_tbl(l_target_index) := p_source_lines.last_update_date_tbl(l_source_index);
7283     x_target_lines.last_update_login_tbl(l_target_index) := p_source_lines.last_update_login_tbl(l_source_index);
7284     x_target_lines.creation_date_tbl(l_target_index) := p_source_lines.creation_date_tbl(l_source_index);
7285     x_target_lines.created_by_tbl(l_target_index) := p_source_lines.created_by_tbl(l_source_index);
7286     x_target_lines.request_id_tbl(l_target_index) := p_source_lines.request_id_tbl(l_source_index);
7287     x_target_lines.program_application_id_tbl(l_target_index) := p_source_lines.program_application_id_tbl(l_source_index);
7288     x_target_lines.program_id_tbl(l_target_index) := p_source_lines.program_id_tbl(l_source_index);
7289     x_target_lines.program_update_date_tbl(l_target_index) := p_source_lines.program_update_date_tbl(l_source_index);
7290 
7291     d_position := 40;
7292 
7293     -- copy attributes from header
7294     x_target_lines.draft_id_tbl(l_target_index) := p_source_lines.draft_id_tbl(l_source_index);
7295     x_target_lines.hd_action_tbl(l_target_index) := p_source_lines.hd_action_tbl(l_source_index);
7296     x_target_lines.hd_po_header_id_tbl(l_target_index) := p_source_lines.hd_po_header_id_tbl(l_source_index);
7297     x_target_lines.hd_vendor_id_tbl(l_target_index) := p_source_lines.hd_vendor_id_tbl(l_source_index);
7298     x_target_lines.hd_min_release_amount_tbl(l_target_index) := p_source_lines.hd_min_release_amount_tbl(l_source_index);
7299     x_target_lines.hd_start_date_tbl(l_target_index) := p_source_lines.hd_start_date_tbl(l_source_index);
7300     x_target_lines.hd_end_date_tbl(l_target_index) := p_source_lines.hd_end_date_tbl(l_source_index);
7301     x_target_lines.hd_global_agreement_flag_tbl(l_target_index) := p_source_lines.hd_global_agreement_flag_tbl(l_source_index);
7302     x_target_lines.hd_currency_code_tbl(l_target_index) := p_source_lines.hd_currency_code_tbl(l_source_index);
7303     x_target_lines.hd_created_language_tbl(l_target_index) := p_source_lines.hd_created_language_tbl(l_source_index);
7304     x_target_lines.hd_style_id_tbl(l_target_index) := p_source_lines.hd_style_id_tbl(l_source_index);
7305     x_target_lines.hd_rate_type_tbl(l_target_index) := p_source_lines.hd_rate_type_tbl(l_source_index);
7306 
7307     -- copy processing attributes
7308     x_target_lines.create_line_loc_tbl(l_target_index) := p_source_lines.create_line_loc_tbl(l_source_index);
7309     x_target_lines.order_type_lookup_code_tbl(l_target_index) := p_source_lines.order_type_lookup_code_tbl(l_source_index);
7310     x_target_lines.purchase_basis_tbl(l_target_index) := p_source_lines.purchase_basis_tbl(l_source_index);
7311     x_target_lines.matching_basis_tbl(l_target_index) := p_source_lines.matching_basis_tbl(l_source_index);
7312     x_target_lines.unordered_flag_tbl(l_target_index) := p_source_lines.unordered_flag_tbl(l_source_index);
7313     x_target_lines.cancel_flag_tbl(l_target_index) := p_source_lines.cancel_flag_tbl(l_source_index);
7314     x_target_lines.quantity_committed_tbl(l_target_index) := p_source_lines.quantity_committed_tbl(l_source_index);
7315     x_target_lines.tax_attribute_update_code_tbl(l_target_index) := p_source_lines.tax_attribute_update_code_tbl(l_source_index);
7316     x_target_lines.allow_desc_update_flag_tbl(l_target_index) := p_source_lines.allow_desc_update_flag_tbl(l_source_index); -- bug5107324
7317 
7318     ----CLM PDOI Integration Project Starts
7319     x_target_lines.contract_type_tbl(l_target_index) := p_source_lines.contract_type_tbl(l_source_index);
7320     x_target_lines.cost_constraint_tbl(l_target_index) := p_source_lines.cost_constraint_tbl(l_source_index);
7321     x_target_lines.note_to_vendor_tbl(l_target_index) := p_source_lines.note_to_vendor_tbl(l_source_index);
7322     x_target_lines.oke_contract_version_id_tbl(l_target_index) := p_source_lines.oke_contract_version_id_tbl(l_source_index);
7323     x_target_lines.oke_contract_header_id_tbl(l_target_index) := p_source_lines.oke_contract_header_id_tbl(l_source_index);
7324     x_target_lines.clm_option_indicator_tbl(l_target_index) := p_source_lines.clm_option_indicator_tbl(l_source_index);
7325     x_target_lines.clm_base_line_num_tbl(l_target_index) := p_source_lines.clm_base_line_num_tbl(l_source_index);
7326     x_target_lines.clm_option_num_tbl(l_target_index) := p_source_lines.clm_option_num_tbl(l_source_index);
7327     x_target_lines.clm_option_from_date_tbl(l_target_index) := p_source_lines.clm_option_from_date_tbl(l_source_index);
7328     x_target_lines.clm_option_to_date_tbl(l_target_index) := p_source_lines.clm_option_to_date_tbl(l_source_index);
7329     x_target_lines.clm_idc_type_tbl(l_target_index) := p_source_lines.clm_idc_type_tbl(l_source_index);
7330     x_target_lines.line_num_display_tbl(l_target_index) := p_source_lines.line_num_display_tbl(l_source_index);
7331     x_target_lines.clm_funded_flag_tbl(l_target_index) := p_source_lines.clm_funded_flag_tbl(l_source_index);
7332     x_target_lines.user_document_status_tbl(l_target_index) := p_source_lines.user_document_status_tbl(l_source_index);
7333     x_target_lines.clm_exercised_flag_tbl(l_target_index) := p_source_lines.clm_exercised_flag_tbl(l_source_index);
7334     x_target_lines.clm_exercised_date_tbl(l_target_index) := p_source_lines.clm_exercised_date_tbl(l_source_index);
7335     x_target_lines.clm_min_total_amount_tbl(l_target_index) := p_source_lines.clm_min_total_amount_tbl(l_source_index);
7336     x_target_lines.clm_max_total_amount_tbl(l_target_index) := p_source_lines.clm_max_total_amount_tbl(l_source_index);
7337     x_target_lines.clm_min_total_quantity_tbl(l_target_index) := p_source_lines.clm_min_total_quantity_tbl(l_source_index);
7338     x_target_lines.clm_max_total_quantity_tbl(l_target_index) := p_source_lines.clm_max_total_quantity_tbl(l_source_index);
7339     x_target_lines.clm_min_order_amount_tbl(l_target_index) := p_source_lines.clm_min_order_amount_tbl(l_source_index);
7340     x_target_lines.clm_max_order_amount_tbl(l_target_index) := p_source_lines.clm_max_order_amount_tbl(l_source_index);
7341     x_target_lines.clm_min_order_quantity_tbl(l_target_index) := p_source_lines.clm_min_order_quantity_tbl(l_source_index);
7342     x_target_lines.clm_max_order_quantity_tbl(l_target_index) := p_source_lines.clm_max_order_quantity_tbl(l_source_index);
7343     x_target_lines.clm_total_amount_ordered_tbl(l_target_index) := p_source_lines.clm_total_amount_ordered_tbl(l_source_index);
7344     x_target_lines.clm_total_quantity_ordered_tbl(l_target_index) := p_source_lines.clm_total_quantity_ordered_tbl(l_source_index);
7345     x_target_lines.clm_period_perf_end_date_tbl(l_target_index) := p_source_lines.clm_period_perf_end_date_tbl(l_source_index);
7346     x_target_lines.clm_period_perf_start_date_tbl(l_target_index) := p_source_lines.clm_period_perf_start_date_tbl(l_source_index);
7347     x_target_lines.clm_option_indicator_tbl(l_target_index) := p_source_lines.clm_option_indicator_tbl(l_source_index);
7348     --CLM PDOI Integration Project Ends
7349     -- get next index
7350     l_source_index := p_source_index_tbl.NEXT(l_source_index);
7351   END LOOP;
7352 
7353   d_position := 50;
7354 
7355   -- rebuild index table
7356   FOR i IN 1..x_target_lines.rec_count
7357   LOOP
7358     x_target_lines.intf_id_index_tbl(x_target_lines.intf_line_id_tbl(i)) := i;
7359   END LOOP;
7360 
7361   IF (PO_LOG.d_proc) THEN
7362     PO_LOG.proc_end(d_module, 'number of copied lines', l_target_index);
7363   END IF;
7364 
7365 EXCEPTION
7366   WHEN OTHERS THEN
7367     PO_MESSAGE_S.add_exc_msg
7368     (
7369       p_pkg_name => d_pkg_name,
7370       p_procedure_name => d_api_name || '.' || d_position
7371     );
7372     RAISE;
7373 END copy_lines;
7374 
7375 -----------------------------------------------------------------------
7376 --Start of Comments
7377 --Name: uniqueness_check_on_desc
7378 --Function:
7379 --  check item uniqueness based on description + category name
7380 --Parameters:
7381 --IN:
7382 --  p_key
7383 --    key value used to identify rows in temp table
7384 --  p_group_num
7385 --    the new group number that is going to be assigned to rows
7386 --    whose action can be decided in this procedure
7387 --IN OUT:
7388 --  x_processing_row_tbl
7389 --    index table of rows that are going to be processed
7390 --  x_lines
7391 --    record of line information read within the batch
7392 --OUT:
7393 --End of Comments
7394 ------------------------------------------------------------------------
7395 PROCEDURE uniqueness_check_on_desc
7396 (
7397   p_key                 IN po_session_gt.key%TYPE,
7398   p_group_num           IN NUMBER,
7399   x_processing_row_tbl  IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
7400   x_lines               IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
7401 ) IS
7402 
7403   d_api_name CONSTANT VARCHAR2(30) := 'uniqueness_check_on_desc';
7404   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
7405   d_position NUMBER;
7406 
7407   -- variables to hold matching result read from po_session_gt table
7408   l_index_tbl           PO_TBL_NUMBER;
7409   l_po_line_id_tbl      PO_TBL_NUMBER;
7410   l_line_num_tbl        PO_TBL_NUMBER;
7411 
7412   l_index               NUMBER;
7413   l_data_key            po_session_gt.key%TYPE;
7414 
7415 BEGIN
7416   d_position := 0;
7417 
7418   IF (PO_LOG.d_proc) THEN
7419     PO_LOG.proc_begin(d_module);
7420   END IF;
7421 
7422   -- check matchings on draft table
7423   FORALL i IN INDICES OF x_processing_row_tbl
7424     INSERT INTO po_session_gt
7425     (
7426       key,
7427       num1,
7428       num2,
7429       num3
7430     )
7431     SELECT
7432       p_key,
7433       x_processing_row_tbl(i),
7434       draft_lines.po_line_id,
7435       draft_lines.line_num
7436     FROM  po_lines_draft_all draft_lines
7437     WHERE draft_lines.po_header_id = x_lines.hd_po_header_id_tbl(i)
7438     AND   draft_lines.draft_id = x_lines.draft_id_tbl(i)
7439     AND   NVL(draft_lines.expiration_date, TRUNC(sysdate)) >= TRUNC(sysdate)
7440     AND   draft_lines.item_description = x_lines.item_desc_tbl(i)
7441     AND   (x_lines.category_tbl(i) IS NULL OR
7442            EXISTS ( SELECT 1
7443                     FROM   mtl_categories_kfv mck
7444                     WHERE  mck.concatenated_segments = x_lines.category_tbl(i)
7445                     AND    mck.category_id = draft_lines.category_id));
7446 
7447   d_position := 10;
7448 
7449   -- check matching on txn table
7450   FORALL i IN INDICES OF x_processing_row_tbl
7451     INSERT INTO po_session_gt
7452     (
7453       key,
7454       num1,
7455       num2,
7456       num3
7457     )
7458     SELECT
7459       p_key,
7460       x_processing_row_tbl(i),
7461       txn_lines.po_line_id,
7462       txn_lines.line_num
7463     FROM  po_lines txn_lines
7464     WHERE txn_lines.po_header_id = x_lines.hd_po_header_id_tbl(i)
7465     AND   NOT EXISTS ( SELECT 1
7466                        FROM   po_lines_draft_all draft_lines
7467                        WHERE  draft_lines.po_line_id = txn_lines.po_line_id
7468                        AND    draft_lines.draft_id = x_lines.draft_id_tbl(i))
7469     AND   txn_lines.item_description = x_lines.item_desc_tbl(i)
7470     AND   (x_lines.category_tbl(i) IS NULL OR
7471            EXISTS ( SELECT 1
7472                     FROM   mtl_categories_kfv mck
7473                     WHERE  mck.concatenated_segments = x_lines.category_tbl(i)
7474                     AND    mck.category_id = txn_lines.category_id))
7475     AND   NVL(txn_lines.expiration_date, TRUNC(sysdate)) >= TRUNC(sysdate)
7476     AND   NVL(txn_lines.closed_code, 'OPEN') <> 'FINALLY CLOSED'
7477     AND   NVL(txn_lines.cancel_flag, 'N') <> 'Y';
7478 
7479   d_position := 20;
7480 
7481   DELETE FROM po_session_gt
7482   WHERE key = p_key
7483   RETURNING num1, num2, num3 BULK COLLECT INTO
7484     l_index_tbl, l_po_line_id_tbl, l_line_num_tbl;
7485 
7486   -- set po_line_id, and line_num from matching record
7487   -- If there is only one matching -- OK
7488   -- If there are multiple matching records, update the line that has same
7489   -- line_num as in interface table; otherwise, update line with maximum
7490   -- line_num
7491   FOR i IN 1..l_index_tbl.COUNT
7492   LOOP
7493     l_index := l_index_tbl(i);
7494 
7495     IF (x_lines.po_line_id_tbl(l_index) IS NULL) THEN
7496       IF (PO_LOG.d_stmt) THEN
7497         PO_LOG.stmt(d_module, d_position, 'first match index', l_index);
7498         PO_LOG.stmt(d_module, d_position, 'po line id', l_po_line_id_tbl(i));
7499         PO_LOG.stmt(d_module, d_position, 'line num', l_line_num_tbl(i));
7500       END IF;
7501 
7502       -- first match found
7503       x_lines.origin_line_num_tbl(l_index) := x_lines.line_num_tbl(l_index);
7504       x_lines.action_tbl(l_index) := PO_PDOI_CONSTANTS.g_ACTION_UPDATE;
7505       x_lines.group_num_tbl(l_index) := p_group_num;
7506       x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
7507       x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
7508       x_processing_row_tbl.DELETE(l_index);
7509       IF (l_line_num_tbl(i) = x_lines.origin_line_num_tbl(l_index)) THEN
7510         x_lines.match_line_found_tbl(l_index) := FND_API.g_TRUE;
7511       END IF;
7512     ELSE
7513       IF (PO_LOG.d_stmt) THEN
7514         PO_LOG.stmt(d_module, d_position, 'multi match index', l_index);
7515         PO_LOG.stmt(d_module, d_position, 'po line id', l_po_line_id_tbl(i));
7516         PO_LOG.stmt(d_module, d_position, 'line num', l_line_num_tbl(i));
7517         PO_LOG.stmt(d_module, d_position, 'original line num',
7518                     x_lines.origin_line_num_tbl(l_index));
7519         PO_LOG.stmt(d_module, d_position, 'match line found',
7520                     x_lines.match_line_found_tbl(l_index));
7521         PO_LOG.stmt(d_module, d_position, 'current line num',
7522                     x_lines.line_num_tbl(l_index));
7523       END IF;
7524 
7525       -- multiple matches found
7526       IF (l_line_num_tbl(i) = x_lines.origin_line_num_tbl(l_index)) THEN
7527         -- record matching line_num is found
7528         x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
7529         x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
7530         x_lines.match_line_found_tbl(l_index) := FND_API.g_TRUE;
7531       ELSIF (x_lines.match_line_found_tbl(l_index) = FND_API.g_TRUE) THEN
7532         -- need to do nothing, record with matching line num is found before
7533         NULL;
7534       ELSIF (x_lines.line_num_tbl(l_index) < l_line_num_tbl(i)) THEN
7535         -- try to update line with maximum line num if exact match can not be found
7536         x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
7537         x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
7538       ELSE
7539         -- do nothing since the new coming record has smaller line num
7540         -- than current matching record
7541         NULL;
7542       END IF;
7543     END IF;
7544   END LOOP;
7545 
7546   d_position := 30;
7547 
7548   -- search within the batch
7549   -- find out all lines that cannot find a match
7550   -- and set their action to ADD
7551   l_data_key := PO_CORE_S.get_session_gt_nextval;
7552   FORALL i IN INDICES OF x_processing_row_tbl
7553     INSERT INTO po_session_gt
7554     (
7555       key,
7556       num1,
7557       num2,
7558       char1,
7559       char2
7560     )
7561   SELECT
7562     l_data_key,
7563     x_lines.intf_line_id_tbl(i),       -- num1
7564     x_lines.hd_po_header_id_tbl(i),    -- num2
7565     x_lines.item_desc_tbl(i),          -- char1
7566     x_lines.category_tbl(i)            -- char2
7567   FROM DUAL;
7568 
7569   d_position := 40;
7570 
7571   FORALL i IN INDICES OF x_processing_row_tbl
7572     INSERT INTO po_session_gt
7573     (
7574       key,
7575       num1
7576     )
7577     SELECT p_key,
7578            x_processing_row_tbl(i)
7579     FROM   DUAL
7580     WHERE  NOT EXISTS(
7581            SELECT 1
7582            FROM   po_session_gt gt
7583            WHERE  key = l_data_key
7584            AND    gt.num1 < x_lines.intf_line_id_tbl(i)
7585            AND    gt.num2 = x_lines.hd_po_header_id_tbl(i)
7586            AND    gt.char1 = x_lines.item_desc_tbl(i)
7587            AND    NVL(x_lines.category_tbl(i), NVL(gt.char2, -99))=
7588                     NVL(gt.char2, -99));
7589 
7590   d_position := 50;
7591 
7592   DELETE FROM po_session_gt
7593   WHERE key = p_key
7594   RETURNING num1 BULK COLLECT INTO l_index_tbl;
7595 
7596   -- bug5093465
7597   -- For the records in l_index_tbl, assign action 'ADD'
7598   set_action_add
7599   ( p_key                    => p_key,
7600     p_group_num              => p_group_num,
7601     p_target_lines_index_tbl => l_index_tbl,
7602     p_check_line_num_assign  => FND_API.G_TRUE,
7603     x_processing_row_tbl     => x_processing_row_tbl,
7604     x_lines                  => x_lines
7605   );
7606 
7607   d_position := 60;
7608 
7609   -- clean up po_session_gt
7610   PO_PDOI_UTL.remove_session_gt_records
7611   ( p_key => l_data_key
7612   );
7613 
7614   IF (PO_LOG.d_proc) THEN
7615     PO_LOG.proc_end(d_module);
7616   END IF;
7617 
7618 EXCEPTION
7619   WHEN OTHERS THEN
7620     PO_MESSAGE_S.add_exc_msg
7621     (
7622       p_pkg_name => d_pkg_name,
7623       p_procedure_name => d_api_name || '.' || d_position
7624     );
7625     RAISE;
7626 END uniqueness_check_on_desc;
7627 
7628 -----------------------------------------------------------------------
7629 --Start of Comments
7630 --Name: uniqueness_check_on_item
7631 --Function:
7632 --  check item uniqueness based on item + revision + vendor_product_num
7633 --  + supplier_part_aux_id
7634 --Parameters:
7635 --IN:
7636 --  p_key
7637 --    key value used to identify rows in temp table
7638 --  p_group_num
7639 --    the new group number that is going to be assigned to rows
7640 --    whose action can be decided in this procedure
7641 --IN OUT:
7642 --  x_processing_row_tbl
7643 --    index table of rows that are going to be processed
7644 --  x_lines
7645 --    record of line information read within the batch
7646 --OUT:
7647 --End of Comments
7648 ------------------------------------------------------------------------
7649 PROCEDURE uniqueness_check_on_item
7650 (
7651   p_key                 IN po_session_gt.key%TYPE,
7652   p_group_num           IN NUMBER,
7653   x_processing_row_tbl  IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
7654   x_lines               IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
7655 ) IS
7656 
7657   d_api_name CONSTANT VARCHAR2(30) := 'uniqueness_check_on_item';
7658   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
7659   d_position NUMBER;
7660 
7661   l_def_master_org_id   NUMBER;
7662 
7663   -- variables to hold matching result read from po_session_gt table
7664   l_index_tbl           PO_TBL_NUMBER;
7665   l_po_line_id_tbl      PO_TBL_NUMBER;
7666   l_line_num_tbl        PO_TBL_NUMBER;
7667 
7668   l_index               NUMBER;
7669   l_data_key            po_session_gt.key%TYPE;
7670 
7671 BEGIN
7672   d_position := 0;
7673 
7674   IF (PO_LOG.d_proc) THEN
7675     PO_LOG.proc_begin(d_module);
7676   END IF;
7677 
7678   -- get default master org id
7679   l_def_master_org_id := PO_PDOI_PARAMS.g_sys.master_inv_org_id;
7680 
7681   IF (PO_LOG.d_stmt) THEN
7682     PO_LOG.stmt(d_module, d_position, 'l_def_master_org_id',
7683                 l_def_master_org_id);
7684     PO_LOG.stmt(d_module, d_position, 'item_tbl', x_lines.item_tbl);
7685     PO_LOG.stmt(d_module, d_position, 'po_header_id_tbl',
7686                 x_lines.hd_po_header_id_tbl);
7687     PO_LOG.stmt(d_module, d_position, 'draft_id_tbl', x_lines.draft_id_tbl);
7688     PO_LOG.stmt(d_module, d_position, 'item_revision_tbl',
7689                 x_lines.item_revision_tbl);
7690     PO_LOG.stmt(d_module, d_position, 'vendor_product_num_tbl',
7691                 x_lines.vendor_product_num_tbl);
7692     PO_LOG.stmt(d_module, d_position, 'supplier_part_auxid_tbl',
7693                 x_lines.supplier_part_auxid_tbl);
7694   END IF;
7695 
7696   -- check matching on draft table
7697   FORALL i IN INDICES OF x_processing_row_tbl
7698     INSERT INTO po_session_gt
7699     (
7700       key,
7701       num1,
7702       num2,
7703       num3
7704     )
7705     SELECT
7706       p_key,
7707       x_processing_row_tbl(i),
7708       draft_lines.po_line_id,
7709       draft_lines.line_num
7710     FROM  po_lines_draft_all draft_lines
7711     WHERE x_lines.item_tbl(i) IS NOT NULL
7712     AND   draft_lines.po_header_id = x_lines.hd_po_header_id_tbl(i)
7713     AND   draft_lines.draft_id = x_lines.draft_id_tbl(i)
7714     AND   NVL(draft_lines.expiration_date, TRUNC(sysdate)) >= TRUNC(sysdate)
7715     AND   EXISTS (SELECT 1
7716                   FROM   mtl_system_items items
7717                   WHERE  items.inventory_item_id = draft_lines.item_id
7718                   AND    items.segment1 = x_lines.item_tbl(i)
7719                   AND    items.organization_id =
7720                            NVL(l_def_master_org_id, items.organization_id))
7721     AND    NVL(x_lines.item_revision_tbl(i), NVL(draft_lines.item_revision, -99)) =
7722              NVL(draft_lines.item_revision, -99)
7723     AND    NVL(x_lines.vendor_product_num_tbl(i), NVL(draft_lines.vendor_product_num, -99)) =
7724              NVL(draft_lines.vendor_product_num, -99)
7725     AND    NVL(x_lines.supplier_part_auxid_tbl(i),
7726                NVL(draft_lines.supplier_part_auxid, FND_API.g_NULL_CHAR))=
7727            NVL(draft_lines.supplier_part_auxid, FND_API.g_NULL_CHAR);
7728 
7729   d_position := 10;
7730 
7731   -- check matching on txn table
7732   FORALL i IN INDICES OF x_processing_row_tbl
7733     INSERT INTO po_session_gt
7734     (
7735       key,
7736       num1,
7737       num2,
7738       num3
7739     )
7740     SELECT
7741       p_key,
7742       x_processing_row_tbl(i),
7743       txn_lines.po_line_id,
7744       txn_lines.line_num
7745     FROM  po_lines txn_lines
7746     WHERE x_lines.item_tbl(i) IS NOT NULL
7747     AND   txn_lines.po_header_id = x_lines.hd_po_header_id_tbl(i)
7748     AND   NOT EXISTS ( SELECT 1
7749                        FROM   po_lines_draft_all draft_lines
7750                        WHERE  draft_lines.po_line_id = txn_lines.po_line_id
7751                        AND    draft_lines.draft_id = x_lines.draft_id_tbl(i))
7752     AND   EXISTS (SELECT 1
7753                   FROM   mtl_system_items items
7754                   WHERE  items.inventory_item_id = txn_lines.item_id
7755                   AND    items.segment1 = x_lines.item_tbl(i)
7756                   AND    items.organization_id =
7757                            NVL(l_def_master_org_id, items.organization_id))
7758     AND   NVL(x_lines.item_revision_tbl(i), NVL(txn_lines.item_revision, -99)) =
7759             NVL(txn_lines.item_revision, -99)
7760     AND   NVL(x_lines.vendor_product_num_tbl(i), NVL(txn_lines.vendor_product_num, -99)) =
7761             NVL(txn_lines.vendor_product_num, -99)
7762     AND   NVL(x_lines.supplier_part_auxid_tbl(i),
7763               NVL(txn_lines.supplier_part_auxid, FND_API.g_NULL_CHAR)) =
7764           NVL(txn_lines.supplier_part_auxid, FND_API.g_NULL_CHAR)
7765     AND   NVL(txn_lines.expiration_date, TRUNC(sysdate)) >= TRUNC(sysdate)
7766     AND   NVL(txn_lines.closed_code, 'OPEN') <> 'FINALLY CLOSED'
7767     AND   NVL(txn_lines.cancel_flag, 'N') <> 'Y';
7768 
7769   d_position := 20;
7770 
7771   DELETE FROM po_session_gt
7772   WHERE key = p_key
7773   RETURNING num1, num2, num3 BULK COLLECT INTO
7774     l_index_tbl, l_po_line_id_tbl, l_line_num_tbl;
7775 
7776   -- set po_line_id, and line_num from matching record
7777   -- If there is only one matching -- OK
7778   -- If there are multiple matching records, update the line that has same
7779   -- line_num as in interface table; otherwise, update line with maximum
7780   -- line_num
7781   FOR i IN 1..l_index_tbl.COUNT
7782   LOOP
7783     l_index := l_index_tbl(i);
7784 
7785     IF (x_lines.po_line_id_tbl(l_index) IS NULL) THEN
7786       IF (PO_LOG.d_stmt) THEN
7787         PO_LOG.stmt(d_module, d_position, 'first match index', l_index);
7788         PO_LOG.stmt(d_module, d_position, 'po line id', l_po_line_id_tbl(i));
7789         PO_LOG.stmt(d_module, d_position, 'line num', l_line_num_tbl(i));
7790       END IF;
7791 
7792       -- first match found
7793       x_lines.origin_line_num_tbl(l_index) := x_lines.line_num_tbl(l_index);
7794       x_lines.action_tbl(l_index) := PO_PDOI_CONSTANTS.g_ACTION_UPDATE;
7795       x_lines.group_num_tbl(l_index) := p_group_num;
7796       x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
7797       x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
7798       x_processing_row_tbl.DELETE(l_index);
7799       IF (l_line_num_tbl(i) = x_lines.origin_line_num_tbl(l_index)) THEN
7800         x_lines.match_line_found_tbl(l_index) := FND_API.g_TRUE;
7801       END IF;
7802     ELSE
7803       IF (PO_LOG.d_stmt) THEN
7804         PO_LOG.stmt(d_module, d_position, 'multi match index', l_index);
7805         PO_LOG.stmt(d_module, d_position, 'po line id', l_po_line_id_tbl(i));
7806         PO_LOG.stmt(d_module, d_position, 'line num', l_line_num_tbl(i));
7807         PO_LOG.stmt(d_module, d_position, 'original line num',
7808                     x_lines.origin_line_num_tbl(l_index));
7809         PO_LOG.stmt(d_module, d_position, 'match line found',
7810                     x_lines.match_line_found_tbl(l_index));
7811         PO_LOG.stmt(d_module, d_position, 'current line num',
7812                     x_lines.line_num_tbl(l_index));
7813       END IF;
7814 
7815       -- multiple matches found
7816       IF (l_line_num_tbl(i) = x_lines.origin_line_num_tbl(l_index)) THEN
7817         -- record matching line_num is found
7818         x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
7819         x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
7820         x_lines.match_line_found_tbl(l_index) := FND_API.g_TRUE;
7821       ELSIF (x_lines.match_line_found_tbl(l_index) = FND_API.g_TRUE) THEN
7822         -- need to do nothing, record with matching line num is found before
7823         NULL;
7824       ELSIF (x_lines.line_num_tbl(l_index) < l_line_num_tbl(i)) THEN
7825         -- try to update line with maximum line num if exact match can not be found
7826         x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
7827         x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
7828       ELSE
7829         -- do nothing since the new coming record has smaller line num
7830         -- than current matching record
7831         NULL;
7832       END IF;
7833     END IF;
7834   END LOOP;
7835 
7836   d_position := 30;
7837 
7838   -- search within the batch
7839   -- find out all lines that cannot find a match
7840   -- and set their action to ADD
7841   l_data_key := PO_CORE_S.get_session_gt_nextval;
7842   FORALL i IN INDICES OF x_processing_row_tbl
7843     INSERT INTO po_session_gt
7844     (
7845       key,
7846       num1,
7847       num2,
7848       char1,
7849       char2,
7850       char3,
7851       char4
7852     )
7853   SELECT
7854     l_data_key,
7855     x_lines.intf_line_id_tbl(i),       -- num1
7856     x_lines.hd_po_header_id_tbl(i),    -- num2
7857     x_lines.item_tbl(i),               -- char1
7858     x_lines.item_revision_tbl(i),      -- char2
7859     x_lines.vendor_product_num_tbl(i), -- char3
7860     x_lines.supplier_part_auxid_tbl(i) -- char4
7861   FROM DUAL;
7862 
7863   d_position := 40;
7864 
7865   -- bug4930510
7866   -- Take away the table mtl_system_items from the query since it's
7867   -- never used.
7868   FORALL i IN INDICES OF x_processing_row_tbl
7869     INSERT INTO po_session_gt
7870     (
7871       key,
7872       num1
7873     )
7874     SELECT p_key,
7875            x_processing_row_tbl(i)
7876     FROM   DUAL
7877     WHERE  x_lines.item_tbl(i) IS NOT NULL
7878     AND    NOT EXISTS(
7879            SELECT 1
7880            FROM   po_session_gt gt
7881            WHERE  key = l_data_key
7882            AND    gt.num1 < x_lines.intf_line_id_tbl(i)
7883            AND    gt.num2 = x_lines.hd_po_header_id_tbl(i)
7884            AND    gt.char1 = x_lines.item_tbl(i)
7885            AND    NVL(x_lines.item_revision_tbl(i), NVL(gt.char2, -99)) =
7886                     NVL(gt.char2, -99)
7887            AND    NVL(x_lines.vendor_product_num_tbl(i), NVL(gt.char3, -99)) =
7888                     NVL(gt.char3, -99)
7889            AND    NVL(x_lines.supplier_part_auxid_tbl(i),
7890                       NVL(gt.char4, FND_API.g_NULL_CHAR))=
7891                   NVL(gt.char4, FND_API.g_NULL_CHAR));
7892 
7893   d_position := 50;
7894 
7895   DELETE FROM po_session_gt
7896   WHERE key = p_key
7897   RETURNING num1 BULK COLLECT INTO l_index_tbl;
7898 
7899   -- bug5093465
7900   -- For the records in l_index_tbl, assign action 'ADD'
7901   set_action_add
7902   ( p_key                    => p_key,
7903     p_group_num              => p_group_num,
7904     p_target_lines_index_tbl => l_index_tbl,
7905     p_check_line_num_assign  => FND_API.G_TRUE,
7906     x_processing_row_tbl     => x_processing_row_tbl,
7907     x_lines                  => x_lines
7908   );
7909 
7910   d_position := 60;
7911 
7912   -- clean up po_session_gt
7913   PO_PDOI_UTL.remove_session_gt_records
7914   ( p_key => l_data_key
7915   );
7916 
7917   IF (PO_LOG.d_proc) THEN
7918     PO_LOG.proc_end(d_module);
7919   END IF;
7920 
7921 EXCEPTION
7922   WHEN OTHERS THEN
7923     PO_MESSAGE_S.add_exc_msg
7924     (
7925       p_pkg_name => d_pkg_name,
7926       p_procedure_name => d_api_name || '.' || d_position
7927     );
7928     RAISE;
7929 END uniqueness_check_on_item;
7930 
7931 -----------------------------------------------------------------------
7932 --Start of Comments
7933 --Name: uniqueness_check_on_vpn
7934 --Function:
7935 --  check item uniqueness based on vendor_product_num + aux id
7936 --Parameters:
7937 --IN:
7938 --  p_key
7939 --    key value used to identify rows in temp table
7940 --  p_group_num
7941 --    the new group number that is going to be assigned to rows
7942 --    whose action can be decided in this procedure
7943 --IN OUT:
7944 --  x_processing_row_tbl
7945 --    index table of rows that are going to be processed
7946 --  x_lines
7947 --    record of line information read within the batch
7948 --OUT:
7949 --End of Comments
7950 ------------------------------------------------------------------------
7951 PROCEDURE uniqueness_check_on_vpn
7952 (
7953   p_key                 IN po_session_gt.key%TYPE,
7954   p_group_num           IN NUMBER,
7955   x_processing_row_tbl  IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
7956   x_lines               IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
7957 ) IS
7958 
7959   d_api_name CONSTANT VARCHAR2(30) := 'uniqueness_check_on_vpn';
7960   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
7961   d_position NUMBER;
7962 
7963   -- variables to hold matching result read from po_session_gt table
7964   l_index_tbl           PO_TBL_NUMBER;
7965   l_po_line_id_tbl      PO_TBL_NUMBER;
7966   l_line_num_tbl        PO_TBL_NUMBER;
7967 
7968   l_index               NUMBER;
7969   l_data_key            po_session_gt.key%TYPE;
7970 
7971 BEGIN
7972   d_position := 0;
7973 
7974   IF (PO_LOG.d_proc) THEN
7975     PO_LOG.proc_begin(d_module);
7976   END IF;
7977 
7978   -- check matchings on draft table
7979   FORALL i IN INDICES OF x_processing_row_tbl
7980     INSERT INTO po_session_gt
7981     (
7982       key,
7983       num1,
7984       num2,
7985       num3
7986     )
7987     SELECT
7988       p_key,
7989       x_processing_row_tbl(i),
7990       draft_lines.po_line_id,
7991       draft_lines.line_num
7992     FROM  po_lines_draft_all draft_lines
7993     WHERE x_lines.item_tbl(i) IS NULL
7994     AND   x_lines.vendor_product_num_tbl(i) IS NOT NULL
7995     AND   draft_lines.po_header_id = x_lines.hd_po_header_id_tbl(i)
7996     AND   draft_lines.draft_id = x_lines.draft_id_tbl(i)
7997     AND   NVL(draft_lines.expiration_date, TRUNC(sysdate)) >= TRUNC(sysdate)
7998     AND   draft_lines.vendor_product_num = x_lines.vendor_product_num_tbl(i)
7999     AND   NVL(x_lines.supplier_part_auxid_tbl(i),
8000               NVL(draft_lines.supplier_part_auxid, FND_API.g_NULL_CHAR))=
8001           NVL(draft_lines.supplier_part_auxid, FND_API.g_NULL_CHAR);
8002 
8003   d_position := 10;
8004 
8005   -- check matching on txn table
8006   FORALL i IN INDICES OF x_processing_row_tbl
8007     INSERT INTO po_session_gt
8008     (
8009       key,
8010       num1,
8011       num2,
8012       num3
8013     )
8014     SELECT
8015       p_key,
8016       x_processing_row_tbl(i),
8017       txn_lines.po_line_id,
8018       txn_lines.line_num
8019     FROM  po_lines txn_lines
8020     WHERE x_lines.item_tbl(i) IS NULL
8021     AND   x_lines.vendor_product_num_tbl(i) IS NOT NULL
8022     AND   txn_lines.po_header_id = x_lines.hd_po_header_id_tbl(i)
8023     AND   NOT EXISTS ( SELECT 1
8024                        FROM   po_lines_draft_all draft_lines
8025                        WHERE  draft_lines.po_line_id = txn_lines.po_line_id
8026                        AND    draft_lines.draft_id = x_lines.draft_id_tbl(i))
8027     AND   txn_lines.vendor_product_num = x_lines.vendor_product_num_tbl(i)
8028     AND   NVL(x_lines.supplier_part_auxid_tbl(i),
8029               NVL(txn_lines.supplier_part_auxid, FND_API.g_NULL_CHAR))=
8030           NVL(txn_lines.supplier_part_auxid, FND_API.g_NULL_CHAR)
8031     AND   NVL(txn_lines.expiration_date, TRUNC(sysdate)) >= TRUNC(sysdate)
8032     AND   NVL(txn_lines.closed_code, 'OPEN') <> 'FINALLY CLOSED'
8033     AND   NVL(txn_lines.cancel_flag, 'N') <> 'Y';
8034 
8035   d_position := 20;
8036 
8037   DELETE FROM po_session_gt
8038   WHERE key = p_key
8039   RETURNING num1, num2, num3 BULK COLLECT INTO
8040     l_index_tbl, l_po_line_id_tbl, l_line_num_tbl;
8041 
8042   -- set po_line_id, and line_num from matching record
8043   -- If there is only one matching -- OK
8044   -- If there are multiple matching records, update the line that has same
8045   -- line_num as in interface table; otherwise, update line with maximum
8046   -- line_num
8047   FOR i IN 1..l_index_tbl.COUNT
8048   LOOP
8049     l_index := l_index_tbl(i);
8050 
8051     IF (x_lines.po_line_id_tbl(l_index) IS NULL) THEN
8052       IF (PO_LOG.d_stmt) THEN
8053         PO_LOG.stmt(d_module, d_position, 'first match index', l_index);
8054         PO_LOG.stmt(d_module, d_position, 'po line id', l_po_line_id_tbl(i));
8055         PO_LOG.stmt(d_module, d_position, 'line num', l_line_num_tbl(i));
8056       END IF;
8057 
8058       -- first match found
8059       x_lines.origin_line_num_tbl(l_index) := x_lines.line_num_tbl(l_index);
8060       x_lines.action_tbl(l_index) := PO_PDOI_CONSTANTS.g_ACTION_UPDATE;
8061       x_lines.group_num_tbl(l_index) := p_group_num;
8062       x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
8063       x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
8064       x_processing_row_tbl.DELETE(l_index);
8065       IF (l_line_num_tbl(i) = x_lines.origin_line_num_tbl(l_index)) THEN
8066         x_lines.match_line_found_tbl(l_index) := FND_API.g_TRUE;
8067       END IF;
8068     ELSE
8069       IF (PO_LOG.d_stmt) THEN
8070         PO_LOG.stmt(d_module, d_position, 'multi match index', l_index);
8071         PO_LOG.stmt(d_module, d_position, 'po line id', l_po_line_id_tbl(i));
8072         PO_LOG.stmt(d_module, d_position, 'line num', l_line_num_tbl(i));
8073         PO_LOG.stmt(d_module, d_position, 'original line num',
8074                     x_lines.origin_line_num_tbl(l_index));
8075         PO_LOG.stmt(d_module, d_position, 'match line found',
8076                     x_lines.match_line_found_tbl(l_index));
8077         PO_LOG.stmt(d_module, d_position, 'current line num',
8078                     x_lines.line_num_tbl(l_index));
8079       END IF;
8080 
8081       -- multiple matches found
8082       IF (l_line_num_tbl(i) = x_lines.origin_line_num_tbl(l_index)) THEN
8083         -- record matching line_num is found
8084         x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
8085         x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
8086         x_lines.match_line_found_tbl(l_index) := FND_API.g_TRUE;
8087       ELSIF (x_lines.match_line_found_tbl(l_index) = FND_API.g_TRUE) THEN
8088         -- need to do nothing, record with matching line num is found before
8089         NULL;
8090       ELSIF (x_lines.line_num_tbl(l_index) < l_line_num_tbl(i)) THEN
8091         -- try to update line with maximum line num if exact match can not be found
8092         x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
8093         x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
8094       ELSE
8095         -- do nothing since the new coming record has smaller line num
8096         -- than current matching record
8097         NULL;
8098       END IF;
8099     END IF;
8100   END LOOP;
8101 
8102   d_position := 30;
8103 
8104   -- search within the batch
8105   -- find out all lines that cannot find a match
8106   -- and set their action to ADD
8107   l_data_key := PO_CORE_S.get_session_gt_nextval;
8108   FORALL i IN INDICES OF x_processing_row_tbl
8109     INSERT INTO po_session_gt
8110     (
8111       key,
8112       num1,
8113       num2,
8114       char1,
8115       char2
8116     )
8117   SELECT
8118     l_data_key,
8119     x_lines.intf_line_id_tbl(i),       -- num1
8120     x_lines.hd_po_header_id_tbl(i),    -- num2
8121     x_lines.vendor_product_num_tbl(i), -- char1
8122     x_lines.supplier_part_auxid_tbl(i) -- char2
8123   FROM DUAL;
8124 
8125   d_position := 40;
8126 
8127   FORALL i IN INDICES OF x_processing_row_tbl
8128     INSERT INTO po_session_gt
8129     (
8130       key,
8131       num1
8132     )
8133     SELECT p_key,
8134            x_processing_row_tbl(i)
8135     FROM   DUAL
8136     WHERE  x_lines.item_tbl(i) IS NULL
8137     AND    x_lines.vendor_product_num_tbl(i) IS NOT NULL
8138     AND    NOT EXISTS(
8139            SELECT 1
8140            FROM   po_session_gt gt
8141            WHERE  key = l_data_key
8142            AND    gt.num1 < x_lines.intf_line_id_tbl(i)
8143            AND    gt.num2 = x_lines.hd_po_header_id_tbl(i)
8144            AND    gt.char1 = x_lines.vendor_product_num_tbl(i)
8145            AND    NVL(x_lines.supplier_part_auxid_tbl(i),
8146                       NVL(gt.char2, FND_API.g_NULL_CHAR))=
8147                   NVL(gt.char2, FND_API.g_NULL_CHAR));
8148 
8149   d_position := 50;
8150 
8151   DELETE FROM po_session_gt
8152   WHERE key = p_key
8153   RETURNING num1 BULK COLLECT INTO l_index_tbl;
8154 
8155   d_position := 60;
8156 
8157   -- bug5093465
8158   -- For the records in l_index_tbl, assign action 'ADD'
8159   set_action_add
8160   ( p_key                    => p_key,
8161     p_group_num              => p_group_num,
8162     p_target_lines_index_tbl => l_index_tbl,
8163     p_check_line_num_assign  => FND_API.G_TRUE,
8164     x_processing_row_tbl     => x_processing_row_tbl,
8165     x_lines                  => x_lines
8166   );
8167 
8168   d_position := 70;
8169 
8170   -- clean up po_session_gt
8171   PO_PDOI_UTL.remove_session_gt_records
8172   ( p_key => l_data_key
8173   );
8174 
8175   IF (PO_LOG.d_proc) THEN
8176     PO_LOG.proc_end(d_module);
8177   END IF;
8178 
8179 EXCEPTION
8180   WHEN OTHERS THEN
8181     PO_MESSAGE_S.add_exc_msg
8182     (
8183       p_pkg_name => d_pkg_name,
8184       p_procedure_name => d_api_name || '.' || d_position
8185     );
8186     RAISE;
8187 END uniqueness_check_on_vpn;
8188 
8189 -----------------------------------------------------------------------
8190 --Start of Comments
8191 --Name: uniqueness_check_on_job
8192 --Function:
8193 --  check item uniqueness based on job name
8194 --Parameters:
8195 --IN:
8196 --  p_key
8197 --    key value used to identify rows in temp table
8198 --  p_group_num
8199 --    the new group number that is going to be assigned to rows
8200 --    whose action can be decided in this procedure
8201 --IN OUT:
8202 --  x_processing_row_tbl
8203 --    index table of rows that are going to be processed
8204 --  x_lines
8205 --    record of line information read within the batch
8206 --OUT:
8207 --End of Comments
8208 ------------------------------------------------------------------------
8209 PROCEDURE uniqueness_check_on_job
8210 (
8211   p_key                 IN po_session_gt.key%TYPE,
8212   p_group_num           IN NUMBER,
8213   x_processing_row_tbl  IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
8214   x_lines               IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
8215 ) IS
8216 
8217   d_api_name CONSTANT VARCHAR2(30) := 'uniqueness_check_on_job';
8218   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
8219   d_position NUMBER;
8220 
8221   -- variables to hold matching result read from po_session_gt table
8222   l_index_tbl           PO_TBL_NUMBER;
8223   l_po_line_id_tbl      PO_TBL_NUMBER;
8224   l_line_num_tbl        PO_TBL_NUMBER;
8225 
8226   l_index               NUMBER;
8227   l_data_key            po_session_gt.key%TYPE;
8228 
8229 BEGIN
8230   d_position := 0;
8231 
8232   IF (PO_LOG.d_proc) THEN
8233     PO_LOG.proc_begin(d_module);
8234   END IF;
8235 
8236   -- check matchings on draft table
8237   FORALL i IN INDICES OF x_processing_row_tbl
8238     INSERT INTO po_session_gt
8239     (
8240       key,
8241       num1,
8242       num2,
8243       num3
8244     )
8245     SELECT
8246       p_key,
8247       x_processing_row_tbl(i),
8248       draft_lines.po_line_id,
8249       draft_lines.line_num
8250     FROM  po_lines_draft_all draft_lines
8251     WHERE x_lines.item_tbl(i) IS NULL
8252     AND   x_lines.vendor_product_num_tbl(i) IS NULL
8253     AND   x_lines.job_name_tbl(i) IS NOT NULL
8254     AND   draft_lines.po_header_id = x_lines.hd_po_header_id_tbl(i)
8255     AND   draft_lines.draft_id = x_lines.draft_id_tbl(i)
8256     AND   NVL(draft_lines.expiration_date, TRUNC(sysdate)) >= TRUNC(sysdate)
8257     AND   EXISTS (SELECT 1
8258                   FROM   per_jobs_vl
8259                   WHERE  name = x_lines.job_name_tbl(i)
8260                   AND    job_id = draft_lines.job_id)
8261     AND   NVL(draft_lines.expiration_date, TRUNC(sysdate)) >= TRUNC(sysdate);
8262 
8263   d_position := 10;
8264 
8265   -- check matching on txn table
8266   FORALL i IN INDICES OF x_processing_row_tbl
8267     INSERT INTO po_session_gt
8268     (
8269       key,
8270       num1,
8271       num2,
8272       num3
8273     )
8274     SELECT
8275       p_key,
8276       x_processing_row_tbl(i),
8277       txn_lines.po_line_id,
8278       txn_lines.line_num
8279     FROM  po_lines txn_lines
8280     WHERE x_lines.item_tbl(i) IS NULL
8281     AND   x_lines.vendor_product_num_tbl(i) IS NULL
8282     AND   x_lines.job_name_tbl(i) IS NOT NULL
8283     AND   txn_lines.po_header_id = x_lines.hd_po_header_id_tbl(i)
8284     AND   NOT EXISTS ( SELECT 1
8285                        FROM   po_lines_draft_all draft_lines
8286                        WHERE  draft_lines.po_line_id = txn_lines.po_line_id
8287                        AND    draft_lines.draft_id = x_lines.draft_id_tbl(i))
8288     AND   EXISTS (SELECT 1
8289                   FROM   per_jobs_vl
8290                   WHERE  name = x_lines.job_name_tbl(i)
8291                   AND    job_id = txn_lines.job_id)
8292     AND   NVL(txn_lines.expiration_date, TRUNC(sysdate)) >= TRUNC(sysdate)
8293     AND   NVL(txn_lines.closed_code, 'OPEN') <> 'FINALLY CLOSED'
8294     AND   NVL(txn_lines.cancel_flag, 'N') <> 'Y';
8295 
8296   d_position := 20;
8297 
8298   DELETE FROM po_session_gt
8299   WHERE key = p_key
8300   RETURNING num1, num2, num3 BULK COLLECT INTO
8301     l_index_tbl, l_po_line_id_tbl, l_line_num_tbl;
8302 
8303   -- set po_line_id, and line_num from matching record
8304   -- If there is only one matching -- OK
8305   -- If there are multiple matching records, update the line that has same
8306   -- line_num as in interface table; otherwise, update line with maximum
8307   -- line_num
8308   FOR i IN 1..l_index_tbl.COUNT
8309   LOOP
8310     l_index := l_index_tbl(i);
8311 
8312     IF (x_lines.po_line_id_tbl(l_index) IS NULL) THEN
8313       IF (PO_LOG.d_stmt) THEN
8314         PO_LOG.stmt(d_module, d_position, 'first match index', l_index);
8315         PO_LOG.stmt(d_module, d_position, 'po line id', l_po_line_id_tbl(i));
8316         PO_LOG.stmt(d_module, d_position, 'line num', l_line_num_tbl(i));
8317       END IF;
8318 
8319       -- first match found
8320       x_lines.origin_line_num_tbl(l_index) := x_lines.line_num_tbl(l_index);
8321       x_lines.action_tbl(l_index) := PO_PDOI_CONSTANTS.g_ACTION_UPDATE;
8322       x_lines.group_num_tbl(l_index) := p_group_num;
8323       x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
8324       x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
8325       x_processing_row_tbl.DELETE(l_index);
8326       IF (l_line_num_tbl(i) = x_lines.origin_line_num_tbl(l_index)) THEN
8327         x_lines.match_line_found_tbl(l_index) := FND_API.g_TRUE;
8328       END IF;
8329     ELSE
8330       IF (PO_LOG.d_stmt) THEN
8331         PO_LOG.stmt(d_module, d_position, 'multi match index', l_index);
8332         PO_LOG.stmt(d_module, d_position, 'po line id', l_po_line_id_tbl(i));
8333         PO_LOG.stmt(d_module, d_position, 'line num', l_line_num_tbl(i));
8334         PO_LOG.stmt(d_module, d_position, 'original line num',
8335                     x_lines.origin_line_num_tbl(l_index));
8336         PO_LOG.stmt(d_module, d_position, 'match line found',
8337                     x_lines.match_line_found_tbl(l_index));
8338         PO_LOG.stmt(d_module, d_position, 'current line num',
8339                     x_lines.line_num_tbl(l_index));
8340       END IF;
8341 
8342       -- multiple matches found
8343       IF (l_line_num_tbl(i) = x_lines.origin_line_num_tbl(l_index)) THEN
8344         -- record matching line_num is found
8345         x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
8346         x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
8347         x_lines.match_line_found_tbl(l_index) := FND_API.g_TRUE;
8348       ELSIF (x_lines.match_line_found_tbl(l_index) = FND_API.g_TRUE) THEN
8349         -- need to do nothing, record with matching line num is found before
8350         NULL;
8351       ELSIF (x_lines.line_num_tbl(l_index) < l_line_num_tbl(i)) THEN
8352         -- try to update line with maximum line num if exact match can not be found
8353         x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
8354         x_lines.line_num_tbl(l_index) := l_line_num_tbl(i);
8355       ELSE
8356         -- do nothing since the new coming record has smaller line num
8357         -- than current matching record
8358         NULL;
8359       END IF;
8360     END IF;
8361   END LOOP;
8362 
8363   d_position := 30;
8364 
8365   -- search within the batch
8366   -- find out all lines that cannot find a match
8367   -- and set their action to ADD
8368   l_data_key := PO_CORE_S.get_session_gt_nextval;
8369   FORALL i IN INDICES OF x_processing_row_tbl
8370     INSERT INTO po_session_gt
8371     (
8372       key,
8373       num1,
8374       num2,
8375       char1
8376     )
8377   SELECT
8378     l_data_key,
8379     x_lines.intf_line_id_tbl(i),       -- num1
8380     x_lines.hd_po_header_id_tbl(i),    -- num2
8381     x_lines.job_name_tbl(i)            -- char1
8382   FROM DUAL;
8383 
8384   d_position := 40;
8385 
8386   FORALL i IN INDICES OF x_processing_row_tbl
8387     INSERT INTO po_session_gt
8388     (
8389       key,
8390       num1
8391     )
8392     SELECT p_key,
8393            x_processing_row_tbl(i)
8394     FROM   DUAL
8395     WHERE  x_lines.item_tbl(i) IS NULL
8396     AND    x_lines.vendor_product_num_tbl(i) IS NULL
8397     AND    x_lines.job_name_tbl(i) IS NOT NULL
8398     AND    NOT EXISTS(
8399            SELECT 1
8400            FROM   po_session_gt gt
8401            WHERE  key = l_data_key
8402            AND    gt.num1 < x_lines.intf_line_id_tbl(i)
8403            AND    gt.num2 = x_lines.hd_po_header_id_tbl(i)
8404            AND    gt.char1 = x_lines.job_name_tbl(i));
8405 
8406   d_position := 50;
8407 
8408   DELETE FROM po_session_gt
8409   WHERE key = p_key
8410   RETURNING num1 BULK COLLECT INTO l_index_tbl;
8411 
8412   -- bug5093465
8413   -- For the records in l_index_tbl, assign action 'ADD'
8414   set_action_add
8415   ( p_key                    => p_key,
8416     p_group_num              => p_group_num,
8417     p_target_lines_index_tbl => l_index_tbl,
8418     p_check_line_num_assign  => FND_API.G_TRUE,
8419     x_processing_row_tbl     => x_processing_row_tbl,
8420     x_lines                  => x_lines
8421   );
8422 
8423   d_position := 60;
8424 
8425   -- clean up po_session_gt
8426   PO_PDOI_UTL.remove_session_gt_records
8427   ( p_key => l_data_key
8428   );
8429 
8430   IF (PO_LOG.d_proc) THEN
8431     PO_LOG.proc_end(d_module);
8432   END IF;
8433 
8434 EXCEPTION
8435   WHEN OTHERS THEN
8436     PO_MESSAGE_S.add_exc_msg
8437     (
8438       p_pkg_name => d_pkg_name,
8439       p_procedure_name => d_api_name || '.' || d_position
8440     );
8441     RAISE;
8442 END uniqueness_check_on_job;
8443 
8444 -----------------------------------------------------------------------
8445 --Start of Comments
8446 --Name: uniqueness_check_on_line_num
8447 --Function:
8448 --  check item uniqueness based on line number
8449 --Parameters:
8450 --IN:
8451 --  p_key
8452 --    key value used to identify rows in temp table
8453 --  p_group_num
8454 --    the new group number that is going to be assigned to rows
8455 --    whose action can be decided in this procedure
8456 --IN OUT:
8457 --  x_processing_row_tbl
8458 --    index table of rows that are going to be processed
8459 --  x_lines
8460 --    record of line information read within the batch
8461 --OUT:
8462 --End of Comments
8463 ------------------------------------------------------------------------
8464 PROCEDURE uniqueness_check_on_line_num
8465 (
8466   p_key                 IN po_session_gt.key%TYPE,
8467   p_group_num           IN NUMBER,
8468   x_processing_row_tbl  IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
8469   x_lines               IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
8470 ) IS
8471 
8472   d_api_name CONSTANT VARCHAR2(30) := 'uniqueness_check_on_line_num';
8473   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
8474   d_position NUMBER;
8475 
8476   -- variables to hold matching result read from po_session_gt table
8477   l_index_tbl           PO_TBL_NUMBER;
8478   l_po_line_id_tbl      PO_TBL_NUMBER;
8479   l_line_num_tbl        PO_TBL_NUMBER;
8480 
8481   l_index               NUMBER;
8482   l_data_key            po_session_gt.key%TYPE;
8483 
8484 BEGIN
8485   d_position := 0;
8486 
8487   IF (PO_LOG.d_proc) THEN
8488     PO_LOG.proc_begin(d_module);
8489   END IF;
8490 
8491   -- check matchings on draft table
8492   FORALL i IN INDICES OF x_processing_row_tbl
8493     INSERT INTO po_session_gt
8494     (
8495       key,
8496       num1,
8497       num2,
8498       num3
8499     )
8500     SELECT
8501       p_key,
8502       x_processing_row_tbl(i),
8503       draft_lines.po_line_id,
8504       draft_lines.line_num
8505     FROM  po_lines_draft_all draft_lines
8506     WHERE x_lines.item_tbl(i) IS NULL
8507     AND   x_lines.vendor_product_num_tbl(i) IS NULL
8508     AND   x_lines.job_name_tbl(i) IS NULL
8509     AND   x_lines.line_num_tbl(i) IS NOT NULL
8510     AND   draft_lines.po_header_id = x_lines.hd_po_header_id_tbl(i)
8511     AND   draft_lines.draft_id = x_lines.draft_id_tbl(i)
8512     AND   NVL(draft_lines.expiration_date, TRUNC(sysdate)) >= TRUNC(sysdate)
8513     AND   draft_lines.line_num = x_lines.line_num_tbl(i);
8514 
8515   d_position := 10;
8516 
8517   -- check matching on txn table
8518   FORALL i IN INDICES OF x_processing_row_tbl
8519     INSERT INTO po_session_gt
8520     (
8521       key,
8522       num1,
8523       num2,
8524       num3
8525     )
8526     SELECT
8527       p_key,
8528       x_processing_row_tbl(i),
8529       txn_lines.po_line_id,
8530       txn_lines.line_num
8531     FROM  po_lines txn_lines
8532     WHERE x_lines.item_tbl(i) IS NULL
8533     AND   x_lines.vendor_product_num_tbl(i) IS NULL
8534     AND   x_lines.job_name_tbl(i) IS NULL
8535     AND   x_lines.line_num_tbl(i) IS NOT NULL
8536     AND   txn_lines.po_header_id = x_lines.hd_po_header_id_tbl(i)
8537     AND   NOT EXISTS ( SELECT 1
8538                        FROM   po_lines_draft_all draft_lines
8539                        WHERE  draft_lines.po_line_id = txn_lines.po_line_id
8540                        AND    draft_lines.draft_id = x_lines.draft_id_tbl(i))
8541     AND   txn_lines.line_num = x_lines.line_num_tbl(i)
8542     AND   NVL(txn_lines.expiration_date, TRUNC(sysdate)) >= TRUNC(sysdate)
8543     AND   NVL(txn_lines.closed_code, 'OPEN') <> 'FINALLY CLOSED'
8544     AND   NVL(txn_lines.cancel_flag, 'N') <> 'Y';
8545 
8546   d_position := 20;
8547 
8548   DELETE FROM po_session_gt
8549   WHERE key = p_key
8550   RETURNING num1, num2, num3 BULK COLLECT INTO
8551     l_index_tbl, l_po_line_id_tbl, l_line_num_tbl;
8552 
8553   -- set po_line_id, and line_num from matching record
8554   -- There can be at most 1 matching record since we match on line num
8555   FOR i IN 1..l_index_tbl.COUNT
8556   LOOP
8557     l_index := l_index_tbl(i);
8558 
8559     x_lines.origin_line_num_tbl(l_index) := x_lines.line_num_tbl(l_index);
8560     x_lines.action_tbl(l_index) := PO_PDOI_CONSTANTS.g_ACTION_UPDATE;
8561     x_lines.group_num_tbl(l_index) := p_group_num;
8562     x_lines.po_line_id_tbl(l_index) := l_po_line_id_tbl(i);
8563     x_processing_row_tbl.DELETE(l_index);
8564 
8565     IF (PO_LOG.d_stmt) THEN
8566       PO_LOG.stmt(d_module, d_position, 'match index', l_index);
8567       PO_LOG.stmt(d_module, d_position, 'po line id', l_po_line_id_tbl(i));
8568       PO_LOG.stmt(d_module, d_position, 'current line num',
8569                   x_lines.line_num_tbl(l_index));
8570     END IF;
8571   END LOOP;
8572 
8573   d_position := 30;
8574 
8575   -- search within the batch
8576   -- find out all lines that cannot find a match
8577   -- and set their action to ADD
8578   l_data_key := PO_CORE_S.get_session_gt_nextval;
8579   FORALL i IN INDICES OF x_processing_row_tbl
8580     INSERT INTO po_session_gt
8581     (
8582       key,
8583       num1,
8584       num2,
8585       num3
8586     )
8587   SELECT
8588     l_data_key,
8589     x_lines.intf_line_id_tbl(i),       -- num1
8590     x_lines.hd_po_header_id_tbl(i),    -- num2
8591     x_lines.line_num_tbl(i)            -- num3
8592   FROM DUAL;
8593 
8594   d_position := 40;
8595 
8596   FORALL i IN INDICES OF x_processing_row_tbl
8597     INSERT INTO po_session_gt
8598     (
8599       key,
8600       num1
8601     )
8602     SELECT p_key,
8603            x_processing_row_tbl(i)
8604     FROM   DUAL
8605     WHERE  x_lines.item_tbl(i) IS NULL
8606     AND    x_lines.vendor_product_num_tbl(i) IS NULL
8607     AND    x_lines.job_name_tbl(i) IS NULL
8608     AND    x_lines.line_num_tbl(i) IS NOT NULL
8609     AND    NOT EXISTS(
8610            SELECT 1
8611            FROM   po_session_gt gt
8612            WHERE  key = l_data_key
8613            AND    gt.num1 < x_lines.intf_line_id_tbl(i)
8614            AND    gt.num2 = x_lines.hd_po_header_id_tbl(i)
8615            AND    gt.num3 = x_lines.line_num_tbl(i));
8616 
8617   d_position := 50;
8618 
8619   DELETE FROM po_session_gt
8620   WHERE key = p_key
8621   RETURNING num1 BULK COLLECT INTO l_index_tbl;
8622 
8623   -- bug5093465
8624   -- For the records in l_index_tbl, assign action 'ADD'
8625   set_action_add
8626   ( p_key                    => p_key,
8627     p_group_num              => p_group_num,
8628     p_target_lines_index_tbl => l_index_tbl,
8629     p_check_line_num_assign  => FND_API.G_FALSE,
8630     x_processing_row_tbl     => x_processing_row_tbl,
8631     x_lines                  => x_lines
8632   );
8633 
8634   d_position := 60;
8635 
8636   PO_PDOI_UTL.remove_session_gt_records
8637   ( p_key => l_data_key
8638   );
8639 
8640   IF (PO_LOG.d_proc) THEN
8641     PO_LOG.proc_end(d_module);
8642   END IF;
8643 
8644 EXCEPTION
8645   WHEN OTHERS THEN
8646     PO_MESSAGE_S.add_exc_msg
8647     (
8648       p_pkg_name => d_pkg_name,
8649       p_procedure_name => d_api_name || '.' || d_position
8650     );
8651     RAISE;
8652 END uniqueness_check_on_line_num;
8653 
8654 
8655 -- bug5093465 START
8656 -----------------------------------------------------------------------
8657 --Start of Comments
8658 --Name: set_action_add
8659 --Function:
8660 --  Assign ADD as the action for the line. If needed, assign new line number
8661 --  for the line
8662 --Parameters:
8663 --IN:
8664 --  p_key
8665 --    key value used to identify rows in temp table
8666 --  p_group_num
8667 --    the new group number that is going to be assigned to rows
8668 --    whose action can be decided in this procedure
8669 --  p_target_line_index_tbl
8670 --    Table containing indexes for the lines to be assigned with action
8671 --    'ADD'
8672 --  p_check_line_num_assign
8673 --    If FND_API.G_TRUE, then it checks whether a new line number needs
8674 --    to be assigned to the record. FND_API.G_FALSE otherwise.
8675 --IN OUT:
8676 --  x_processing_row_tbl
8677 --    index table of rows that are going to be processed
8678 --  x_lines
8679 --    record of line information read within the batch
8680 --OUT:
8681 --End of Comments
8682 ------------------------------------------------------------------------
8683 
8684 PROCEDURE set_action_add
8685 (
8686   p_key                   IN po_session_gt.key%TYPE,
8687   p_group_num             IN NUMBER,
8688   p_target_lines_index_tbl IN PO_TBL_NUMBER,
8689   p_check_line_num_assign IN VARCHAR2,
8690   x_processing_row_tbl    IN OUT NOCOPY DBMS_SQL.NUMBER_TABLE,
8691   x_lines                 IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
8692 ) IS
8693 
8694 
8695 d_api_name CONSTANT VARCHAR2(30) := 'set_action_add';
8696 d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
8697 d_position NUMBER;
8698 
8699 l_index NUMBER;
8700 BEGIN
8701   d_position := 0;
8702 
8703   IF (PO_LOG.d_proc) THEN
8704     PO_LOG.proc_begin(d_module);
8705   END IF;
8706 
8707   -- mark all lines as to be created
8708   FOR i IN 1..p_target_lines_index_tbl.COUNT
8709   LOOP
8710 
8711     d_position := 10;
8712     l_index := p_target_lines_index_tbl(i);
8713 
8714     x_lines.action_tbl(l_index) := PO_PDOI_CONSTANTS.g_ACTION_ADD;
8715     x_lines.group_num_tbl(l_index) := p_group_num;
8716     x_lines.po_line_id_tbl(l_index) := PO_PDOI_MAINPROC_UTL_PVT.get_next_po_line_id;
8717 
8718     IF (p_check_line_num_assign = FND_API.G_TRUE) THEN
8719 
8720 
8721       IF (x_lines.line_num_tbl(l_index) IS NULL OR
8722           x_lines.line_num_unique_tbl(l_index) = FND_API.g_FALSE) THEN
8723 
8724         d_position := 20;
8725 
8726         x_lines.line_num_tbl(l_index) :=
8727           PO_PDOI_MAINPROC_UTL_PVT.get_next_line_num
8728           (
8729             p_po_header_id => x_lines.hd_po_header_id_tbl(l_index)
8730           );
8731 
8732         IF (PO_LOG.d_stmt) THEN
8733           PO_LOG.stmt(d_module, d_position, 'assign new line num', x_lines.line_num_tbl(l_index));
8734         END IF;
8735 
8736       END IF;
8737 
8738     END IF;
8739 
8740     d_position := 30;
8741 
8742     -- action is determined. No longer need to process it
8743     x_processing_row_tbl.DELETE(l_index);
8744 
8745     IF (PO_LOG.d_stmt) THEN
8746       PO_LOG.stmt(d_module, d_position, 'match index', l_index);
8747       PO_LOG.stmt(d_module, d_position, 'po line id',
8748                   x_lines.po_line_id_tbl(l_index));
8749     END IF;
8750 
8751   END LOOP;
8752 
8753   IF (PO_LOG.d_proc) THEN
8754     PO_LOG.proc_end(d_module);
8755   END IF;
8756 
8757 EXCEPTION
8758   WHEN OTHERS THEN
8759     PO_MESSAGE_S.add_exc_msg
8760     (
8761       p_pkg_name => d_pkg_name,
8762       p_procedure_name => d_api_name || '.' || d_position
8763     );
8764     RAISE;
8765 END set_action_add;
8766 
8767 -- bug5093465 END
8768 
8769 
8770 
8771 -----------------------------------------------------------------------
8772 --Start of Comments
8773 --Name: validate_attr_tlp
8774 --Function:
8775 --  validate whether there is a line with creation language existing
8776 --  in po_attr_values_tlp_interface table; If rows with creation lang
8777 --  does not exist but rows in other langs exist, insert error in
8778 --  error interface table
8779 --  The procedure is called only when line action = 'CREATE'
8780 --Parameters:
8781 --IN:
8782 --IN OUT:
8783 --  x_lines
8784 --    record of line information read within the batch
8785 --OUT:
8786 --End of Comments
8787 ------------------------------------------------------------------------
8788 PROCEDURE validate_attr_tlp
8789 (
8790   x_lines IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
8791 ) IS
8792 
8793   d_api_name CONSTANT VARCHAR2(30) := 'validate_attr_tlp';
8794   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
8795   d_position NUMBER;
8796 
8797   l_key po_session_gt.key%TYPE;
8798 
8799   -- table used to save the index of the each row
8800   l_index_tbl DBMS_SQL.NUMBER_TABLE;
8801   l_index     NUMBER;
8802 BEGIN
8803   d_position := 0;
8804 
8805   IF (PO_LOG.d_proc) THEN
8806     PO_LOG.proc_begin(d_module);
8807   END IF;
8808 
8809   -- assign a new key used in temporary table
8810   l_key := PO_CORE_S.get_session_gt_nextval;
8811 
8812   -- initialize table containing the row number(index)
8813   PO_PDOI_UTL.generate_ordered_num_list
8814   (
8815     p_size     => x_lines.rec_count,
8816     x_num_list => l_index_tbl
8817   );
8818 
8819   FORALL i IN 1..x_lines.rec_count
8820     INSERT INTO po_session_gt
8821     (
8822       key,
8823       num1
8824     )
8825     SELECT
8826       l_key,
8827       l_index_tbl(i)
8828     FROM   DUAL
8829     WHERE  NOT EXISTS
8830            (
8831              SELECT 1
8832              FROM   po_attr_values_tlp_interface
8833              WHERE  interface_line_id = x_lines.intf_line_id_tbl(i)
8834              AND    language = x_lines.hd_created_language_tbl(i)
8835            )
8836     AND    EXISTS
8837            (
8838              SELECT 1
8839              FROM   po_attr_values_tlp_interface
8840              WHERE  interface_line_id = x_lines.intf_line_id_tbl(i)
8841              AND    language <> x_lines.hd_created_language_tbl(i)
8842            );
8843 
8844   d_position := 10;
8845 
8846   DELETE FROM po_session_gt
8847   WHERE key = l_key
8848   RETURNING num1 BULK COLLECT INTO l_index_tbl;
8849 
8850   d_position := 20;
8851 
8852   FOR i IN 1..l_index_tbl.COUNT
8853   LOOP
8854     l_index := l_index_tbl(i);
8855 
8856     IF (PO_LOG.d_stmt) THEN
8857       PO_LOG.stmt(d_module, d_position, 'error on index', l_index);
8858     END IF;
8859 
8860     PO_PDOI_ERR_UTL.add_fatal_error
8861     (
8862       p_interface_header_id  => x_lines.intf_header_id_tbl(l_index),
8863       p_interface_line_id    => x_lines.intf_line_id_tbl(l_index),
8864       p_error_message_name   => 'PO_PDOI_NO_TLP_IN_CREATE_LANG',
8865       p_table_name           => 'PO_LINES_INTERFACE',
8866       p_column_name          => NULL,
8867       p_column_value         => NULL,
8868       p_validation_id        => PO_VAL_CONSTANTS.c_language,
8869       p_lines                => x_lines
8870     );
8871 
8872     x_lines.error_flag_tbl(l_index) := FND_API.g_TRUE;
8873   END LOOP;
8874 
8875   IF (PO_LOG.d_proc) THEN
8876     PO_LOG.proc_end(d_module);
8877   END IF;
8878 
8879 EXCEPTION
8880   WHEN OTHERS THEN
8881     PO_MESSAGE_S.add_exc_msg
8882     (
8883       p_pkg_name => d_pkg_name,
8884       p_procedure_name => d_api_name || '.' || d_position
8885     );
8886     RAISE;
8887 END validate_attr_tlp;
8888 
8889 -----------------------------------------------------------------------
8890 --Start of Comments
8891 --Name: populate_error_flag
8892 --Function:
8893 --  corresponding value in error_flag_tbl will be set with value FND_API.G_FALSE.
8894 --Parameters:
8895 --IN:
8896 --x_results
8897 --  The validation results that contains the errored line information.
8898 --IN OUT:
8899 --x_lines
8900 --  The record contains the values to be validated.
8901 --  If there is error(s) on any attribute of the price differential row,
8902 --  corresponding value in error_flag_tbl will be set with value
8903 --  FND_API.G_FALSE.
8904 --OUT:
8905 --End of Comments
8906 ------------------------------------------------------------------------
8907 PROCEDURE populate_error_flag
8908 (
8909   x_results           IN     po_validation_results_type,
8910   x_lines             IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
8911 ) IS
8912 
8913   d_api_name CONSTANT VARCHAR2(30) := 'populate_error_flag';
8914   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
8915   d_position NUMBER;
8916 
8917   l_index_tbl DBMS_SQL.number_table;
8918 
8919 BEGIN
8920   d_position := 0;
8921 
8922   IF (PO_LOG.d_proc) THEN
8923     PO_LOG.proc_begin(d_module);
8924   END IF;
8925 
8926   d_position := 10;
8927 
8928   FOR i IN 1 .. x_lines.intf_line_id_tbl.COUNT LOOP
8929       l_index_tbl(x_lines.intf_line_id_tbl(i)) := i;
8930   END LOOP;
8931 
8932   d_position := 20;
8933 
8934   FOR i IN 1 .. x_results.entity_id.COUNT LOOP
8935      IF x_results.result_type(i) = po_validations.c_result_type_failure THEN
8936         IF (PO_LOG.d_stmt) THEN
8937           PO_LOG.stmt(d_module, d_position, 'error on index',
8938                       l_index_tbl(x_results.entity_id(i)));
8939         END IF;
8940 
8941         x_lines.error_flag_tbl(l_index_tbl(x_results.entity_id(i))) := FND_API.g_TRUE;
8942      END IF;
8943   END LOOP;
8944 
8945   IF (PO_LOG.d_proc) THEN
8946     PO_LOG.proc_end(d_module);
8947   END IF;
8948 
8949 EXCEPTION
8950   WHEN OTHERS THEN
8951     PO_MESSAGE_S.add_exc_msg
8952     (
8953       p_pkg_name => d_pkg_name,
8954       p_procedure_name => d_api_name || '.' || d_position
8955     );
8956     RAISE;
8957 END populate_error_flag;
8958 
8959 -----------------------------------------------------------------------
8960 --Start of Comments
8961 --Name: handle_err_tolerance
8962 --Function:  This procedure maintains line processing information for each
8963 --           document. It also handles the error tolerance for Catalog Upload.
8964 --           Update PO_PDOI_PARAMS.g_docs_info(intf_header_id).number_of_processed_lines
8965 --           for each line.
8966 --
8967 --           If line contains error, increment
8968 --           PO_PDOI_PARAMS.g_docs_info(intf_header_id).number_of_errored_lines
8969 --
8970 --           If the number of errored lines exceeds the error tolerance, then set
8971 --           PO_PDOI_PARAMS.g_docs_info(intf_header_id).err_tolerance_exceeded to TRUE and
8972 --           set x_lines.need_to_reject_flag_tbl to TRUE.
8973 --
8974 --           If the line does not have error, increment
8975 --           PO_PDOI_PARAMS.g_docs_info(intf_header_id).number_of_valid_lines
8976 --Parameters:
8977 --IN OUT:
8978 --  x_lines
8979 --    record which stores all the line rows within the batch;
8980 --OUT:
8981 --End of Comments
8982 ------------------------------------------------------------------------
8983 PROCEDURE handle_err_tolerance
8984 (
8985   x_lines       IN OUT NOCOPY PO_PDOI_TYPES.lines_rec_type
8986 ) IS
8987 
8988   d_api_name CONSTANT VARCHAR2(30) := 'handle_err_tolerance';
8989   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
8990   d_position NUMBER;
8991 
8992   l_err_lines_tolerance  NUMBER := PO_PDOI_PARAMS.g_request.err_lines_tolerance;
8993   l_intf_header_id       NUMBER;
8994   l_num_errored_lines    NUMBER;
8995   l_num_processed_lines  NUMBER;
8996   l_num_valid_lines      NUMBER;
8997   l_remove_err_line_tbl  PO_TBL_NUMBER := PO_TBL_NUMBER();
8998 
8999 BEGIN
9000 
9001   d_position := 0;
9002 
9003   IF (PO_LOG.d_proc) THEN
9004     PO_LOG.proc_begin(d_module, 'err_lines_tolerance', l_err_lines_tolerance);
9005   END IF;
9006 
9007   FOR i IN 1 .. x_lines.rec_count
9008   LOOP
9009     l_intf_header_id := x_lines.intf_header_id_tbl(i);
9010 
9011     IF (PO_LOG.d_stmt) THEN
9012       PO_LOG.stmt(d_module, d_position, 'index', i);
9013       PO_LOG.stmt(d_module, d_position, 'intf header id', l_intf_header_id);
9014     END IF;
9015 
9016     d_position := 10;
9017 
9018     IF (PO_PDOI_PARAMS.g_request.calling_module = PO_PDOI_CONSTANTS.g_call_mod_CATALOG_UPLOAD AND
9019         PO_PDOI_PARAMS.g_docs_info(l_intf_header_id).err_tolerance_exceeded = FND_API.G_TRUE ) THEN
9020        x_lines.need_to_reject_flag_tbl(i) := FND_API.g_TRUE;
9021 
9022        -- bug 5215781:
9023        -- collect ids of lines for which errors on them would be removed from error interface
9024        -- table since error tolerance threshold is hit before them
9025        l_remove_err_line_tbl.EXTEND;
9026        l_remove_err_line_tbl(l_remove_err_line_tbl.COUNT) := x_lines.intf_line_id_tbl(i);
9027     ELSE
9028       l_num_processed_lines := PO_PDOI_PARAMS.g_docs_info(l_intf_header_id).number_of_processed_lines + 1;
9029       PO_PDOI_PARAMS.g_docs_info(l_intf_header_id).number_of_processed_lines := l_num_processed_lines;
9030 
9031       IF (PO_LOG.d_stmt) THEN
9032        PO_LOG.stmt(d_module, d_position, 'num_processed_lines', l_num_processed_lines);
9033       END IF;
9034 
9035       d_position := 20;
9036 
9037       IF x_lines.error_flag_tbl(i) = FND_API.g_TRUE THEN
9038         l_num_errored_lines := PO_PDOI_PARAMS.g_docs_info(l_intf_header_id).number_of_errored_lines + 1;
9039         PO_PDOI_PARAMS.g_docs_info(l_intf_header_id).number_of_errored_lines := l_num_errored_lines;
9040 
9041         -- set corresponding line to ERROR
9042         PO_PDOI_PARAMS.g_errored_lines(x_lines.intf_line_id_tbl(i)) := 'Y';
9043 
9044         IF (PO_LOG.d_stmt) THEN
9045           PO_LOG.stmt(d_module, d_position, 'num_errored_lines', l_num_errored_lines);
9046         END IF;
9047 
9048         d_position := 30;
9049 
9050         IF (PO_PDOI_PARAMS.g_request.calling_module =
9051               PO_PDOI_CONSTANTS.g_call_mod_CATALOG_UPLOAD AND
9052             l_num_errored_lines = l_err_lines_tolerance) THEN
9053 
9054            PO_PDOI_PARAMS.g_docs_info(l_intf_header_id).err_tolerance_exceeded := FND_API.g_TRUE;
9055         END IF;
9056 
9057         d_position := 40;
9058       ELSE
9059         d_position := 50;
9060 
9061         -- maintain number of valid lines
9062         l_num_valid_lines := PO_PDOI_PARAMS.g_docs_info(l_intf_header_id).number_of_valid_lines + 1;
9063         PO_PDOI_PARAMS.g_docs_info(l_intf_header_id).number_of_valid_lines := l_num_valid_lines;
9064 
9065       END IF;
9066     END IF;
9067   END LOOP;
9068 
9069   d_position := 60;
9070 
9071   -- Bug 5215781:
9072   -- remove the errors for lines from po_interface_errors if those lines are supposed to be processed
9073   -- after the line where we hit the error tolerance; That means, we want to rollback the changes if
9074   -- error tolerance is reached at some point
9075   PO_INTERFACE_ERRORS_UTL.flush_errors_tbl;
9076 
9077   FORALL i IN 1..l_remove_err_line_tbl.COUNT
9078     DELETE FROM PO_INTERFACE_ERRORS
9079     WHERE interface_line_id = l_remove_err_line_tbl(i);
9080 
9081   d_position := 70;
9082 
9083   IF (PO_LOG.d_proc) THEN
9084     PO_LOG.proc_end(d_module, 'num_processed_lines', l_num_processed_lines);
9085     PO_LOG.proc_end(d_module, 'num_errored_lines', l_num_errored_lines);
9086   END IF;
9087 
9088 EXCEPTION
9089   WHEN OTHERS THEN
9090     PO_MESSAGE_S.add_exc_msg
9091     (
9092       p_pkg_name => d_pkg_name,
9093       p_procedure_name => d_api_name || '.' || d_position
9094     );
9095     RAISE;
9096 END handle_err_tolerance;
9097 
9098 
9099 --CLM PDOI Integration
9100 
9101 PROCEDURE derive_contract_type
9102 (
9103   p_key                       IN po_session_gt.key%TYPE,
9104   p_index_tbl                 IN DBMS_SQL.NUMBER_TABLE,
9105   p_contract_type_display_tbl IN PO_TBL_VARCHAR240,
9106   x_contract_type_tbl         IN OUT NOCOPY PO_TBL_VARCHAR240
9107 ) IS
9108 
9109   d_api_name CONSTANT VARCHAR2(30) := 'derive_contract_type';
9110   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
9111   d_position NUMBER;
9112 
9113   -- tables to store the derived result
9114   l_index_tbl        PO_TBL_NUMBER;
9115   l_result_tbl       PO_TBL_VARCHAR240;
9116 BEGIN
9117   d_position := 0;
9118 
9119   IF (PO_LOG.d_proc) THEN
9120     PO_LOG.proc_begin(d_module);--, 'p_contract_type_display_tbl', p_contract_type_display_tbl);
9121   END IF;
9122 
9123   --derive contract_type based on contract_type_display
9124   FORALL i IN 1..p_index_tbl.COUNT
9125     INSERT INTO po_session_gt(key, num1, char1)
9126     SELECT p_key,
9127            p_index_tbl(i),
9128            lookup_code
9129     FROM   PO_LOOKUP_CODES
9130     WHERE  p_contract_type_display_tbl(i) IS NOT NULL
9131     AND    x_contract_type_tbl(i) IS null
9132     AND    LOOKUP_TYPE IN ('PO_FEDERAL_CONTRACT_TYPES_AMT','PO_FEDERAL_CONTRACT_TYPES_QTY')
9133     AND    displayed_field = p_contract_type_display_tbl(i)
9134     AND    ROWNUM < 2;
9135 
9136     d_position := 10;
9137 
9138   -- read result from temp table, and delete the records from temp table
9139   DELETE FROM po_session_gt
9140   WHERE  key = p_key
9141   RETURNING num1, char1 BULK COLLECT INTO l_index_tbl, l_result_tbl;
9142 
9143   d_position := 20;
9144 
9145   -- push the result back to x_line_type_ids
9146   FOR i IN 1..l_index_tbl.COUNT
9147   LOOP
9148     IF (PO_LOG.d_stmt) THEN
9149       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
9150       PO_LOG.stmt(d_module, d_position, 'new contract type', l_result_tbl(i));
9151     END IF;
9152 
9153     x_contract_type_tbl(l_index_tbl(i)) := l_result_tbl(i);
9154   END LOOP;
9155 
9156   IF (PO_LOG.d_proc) THEN
9157     PO_LOG.proc_end(d_module);
9158   END IF;
9159 
9160 EXCEPTION
9161   WHEN OTHERS THEN
9162     PO_MESSAGE_S.add_exc_msg
9163     (
9164       p_pkg_name => d_pkg_name,
9165       p_procedure_name => d_api_name || '.' || d_position
9166     );
9167     RAISE;
9168 END derive_contract_type;
9169 
9170 
9171 
9172 PROCEDURE derive_cost_constraint
9173 (
9174   p_key                                IN po_session_gt.key%TYPE,
9175   p_index_tbl                          IN DBMS_SQL.NUMBER_TABLE,
9176   p_cost_constraint_display_tbl IN PO_TBL_VARCHAR240,
9177   x_cost_constraint_tbl         IN OUT NOCOPY PO_TBL_VARCHAR30
9178 ) IS
9179 
9180   d_api_name CONSTANT VARCHAR2(30) := 'derive_cost_constraint';
9181   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
9182   d_position NUMBER;
9183 
9184   -- tables to store the derived result
9185   l_index_tbl        PO_TBL_NUMBER;
9186   l_result_tbl       PO_TBL_VARCHAR240;
9187 BEGIN
9188   d_position := 0;
9189 
9190   IF (PO_LOG.d_proc) THEN
9191     PO_LOG.proc_begin(d_module);--, 'p_cost_constraint_display_tbl', p_cost_constraint_display_tbl);
9192   END IF;
9193 
9194   --derive cost_constraint based on cost_constraint_display
9195   FORALL i IN 1..p_index_tbl.COUNT
9196     INSERT INTO po_session_gt(key, num1, char1)
9197     SELECT p_key,
9198            p_index_tbl(i),
9199            lookup_code
9200     FROM   PO_LOOKUP_CODES
9201     WHERE  p_cost_constraint_display_tbl(i) IS NOT NULL
9202     AND    x_cost_constraint_tbl(i) IS null
9203     AND    LOOKUP_TYPE = 'PO_FEDERAL_COST_CONSTRAINTS'
9204     AND    displayed_field = p_cost_constraint_display_tbl(i);
9205 
9206     d_position := 10;
9207 
9208   -- read result from temp table, and delete the records from temp table
9209   DELETE FROM po_session_gt
9210   WHERE  key = p_key
9211   RETURNING num1, char1 BULK COLLECT INTO l_index_tbl, l_result_tbl;
9212 
9213   d_position := 20;
9214 
9215   -- push the result back to x_line_type_ids
9216   FOR i IN 1..l_index_tbl.COUNT
9217   LOOP
9218     IF (PO_LOG.d_stmt) THEN
9219       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
9220       PO_LOG.stmt(d_module, d_position, 'new cost constraint', l_result_tbl(i));
9221     END IF;
9222 
9223     x_cost_constraint_tbl(l_index_tbl(i)) := l_result_tbl(i);
9224   END LOOP;
9225 
9226   IF (PO_LOG.d_proc) THEN
9227     PO_LOG.proc_end(d_module);
9228   END IF;
9229 
9230 EXCEPTION
9231   WHEN OTHERS THEN
9232     PO_MESSAGE_S.add_exc_msg
9233     (
9234       p_pkg_name => d_pkg_name,
9235       p_procedure_name => d_api_name || '.' || d_position
9236     );
9237     RAISE;
9238 END derive_cost_constraint;
9239 
9240 
9241 
9242 PROCEDURE derive_clm_idc_type
9243 (
9244   p_key                      IN po_session_gt.key%TYPE,
9245   p_index_tbl                IN DBMS_SQL.NUMBER_TABLE,
9246   p_clm_idc_type_display_tbl IN PO_TBL_VARCHAR240,
9247   x_clm_idc_type_tbl         IN OUT NOCOPY PO_TBL_VARCHAR240
9248 ) IS
9249 
9250   d_api_name CONSTANT VARCHAR2(30) := 'derive_clm_idc_type';
9251   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
9252   d_position NUMBER;
9253 
9254   -- tables to store the derived result
9255   l_index_tbl        PO_TBL_NUMBER;
9256   l_result_tbl       PO_TBL_VARCHAR240;
9257 BEGIN
9258   d_position := 0;
9259 
9260   IF (PO_LOG.d_proc) THEN
9261     PO_LOG.proc_begin(d_module);--, 'p_clm_idc_type_display_tbl', p_clm_idc_type_display_tbl);
9262   END IF;
9263 
9264   --derive idc_type based on clm_idc_type_display
9265   FORALL i IN 1..p_index_tbl.COUNT
9266     INSERT INTO po_session_gt(key, num1, char1)
9267     SELECT p_key,
9268            p_index_tbl(i),
9269            lookup_code
9270     FROM   PO_LOOKUP_CODES
9271     WHERE  p_clm_idc_type_display_tbl(i) IS NOT NULL
9272     AND    x_clm_idc_type_tbl(i) IS null
9273     AND    LOOKUP_TYPE = 'PO_FEDERAL_IDC_TYPES'
9274     AND    displayed_field = p_clm_idc_type_display_tbl(i);
9275 
9276     d_position := 10;
9277 
9278   -- read result from temp table, and delete the records from temp table
9279   DELETE FROM po_session_gt
9280   WHERE  key = p_key
9281   RETURNING num1, char1 BULK COLLECT INTO l_index_tbl, l_result_tbl;
9282 
9283   d_position := 20;
9284 
9285   -- push the result back to x_line_type_ids
9286   FOR i IN 1..l_index_tbl.COUNT
9287   LOOP
9288     IF (PO_LOG.d_stmt) THEN
9289       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
9290       PO_LOG.stmt(d_module, d_position, 'new idc type', l_result_tbl(i));
9291     END IF;
9292 
9293     x_clm_idc_type_tbl(l_index_tbl(i)) := l_result_tbl(i);
9294   END LOOP;
9295 
9296   IF (PO_LOG.d_proc) THEN
9297     PO_LOG.proc_end(d_module);
9298   END IF;
9299 
9300 EXCEPTION
9301   WHEN OTHERS THEN
9302     PO_MESSAGE_S.add_exc_msg
9303     (
9304       p_pkg_name => d_pkg_name,
9305       p_procedure_name => d_api_name || '.' || d_position
9306     );
9307     RAISE;
9308 END derive_clm_idc_type;
9309 
9310 
9311 
9312 PROCEDURE derive_clm_base_line_num
9313 (
9314   p_key                        IN po_session_gt.key%TYPE,
9315   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
9316   p_clm_base_line_num_disp_tbl IN PO_TBL_VARCHAR240,
9317   p_intf_line_id_tbl           IN PO_TBL_NUMBER,
9318   p_intf_header_id_tbl         IN PO_TBL_NUMBER,
9319   p_line_num_display_tbl       IN PO_TBL_VARCHAR100,
9320   p_clm_option_indicator       IN PO_TBL_VARCHAR1,
9321   x_clm_base_line_num_tbl      IN OUT NOCOPY PO_TBL_NUMBER
9322 ) IS
9323 
9324   d_api_name CONSTANT VARCHAR2(30) := 'derive_clm_base_line_num';
9325   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
9326   d_position NUMBER;
9327 
9328   -- tables to store the derived result
9329   l_index_tbl        PO_TBL_NUMBER;
9330   l_result_tbl       PO_TBL_NUMBER;
9331 BEGIN
9332   d_position := 0;
9333 
9334   IF (PO_LOG.d_proc) THEN
9335     PO_LOG.proc_begin(d_module);--, 'p_clm_base_line_num_disp_tbl', p_clm_base_line_num_disp_tbl);
9336   END IF;
9337 
9338   --derive clm_base_line_num based on clm_base_line_num_disp
9339   FORALL i IN 1..p_index_tbl.COUNT
9340     INSERT INTO po_session_gt(key, num1, num2, num3, char1, char2, char3, num4)
9341     SELECT p_key,
9342            p_index_tbl(i),
9343            p_intf_header_id_tbl(i),
9344            p_intf_line_id_tbl(i),
9345            p_line_num_display_tbl(i),
9346            p_clm_base_line_num_disp_tbl(i),
9347            p_clm_option_indicator(i),
9348            x_clm_base_line_num_tbl(i)
9349     FROM dual;
9350 
9351 
9352   UPDATE po_session_gt psg1
9353   SET psg1.num4 = ( SELECT psg2.num3 FROM po_session_gt psg2
9354                     WHERE  psg1.char2 = psg2.char1
9355                     AND    psg1.num2  = psg2.num2
9356                   )
9357   WHERE psg1.char2 IS NOT NULL
9358   AND   psg1.num4 IS NULL
9359   AND   Nvl(psg1.char3,'*') = 'O';
9360 
9361    -- read result from temp table, and delete the records from temp table
9362   DELETE FROM po_session_gt
9363   WHERE  key = p_key
9364   RETURNING num1, num4 BULK COLLECT INTO l_index_tbl, l_result_tbl;
9365 
9366   d_position := 20;
9367 
9368   -- push the result back to x_line_type_ids
9369   FOR i IN 1..l_index_tbl.COUNT
9370   LOOP
9371     IF (PO_LOG.d_stmt) THEN
9372       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
9373       PO_LOG.stmt(d_module, d_position, 'new base line num', l_result_tbl(i));
9374     END IF;
9375     x_clm_base_line_num_tbl(l_index_tbl(i)) := l_result_tbl(i);
9376   END LOOP;
9377 
9378   IF (PO_LOG.d_proc) THEN
9379     PO_LOG.proc_end(d_module);
9380   END IF;
9381 
9382 EXCEPTION
9383   WHEN OTHERS THEN
9384     PO_MESSAGE_S.add_exc_msg
9385     (
9386       p_pkg_name => d_pkg_name,
9387       p_procedure_name => d_api_name || '.' || d_position
9388     );
9389     RAISE;
9390 END derive_clm_base_line_num;
9391 
9392 
9393 PROCEDURE derive_from_header_id
9394 (
9395   p_key                        IN po_session_gt.key%TYPE,
9396   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
9397   p_from_header_disp_tbl       IN PO_TBL_VARCHAR240,
9398   x_from_header_id_tbl         IN OUT NOCOPY PO_TBL_NUMBER
9399 ) IS
9400 
9401   d_api_name CONSTANT VARCHAR2(30) := 'derive_from_header_id';
9402   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
9403   d_position NUMBER;
9404 
9405   -- tables to store the derived result
9406   l_index_tbl        PO_TBL_NUMBER;
9407   l_result_tbl       PO_TBL_NUMBER;
9408 BEGIN
9409   d_position := 0;
9410 
9411   IF (PO_LOG.d_proc) THEN
9412     PO_LOG.proc_begin(d_module);--, 'p_clm_base_line_num_disp_tbl', p_clm_base_line_num_disp_tbl);
9413   END IF;
9414 
9415   --derive from_header_id based on from_header_id
9416   FORALL i IN 1..p_index_tbl.COUNT
9417     INSERT INTO po_session_gt(key, num1, char1, num2)
9418     SELECT p_key,
9419            p_index_tbl(i),
9420            p_from_header_disp_tbl(i),
9421            x_from_header_id_tbl(i)
9422     FROM dual;
9423 
9424   UPDATE po_session_gt psg
9425   SET psg.num2 = ( SELECT phi.po_header_id
9426                    FROM po_headers_all phi
9427                    WHERE clm_document_number = psg.char1
9428                  )
9429   WHERE psg.char1 IS NOT NULL
9430   AND   psg.num2 IS NULL;
9431 
9432    -- read result from temp table, and delete the records from temp table
9433   DELETE FROM po_session_gt
9434   WHERE  key = p_key
9435   RETURNING num1, num2 BULK COLLECT INTO l_index_tbl, l_result_tbl;
9436 
9437   d_position := 20;
9438 
9439   -- push the result back to x_line_type_ids
9440   FOR i IN 1..l_index_tbl.COUNT
9441   LOOP
9442     IF (PO_LOG.d_stmt) THEN
9443       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
9444       PO_LOG.stmt(d_module, d_position, 'new from header id', l_result_tbl(i));
9445     END IF;
9446     x_from_header_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
9447   END LOOP;
9448 
9449   IF (PO_LOG.d_proc) THEN
9450     PO_LOG.proc_end(d_module);
9451   END IF;
9452 
9453 EXCEPTION
9454   WHEN OTHERS THEN
9455     PO_MESSAGE_S.add_exc_msg
9456     (
9457       p_pkg_name => d_pkg_name,
9458       p_procedure_name => d_api_name || '.' || d_position
9459     );
9460     RAISE;
9461 END derive_from_header_id;
9462 
9463 
9464 
9465 
9466 
9467 PROCEDURE derive_from_line_id
9468 (
9469   p_key                        IN po_session_gt.key%TYPE,
9470   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
9471   p_from_line_disp_tbl         IN PO_TBL_VARCHAR240,
9472   p_from_header_id_tbl         IN PO_TBL_NUMBER,
9473   x_from_line_id_tbl           IN OUT NOCOPY PO_TBL_NUMBER
9474 ) IS
9475 
9476   d_api_name CONSTANT VARCHAR2(30) := 'derive_from_line_id';
9477   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
9478   d_position NUMBER;
9479 
9480   -- tables to store the derived result
9481   l_index_tbl        PO_TBL_NUMBER;
9482   l_result_tbl       PO_TBL_NUMBER;
9483 BEGIN
9484   d_position := 0;
9485 
9486   IF (PO_LOG.d_proc) THEN
9487     PO_LOG.proc_begin(d_module);--, 'p_clm_base_line_num_disp_tbl', p_clm_base_line_num_disp_tbl);
9488   END IF;
9489 
9490   --derive from_line_id based on from_line_disp_tbl
9491   FORALL i IN 1..p_index_tbl.COUNT
9492     INSERT INTO po_session_gt(key, num1, char1, num2, num3)
9493     SELECT p_key,
9494            p_index_tbl(i),
9495            p_from_line_disp_tbl(i),
9496            p_from_header_id_tbl(i),
9497            x_from_line_id_tbl(i)
9498     FROM dual;
9499 
9500   UPDATE po_session_gt psg
9501   SET psg.num3 = ( SELECT PLI.po_line_id
9502                    FROM po_lines_all pli
9503                    WHERE PLI.po_header_id = psg.num2
9504                    AND   PLI.line_num_display = psg.char1
9505                  )
9506   WHERE psg.num2 IS NOT null
9507   AND   psg.char1 IS NOT NULL
9508   AND   psg.num3 IS NULL;
9509 
9510    -- read result from temp table, and delete the records from temp table
9511   DELETE FROM po_session_gt
9512   WHERE  key = p_key
9513   RETURNING num1, num3 BULK COLLECT INTO l_index_tbl, l_result_tbl;
9514 
9515   d_position := 20;
9516 
9517   -- push the result back to x_from_line_id_tbl
9518   FOR i IN 1..l_index_tbl.COUNT
9519   LOOP
9520     IF (PO_LOG.d_stmt) THEN
9521       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
9522       PO_LOG.stmt(d_module, d_position, 'new from line id', l_result_tbl(i));
9523     END IF;
9524 	x_from_line_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
9525   END LOOP;
9526 
9527   IF (PO_LOG.d_proc) THEN
9528     PO_LOG.proc_end(d_module);
9529   END IF;
9530 
9531 EXCEPTION
9532   WHEN OTHERS THEN
9533     PO_MESSAGE_S.add_exc_msg
9534     (
9535       p_pkg_name => d_pkg_name,
9536       p_procedure_name => d_api_name || '.' || d_position
9537     );
9538     RAISE;
9539 END derive_from_line_id;
9540 
9541 
9542 
9543 PROCEDURE default_clm_option_indicator
9544 (
9545   p_key                        IN po_session_gt.key%TYPE,
9546   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
9547   p_intf_line_id_tbl           IN PO_TBL_NUMBER,
9548   p_clm_base_line_num_tbl      IN PO_TBL_NUMBER,
9549   x_clm_option_indicator_tbl   IN OUT NOCOPY PO_TBL_VARCHAR1
9550 ) IS
9551 
9552   d_api_name CONSTANT VARCHAR2(30) := 'default_clm_option_indicator';
9553   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
9554   d_position NUMBER;
9555 
9556   -- tables to store the derived result
9557   l_index_tbl        PO_TBL_NUMBER;
9558   l_result_tbl       PO_TBL_VARCHAR1;
9559 BEGIN
9560   d_position := 0;
9561 
9562   IF (PO_LOG.d_proc) THEN
9563     PO_LOG.proc_begin(d_module);
9564   END IF;
9565 
9566   --derive default_clm_option_indicator based on clm_base_line_num
9567   FORALL i IN 1..p_index_tbl.COUNT
9568     INSERT INTO po_session_gt(key, num1, num2, num3, char1)
9569     SELECT p_key,
9570            p_index_tbl(i),
9571            p_intf_line_id_tbl(i),
9572            p_clm_base_line_num_tbl(i),
9573            x_clm_option_indicator_tbl(i)
9574     FROM dual;
9575 
9576   UPDATE po_session_gt psg1
9577   SET    psg1.char1 = 'B'
9578   WHERE  psg1.num2 IN ( SELECT psg2.num3 FROM po_session_gt psg2
9579                         WHERE  Nvl(psg2.char1,'*') = 'O'
9580                         AND    psg2.num3 IS NOT null
9581                       )
9582   AND    psg1.char1 IS NULL;
9583 
9584   -- read result from temp table, and delete the records from temp table
9585   DELETE FROM po_session_gt
9586   WHERE  key = p_key
9587   RETURNING num1, char1 BULK COLLECT INTO l_index_tbl, l_result_tbl;
9588 
9589   d_position := 20;
9590 
9591   -- push the result back to x_clm_option_indicator_tbl
9592   FOR i IN 1..l_index_tbl.COUNT
9593   LOOP
9594     IF (PO_LOG.d_stmt) THEN
9595       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
9596       PO_LOG.stmt(d_module, d_position, 'new option indicator', l_result_tbl(i));
9597     END IF;
9598 
9599     x_clm_option_indicator_tbl(l_index_tbl(i)) := l_result_tbl(i);
9600   END LOOP;
9601 
9602   IF (PO_LOG.d_proc) THEN
9603     PO_LOG.proc_end(d_module);
9604   END IF;
9605 
9606 EXCEPTION
9607   WHEN OTHERS THEN
9608     PO_MESSAGE_S.add_exc_msg
9609     (
9610       p_pkg_name => d_pkg_name,
9611       p_procedure_name => d_api_name || '.' || d_position
9612     );
9613     RAISE;
9614 
9615 END default_clm_option_indicator;
9616 
9617 
9618 PROCEDURE default_clm_option_num
9619 (
9620   p_key                        IN po_session_gt.key%TYPE,
9621   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
9622   p_intf_header_id_tbl         IN PO_TBL_NUMBER,
9623   p_intf_line_id_tbl           IN PO_TBL_NUMBER,
9624   p_clm_base_line_num_tbl      IN PO_TBL_NUMBER,
9625   p_clm_option_indicator_tbl   IN PO_TBL_VARCHAR1,
9626   x_clm_option_num_tbl         IN OUT NOCOPY PO_TBL_NUMBER
9627 ) IS
9628 
9629   d_api_name CONSTANT VARCHAR2(30) := 'default_clm_option_indicator';
9630   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
9631   d_position NUMBER;
9632 
9633   -- tables to store the derived result
9634   l_index_tbl        PO_TBL_NUMBER;
9635 
9636   l_result_tbl        PO_TBL_NUMBER;
9637   l_option_num_tbl    PO_TBL_NUMBER;
9638 BEGIN
9639   d_position := 0;
9640 
9641   IF (PO_LOG.d_proc) THEN
9642     PO_LOG.proc_begin(d_module);
9643   END IF;
9644 
9645   FORALL i IN 1..p_index_tbl.COUNT
9646     INSERT INTO po_session_gt(key, num1, num2, num3, num4, char1, num5)
9647     SELECT p_key,
9648            p_index_tbl(i),
9649            p_intf_header_id_tbl(i),
9650            p_intf_line_id_tbl(i),
9651            p_clm_base_line_num_tbl(i),
9652            p_clm_option_indicator_tbl(i),
9653            null
9654     FROM dual;
9655 
9656   SELECT num1,
9657          Rank() over (PARTITION BY num4 ORDER BY num3)
9658   BULK COLLECT INTO l_index_tbl, l_option_num_tbl
9659   FROM   po_session_gt
9660   WHERE  num4 IS NOT NULL;
9661 
9662   FORALL i IN 1..l_index_tbl.Count
9663     UPDATE po_session_gt
9664     SET    num5 = l_option_num_tbl(i)
9665     WHERE  KEY = p_key
9666     AND    num1 = l_index_tbl(i);
9667 
9668   l_index_tbl.DELETE;
9669 
9670   -- read result from temp table, and delete the records from temp table
9671   DELETE FROM po_session_gt
9672   WHERE  key = p_key
9673   RETURNING num1, num5 BULK COLLECT INTO l_index_tbl, l_result_tbl;
9674 
9675   d_position := 20;
9676 
9677   -- push the result back to x_clm_option_num_tbl
9678   FOR i IN 1..l_index_tbl.COUNT
9679   LOOP
9680     IF (PO_LOG.d_stmt) THEN
9681       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
9682       PO_LOG.stmt(d_module, d_position, 'new option num', l_result_tbl(i));
9683     END IF;
9684 
9685     x_clm_option_num_tbl(l_index_tbl(i)) := l_result_tbl(i);
9686   END LOOP;
9687 
9688   IF (PO_LOG.d_proc) THEN
9689     PO_LOG.proc_end(d_module);
9690   END IF;
9691 
9692 EXCEPTION
9693   WHEN OTHERS THEN
9694     PO_MESSAGE_S.add_exc_msg
9695     (
9696       p_pkg_name => d_pkg_name,
9697       p_procedure_name => d_api_name || '.' || d_position
9698     );
9699     RAISE;
9700 
9701 END default_clm_option_num;
9702 
9703 
9704 
9705 
9706 PROCEDURE default_from_header_id
9707 (
9708   p_key                        IN po_session_gt.key%TYPE,
9709   p_index_tbl                  IN DBMS_SQL.NUMBER_TABLE,
9710   p_intf_header_id_tbl         IN PO_TBL_NUMBER,
9711   p_intf_line_id_tbl           IN PO_TBL_NUMBER,
9712   x_from_header_id_tbl         IN OUT NOCOPY PO_TBL_NUMBER
9713 ) IS
9714 
9715   d_api_name CONSTANT VARCHAR2(30) := 'default_from_header_id';
9716   d_module   CONSTANT VARCHAR2(255) := d_pkg_name || d_api_name || '.';
9717   d_position NUMBER;
9718 
9719   -- tables to store the derived result
9720   l_index_tbl        PO_TBL_NUMBER;
9721 
9722   l_result_tbl        PO_TBL_NUMBER;
9723 
9724 BEGIN
9725   d_position := 0;
9726 
9727   IF (PO_LOG.d_proc) THEN
9728     PO_LOG.proc_begin(d_module);
9729   END IF;
9730 
9731   FORALL i IN 1..p_index_tbl.COUNT
9732     INSERT INTO po_session_gt(key, num1, num2, num3, num4)
9733     SELECT p_key,
9734            p_index_tbl(i),
9735            p_intf_header_id_tbl(i),
9736            p_intf_line_id_tbl(i),
9737            x_from_header_id_tbl(i)
9738     FROM dual;
9739 
9740   UPDATE po_session_gt psg
9741   SET psg.num4 = ( SELECT phd.clm_source_document_id
9742                    FROM po_headers_draft_all phd, po_lines_interface PLI, po_headers_interface phi
9743                    WHERE PLI.interface_line_id = psg.num3
9744                    AND   PLI.interface_header_id = phi.interface_header_id
9745                    AND   phi.po_header_id = phd.po_header_id
9746                  )
9747   WHERE psg.num4 IS NULL;
9748 
9749   -- read result from temp table, and delete the records from temp table
9750   DELETE FROM po_session_gt
9751   WHERE  key = p_key
9752   RETURNING num1, num4 BULK COLLECT INTO l_index_tbl, l_result_tbl;
9753 
9754   d_position := 20;
9755 
9756   -- push the result back to x_from_header_id_tbl
9757   FOR i IN 1..l_index_tbl.COUNT
9758   LOOP
9759     IF (PO_LOG.d_stmt) THEN
9760       PO_LOG.stmt(d_module, d_position, 'index', l_index_tbl(i));
9761       PO_LOG.stmt(d_module, d_position, 'new from header id', l_result_tbl(i));
9762     END IF;
9763 
9764     x_from_header_id_tbl(l_index_tbl(i)) := l_result_tbl(i);
9765   END LOOP;
9766 
9767   IF (PO_LOG.d_proc) THEN
9768     PO_LOG.proc_end(d_module);
9769   END IF;
9770 
9771 EXCEPTION
9772   WHEN OTHERS THEN
9773     PO_MESSAGE_S.add_exc_msg
9774     (
9775       p_pkg_name => d_pkg_name,
9776       p_procedure_name => d_api_name || '.' || d_position
9777     );
9778     RAISE;
9779 
9780 END default_from_header_id;
9781 
9782 END PO_PDOI_LINE_PROCESS_PVT;