DBA Data[Home] [Help]

PACKAGE BODY: APPS.INL_INTERFACE_PVT

Source


1 PACKAGE BODY INL_INTERFACE_PVT AS
2 /* $Header: INLVINTB.pls 120.72.12020000.6 2013/02/19 17:22:02 acferrei ship $ */
3 
4     L_FND_USER_ID               CONSTANT NUMBER        := fnd_global.user_id;           --Bug#9660043
5     L_FND_CONC_PROGRAM_ID       CONSTANT NUMBER        := fnd_global.conc_program_id;   --Bug#9660043
6     L_FND_PROG_APPL_ID          CONSTANT NUMBER        := fnd_global.prog_appl_id ;     --Bug#9660043
7     L_FND_CONC_REQUEST_ID       CONSTANT NUMBER        := fnd_global.conc_request_id;   --Bug#9660043
8     L_FND_CONC_REQUEST_ID_INT            NUMBER        ;  --Bug#11794483B(error when submitted from sql plus)
9     L_FND_LOGIN_ID              CONSTANT NUMBER        := fnd_global.login_id;          --Bug#9660043
10 
11     L_FND_EXC_ERROR             EXCEPTION;                                              --Bug#9660043
12     L_FND_EXC_UNEXPECTED_ERROR  EXCEPTION;                                              --Bug#9660043
13 
14     L_FND_RET_STS_SUCCESS       CONSTANT VARCHAR2(1)   := fnd_api.g_ret_sts_success;    --Bug#9660043
15     L_FND_RET_STS_ERROR         CONSTANT VARCHAR2(1)   := fnd_api.g_ret_sts_error;      --Bug#9660043
16     L_FND_RET_STS_UNEXP_ERROR   CONSTANT VARCHAR2(1)   := fnd_api.g_ret_sts_unexp_error;--Bug#9660043
17 
18     CURSOR c_ship_hdr_int
19     IS
20         SELECT
21             ship_header_int_id       ,
22             group_id                 ,
23             transaction_type         ,
24             interface_source_code    ,
25             interface_source_table   ,
26             interface_source_line_id ,
27             validation_flag          ,
28             ship_num                 ,
29             ship_date                ,
30             ship_type_id             ,
31             ship_type_code           ,
32 -- Bug#13582437 problem in 12.2
33             NULL legal_entity_id     ,
34 --            legal_entity_name      ,
35             organization_id          ,
36             organization_code        ,
37             location_id              ,
38             location_code            ,
39 -- Bug#13056434 problem in 12.2
40 --            org_id                 ,
41             NULL org_id              ,
42 -- Bug#13056434 problem in 12.2
43             taxation_country         ,
44             document_sub_type        ,
45             ship_header_id           ,
46             last_task_code           ,
47             DECODE(h.transaction_type,'CREATE', NVL(h.rcv_enabled_flag,'Y'), h.rcv_enabled_flag) rcv_enabled_flag, -- dependence
48             attribute_category       ,
49             attribute1               ,
50             attribute2               ,
51             attribute3               ,
52             attribute4               ,
53             attribute5               ,
54             attribute6               ,
55             attribute7               ,
56             attribute8               ,
57             attribute9               ,
58             attribute10              ,
59             attribute11              ,
60             attribute12              ,
61             attribute13              ,
62             attribute14              ,
63             attribute15              ,
64             NULL user_defined_ship_num_code, -- from inl_parameters (AUTOMATIC or MANUAL)
65             NULL manual_ship_num_type,       -- from inl_parameters (NUMERIC or ALPHA)
66             NULL LCM_FLOW,                   -- can be AAS=as a service PR= pre receiving
67             NULL dflt_country
68         FROM inl_ship_headers_int h
69         WHERE h.request_id = l_fnd_conc_request_id_int
70         ORDER BY h.organization_id -- Bug 16310024
71         ;
72 
73     TYPE ship_hdr_int_list_type
74         IS
75         TABLE OF c_ship_hdr_int%ROWTYPE INDEX BY BINARY_INTEGER;
76 
77     CURSOR c_ship_ln_int (pc_ship_header_int_id NUMBER)
78     IS
79         SELECT
80             ship_header_int_id         ,
81             ship_line_int_id           ,
82             group_id                   ,
83             processing_status_code     ,
84             validation_flag            ,
85             ship_line_group_reference  ,
86             party_id                   ,
87             party_number               ,
88             party_site_id              ,
89             party_site_number          ,
90             source_organization_id     ,
91             source_organization_code   ,
92             ship_line_num              ,
93             ship_line_type_id          ,
94             ship_line_type_code        ,
95             ship_line_src_type_code    ,
96             ship_line_source_id        ,
97             currency_code              ,
98             currency_conversion_type   ,
99             currency_conversion_date   ,
100             currency_conversion_rate   ,
101             inventory_item_id          ,
102             txn_qty                    ,
103             txn_uom_code               ,
104             txn_unit_price             ,
105             primary_qty                ,
106             primary_uom_code           ,
107             primary_unit_price         ,
108             secondary_qty              ,
109             secondary_uom_code         ,
110             secondary_unit_price       ,
111             landed_cost_flag           ,
112             allocation_enabled_flag    ,
113             trx_business_category      ,
114             intended_use               ,
115             product_fiscal_class       ,
116             product_category           ,
117             product_type               ,
118             user_def_fiscal_class      ,
119             tax_classification_code    ,
120             assessable_value           ,
121             ship_from_party_id         ,
122             ship_from_party_number     ,
123             ship_from_party_site_id    ,
124             ship_from_party_site_number,
125             ship_to_organization_id    ,
126             ship_to_organization_code  ,
127             ship_to_location_id        ,
128             ship_to_location_code      ,
129             bill_from_party_id         ,
130             bill_from_party_number     ,
131             bill_from_party_site_id    ,
132             bill_from_party_site_number,
133             bill_to_organization_id    ,
134             bill_to_organization_code  ,
135             bill_to_location_id        ,
136             bill_to_location_code      ,
137             poa_party_id               ,
138             poa_party_number           ,
139             poa_party_site_id          ,
140             poa_party_site_number      ,
141             poo_organization_id        ,
142             poo_to_organization_code   ,
143             poo_location_id            ,
144             poo_location_code          ,
145 -- Bug#13056434 problem in 12.2
146 --            org_id                   ,
147             NULL org_id                ,
148 -- Bug#13056434 problem in 12.2
149             ship_header_id             ,
150             ship_line_id               ,
151             interface_source_table     ,
152             interface_source_line_id   ,
153             created_by                 ,
154             creation_date              ,
155             last_updated_by            ,
156             last_update_date           ,
157             last_update_login          ,
158             request_id                 ,
159             program_id                 ,
160             program_application_id     ,
161             program_update_date        ,
162             attribute_category_lg      ,
163             attribute1_lg              ,
164             attribute2_lg              ,
165             attribute3_lg              ,
166             attribute4_lg              ,
167             attribute5_lg              ,
168             attribute6_lg              ,
169             attribute7_lg              ,
170             attribute8_lg              ,
171             attribute9_lg              ,
172             attribute10_lg             ,
173             attribute11_lg             ,
174             attribute12_lg             ,
175             attribute13_lg             ,
176             attribute14_lg             ,
177             attribute15_lg             ,
178             attribute_category_sl      ,
179             attribute1_sl              ,
180             attribute2_sl              ,
181             attribute3_sl              ,
182             attribute4_sl              ,
183             attribute5_sl              ,
184             attribute6_sl              ,
185             attribute7_sl              ,
186             attribute8_sl              ,
187             attribute9_sl              ,
188             attribute10_sl             ,
189             attribute11_sl             ,
190             attribute12_sl             ,
191             attribute13_sl             ,
192             attribute14_sl             ,
193             attribute15_sl             ,
194             ship_line_group_num        ,
195             inventory_item_name        ,
196             ship_line_group_id
197         FROM inl_ship_lines_int
198         WHERE ship_header_int_id = pc_ship_header_int_id
199         ORDER BY
200             ship_line_group_reference,
201             ship_line_src_type_code,
202             ship_header_id,
203             party_id,
204             party_site_id,
205             source_organization_id,
206             ship_line_int_id
207     ;
208     TYPE ship_ln_int_list_type IS TABLE OF c_ship_ln_int%ROWTYPE INDEX BY BINARY_INTEGER;
209 
210     TYPE current_SLnGr_rec_type IS RECORD (
211         ship_line_group_id        NUMBER,
212         ship_line_group_num       NUMBER,
213         ship_line_group_reference VARCHAR2(30),
214         ship_header_id            NUMBER,
215         src_type_code             VARCHAR2(30),
216         party_id                  NUMBER,
217         party_site_id             NUMBER,
218         source_organization_id    NUMBER
219     );
220 
221     current_SLnGr_rec current_SLnGr_rec_type;
222 
223 
224     -- Utility name : Handle_InterfError
225     -- Type         : Private
226     -- Function     : Handle LCM open interface errors
227     -- Pre-reqs     : None
228     -- Parameters   :
229     -- IN         : p_parent_table_name  IN  VARCHAR2, Identify the point of the error: table_name and
230     --              p_parent_table_id    IN  NUMBER,                                    table_ID
231     --              p_column_name        IN VARCHAR2   Conditionally Error column name
232     --              p_column_value       IN VARCHAR2   Conditionally Error column value
233     --              p_error_message_name IN VARCHAR2   Optional Message name(if exists)
234     --              p_token1_name        IN VARCHAR2   Optional Message tokens names and values from 1 to 6
235     --              p_token1_value       IN VARCHAR2   Optional
236     --              p_token2_name        IN VARCHAR2   Optional
237     --              p_token2_value       IN VARCHAR2   Optional
238     --              p_token3_name        IN VARCHAR2   Optional
239     --              p_token3_value       IN VARCHAR2   Optional
240     --              p_token4_name        IN VARCHAR2   Optional
241     --              p_token4_value       IN VARCHAR2   Optional
242     --              p_token5_name        IN VARCHAR2   Optional
243     --              p_token5_value       IN VARCHAR2   Optional
244     --              p_token6_name        IN VARCHAR2   Optional
245     --              p_token6_value       IN VARCHAR2   Optional
246     --
247     -- OUT          x_return_status      OUT NOCOPY VARCHAR2
248     --
249     -- Version    : Current version 1.0
250     --
251     -- Notes      :
252 PROCEDURE Handle_InterfError
253     (
254         p_parent_table_name  IN VARCHAR2,
255         p_parent_table_id    IN NUMBER,
256         p_column_name        IN VARCHAR2,
257         p_column_value       IN VARCHAR2,
258         p_error_message_name IN VARCHAR2,
259         p_token1_name        IN VARCHAR2 DEFAULT NULL,
260         p_token1_value       IN VARCHAR2 DEFAULT NULL,
261         p_token2_name        IN VARCHAR2 DEFAULT NULL,
262         p_token2_value       IN VARCHAR2 DEFAULT NULL,
263         p_token3_name        IN VARCHAR2 DEFAULT NULL,
264         p_token3_value       IN VARCHAR2 DEFAULT NULL,
265         p_token4_name        IN VARCHAR2 DEFAULT NULL,
266         p_token4_value       IN VARCHAR2 DEFAULT NULL,
267         p_token5_name        IN VARCHAR2 DEFAULT NULL,
268         p_token5_value       IN VARCHAR2 DEFAULT NULL,
269         p_token6_name        IN VARCHAR2 DEFAULT NULL,
270         p_token6_value       IN VARCHAR2 DEFAULT NULL,
271         x_return_status      OUT NOCOPY VARCHAR2
272     ) IS
273     l_program_name          CONSTANT VARCHAR2(30) := 'Handle_InterfError';
274     l_return_status      VARCHAR2(1) ;
275     l_debug_info         VARCHAR2(2000) ;
276     l_ship_header_int_id NUMBER;
277     l_error_message      VARCHAR2(2000) ;
278 BEGIN
279     -- Standard Beginning of Procedure/Function Logging
280     INL_LOGGING_PVT.Log_BeginProc(
281         p_module_name    => g_module_name,
282         p_procedure_name => l_program_name) ;
283     --  Initialize API return status to success
284     x_return_status := L_FND_RET_STS_SUCCESS;
285     -- Creation of Messages
286     IF p_error_message_name IS NOT NULL THEN
287         FND_MESSAGE.SET_NAME('INL', p_error_message_name) ;
288         IF p_token1_name IS NOT NULL THEN
289             FND_MESSAGE.SET_TOKEN(p_token1_name, p_token1_value) ;
290             IF p_token2_name IS NOT NULL THEN
291                 FND_MESSAGE.SET_TOKEN(p_token2_name, p_token2_value) ;
292                 IF p_token3_name IS NOT NULL THEN
293                     FND_MESSAGE.SET_TOKEN(p_token3_name, p_token3_value) ;
294                     IF p_token4_name IS NOT NULL THEN
295                         FND_MESSAGE.SET_TOKEN(p_token4_name, p_token4_value) ;
296                         IF p_token5_name IS NOT NULL THEN
297                             FND_MESSAGE.SET_TOKEN(p_token5_name, p_token5_value) ;
298                             IF p_token6_name IS NOT NULL THEN
299                                 FND_MESSAGE.SET_TOKEN(p_token6_name, p_token6_value) ;
300                             END IF;
301                         END IF;
302                     END IF;
303                 END IF;
304             END IF;
305         END IF;
306         FND_MSG_PUB.ADD;
307         l_error_message := SUBSTR(FND_MSG_PUB.get(FND_MSG_PUB.Count_Msg(), L_FND_FALSE), 1, 2000) ;
308     END IF;
309     l_debug_info := 'Error Mesage: '||l_error_message;
310     INL_LOGGING_PVT.Log_Statement(
311         p_module_name      => g_module_name,
312         p_procedure_name   => l_program_name,
313         p_debug_info       => l_debug_info ) ;
314 
315     -- In case of error during Shipment Line import process
316     IF p_parent_table_name = 'INL_SHIP_LINES_INT' THEN
317         l_debug_info := 'Set Shipment Line Interface status to ERROR.';
318         INL_LOGGING_PVT.LOG_STATEMENT(
319            P_MODULE_NAME      => G_MODULE_NAME,
320            P_PROCEDURE_NAME   => l_program_name,
321            P_DEBUG_INFO       => L_DEBUG_INFO) ;
322 
323         UPDATE inl_ship_lines_int
324         SET processing_status_code      = 'ERROR'              ,
325             request_id                  = L_FND_CONC_REQUEST_ID,
326             last_updated_by             = L_FND_USER_ID        ,
327             last_update_date            = SYSDATE              ,
328             last_update_login           = L_FND_LOGIN_ID       ,
329             program_id                  = L_FND_CONC_PROGRAM_ID,
330             program_update_date         = SYSDATE              ,
331             program_application_id      = L_FND_PROG_APPL_ID
332           WHERE ship_line_int_id        = p_parent_table_id
333             AND processing_status_code <> 'ERROR';
334 
335          SELECT ship_header_int_id
336            INTO l_ship_header_int_id
337            FROM inl_ship_lines_int
338           WHERE ship_line_int_id = p_parent_table_id;
339 /* --Bug#11794442 made in procedure Run_MatchPreProcessor
340     ELSIF p_parent_table_name = 'INL_MATCHES_INT' THEN
341         l_debug_info := 'Set Match Interface status to ERROR.';
342         INL_LOGGING_PVT.Log_Statement(
343             p_module_name      => g_module_name,
344             p_procedure_name   => l_program_name,
345             p_debug_info       => l_debug_info) ;
346 
347         UPDATE inl_matches_int
348         SET processing_status_code      = 'ERROR'              ,
349             request_id                  = L_FND_CONC_REQUEST_ID,
350             last_updated_by             = L_FND_USER_ID        ,
351             last_update_date            = SYSDATE              ,
352             last_update_login           = L_FND_LOGIN_ID       ,
353             program_id                  = L_FND_CONC_PROGRAM_ID,
354             program_update_date         = SYSDATE              ,
355             program_application_id      = L_FND_PROG_APPL_ID
356           WHERE match_int_id            = p_parent_table_id
357           AND processing_status_code <> 'ERROR';
358 */
359     END IF;
360     IF p_parent_table_name = 'INL_SHIP_HEADERS_INT'
361        OR l_ship_header_int_id IS NOT NULL
362     THEN
363         l_debug_info := 'Set Shipment Header Interface status to ERROR.';
364         INL_LOGGING_PVT.Log_Statement(
365             p_module_name      => g_module_name,
366             p_procedure_name   => l_program_name,
367             p_debug_info       => l_debug_info) ;
368 
369         UPDATE inl_ship_headers_int
370         SET processing_status_code      = 'ERROR'              ,
371             request_id                  = L_FND_CONC_REQUEST_ID,
372             last_updated_by             = L_FND_USER_ID        ,
373             last_update_date            = SYSDATE              ,
374             last_update_login           = L_FND_LOGIN_ID       ,
375             program_id                  = L_FND_CONC_PROGRAM_ID,
376             program_update_date         = SYSDATE              ,
377             program_application_id      = L_FND_PROG_APPL_ID
378           WHERE ship_header_int_id      = NVL(l_ship_header_int_id, p_parent_table_id)
379             AND processing_status_code <> 'ERROR';
380     END IF;
381     l_debug_info := 'Insert detailed error message into Interface Error table.';
382     INL_LOGGING_PVT.Log_Statement(
383         p_module_name      => g_module_name,
384         p_procedure_name   => l_program_name,
385         p_debug_info       => l_debug_info) ;
386 
387     INSERT INTO inl_interface_errors (
388             interface_error_id,            /*01*/
389             parent_table_name,             /*02*/
390             parent_table_id,               /*03*/
391             column_name,                   /*04*/
392             column_value,                  /*05*/
393             processing_date,               /*06*/
394             error_message_name,            /*07*/
395             error_message,                 /*08*/
396             token1_name,                   /*09*/
397             token1_value,                  /*10*/
398             token2_name,                   /*11*/
399             token2_value,                  /*12*/
400             token3_name,                   /*13*/
401             token3_value,                  /*14*/
402             token4_name,                   /*15*/
403             token4_value,                  /*16*/
404             token5_name,                   /*17*/
405             token5_value,                  /*18*/
406             token6_name,                   /*19*/
407             token6_value,                  /*20*/
408             created_by,                    /*21*/
409             creation_date,                 /*22*/
410             last_updated_by,               /*23*/
411             last_update_date,              /*24*/
412             last_update_login,             /*25*/
413             program_id,                    /*26*/
414             program_application_id,        /*27*/
415             program_update_date,           /*28*/
416             request_id                     /*29*/
417         )
418         VALUES (
419             inl_interface_errors_s.NEXTVAL,/*01*/
420             p_parent_table_name,           /*02*/
421             p_parent_table_id,             /*03*/
422             p_column_name,                 /*04*/
423             p_column_value,                /*05*/
424             SYSDATE,                       /*06*/
425             p_error_message_name,          /*07*/
426             l_error_message,               /*08*/
427             p_token1_name,                 /*09*/
428             SUBSTR(p_token1_value,0,200),  /*10*/
429             p_token2_name,                 /*11*/
430             p_token2_value,                /*12*/
431             p_token3_name,                 /*13*/
432             p_token3_value,                /*14*/
433             p_token4_name,                 /*15*/
434             p_token4_value,                /*16*/
435             p_token5_name,                 /*17*/
436             p_token5_value,                /*18*/
437             p_token6_name,                 /*19*/
438             p_token6_value,                /*20*/
439             L_FND_USER_ID,                 /*21*/
440             SYSDATE,                       /*22*/
441             L_FND_USER_ID,                 /*23*/
442             SYSDATE,                       /*24*/
443             L_FND_USER_ID,                 /*25*/
444             L_FND_CONC_PROGRAM_ID,         /*26*/
445             L_FND_PROG_APPL_ID,            /*27*/
446             SYSDATE,                       /*28*/
447             L_FND_CONC_REQUEST_ID          /*29*/
448     );
449     -- Standard End of Procedure/Function Logging
450     INL_LOGGING_PVT.Log_EndProc(
451         p_module_name    => g_module_name,
452         p_procedure_name => l_program_name);
453 
454 EXCEPTION
455     WHEN L_FND_EXC_ERROR THEN
456         -- Standard Expected Error Logging
457         INL_LOGGING_PVT.Log_ExpecError (
458             p_module_name    => g_module_name,
459             p_procedure_name => l_program_name);
460         x_return_status := L_FND_RET_STS_ERROR;
461     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
462         -- Standard Unexpected Error Logging
463         INL_LOGGING_PVT.Log_UnexpecError (
464             p_module_name    => g_module_name,
465             p_procedure_name => l_program_name);
466         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
467     WHEN OTHERS THEN
468         -- Standard Unexpected Error Logging
469         INL_LOGGING_PVT.Log_UnexpecError (
470             p_module_name    => g_module_name,
471             p_procedure_name => l_program_name);
472         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
473         IF FND_MSG_PUB.Check_Msg_Level(
474             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
475         ) THEN
476             FND_MSG_PUB.Add_Exc_Msg(
477                 p_pkg_name       => g_pkg_name,
478                 p_procedure_name => l_program_name);
479         END IF;
480 END Handle_InterfError;
481 
482 -- Utility name : Reset_InterfError
483 -- Type       : Private
484 -- Function   : Delete errors recorded by previous validations
485 -- Pre-reqs   : None
486 -- Parameters :
487 -- IN         : p_parent_table_name IN VARCHAR2
488 --              p_parent_table_id   IN NUMBER
489 --
490 -- OUT          x_return_status     OUT NOCOPY VARCHAR2
491 --
492 -- Version    : Current version 1.0
493 --
494 -- Notes      :
495 PROCEDURE Reset_InterfError(
496         p_parent_table_name IN VARCHAR2,
497         p_parent_table_id   IN NUMBER,
498         x_return_status OUT NOCOPY VARCHAR2
499 ) IS
500     l_program_name CONSTANT VARCHAR2(30):= 'Reset_InterfError';
501     l_return_status VARCHAR2(1);
502     l_debug_info VARCHAR2(200);
503 BEGIN
504     -- Standard Beginning of Procedure/Function Logging
505     INL_LOGGING_PVT.Log_BeginProc(
506         p_module_name    => g_module_name,
507         p_procedure_name => l_program_name
508     ) ;
509     --  Initialize API return status to success
510     x_return_status := L_FND_RET_STS_SUCCESS;
511     l_debug_info    := 'Delete Errors from previous validation.';
512     INL_LOGGING_PVT.Log_Statement(
513         p_module_name      => g_module_name,
514         p_procedure_name   => l_program_name,
515         p_debug_info       => l_debug_info
516     ) ;
517      DELETE
518        FROM inl_interface_errors
519       WHERE parent_table_name = p_parent_table_name
520         AND parent_table_id   = p_parent_table_id;
521     -- Standard End of Procedure/Function Logging
522     INL_LOGGING_PVT.Log_EndProc(
523         p_module_name    => g_module_name,
524         p_procedure_name => l_program_name);
525 EXCEPTION
526     WHEN L_FND_EXC_ERROR THEN
527         -- Standard Expected Error Logging
528         INL_LOGGING_PVT.Log_ExpecError (
529             p_module_name    => g_module_name,
530             p_procedure_name => l_program_name);
531         x_return_status := L_FND_RET_STS_ERROR;
532     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
533         -- Standard Unexpected Error Logging
534         INL_LOGGING_PVT.Log_UnexpecError (
535             p_module_name    => g_module_name,
536             p_procedure_name => l_program_name);
537         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
538     WHEN OTHERS THEN
539         -- Standard Unexpected Error Logging
540         INL_LOGGING_PVT.Log_UnexpecError (
541             p_module_name    => g_module_name,
542             p_procedure_name => l_program_name);
543         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
544         IF FND_MSG_PUB.Check_Msg_Level(
545             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
546         ) THEN
547             FND_MSG_PUB.Add_Exc_Msg(
548                 p_pkg_name       => g_pkg_name,
549                 p_procedure_name => l_program_name);
550         END IF;
551 END Reset_InterfError;
552 
553 -- Utility name : Derive_PartyID
554 -- Type       : Private
555 -- Function   : Get Party Id based on a given Party Number
556 -- Pre-reqs   : None
557 -- Parameters :
558 -- IN         : p_party_number  IN VARCHAR2
559 --
560 -- OUT          x_return_status OUT NOCOPY VARCHAR2
561 --
562 -- Version    : Current version 1.0
563 --
564 -- Notes      :
565 FUNCTION Derive_PartyID(
566         p_party_number  IN VARCHAR2,
567         x_return_status IN OUT NOCOPY VARCHAR2
568 ) RETURN NUMBER IS
569     l_program_name     CONSTANT VARCHAR2(30) := 'Derive_PartyID';
570     l_return_status VARCHAR2(1) ;
571     l_debug_info    VARCHAR2(200) ;
572     l_return_value  NUMBER;
573 BEGIN
574     -- Standard Beginning of Procedure/Function Logging
575     INL_LOGGING_PVT.Log_BeginProc(
576         p_module_name    => g_module_name,
577         p_procedure_name => l_program_name
578     ) ;
579     --  Initialize API return status to success
580     x_return_status := L_FND_RET_STS_SUCCESS;
581     l_debug_info    := 'Getting party_id.';
582     INL_LOGGING_PVT.Log_Statement(
583         p_module_name      => g_module_name,
584         p_procedure_name   => l_program_name,
585         p_debug_info       => l_debug_info
586     ) ;
587      SELECT party_id
588        INTO l_return_value
589        FROM hz_parties
590       WHERE PARTY_NUMBER = p_party_number;
591     -- Standard End of Procedure/Function Logging
592     INL_LOGGING_PVT.Log_EndProc(
593         p_module_name    => g_module_name,
594         p_procedure_name => l_program_name
595     );
596     RETURN l_return_value;
597 EXCEPTION
598     WHEN L_FND_EXC_ERROR THEN
599         -- Standard Expected Error Logging
600         INL_LOGGING_PVT.Log_ExpecError (
601             p_module_name    => g_module_name,
602             p_procedure_name => l_program_name
603         );
604         x_return_status := L_FND_RET_STS_ERROR;
605         RETURN 0;
606     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
607         -- Standard Unexpected Error Logging
608         INL_LOGGING_PVT.Log_UnexpecError (
609             p_module_name    => g_module_name,
610             p_procedure_name => l_program_name
611         );
612         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
613         RETURN 0;
614     WHEN OTHERS THEN
615         -- Standard Unexpected Error Logging
616         INL_LOGGING_PVT.Log_UnexpecError (
617             p_module_name    => g_module_name,
618             p_procedure_name => l_program_name
619         );
620         IF FND_MSG_PUB.Check_Msg_Level(
621             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
622         ) THEN
623             FND_MSG_PUB.Add_Exc_Msg(
624                 p_pkg_name       => g_pkg_name,
625                 p_procedure_name => l_program_name
626             );
627         END IF;
628         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
629         RETURN 0;
630 END Derive_PartyID;
631 
632 -- Utility name : Derive_PartySiteID
633 -- Type       : Private
634 -- Function   : Get Party Site Id based on a given Party Site Number
635 -- Pre-reqs   : None
636 -- Parameters :
637 -- IN         : p_party_site_number IN VARCHAR2
638 --
639 -- OUT          x_return_status     OUT NOCOPY VARCHAR2
640 --
641 -- Version    : Current version 1.0
642 --
643 -- Notes      :
644 FUNCTION Derive_PartySiteID(
645     p_party_site_number IN         VARCHAR2,
646     x_return_status     OUT NOCOPY VARCHAR2
647 ) RETURN NUMBER IS
648     l_program_name     CONSTANT VARCHAR2(30) := 'Derive_PartySiteID';
649     l_return_status VARCHAR2(1);
650     l_debug_info    VARCHAR2(200);
651     l_return_value  NUMBER;
652 BEGIN
653     -- Standard Beginning of Procedure/Function Logging
654     INL_LOGGING_PVT.Log_BeginProc(
655         p_module_name    => g_module_name,
656         p_procedure_name => l_program_name
657     ) ;
658     --  Initialize API return status to success
659     x_return_status := L_FND_RET_STS_SUCCESS;
660     l_debug_info := 'Getting PartySite_id.';
661     INL_LOGGING_PVT.Log_Statement(
662         p_module_name      => g_module_name,
663         p_procedure_name   => l_program_name,
664         p_debug_info       => l_debug_info
665     ) ;
666      SELECT party_site_id
667        INTO l_return_value
668        FROM hz_party_sites
669       WHERE party_site_number = p_party_site_number;
670     -- Standard End of Procedure/Function Logging
671     INL_LOGGING_PVT.Log_EndProc(
672         p_module_name    => g_module_name,
673         p_procedure_name => l_program_name
674     );
675     RETURN l_return_value;
676 EXCEPTION
677     WHEN L_FND_EXC_ERROR THEN
678         -- Standard Expected Error Logging
679         INL_LOGGING_PVT.Log_ExpecError (
680             p_module_name    => g_module_name,
681             p_procedure_name => l_program_name
682         );
683         x_return_status := L_FND_RET_STS_ERROR;
684         RETURN 0;
685     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
686         -- Standard Unexpected Error Logging
687         INL_LOGGING_PVT.Log_UnexpecError (
688             p_module_name    => g_module_name,
689             p_procedure_name => l_program_name
690         );
691         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
692         RETURN 0;
693     WHEN OTHERS THEN
694         -- Standard Unexpected Error Logging
695         INL_LOGGING_PVT.Log_UnexpecError (
696             p_module_name    => g_module_name,
697             p_procedure_name => l_program_name
698         );
699         IF FND_MSG_PUB.Check_Msg_Level(
700             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
701         ) THEN
702             FND_MSG_PUB.Add_Exc_Msg(
703                 p_pkg_name       => g_pkg_name,
704                 p_procedure_name => l_program_name
705             );
706         END IF;
707         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
708         RETURN 0;
709 END Derive_PartySiteID;
710 
711 -- Utility name   : Validate_ShipNum
712 -- Type       : Private
713 -- Function   : Shipment Number validation.
714 --              Check if the ship numbering is autiomatic and check the number informed
715 -- Pre-reqs   : None
716 -- Parameters :
717 -- IN         :     p_ship_header_int_id            IN NUMBER
718 --                  p_validation_flag               IN VARCHAR2
719 --                  p_organization_id               IN NUMBER
720 --                  p_transaction_type              IN VARCHAR2
721 --                  p_user_defined_ship_num_code    IN VARCHAR2,
722 --                  p_LCM_FLOW                      IN VARCHAR2,
723 --                  p_manual_ship_num_type          IN VARCHAR2,
724 --                  p_ship_num                      IN VARCHAR2,
725 --
726 -- OUT        :     x_return_status      OUT NOCOPY VARCHAR2
727 --
728 -- Version    : Current version 1.0
729 --
730 -- Notes      : ShipNum in create transactions, for LCM as a service, should be null  and automatic (Bug#9198199)
731 --                                                  in Pre receiving flow verify the LCM Option
732 --                                                      if it is manual => ship num should be informed and shouldn't exist in shipment header
733 --              ShipNum in Update transactions can be null if ship header id is informed (verified in validate_HdrUpdateTrxType)
734 
735 FUNCTION Validate_ShipNum(
736     p_ship_header_int_id            IN NUMBER,
737     p_organization_id               IN NUMBER,
738     p_validation_flag               IN VARCHAR2,
739     p_transaction_type              IN VARCHAR2,
740     p_user_defined_ship_num_code    IN VARCHAR2,
741     p_LCM_FLOW                      IN VARCHAR2,
742     p_manual_ship_num_type          IN VARCHAR2,
743     p_ship_num                      IN VARCHAR2,
744     x_return_status                OUT NOCOPY VARCHAR2
745 ) RETURN BOOLEAN IS
746     l_program_name              CONSTANT VARCHAR2(30) := 'Validate_ShipNum';
747     l_debug_info             VARCHAR2(400) ;
748     l_result                 VARCHAR2(1) := L_FND_TRUE;
749     l_return_status          VARCHAR2(1) := L_FND_TRUE;
750     l_count_ship_num_exist   NUMBER;
751     l_check_numeric          NUMBER;
752     l_valid_ship_num         NUMBER;
753 
754 BEGIN
755     -- Standard Beginning of Procedure/Function Logging
756     INL_LOGGING_PVT.Log_BeginProc(
757         p_module_name    => g_module_name,
758         p_procedure_name => l_program_name) ;
759     --  Initialize API return status to success
760     x_return_status := L_FND_RET_STS_SUCCESS;
761     INL_LOGGING_PVT.Log_Variable(
762         p_module_name    => g_module_name,
763         p_procedure_name => l_program_name,
764         p_var_name       => 'p_ship_header_int_id',
765         p_var_value      => p_ship_header_int_id) ;
766     INL_LOGGING_PVT.Log_Variable(
767         p_module_name    => g_module_name,
768         p_procedure_name => l_program_name,
769         p_var_name       => 'p_organization_id',
770         p_var_value      => p_organization_id) ;
771     INL_LOGGING_PVT.Log_Variable(
772         p_module_name    => g_module_name,
773         p_procedure_name => l_program_name,
774         p_var_name       => 'p_transaction_type',
775         p_var_value      => p_transaction_type) ;
776     INL_LOGGING_PVT.Log_Variable(
777         p_module_name    => g_module_name,
778         p_procedure_name => l_program_name,
779         p_var_name       => 'p_user_defined_ship_num_code',
780         p_var_value      => p_user_defined_ship_num_code) ;
781     INL_LOGGING_PVT.Log_Variable(
782         p_module_name    => g_module_name,
783         p_procedure_name => l_program_name,
784         p_var_name       => 'p_LCM_FLOW',
785         p_var_value      => p_LCM_FLOW) ;
786     INL_LOGGING_PVT.Log_Variable(
787         p_module_name    => g_module_name,
788         p_procedure_name => l_program_name,
789         p_var_name       => 'p_ship_num',
790         p_var_value      => p_ship_num) ;
791 
792     l_debug_info := 'Ship Number validation';
793     INL_LOGGING_PVT.Log_Statement(
794         p_module_name      => g_module_name,
795         p_procedure_name   => l_program_name,
796         p_debug_info       => l_debug_info);
797 
798 /* Verifyed at Validate_HdrUpdateTrxType
799 
800     IF x_ship_header_id IS NOT NULL THEN
801         x_ship_num := NULL;
802         l_debug_info := 'Ship Header Id IS NOT NULL, then Ship Num is set to be NULL';
803         INL_LOGGING_PVT.Log_Statement(
804             p_module_name      => g_module_name,
805             p_procedure_name   => l_program_name,
806             p_debug_info       => l_debug_info);
807     ELSIF x_ship_num IS NOT NULL AND p_transaction_type = 'UPDATE' THEN
808         BEGIN
809             SELECT sh.ship_header_id
810             INTO x_ship_header_id
811             FROM inl_ship_headers_all sh --Bug#10381495
812             WHERE sh.ship_num = x_ship_num
813             AND   sh.organization_id = p_organization_id;
814         EXCEPTION
815             WHEN OTHERS THEN
816                 l_debug_info := 'Ship Num: ' || x_ship_num || ' not found in inl_ship_headers';
817                 INL_LOGGING_PVT.Log_Statement(
818                     p_module_name      => g_module_name,
819                     p_procedure_name   => l_program_name,
820                     p_debug_info       => l_debug_info);
821                 l_result := L_FND_FALSE;
822                 -- Add a line into inl_ship_errors
823                 Handle_InterfError(
824                     p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
825                     p_parent_table_id    => p_ship_header_int_id,
826                     p_column_name        => 'SHIP_NUM',
827                     p_column_value       => x_ship_num,
828                     p_error_message_name => 'INL_ERR_NO_SHIP_NUM',
829                     p_token1_name        => 'SHIP_NUM',
830                     p_token1_value       => x_ship_num,
831                     p_token2_name        => 'ORGANIZATION_ID',
832                     p_token2_value       => p_organization_id,
833                     x_return_status      => l_return_status);
834                 -- If any errors happen abort API.
835                 IF l_return_status = L_FND_RET_STS_ERROR THEN
836                     RAISE L_FND_EXC_ERROR;
837                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
838                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
839                 END IF;
840         END;
841     END IF;
842 */
843     -- Bug #9198199- If LCM Shipment Numbering is MANUAL and is a LCM as a
844     -- Service Organization, refuse it
845     IF p_user_defined_ship_num_code = 'MANUAL'
846         AND  p_LCM_FLOW = 'AAS'
847     THEN
848         l_debug_info := 'the import Shipment through LCM interface is only allowed for AUTOMATIC Shipment Number Generation in LCM as a Service Flow.';
849         INL_LOGGING_PVT.Log_Statement(
850            p_module_name      => g_module_name,
851            p_procedure_name   => l_program_name,
852            p_debug_info       => l_debug_info);
853 
854         l_result := L_FND_FALSE;
855         -- Add a line into inl_ship_errors
856         Handle_InterfError(
857                 p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
858                 p_parent_table_id    => p_ship_header_int_id,
859                 p_column_name        => 'ORGANIZATION_ID',
860                 p_column_value       => p_organization_id,
861                 p_error_message_name => 'INL_ERR_IMPORT_SHIP_NUM_GEN',
862                 p_token1_name        => 'user_defined_ship_num_code',
863                 p_token1_value       => p_user_defined_ship_num_code,
864                 x_return_status      => l_return_status) ;
865 
866         -- If any errors happen abort API.
867         IF l_return_status = L_FND_RET_STS_ERROR THEN
868             RAISE L_FND_EXC_ERROR;
869         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
870            RAISE L_FND_EXC_UNEXPECTED_ERROR;
871         END IF;
872     END IF;
873     -- /Bug #9198199
874 
875     IF p_validation_flag = 'Y' THEN
876         l_debug_info := 'Validate Shipment Number according to transation type';
877         INL_LOGGING_PVT.Log_Statement(
878             p_module_name      => g_module_name,
879             p_procedure_name   => l_program_name,
880             p_debug_info       => l_debug_info);
881 
882         IF p_transaction_type = 'CREATE' THEN
883             IF p_user_defined_ship_num_code = 'MANUAL' AND p_LCM_FLOW = 'PR'
884             THEN
885                 IF p_ship_num IS NULL THEN
886                     l_debug_info := 'Ship Number cannot be null for a MANUAL defined organization';
887                     INL_LOGGING_PVT.Log_Statement(
888                         p_module_name      => g_module_name,
889                         p_procedure_name   => l_program_name,
890                         p_debug_info       => l_debug_info);
891 
892                     l_result := L_FND_FALSE;
893                     -- Add a line into inl_ship_errors
894                     Handle_InterfError(
895                         p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
896                         p_parent_table_id    => p_ship_header_int_id,
897                         p_column_name        => 'SHIP_NUM',
898                         p_column_value       => p_ship_num,
899                         p_error_message_name => 'INL_ERR_SHIP_NUM_NULL',
900                         x_return_status      => l_return_status);
901                     -- If any errors happen abort API.
902                     IF l_return_status = L_FND_RET_STS_ERROR THEN
903                         RAISE L_FND_EXC_ERROR;
904                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
905                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
906                     END IF;
907                 ELSIF p_ship_num IS NOT NULL
908                     AND p_organization_id IS NOT NULL
909                 THEN
910                     SELECT COUNT(1)
911                     INTO   l_count_ship_num_exist
912                     FROM   inl_ship_headers_all sh --Bug#10381495
913                     WHERE  sh.ship_num = p_ship_num
914                     AND    sh.organization_id = p_organization_id;
915 
916                     INL_LOGGING_PVT.Log_Variable(
917                         p_module_name    => g_module_name,
918                         p_procedure_name => l_program_name,
919                         p_var_name       => 'l_count_ship_num_exist',
920                         p_var_value      => l_count_ship_num_exist);
921 
922                     IF NVL(l_count_ship_num_exist,0) > 0 THEN
923                         l_debug_info := 'Ship Number exists for this Organization';
924                         INL_LOGGING_PVT.Log_Statement(
925                             p_module_name      => g_module_name,
926                             p_procedure_name   => l_program_name,
927                             p_debug_info       => l_debug_info);
928 
929                         l_result := L_FND_FALSE;
930                         -- Add a line into inl_ship_errors
931                         Handle_InterfError(
932                             p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
933                             p_parent_table_id    => p_ship_header_int_id,
934                             p_column_name        => 'SHIP_NUM',
935                             p_column_value       => p_ship_num,
936                             p_error_message_name => 'INL_ERR_SHIP_NUM',
937                             p_token1_name        => 'SHIP_NUM',
938                             p_token1_value       => p_ship_num,
939                             x_return_status      => l_return_status);
940 
941                         -- If any errors happen abort API.
942                         IF l_return_status = L_FND_RET_STS_ERROR THEN
943                             RAISE L_FND_EXC_ERROR;
944                         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
945                             RAISE L_FND_EXC_UNEXPECTED_ERROR;
946                         END IF;
947                     END IF;
948 
949                     IF p_manual_ship_num_type = 'NUMERIC' THEN
950                         BEGIN -- alternative approach
951                             l_check_numeric := p_ship_num - p_ship_num;
952                         EXCEPTION
953                             WHEN OTHERS THEN
954                                 l_check_numeric := null;
955                         END;
956 
957                         INL_LOGGING_PVT.Log_Variable(
958                             p_module_name    => g_module_name,
959                             p_procedure_name => l_program_name,
960                             p_var_name       => 'l_check_numeric',
961                             p_var_value      => l_check_numeric) ;
962 
963                         IF(l_check_numeric IS NULL OR l_check_numeric <> 0) THEN
964                             l_debug_info := 'Ship Number should be numeric';
965                             INL_LOGGING_PVT.Log_Statement(
966                                 p_module_name      => g_module_name,
967                                 p_procedure_name   => l_program_name,
968                                 p_debug_info       => l_debug_info);
969 
970                             l_result := L_FND_FALSE;
971                             -- Add a line into inl_ship_errors
972                             Handle_InterfError(
973                                 p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
974                                 p_parent_table_id    => p_ship_header_int_id,
975                                 p_column_name        => 'SHIP_NUM',
976                                 p_column_value       => p_ship_num,
977                                 p_error_message_name => 'INL_SHIPMENT_NUMERIC',
978                                 p_token1_name        => 'SHIP_NUM',
979                                 p_token1_value       => p_ship_num,
980                                 x_return_status      => l_return_status);
981 
982                             -- If any errors happen abort API.
983                             IF l_return_status = L_FND_RET_STS_ERROR THEN
984                                 RAISE L_FND_EXC_ERROR;
985                             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
986                                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
987                             END IF;
988                         END IF;
989                     END IF;
990                 END IF;
991             ELSIF p_user_defined_ship_num_code = 'AUTOMATIC' THEN
992                 IF p_ship_num IS NOT NULL THEN
993                     l_debug_info := 'For transaction type = CREATE, Ship_Num should be null';
994                     INL_LOGGING_PVT.Log_Statement(
995                         p_module_name      => g_module_name,
996                         p_procedure_name   => l_program_name,
997                         p_debug_info       => l_debug_info) ;
998                         l_result := L_FND_FALSE;
999                     -- Add a line into inl_ship_errors
1000                     Handle_InterfError(
1001                         p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
1002                         p_parent_table_id    => p_ship_header_int_id,
1003                         p_column_name        => 'USER_DEF_SHIP_NUM_CODE',
1004                         p_column_value       => 'AUTOMATIC',
1005                         p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
1006                         p_token1_name        => 'COLUMN',
1007                         p_token1_value       => 'SHIP_NUM',
1008                         p_token2_name        => 'ID_NAME',
1009                         p_token2_value       => 'INL_SHIP_HEADERS_INT',
1010                         p_token3_name        => 'ID_VAL',
1011                         p_token3_value       => p_ship_header_int_id,
1012                         x_return_status      => l_return_status);
1013                     -- If any errors happen abort API.
1014                     IF l_return_status = L_FND_RET_STS_ERROR THEN
1015                         RAISE L_FND_EXC_ERROR;
1016                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1017                        RAISE L_FND_EXC_UNEXPECTED_ERROR;
1018                     END IF;
1019                 END IF;
1020             END IF;
1021         END IF;
1022     END IF;
1023     -- Standard End of Procedure/Function Logging
1024     INL_LOGGING_PVT.Log_EndProc(
1025         p_module_name    => g_module_name,
1026         p_procedure_name => l_program_name);
1027     RETURN FND_API.to_boolean(l_result) ;
1028 
1029 EXCEPTION
1030     WHEN L_FND_EXC_ERROR THEN
1031         -- Standard Expected Error Logging
1032         INL_LOGGING_PVT.Log_ExpecError (
1033             p_module_name    => g_module_name,
1034             p_procedure_name => l_program_name);
1035         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1036     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
1037         -- Standard Unexpected Error Logging
1038         INL_LOGGING_PVT.Log_UnexpecError (
1039             p_module_name    => g_module_name,
1040             p_procedure_name => l_program_name);
1041         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1042     WHEN OTHERS THEN
1043         -- Standard Unexpected Error Logging
1044         INL_LOGGING_PVT.Log_UnexpecError (
1045             p_module_name    => g_module_name,
1046             p_procedure_name => l_program_name);
1047         IF FND_MSG_PUB.Check_Msg_Level(
1048             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
1049         ) THEN
1050             FND_MSG_PUB.Add_Exc_Msg(
1051                 p_pkg_name       => g_pkg_name,
1052                 p_procedure_name => l_program_name);
1053         END IF;
1054         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1055 END Validate_ShipNum;
1056 
1057 -- Utility name   : Validate_ShipType
1058 -- Type       : Private
1059 -- Function   : Derive ship type columns and validate if required.
1060 --
1061 -- Pre-reqs   : None
1062 -- Parameters :
1063 -- IN         : p_ship_header_int_id IN NUMBER,
1064 --              p_validation_flag    IN VARCHAR2
1065 --
1066 -- OUT        : x_ship_type_id       IN OUT NOCOPY NUMBER
1067 --              x_ship_type_code     IN OUT NOCOPY VARCHAR2
1068 --              x_return_status      IN OUT NOCOPY VARCHAR2
1069 --
1070 -- Version    : Current version 1.0
1071 --
1072 -- Notes      :
1073 FUNCTION Validate_ShipType(
1074     p_ship_header_int_id IN NUMBER,
1075     p_validation_flag    IN VARCHAR2,
1076     x_ship_type_id       IN OUT NOCOPY NUMBER,
1077     x_ship_type_code     IN OUT NOCOPY VARCHAR2,
1078     x_return_status      OUT NOCOPY VARCHAR2
1079 ) RETURN BOOLEAN IS
1080     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_ShipType';
1081     l_debug_info    VARCHAR2(400) ;
1082     l_result        VARCHAR2(1) := L_FND_TRUE;
1083     l_return_status VARCHAR2(1) := L_FND_TRUE;
1084 
1085     l_ship_type_code   VARCHAR2(400);
1086     l_active_from_date DATE;
1087     l_active_to_date   DATE;
1088     l_column_name      VARCHAR2(15) := 'SHIP_TYPE_ID';
1089     l_column_value     VARCHAR2(15) := x_ship_type_id;
1090     l_count_alw_ln_types NUMBER;
1091     l_count_alw_src_types NUMBER;
1092 
1093 BEGIN
1094     -- Standard Beginning of Procedure/Function Logging
1095     INL_LOGGING_PVT.Log_BeginProc(
1096         p_module_name    => g_module_name,
1097         p_procedure_name => l_program_name) ;
1098     --  Initialize API return status to success
1099     x_return_status := L_FND_RET_STS_SUCCESS;
1100 
1101     l_debug_info := 'Derive and validate Shipment Type if required';
1102     INL_LOGGING_PVT.Log_Statement(
1103         p_module_name      => g_module_name,
1104         p_procedure_name   => l_program_name,
1105         p_debug_info       => l_debug_info) ;
1106 
1107     INL_LOGGING_PVT.Log_Variable(
1108         p_module_name    => g_module_name,
1109         p_procedure_name => l_program_name,
1110         p_var_name       => 'x_ship_type_id',
1111         p_var_value      => x_ship_type_id) ;
1112 
1113     INL_LOGGING_PVT.Log_Variable(
1114         p_module_name    => g_module_name,
1115         p_procedure_name => l_program_name,
1116         p_var_name       => 'x_ship_type_code',
1117         p_var_value      => x_ship_type_code) ;
1118 
1119     INL_LOGGING_PVT.Log_Variable(
1120         p_module_name    => g_module_name,
1121         p_procedure_name => l_program_name,
1122         p_var_name       => 'p_validation_flag',
1123         p_var_value      => p_validation_flag) ;
1124 
1125     IF p_validation_flag = 'N' THEN
1126         l_debug_info := 'Validation is not required for Ship Type';
1127         INL_LOGGING_PVT.Log_Statement(
1128             p_module_name      => g_module_name,
1129             p_procedure_name   => l_program_name,
1130             p_debug_info       => l_debug_info);
1131 
1132          IF x_ship_type_id IS NOT NULL
1133          THEN
1134             x_ship_type_code := NULL;
1135          ELSIF x_ship_type_code IS NOT NULL
1136          THEN
1137             l_column_name := 'SHIP_TYPE_CODE';
1138             l_column_value := x_ship_type_code;
1139 
1140             SELECT st.ship_type_id
1141             INTO   x_ship_type_id
1142             FROM   inl_ship_types_b st
1143             WHERE st.ship_type_code = x_ship_type_code;
1144          END IF;
1145     ELSIF p_validation_flag = 'Y' THEN
1146         l_column_name := 'SHIP_TYPE_ID';
1147         l_column_value := x_ship_type_id;
1148         SELECT
1149             st.ship_type_code,
1150             TRUNC(st.active_from_date),
1151             TRUNC(st.active_to_date),
1152             (   SELECT COUNT(1)
1153                 FROM inl_alwd_line_types alt
1154                 WHERE alt.parent_table_id = st.ship_type_id
1155                 AND   alt.parent_table_name = 'INL_SHIP_TYPES'
1156             ),
1157             (   SELECT COUNT(1)
1158                 FROM inl_alwd_source_types alst
1159                 WHERE alst.ship_type_id = st.ship_type_id
1160             )
1161         INTO
1162             x_ship_type_code,
1163             l_active_from_date,
1164             l_active_to_date,
1165             l_count_alw_ln_types,
1166             l_count_alw_src_types
1167         FROM   inl_ship_types_vl st
1168         WHERE (x_ship_type_id IS NOT NULL
1169                 AND st.ship_type_id = x_ship_type_id)
1170             OR st.ship_type_code = x_ship_type_code
1171         ;
1172         -- Validate Ship Type
1173         IF NOT SYSDATE BETWEEN NVL((TRUNC(l_active_from_date)),SYSDATE)
1174         AND NVL((TRUNC(l_active_to_date)+.99999)-1,SYSDATE) THEN
1175             l_debug_info := 'Date is closed for the Ship Type';
1176             INL_LOGGING_PVT.Log_Statement(
1177                 p_module_name      => g_module_name,
1178                 p_procedure_name   => l_program_name,
1179                 p_debug_info       => l_debug_info) ;
1180 
1181             l_result := L_FND_FALSE;
1182 
1183             -- Add a line into inl_ship_errors
1184             Handle_InterfError(
1185                 p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
1186                 p_parent_table_id    => p_ship_header_int_id,
1187                 p_column_name        => 'SHIP_TYPE_ID',
1188                 p_column_value       => x_ship_type_id,
1189                 p_error_message_name => 'INL_ERR_SHIP_TYPE_CLOSED',
1190                 x_return_status      => l_return_status);
1191             -- If any errors happen abort API.
1192             IF l_return_status = L_FND_RET_STS_ERROR THEN
1193                 RAISE L_FND_EXC_ERROR;
1194             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1195                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
1196             END IF;
1197         END IF;
1198 
1199         IF NVL(l_count_alw_ln_types,0) = 0 THEN
1200             l_debug_info := 'No Ship Line Type allowed for the Shipment Type: ' || x_ship_type_code;
1201             INL_LOGGING_PVT.Log_Statement(
1202                  p_module_name      => g_module_name,
1203                  p_procedure_name   => l_program_name,
1204                  p_debug_info       => l_debug_info) ;
1205 
1206             l_result := L_FND_FALSE;
1207 
1208             -- Add a line into inl_ship_errors
1209             Handle_InterfError(
1210                 p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
1211                 p_parent_table_id    => p_ship_header_int_id,
1212                 p_column_name        => 'SHIP_TYPE_ID',
1213                 p_column_value       => x_ship_type_id,
1214                 p_error_message_name => 'INL_ERR_NO_SHIP_LN_TYPE',
1215                 x_return_status      => l_return_status);
1216             -- If any errors happen abort API.
1217             IF l_return_status = L_FND_RET_STS_ERROR THEN
1218                 RAISE L_FND_EXC_ERROR;
1219             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1220                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
1221             END IF;
1222         END IF;
1223 
1224         IF NVL(l_count_alw_src_types,0) = 0 THEN
1225             l_debug_info := 'No Ship Line Type allowed for the Shipment Type: ' || x_ship_type_code;
1226             INL_LOGGING_PVT.Log_Statement(
1227                 p_module_name      => g_module_name,
1228                 p_procedure_name   => l_program_name,
1229                 p_debug_info       => l_debug_info) ;
1230 
1231             l_result := L_FND_FALSE;
1232 
1233             -- Add a line into inl_ship_errors
1234             Handle_InterfError(
1235                 p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
1236                 p_parent_table_id    => p_ship_header_int_id,
1237                 p_column_name        => 'SHIP_TYPE_ID',
1238                 p_column_value       => x_ship_type_id,
1239                 p_error_message_name => 'INL_ERR_NO_SRC_TYPE',
1240                 x_return_status      => l_return_status);
1241             -- If any errors happen abort API.
1242             IF l_return_status = L_FND_RET_STS_ERROR THEN
1243                 RAISE L_FND_EXC_ERROR;
1244             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1245                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
1246             END IF;
1247         END IF;
1248     END IF;
1249     -- Standard End of Procedure/Function Logging
1250     INL_LOGGING_PVT.Log_EndProc(
1251         p_module_name    => g_module_name,
1252         p_procedure_name => l_program_name);
1253     RETURN FND_API.to_boolean(l_result) ;
1254 EXCEPTION
1255     WHEN L_FND_EXC_ERROR THEN
1256         -- Standard Expected Error Logging
1257         INL_LOGGING_PVT.Log_ExpecError (
1258             p_module_name    => g_module_name,
1259             p_procedure_name => l_program_name);
1260         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1261     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
1262         -- Standard Unexpected Error Logging
1263         INL_LOGGING_PVT.Log_UnexpecError (
1264             p_module_name    => g_module_name,
1265             p_procedure_name => l_program_name);
1266         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1267     WHEN OTHERS THEN
1268         -- Add a line into inl_ship_errors
1269         Handle_InterfError(
1270             p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
1271             p_parent_table_id    => p_ship_header_int_id,
1272             p_column_name        => l_column_name,
1273             p_column_value       => l_column_value,
1274             p_error_message_name => 'INL_ERR_SHIP_TP',
1275             x_return_status      => l_return_status);
1276 
1277         -- If any errors happen abort API.
1278         IF l_return_status = L_FND_RET_STS_ERROR THEN
1279             RAISE L_FND_EXC_ERROR;
1280         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1281             RAISE L_FND_EXC_UNEXPECTED_ERROR;
1282         END IF;
1283         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1284 END Validate_ShipType;
1285 
1286 -- Utility name   : Validate_Party
1287 -- Type       : Private
1288 -- Function   : Derive Party fields and validate if required
1289 --
1290 -- Pre-reqs   : None
1291 -- Parameters :
1292 -- IN         :     p_ship_header_int_id    IN NUMBER
1293 --                  p_ship_line_int_id      IN NUMBER
1294 --                  p_validation_flag       IN VARCHAR2,
1295 --                  p_src_organization_id   IN NUMBER
1296 --                  p_src_organization_code IN VARCHAR2
1297 --                  p_ship_type_id          IN NUMBER
1298 --
1299 -- OUT        :     x_party_id              IN OUT NOCOPY NUMBER
1300 --                  x_party_number          IN OUT NOCOPY VARCHAR2
1301 --                  x_return_status         OUT NOCOPY VARCHAR2
1302 --
1303 -- Version    : Current version 1.0
1304 --
1305 -- Notes      : Called only for transaction_type = CREATE
1306 FUNCTION Validate_Party(
1307     p_ship_line_int_id      IN NUMBER,
1308     p_validation_flag       IN VARCHAR2,
1309     p_ship_type_id          IN NUMBER,
1310     x_party_id              IN OUT NOCOPY NUMBER,
1311     x_party_number          IN OUT NOCOPY VARCHAR2,
1312     x_return_status         OUT NOCOPY VARCHAR2
1313 ) RETURN BOOLEAN IS
1314     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_Party';
1315     l_debug_info    VARCHAR2(400) ;
1316     l_response        VARCHAR2(1) := L_FND_TRUE;
1317     l_return_status VARCHAR2(1) := L_FND_TRUE;
1318 
1319     l_column_name      VARCHAR2(15) := 'PARTY_ID';
1320     l_column_value     VARCHAR2(15) := x_party_id;
1321     l_count_alw_party_type NUMBER;
1322     l_count_alw_party_usg  NUMBER;
1323 
1324 BEGIN
1325     -- Standard Beginning of Procedure/Function Logging
1326     INL_LOGGING_PVT.Log_BeginProc(
1327         p_module_name    => g_module_name,
1328         p_procedure_name => l_program_name) ;
1329     --  Initialize API return status to success
1330     x_return_status := L_FND_RET_STS_SUCCESS;
1331 
1332     INL_LOGGING_PVT.Log_Variable(
1333         p_module_name    => g_module_name,
1334         p_procedure_name => l_program_name,
1335         p_var_name       => 'p_ship_line_int_id',
1336         p_var_value      => p_ship_line_int_id);
1337 
1338     INL_LOGGING_PVT.Log_Variable(
1339         p_module_name    => g_module_name,
1340         p_procedure_name => l_program_name,
1341         p_var_name       => 'p_validation_flag',
1342         p_var_value      => p_validation_flag);
1343 
1344     INL_LOGGING_PVT.Log_Variable(
1345         p_module_name    => g_module_name,
1346         p_procedure_name => l_program_name,
1347         p_var_name       => 'p_ship_type_id',
1348         p_var_value      => p_ship_type_id);
1349 
1350 
1351     INL_LOGGING_PVT.Log_Variable(
1352         p_module_name    => g_module_name,
1353         p_procedure_name => l_program_name,
1354         p_var_name       => 'x_party_id',
1355         p_var_value      => x_party_id);
1356 
1357     INL_LOGGING_PVT.Log_Variable(
1358         p_module_name    => g_module_name,
1359         p_procedure_name => l_program_name,
1360         p_var_name       => 'x_party_number',
1361         p_var_value      => x_party_number);
1362 
1363     IF p_validation_flag = 'N' THEN
1364         IF x_party_id IS NOT NULL THEN
1365             x_party_number := NULL;
1366         ELSIF x_party_number IS NOT NULL THEN
1367             l_column_name := 'PARTY_NUMBER';
1368             l_column_value := x_party_NUMBER;
1369 
1370             SELECT party_id
1371             INTO x_party_id
1372             FROM hz_parties
1373             WHERE party_number = x_party_number;
1374         END IF;
1375 
1376     ELSIF p_validation_flag = 'Y' THEN
1377         IF x_party_id IS NOT NULL THEN
1378             l_column_name := 'PARTY_ID';
1379             l_column_value := x_party_id;
1380         ELSIF x_party_number IS NOT NULL THEN
1381             l_column_name := 'PARTY_NUMBER';
1382             l_column_value := x_party_number;
1383         END IF;
1384 
1385         SELECT
1386             party_id,
1387             party_number,
1388             (SELECT COUNT(1)
1389              FROM hz_party_usg_assignments ua
1390              WHERE ua.party_id = hp.party_id
1391              AND(UPPER(hp.party_type)
1392                 IN (SELECT
1393                         UPPER(cfopt.party_type_code)
1394                     FROM
1395                         inl_ship_types_vl cfot,
1396                         inl_alwd_party_types cfopt
1397                     WHERE
1398                         cfopt.parent_table_id = cfot.ship_type_id
1399                     AND cfopt.parent_table_name = 'INL_SHIP_TYPES'
1400                     AND cfot.ship_type_id = p_ship_type_id))
1401              AND hp.party_id = hp.party_id),
1402             (SELECT
1403                 COUNT(1)
1404              FROM
1405                 hz_party_usages_vl pu,
1406                 hz_party_usg_assignments ua,
1407                 hz_parties hp1
1408              WHERE
1409                   pu.party_usage_code = ua.party_usage_code
1410              AND  ua.party_id = hp1.party_id
1411              AND  UPPER(pu.party_usage_code)
1412                     IN
1413                         (SELECT UPPER(party_usage_code)
1414                          FROM
1415                             inl_ship_types_vl cfot,
1416                             inl_alwd_party_usages cfopt
1417                          WHERE cfopt.parent_table_id = cfot.ship_type_id
1418                          AND cfopt.parent_table_name = 'INL_SHIP_TYPES'
1419                          AND cfot.ship_type_id = p_ship_type_id)
1420              AND hp1.party_id = hp.party_id)
1421         INTO
1422             x_party_id,
1423             x_party_number,
1424             l_count_alw_party_type,
1425             l_count_alw_party_usg
1426         FROM hz_parties hp
1427         WHERE
1428             (x_party_id IS NOT NULL
1429              AND party_id = x_party_id)
1430              OR party_number = x_party_number;
1431 
1432         INL_LOGGING_PVT.Log_Variable(
1433             p_module_name    => g_module_name,
1434             p_procedure_name => l_program_name,
1435             p_var_name       => 'l_count_alw_party_type',
1436             p_var_value      => l_count_alw_party_type);
1437 
1438         INL_LOGGING_PVT.Log_Variable(
1439             p_module_name    => g_module_name,
1440             p_procedure_name => l_program_name,
1441             p_var_name       => 'l_count_alw_party_usg',
1442             p_var_value      => l_count_alw_party_usg);
1443 
1444         IF NVL(l_count_alw_party_type, 0) = 0 AND x_party_id IS NOT NULL THEN
1445             l_debug_info := 'Party is not compliant with Party Types defined for the Shipment Type';
1446             INL_LOGGING_PVT.Log_Statement(
1447                 p_module_name      => g_module_name,
1448                 p_procedure_name   => l_program_name,
1449                 p_debug_info       => l_debug_info);
1450             l_response := L_FND_FALSE;
1451             -- Add a line into inl_ship_errors
1452             Handle_InterfError(
1453                p_parent_table_name  => 'INL_SHIP_LINES_INT',
1454                p_parent_table_id    => p_ship_line_int_id,
1455                p_column_name        => 'PARTY_ID',
1456                p_column_value       => x_party_id,
1457                p_error_message_name => 'INL_ERR_PARTY_TYPE',
1458                x_return_status      => l_return_status);
1459              -- If any errors happen abort API.
1460              IF l_return_status = L_FND_RET_STS_ERROR THEN
1461                 RAISE L_FND_EXC_ERROR;
1462             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1463                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
1464              END IF;
1465         END IF;
1466         IF NVL(l_count_alw_party_usg,0) = 0 AND x_party_id IS NOT NULL THEN
1467             l_debug_info := 'Party is not compliant with Party Usage defined for the Shipment Type';
1468             INL_LOGGING_PVT.Log_Statement(
1469               p_module_name      => g_module_name,
1470               p_procedure_name   => l_program_name,
1471               p_debug_info       => l_debug_info);
1472             l_response := L_FND_FALSE;
1473             -- Add a line into inl_ship_errors
1474             Handle_InterfError(
1475                p_parent_table_name  => 'INL_SHIP_LINES_INT',
1476                p_parent_table_id    => p_ship_line_int_id,
1477                p_column_name        => 'PARTY_ID',
1478                p_column_value       => x_party_id,
1479                p_error_message_name => 'INL_ERR_PARTY_USAGE',
1480                x_return_status      => l_return_status);
1481              -- If any errors happen abort API.
1482             IF l_return_status = L_FND_RET_STS_ERROR THEN
1483                 RAISE L_FND_EXC_ERROR;
1484             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1485                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
1486             END IF;
1487         END IF;
1488     END IF;
1489     -- Standard End of Procedure/Function Logging
1490     INL_LOGGING_PVT.Log_EndProc(
1491         p_module_name    => g_module_name,
1492         p_procedure_name => l_program_name);
1493     RETURN FND_API.to_boolean(l_response) ;
1494 EXCEPTION
1495     WHEN L_FND_EXC_ERROR THEN
1496         -- Standard Expected Error Logging
1497         INL_LOGGING_PVT.Log_ExpecError (
1498             p_module_name    => g_module_name,
1499             p_procedure_name => l_program_name);
1500         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1501     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
1502         -- Standard Unexpected Error Logging
1503         INL_LOGGING_PVT.Log_UnexpecError (
1504             p_module_name    => g_module_name,
1505             p_procedure_name => l_program_name);
1506         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1507     WHEN OTHERS THEN
1508         -- Add a line into inl_ship_errors
1509         Handle_InterfError(
1510             p_parent_table_name  => 'INL_SHIP_LINES_INT',
1511             p_parent_table_id    => p_ship_line_int_id,
1512             p_column_name        => l_column_name,
1513             p_column_value       => l_column_value,
1514             p_error_message_name => 'INL_ERR_PARTY',
1515             x_return_status      => l_return_status);
1516 
1517         -- If any errors happen abort API.
1518         IF l_return_status = L_FND_RET_STS_ERROR THEN
1519             RAISE L_FND_EXC_ERROR;
1520         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1521             RAISE L_FND_EXC_UNEXPECTED_ERROR;
1522         END IF;
1523         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1524 END Validate_Party;
1525 
1526 -- Utility name   : Validate_PartySite
1527 -- Type       : Private
1528 -- Function   : Derive Party Site fields and validate if required
1529 --
1530 -- Pre-reqs   : None
1531 -- Parameters :
1532 -- IN         :     p_ship_line_int_id      IN NUMBER
1533 --                  p_validation_flag       IN VARCHAR2
1534 --                  p_party_id              IN NUMBER
1535 --                  p_dflt_country          IN VARCHAR2
1536 --                  p_ship_type_id          IN NUMBER
1537 --
1538 -- OUT        : x_party_site_id      IN OUT NOCOPY NUMBER
1539 --              x_party_site_number  IN OUT NOCOPY VARCHAR2
1540 --              x_return_status      OUT NOCOPY VARCHAR2
1541 --
1542 -- Version    : Current version 1.0
1543 --
1544 -- Notes      :
1545 FUNCTION Validate_PartySite(
1546     p_ship_line_int_id      IN NUMBER,
1547     p_validation_flag       IN VARCHAR2,
1548     p_party_id              IN NUMBER,
1549     p_dflt_country          IN VARCHAR2,
1550     p_ship_type_id          IN NUMBER,
1551     x_party_site_id         IN OUT NOCOPY NUMBER,
1552     x_party_site_number     IN OUT NOCOPY VARCHAR2,
1553     x_return_status         OUT NOCOPY VARCHAR2
1554 ) RETURN BOOLEAN IS
1555     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_PartySite';
1556     l_debug_info    VARCHAR2(400) ;
1557     l_response        VARCHAR2(1) := L_FND_TRUE;
1558     l_return_status VARCHAR2(1) := L_FND_TRUE;
1559 
1560     l_column_name         VARCHAR2(25) := 'PARTY_SITE_ID';
1561     l_column_value        VARCHAR2(20) := x_party_site_id;
1562     l_count_belongs_party NUMBER;
1563     l_count_alw_party     NUMBER;
1564 
1565 BEGIN
1566     -- Standard Beginning of Procedure/Function Logging
1567     INL_LOGGING_PVT.Log_BeginProc(
1568         p_module_name    => g_module_name,
1569         p_procedure_name => l_program_name) ;
1570     --  Initialize API return status to success
1571     x_return_status := L_FND_RET_STS_SUCCESS;
1572 
1573     INL_LOGGING_PVT.Log_Variable(
1574         p_module_name    => g_module_name,
1575         p_procedure_name => l_program_name,
1576         p_var_name       => 'p_party_id',
1577         p_var_value      => p_party_id);
1578 
1579     INL_LOGGING_PVT.Log_Variable(
1580         p_module_name    => g_module_name,
1581         p_procedure_name => l_program_name,
1582         p_var_name       => 'x_party_site_id',
1583         p_var_value      => x_party_site_id);
1584 
1585     INL_LOGGING_PVT.Log_Variable(
1586         p_module_name    => g_module_name,
1587         p_procedure_name => l_program_name,
1588         p_var_name       => 'x_party_site_number',
1589         p_var_value      => x_party_site_number);
1590 
1591     INL_LOGGING_PVT.Log_Variable(
1592         p_module_name    => g_module_name,
1593         p_procedure_name => l_program_name,
1594         p_var_name       => 'p_ship_line_int_id',
1595         p_var_value      => p_ship_line_int_id);
1596 
1597     INL_LOGGING_PVT.Log_Variable(
1598         p_module_name    => g_module_name,
1599         p_procedure_name => l_program_name,
1600         p_var_name       => 'p_validation_flag',
1601         p_var_value      => p_validation_flag);
1602 
1603     INL_LOGGING_PVT.Log_Variable(
1604         p_module_name    => g_module_name,
1605         p_procedure_name => l_program_name,
1606         p_var_name       => 'p_dflt_country',
1607         p_var_value      => p_dflt_country);
1608 
1609     INL_LOGGING_PVT.Log_Variable(
1610         p_module_name    => g_module_name,
1611         p_procedure_name => l_program_name,
1612         p_var_name       => 'p_ship_type_id',
1613         p_var_value      => p_ship_type_id);
1614 
1615     IF p_validation_flag = 'N' THEN
1616         l_debug_info := 'Validation is not required for Party Site';
1617         INL_LOGGING_PVT.Log_Statement(
1618             p_module_name      => g_module_name,
1619             p_procedure_name   => l_program_name,
1620             p_debug_info       => l_debug_info);
1621         IF x_party_site_id IS NOT NULL THEN
1622             x_party_site_number := NULL;
1623         ELSIF x_party_site_number IS NOT NULL THEN
1624             l_column_name  := 'PARTY_SITE_NUMBER';
1625             l_column_value := x_party_site_number;
1626 
1627             SELECT hps.party_site_id
1628             INTO x_party_site_id
1629             FROM hz_party_sites hps
1630             WHERE party_site_number = x_party_site_number;
1631         END IF;
1632     ELSE
1633 
1634         l_debug_info := 'Validation is required for Party Site';
1635         INL_LOGGING_PVT.Log_Statement(
1636             p_module_name      => g_module_name,
1637             p_procedure_name   => l_program_name,
1638             p_debug_info       => l_debug_info);
1639 
1640         IF x_party_site_id IS NOT NULL THEN
1641             l_column_name  := 'PARTY_SITE_NUMBER';
1642             l_column_value := x_party_site_number;
1643         ELSIF x_party_site_number IS NOT NULL THEN
1644             l_column_name  := 'PARTY_SITE_NUMBER';
1645             l_column_value := x_party_site_number;
1646         END IF;
1647 
1648         l_debug_info := 'Derive Party Site Id from Party Site Number';
1649         INL_LOGGING_PVT.Log_Statement(
1650             p_module_name      => g_module_name,
1651             p_procedure_name   => l_program_name,
1652             p_debug_info       => l_debug_info);
1653 
1654         SELECT hps.party_site_id,
1655                hps.party_site_number,
1656                (SELECT COUNT(1)
1657                 FROM hz_party_sites hps1
1658                 WHERE hps1.party_id = p_party_id
1659                 AND   hps1.party_site_id = hps.party_site_id),
1660                 (SELECT COUNT(1)
1661                  FROM   hz_party_sites   hps2,
1662                         hz_locations     hl,
1663                         fnd_territories_vl ftv,
1664                         inl_ship_types_vl shv
1665                  WHERE hps.location_id = hl.location_id
1666                  AND   ftv.territory_code = hl.country
1667                  AND   shv.ship_type_id = p_ship_type_id
1668                  AND   hps.party_id = p_party_id
1669                  AND  ((shv.trd_pties_alwd_code = 1 AND hl.country = p_dflt_country)
1670                  OR    (shv.trd_pties_alwd_code = 2 AND hl.country <> p_dflt_country)
1671                  OR    (shv.trd_pties_alwd_code = 3))
1672                  AND   hps.party_site_id = hps.party_site_id)
1673         INTO
1674             x_party_site_id,
1675             x_party_site_number,
1676             l_count_belongs_party,
1677             l_count_alw_party
1678         FROM hz_party_sites hps
1679         WHERE ( x_party_site_id IS NOT null
1680                 AND party_site_id = x_party_site_id)
1681             OR party_site_number = x_party_site_number;
1682 
1683         INL_LOGGING_PVT.Log_Variable(
1684             p_module_name    => g_module_name,
1685             p_procedure_name => l_program_name,
1686             p_var_name       => 'x_party_site_id',
1687             p_var_value      => x_party_site_id);
1688         INL_LOGGING_PVT.Log_Variable(
1689             p_module_name    => g_module_name,
1690             p_procedure_name => l_program_name,
1691             p_var_name       => 'x_party_site_number',
1692             p_var_value      => x_party_site_number);
1693 
1694         -- Party Site Validation
1695         IF p_party_id IS NULL AND
1696           (x_party_site_id IS NOT NULL OR x_party_site_number IS NOT NULL) THEN
1697             l_debug_info := 'Party is null, so party site should be null';
1698             INL_LOGGING_PVT.Log_Statement(
1699                 p_module_name      => g_module_name,
1700                 p_procedure_name   => l_program_name,
1701                 p_debug_info       => l_debug_info);
1702             l_response := L_FND_FALSE;
1703             -- Add a line into inl_ship_errors
1704             Handle_InterfError(
1705                 p_parent_table_name  => 'INL_SHIP_LINES_INT',
1706                 p_parent_table_id    => p_ship_line_int_id,
1707                 p_column_name        => 'PARTY_SITE_ID',
1708                 p_column_value       => x_party_site_id,
1709                 p_error_message_name => 'INL_ERR_3RD_PTY_ST_NNULL',
1710                 x_return_status      => l_return_status);
1711             -- If any errors happen abort API.
1712             IF l_return_status = L_FND_RET_STS_ERROR THEN
1713                 RAISE L_FND_EXC_ERROR;
1714             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1715                RAISE L_FND_EXC_UNEXPECTED_ERROR;
1716             END IF;
1717         END IF;
1718 
1719         IF NVL(l_count_belongs_party, 0) = 0
1720             AND x_party_site_id IS NOT NULL
1721         THEN
1722             l_debug_info := 'Party Site should belong to the Party';
1723             INL_LOGGING_PVT.Log_Statement(
1724                 p_module_name      => g_module_name,
1725                 p_procedure_name   => l_program_name,
1726                 p_debug_info       => l_debug_info);
1727             l_response := L_FND_FALSE;
1728             -- Add a line into inl_ship_errors
1729             Handle_InterfError(
1730                 p_parent_table_name  => 'INL_SHIP_LINES_INT',
1731                 p_parent_table_id    => p_ship_line_int_id,
1732                 p_column_name        => 'PARTY_SITE_ID',
1733                 p_column_value       => x_party_site_id,
1734                 p_error_message_name => 'INL_ERR_NO_3RD_PTY_ST_DEF_PTY',
1735                 x_return_status      => l_return_status);
1736             -- If any errors happen abort API.
1737             IF l_return_status = L_FND_RET_STS_ERROR THEN
1738                 RAISE L_FND_EXC_ERROR;
1739             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1740                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
1741              END IF;
1742         ELSIF NVL(l_count_alw_party, 0) = 0 AND x_party_site_id IS NOT NULL THEN
1743             l_debug_info := 'Party Site does not match with the Third Party Sites Allowed defined in Ship Type';
1744             INL_LOGGING_PVT.Log_Statement(
1745                 p_module_name      => g_module_name,
1746                 p_procedure_name   => l_program_name,
1747                 p_debug_info       => l_debug_info);
1748             l_response := L_FND_FALSE;
1749             -- Add a line into inl_ship_errors
1750             Handle_InterfError(
1751                 p_parent_table_name  => 'INL_SHIP_LINES_INT',
1752                 p_parent_table_id    => p_ship_line_int_id,
1753                 p_column_name        => 'PARTY_SITE_ID',
1754                 p_column_value       => x_party_site_id,
1755                 p_error_message_name => 'INL_ERR_3RD_PTY_ST_ALLOWED',
1756                 p_token1_name        => 'GROUP_REF',
1757                 p_token1_value       => NULL,
1758                 p_token2_name        => 'PARTY_SITE',
1759                 p_token2_value       => x_party_site_id,
1760                 p_token3_name        => 'SHIP_TYPE',
1761                 p_token3_value       => p_ship_type_id,
1762                 x_return_status      => l_return_status);
1763             -- If any errors happen abort API.
1764             IF l_return_status = L_FND_RET_STS_ERROR THEN
1765                 RAISE L_FND_EXC_ERROR;
1766             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1767                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
1768             END IF;
1769         END IF;
1770     END IF;
1771     -- Standard End of Procedure/Function Logging
1772     INL_LOGGING_PVT.Log_EndProc(
1773         p_module_name    => g_module_name,
1774         p_procedure_name => l_program_name);
1775     RETURN FND_API.to_boolean(l_response) ;
1776 EXCEPTION
1777     WHEN L_FND_EXC_ERROR THEN
1778         -- Standard Expected Error Logging
1779         INL_LOGGING_PVT.Log_ExpecError (
1780             p_module_name    => g_module_name,
1781             p_procedure_name => l_program_name);
1782         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1783     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
1784         -- Standard Unexpected Error Logging
1785         INL_LOGGING_PVT.Log_UnexpecError (
1786             p_module_name    => g_module_name,
1787             p_procedure_name => l_program_name);
1788         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1789     WHEN OTHERS THEN
1790         -- Add a line into inl_ship_errors
1791         Handle_InterfError(
1792             p_parent_table_name  => 'INL_SHIP_LINES_INT',
1793             p_parent_table_id    => p_ship_line_int_id,
1794             p_column_name        => l_column_name,
1795             p_column_value       => l_column_value,
1796             p_error_message_name => 'INL_ERR_PARTY_SITE',
1797             x_return_status      => l_return_status);
1798 
1799         -- If any errors happen abort API.
1800         IF l_return_status = L_FND_RET_STS_ERROR THEN
1801             RAISE L_FND_EXC_ERROR;
1802         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1803             RAISE L_FND_EXC_UNEXPECTED_ERROR;
1804         END IF;
1805         RETURN FND_API.to_boolean(L_FND_FALSE);
1806 END Validate_PartySite;
1807 
1808 -- Utility name   : Validate_SrcOrganization
1809 -- Type       : Private
1810 -- Function   : Derive Source Organization fields and validate it if required
1811 --
1812 -- Pre-reqs   : None
1813 -- Parameters :
1814 -- IN         :     p_ship_line_int_id      IN NUMBER
1815 --                  p_validation_flag       IN VARCHAR2
1816 --
1817 -- OUT        : x_src_organization_id   IN NOUT NOCOPY NUMBER
1818 --              x_src_organization_code IN OUT NOCOPY VARCHAR2
1819 --              x_return_status         OUT NOCOPY VARCHAR2
1820 --
1821 -- Version    : Current version 1.0
1822 --
1823 -- Notes      :
1824 FUNCTION Validate_SrcOrganization(
1825     p_ship_line_int_id      IN NUMBER,
1826     p_validation_flag       IN VARCHAR2,
1827     x_src_organization_id   IN OUT NOCOPY NUMBER,
1828     x_src_organization_code IN OUT NOCOPY VARCHAR2,
1829     x_return_status         OUT NOCOPY VARCHAR2
1830 ) RETURN BOOLEAN IS
1831     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_SrcOrganization';
1832     l_debug_info    VARCHAR2(400) ;
1833     l_result        VARCHAR2(1) := L_FND_TRUE;
1834     l_return_status VARCHAR2(1) := L_FND_TRUE;
1835 
1836     l_column_name      VARCHAR2(40);
1837     l_column_value     VARCHAR2(25);
1838     l_count_alw_party_type NUMBER;
1839     l_count_alw_party_usg  NUMBER;
1840 
1841 BEGIN
1842     -- Standard Beginning of Procedure/Function Logging
1843     INL_LOGGING_PVT.Log_BeginProc(
1844         p_module_name    => g_module_name,
1845         p_procedure_name => l_program_name) ;
1846     --  Initialize API return status to success
1847     x_return_status := L_FND_RET_STS_SUCCESS;
1848 
1849     l_debug_info := 'Derive Source Organization and validate it if required ';
1850     INL_LOGGING_PVT.Log_Statement(
1851         p_module_name      => g_module_name,
1852         p_procedure_name   => l_program_name,
1853         p_debug_info       => l_debug_info);
1854 
1855     INL_LOGGING_PVT.Log_Variable(
1856         p_module_name    => g_module_name,
1857         p_procedure_name => l_program_name,
1858         p_var_name       => 'x_src_organization_id',
1859         p_var_value      => x_src_organization_id);
1860     INL_LOGGING_PVT.Log_Variable(
1861         p_module_name    => g_module_name,
1862         p_procedure_name => l_program_name,
1863         p_var_name       => 'x_src_organization_code',
1864         p_var_value      => x_src_organization_code);
1865     INL_LOGGING_PVT.Log_Variable(
1866         p_module_name    => g_module_name,
1867         p_procedure_name => l_program_name,
1868         p_var_name       => 'p_ship_line_int_id',
1869         p_var_value      => p_ship_line_int_id);
1870     INL_LOGGING_PVT.Log_Variable(
1871         p_module_name    => g_module_name,
1872         p_procedure_name => l_program_name,
1873         p_var_name       => 'p_validation_flag',
1874         p_var_value      => p_validation_flag);
1875 
1876     IF p_validation_flag = 'N' THEN
1877         l_debug_info := 'Validation is not required for Source Organization, only derivation';
1878         INL_LOGGING_PVT.Log_Statement(
1879             p_module_name      => g_module_name,
1880             p_procedure_name   => l_program_name,
1881             p_debug_info       => l_debug_info) ;
1882         IF x_src_organization_id IS NOT NULL THEN
1883             x_src_organization_code := NULL;
1884         ELSIF x_src_organization_code IS NOT NULL THEN
1885             l_column_name  := 'SOURCE_ORGANIZATION_CODE';
1886             l_column_value := x_src_organization_code;
1887 
1888             SELECT ood.organization_id
1889             INTO x_src_organization_id
1890             FROM org_organization_definitions ood
1891             WHERE ood.organization_code = x_src_organization_code;
1892         END IF;
1893     ELSIF p_validation_flag = 'Y' THEN
1894         l_debug_info := 'Derive and validate Source Organization';
1895         INL_LOGGING_PVT.Log_Statement(
1896             p_module_name      => g_module_name,
1897             p_procedure_name   => l_program_name,
1898             p_debug_info       => l_debug_info) ;
1899 
1900         IF x_src_organization_id IS NOT NULL THEN
1901             l_column_name  := 'SOURCE_ORGANIZATION_CODE';
1902             l_column_value := x_src_organization_code;
1903         ELSE -- x_src_organization_code IS NOT NULL
1904             l_column_name  := 'SOURCE_ORGANIZATION_CODE';
1905             l_column_value := x_src_organization_code;
1906         END IF;
1907         SELECT
1908             ood.organization_code,
1909             ood.organization_id
1910         INTO
1911             x_src_organization_code,
1912             x_src_organization_id
1913         FROM
1914             org_organization_definitions ood
1915         WHERE (
1916             x_src_organization_id IS NOT NULL
1917             AND ood.organization_id = x_src_organization_id
1918             )
1919             OR
1920             ood.organization_code = x_src_organization_code
1921         ;
1922    END IF;
1923 
1924     -- Standard End of Procedure/Function Logging
1925     INL_LOGGING_PVT.Log_EndProc(
1926         p_module_name    => g_module_name,
1927         p_procedure_name => l_program_name);
1928     RETURN FND_API.to_boolean(l_result) ;
1929 EXCEPTION
1930     WHEN L_FND_EXC_ERROR THEN
1931         -- Standard Expected Error Logging
1932         INL_LOGGING_PVT.Log_ExpecError (
1933             p_module_name    => g_module_name,
1934             p_procedure_name => l_program_name);
1935         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1936     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
1937         -- Standard Unexpected Error Logging
1938         INL_LOGGING_PVT.Log_UnexpecError (
1939             p_module_name    => g_module_name,
1940             p_procedure_name => l_program_name);
1941         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1942     WHEN OTHERS THEN
1943         -- Add a line into inl_ship_errors
1944         Handle_InterfError(
1945             p_parent_table_name  => 'INL_SHIP_LINES_INT',
1946             p_parent_table_id    => p_ship_line_int_id,
1947             p_column_name        => l_column_name,
1948             p_column_value       => l_column_value,
1949             p_error_message_name => 'INL_ERR_SRC_ORG',
1950             x_return_status      => l_return_status);
1951         -- If any errors happen abort API.
1952         IF l_return_status = L_FND_RET_STS_ERROR THEN
1953             RAISE L_FND_EXC_ERROR;
1954         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
1955             RAISE L_FND_EXC_UNEXPECTED_ERROR;
1956         END IF;
1957         RETURN FND_API.to_boolean(L_FND_FALSE) ;
1958 END Validate_SrcOrganization;
1959 
1960 -- Utility name   : Validate_ShipLineGrpNum
1961 -- Type       : Private
1962 -- Function   : Derive ship line group id when transaction_type = UPDATE
1963 --
1964 -- Pre-reqs   : None
1965 -- Parameters :
1966 -- IN         :     p_ship_header_int_id  IN NUMBER
1967 --                  p_ship_line_int_id    IN NUMBER
1968 --                  p_validation_flag     IN VARCHAR2
1969 --                  p_ship_header_id      IN NUMBER
1970 --                  p_ship_line_id        IN NUMBER
1971 --
1972 -- OUT        :     x_ship_line_group_num IN OUT NOCOPY NUMBER
1973 --                  x_ship_line_group_id  IN OUT NOCOPY NUMBER
1974 --                  x_return_status       OUT NOCOPY VARCHAR2
1975 --
1976 -- Version    : Current version 1.0
1977 --
1978 -- Notes      : Called only for transaction_type = UPDATE
1979 
1980 FUNCTION Validate_ShipLineGrpNum(
1981     p_ship_header_int_id  IN NUMBER,
1982     p_ship_line_int_id    IN NUMBER,
1983     p_validation_flag     IN VARCHAR2,
1984     p_ship_header_id      IN NUMBER,
1985     p_ship_line_id        IN NUMBER,
1986     x_ship_line_group_num IN OUT NOCOPY NUMBER,
1987     x_ship_line_group_id  IN OUT NOCOPY NUMBER,
1988     x_return_status       OUT NOCOPY VARCHAR2
1989 ) RETURN BOOLEAN IS
1990     l_program_name              CONSTANT VARCHAR2(30) := 'Validate_ShipLineGrpNum';
1991     l_debug_info             VARCHAR2(400) ;
1992     l_result                 VARCHAR2(1) := L_FND_TRUE;
1993     l_return_status          VARCHAR2(1) := L_FND_TRUE;
1994     l_column_name            VARCHAR2(30):= 'SHIP_LINE_GROUP_NUM';
1995     l_colum_value            VARCHAR2(30):= x_ship_line_group_num;
1996     l_valid_ln_group         NUMBER;
1997 
1998 BEGIN
1999     -- Standard Beginning of Procedure/Function Logging
2000     INL_LOGGING_PVT.Log_BeginProc(
2001         p_module_name    => g_module_name,
2002         p_procedure_name => l_program_name) ;
2003     --  Initialize API return status to success
2004     x_return_status := L_FND_RET_STS_SUCCESS;
2005 
2006     l_debug_info := 'Ship Line Group validation';
2007     INL_LOGGING_PVT.Log_Statement(
2008         p_module_name      => g_module_name,
2009         p_procedure_name   => l_program_name,
2010         p_debug_info       => l_debug_info);
2011 
2012     INL_LOGGING_PVT.Log_Variable(
2013         p_module_name    => g_module_name,
2014         p_procedure_name => l_program_name,
2015         p_var_name       => 'p_ship_header_int_id',
2016         p_var_value      => p_ship_header_int_id) ;
2017 
2018     INL_LOGGING_PVT.Log_Variable(
2019         p_module_name    => g_module_name,
2020         p_procedure_name => l_program_name,
2021         p_var_name       => 'p_ship_line_int_id',
2022         p_var_value      => p_ship_line_int_id);
2023 
2024     INL_LOGGING_PVT.Log_Variable(
2025         p_module_name    => g_module_name,
2026         p_procedure_name => l_program_name,
2027         p_var_name       => 'p_validation_flag',
2028         p_var_value      => p_validation_flag) ;
2029 
2030     INL_LOGGING_PVT.Log_Variable(
2031         p_module_name    => g_module_name,
2032         p_procedure_name => l_program_name,
2033         p_var_name       => 'p_ship_header_id',
2034         p_var_value      => p_ship_header_id) ;
2035 
2036     INL_LOGGING_PVT.Log_Variable(
2037         p_module_name    => g_module_name,
2038         p_procedure_name => l_program_name,
2039         p_var_name       => 'p_ship_line_id',
2040         p_var_value      => p_ship_line_id) ;
2041 
2042     INL_LOGGING_PVT.Log_Variable(
2043         p_module_name    => g_module_name,
2044         p_procedure_name => l_program_name,
2045         p_var_name       => 'x_ship_line_group_num',
2046         p_var_value      => x_ship_line_group_num) ;
2047 
2048     INL_LOGGING_PVT.Log_Variable(
2049         p_module_name    => g_module_name,
2050         p_procedure_name => l_program_name,
2051         p_var_name       => 'x_ship_line_group_id',
2052         p_var_value      => x_ship_line_group_id) ;
2053 
2054     IF x_ship_line_group_id IS NOT NULL THEN
2055         x_ship_line_group_num := NULL;
2056 
2057         IF p_validation_flag = 'Y' THEN
2058 
2059             l_debug_info := 'Validating Ship Line Group Number';
2060             INL_LOGGING_PVT.Log_Statement(
2061                 p_module_name      => g_module_name,
2062                 p_procedure_name   => l_program_name,
2063                 p_debug_info       => l_debug_info);
2064 
2065             SELECT COUNT(1)
2066             INTO l_valid_ln_group
2067             FROM inl_ship_line_groups slg
2068             WHERE slg.ship_line_group_id = x_ship_line_group_id;
2069 
2070             INL_LOGGING_PVT.Log_Variable(
2071                 p_module_name    => g_module_name,
2072                 p_procedure_name => l_program_name,
2073                 p_var_name       => 'l_valid_ln_group',
2074                 p_var_value      => l_valid_ln_group);
2075 
2076             IF NVL(l_valid_ln_group, 0) = 0 THEN
2077                 l_debug_info := 'No Group Number found';
2078                 INL_LOGGING_PVT.Log_Statement(
2079                     p_module_name      => g_module_name,
2080                     p_procedure_name   => l_program_name,
2081                     p_debug_info       => l_debug_info);
2082                 l_result := L_FND_FALSE;
2083                 -- Add a line into inl_ship_errors
2084                 Handle_InterfError(
2085                     p_parent_table_name  => 'INL_SHIP_LINES_INT',
2086                     p_parent_table_id    => p_ship_line_int_id,
2087                     p_column_name        => 'SHIP_LINE_GROUP_NUM',
2088                     p_column_value       => x_ship_line_group_num,
2089                     p_error_message_name => 'INL_ERR_NO_LN_GRP',
2090                     x_return_status      => l_return_status);
2091                 -- If any errors happen abort API.
2092                 IF l_return_status = L_FND_RET_STS_ERROR THEN
2093                     RAISE L_FND_EXC_ERROR;
2094                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2095                    RAISE L_FND_EXC_UNEXPECTED_ERROR;
2096                 END IF;
2097             END IF;
2098         END IF;
2099     ELSIF x_ship_line_group_num IS NOT NULL THEN
2100         l_debug_info := 'Deriving Ship Line Group from x_ship_line_group_num';
2101         INL_LOGGING_PVT.Log_Statement(
2102             p_module_name      => g_module_name,
2103             p_procedure_name   => l_program_name,
2104             p_debug_info       => l_debug_info);
2105         BEGIN
2106             SELECT slg.ship_line_group_id
2107             INTO x_ship_line_group_id
2108             FROM inl_ship_line_groups slg
2109             WHERE slg.ship_header_id = p_ship_header_id
2110             AND   slg.ship_line_group_num = x_ship_line_group_num;
2111         EXCEPTION
2112             WHEN OTHERS THEN
2113                 l_debug_info := 'No Group Number found';
2114                 INL_LOGGING_PVT.Log_Statement(
2115                     p_module_name      => g_module_name,
2116                     p_procedure_name   => l_program_name,
2117                     p_debug_info       => l_debug_info);
2118                 l_result := L_FND_FALSE;
2119                 -- Add a line into inl_ship_errors
2120                 Handle_InterfError(
2121                     p_parent_table_name  => 'INL_SHIP_LINES_INT',
2122                     p_parent_table_id    => p_ship_line_int_id,
2123                     p_column_name        => 'SHIP_LINE_GROUP_NUM',
2124                     p_column_value       => x_ship_line_group_num,
2125                     p_error_message_name => 'INL_ERR_NO_LN_GRP',
2126                     x_return_status      => l_return_status);
2127                 -- If any errors happen abort API.
2128                 IF l_return_status = L_FND_RET_STS_ERROR THEN
2129                     RAISE L_FND_EXC_ERROR;
2130                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2131                    RAISE L_FND_EXC_UNEXPECTED_ERROR;
2132                 END IF;
2133         END;
2134 /* -- -- -- -- -- */
2135     ELSIF p_ship_line_id IS NOT NULL THEN
2136         l_debug_info := 'Deriving Ship Line Group from p_ship_line_id';
2137         INL_LOGGING_PVT.Log_Statement(
2138             p_module_name      => g_module_name,
2139             p_procedure_name   => l_program_name,
2140             p_debug_info       => l_debug_info);
2141         BEGIN
2142             SELECT sl.ship_line_group_id, slg.ship_line_group_num
2143             INTO x_ship_line_group_id,
2144                  x_ship_line_group_num
2145             FROM inl_ship_lines_all sl, --Bug#10381495
2146                  inl_ship_line_groups slg
2147             WHERE sl.ship_header_id = p_ship_header_id
2148             AND   sl.ship_line_id = p_ship_line_id
2149             AND   sl.ship_line_group_id = slg.ship_line_group_id
2150             ;
2151         EXCEPTION
2152             WHEN OTHERS THEN
2153                 l_debug_info := 'No Group Number found';
2154                 INL_LOGGING_PVT.Log_Statement(
2155                     p_module_name      => g_module_name,
2156                     p_procedure_name   => l_program_name,
2157                     p_debug_info       => l_debug_info);
2158                 l_result := L_FND_FALSE;
2159                 -- Add a line into inl_ship_errors
2160                 Handle_InterfError(
2161                     p_parent_table_name  => 'INL_SHIP_LINES_INT',
2162                     p_parent_table_id    => p_ship_line_int_id,
2163                     p_column_name        => 'SHIP_LINE_GROUP_NUM',
2164                     p_column_value       => x_ship_line_group_num,
2165                     p_error_message_name => 'INL_ERR_NO_LN_GRP',
2166                     x_return_status      => l_return_status);
2167                 -- If any errors happen abort API.
2168                 IF l_return_status = L_FND_RET_STS_ERROR THEN
2169                     RAISE L_FND_EXC_ERROR;
2170                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2171                    RAISE L_FND_EXC_UNEXPECTED_ERROR;
2172                 END IF;
2173         END;
2174 /* -- -- -- -- -- */
2175     END IF;
2176     INL_LOGGING_PVT.Log_Variable(
2177         p_module_name    => g_module_name,
2178         p_procedure_name => l_program_name,
2179         p_var_name       => 'x_ship_line_group_num',
2180         p_var_value      => x_ship_line_group_num) ;
2181 
2182     INL_LOGGING_PVT.Log_Variable(
2183         p_module_name    => g_module_name,
2184         p_procedure_name => l_program_name,
2185         p_var_name       => 'x_ship_line_group_id',
2186         p_var_value      => x_ship_line_group_id) ;
2187 
2188 
2189     -- Standard End of Procedure/Function Logging
2190     INL_LOGGING_PVT.Log_EndProc(
2191         p_module_name    => g_module_name,
2192         p_procedure_name => l_program_name);
2193     RETURN FND_API.to_boolean(l_result) ;
2194 EXCEPTION
2195     WHEN L_FND_EXC_ERROR THEN
2196         -- Standard Expected Error Logging
2197         INL_LOGGING_PVT.Log_ExpecError (
2198             p_module_name    => g_module_name,
2199             p_procedure_name => l_program_name);
2200         RETURN FND_API.to_boolean(L_FND_FALSE) ;
2201     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
2202         -- Standard Unexpected Error Logging
2203         INL_LOGGING_PVT.Log_UnexpecError (
2204             p_module_name    => g_module_name,
2205             p_procedure_name => l_program_name);
2206         RETURN FND_API.to_boolean(L_FND_FALSE) ;
2207     WHEN OTHERS THEN
2208       -- Standard Unexpected Error Logging
2209         INL_LOGGING_PVT.Log_UnexpecError (
2210             p_module_name    => g_module_name,
2211             p_procedure_name => l_program_name);
2212         IF FND_MSG_PUB.Check_Msg_Level(
2213             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
2214         ) THEN
2215             FND_MSG_PUB.Add_Exc_Msg(
2216                 p_pkg_name       => g_pkg_name,
2217                 p_procedure_name => l_program_name);
2218         END IF;
2219         RETURN FND_API.to_boolean(L_FND_FALSE) ;
2220 END Validate_ShipLineGrpNum;
2221 
2222 -- Utility name   : Validate_ShipLineNum
2223 -- Type       : Private
2224 -- Function   : Derive ship line id when transaction_type = UPDATE
2225 --
2226 -- Pre-reqs   : None
2227 -- Parameters :
2228 -- IN         :     p_ship_line_int_id    IN NUMBER
2229 --                  p_validation_flag     IN VARCHAR2
2230 --                  p_transaction_type    IN VARCHAR2
2231 --                  p_ship_header_id      IN NUMBER
2232 --                  p_ship_line_group_id  IN NUMBER
2233 --                  p_ship_line_num       IN NUMBER
2234 --
2235 -- OUT        :     x_ship_line_id        IN OUT NOCOPY NUMBER
2236 --                  x_return_status       OUT NOCOPY VARCHAR2
2237 --
2238 -- Version    : Current version 1.0
2239 --
2240 -- Notes      : Called only for transaction_type = UPDATE
2241 
2242 FUNCTION Validate_ShipLineNum(
2243     p_ship_line_int_id    IN NUMBER,
2244     p_validation_flag     IN VARCHAR2,
2245     p_ship_header_id      IN NUMBER,
2246     p_ship_line_group_id  IN NUMBER,
2247     x_ship_line_num       IN OUT NOCOPY NUMBER,
2248     x_ship_line_id        IN OUT NOCOPY NUMBER,
2249     x_return_status       OUT NOCOPY VARCHAR2
2250 ) RETURN BOOLEAN IS
2251     l_program_name               CONSTANT VARCHAR2(30) := 'Validate_ShipLineNum';
2252     l_debug_info              VARCHAR2(400) ;
2253     l_response                VARCHAR2(1) := L_FND_TRUE;
2254     l_return_status           VARCHAR2(1);
2255     l_count_ship_ln_num_exist NUMBER;
2256     l_column_name             VARCHAR2(30);
2257     l_colum_value             VARCHAR2(30);
2258 BEGIN
2259     -- Standard Beginning of Procedure/Function Logging
2260     INL_LOGGING_PVT.Log_BeginProc(
2261         p_module_name    => g_module_name,
2262         p_procedure_name => l_program_name) ;
2263     --  Initialize API return status to success
2264     x_return_status := L_FND_RET_STS_SUCCESS;
2265 
2266     INL_LOGGING_PVT.Log_Variable(
2267         p_module_name    => g_module_name,
2268         p_procedure_name => l_program_name,
2269         p_var_name       => 'p_ship_line_int_id',
2270         p_var_value      => p_ship_line_int_id);
2271 
2272     INL_LOGGING_PVT.Log_Variable(
2273         p_module_name    => g_module_name,
2274         p_procedure_name => l_program_name,
2275         p_var_name       => 'p_validation_flag',
2276         p_var_value      => p_validation_flag) ;
2277 
2278     INL_LOGGING_PVT.Log_Variable(
2279         p_module_name    => g_module_name,
2280         p_procedure_name => l_program_name,
2281         p_var_name       => 'p_ship_header_id',
2282         p_var_value      => p_ship_header_id) ;
2283 
2284     INL_LOGGING_PVT.Log_Variable(
2285         p_module_name    => g_module_name,
2286         p_procedure_name => l_program_name,
2287         p_var_name       => 'p_ship_line_group_id',
2288         p_var_value      => p_ship_line_group_id) ;
2289 
2290     INL_LOGGING_PVT.Log_Variable(
2291         p_module_name    => g_module_name,
2292         p_procedure_name => l_program_name,
2293         p_var_name       => 'x_ship_line_num',
2294         p_var_value      => x_ship_line_num) ;
2295 
2296     INL_LOGGING_PVT.Log_Variable(
2297         p_module_name    => g_module_name,
2298         p_procedure_name => l_program_name,
2299         p_var_name       => 'x_ship_line_id',
2300         p_var_value      => x_ship_line_id) ;
2301 
2302     IF x_ship_line_id IS NOT NULL THEN
2303         l_column_name := 'x_ship_line_id';
2304         l_colum_value := x_ship_line_id;
2305 
2306         x_ship_line_num := NULL;
2307         IF p_validation_flag = 'Y' THEN
2308             SELECT COUNT (1)
2309             INTO l_count_ship_ln_num_exist
2310             FROM inl_ship_lines_all sl --Bug#10381495
2311             WHERE sl.ship_line_id = x_ship_line_id;
2312 
2313             IF NVL(l_count_ship_ln_num_exist,0) = 0 THEN
2314                 l_debug_info := 'No Shipment Line found';
2315                 INL_LOGGING_PVT.Log_Statement(
2316                     p_module_name      => g_module_name,
2317                     p_procedure_name   => l_program_name,
2318                     p_debug_info       => l_debug_info);
2319                 l_response := L_FND_FALSE;
2320                 -- Add a line into inl_ship_errors
2321                 Handle_InterfError(
2322                     p_parent_table_name  => 'INL_SHIP_LINES_INT',
2323                     p_parent_table_id    => p_ship_line_int_id,
2324                     p_column_name        => 'SHIP_LINE_ID',
2325                     p_column_value       => x_ship_line_id,
2326                     p_error_message_name => 'INL_ERR_CHK_NO_SHIP_LN',
2327                     x_return_status      => l_return_status);
2328                 -- If any errors happen abort API.
2329                 IF l_return_status = L_FND_RET_STS_ERROR THEN
2330                     RAISE L_FND_EXC_ERROR;
2331                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2332                    RAISE L_FND_EXC_UNEXPECTED_ERROR;
2333                 END IF;
2334             END IF;
2335         END IF;
2336     ELSIF x_ship_line_num IS NOT NULL THEN
2337         l_column_name := 'x_ship_line_num';
2338         l_colum_value := x_ship_line_num;
2339         BEGIN
2340             SELECT sl.ship_line_id
2341             INTO x_ship_line_id
2342             FROM inl_ship_lines_all sl --Bug#10381495
2343             WHERE sl.ship_header_id = p_ship_header_id
2344             AND sl.ship_line_group_id = p_ship_line_group_id
2345             AND sl.ship_line_num = x_ship_line_num;
2346         EXCEPTION
2347             WHEN OTHERS THEN
2348                 l_debug_info := 'No Ship Line Number found';
2349                 INL_LOGGING_PVT.Log_Statement(
2350                     p_module_name      => g_module_name,
2351                     p_procedure_name   => l_program_name,
2352                     p_debug_info       => l_debug_info);
2353                 l_response := L_FND_FALSE;
2354                 -- Add a line into inl_ship_errors
2355                 Handle_InterfError(
2356                     p_parent_table_name  => 'INL_SHIP_LINES_INT',
2357                     p_parent_table_id    => p_ship_line_int_id,
2358                     p_column_name        => 'SHIP_LINE_NUM',
2359                     p_column_value       => x_ship_line_num,
2360                     p_error_message_name => 'INL_ERR_CHK_NO_SHIP_LN',
2361                     x_return_status      => l_return_status);
2362                 -- If any errors happen abort API.
2363                 IF l_return_status = L_FND_RET_STS_ERROR THEN
2364                     RAISE L_FND_EXC_ERROR;
2365                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2366                    RAISE L_FND_EXC_UNEXPECTED_ERROR;
2367                 END IF;
2368         END;
2369     END IF;
2370 
2371     -- Standard End of Procedure/Function Logging
2372     INL_LOGGING_PVT.Log_EndProc(
2373         p_module_name    => g_module_name,
2374         p_procedure_name => l_program_name);
2375     RETURN FND_API.to_boolean(l_response) ;
2376 EXCEPTION
2377     WHEN L_FND_EXC_ERROR THEN
2378         -- Standard Expected Error Logging
2379         INL_LOGGING_PVT.Log_ExpecError (
2380             p_module_name    => g_module_name,
2381             p_procedure_name => l_program_name);
2382         RETURN FND_API.to_boolean(L_FND_FALSE) ;
2383     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
2384         -- Standard Unexpected Error Logging
2385         INL_LOGGING_PVT.Log_UnexpecError (
2386             p_module_name    => g_module_name,
2387             p_procedure_name => l_program_name);
2388         RETURN FND_API.to_boolean(L_FND_FALSE) ;
2389     WHEN OTHERS THEN
2390         -- Add a line into inl_ship_errors
2391         Handle_InterfError(
2392             p_parent_table_name  => 'INL_SHIP_LINES_INT',
2393             p_parent_table_id    => p_ship_line_int_id,
2394             p_column_name        => 'SHIP_LINE_NUM',
2395             p_column_value       => x_ship_line_num,
2396             p_error_message_name => 'INL_ERR_CHK_NO_SHIP_LN',
2397             x_return_status      => l_return_status);
2398         -- If any errors happen abort API.
2399         IF l_return_status = L_FND_RET_STS_ERROR THEN
2400             RAISE L_FND_EXC_ERROR;
2401         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2402             RAISE L_FND_EXC_UNEXPECTED_ERROR;
2403         END IF;
2404         RETURN FND_API.to_boolean(L_FND_FALSE) ;
2405 END Validate_ShipLineNum;
2406 
2407 -- Utility name   : Validate_ShipLineType
2408 -- Type       : Private
2409 -- Function   : Derive Shipment Line Type and validate it if required
2410 --              Check if the ship Line type exists, is active for sysdate
2411 --              and is associated with the ship type
2412 -- Pre-reqs   : None
2413 -- Parameters :
2414 -- IN         :     p_ship_line_int_id    IN NUMBER,
2415 --                  p_validation_flag     IN VARCHAR2,
2416 --                  p_ship_type_id        IN NUMBER,
2417 --
2418 -- OUT        :     x_ship_line_type_id   IN OUT NOCOPY NUMBER,
2419 --                  x_ship_line_type_code IN OUT NOCOPY VARCHAR2,
2420 --                  x_landed_cost_flag    IN OUT NOCOPY VARCHAR2,
2421 --                  x_alloc_enabled_flag  IN OUT NOCOPY VARCHAR2,
2422 --                  x_return_status       OUT NOCOPY VARCHAR2
2423 --
2424 -- Version    : Current version 1.0
2425 --
2426 -- Notes      :
2427 FUNCTION Validate_ShipLineType(
2428     p_ship_line_int_id    IN NUMBER,
2429     p_validation_flag     IN VARCHAR2,
2430     p_ship_type_id        IN NUMBER,
2431     x_ship_line_type_id   IN OUT NOCOPY NUMBER,
2432     x_ship_line_type_code IN OUT NOCOPY VARCHAR2,
2433     x_landed_cost_flag    IN OUT NOCOPY VARCHAR2,
2434     x_alloc_enabled_flag  IN OUT NOCOPY VARCHAR2,
2435     x_return_status       OUT NOCOPY VARCHAR2
2436 ) RETURN BOOLEAN IS
2437     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_ShipLineType';
2438     l_debug_info    VARCHAR2(400) ;
2439     l_result        VARCHAR2(1) := L_FND_TRUE;
2440     l_return_status VARCHAR2(1) := L_FND_TRUE;
2441 
2442     l_ship_line_type_code VARCHAR2(400);
2443     l_active_from_date    DATE;
2444     l_active_to_date      DATE;
2445     l_count_alw_ship_ln   NUMBER;
2446     l_column_name         VARCHAR2(30);
2447     l_column_value        VARCHAR2(30);
2448 
2449 BEGIN
2450     -- Standard Beginning of Procedure/Function Logging
2451     INL_LOGGING_PVT.Log_BeginProc(
2452         p_module_name    => g_module_name,
2453         p_procedure_name => l_program_name) ;
2454     --  Initialize API return status to success
2455     x_return_status := L_FND_RET_STS_SUCCESS;
2456 
2457     INL_LOGGING_PVT.Log_Variable(
2458         p_module_name    => g_module_name,
2459         p_procedure_name => l_program_name,
2460         p_var_name       => 'p_ship_line_int_id',
2461         p_var_value      => p_ship_line_int_id);
2462     INL_LOGGING_PVT.Log_Variable(
2463         p_module_name    => g_module_name,
2464         p_procedure_name => l_program_name,
2465         p_var_name       => 'p_validation_flag',
2466         p_var_value      => p_validation_flag);
2467     INL_LOGGING_PVT.Log_Variable(
2468         p_module_name    => g_module_name,
2469         p_procedure_name => l_program_name,
2470         p_var_name       => 'p_ship_type_id',
2471         p_var_value      => p_ship_type_id);
2472     INL_LOGGING_PVT.Log_Variable(
2473         p_module_name    => g_module_name,
2474         p_procedure_name => l_program_name,
2475         p_var_name       => 'x_ship_line_type_id',
2476         p_var_value      => x_ship_line_type_id);
2477     INL_LOGGING_PVT.Log_Variable(
2478         p_module_name    => g_module_name,
2479         p_procedure_name => l_program_name,
2480         p_var_name       => 'x_ship_line_type_code',
2481         p_var_value      => x_ship_line_type_code);
2482 
2483     IF p_validation_flag = 'N' THEN
2484         l_debug_info := 'Validation is not required for Ship Line Type';
2485         INL_LOGGING_PVT.Log_Statement(
2486             p_module_name      => g_module_name,
2487             p_procedure_name   => l_program_name,
2488             p_debug_info       => l_debug_info) ;
2489 
2490         IF x_ship_line_type_id IS NOT NULL THEN
2491             l_column_name  := 'SHIP_LINE_TYPE_ID';
2492             l_column_value := x_ship_line_type_id;
2493             x_ship_line_type_code := NULL;
2494         ELSE
2495             l_column_name  := 'SHIP_LINE_TYPE_CODE';
2496             l_column_value := x_ship_line_type_code;
2497         END IF;
2498         SELECT slt.ship_line_type_id,
2499                slt.dflt_landed_cost_flag,       -- # Bug 9866323
2500                slt.dflt_allocation_enabled_flag -- # Bug 9866323
2501         INTO x_ship_line_type_id,
2502              x_landed_cost_flag,
2503              x_alloc_enabled_flag
2504         FROM inl_ship_line_types_b slt
2505         WHERE (
2506             x_ship_line_type_id IS NOT NULL
2507             AND slt.ship_line_type_id = x_ship_line_type_id
2508         ) OR
2509             slt.ship_line_type_code = x_ship_line_type_code;
2510         INL_LOGGING_PVT.Log_Variable(
2511             p_module_name    => g_module_name,
2512             p_procedure_name => l_program_name,
2513             p_var_name       => 'x_landed_cost_flag',
2514             p_var_value      => x_landed_cost_flag);
2515 
2516         INL_LOGGING_PVT.Log_Variable(
2517             p_module_name    => g_module_name,
2518             p_procedure_name => l_program_name,
2519             p_var_name       => 'x_alloc_enabled_flag',
2520             p_var_value      => x_alloc_enabled_flag);
2521 
2522     ELSIF p_validation_flag = 'Y' THEN
2523         l_debug_info := 'Derive and validate Ship Line Type';
2524         INL_LOGGING_PVT.Log_Statement(
2525             p_module_name      => g_module_name,
2526             p_procedure_name   => l_program_name,
2527             p_debug_info       => l_debug_info);
2528         IF x_ship_line_type_id IS NOT NULL THEN
2529             l_column_name  := 'SHIP_LINE_TYPE_ID';
2530             l_column_value := x_ship_line_type_id;
2531             x_ship_line_type_code := NULL;
2532         ELSE
2533             l_column_name  := 'SHIP_LINE_TYPE_CODE';
2534             l_column_value := x_ship_line_type_code;
2535         END IF;
2536         SELECT
2537             slt.ship_line_type_code,
2538             slt.active_from_date,
2539             slt.active_to_date,
2540                    (SELECT COUNT(1)
2541                     FROM inl_alwd_line_types sltallow
2542                     WHERE sltallow.ship_line_type_id = slt.ship_line_type_id
2543                     AND   sltallow.parent_table_name   = 'INL_SHIP_TYPES'
2544                     AND   sltallow.parent_table_id     = p_ship_type_id),
2545             slt.dflt_landed_cost_flag,       -- # Bug 9866323
2546             slt.dflt_allocation_enabled_flag -- # Bug 9866323
2547         INTO
2548             x_ship_line_type_code,
2549             l_active_from_date,
2550             l_active_to_date,
2551             l_count_alw_ship_ln,
2552             x_landed_cost_flag,
2553             x_alloc_enabled_flag
2554         FROM inl_ship_line_types_b slt
2555         WHERE (x_ship_line_type_id IS NOT NULL
2556                AND slt.ship_line_type_id = x_ship_line_type_id)
2557         OR slt.ship_line_type_code = x_ship_line_type_code;
2558 
2559         INL_LOGGING_PVT.Log_Variable(
2560             p_module_name    => g_module_name,
2561             p_procedure_name => l_program_name,
2562             p_var_name       => 'x_landed_cost_flag',
2563             p_var_value      => x_landed_cost_flag);
2564 
2565         INL_LOGGING_PVT.Log_Variable(
2566             p_module_name    => g_module_name,
2567             p_procedure_name => l_program_name,
2568             p_var_name       => 'x_alloc_enabled_flag',
2569             p_var_value      => x_alloc_enabled_flag);
2570 
2571         -- Validate Ship Line Type
2572         IF NOT SYSDATE BETWEEN NVL((TRUNC(l_active_from_date)),SYSDATE)
2573         AND NVL((TRUNC(l_active_to_date)+.99999)-1,SYSDATE) THEN
2574             l_debug_info := 'Date is closed for the Ship Line Type';
2575             INL_LOGGING_PVT.Log_Statement(
2576                 p_module_name      => g_module_name,
2577                 p_procedure_name   => l_program_name,
2578                 p_debug_info       => l_debug_info);
2579             l_result := L_FND_FALSE;
2580             -- Add a line into inl_ship_errors
2581             Handle_InterfError(
2582                 p_parent_table_name  => 'INL_SHIP_LINES_INT',
2583                 p_parent_table_id    => p_ship_line_int_id,
2584                 p_column_name        => 'SHIP_LINE_TYPE_ID',
2585                 p_column_value       => x_ship_line_type_id,
2586                 p_error_message_name => 'INL_ERR_SHIP_LN_TP_CLOSED',
2587                 x_return_status      => l_return_status);
2588             -- If any errors happen abort API.
2589             IF l_return_status = L_FND_RET_STS_ERROR THEN
2590                 RAISE L_FND_EXC_ERROR;
2591             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2592                RAISE L_FND_EXC_UNEXPECTED_ERROR;
2593             END IF;
2594         END IF;
2595 
2596         IF NVL(l_count_alw_ship_ln,0) = 0 THEN
2597             l_debug_info := 'Ship Line Type is not defined for the specified Ship Type';
2598             INL_LOGGING_PVT.Log_Statement(
2599                 p_module_name      => g_module_name,
2600                 p_procedure_name   => l_program_name,
2601                 p_debug_info       => l_debug_info);
2602             l_result := L_FND_FALSE;
2603             -- Add a line into inl_ship_errors
2604             Handle_InterfError(
2605                 p_parent_table_name  => 'INL_SHIP_LINES_INT',
2606                 p_parent_table_id    => p_ship_line_int_id,
2607                 p_column_name        => 'SHIP_LINE_TYPE_ID',
2608                 p_column_value       => x_ship_line_type_id,
2609                 p_error_message_name => 'INL_ERR_NO_SHIP_LN_DEF',
2610                 x_return_status      => l_return_status);
2611             -- If any errors happen abort API.
2612             IF l_return_status = L_FND_RET_STS_ERROR THEN
2613                 RAISE L_FND_EXC_ERROR;
2614             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2615                RAISE L_FND_EXC_UNEXPECTED_ERROR;
2616             END IF;
2617         END IF;
2618     END IF;
2619 
2620     -- Standard End of Procedure/Function Logging
2621     INL_LOGGING_PVT.Log_EndProc(
2622         p_module_name    => g_module_name,
2623         p_procedure_name => l_program_name);
2624     RETURN FND_API.to_boolean(l_result);
2625 EXCEPTION
2626     WHEN L_FND_EXC_ERROR THEN
2627         -- Standard Expected Error Logging
2628         INL_LOGGING_PVT.Log_ExpecError (
2629             p_module_name    => g_module_name,
2630             p_procedure_name => l_program_name);
2631         RETURN FND_API.to_boolean(L_FND_FALSE) ;
2632     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
2633         -- Standard Unexpected Error Logging
2634         INL_LOGGING_PVT.Log_UnexpecError (
2635             p_module_name    => g_module_name,
2636             p_procedure_name => l_program_name);
2637         RETURN FND_API.to_boolean(L_FND_FALSE) ;
2638     WHEN OTHERS THEN
2639         -- Add a line into inl_ship_errors
2640         Handle_InterfError(
2641             p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
2642             p_parent_table_id    => p_ship_line_int_id,
2643             p_column_name        => l_column_name,
2644             p_column_value       => l_column_value,
2645             p_error_message_name => 'INL_ERR_LN_TP',
2646             x_return_status      => l_return_status);
2647 
2648         -- If any errors happen abort API.
2649         IF l_return_status = L_FND_RET_STS_ERROR THEN
2650             RAISE L_FND_EXC_ERROR;
2651         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2652             RAISE L_FND_EXC_UNEXPECTED_ERROR;
2653         END IF;
2654         RETURN FND_API.to_boolean(L_FND_FALSE) ;
2655 END Validate_ShipLineType;
2656 
2657 -- Utility name   : Validate_ShipLnSrcTypeCode
2658 -- Type       : Private
2659 -- Function   : Validate the ship line source type code if required.
2660 --              Check against INL_SHIP_LINE_SRC_TYPES lookup
2661 -- Pre-reqs   : None
2662 -- Parameters :
2663 -- IN         :     p_ship_line_int_id    IN NUMBER
2664 --                  p_ship_ln_src_tp_code IN VARCHAR2
2665 --
2666 -- OUT        :     x_return_status      OUT NOCOPY VARCHAR2
2667 --
2668 -- Version    : Current version 1.0
2669 --
2670 -- Notes      : only when p_validation_flag = 'Y'
2671 FUNCTION Validate_ShipLnSrcTypeCode(
2672     p_ship_line_int_id    IN NUMBER,
2673     p_ship_ln_src_tp_code IN VARCHAR2,
2674     x_return_status       OUT NOCOPY VARCHAR2
2675 ) RETURN BOOLEAN IS
2676     l_program_name          CONSTANT VARCHAR2(30) := 'Validate_ShipLnSrcTypeCode';
2677     l_debug_info         VARCHAR2(400) ;
2678     l_result             VARCHAR2(1) := L_FND_TRUE;
2679     l_return_status      VARCHAR2(1) := L_FND_TRUE;
2680     l_count_alw_src_type NUMBER;
2681 
2682 BEGIN
2683     -- Standard Beginning of Procedure/Function Logging
2684     INL_LOGGING_PVT.Log_BeginProc(
2685         p_module_name    => g_module_name,
2686         p_procedure_name => l_program_name) ;
2687     --  Initialize API return status to success
2688     x_return_status := L_FND_RET_STS_SUCCESS;
2689 
2690     INL_LOGGING_PVT.Log_Variable(
2691         p_module_name    => g_module_name,
2692         p_procedure_name => l_program_name,
2693         p_var_name       => 'p_ship_line_int_id',
2694         p_var_value      => p_ship_line_int_id);
2695 
2696     INL_LOGGING_PVT.Log_Variable(
2697         p_module_name    => g_module_name,
2698         p_procedure_name => l_program_name,
2699         p_var_name       => 'p_ship_ln_src_tp_code',
2700         p_var_value      => p_ship_ln_src_tp_code);
2701 
2702     SELECT COUNT(1)
2703     INTO l_count_alw_src_type
2704     FROM fnd_lookups fl
2705     WHERE fl.lookup_type = 'INL_SHIP_LINE_SRC_TYPES'
2706     AND   fl.lookup_code = p_ship_ln_src_tp_code;
2707 
2708     IF NVL(l_count_alw_src_type, 0) = 0 THEN
2709         l_debug_info := 'Invalid Shipment Line Source Type Code';
2710         INL_LOGGING_PVT.Log_Statement(
2711           p_module_name      => g_module_name,
2712           p_procedure_name   => l_program_name,
2713           p_debug_info       => l_debug_info);
2714         l_result := L_FND_FALSE;
2715         -- Add a line into inl_ship_errors
2716         Handle_InterfError(
2717            p_parent_table_name  => 'INL_SHIP_LINES_INT',
2718            p_parent_table_id    => p_ship_line_int_id,
2719            p_column_name        => 'SHIP_LINE_SRC_TYPE_CODE',
2720            p_column_value       => p_ship_ln_src_tp_code,
2721            p_error_message_name => 'INL_ERR_CHK_SHIP_LN_SRC_TP',
2722            p_token1_name        => 'SHIPL_SRC_T',
2723            p_token1_value       => p_ship_ln_src_tp_code,
2724            p_token2_name        => 'SHIP_LINE_NUM',
2725            p_token2_value       => NULL,
2726            x_return_status      => l_return_status);
2727          -- If any errors happen abort API.
2728          IF l_return_status = L_FND_RET_STS_ERROR THEN
2729             RAISE L_FND_EXC_ERROR;
2730         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2731             RAISE L_FND_EXC_UNEXPECTED_ERROR;
2732          END IF;
2733     END IF;
2734 
2735     -- Standard End of Procedure/Function Logging
2736     INL_LOGGING_PVT.Log_EndProc(
2737         p_module_name    => g_module_name,
2738         p_procedure_name => l_program_name);
2739     RETURN FND_API.to_boolean(l_result) ;
2740 EXCEPTION
2741     WHEN L_FND_EXC_ERROR THEN
2742         -- Standard Expected Error Logging
2743         INL_LOGGING_PVT.Log_ExpecError (
2744             p_module_name    => g_module_name,
2745             p_procedure_name => l_program_name);
2746         RETURN FND_API.to_boolean(L_FND_FALSE) ;
2747     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
2748         -- Standard Unexpected Error Logging
2749         INL_LOGGING_PVT.Log_UnexpecError (
2750             p_module_name    => g_module_name,
2751             p_procedure_name => l_program_name);
2752         RETURN FND_API.to_boolean(L_FND_FALSE);
2753     WHEN OTHERS THEN
2754         -- Standard Unexpected Error Logging
2755         INL_LOGGING_PVT.Log_UnexpecError (
2756             p_module_name    => g_module_name,
2757             p_procedure_name => l_program_name);
2758         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
2759         IF FND_MSG_PUB.Check_Msg_Level(
2760             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
2761         ) THEN
2762             FND_MSG_PUB.Add_Exc_Msg(
2763                 p_pkg_name       => g_pkg_name,
2764                 p_procedure_name => l_program_name);
2765         END IF;
2766 END Validate_ShipLnSrcTypeCode;
2767 
2768 -- Utility name   : Validate_Currency
2769 -- Type       : Private
2770 -- Function   : Validate Currency if required
2771 --              Validate against FND_CURRENCIES
2772 --
2773 -- Pre-reqs   : None
2774 -- Parameters :
2775 -- IN         :     p_ship_line_int_id    IN NUMBER
2776 --                  p_currency_code       IN VARCHAR2
2777 --                  p_curr_conv_date      IN DATE,
2778 --                  p_curr_conv_type      IN VARCHAR2,
2779 --                  p_org_id              IN NUMBER,
2780 --
2781 -- OUT        :     x_curr_conv_rate      IN OUT NOCOPY NUMBER,
2782 --                  x_return_status      OUT NOCOPY VARCHAR2
2783 --
2784 -- Version    : Current version 1.0
2785 --
2786 -- Notes      :
2787 FUNCTION Validate_Currency(
2788     p_ship_line_int_id    IN NUMBER,
2789     p_validation_flag     IN VARCHAR2,
2790     p_currency_code       IN VARCHAR2,
2791     p_curr_conv_date      IN DATE,
2792     p_curr_conv_type      IN VARCHAR2,
2793     p_org_id              IN NUMBER,
2794     x_curr_conv_rate      IN OUT NOCOPY NUMBER,
2795     x_return_status       OUT NOCOPY VARCHAR2
2796 ) RETURN BOOLEAN IS
2797     l_program_name             CONSTANT VARCHAR2(30) := 'Validate_Currency';
2798     l_debug_info            VARCHAR2(400) ;
2799     l_response              VARCHAR2(1) := L_FND_TRUE;
2800     l_return_status         VARCHAR2(1) := L_FND_TRUE;
2801     l_count_curr_code_valid NUMBER;
2802     l_func_currency_code    VARCHAR2(15) ;
2803     l_count_conv_tp_valid   NUMBER;
2804 BEGIN
2805     -- Standard Beginning of Procedure/Function Logging
2806     INL_LOGGING_PVT.Log_BeginProc(
2807         p_module_name    => g_module_name,
2808         p_procedure_name => l_program_name) ;
2809     --  Initialize API return status to success
2810     x_return_status := L_FND_RET_STS_SUCCESS;
2811 
2812     INL_LOGGING_PVT.Log_Variable(
2813         p_module_name    => g_module_name,
2814         p_procedure_name => l_program_name,
2815         p_var_name       => 'p_ship_line_int_id',
2816         p_var_value      => p_ship_line_int_id);
2817     INL_LOGGING_PVT.Log_Variable(
2818         p_module_name    => g_module_name,
2819         p_procedure_name => l_program_name,
2820         p_var_name       => 'p_validation_flag',
2821         p_var_value      => p_validation_flag);
2822     INL_LOGGING_PVT.Log_Variable(
2823         p_module_name    => g_module_name,
2824         p_procedure_name => l_program_name,
2825         p_var_name       => 'p_currency_code',
2826         p_var_value      => p_currency_code);
2827     INL_LOGGING_PVT.Log_Variable(
2828         p_module_name    => g_module_name,
2829         p_procedure_name => l_program_name,
2830         p_var_name       => 'p_curr_conv_date',
2831         p_var_value      => p_curr_conv_date);
2832     INL_LOGGING_PVT.Log_Variable(
2833         p_module_name    => g_module_name,
2834         p_procedure_name => l_program_name,
2835         p_var_name       => 'x_curr_conv_rate',
2836         p_var_value      => x_curr_conv_rate);
2837     INL_LOGGING_PVT.Log_Variable(
2838         p_module_name    => g_module_name,
2839         p_procedure_name => l_program_name,
2840         p_var_name       => 'p_curr_conv_type',
2841         p_var_value      => p_curr_conv_type);
2842     INL_LOGGING_PVT.Log_Variable(
2843         p_module_name    => g_module_name,
2844         p_procedure_name => l_program_name,
2845         p_var_name       => 'p_org_id',
2846         p_var_value      => p_org_id);
2847 
2848     l_debug_info := 'Get functional currency code';
2849     INL_LOGGING_PVT.Log_Statement(
2850         p_module_name      => g_module_name,
2851         p_procedure_name   => l_program_name,
2852         p_debug_info       => l_debug_info);
2853 
2854     SELECT gl.currency_code
2855     INTO   l_func_currency_code
2856     FROM   gl_sets_of_books gl,
2857            financials_system_params_all fsp --Bug#10381495
2858     WHERE gl.set_of_books_id = fsp.set_of_books_id
2859     AND   org_id = p_org_id;
2860 
2861     INL_LOGGING_PVT.Log_Variable(
2862         p_module_name    => g_module_name,
2863         p_procedure_name => l_program_name,
2864         p_var_name       => 'l_func_currency_code',
2865         p_var_value      => l_func_currency_code);
2866 
2867     IF p_validation_flag = 'Y'
2868     THEN
2869         SELECT COUNT(1)
2870         INTO  l_count_curr_code_valid
2871         FROM  fnd_currencies fc
2872         WHERE fc.currency_code = p_currency_code;
2873 
2874         IF NVL(l_count_curr_code_valid, 0) = 0 THEN
2875             l_debug_info := 'Currency Code is invalid';
2876             INL_LOGGING_PVT.Log_Statement(
2877               p_module_name      => g_module_name,
2878               p_procedure_name   => l_program_name,
2879               p_debug_info       => l_debug_info);
2880             l_response := L_FND_FALSE;
2881             -- Add a line into inl_ship_errors
2882             Handle_InterfError(
2883                p_parent_table_name  => 'INL_SHIP_LINES_INT',
2884                p_parent_table_id    => p_ship_line_int_id,
2885                p_column_name        => 'CURRENCY_CODE',
2886                p_column_value       => p_currency_code,
2887                p_error_message_name => 'INL_ERR_CURR_CODE_INV',
2888                x_return_status      => l_return_status);
2889              -- If any errors happen abort API.
2890              IF l_return_status = L_FND_RET_STS_ERROR THEN
2891                 RAISE L_FND_EXC_ERROR;
2892              ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2893                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
2894              END IF;
2895         ELSE
2896             IF l_func_currency_code = p_currency_code THEN
2897                 IF p_curr_conv_type IS NOT NULL
2898                 THEN
2899                     l_debug_info := 'Currency Conversion type should be null';
2900                     INL_LOGGING_PVT.Log_Statement(
2901                       p_module_name      => g_module_name,
2902                       p_procedure_name   => l_program_name,
2903                       p_debug_info       => l_debug_info);
2904                     l_response := L_FND_FALSE;
2905                     -- Add a line into inl_ship_errors
2906                     Handle_InterfError(
2907                        p_parent_table_name  => 'INL_SHIP_LINES_INT',
2908                        p_parent_table_id    => p_ship_line_int_id,
2909                        p_column_name        => 'CURRENCY_CONVERSION_TYPE',
2910                        p_column_value       => p_curr_conv_type,
2911                        p_error_message_name => 'INL_ERR_CURR_CONV_TP_NNULL',
2912                        x_return_status      => l_return_status);
2913                     -- If any errors happen abort API.
2914                     IF l_return_status = L_FND_RET_STS_ERROR THEN
2915                         RAISE L_FND_EXC_ERROR;
2916                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2917                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
2918                     END IF;
2919                 END IF;
2920                 IF x_curr_conv_rate IS NOT NULL
2921                 THEN
2922                     l_debug_info := 'Currency Conversion Rate should be null';
2923                     INL_LOGGING_PVT.Log_Statement(
2924                       p_module_name      => g_module_name,
2925                       p_procedure_name   => l_program_name,
2926                       p_debug_info       => l_debug_info);
2927                     l_response := L_FND_FALSE;
2928                     -- Add a line into inl_ship_errors
2929                     Handle_InterfError(
2930                        p_parent_table_name  => 'INL_SHIP_LINES_INT',
2931                        p_parent_table_id    => p_ship_line_int_id,
2932                        p_column_name        => 'CURRENCY_CONVERSION_RATE',
2933                        p_column_value       => x_curr_conv_rate,
2934                        p_error_message_name => 'INL_ERR_CURR_CONV_RT_NNULL',
2935                        x_return_status      => l_return_status);
2936                     -- If any errors happen abort API.
2937                     IF l_return_status = L_FND_RET_STS_ERROR THEN
2938                         RAISE L_FND_EXC_ERROR;
2939                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2940                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
2941                     END IF;
2942                 END IF;
2943                 IF p_curr_conv_date IS NOT NULL
2944                 THEN
2945                     l_debug_info := 'Currency Conversion Date should be null';
2946                     INL_LOGGING_PVT.Log_Statement(
2947                       p_module_name      => g_module_name,
2948                       p_procedure_name   => l_program_name,
2949                       p_debug_info       => l_debug_info);
2950                     l_response := L_FND_FALSE;
2951                     -- Add a line into inl_ship_errors
2952                     Handle_InterfError(
2953                        p_parent_table_name  => 'INL_SHIP_LINES_INT',
2954                        p_parent_table_id    => p_ship_line_int_id,
2955                        p_column_name        => 'CURRENCY_CONVERSION_DATE',
2956                        p_column_value       => p_curr_conv_date,
2957                        p_error_message_name => 'INL_ERR_CURR_CONV_DT_NNULL',
2958                        x_return_status      => l_return_status);
2959                     -- If any errors happen abort API.
2960                     IF l_return_status = L_FND_RET_STS_ERROR THEN
2961                         RAISE L_FND_EXC_ERROR;
2962                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2963                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
2964                     END IF;
2965                 END IF;
2966             ELSE --p_func_currency_code <> p_currency_code
2967                 IF p_curr_conv_date IS NULL
2968                 THEN
2969                     l_debug_info := 'Currency Conversion Date should not be null';
2970                     INL_LOGGING_PVT.Log_Statement(
2971                       p_module_name      => g_module_name,
2972                       p_procedure_name   => l_program_name,
2973                       p_debug_info       => l_debug_info);
2974                     l_response := L_FND_FALSE;
2975                     -- Add a line into inl_ship_errors
2976                     Handle_InterfError(
2977                        p_parent_table_name  => 'INL_SHIP_LINES_INT',
2978                        p_parent_table_id    => p_ship_line_int_id,
2979                        p_column_name        => 'CURRENCY_CONVERSION_DATE',
2980                        p_column_value       => p_curr_conv_date,
2981                        p_error_message_name => 'INL_ERR_CURR_CONV_DT_NULL',
2982                        x_return_status      => l_return_status);
2983                     -- If any errors happen abort API.
2984                     IF l_return_status = L_FND_RET_STS_ERROR THEN
2985                         RAISE L_FND_EXC_ERROR;
2986                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
2987                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
2988                     END IF;
2989                 END IF;
2990                 IF x_curr_conv_rate IS NULL
2991                 THEN
2992                     l_debug_info := 'Currency Conversion Rate should not be null';
2993                     INL_LOGGING_PVT.Log_Statement(
2994                       p_module_name      => g_module_name,
2995                       p_procedure_name   => l_program_name,
2996                       p_debug_info       => l_debug_info);
2997                     l_response := L_FND_FALSE;
2998                     -- Add a line into inl_ship_errors
2999                     Handle_InterfError(
3000                        p_parent_table_name  => 'INL_SHIP_LINES_INT',
3001                        p_parent_table_id    => p_ship_line_int_id,
3002                        p_column_name        => 'CURRENCY_CONVERSION_RATE',
3003                        p_column_value       => x_curr_conv_rate,
3004                        p_error_message_name => 'INL_ERR_CURR_CONV_RT_NULL',
3005                        x_return_status      => l_return_status);
3006                     -- If any errors happen abort API.
3007                     IF l_return_status = L_FND_RET_STS_ERROR THEN
3008                         RAISE L_FND_EXC_ERROR;
3009                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
3010                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
3011                     END IF;
3012                 END IF;
3013                 IF p_curr_conv_type IS NULL
3014                 THEN
3015                     l_debug_info := 'Currency Conversion Type should not be null';
3016                     INL_LOGGING_PVT.Log_Statement(
3017                       p_module_name      => g_module_name,
3018                       p_procedure_name   => l_program_name,
3019                       p_debug_info       => l_debug_info);
3020                     l_response := L_FND_FALSE;
3021                     -- Add a line into inl_ship_errors
3022                     Handle_InterfError(
3023                        p_parent_table_name  => 'INL_SHIP_LINES_INT',
3024                        p_parent_table_id    => p_ship_line_int_id,
3025                        p_column_name        => 'CURRENCY_CONVERSION_TYPE',
3026                        p_column_value       => p_curr_conv_type,
3027                        p_error_message_name => 'INL_ERR_CURR_CONV_TP_NULL',
3028                        x_return_status      => l_return_status);
3029                     -- If any errors happen abort API.
3030                     IF l_return_status = L_FND_RET_STS_ERROR THEN
3031                         RAISE L_FND_EXC_ERROR;
3032                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
3033                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
3034                     END IF;
3035                 ELSE
3036                     l_debug_info := 'Checking conversion type';
3037                     INL_LOGGING_PVT.Log_Statement(
3038                       p_module_name      => g_module_name,
3039                       p_procedure_name   => l_program_name,
3040                       p_debug_info       => l_debug_info);
3041                     SELECT COUNT(1)
3042                     INTO  l_count_conv_tp_valid
3043                     FROM  gl_daily_conversion_types dct
3044                     WHERE dct.conversion_type = p_curr_conv_type;
3045 
3046                     IF NVL(l_count_conv_tp_valid, 0) = 0 THEN
3047                        l_debug_info := 'Currency Conversion Type is invalid';
3048                        INL_LOGGING_PVT.Log_Statement(
3049                         p_module_name      => g_module_name,
3050                         p_procedure_name   => l_program_name,
3051                         p_debug_info       => l_debug_info);
3052                         l_response := L_FND_FALSE;
3053                         -- Add a line into inl_ship_errors
3054                         Handle_InterfError(
3055                             p_parent_table_name  => 'INL_SHIP_LINES_INT',
3056                             p_parent_table_id    => p_ship_line_int_id,
3057                             p_column_name        => 'CURRENCY_CONVERSION_TYPE',
3058                             p_column_value       => p_curr_conv_type,
3059                             p_error_message_name => 'INL_ERR_CURR_CONV_TP_INV',
3060                             x_return_status      => l_return_status);
3061                          -- If any errors happen abort API.
3062                          IF l_return_status = L_FND_RET_STS_ERROR THEN
3063                             RAISE L_FND_EXC_ERROR;
3064                         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
3065                             RAISE L_FND_EXC_UNEXPECTED_ERROR;
3066                         END IF;
3067                     END IF;
3068                 END IF;
3069             END IF;
3070         END IF;
3071     END IF;
3072 
3073 
3074     IF l_func_currency_code <> p_currency_code
3075         AND l_response = L_FND_TRUE
3076     THEN
3077         IF p_curr_conv_type <> 'User' THEN
3078         l_debug_info := 'Conversion Type <> User, derive rate from currency code, type and dated';
3079         INL_LOGGING_PVT.Log_Statement(
3080             p_module_name      => g_module_name,
3081             p_procedure_name   => l_program_name,
3082             p_debug_info       => l_debug_info );
3083             -- Derive rate from code, type and date
3084             BEGIN
3085                 SELECT conversion_rate
3086                 INTO x_curr_conv_rate
3087                 FROM gl_daily_rates
3088                 WHERE from_currency = p_currency_code
3089                 AND to_currency = l_func_currency_code
3090                 AND conversion_type = p_curr_conv_type
3091                 AND TRUNC(conversion_date) = TRUNC(p_curr_conv_date);
3092             EXCEPTION
3093                 WHEN NO_DATA_FOUND THEN
3094                 l_debug_info := 'No rate has been defined for the selected rate type and rate date';
3095                 INL_LOGGING_PVT.Log_Statement(
3096                   p_module_name      => g_module_name,
3097                   p_procedure_name   => l_program_name,
3098                   p_debug_info       => l_debug_info);
3099                 l_response := L_FND_FALSE;
3100                 -- Add a line into inl_ship_errors
3101                 Handle_InterfError(
3102                    p_parent_table_name  => 'INL_SHIP_LINES_INT',
3103                    p_parent_table_id    => p_ship_line_int_id,
3104                    p_column_name        => 'CURRENCY_CONVERSION_RATE',
3105                    p_column_value       => x_curr_conv_rate,
3106                    p_error_message_name => 'INL_NO_RATE_DEFINED',
3107                    x_return_status      => l_return_status);
3108                  -- If any errors happen abort API.
3109                  IF l_return_status = L_FND_RET_STS_ERROR THEN
3110                     RAISE L_FND_EXC_ERROR;
3111                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
3112                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
3113                  END IF;
3114             END;
3115         END IF;
3116     END IF;
3117     -- Standard End of Procedure/Function Logging
3118     INL_LOGGING_PVT.Log_EndProc(
3119         p_module_name    => g_module_name,
3120         p_procedure_name => l_program_name);
3121     RETURN FND_API.to_boolean(l_response) ;
3122 EXCEPTION
3123     WHEN L_FND_EXC_ERROR THEN
3124         -- Standard Expected Error Logging
3125         INL_LOGGING_PVT.Log_ExpecError (
3126             p_module_name    => g_module_name,
3127             p_procedure_name => l_program_name);
3128         RETURN FND_API.to_boolean(L_FND_FALSE) ;
3129     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
3130         -- Standard Unexpected Error Logging
3131         INL_LOGGING_PVT.Log_UnexpecError (
3132             p_module_name    => g_module_name,
3133             p_procedure_name => l_program_name);
3134         RETURN FND_API.to_boolean(L_FND_FALSE);
3135     WHEN OTHERS THEN
3136         -- Standard Unexpected Error Logging
3137         INL_LOGGING_PVT.Log_UnexpecError (
3138             p_module_name    => g_module_name,
3139             p_procedure_name => l_program_name);
3140         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
3141         IF FND_MSG_PUB.Check_Msg_Level(
3142             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
3143         ) THEN
3144             FND_MSG_PUB.Add_Exc_Msg(
3145                 p_pkg_name       => g_pkg_name,
3146                 p_procedure_name => l_program_name);
3147         END IF;
3148 END Validate_Currency;
3149 
3150 -- Utility name   : Validate_InvItemId
3151 -- Type       : Private
3152 -- Function   : Inventory Item validation.
3153 --              Check if a given Location is valid
3154 --
3155 -- Pre-reqs   : None
3156 -- Parameters :
3157 -- IN         : p_ship_header_int_id IN NUMBER
3158 --              p_ship_line_int_id   IN NUMBER
3159 --              p_validation_flag    IN VARCHAR2
3160 --              p_organization_id    IN NUMBER
3161 --
3162 -- OUT        : x_inv_item_id        IN OUT NOCOPY NUMBER
3163 --              x_inv_item_name      IN OUT NOCOPY VARCHAR2
3164 --              x_return_status      IN OUT NOCOPY VARCHAR2
3165 --
3166 -- Version    : Current version 1.0
3167 --
3168 -- Notes      :
3169 FUNCTION Validate_InvItemId(
3170     p_ship_line_int_id   IN NUMBER,
3171     p_validation_flag    IN VARCHAR2,
3172     p_organization_id    IN NUMBER,
3173     x_inv_item_name      IN OUT NOCOPY VARCHAR2,
3174     x_inv_item_id        IN OUT NOCOPY NUMBER,
3175     x_return_status      OUT NOCOPY VARCHAR2
3176 ) RETURN BOOLEAN IS
3177     l_program_name      CONSTANT VARCHAR2(30) := 'Validate_InvItemId';
3178     l_debug_info     VARCHAR2(400) ;
3179     l_return_status  VARCHAR2(1) := L_FND_TRUE;
3180     l_column_name    VARCHAR2(30);
3181     l_column_value   VARCHAR2(30);
3182 
3183 BEGIN
3184     -- Standard Beginning of Procedure/Function Logging
3185     INL_LOGGING_PVT.Log_BeginProc(
3186         p_module_name    => g_module_name,
3187         p_procedure_name => l_program_name) ;
3188     --  Initialize API return status to success
3189     x_return_status := L_FND_RET_STS_SUCCESS;
3190 
3191     INL_LOGGING_PVT.Log_Variable(
3192         p_module_name    => g_module_name,
3193         p_procedure_name => l_program_name,
3194         p_var_name       => 'x_inv_item_id',
3195         p_var_value      => x_inv_item_id) ;
3196     INL_LOGGING_PVT.Log_Variable(
3197         p_module_name    => g_module_name,
3198         p_procedure_name => l_program_name,
3199         p_var_name       => 'x_inv_item_name',
3200         p_var_value      => x_inv_item_name);
3201     INL_LOGGING_PVT.Log_Variable(
3202         p_module_name    => g_module_name,
3203         p_procedure_name => l_program_name,
3204         p_var_name       => 'p_ship_line_int_id',
3205         p_var_value      => p_ship_line_int_id);
3206     INL_LOGGING_PVT.Log_Variable(
3207         p_module_name    => g_module_name,
3208         p_procedure_name => l_program_name,
3209         p_var_name       => 'p_organization_id',
3210         p_var_value      => p_organization_id);
3211     INL_LOGGING_PVT.Log_Variable(
3212         p_module_name    => g_module_name,
3213         p_procedure_name => l_program_name,
3214         p_var_name       => 'p_validation_flag',
3215         p_var_value      => p_validation_flag);
3216 
3217     IF p_validation_flag = 'N'
3218         AND x_inv_item_id IS NOT NULL
3219     THEN
3220         l_debug_info := 'Validation is not required for Inventory Item';
3221         INL_LOGGING_PVT.Log_Statement(
3222             p_module_name      => g_module_name,
3223             p_procedure_name   => l_program_name,
3224             p_debug_info       => l_debug_info);
3225         x_inv_item_name := NULL;
3226     ELSE
3227         l_debug_info := 'Checking Inventory Item';
3228         INL_LOGGING_PVT.Log_Statement(
3229             p_module_name      => g_module_name,
3230             p_procedure_name   => l_program_name,
3231             p_debug_info       => l_debug_info);
3232         IF x_inv_item_name IS NOT NULL THEN
3233             l_column_name  := 'INVENTORY_ITEM_NAME';
3234             l_column_value := x_inv_item_name;
3235         ELSE
3236             l_column_name  := 'INVENTORY_ITEM_ID';
3237             l_column_value := x_inv_item_id;
3238         END IF;
3239 
3240         SELECT
3241             msi.inventory_item_id,
3242             msi.concatenated_segments
3243         INTO x_inv_item_id,
3244              x_inv_item_name
3245         FROM mtl_system_items_kfv msi
3246         WHERE msi.organization_id = p_organization_id
3247         AND (
3248             (x_inv_item_id IS NOT NULL
3249              AND msi.inventory_item_id = x_inv_item_id)
3250              OR msi.concatenated_segments = x_inv_item_name)
3251         ;
3252     END IF;
3253 
3254     -- Standard End of Procedure/Function Logging
3255     INL_LOGGING_PVT.Log_EndProc(
3256         p_module_name    => g_module_name,
3257         p_procedure_name => l_program_name);
3258     RETURN FND_API.to_boolean(L_FND_TRUE) ;
3259 EXCEPTION
3260     WHEN L_FND_EXC_ERROR THEN
3261         -- Standard Expected Error Logging
3262         INL_LOGGING_PVT.Log_ExpecError (
3263             p_module_name    => g_module_name,
3264             p_procedure_name => l_program_name);
3265         RETURN FND_API.to_boolean(L_FND_FALSE) ;
3266     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
3267         -- Standard Unexpected Error Logging
3268         INL_LOGGING_PVT.Log_UnexpecError (
3269             p_module_name    => g_module_name,
3270             p_procedure_name => l_program_name);
3271         RETURN FND_API.to_boolean(L_FND_FALSE);
3272     WHEN OTHERS THEN
3273         -- Add a line into inl_ship_errors
3274         Handle_InterfError(
3275             p_parent_table_name  => 'INL_SHIP_LINES_INT',
3276             p_parent_table_id    => p_ship_line_int_id,
3277             p_column_name        => l_column_name,
3278             p_column_value       => l_column_value,
3279             p_error_message_name => 'INL_ERR_INV_ITEM_INV',
3280             x_return_status      => l_return_status);
3281 
3282         -- If any errors happen abort API.
3283         IF l_return_status = L_FND_RET_STS_ERROR THEN
3284             RAISE L_FND_EXC_ERROR;
3285         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
3286             RAISE L_FND_EXC_UNEXPECTED_ERROR;
3287         END IF;
3288         RETURN FND_API.to_boolean(L_FND_FALSE);
3289 END Validate_InvItemId;
3290 
3291 -- Utility name   : Validate_TxnUomCode
3292 -- Type       : Private
3293 -- Function   : Transaction Uom Code validation if required.
3294 --
3295 --
3296 -- Pre-reqs   : None
3297 -- Parameters :
3298 -- IN         : p_ship_line_int_id   IN NUMBER
3299 --              p_txn_uom_code       IN VARCHAR2
3300 --
3301 -- OUT        : x_return_status      IN OUT NOCOPY VARCHAR2
3302 --
3303 -- Version    : Current version 1.0
3304 --
3305 -- Notes      :
3306 FUNCTION Validate_TxnUomCode(
3307     p_ship_line_int_id   IN NUMBER,
3308     p_txn_uom_code       IN VARCHAR2,
3309     x_return_status      OUT NOCOPY VARCHAR2
3310 ) RETURN BOOLEAN IS
3311     l_program_name           CONSTANT VARCHAR2(30) := 'Validate_TxnUomCode';
3312     l_debug_info          VARCHAR2(400) ;
3313     l_result              VARCHAR2(1) := L_FND_TRUE;
3314     l_return_status       VARCHAR2(1) := L_FND_TRUE;
3315     l_count_txn_uom_valid NUMBER;
3316 
3317 BEGIN
3318     -- Standard Beginning of Procedure/Function Logging
3319     INL_LOGGING_PVT.Log_BeginProc(
3320         p_module_name    => g_module_name,
3321         p_procedure_name => l_program_name) ;
3322     --  Initialize API return status to success
3323     x_return_status := L_FND_RET_STS_SUCCESS;
3324 
3325     -- Check if the Location is null
3326     l_debug_info := 'Validate Txn Uom Code if required';
3327     INL_LOGGING_PVT.Log_Statement(
3328         p_module_name      => g_module_name,
3329         p_procedure_name   => l_program_name,
3330         p_debug_info       => l_debug_info);
3331 
3332     INL_LOGGING_PVT.Log_Variable(
3333         p_module_name    => g_module_name,
3334         p_procedure_name => l_program_name,
3335         p_var_name       => 'p_txn_uom_code',
3336         p_var_value      => p_txn_uom_code) ;
3337     INL_LOGGING_PVT.Log_Variable(
3338         p_module_name    => g_module_name,
3339         p_procedure_name => l_program_name,
3340         p_var_name       => 'p_ship_line_int_id',
3341         p_var_value      => p_ship_line_int_id) ;
3342 
3343     SELECT COUNT(1)
3344     INTO  l_count_txn_uom_valid
3345     FROM  mtl_units_of_measure mum
3346     WHERE mum.uom_code = p_txn_uom_code;
3347 
3348     IF NVL(l_count_txn_uom_valid, 0) = 0 THEN
3349         l_debug_info := 'Transaction Uom Code is invalid';
3350         INL_LOGGING_PVT.Log_Statement(
3351           p_module_name      => g_module_name,
3352           p_procedure_name   => l_program_name,
3353           p_debug_info       => l_debug_info);
3354         l_result := L_FND_FALSE;
3355         -- Add a line into inl_ship_errors
3356         Handle_InterfError(
3357            p_parent_table_name  => 'INL_SHIP_LINES_INT',
3358            p_parent_table_id    => p_ship_line_int_id,
3359            p_column_name        => 'TXN_UOM_CODE',
3360            p_column_value       => p_txn_uom_code,
3361            p_error_message_name => 'INL_ERR_UOM_CODE_INV',
3362            x_return_status      => l_return_status);
3363          -- If any errors happen abort API.
3364          IF l_return_status = L_FND_RET_STS_ERROR THEN
3365             RAISE L_FND_EXC_ERROR;
3366          ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
3367             RAISE L_FND_EXC_UNEXPECTED_ERROR;
3368          END IF;
3369     END IF;
3370     -- Standard End of Procedure/Function Logging
3371     INL_LOGGING_PVT.Log_EndProc(
3372         p_module_name    => g_module_name,
3373         p_procedure_name => l_program_name);
3374     RETURN FND_API.to_boolean(l_result) ;
3375 EXCEPTION
3376     WHEN L_FND_EXC_ERROR THEN
3377         -- Standard Expected Error Logging
3378         INL_LOGGING_PVT.Log_ExpecError (
3379             p_module_name    => g_module_name,
3380             p_procedure_name => l_program_name);
3381         RETURN FND_API.to_boolean(L_FND_FALSE) ;
3382     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
3383         -- Standard Unexpected Error Logging
3384         INL_LOGGING_PVT.Log_UnexpecError (
3385             p_module_name    => g_module_name,
3386             p_procedure_name => l_program_name);
3387         RETURN FND_API.to_boolean(L_FND_FALSE) ;
3388     WHEN OTHERS THEN
3389         -- Standard Unexpected Error Logging
3390         INL_LOGGING_PVT.Log_UnexpecError (
3391             p_module_name    => g_module_name,
3392             p_procedure_name => l_program_name);
3393         IF FND_MSG_PUB.Check_Msg_Level(
3394             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
3395         ) THEN
3396             FND_MSG_PUB.Add_Exc_Msg(
3397                 p_pkg_name       => g_pkg_name,
3398                 p_procedure_name => l_program_name);
3399         END IF;
3400         RETURN FND_API.to_boolean(L_FND_FALSE) ;
3401 END Validate_TxnUomCode;
3402 
3403 -- Utility name   : Validate_PriSecFields
3404 -- Type       : Private
3405 -- Function   : Derive Primary fields
3406 --
3407 --
3408 -- Pre-reqs   : None
3409 -- Parameters :
3410 -- IN         : p_ship_header_int_id    IN NUMBER
3411 --              p_ship_line_int_id      IN NUMBER
3412 --              p_validation_flag       IN VARCHAR2
3413 --              p_organization_id       IN NUMBER
3414 --              p_inventory_item_id     IN NUMBER
3415 --              p_txn_uom_code          IN VARCHAR2
3416 --              p_txn_qty               IN NUMBER
3417 --              p_txn_unit_price        IN NUMBER
3418 --              p_ship_line_id          IN NUMBER
3419 --              p_interface_source_code IN VARCHAR2
3420 --              p_interface_source_line_id IN NUMBER
3421 --
3422 -- OUT        : x_1ary_uom_code      IN OUT NOCOPY VARCHAR2
3423 --             x_1ary_qty           IN OUT NOCOPY NUMBER
3424 --             x_1ary_unit_price    IN OUT NOCOPY NUMBER
3425 --             x_2ary_uom_code      IN OUT NOCOPY VARCHAR2
3426 --             x_2ary_qty           IN OUT NOCOPY NUMBER
3427 --             x_2ary_unit_price    IN OUT NOCOPY NUMBER
3428 --             x_return_status      OUT NOCOPY VARCHAR2
3429 --
3430 -- Version    : Current version 1.0
3431 --
3432 -- Notes      :
3433 FUNCTION Validate_PriSecFields(
3434     p_ship_line_int_id         IN NUMBER,
3435     p_validation_flag          IN VARCHAR2,
3436     p_organization_id          IN NUMBER,
3437     p_inventory_item_id        IN NUMBER,
3438     p_txn_uom_code             IN VARCHAR2,
3439     p_txn_qty                  IN NUMBER,
3440     p_txn_unit_price           IN NUMBER,
3441     p_ship_line_id             IN NUMBER,
3442     p_interface_source_code    IN VARCHAR2,
3443     p_interface_source_line_id IN NUMBER,    -- Bug 11710754
3444     x_1ary_uom_code            IN OUT NOCOPY VARCHAR2,
3445     x_1ary_qty                 IN OUT NOCOPY NUMBER,
3446     x_1ary_unit_price          IN OUT NOCOPY NUMBER,
3447     x_2ary_uom_code            IN OUT NOCOPY VARCHAR2,
3448     x_2ary_qty                 IN OUT NOCOPY NUMBER,
3449     x_2ary_unit_price          IN OUT NOCOPY NUMBER,
3450     x_return_status               OUT NOCOPY VARCHAR2
3451 ) RETURN BOOLEAN IS
3452     l_program_name           CONSTANT VARCHAR2(30) := 'Validate_PriSecFields';
3453     l_debug_info          VARCHAR2(400) ;
3454     l_result              VARCHAR2(1) := L_FND_TRUE;
3455     l_return_status       VARCHAR2(1) := L_FND_TRUE;
3456     l_count_txn_uom_valid NUMBER;
3457     l_1ary_uom_code       VARCHAR2(3);
3458     l_1ary_qty            NUMBER;
3459     l_2ary_uom_code       VARCHAR2(3);
3460     l_2ary_qty            NUMBER;
3461     l_msg_count           NUMBER;
3462     l_msg_data            VARCHAR2(2000) ;
3463     l_count_2ary_uom_vld  VARCHAR2(3);
3464     l_inventory_item_id   NUMBER       := p_inventory_item_id;
3465     l_txn_uom_code        VARCHAR2(30) := p_txn_uom_code;
3466     l_txn_qty             NUMBER       := p_txn_qty;
3467     l_txn_unit_price      NUMBER       := p_txn_unit_price;
3468     l_rcv_uom_code        VARCHAR2(3);   -- Bug 11710754
3469     l_po_uom_code         VARCHAR2(25);  -- Bug 11710754
3470     l_po_unit_price       NUMBER;        -- Bug 11710754
3471 BEGIN
3472     -- Standard Beginning of Procedure/Function Logging
3473     INL_LOGGING_PVT.Log_BeginProc(
3474         p_module_name    => g_module_name,
3475         p_procedure_name => l_program_name) ;
3476     --  Initialize API return status to success
3477     x_return_status := L_FND_RET_STS_SUCCESS;
3478 
3479     l_debug_info := 'Derive Primary and secondary fields if required';
3480     INL_LOGGING_PVT.Log_Statement(
3481         p_module_name      => g_module_name,
3482         p_procedure_name   => l_program_name,
3483         p_debug_info       => l_debug_info);
3484 
3485     INL_LOGGING_PVT.Log_Variable(
3486         p_module_name    => g_module_name,
3487         p_procedure_name => l_program_name,
3488         p_var_name       => 'p_ship_line_int_id',
3489         p_var_value      => p_ship_line_int_id) ;
3490 
3491     INL_LOGGING_PVT.Log_Variable(
3492         p_module_name    => g_module_name,
3493         p_procedure_name => l_program_name,
3494         p_var_name       => 'p_validation_flag',
3495         p_var_value      => p_validation_flag) ;
3496 
3497     INL_LOGGING_PVT.Log_Variable(
3498         p_module_name    => g_module_name,
3499         p_procedure_name => l_program_name,
3500         p_var_name       => 'p_organization_id',
3501         p_var_value      => p_organization_id) ;
3502 
3503     INL_LOGGING_PVT.Log_Variable(
3504         p_module_name    => g_module_name,
3505         p_procedure_name => l_program_name,
3506         p_var_name       => 'p_inventory_item_id',
3507         p_var_value      => p_inventory_item_id) ;
3508 
3509     INL_LOGGING_PVT.Log_Variable(
3510         p_module_name    => g_module_name,
3511         p_procedure_name => l_program_name,
3512         p_var_name       => 'p_txn_uom_code',
3513         p_var_value      => p_txn_uom_code) ;
3514 
3515     INL_LOGGING_PVT.Log_Variable(
3516         p_module_name    => g_module_name,
3517         p_procedure_name => l_program_name,
3518         p_var_name       => 'p_txn_qty',
3519         p_var_value      => p_txn_qty) ;
3520 
3521     INL_LOGGING_PVT.Log_Variable(
3522         p_module_name    => g_module_name,
3523         p_procedure_name => l_program_name,
3524         p_var_name       => 'p_txn_unit_price',
3525         p_var_value      => p_txn_unit_price) ;
3526 
3527     INL_LOGGING_PVT.Log_Variable(
3528         p_module_name    => g_module_name,
3529         p_procedure_name => l_program_name,
3530         p_var_name       => 'p_ship_line_id',
3531         p_var_value      => p_ship_line_id) ;
3532 
3533     INL_LOGGING_PVT.Log_Variable(
3534         p_module_name    => g_module_name,
3535         p_procedure_name => l_program_name,
3536         p_var_name       => 'p_interface_source_code',
3537         p_var_value      => p_interface_source_code) ;
3538 
3539     INL_LOGGING_PVT.Log_Variable(
3540         p_module_name    => g_module_name,
3541         p_procedure_name => l_program_name,
3542         p_var_name       => 'p_interface_source_line_id',
3543         p_var_value      => p_interface_source_line_id) ;
3544 
3545     INL_LOGGING_PVT.Log_Variable(
3546         p_module_name    => g_module_name,
3547         p_procedure_name => l_program_name,
3548         p_var_name       => 'x_1ary_uom_code',
3549         p_var_value      => x_1ary_uom_code) ;
3550 
3551     INL_LOGGING_PVT.Log_Variable(
3552         p_module_name    => g_module_name,
3553         p_procedure_name => l_program_name,
3554         p_var_name       => 'x_1ary_qty',
3555         p_var_value      => x_1ary_qty) ;
3556 
3557     INL_LOGGING_PVT.Log_Variable(
3558         p_module_name    => g_module_name,
3559         p_procedure_name => l_program_name,
3560         p_var_name       => 'x_1ary_unit_price',
3561         p_var_value      => x_1ary_unit_price) ;
3562 
3563     IF (p_ship_line_id IS NOT NULL)
3564         AND
3565        (p_inventory_item_id IS NULL
3566         OR l_txn_uom_code IS NULL
3567         OR l_txn_qty IS NULL
3568         OR l_txn_unit_price IS NULL)
3569     THEN
3570         l_debug_info := 'Inventory Item IS NULL, getting from ship line';
3571         INL_LOGGING_PVT.Log_Statement(
3572             p_module_name      => g_module_name,
3573             p_procedure_name   => l_program_name,
3574             p_debug_info       => l_debug_info);
3575 
3576         SELECT NVL(l_inventory_item_id, sl.inventory_item_id),
3577                NVL(l_txn_uom_code, sl.txn_uom_code),
3578                NVL(l_txn_qty, sl.txn_qty),
3579                NVL(l_txn_unit_price, sl.txn_unit_price)
3580         INTO l_inventory_item_id,
3581              l_txn_uom_code,
3582              l_txn_qty,
3583              l_txn_unit_price
3584         FROM  inl_ship_lines_all sl  --Bug#10381495
3585         WHERE sl.ship_line_id = p_ship_line_id;
3586     END IF;
3587 
3588     INL_LOGGING_PVT.Log_Variable(
3589         p_module_name    => g_module_name,
3590         p_procedure_name => l_program_name,
3591         p_var_name       => 'l_inventory_item_id',
3592         p_var_value      => l_inventory_item_id) ;
3593 
3594     INL_LOGGING_PVT.Log_Variable(
3595         p_module_name    => g_module_name,
3596         p_procedure_name => l_program_name,
3597         p_var_name       => 'l_txn_uom_code',
3598         p_var_value      => l_txn_uom_code) ;
3599 
3600     INL_LOGGING_PVT.Log_Variable(
3601         p_module_name    => g_module_name,
3602         p_procedure_name => l_program_name,
3603         p_var_name       => 'l_txn_qty',
3604         p_var_value      => l_txn_qty) ;
3605 
3606     INL_LOGGING_PVT.Log_Variable(
3607         p_module_name    => g_module_name,
3608         p_procedure_name => l_program_name,
3609         p_var_name       => 'l_txn_unit_price',
3610         p_var_value      => l_txn_unit_price) ;
3611 
3612     IF l_inventory_item_id IS NOT NULL
3613        AND p_organization_id IS NOT NULL
3614        AND l_txn_uom_code IS NOT NULL THEN
3615         l_debug_info := 'Derive Primary and Secondary Fields';
3616         INL_LOGGING_PVT.Log_Statement(
3617             p_module_name      => g_module_name,
3618             p_procedure_name   => l_program_name,
3619             p_debug_info       => l_debug_info);
3620 
3621         INL_SHIPMENT_PVT.Get_1ary2aryQty(
3622             p_api_version       => 1.0,
3623             p_init_msg_list     => L_FND_FALSE,
3624             p_commit            => L_FND_FALSE,
3625             p_inventory_item_id => l_inventory_item_id,
3626             p_organization_id   => p_organization_id,
3627             p_uom_code          => l_txn_uom_code,
3628             p_qty               => NVL(l_txn_qty,0),
3629             x_1ary_uom_code     => l_1ary_uom_code,
3630             x_1ary_qty          => l_1ary_qty,
3631             x_2ary_uom_code     => l_2ary_uom_code,
3632             x_2ary_qty          => l_2ary_qty,
3633             x_return_status     => l_return_status,
3634             x_msg_count         => l_msg_count,
3635             x_msg_data          => l_msg_data
3636         ) ;
3637 
3638         IF l_return_status <> 'S' THEN
3639             l_debug_info := 'Error when converting txn uom code: ' || l_txn_uom_code;
3640             INL_LOGGING_PVT.Log_Statement(
3641                 p_module_name      => g_module_name,
3642                 p_procedure_name   => l_program_name,
3643                 p_debug_info       => l_debug_info);
3644 
3645             INL_LOGGING_PVT.Log_Variable(
3646                 p_module_name    => g_module_name,
3647                 p_procedure_name => l_program_name,
3648                 p_var_name       => 'l_return_status',
3649                 p_var_value      => l_return_status) ;
3650 
3651             l_result := L_FND_FALSE;
3652             -- Add a line into inl_ship_errors
3653             Handle_InterfError(
3654                p_parent_table_name  => 'INL_SHIP_LINES_INT',
3655                p_parent_table_id    => p_ship_line_int_id,
3656                p_column_name        => 'TXN_UOM_CODE',
3657                p_column_value       => l_txn_uom_code,
3658                p_error_message_name => 'INL_ERR_DERIVE_PRI_SEC_FLDS',
3659                p_token1_name        => 'TXN_UOM_CODE',
3660                p_token1_value       => l_txn_uom_code,
3661                x_return_status      => l_return_status);
3662              -- If any errors happen abort API.
3663              IF l_return_status = L_FND_RET_STS_ERROR THEN
3664                 RAISE L_FND_EXC_ERROR;
3665             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
3666                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
3667              END IF;
3668             RAISE L_FND_EXC_ERROR;
3669         END IF;
3670 
3671         -- If any errors happen abort the process.
3672         IF l_return_status = L_FND_RET_STS_ERROR THEN
3673             l_debug_info := 'Error when deriving primary and secondary fields for txn uom code: ' || l_txn_uom_code;
3674         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
3675             RAISE L_FND_EXC_UNEXPECTED_ERROR;
3676         END IF;
3677 
3678         INL_LOGGING_PVT.Log_Variable(
3679             p_module_name    => g_module_name,
3680             p_procedure_name => l_program_name,
3681             p_var_name       => 'l_1ary_uom_code',
3682             p_var_value      => l_1ary_uom_code) ;
3683 
3684         INL_LOGGING_PVT.Log_Variable(
3685             p_module_name    => g_module_name,
3686             p_procedure_name => l_program_name,
3687             p_var_name       => 'l_1ary_qty',
3688             p_var_value      => l_1ary_qty) ;
3689 
3690         INL_LOGGING_PVT.Log_Variable(
3691             p_module_name    => g_module_name,
3692             p_procedure_name => l_program_name,
3693             p_var_name       => 'l_2ary_uom_code',
3694             p_var_value      => l_2ary_uom_code) ;
3695 
3696         INL_LOGGING_PVT.Log_Variable(
3697             p_module_name    => g_module_name,
3698             p_procedure_name => l_program_name,
3699             p_var_name       => 'l_2ary_qty',
3700             p_var_value      => l_2ary_qty) ;
3701 
3702         IF l_1ary_uom_code IS NOT NULL THEN
3703             x_1ary_qty      := l_1ary_qty;
3704             x_1ary_uom_code := l_1ary_uom_code;
3705 
3706             -- Bug 11710754
3707             -- x_1ary_unit_price := (l_txn_qty * l_txn_unit_price) / x_1ary_qty;
3708             IF p_interface_source_code = 'RCV' THEN
3709                 l_debug_info := 'source table is RCV_TRANSACTIONS_INTERFACE';
3710                 INL_LOGGING_PVT.Log_Statement(
3711                     p_module_name      => g_module_name,
3712                     p_procedure_name   => l_program_name,
3713                     p_debug_info       => l_debug_info);
3714 
3715                 SELECT rti.uom_code, muom.uom_code, pl.unit_price
3716                 INTO l_rcv_uom_code, l_po_uom_code, l_po_unit_price
3717                 FROM rcv_transactions_interface rti,
3718                     po_lines_all pl,
3719                     mtl_units_of_measure muom
3720                 WHERE  muom.unit_of_measure = pl.unit_meas_lookup_code
3721                 AND pl.po_line_id = rti.po_line_id
3722                 AND interface_transaction_id = p_interface_source_line_id;
3723 
3724                 INL_LOGGING_PVT.Log_Variable(
3725                     p_module_name    => g_module_name,
3726                     p_procedure_name => l_program_name,
3727                     p_var_name       => 'l_rcv_uom_code',
3728                     p_var_value      => l_rcv_uom_code);
3729 
3730                 INL_LOGGING_PVT.Log_Variable(
3731                     p_module_name    => g_module_name,
3732                     p_procedure_name => l_program_name,
3733                     p_var_name       => 'l_po_uom_code',
3734                     p_var_value      => l_po_uom_code);
3735 
3736                 INL_LOGGING_PVT.Log_Variable(
3737                     p_module_name    => g_module_name,
3738                     p_procedure_name => l_program_name,
3739                     p_var_name       => 'l_po_unit_price',
3740                     p_var_value      => l_po_unit_price);
3741 
3742                 IF l_1ary_uom_code = l_rcv_uom_code THEN
3743                     l_debug_info := 'Item primary uom is equal RCV uom code';
3744                     x_1ary_unit_price := p_txn_unit_price;
3745                 ELSIF l_1ary_uom_code = l_po_uom_code THEN
3746                     l_debug_info := 'Item primary uom is equal PO uom code';
3747                     x_1ary_unit_price := l_po_unit_price;
3748                 ELSE
3749                     l_debug_info := 'PO primary uom should be converted to : ' || l_1ary_uom_code;
3750 
3751                     x_1ary_unit_price := INL_LANDEDCOST_PVT.Converted_Price(
3752                                        p_unit_price        => l_po_unit_price,
3753                                        p_organization_id   => p_organization_id,
3754                                        p_inventory_item_id => l_inventory_item_id, --Bug#11794483C
3755                                        p_from_uom_code     => l_po_uom_code,
3756                                        p_to_uom_code       => l_1ary_uom_code);
3757                 END IF;
3758 
3759                 INL_LOGGING_PVT.Log_Statement(
3760                     p_module_name      => g_module_name,
3761                     p_procedure_name   => l_program_name,
3762                     p_debug_info       => l_debug_info);
3763 
3764            ELSE
3765                 l_debug_info := 'Source is different from RCV_TRANSACTIONS_INTERFACE';
3766                 INL_LOGGING_PVT.Log_Statement(
3767                     p_module_name      => g_module_name,
3768                     p_procedure_name   => l_program_name,
3769                     p_debug_info       => l_debug_info);
3770 
3771                 IF l_1ary_uom_code = l_txn_uom_code
3772                 THEN
3773                     x_1ary_unit_price := l_txn_unit_price;
3774                 ELSE
3775                     x_1ary_unit_price :=
3776                             INL_LANDEDCOST_PVT.Converted_Price(
3777                                     p_unit_price        => l_txn_unit_price,
3778                                     p_organization_id   => p_organization_id,
3779                                     p_inventory_item_id => l_inventory_item_id, --Bug#11794483C
3780                                     p_from_uom_code     => l_txn_uom_code,
3781                                     p_to_uom_code       => l_1ary_uom_code);
3782                END IF;
3783            END IF;
3784            -- /Bug 11710754
3785 
3786             INL_LOGGING_PVT.Log_Variable(
3787                 p_module_name    => g_module_name,
3788                 p_procedure_name => l_program_name,
3789                 p_var_name       => 'x_1ary_unit_price',
3790                 p_var_value      => x_1ary_unit_price);
3791         END IF;
3792 
3793         -- Bug #8932386
3794         IF  x_2ary_uom_code IS NULL
3795         AND x_2ary_qty IS NULL
3796         AND x_2ary_unit_price IS NULL
3797         THEN
3798             l_debug_info := 'Secondary fields are null, then derivating them';
3799             INL_LOGGING_PVT.Log_Statement(
3800                 p_module_name      => g_module_name,
3801                 p_procedure_name   => l_program_name,
3802                 p_debug_info       => l_debug_info);
3803 
3804             INL_LOGGING_PVT.Log_Variable(
3805                 p_module_name    => g_module_name,
3806                 p_procedure_name => l_program_name,
3807                 p_var_name       => 'l_2ary_uom_code',
3808                 p_var_value      => l_2ary_uom_code);
3809 
3810             INL_LOGGING_PVT.Log_Variable(
3811                 p_module_name    => g_module_name,
3812                 p_procedure_name => l_program_name,
3813                 p_var_name       => 'l_2ary_qty',
3814                 p_var_value      => l_2ary_qty) ;
3815 
3816             IF l_2ary_uom_code IS NOT NULL AND p_interface_source_code <> 'RCV' THEN
3817 
3818                 l_debug_info := 'Derive secondary fields for interface source code <> RCV';
3819                 INL_LOGGING_PVT.Log_Statement(
3820                     p_module_name      => g_module_name,
3821                     p_procedure_name   => l_program_name,
3822                     p_debug_info       => l_debug_info);
3823 
3824                 x_2ary_qty := l_2ary_qty;
3825                 x_2ary_uom_code := l_2ary_uom_code;
3826                 x_2ary_unit_price := (l_txn_qty * l_txn_unit_price) / x_2ary_qty;
3827 
3828                 INL_LOGGING_PVT.Log_Variable(
3829                     p_module_name    => g_module_name,
3830                     p_procedure_name => l_program_name,
3831                     p_var_name       => 'x_2ary_unit_price',
3832                     p_var_value      => x_2ary_unit_price);
3833             END IF;
3834         ELSE
3835             IF p_validation_flag = 'Y' THEN
3836                 IF x_2ary_uom_code IS NULL OR x_2ary_qty IS NULL OR
3837                     x_2ary_unit_price IS NULL THEN
3838                     l_debug_info := 'If one of Secondary fields is populated, then all of them should be also populated';
3839                     INL_LOGGING_PVT.Log_Statement(
3840                         p_module_name      => g_module_name,
3841                         p_procedure_name   => l_program_name,
3842                         p_debug_info       => l_debug_info);
3843                     l_result := L_FND_FALSE;
3844                     -- Add a line into inl_ship_errors
3845                     Handle_InterfError(
3846                         p_parent_table_name  => 'INL_SHIP_LINES_INT',
3847                         p_parent_table_id    => p_ship_line_int_id,
3848                         p_column_name        => 'SECONDARY_UOM_CODE',
3849                         p_column_value       => x_2ary_uom_code,
3850                         p_error_message_name => 'INL_ERR_SEC_FLDS_NULL',
3851                         x_return_status      => l_return_status);
3852                     -- If any errors happen abort API.
3853                     IF l_return_status = L_FND_RET_STS_ERROR THEN
3854                         RAISE L_FND_EXC_ERROR;
3855                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
3856                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
3857                     END IF;
3858                 ELSIF x_2ary_uom_code IS NOT NULL AND x_2ary_qty IS NOT NULL AND
3859                       x_2ary_unit_price IS NOT NULL THEN
3860                     l_debug_info := 'Secondary Uom Code has been populated. Validating it';
3861                     INL_LOGGING_PVT.Log_Statement(
3862                         p_module_name      => g_module_name,
3863                         p_procedure_name   => l_program_name,
3864                         p_debug_info       => l_debug_info);
3865 
3866                     SELECT COUNT(1)
3867                     INTO  l_count_2ary_uom_vld
3868                     FROM  mtl_units_of_measure mum
3869                     WHERE mum.uom_code = x_2ary_uom_code;
3870 
3871                     IF NVL(l_count_2ary_uom_vld,0) = 0 THEN
3872                         l_debug_info := 'Secondary Uom Code populated is invalid';
3873                         INL_LOGGING_PVT.Log_Statement(
3874                             p_module_name      => g_module_name,
3875                             p_procedure_name   => l_program_name,
3876                             p_debug_info       => l_debug_info);
3877                             l_result := L_FND_FALSE;
3878                         -- Add a line into inl_ship_errors
3879                         Handle_InterfError(
3880                             p_parent_table_name  => 'INL_SHIP_LINES_INT',
3881                             p_parent_table_id    => p_ship_line_int_id,
3882                             p_column_name        => 'SECONDARY_UOM_CODE',
3883                             p_column_value       => x_2ary_uom_code,
3884                             p_error_message_name => 'INL_ERR_SEC_UOM_CODE_INV',
3885                             x_return_status      => l_return_status);
3886                         -- If any errors happen abort API.
3887                         IF l_return_status = L_FND_RET_STS_ERROR THEN
3888                             RAISE L_FND_EXC_ERROR;
3889                         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
3890                             RAISE L_FND_EXC_UNEXPECTED_ERROR;
3891                         END IF;
3892                     END IF;
3893                 END IF;
3894             END IF;
3895         END IF;
3896         -- /Bug #8932386
3897     END IF;
3898     -- Standard End of Procedure/Function Logging
3899     INL_LOGGING_PVT.Log_EndProc(
3900         p_module_name    => g_module_name,
3901         p_procedure_name => l_program_name);
3902     RETURN FND_API.to_boolean(l_result) ;
3903 EXCEPTION
3904     WHEN L_FND_EXC_ERROR THEN
3905         -- Standard Expected Error Logging
3906         x_return_status := L_FND_RET_STS_ERROR;
3907         INL_LOGGING_PVT.Log_ExpecError (
3908             p_module_name    => g_module_name,
3909             p_procedure_name => l_program_name);
3910         RETURN FND_API.to_boolean(L_FND_FALSE) ;
3911     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
3912         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
3913         -- Standard Unexpected Error Logging
3914         INL_LOGGING_PVT.Log_UnexpecError (
3915             p_module_name    => g_module_name,
3916             p_procedure_name => l_program_name);
3917         RETURN FND_API.to_boolean(L_FND_FALSE) ;
3918     WHEN OTHERS THEN
3919         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
3920         -- Standard Unexpected Error Logging
3921         INL_LOGGING_PVT.Log_UnexpecError (
3922             p_module_name    => g_module_name,
3923             p_procedure_name => l_program_name);
3924         IF FND_MSG_PUB.Check_Msg_Level(
3925             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
3926         ) THEN
3927             FND_MSG_PUB.Add_Exc_Msg(
3928                 p_pkg_name       => g_pkg_name,
3929                 p_procedure_name => l_program_name);
3930         END IF;
3931         RETURN FND_API.to_boolean(L_FND_FALSE) ;
3932 END Validate_PriSecFields;
3933 
3934 -- Utility name   : Validate_LandedCostFlag
3935 -- Type       : Private
3936 -- Function   : Validaye Landed Cost Flag if required
3937 --
3938 -- Pre-reqs   : None
3939 -- Parameters :
3940 -- IN         :     p_ship_line_int_id      IN NUMBER
3941 --                  p_landed_cost_flag      IN VARCHAR2
3942 --
3943 -- OUT        : x_return_status      OUT NOCOPY VARCHAR2
3944 --
3945 -- Version    : Current version 1.0
3946 --
3947 -- Notes      :
3948 FUNCTION Validate_LandedCostFlag(
3949     p_ship_line_int_id      IN NUMBER,
3950     p_landed_cost_flag      IN VARCHAR2,
3951     x_return_status         OUT NOCOPY VARCHAR2
3952 ) RETURN BOOLEAN IS
3953     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_LandedCostFlag';
3954     l_debug_info    VARCHAR2(400) ;
3955     l_result        VARCHAR2(1) := L_FND_TRUE;
3956     l_return_status VARCHAR2(1) := L_FND_TRUE;
3957 
3958 BEGIN
3959     -- Standard Beginning of Procedure/Function Logging
3960     INL_LOGGING_PVT.Log_BeginProc(
3961         p_module_name    => g_module_name,
3962         p_procedure_name => l_program_name) ;
3963     --  Initialize API return status to success
3964     x_return_status := L_FND_RET_STS_SUCCESS;
3965 
3966     l_debug_info := 'Validate Landed Cost Flag';
3967     INL_LOGGING_PVT.Log_Statement(
3968         p_module_name      => g_module_name,
3969         p_procedure_name   => l_program_name,
3970         p_debug_info       => l_debug_info);
3971 
3972     INL_LOGGING_PVT.Log_Variable(
3973         p_module_name    => g_module_name,
3974         p_procedure_name => l_program_name,
3975         p_var_name       => 'p_landed_cost_flag',
3976         p_var_value      => p_landed_cost_flag);
3977 
3978     l_debug_info := 'Validate Landed Cost Flag if required';
3979     INL_LOGGING_PVT.Log_Statement(
3980         p_module_name      => g_module_name,
3981         p_procedure_name   => l_program_name,
3982         p_debug_info       => l_debug_info) ;
3983 
3984     IF p_landed_cost_flag NOT IN ('Y', 'N') THEN
3985         l_debug_info := 'Landed Cost Flag should be Y or N';
3986         INL_LOGGING_PVT.Log_Statement(
3987             p_module_name      => g_module_name,
3988             p_procedure_name   => l_program_name,
3989             p_debug_info       => l_debug_info);
3990         l_result := L_FND_FALSE;
3991 
3992         -- Add a line into inl_ship_errors
3993         Handle_InterfError(
3994             p_parent_table_name  => 'INL_SHIP_LINES_INT',
3995             p_parent_table_id    => p_ship_line_int_id,
3996             p_column_name        => 'LANDED_COST_FLAG',
3997             p_column_value       => p_landed_cost_flag,
3998             p_error_message_name => 'INL_ERR_LC_FLAG_INV',
3999             x_return_status      => l_return_status);
4000         -- If any errors happen abort API.
4001         IF l_return_status = L_FND_RET_STS_ERROR THEN
4002             RAISE L_FND_EXC_ERROR;
4003         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
4004            RAISE L_FND_EXC_UNEXPECTED_ERROR;
4005         END IF;
4006     END IF;
4007 
4008     -- Standard End of Procedure/Function Logging
4009     INL_LOGGING_PVT.Log_EndProc(
4010         p_module_name    => g_module_name,
4011         p_procedure_name => l_program_name);
4012     RETURN FND_API.to_boolean(l_result) ;
4013 EXCEPTION
4014     WHEN L_FND_EXC_ERROR THEN
4015         -- Standard Expected Error Logging
4016         INL_LOGGING_PVT.Log_ExpecError (
4017             p_module_name    => g_module_name,
4018             p_procedure_name => l_program_name);
4019         RETURN FND_API.to_boolean(L_FND_FALSE) ;
4020     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
4021         -- Standard Unexpected Error Logging
4022         INL_LOGGING_PVT.Log_UnexpecError (
4023             p_module_name    => g_module_name,
4024             p_procedure_name => l_program_name);
4025         RETURN FND_API.to_boolean(L_FND_FALSE) ;
4026     WHEN OTHERS THEN
4027         -- Standard Unexpected Error Logging
4028         INL_LOGGING_PVT.Log_UnexpecError (
4029             p_module_name    => g_module_name,
4030             p_procedure_name => l_program_name);
4031         IF FND_MSG_PUB.Check_Msg_Level(
4032             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
4033         ) THEN
4034             FND_MSG_PUB.Add_Exc_Msg(
4035                 p_pkg_name       => g_pkg_name,
4036                 p_procedure_name => l_program_name);
4037         END IF;
4038         RETURN FND_API.to_boolean(L_FND_FALSE) ;
4039 END Validate_LandedCostFlag;
4040 
4041 -- Utility name   : Validate_AllocEnabledFlag
4042 -- Type       : Private
4043 -- Function   : Validate Allocation Enabled Flag if required
4044 --
4045 -- Pre-reqs   : None
4046 -- Parameters :
4047 -- IN         :     p_ship_line_int_id      IN NUMBER
4048 --                  p_alloc_enabled_flag    IN VARCHAR2
4049 --
4050 -- OUT        : x_return_status      OUT NOCOPY VARCHAR2
4051 --
4052 -- Version    : Current version 1.0
4053 --
4054 -- Notes      :
4055 FUNCTION Validate_AllocEnabledFlag(
4056     p_ship_line_int_id      IN NUMBER,
4057     p_alloc_enabled_flag    IN VARCHAR2,
4058     x_return_status         OUT NOCOPY VARCHAR2
4059 ) RETURN BOOLEAN IS
4060     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_AllocEnabledFlag';
4061     l_debug_info    VARCHAR2(400) ;
4062     l_result        VARCHAR2(1) := L_FND_TRUE;
4063     l_return_status VARCHAR2(1) := L_FND_TRUE;
4064 
4065 BEGIN
4066     -- Standard Beginning of Procedure/Function Logging
4067     INL_LOGGING_PVT.Log_BeginProc(
4068         p_module_name    => g_module_name,
4069         p_procedure_name => l_program_name) ;
4070     --  Initialize API return status to success
4071     x_return_status := L_FND_RET_STS_SUCCESS;
4072 
4073     l_debug_info := 'Validate Allocation Enabled Flag if required';
4074     INL_LOGGING_PVT.Log_Statement(
4075         p_module_name      => g_module_name,
4076         p_procedure_name   => l_program_name,
4077         p_debug_info       => l_debug_info) ;
4078 
4079     INL_LOGGING_PVT.Log_Variable(
4080         p_module_name    => g_module_name,
4081         p_procedure_name => l_program_name,
4082         p_var_name       => 'p_alloc_enabled_flag',
4083         p_var_value      => p_alloc_enabled_flag);
4084 
4085     IF p_alloc_enabled_flag NOT IN ('Y', 'N') THEN
4086         l_debug_info := 'Allocation Enabled Flag should be Y or N';
4087         INL_LOGGING_PVT.Log_Statement(
4088             p_module_name      => g_module_name,
4089             p_procedure_name   => l_program_name,
4090             p_debug_info       => l_debug_info);
4091         l_result := L_FND_FALSE;
4092 
4093         -- Add a line into inl_ship_errors
4094         Handle_InterfError(
4095             p_parent_table_name  => 'INL_SHIP_LINES_INT',
4096             p_parent_table_id    => p_ship_line_int_id,
4097             p_column_name        => 'ALLOCATION_ENABLED_FLAG',
4098             p_column_value       => p_alloc_enabled_flag,
4099             p_error_message_name => 'INL_ERR_ALLOC_ENABLED_INV',
4100             p_token1_name        => 'ID_NAME',
4101             p_token1_value       => 'INL_SHIP_LINES_INT',
4102             p_token2_name        => 'ID_VAL',
4103             p_token2_value       => p_ship_line_int_id,
4104             x_return_status      => l_return_status);
4105         -- If any errors happen abort API.
4106         IF l_return_status = L_FND_RET_STS_ERROR THEN
4107             RAISE L_FND_EXC_ERROR;
4108         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
4109            RAISE L_FND_EXC_UNEXPECTED_ERROR;
4110         END IF;
4111     END IF;
4112     -- Standard End of Procedure/Function Logging
4113     INL_LOGGING_PVT.Log_EndProc(
4114         p_module_name    => g_module_name,
4115         p_procedure_name => l_program_name);
4116     RETURN FND_API.to_boolean(l_result) ;
4117 EXCEPTION
4118     WHEN L_FND_EXC_ERROR THEN
4119         -- Standard Expected Error Logging
4120         INL_LOGGING_PVT.Log_ExpecError (
4121             p_module_name    => g_module_name,
4122             p_procedure_name => l_program_name);
4123         RETURN FND_API.to_boolean(L_FND_FALSE) ;
4124     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
4125         -- Standard Unexpected Error Logging
4126         INL_LOGGING_PVT.Log_UnexpecError (
4127             p_module_name    => g_module_name,
4128             p_procedure_name => l_program_name);
4129         RETURN FND_API.to_boolean(L_FND_FALSE) ;
4130     WHEN OTHERS THEN
4131         -- Standard Unexpected Error Logging
4132         INL_LOGGING_PVT.Log_UnexpecError (
4133             p_module_name    => g_module_name,
4134             p_procedure_name => l_program_name);
4135         IF FND_MSG_PUB.Check_Msg_Level(
4136             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
4137         ) THEN
4138             FND_MSG_PUB.Add_Exc_Msg(
4139                 p_pkg_name       => g_pkg_name,
4140                 p_procedure_name => l_program_name);
4141         END IF;
4142         RETURN FND_API.to_boolean(L_FND_FALSE) ;
4143 END Validate_AllocEnabledFlag;
4144 
4145 -- Utility name   : Validate_Organization
4146 -- Type       : Private
4147 -- Function   : Inventory Organization derivation
4148 --              Valid if required
4149 --              Get the org_id
4150 --
4151 -- Pre-reqs   : None
4152 -- Parameters :
4153 -- IN         : p_ship_header_int_id IN NUMBER
4154 --              p_validation_flag    IN VARCHAR2
4155 --              p_ship_header_id             IN NUMBER,
4156 
4157 --
4158 -- OUT        : x_organization_id            IN OUT NOCOPY NUMBER
4159 --              x_organization_code          IN OUT NOCOPY VARCHAR2
4160 --              x_org_id                     IN OUT NOCOPY NUMBER
4161 --              x_user_defined_ship_num_code IN OUT NOCOPY VARCHAR2,
4162 --              x_manual_ship_num_type       IN OUT NOCOPY VARCHAR2,
4163 --              x_LCM_FLOW                   IN OUT NOCOPY VARCHAR2,
4164 --              x_return_status              IN OUT NOCOPY VARCHAR2
4165 --
4166 -- Version    : Current version 1.0
4167 --
4168 -- Notes      :
4169 FUNCTION Validate_Organization(
4170     p_ship_header_int_id         IN NUMBER,
4171     p_validation_flag            IN VARCHAR2,
4172     p_ship_header_id             IN NUMBER,
4173     x_organization_id            IN OUT NOCOPY NUMBER,
4174     x_organization_code          IN OUT NOCOPY VARCHAR2,
4175     x_org_id                     IN OUT NOCOPY NUMBER,
4176     x_user_defined_ship_num_code IN OUT NOCOPY VARCHAR2,
4177     x_manual_ship_num_type       IN OUT NOCOPY VARCHAR2,
4178     x_LCM_FLOW                   IN OUT NOCOPY VARCHAR2,
4179     x_legal_entity_id            IN OUT NOCOPY NUMBER,
4180     x_return_status              OUT NOCOPY VARCHAR2
4181 ) RETURN BOOLEAN IS
4182 
4183     l_program_name              CONSTANT VARCHAR2(30) := 'Validate_Organization';
4184     l_debug_info             VARCHAR2(400) ;
4185     l_result                 VARCHAR2(1) := L_FND_TRUE;
4186     l_return_status          VARCHAR2(1) := L_FND_TRUE;
4187     l_msg_count              NUMBER;
4188     l_msg_data               VARCHAR2(2000) ;
4189     l_column_name            VARCHAR2(50);
4190     l_column_value           VARCHAR2(30);
4191     l_count_org_def_lcm      NUMBER;
4192 
4193 --    l_user_def_ship_num_code VARCHAR2(25); -- Bug #9198199
4194 --    l_count_lcm_as_service   NUMBER; -- Bug #9198199
4195 
4196 BEGIN
4197     -- Standard Beginning of Procedure/Function Logging
4198     INL_LOGGING_PVT.Log_BeginProc(
4199         p_module_name    => g_module_name,
4200         p_procedure_name => l_program_name) ;
4201 
4202     --  Initialize API return status to success
4203     x_return_status := L_FND_RET_STS_SUCCESS;
4204 
4205     l_debug_info := 'Derive organization fields and validate them if required';
4206     INL_LOGGING_PVT.Log_Statement(
4207         p_module_name      => g_module_name,
4208         p_procedure_name   => l_program_name,
4209         p_debug_info       => l_debug_info) ;
4210 
4211     INL_LOGGING_PVT.Log_Variable(
4212         p_module_name    => g_module_name,
4213         p_procedure_name => l_program_name,
4214         p_var_name       => 'p_ship_header_int_id',
4215         p_var_value      => p_ship_header_int_id) ;
4216     INL_LOGGING_PVT.Log_Variable(
4217         p_module_name    => g_module_name,
4218         p_procedure_name => l_program_name,
4219         p_var_name       => 'p_validation_flag',
4220         p_var_value      => p_validation_flag) ;
4221     INL_LOGGING_PVT.Log_Variable(
4222         p_module_name    => g_module_name,
4223         p_procedure_name => l_program_name,
4224         p_var_name       => 'x_organization_code',
4225         p_var_value      => x_organization_code) ;
4226     INL_LOGGING_PVT.Log_Variable(
4227         p_module_name    => g_module_name,
4228         p_procedure_name => l_program_name,
4229         p_var_name       => 'x_org_id',
4230         p_var_value      => x_org_id) ;
4231     INL_LOGGING_PVT.Log_Variable(
4232         p_module_name    => g_module_name,
4233         p_procedure_name => l_program_name,
4234         p_var_name       => 'p_ship_header_id',
4235         p_var_value      => p_ship_header_id) ;
4236 
4237 --=================================================================================
4238 -- The inl_parameters table should always be checked
4239 -- if a organization does not have this setup
4240 -- the record should be rejected otherwise we'll get a exception in import process
4241 -- BUG#8971635
4242 -- Begin
4243 --=================================================================================
4244 /* -- BUG#8971635
4245     IF p_validation_flag = 'N' THEN
4246         l_debug_info := 'Validation is not required for Organization';
4247         INL_LOGGING_PVT.Log_Statement(
4248             p_module_name      => g_module_name,
4249             p_procedure_name   => l_program_name,
4250             p_debug_info       => l_debug_info);
4251         IF x_organization_id IS NOT NULL THEN
4252             x_organization_code := NULL;
4253             SELECT ood.operating_unit
4254             INTO x_org_id
4255             FROM org_organization_definitions ood
4256             WHERE ood.organization_id = x_organization_id;
4257         ELSIF x_organization_code IS NOT NULL THEN
4258             l_column_name := 'ORGANIZATION_CODE';
4259             l_column_value := x_organization_code;
4260 
4261             l_debug_info := 'Derive organization id from organization code';
4262             INL_LOGGING_PVT.Log_Statement(
4263                 p_module_name      => g_module_name,
4264                 p_procedure_name   => l_program_name,
4265                 p_debug_info       => l_debug_info);
4266 
4267              SELECT ood.organization_id, ood.operating_unit
4268              INTO x_organization_id, x_org_id
4269              FROM org_organization_definitions ood
4270              WHERE ood.organization_code = x_organization_code;
4271         END IF;
4272     ELSIF p_validation_flag = 'Y' THEN
4273 */ -- BUG#8971635
4274 --=================================================================================
4275 -- The inl_parameters table should always be checked
4276 -- if a organization does not have this setup
4277 -- the record should be rejected otherwise we'll get a exception in import process
4278 -- BUG#8971635
4279 -- End
4280 --=================================================================================
4281 
4282     IF p_ship_header_id IS NOT NULL THEN
4283         l_column_name := 'ship_header_id';
4284         l_column_value := p_ship_header_id;
4285 
4286         SELECT organization_id
4287         INTO x_organization_id
4288         FROM inl_ship_headers_all
4289         WHERE ship_header_id = p_ship_header_id;
4290 
4291     END IF;
4292     INL_LOGGING_PVT.Log_Variable(
4293         p_module_name    => g_module_name,
4294         p_procedure_name => l_program_name,
4295         p_var_name       => 'x_organization_id',
4296         p_var_value      => x_organization_id) ;
4297     l_column_name := 'ORGANIZATION_ID';
4298     l_column_value := x_organization_id;
4299     l_debug_info := 'Derive organization information.';
4300     INL_LOGGING_PVT.Log_Statement(
4301             p_module_name      => g_module_name,
4302             p_procedure_name   => l_program_name,
4303             p_debug_info       => l_debug_info);
4304 
4305     SELECT
4306         ood.legal_entity,
4307         ood.organization_id,
4308         ood.organization_code,
4309         ood.operating_unit,
4310         DECODE(NVL(rp.pre_receive, 'N'),'N','AAS','PR'),
4311         ipa.user_defined_ship_num_code,
4312         ipa.manual_ship_num_type,
4313         DECODE(ipa.organization_id, NULL, 0 , 1)
4314     INTO
4315         x_legal_entity_id,
4316         x_organization_id,
4317         x_organization_code,
4318         x_org_id,
4319         x_LCM_FLOW,
4320         x_user_defined_ship_num_code,
4321         x_manual_ship_num_type,
4322         l_count_org_def_lcm
4323     FROM org_organization_definitions ood,
4324          inl_parameters ipa,
4325          rcv_parameters rp
4326     WHERE
4327         ipa.organization_id (+) = ood.organization_id
4328     AND rp.organization_id (+)  = ood.organization_id
4329     AND ((x_organization_id IS NOT NULL
4330           AND ood.organization_id = x_organization_id)
4331          OR
4332           ood.organization_code = x_organization_code)
4333     ;
4334     INL_LOGGING_PVT.Log_Variable(
4335         p_module_name    => g_module_name,
4336         p_procedure_name => l_program_name,
4337         p_var_name       => 'x_legal_entity_id',
4338         p_var_value      => x_legal_entity_id) ;
4339     INL_LOGGING_PVT.Log_Variable(
4340         p_module_name    => g_module_name,
4341         p_procedure_name => l_program_name,
4342         p_var_name       => 'x_organization_id',
4343         p_var_value      => x_organization_id) ;
4344     INL_LOGGING_PVT.Log_Variable(
4345         p_module_name    => g_module_name,
4346         p_procedure_name => l_program_name,
4347         p_var_name       => 'x_organization_code',
4348         p_var_value      => x_organization_code) ;
4349     INL_LOGGING_PVT.Log_Variable(
4350         p_module_name    => g_module_name,
4351         p_procedure_name => l_program_name,
4352         p_var_name       => 'x_org_id',
4353         p_var_value      => x_org_id) ;
4354     INL_LOGGING_PVT.Log_Variable(
4355         p_module_name    => g_module_name,
4356         p_procedure_name => l_program_name,
4357         p_var_name       => 'x_LCM_FLOW',
4358         p_var_value      => x_LCM_FLOW) ;
4359     INL_LOGGING_PVT.Log_Variable(
4360         p_module_name    => g_module_name,
4361         p_procedure_name => l_program_name,
4362         p_var_name       => 'x_user_defined_ship_num_code',
4363         p_var_value      => x_user_defined_ship_num_code) ;
4364     INL_LOGGING_PVT.Log_Variable(
4365         p_module_name    => g_module_name,
4366         p_procedure_name => l_program_name,
4367         p_var_name       => 'x_manual_ship_num_type',
4368         p_var_value      => x_manual_ship_num_type) ;
4369     INL_LOGGING_PVT.Log_Variable(
4370         p_module_name    => g_module_name,
4371         p_procedure_name => l_program_name,
4372         p_var_name       => 'l_count_org_def_lcm',
4373         p_var_value      => l_count_org_def_lcm) ;
4374 
4375     -- Validating Organization
4376     IF NVL(l_count_org_def_lcm,0) = 0 THEN
4377         l_debug_info := 'The organization has no LCM Options defined';
4378         INL_LOGGING_PVT.Log_Statement(
4379             p_module_name      => g_module_name,
4380             p_procedure_name   => l_program_name,
4381             p_debug_info       => l_debug_info);
4382 
4383         l_result := L_FND_FALSE;
4384         -- Add a line into inl_ship_errors
4385         Handle_InterfError(
4386             p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
4387             p_parent_table_id    => p_ship_header_int_id,
4388             p_column_name        => 'ORGANIZATION_ID',
4389             p_column_value       => x_organization_id,
4390             p_error_message_name => 'INL_ERR_NO_LCM_OPT_DEF_ORG',
4391             p_token1_name        => 'INV_ORG_NAME',
4392             p_token1_value       => x_organization_id,
4393             x_return_status      => l_return_status) ;
4394 
4395         -- If any errors happen abort API.
4396         IF l_return_status = L_FND_RET_STS_ERROR THEN
4397             RAISE L_FND_EXC_ERROR;
4398         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
4399             RAISE L_FND_EXC_UNEXPECTED_ERROR;
4400         END IF;
4401 --        END IF; -- BUG#8971635
4402 
4403         IF x_org_id IS NULL THEN
4404             l_debug_info := 'Operating Unit is not defined for the Organization';
4405             INL_LOGGING_PVT.Log_Statement(
4406                p_module_name      => g_module_name,
4407                p_procedure_name   => l_program_name,
4408                p_debug_info       => l_debug_info);
4409 
4410             l_result := L_FND_FALSE;
4411             -- Add a line into inl_ship_errors
4412             Handle_InterfError(
4413                     p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
4414                     p_parent_table_id    => p_ship_header_int_id,
4415                     p_column_name        => 'ORGANIZATION_ID',
4416                     p_column_value       => x_organization_id,
4417                     p_error_message_name => 'INL_ERR_NO_OP_UNIT_DEF',
4418                     x_return_status      => l_return_status) ;
4419 
4420             -- If any errors happen abort API.
4421             IF l_return_status = L_FND_RET_STS_ERROR THEN
4422                 RAISE L_FND_EXC_ERROR;
4423             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
4424                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
4425             END IF;
4426         END IF;
4427     END IF;
4428 
4429     -- Standard End of Procedure/Function Logging
4430     INL_LOGGING_PVT.Log_EndProc(
4431         p_module_name    => g_module_name,
4432         p_procedure_name => l_program_name);
4433 
4434     RETURN FND_API.to_boolean(l_result) ;
4435 EXCEPTION
4436     WHEN L_FND_EXC_ERROR THEN
4437         -- Standard Expected Error Logging
4438         INL_LOGGING_PVT.Log_ExpecError (
4439             p_module_name    => g_module_name,
4440             p_procedure_name => l_program_name);
4441         RETURN FND_API.to_boolean(L_FND_FALSE) ;
4442     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
4443         -- Standard Unexpected Error Logging
4444         INL_LOGGING_PVT.Log_UnexpecError (
4445             p_module_name    => g_module_name,
4446             p_procedure_name => l_program_name);
4447         RETURN FND_API.to_boolean(L_FND_FALSE) ;
4448     WHEN OTHERS THEN
4449         -- Add a line into inl_ship_errors
4450         Handle_InterfError(
4451             p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
4452             p_parent_table_id    => p_ship_header_int_id,
4453             p_column_name        => l_column_name,
4454             p_column_value       => l_column_value,
4455             p_error_message_name => 'INL_ERR_INVL_INV_ORG',
4456             x_return_status      => l_return_status);
4457         -- If any errors happen abort API.
4458         IF l_return_status = L_FND_RET_STS_ERROR THEN
4459             RAISE L_FND_EXC_ERROR;
4460         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
4461             RAISE L_FND_EXC_UNEXPECTED_ERROR;
4462         END IF;
4463         RETURN FND_API.to_boolean(L_FND_FALSE) ;
4464 END Validate_Organization;
4465 
4466 -- Utility name   : Validate_Location
4467 -- Type       : Private
4468 -- Function   : Location validation.
4469 --              Check if a given Location is valid
4470 --
4471 -- Pre-reqs   : None
4472 -- Parameters :
4473 -- IN         : p_ship_header_int_id IN NUMBER
4474 --              p_validation_flag    IN VARCHAR2
4475 --              p_organization_id    IN NUMBER
4476 --
4477 -- OUT        : x_location_id        IN OUT NOCOPY NUMBER
4478 --              x_location_code      IN OUT NOCOPY VARCHAR2
4479 --              x_dflt_country       IN OUT NOCOPY VARCHAR2
4480 --              x_return_status      OUT NOCOPY VARCHAR2
4481 --
4482 -- Version    : Current version 1.0
4483 --
4484 -- Notes      :
4485 FUNCTION Validate_Location(
4486     p_ship_header_int_id IN NUMBER,
4487     p_validation_flag    IN VARCHAR2,
4488     p_organization_id    IN NUMBER,
4489     x_location_id        IN OUT NOCOPY NUMBER,
4490     x_location_code      IN OUT NOCOPY VARCHAR2,
4491     x_dflt_country       IN OUT NOCOPY VARCHAR2,
4492     x_return_status      OUT NOCOPY VARCHAR2
4493 ) RETURN BOOLEAN IS
4494     l_program_name      CONSTANT VARCHAR2(30) := 'Validate_Location';
4495     l_debug_info     VARCHAR2(400) ;
4496     l_result         VARCHAR2(1) := L_FND_TRUE;
4497     l_return_status  VARCHAR2(1) := L_FND_TRUE;
4498     l_msg_count      NUMBER;
4499     l_msg_data       VARCHAR2(2000) ;
4500     l_location_count NUMBER;
4501     l_column_name    VARCHAR2(30);
4502     l_column_value   VARCHAR2(30);
4503     l_count_loc_org  NUMBER;
4504 
4505 BEGIN
4506     -- Standard Beginning of Procedure/Function Logging
4507     INL_LOGGING_PVT.Log_BeginProc(
4508         p_module_name    => g_module_name,
4509         p_procedure_name => l_program_name) ;
4510     --  Initialize API return status to success
4511     x_return_status := L_FND_RET_STS_SUCCESS;
4512 
4513     -- Check if the Location is null
4514     l_debug_info := 'Derive location and validate if required';
4515     INL_LOGGING_PVT.Log_Statement(
4516         p_module_name      => g_module_name,
4517         p_procedure_name   => l_program_name,
4518         p_debug_info       => l_debug_info);
4519 
4520     INL_LOGGING_PVT.Log_Variable(
4521         p_module_name    => g_module_name,
4522         p_procedure_name => l_program_name,
4523         p_var_name       => 'p_organization_id',
4524         p_var_value      => p_organization_id) ;
4525 
4526     INL_LOGGING_PVT.Log_Variable(
4527         p_module_name    => g_module_name,
4528         p_procedure_name => l_program_name,
4529         p_var_name       => 'x_location_id',
4530         p_var_value      => x_location_id) ;
4531 
4532     INL_LOGGING_PVT.Log_Variable(
4533         p_module_name    => g_module_name,
4534         p_procedure_name => l_program_name,
4535         p_var_name       => 'x_location_code',
4536         p_var_value      => x_location_code) ;
4537 
4538     IF x_location_id IS NULL AND x_location_code IS NULL THEN
4539         l_debug_info := 'Location Id and Location Code are null, derivating from organization';
4540         INL_LOGGING_PVT.Log_Statement(
4541             p_module_name      => g_module_name,
4542             p_procedure_name   => l_program_name,
4543             p_debug_info       => l_debug_info);
4544 
4545         SELECT
4546             hou.location_id,
4547             hl.location_code,
4548             hl.country
4549         INTO
4550             x_location_id,
4551             x_location_code,
4552             x_dflt_country
4553         FROM
4554             hr_organization_units hou,
4555             hr_locations_all hl --Bug#11794483B
4556         WHERE hl.location_id    = hou.location_id
4557         AND hou.organization_id = p_organization_id;
4558         INL_LOGGING_PVT.Log_Variable(
4559             p_module_name    => g_module_name,
4560             p_procedure_name => l_program_name,
4561             p_var_name       => '(a)x_location_id',
4562             p_var_value      => x_location_id) ;
4563         INL_LOGGING_PVT.Log_Variable(
4564             p_module_name    => g_module_name,
4565             p_procedure_name => l_program_name,
4566             p_var_name       => '(a)x_location_code',
4567             p_var_value      => x_location_code) ;
4568         INL_LOGGING_PVT.Log_Variable(
4569             p_module_name    => g_module_name,
4570             p_procedure_name => l_program_name,
4571             p_var_name       => '(a)x_dflt_country',
4572             p_var_value      => x_dflt_country) ;
4573     ELSE
4574         IF p_validation_flag = 'N' THEN
4575             l_debug_info := 'Validation is not required for Location';
4576             INL_LOGGING_PVT.Log_Statement(
4577                 p_module_name      => g_module_name,
4578                 p_procedure_name   => l_program_name,
4579                 p_debug_info       => l_debug_info);
4580             IF x_location_id IS NOT NULL THEN
4581                 x_location_code := NULL;
4582             ELSIF x_location_code IS NOT NULL THEN
4583                 l_column_name  := 'LOCATION_CODE';
4584                 l_column_value := x_location_code;
4585 
4586                 SELECT
4587                     hl.location_id,
4588                     hl.country
4589                 INTO
4590                     x_location_id,
4591                     x_dflt_country
4592                 FROM
4593                     hr_locations_all hl --Bug#11794483B
4594                 WHERE
4595                     hl.location_code = x_location_code;
4596             END IF;
4597             INL_LOGGING_PVT.Log_Variable(
4598                 p_module_name    => g_module_name,
4599                 p_procedure_name => l_program_name,
4600                 p_var_name       => '(b)x_location_id',
4601                 p_var_value      => x_location_id) ;
4602             INL_LOGGING_PVT.Log_Variable(
4603                 p_module_name    => g_module_name,
4604                 p_procedure_name => l_program_name,
4605                 p_var_name       => '(b)x_dflt_country',
4606                 p_var_value      => x_dflt_country) ;
4607         ELSE
4608             l_debug_info := 'Validation is required for Location';
4609             INL_LOGGING_PVT.Log_Statement(
4610                 p_module_name      => g_module_name,
4611                 p_procedure_name   => l_program_name,
4612                 p_debug_info       => l_debug_info);
4613 
4614             SELECT
4615                 hl.location_code,
4616                 hl.location_id,
4617                 hl.country,
4618                 (SELECT COUNT(1)
4619                  FROM hr_locations_all hl1 --Bug#11794483B
4620                  WHERE hl1.location_id = hl.location_id
4621                  AND   hl1.inventory_organization_id = p_organization_id)
4622             INTO
4623                 x_location_code,
4624                 x_location_id,
4625                 x_dflt_country,
4626                 l_count_loc_org
4627             FROM
4628                 hr_locations_all hl --Bug#11794483B
4629             WHERE
4630                 (x_location_id IS NOT NULL
4631                  AND hl.location_id = x_location_id)
4632                 OR hl.location_code = x_location_code
4633             ;
4634             INL_LOGGING_PVT.Log_Variable(
4635                 p_module_name    => g_module_name,
4636                 p_procedure_name => l_program_name,
4637                 p_var_name       => '(c)x_location_id',
4638                 p_var_value      => x_location_id) ;
4639             INL_LOGGING_PVT.Log_Variable(
4640                 p_module_name    => g_module_name,
4641                 p_procedure_name => l_program_name,
4642                 p_var_name       => '(c)x_location_code',
4643                 p_var_value      => x_location_code) ;
4644             INL_LOGGING_PVT.Log_Variable(
4645                 p_module_name    => g_module_name,
4646                 p_procedure_name => l_program_name,
4647                 p_var_name       => '(c)x_dflt_country',
4648                 p_var_value      => x_dflt_country) ;
4649             INL_LOGGING_PVT.Log_Variable(
4650                 p_module_name    => g_module_name,
4651                 p_procedure_name => l_program_name,
4652                 p_var_name       => '(c)l_count_loc_org',
4653                 p_var_value      => l_count_loc_org) ;
4654 
4655             IF NVL(l_count_loc_org,0) = 0 THEN
4656                 l_debug_info := 'The Location is not compliant with the Inventory Organization';
4657                 INL_LOGGING_PVT.Log_Statement(
4658                     p_module_name      => g_module_name,
4659                     p_procedure_name   => l_program_name,
4660                     p_debug_info       => l_debug_info) ;
4661 
4662                 l_result := L_FND_FALSE;
4663 
4664                 -- Add a line into inl_ship_errors
4665                 Handle_InterfError(
4666                     p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
4667                     p_parent_table_id    => p_ship_header_int_id,
4668                     p_column_name        => 'LOCATION_ID',
4669                     p_column_value       => x_location_id,
4670                     p_error_message_name => 'INL_ERR_NO_LOCATION_INV_ORG',
4671                     x_return_status      => l_return_status);
4672                 -- If any errors happen abort API.
4673                 IF l_return_status = L_FND_RET_STS_ERROR THEN
4674                     RAISE L_FND_EXC_ERROR;
4675                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
4676                    RAISE L_FND_EXC_UNEXPECTED_ERROR;
4677                 END IF;
4678             END IF;
4679 
4680             IF x_dflt_country IS NULL THEN
4681                 l_debug_info := 'Country is required to assign a valid Location for the Shipment';
4682                 INL_LOGGING_PVT.Log_Statement(
4683                     p_module_name      => g_module_name,
4684                     p_procedure_name   => l_program_name,
4685                     p_debug_info       => l_debug_info);
4686                 l_result := L_FND_FALSE;
4687 
4688                 -- Add a line into inl_ship_errors
4689                 Handle_InterfError(
4690                     p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
4691                     p_parent_table_id    => p_ship_header_int_id,
4692                     p_column_name        => 'LOCATION_ID',
4693                     p_column_value       => x_location_id,
4694                     p_error_message_name => 'INL_ERR_COUNTRY_LOCATION',
4695                     x_return_status      => l_return_status);
4696                 -- If any errors happen abort API.
4697                 IF l_return_status = L_FND_RET_STS_ERROR THEN
4698                     RAISE L_FND_EXC_ERROR;
4699                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
4700                    RAISE L_FND_EXC_UNEXPECTED_ERROR;
4701                 END IF;
4702             END IF;
4703         END IF;
4704     END IF;
4705 
4706     -- Standard End of Procedure/Function Logging
4707     INL_LOGGING_PVT.Log_EndProc(
4708         p_module_name    => g_module_name,
4709         p_procedure_name => l_program_name);
4710 
4711     RETURN FND_API.to_boolean(l_result) ;
4712 EXCEPTION
4713     WHEN L_FND_EXC_ERROR THEN
4714         -- Standard Expected Error Logging
4715         INL_LOGGING_PVT.Log_ExpecError (
4716             p_module_name    => g_module_name,
4717             p_procedure_name => l_program_name);
4718         RETURN FND_API.to_boolean(L_FND_FALSE) ;
4719     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
4720         -- Standard Unexpected Error Logging
4721         INL_LOGGING_PVT.Log_UnexpecError (
4722             p_module_name    => g_module_name,
4723             p_procedure_name => l_program_name);
4724         RETURN FND_API.to_boolean(L_FND_FALSE) ;
4725     WHEN OTHERS THEN
4726         -- Add a line into inl_ship_errors
4727         Handle_InterfError(
4728             p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
4729             p_parent_table_id    => p_ship_header_int_id,
4730             p_column_name        => l_column_name,
4731             p_column_value       => l_column_value,
4732             p_error_message_name => 'INL_ERR_LOCATION_INV',
4733             x_return_status      => l_return_status);
4734 
4735         -- If any errors happen abort API.
4736         IF l_return_status = L_FND_RET_STS_ERROR THEN
4737             RAISE L_FND_EXC_ERROR;
4738         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
4739             RAISE L_FND_EXC_UNEXPECTED_ERROR;
4740         END IF;
4741         RETURN FND_API.to_boolean(L_FND_FALSE) ;
4742 END Validate_Location;
4743 
4744 -- Utility name : Validate_LnCreateTrxType
4745 -- Type       : Private
4746 -- Function   : Validate the CREATE transaction type
4747 --
4748 -- Pre-reqs   : None
4749 -- Parameters :
4750 -- IN         : p_validation_flag IN VARCHAR2,
4751 --              p_dflt_country    IN VARCHAR2,
4752 --              p_ship_type_id    IN NUMBER,
4753 --              p_organization_id IN NUMBER,
4754 --              p_org_id          IN NUMBER,
4755 --              p_interface_source_code IN VARCHAR2
4756 --
4757 -- IN OUT     : x_ship_ln_int_lst IN OUT NOCOPY ship_ln_int_list_type
4758 --              x_return_status      OUT NOCOPY VARCHAR2
4759 --              x_validate_inv_item  OUT NOCOPY BOOLEAN,
4760 --
4761 -- Version    : Current version 1.0
4762 --
4763 -- Notes
4764 FUNCTION Validate_LnCreateTrxType(
4765         p_validation_flag IN VARCHAR2,
4766         p_dflt_country    IN VARCHAR2,
4767         p_ship_type_id    IN NUMBER,
4768         p_organization_id IN NUMBER,
4769         p_org_id          IN NUMBER,
4770         p_interface_source_code IN VARCHAR2,
4771         x_ship_ln_int_lst IN OUT NOCOPY ship_ln_int_list_type,
4772         x_return_status      OUT NOCOPY VARCHAR2
4773 )RETURN BOOLEAN IS
4774 
4775     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_LnCreateTrxType';
4776     l_return_status VARCHAR2(1) ;
4777     l_debug_info    VARCHAR2(400) ;
4778     l_response      BOOLEAN := TRUE;
4779     l_response_int  BOOLEAN := TRUE;
4780     l_ship_line_int_id NUMBER;
4781     l_lcm_flag      VARCHAR2(1); --Bug 13056120
4782     l_validate_inv_item     BOOLEAN := TRUE;
4783     l_validate_txn_uom_code BOOLEAN := TRUE;
4784 BEGIN
4785 
4786     -- Standard Beginning of Procedure/Function Logging
4787     INL_LOGGING_PVT.Log_BeginProc(
4788         p_module_name    => g_module_name,
4789         p_procedure_name => l_program_name) ;
4790     --  Initialize API return status to success
4791     x_return_status      := L_FND_RET_STS_SUCCESS;
4792 
4793     l_debug_info := 'Check Line columns for the CREATE transaction type';
4794     INL_LOGGING_PVT.Log_Statement(
4795         p_module_name      => g_module_name,
4796         p_procedure_name   => l_program_name,
4797         p_debug_info       => l_debug_info);
4798 
4799     FOR l_ship_ln_int_idx IN 1 .. x_ship_ln_int_lst.COUNT
4800     LOOP
4801 
4802         IF x_ship_ln_int_lst(l_ship_ln_int_idx).org_id IS NULL
4803         THEN
4804             x_ship_ln_int_lst(l_ship_ln_int_idx).org_id := p_org_id;
4805         END IF;
4806 
4807         INL_LOGGING_PVT.Log_Variable(
4808             p_module_name    => g_module_name,
4809             p_procedure_name => l_program_name,
4810             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').currency_code',
4811             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).currency_code);
4812         INL_LOGGING_PVT.Log_Variable(
4813             p_module_name    => g_module_name,
4814             p_procedure_name => l_program_name,
4815             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').inventory_item_id',
4816             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_id);
4817         INL_LOGGING_PVT.Log_Variable(
4818             p_module_name    => g_module_name,
4819             p_procedure_name => l_program_name,
4820             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').inventory_item_name',
4821             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_name);
4822         INL_LOGGING_PVT.Log_Variable(
4823             p_module_name    => g_module_name,
4824             p_procedure_name => l_program_name,
4825             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').party_id',
4826             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).party_id);
4827         INL_LOGGING_PVT.Log_Variable(
4828             p_module_name    => g_module_name,
4829             p_procedure_name => l_program_name,
4830             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').party_number',
4831             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).party_number);
4832         INL_LOGGING_PVT.Log_Variable(
4833             p_module_name    => g_module_name,
4834             p_procedure_name => l_program_name,
4835             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').party_site_id',
4836             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_id);
4837         INL_LOGGING_PVT.Log_Variable(
4838             p_module_name    => g_module_name,
4839             p_procedure_name => l_program_name,
4840             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').party_site_number',
4841             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_number);
4842         INL_LOGGING_PVT.Log_Variable(
4843             p_module_name    => g_module_name,
4844             p_procedure_name => l_program_name,
4845             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').ship_header_id',
4846             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).ship_header_id);
4847         INL_LOGGING_PVT.Log_Variable(
4848             p_module_name    => g_module_name,
4849             p_procedure_name => l_program_name,
4850             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').ship_line_group_id',
4851             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_id);
4852         INL_LOGGING_PVT.Log_Variable(
4853             p_module_name    => g_module_name,
4854             p_procedure_name => l_program_name,
4855             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').ship_line_group_num',
4856             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_num);
4857         INL_LOGGING_PVT.Log_Variable(
4858             p_module_name    => g_module_name,
4859             p_procedure_name => l_program_name,
4860             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').ship_line_id',
4861             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id);
4862         INL_LOGGING_PVT.Log_Variable(
4863             p_module_name    => g_module_name,
4864             p_procedure_name => l_program_name,
4865             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').ship_line_num',
4866             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num);
4867         INL_LOGGING_PVT.Log_Variable(
4868             p_module_name    => g_module_name,
4869             p_procedure_name => l_program_name,
4870             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').ship_line_src_type_code',
4871             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code);
4872         INL_LOGGING_PVT.Log_Variable(
4873             p_module_name    => g_module_name,
4874             p_procedure_name => l_program_name,
4875             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').ship_line_type_code',
4876             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_code);
4877         INL_LOGGING_PVT.Log_Variable(
4878             p_module_name    => g_module_name,
4879             p_procedure_name => l_program_name,
4880             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').ship_line_type_id',
4881             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_id);
4882         INL_LOGGING_PVT.Log_Variable(
4883             p_module_name    => g_module_name,
4884             p_procedure_name => l_program_name,
4885             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').source_organization_code',
4886             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_code);
4887         INL_LOGGING_PVT.Log_Variable(
4888             p_module_name    => g_module_name,
4889             p_procedure_name => l_program_name,
4890             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').source_organization_id',
4891             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_id);
4892         INL_LOGGING_PVT.Log_Variable(
4893             p_module_name    => g_module_name,
4894             p_procedure_name => l_program_name,
4895             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').txn_qty',
4896             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).txn_qty);
4897         INL_LOGGING_PVT.Log_Variable(
4898             p_module_name    => g_module_name,
4899             p_procedure_name => l_program_name,
4900             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').txn_unit_price',
4901             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).txn_unit_price);
4902         INL_LOGGING_PVT.Log_Variable(
4903             p_module_name    => g_module_name,
4904             p_procedure_name => l_program_name,
4905             p_var_name       => 'x_ship_ln_int_lst('||l_ship_ln_int_idx||').txn_uom_code',
4906             p_var_value      =>        x_ship_ln_int_lst(l_ship_ln_int_idx).txn_uom_code);
4907 
4908         l_ship_line_int_id := x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id;
4909 
4910         l_debug_info := 'Checking l_ship_line_int_id: ' || l_ship_line_int_id;
4911         INL_LOGGING_PVT.Log_Statement(
4912             p_module_name      => g_module_name,
4913             p_procedure_name   => l_program_name,
4914             p_debug_info       => l_debug_info);
4915 
4916         l_debug_info := 'Checking if ship_line_src_type_code IS NULL';
4917         INL_LOGGING_PVT.Log_Statement(
4918             p_module_name      => g_module_name,
4919             p_procedure_name   => l_program_name,
4920             p_debug_info       => l_debug_info);
4921 
4922         IF(x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code IS NULL)
4923         THEN
4924             l_response := FALSE;
4925             -- Add a line into inl_ship_errors
4926             Handle_InterfError(
4927                 p_parent_table_name => 'INL_SHIP_LINES_INT',
4928                 p_parent_table_id   => l_ship_line_int_id,
4929                 p_column_name       => 'TRANSACTION_TYPE',
4930                 p_column_value      => 'CREATE',
4931                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
4932                 p_token1_name       => 'COLUMN',
4933                 p_token1_value      => 'SHIP_LINE_SRC_TYPE_CODE',
4934                 p_token2_name       => 'ID_NAME',
4935                 p_token2_value      => 'INL_SHIP_LINES_INT',
4936                 p_token3_name       => 'ID_VAL',
4937                 p_token3_value      => l_ship_line_int_id,
4938                 x_return_status     => l_return_status) ;
4939             -- If any errors happen abort API.
4940             IF l_return_status = L_FND_RET_STS_ERROR THEN
4941                 RAISE L_FND_EXC_ERROR;
4942             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
4943                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
4944             END IF;
4945         END IF;
4946 
4947         l_debug_info := 'Checking parties to PO';
4948         INL_LOGGING_PVT.Log_Statement(
4949             p_module_name      => g_module_name,
4950             p_procedure_name   => l_program_name,
4951             p_debug_info       => l_debug_info);
4952 
4953         -- PO Source Type required columns validations
4954         IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code = 'PO'
4955         THEN
4956             IF (x_ship_ln_int_lst(l_ship_ln_int_idx).party_id IS NULL AND
4957                 x_ship_ln_int_lst(l_ship_ln_int_idx).party_number IS NULL)
4958                 OR
4959                 (x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_id IS NULL AND
4960                  x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_number IS NULL)
4961             THEN
4962                 l_response := FALSE;
4963                 -- Add a line into inl_ship_errors
4964                 Handle_InterfError(
4965                     p_parent_table_name => 'INL_SHIP_LINES_INT',
4966                     p_parent_table_id   => l_ship_line_int_id,
4967                     p_column_name       => 'TRANSACTION_TYPE',
4968                     p_column_value      => 'CREATE',
4969                     p_error_message_name => 'INL_ERR_PARTY_FLDS_NULL_SRC_TP',
4970                     p_token1_name       => 'SHIP_LN_SRC',
4971                     p_token1_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code,
4972                     p_token2_name       => 'ID_NAME',
4973                     p_token2_value      => 'INL_SHIP_LINES_INT',
4974                     p_token3_name       => 'ID_VAL',
4975                     p_token3_value      => l_ship_line_int_id,
4976                     x_return_status     => l_return_status) ;
4977                 -- If any errors happen abort API.
4978                 IF l_return_status = L_FND_RET_STS_ERROR THEN
4979                     RAISE L_FND_EXC_ERROR;
4980                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
4981                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
4982                 END IF;
4983 
4984             END IF;
4985 
4986             --Bug 13056120 Starts
4987         l_debug_info := 'Checking if lines are compliant or not';
4988         INL_LOGGING_PVT.Log_Statement(
4989             p_module_name      => g_module_name,
4990             p_procedure_name   => l_program_name,
4991             p_debug_info       => l_debug_info);
4992 
4993               SELECT INV_UTILITIES.inv_check_lcm(pla.item_id,
4994                                                    plla.ship_to_organization_id,
4995                                                    plla.consigned_flag,
4996                                                    NULL,
4997                                                    pha.vendor_id,
4998                                                    pha.vendor_site_id,
4999                                                    plla.line_location_id)
5000                 INTO l_lcm_flag
5001                 FROM    po_headers_all pha
5002                       , po_lines_all pla
5003                       , po_line_locations_all plla
5004                 WHERE   pha.po_header_id = pla.po_header_id
5005                     AND pla.po_line_id = plla.po_line_id
5006                     AND pha.po_header_id = plla.po_header_id
5007                     AND plla.line_location_id = x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_source_id;
5008 
5009                 INL_LOGGING_PVT.Log_Variable(
5010                     p_module_name    => g_module_name,
5011                     p_procedure_name => l_program_name,
5012                     p_var_name       => 'l_lcm_flag',
5013                     p_var_value      =>  NVL(l_lcm_flag,'NULL'));
5014 
5015                 IF NVL(l_lcm_flag,'N') <> 'Y' THEN
5016                    l_response := FALSE;
5017                 -- Add a line into inl_ship_errors
5018                 Handle_InterfError(
5019                     p_parent_table_name => 'INL_SHIP_LINES_INT',
5020                     p_parent_table_id   => l_ship_line_int_id,
5021                     p_column_name       => 'TRANSACTION_TYPE',
5022                     p_column_value      => 'CREATE',
5023                     p_error_message_name => 'INL_ERR_SHIP_REC_NOT_COMPL',
5024                     p_token1_name       => 'ID_NAME1',
5025                     p_token1_value      => 'INL_SHIP_LINES_INT',
5026                     p_token2_name       => 'ID_VAL1',
5027                     p_token2_value      => l_ship_line_int_id,
5028                     p_token3_name       => 'ID_NAME2',
5029                     p_token3_value      => 'INL_SHIP_HEADERS_INT',
5030                     p_token4_name       => 'ID_VAL2',
5031                     p_token4_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_header_int_id,
5032                     x_return_status     => l_return_status) ;
5033                             -- If any errors happen abort API.
5034                             IF l_return_status = L_FND_RET_STS_ERROR THEN
5035                                 RAISE L_FND_EXC_ERROR;
5036                             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5037                                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5038                             END IF;
5039                   END IF;
5040 
5041             --Bug 13056120 Ends here
5042 
5043             IF(x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_id IS NOT NULL
5044             AND x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_code IS NOT NULL)
5045             THEN
5046                 l_response := FALSE;
5047                 -- Add a line into inl_ship_errors
5048                 Handle_InterfError(
5049                     p_parent_table_name => 'INL_SHIP_LINES_INT',
5050                     p_parent_table_id   => l_ship_line_int_id,
5051                     p_column_name       => 'TRANSACTION_TYPE',
5052                     p_column_value      => 'CREATE',
5053                     p_error_message_name => 'INL_ERR_SRC_ORG_FLDS_NNULL',
5054                     p_token1_name       => 'SHIP_LN_SRC',
5055                     p_token1_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code,
5056                     p_token2_name       => 'ID_NAME',
5057                     p_token2_value      => 'INL_SHIP_LINES_INT',
5058                     p_token3_name       => 'ID_VAL',
5059                     p_token3_value      => l_ship_line_int_id,
5060                     x_return_status     => l_return_status) ;
5061                 -- If any errors happen abort API.
5062                 IF l_return_status = L_FND_RET_STS_ERROR THEN
5063                     RAISE L_FND_EXC_ERROR;
5064                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5065                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
5066                 END IF;
5067 
5068             END IF;
5069         ELSIF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code = 'RMA'
5070         THEN
5071             l_debug_info := 'Checking parties to RMA';
5072             INL_LOGGING_PVT.Log_Statement(
5073                 p_module_name      => g_module_name,
5074                 p_procedure_name   => l_program_name,
5075                 p_debug_info       => l_debug_info);
5076             IF x_ship_ln_int_lst(l_ship_ln_int_idx).party_id IS NULL AND
5077                x_ship_ln_int_lst(l_ship_ln_int_idx).party_number IS NULL
5078             THEN
5079                 l_response := FALSE;
5080                 -- Add a line into inl_ship_errors
5081                 Handle_InterfError(
5082                     p_parent_table_name => 'INL_SHIP_LINES_INT',
5083                     p_parent_table_id   => l_ship_line_int_id,
5084                     p_column_name       => 'TRANSACTION_TYPE',
5085                     p_column_value      => 'CREATE',
5086                     p_error_message_name => 'INL_ERR_PARTY_NULL',
5087                     p_token1_name       => 'SHIP_LN_SRC',
5088                     p_token1_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code,
5089                     p_token2_name       => 'ID_NAME',
5090                     p_token2_value      => 'INL_SHIP_LINES_INT',
5091                     p_token3_name       => 'ID_VAL',
5092                     p_token3_value      => l_ship_line_int_id,
5093                     x_return_status     => l_return_status) ;
5094                 -- If any errors happen abort API.
5095                 IF l_return_status = L_FND_RET_STS_ERROR THEN
5096                     RAISE L_FND_EXC_ERROR;
5097                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5098                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
5099                 END IF;
5100             END IF;
5101             IF(x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_id IS NOT NULL
5102                 AND x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_code IS NOT NULL)
5103             THEN
5104                 l_response := FALSE;
5105                 -- Add a line into inl_ship_errors
5106                 Handle_InterfError(
5107                     p_parent_table_name => 'INL_SHIP_LINES_INT',
5108                     p_parent_table_id   => l_ship_line_int_id,
5109                     p_column_name       => 'TRANSACTION_TYPE',
5110                     p_column_value      => 'CREATE',
5111                     p_error_message_name => 'INL_ERR_SRC_ORG_FLDS_NNULL',
5112                     p_token1_name       => 'SHIP_LN_SRC',
5113                     p_token1_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code,
5114                     p_token2_name       => 'ID_NAME',
5115                     p_token2_value      => 'INL_SHIP_LINES_INT',
5116                     p_token3_name       => 'ID_VAL',
5117                     p_token3_value      => l_ship_line_int_id,
5118                     x_return_status     => l_return_status) ;
5119                 -- If any errors happen abort API.
5120                 IF l_return_status = L_FND_RET_STS_ERROR THEN
5121                     RAISE L_FND_EXC_ERROR;
5122                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5123                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
5124                 END IF;
5125             END IF;
5126             IF x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_id IS NOT NULL
5127                 OR x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_number IS NOT NULL
5128             THEN
5129                 l_response := FALSE;
5130                 -- Add a line into inl_ship_errors
5131                 Handle_InterfError(
5132                     p_parent_table_name => 'INL_SHIP_LINES_INT',
5133                     p_parent_table_id   => l_ship_line_int_id,
5134                     p_column_name       => 'TRANSACTION_TYPE',
5135                     p_column_value      => 'CREATE',
5136                     p_error_message_name => 'INL_ERR_PTY_ST_NNULL_SRC_TP',
5137                     p_token1_name       => 'SHIP_LN_SRC',
5138                     p_token1_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code,
5139                     p_token2_name       => 'ID_NAME',
5140                     p_token2_value      => 'INL_SHIP_LINES_INT',
5141                     p_token3_name       => 'ID_VAL',
5142                     p_token3_value      => l_ship_line_int_id,
5143                     x_return_status     => l_return_status) ;
5144                 -- If any errors happen abort API.
5145                 IF l_return_status = L_FND_RET_STS_ERROR THEN
5146                     RAISE L_FND_EXC_ERROR;
5147                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5148                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
5149                 END IF;
5150             END IF;
5151         ELSIF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code = 'IR'
5152         THEN
5153             l_debug_info := 'Checking parties to IR';
5154             INL_LOGGING_PVT.Log_Statement(
5155                 p_module_name      => g_module_name,
5156                 p_procedure_name   => l_program_name,
5157                 p_debug_info       => l_debug_info);
5158             IF x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_id IS NULL
5159                 AND x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_code IS NULL
5160             THEN
5161                 l_response := FALSE;
5162                 -- Add a line into inl_ship_errors
5163                 Handle_InterfError(
5164                     p_parent_table_name => 'INL_SHIP_LINES_INT',
5165                     p_parent_table_id   => l_ship_line_int_id,
5166                     p_column_name       => 'TRANSACTION_TYPE',
5167                     p_column_value      => 'CREATE',
5168                     p_error_message_name => 'INL_ERR_SRC_ORG_NULL_SRC_TP',
5169                     p_token1_name       => 'SHIP_LN_SRC_TYPE_CODE',
5170                     p_token2_name       => 'ID_NAME',
5171                     p_token2_value      => 'INL_SHIP_LINES_INT',
5172                     p_token3_name       => 'ID_VAL',
5173                     p_token3_value      => l_ship_line_int_id,
5174                     p_token1_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code,
5175                     x_return_status     => l_return_status) ;
5176                 -- If any errors happen abort API.
5177                 IF l_return_status = L_FND_RET_STS_ERROR THEN
5178                     RAISE L_FND_EXC_ERROR;
5179                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5180                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
5181                 END IF;
5182             END IF;
5183 
5184             IF x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_id IS NOT NULL
5185                 OR x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_number IS NOT NULL
5186             THEN
5187                 l_response := FALSE;
5188                 -- Add a line into inl_ship_errors
5189                 Handle_InterfError(
5190                     p_parent_table_name => 'INL_SHIP_LINES_INT',
5191                     p_parent_table_id   => l_ship_line_int_id,
5192                     p_column_name       => 'TRANSACTION_TYPE',
5193                     p_column_value      => 'CREATE',
5194                     p_error_message_name => 'INL_ERR_PTY_ST_NNULL_SRC_TP',
5195                     p_token1_name       => 'SHIP_LN_SRC',
5196                     p_token1_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code,
5197                     p_token2_name       => 'ID_NAME',
5198                     p_token2_value      => 'INL_SHIP_LINES_INT',
5199                     p_token3_name       => 'ID_VAL',
5200                     p_token3_value      => l_ship_line_int_id,
5201                     x_return_status     => l_return_status) ;
5202                 -- If any errors happen abort API.
5203                 IF l_return_status = L_FND_RET_STS_ERROR THEN
5204                     RAISE L_FND_EXC_ERROR;
5205                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5206                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
5207                 END IF;
5208             END IF;
5209 
5210             IF x_ship_ln_int_lst(l_ship_ln_int_idx).party_id IS NOT NULL
5211                 OR x_ship_ln_int_lst(l_ship_ln_int_idx).party_number IS NOT NULL
5212             THEN
5213                 l_response := FALSE;
5214                 -- Add a line into inl_ship_errors
5215                 Handle_InterfError(
5216                     p_parent_table_name => 'INL_SHIP_LINES_INT',
5217                     p_parent_table_id   => l_ship_line_int_id,
5218                     p_column_name       => 'TRANSACTION_TYPE',
5219                     p_column_value      => 'CREATE',
5220                     p_error_message_name => 'INL_ERR_PARTY_NNULL_SRC_TP',
5221                     p_token1_name       => 'SHIP_LN_SRC',
5222                     p_token1_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code,
5223                     p_token2_name       => 'ID_NAME',
5224                     p_token2_value      => 'INL_SHIP_LINES_INT',
5225                     p_token3_name       => 'ID_VAL',
5226                     p_token3_value      => l_ship_line_int_id,
5227                     x_return_status     => l_return_status) ;
5228                 -- If any errors happen abort API.
5229                 IF l_return_status = L_FND_RET_STS_ERROR THEN
5230                     RAISE L_FND_EXC_ERROR;
5231                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5232                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
5233                 END IF;
5234             END IF;
5235         ELSE
5236             l_debug_info := 'Bad trx type code';
5237             INL_LOGGING_PVT.Log_Statement(
5238                 p_module_name      => g_module_name,
5239                 p_procedure_name   => l_program_name,
5240                 p_debug_info       => l_debug_info);
5241             l_response := FALSE;
5242             -- Add a line into inl_ship_errors
5243             Handle_InterfError(
5244                 p_parent_table_name => 'INL_SHIP_LINES_INT',
5245                 p_parent_table_id   => l_ship_line_int_id,
5246                 p_column_name       => 'TRANSACTION_TYPE',
5247                 p_column_value      => 'CREATE',
5248                 p_error_message_name => 'INL_ERR_OI_CHK_TRX_TP_INVL',
5249                 p_token1_name       => 'TTYPE',
5250                 p_token1_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code,
5251                 p_token2_name       => 'ID_NAME',
5252                 p_token2_value      => 'INL_SHIP_LINES_INT',
5253                 p_token3_name       => 'ID_VAL',
5254                 p_token3_value      => l_ship_line_int_id,
5255                 x_return_status     => l_return_status) ;
5256             -- If any errors happen abort API.
5257             IF l_return_status = L_FND_RET_STS_ERROR THEN
5258                 RAISE L_FND_EXC_ERROR;
5259             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5260                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5261             END IF;
5262         END IF;
5263 
5264         IF      (x_ship_ln_int_lst(l_ship_ln_int_idx).party_id IS NOT NULL
5265                 OR x_ship_ln_int_lst(l_ship_ln_int_idx).party_number IS NOT NULL)
5266             AND (x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_id IS NOT NULL
5267                 OR x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_code IS NOT NULL)
5268         THEN
5269             l_debug_info := 'Party and Source Organization are mutually exclusive. Only one field or the other may be populated.';
5270             INL_LOGGING_PVT.Log_Statement(
5271                 p_module_name      => g_module_name,
5272                 p_procedure_name   => l_program_name,
5273                 p_debug_info       => l_debug_info);
5274             l_response := FALSE;
5275             -- Add a line into inl_ship_errors
5276             Handle_InterfError(
5277                p_parent_table_name  => 'INL_SHIP_LINES_INT',
5278                p_parent_table_id    => l_ship_line_int_id,
5279                p_column_name        => 'PARTY_ID',
5280                p_column_value       => x_ship_ln_int_lst(l_ship_ln_int_idx).party_id,
5281                p_error_message_name => 'INL_ERR_PARTY_SRC_ORG_EXISTS',
5282                x_return_status      => l_return_status);
5283              -- If any errors happen abort API.
5284              IF l_return_status = L_FND_RET_STS_ERROR THEN
5285                 RAISE L_FND_EXC_ERROR;
5286             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5287                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5288              END IF;
5289         END IF;
5290 
5291         l_debug_info := 'Checking currency';
5292         INL_LOGGING_PVT.Log_Statement(
5293             p_module_name      => g_module_name,
5294             p_procedure_name   => l_program_name,
5295             p_debug_info       => l_debug_info);
5296 
5297         IF(x_ship_ln_int_lst(l_ship_ln_int_idx).currency_code IS NULL) THEN
5298             l_response := FALSE;
5299             -- Add a line into inl_ship_errors
5300             Handle_InterfError(
5301                 p_parent_table_name => 'INL_SHIP_LINES_INT',
5302                 p_parent_table_id   => l_ship_line_int_id,
5303                 p_column_name       => 'TRANSACTION_TYPE',
5304                 p_column_value      => 'CREATE',
5305                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
5306                 p_token1_name       => 'COLUMN',
5307                 p_token1_value      => 'CURRENCY_CODE',
5308                 p_token2_name       => 'ID_NAME',
5309                 p_token2_value      => 'INL_SHIP_LINES_INT',
5310                 p_token3_name       => 'ID_VAL',
5311                 p_token3_value      => l_ship_line_int_id,
5312                 x_return_status     => l_return_status) ;
5313             -- If any errors happen abort API.
5314             IF l_return_status = L_FND_RET_STS_ERROR THEN
5315                 RAISE L_FND_EXC_ERROR;
5316             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5317                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5318             END IF;
5319         END IF;
5320 
5321         l_debug_info := 'Checking Trx Qty';
5322         INL_LOGGING_PVT.Log_Statement(
5323             p_module_name      => g_module_name,
5324             p_procedure_name   => l_program_name,
5325             p_debug_info       => l_debug_info);
5326 
5327         IF(x_ship_ln_int_lst(l_ship_ln_int_idx).txn_qty IS NULL) THEN
5328             l_response := FALSE;
5329             -- Add a line into inl_ship_errors
5330             Handle_InterfError(
5331                 p_parent_table_name => 'INL_SHIP_LINES_INT',
5332                 p_parent_table_id   => l_ship_line_int_id,
5333                 p_column_name       => 'TRANSACTION_TYPE',
5334                 p_column_value      => 'CREATE',
5335                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
5336                 p_token1_name       => 'COLUMN',
5337                 p_token1_value      => 'TXN_QTY',
5338                 p_token2_name       => 'ID_NAME',
5339                 p_token2_value      => 'INL_SHIP_LINES_INT',
5340                 p_token3_name       => 'ID_VAL',
5341                 p_token3_value      => l_ship_line_int_id,
5342                 x_return_status     => l_return_status) ;
5343             -- If any errors happen abort API.
5344             IF l_return_status = L_FND_RET_STS_ERROR THEN
5345                 RAISE L_FND_EXC_ERROR;
5346             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5347                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5348             END IF;
5349         END IF;
5350 
5351         l_debug_info := 'Checking UOM';
5352         INL_LOGGING_PVT.Log_Statement(
5353             p_module_name      => g_module_name,
5354             p_procedure_name   => l_program_name,
5355             p_debug_info       => l_debug_info);
5356 
5357         IF(x_ship_ln_int_lst(l_ship_ln_int_idx).txn_uom_code IS NULL) THEN
5358             l_response := FALSE;
5359             -- Add a line into inl_ship_errors
5360             Handle_InterfError(
5361                 p_parent_table_name => 'INL_SHIP_LINES_INT',
5362                 p_parent_table_id   => l_ship_line_int_id,
5363                 p_column_name       => 'TRANSACTION_TYPE',
5364                 p_column_value      => 'CREATE',
5365                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
5366                 p_token1_name       => 'COLUMN',
5367                 p_token1_value      => 'TXN_UOM_CODE',
5368                 p_token2_name       => 'ID_NAME',
5369                 p_token2_value      => 'INL_SHIP_LINES_INT',
5370                 p_token3_name       => 'ID_VAL',
5371                 p_token3_value      => l_ship_line_int_id,
5372                 x_return_status     => l_return_status) ;
5373             -- If any errors happen abort API.
5374             IF l_return_status = L_FND_RET_STS_ERROR THEN
5375                 RAISE L_FND_EXC_ERROR;
5376             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5377                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5378             END IF;
5379         END IF;
5380 
5381         l_debug_info := 'Checking Trx Unit Price';
5382         INL_LOGGING_PVT.Log_Statement(
5383             p_module_name      => g_module_name,
5384             p_procedure_name   => l_program_name,
5385             p_debug_info       => l_debug_info);
5386 
5387         IF(x_ship_ln_int_lst(l_ship_ln_int_idx).txn_unit_price IS NULL) THEN
5388             l_response := FALSE;
5389             -- Add a line into inl_ship_errors
5390             Handle_InterfError(
5391                 p_parent_table_name => 'INL_SHIP_LINES_INT',
5392                 p_parent_table_id   => l_ship_line_int_id,
5393                 p_column_name       => 'TRANSACTION_TYPE',
5394                 p_column_value      => 'CREATE',
5395                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
5396                 p_token1_name       => 'COLUMN',
5397                 p_token1_value      => 'TXN_UNIT_PRICE',
5398                 p_token2_name       => 'ID_NAME',
5399                 p_token2_value      => 'INL_SHIP_LINES_INT',
5400                 p_token3_name       => 'ID_VAL',
5401                 p_token3_value      => l_ship_line_int_id,
5402                 x_return_status     => l_return_status) ;
5403             -- If any errors happen abort API.
5404             IF l_return_status = L_FND_RET_STS_ERROR THEN
5405                 RAISE L_FND_EXC_ERROR;
5406             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5407                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5408             END IF;
5409         END IF;
5410 
5411         IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_id IS NULL AND
5412            x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_code IS NULL
5413         THEN
5414             l_response := FALSE;
5415             -- Add a line into inl_ship_errors
5416             Handle_InterfError(
5417                 p_parent_table_name => 'INL_SHIP_LINES_INT',
5418                 p_parent_table_id   => l_ship_line_int_id,
5419                 p_column_name       => 'TRANSACTION_TYPE',
5420                 p_column_value      => 'CREATE',
5421                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
5422                 p_token1_name       => 'COLUMN',
5423                 p_token1_value      => 'SHIP_LINE_TYPE_ID OR SHIP_LINE_TYPE_CODE',
5424                 p_token2_name       => 'ID_NAME',
5425                 p_token2_value      => 'INL_SHIP_LINES_INT',
5426                 p_token3_name       => 'ID_VAL',
5427                 p_token3_value      => l_ship_line_int_id,
5428                 x_return_status     => l_return_status) ;
5429             -- If any errors happen abort API.
5430             IF l_return_status = L_FND_RET_STS_ERROR THEN
5431                 RAISE L_FND_EXC_ERROR;
5432             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5433                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5434             END IF;
5435         END IF;
5436 
5437         IF x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_id IS NULL AND
5438            x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_name IS NULL
5439         THEN
5440             l_response := FALSE;
5441 
5442             -- Add a line into inl_ship_errors
5443             Handle_InterfError(
5444                 p_parent_table_name => 'INL_SHIP_LINES_INT',
5445                 p_parent_table_id   => l_ship_line_int_id,
5446                 p_column_name       => 'TRANSACTION_TYPE',
5447                 p_column_value      => 'CREATE',
5448                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
5449                 p_token1_name       => 'COLUMN',
5450                 p_token1_value      => 'INVENTORY_ITEM_ID OR INVENTORY_ITEM_NAME',
5451                 p_token2_name       => 'ID_NAME',
5452                 p_token2_value      => 'INL_SHIP_LINES_INT',
5453                 p_token3_name       => 'ID_VAL',
5454                 p_token3_value      => l_ship_line_int_id,
5455                 x_return_status     => l_return_status) ;
5456             -- If any errors happen abort API.
5457             IF l_return_status = L_FND_RET_STS_ERROR THEN
5458                 RAISE L_FND_EXC_ERROR;
5459             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5460                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5461             END IF;
5462         END IF;
5463 
5464         IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_header_id IS NOT NULL
5465         THEN
5466             l_response := FALSE;
5467             -- Add a line into inl_ship_errors
5468             Handle_InterfError(
5469                 p_parent_table_name => 'INL_SHIP_LINES_INT',
5470                 p_parent_table_id   => l_ship_line_int_id,
5471                 p_column_name       => 'TRANSACTION_TYPE',
5472                 p_column_value      => 'CREATE',
5473                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
5474                 p_token1_name       => 'COLUMN',
5475                 p_token1_value      => 'SHIP_HEADER_ID',
5476                 p_token2_name       => 'ID_NAME',
5477                 p_token2_value      => 'INL_SHIP_LINES_INT',
5478                 p_token3_name       => 'ID_VAL',
5479                 p_token3_value      => l_ship_line_int_id,
5480                 x_return_status     => l_return_status) ;
5481             -- If any errors happen abort API.
5482             IF l_return_status = L_FND_RET_STS_ERROR THEN
5483                 RAISE L_FND_EXC_ERROR;
5484             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5485                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5486             END IF;
5487         END IF;
5488 
5489         IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_id IS NOT NULL OR
5490            x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_num IS NOT NULL
5491         THEN
5492             l_response := FALSE;
5493 
5494             -- Add a line into inl_ship_errors
5495             Handle_InterfError(
5496                 p_parent_table_name => 'INL_SHIP_LINES_INT',
5497                 p_parent_table_id   => l_ship_line_int_id,
5498                 p_column_name       => 'TRANSACTION_TYPE',
5499                 p_column_value      => 'CREATE',
5500                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
5501                 p_token1_name       => 'COLUMN',
5502                 p_token1_value      => 'SHIP_LINE_GROUP_ID AND SHIP_LINE_GROUP_NUM',
5503                 p_token2_name       => 'ID_NAME',
5504                 p_token2_value      => 'INL_SHIP_LINES_INT',
5505                 p_token3_name       => 'ID_VAL',
5506                 p_token3_value      => l_ship_line_int_id,
5507                 x_return_status     => l_return_status) ;
5508             -- If any errors happen abort API.
5509             IF l_return_status = L_FND_RET_STS_ERROR THEN
5510                 RAISE L_FND_EXC_ERROR;
5511             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5512                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5513             END IF;
5514         END IF;
5515 
5516         IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id IS NOT NULL OR
5517             x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num IS NOT NULL
5518         THEN
5519             l_response := FALSE;
5520 
5521             -- Add a line into inl_ship_errors
5522             Handle_InterfError(
5523                 p_parent_table_name => 'INL_SHIP_LINES_INT',
5524                 p_parent_table_id   => l_ship_line_int_id,
5525                 p_column_name       => 'TRANSACTION_TYPE',
5526                 p_column_value      => 'CREATE',
5527                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
5528                 p_token1_name       => 'COLUMN',
5529                 p_token1_value      => 'SHIP_LINE_ID AND SHIP_LINE_NUM',
5530                 p_token2_name       => 'ID_NAME',
5531                 p_token2_value      => 'INL_SHIP_LINES_INT',
5532                 p_token3_name       => 'ID_VAL',
5533                 p_token3_value      => l_ship_line_int_id,
5534                 x_return_status     => l_return_status) ;
5535             -- If any errors happen abort API.
5536             IF l_return_status = L_FND_RET_STS_ERROR THEN
5537                 RAISE L_FND_EXC_ERROR;
5538             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5539                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5540             END IF;
5541         END IF;
5542 
5543         IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code <> 'IR'
5544         THEN
5545             l_debug_info := 'Calling Validate_Party';
5546             INL_LOGGING_PVT.Log_Statement(
5547                 p_module_name      => g_module_name,
5548                 p_procedure_name   => l_program_name,
5549                 p_debug_info       => l_debug_info);
5550 
5551             l_response_int :=
5552                 Validate_Party
5553                 (
5554                     p_ship_line_int_id  => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
5555                     p_validation_flag   => p_validation_flag,
5556                     p_ship_type_id      => p_ship_type_id,
5557                     x_party_id          => x_ship_ln_int_lst(l_ship_ln_int_idx).party_id,
5558                     x_party_number      => x_ship_ln_int_lst(l_ship_ln_int_idx).party_number,
5559                     x_return_status     => l_return_status
5560             );
5561 
5562             -- If any errors happen abort API.
5563             IF l_return_status = L_FND_RET_STS_ERROR THEN
5564                 RAISE L_FND_EXC_ERROR;
5565             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5566                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5567             END IF;
5568             IF (l_response_int)
5569             THEN
5570                 l_debug_info := 'True';
5571             ELSE
5572                 l_debug_info := 'False';
5573                 l_response := l_response_int;
5574             END IF;
5575             INL_LOGGING_PVT.Log_Variable(
5576                 p_module_name    => g_module_name,
5577                 p_procedure_name => l_program_name,
5578                 p_var_name       => 'l_response_int',
5579                 p_var_value      => l_debug_info);
5580 
5581             IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code = 'PO'
5582             THEN
5583 
5584                 l_debug_info := 'Calling Validate_Party Site';
5585                 INL_LOGGING_PVT.Log_Statement(
5586                     p_module_name      => g_module_name,
5587                     p_procedure_name   => l_program_name,
5588                     p_debug_info       => l_debug_info);
5589                 l_response_int :=
5590                     Validate_PartySite
5591                     (
5592                         p_ship_line_int_id  => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
5593                         p_validation_flag   => p_validation_flag,
5594                         p_party_id          => x_ship_ln_int_lst(l_ship_ln_int_idx).party_id,
5595                         p_dflt_country      => p_dflt_country,
5596                         p_ship_type_id      => p_ship_type_id,
5597                         x_party_site_id     => x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_id,
5598                         x_party_site_number => x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_number,
5599                         x_return_status     => l_return_status
5600                 );
5601 
5602                 -- If any errors happen abort API.
5603                 IF l_return_status = L_FND_RET_STS_ERROR THEN
5604                     RAISE L_FND_EXC_ERROR;
5605                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5606                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
5607                 END IF;
5608                 IF (l_response_int)
5609                 THEN
5610                     l_debug_info := 'True';
5611                 ELSE
5612                     l_debug_info := 'False';
5613                     l_response := l_response_int;
5614                 END IF;
5615                 INL_LOGGING_PVT.Log_Variable(
5616                     p_module_name    => g_module_name,
5617                     p_procedure_name => l_program_name,
5618                     p_var_name       => 'l_response_int',
5619                     p_var_value      => l_debug_info);
5620 
5621             END IF;
5622         ELSE -- = 'IR'
5623             l_debug_info := 'Calling Validate_SrcOrganization';
5624             INL_LOGGING_PVT.Log_Statement(
5625                 p_module_name      => g_module_name,
5626                 p_procedure_name   => l_program_name,
5627                 p_debug_info       => l_debug_info);
5628 
5629             l_response_int :=
5630                 Validate_SrcOrganization
5631                 (
5632                     p_ship_line_int_id      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
5633                     p_validation_flag       => p_validation_flag,
5634                     x_src_organization_id   => x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_id,
5635                     x_src_organization_code => x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_code,
5636                     x_return_status         => l_return_status
5637             );
5638 
5639             -- If any errors happen abort API.
5640             IF l_return_status = L_FND_RET_STS_ERROR THEN
5641                 RAISE L_FND_EXC_ERROR;
5642             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5643                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5644             END IF;
5645             IF (l_response_int)
5646             THEN
5647                 l_debug_info := 'True';
5648             ELSE
5649                 l_debug_info := 'False';
5650                 l_response := l_response_int;
5651             END IF;
5652             INL_LOGGING_PVT.Log_Variable(
5653                 p_module_name    => g_module_name,
5654                 p_procedure_name => l_program_name,
5655                 p_var_name       => 'l_response_int',
5656                 p_var_value      => l_debug_info);
5657 
5658         END IF;
5659         l_debug_info := 'Calling Validate_ShipLineType';
5660         INL_LOGGING_PVT.Log_Statement(
5661             p_module_name      => g_module_name,
5662             p_procedure_name   => l_program_name,
5663             p_debug_info       => l_debug_info);
5664 
5665         l_response_int :=
5666             Validate_ShipLineType
5667             (
5668                 p_ship_line_int_id      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
5669                 p_validation_flag       => p_validation_flag,
5670                 p_ship_type_id          => p_ship_type_id,
5671                 x_ship_line_type_id     => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_id,
5672                 x_ship_line_type_code   => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_code,
5673                 x_landed_cost_flag      => x_ship_ln_int_lst(l_ship_ln_int_idx).landed_cost_flag,
5674                 x_alloc_enabled_flag    => x_ship_ln_int_lst(l_ship_ln_int_idx).allocation_enabled_flag,
5675                 x_return_status         => l_return_status
5676         );
5677 
5678         -- If any errors happen abort API.
5679         IF l_return_status = L_FND_RET_STS_ERROR THEN
5680             RAISE L_FND_EXC_ERROR;
5681         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5682             RAISE L_FND_EXC_UNEXPECTED_ERROR;
5683         END IF;
5684         IF (l_response_int)
5685         THEN
5686             l_debug_info := 'True';
5687         ELSE
5688             l_debug_info := 'False';
5689             l_response := l_response_int;
5690         END IF;
5691         INL_LOGGING_PVT.Log_Variable(
5692             p_module_name    => g_module_name,
5693             p_procedure_name => l_program_name,
5694             p_var_name       => 'l_response_int',
5695             p_var_value      => l_debug_info);
5696 
5697         IF p_validation_flag = 'Y' THEN
5698 
5699             l_debug_info := 'Calling Validate_ShipLnSrcTypeCode';
5700             INL_LOGGING_PVT.Log_Statement(
5701                 p_module_name      => g_module_name,
5702                 p_procedure_name   => l_program_name,
5703                 p_debug_info       => l_debug_info);
5704             l_response_int :=
5705                 Validate_ShipLnSrcTypeCode(
5706                     p_ship_line_int_id      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
5707                     p_ship_ln_src_tp_code   => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code,
5708                     x_return_status         => l_return_status
5709             );
5710 
5711             -- If any errors happen abort API.
5712             IF l_return_status = L_FND_RET_STS_ERROR THEN
5713                 RAISE L_FND_EXC_ERROR;
5714             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5715                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5716             END IF;
5717             IF (l_response_int)
5718             THEN
5719                 l_debug_info := 'True';
5720             ELSE
5721                 l_debug_info := 'False';
5722                 l_response := l_response_int;
5723             END IF;
5724             INL_LOGGING_PVT.Log_Variable(
5725                 p_module_name    => g_module_name,
5726                 p_procedure_name => l_program_name,
5727                 p_var_name       => 'l_response_int',
5728                 p_var_value      => l_debug_info);
5729         END IF;
5730 
5731         l_debug_info := 'Calling Validate_CurrencyCode';
5732         INL_LOGGING_PVT.Log_Statement(
5733             p_module_name      => g_module_name,
5734             p_procedure_name   => l_program_name,
5735             p_debug_info       => l_debug_info);
5736         l_response_int :=
5737             Validate_Currency
5738             (   p_ship_line_int_id  => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
5739                 p_validation_flag   => x_ship_ln_int_lst(l_ship_ln_int_idx).validation_flag,
5740                 p_currency_code     => x_ship_ln_int_lst(l_ship_ln_int_idx).currency_code,
5741                 p_curr_conv_date    => x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_date,
5742                 p_curr_conv_type    => x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_type,
5743                 p_org_id            => x_ship_ln_int_lst(l_ship_ln_int_idx).org_id,
5744                 x_curr_conv_rate    => x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_rate,
5745                 x_return_status     => l_return_status
5746         );
5747 
5748         -- If any errors happen abort API.
5749         IF l_return_status = L_FND_RET_STS_ERROR THEN
5750             RAISE L_FND_EXC_ERROR;
5751         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5752             RAISE L_FND_EXC_UNEXPECTED_ERROR;
5753         END IF;
5754         IF (l_response_int)
5755         THEN
5756             l_debug_info := 'True';
5757         ELSE
5758             l_debug_info := 'False';
5759             l_response := l_response_int;
5760         END IF;
5761         INL_LOGGING_PVT.Log_Variable(
5762             p_module_name    => g_module_name,
5763             p_procedure_name => l_program_name,
5764             p_var_name       => 'l_response_int',
5765             p_var_value      => l_debug_info);
5766 
5767         l_debug_info := 'Calling Validate_InvItemId';
5768         INL_LOGGING_PVT.Log_Statement(
5769             p_module_name      => g_module_name,
5770             p_procedure_name   => l_program_name,
5771             p_debug_info       => l_debug_info);
5772         l_response_int :=
5773             Validate_InvItemId
5774             (   p_ship_line_int_id  => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
5775                 p_validation_flag   => x_ship_ln_int_lst(l_ship_ln_int_idx).validation_flag,
5776                 p_organization_id   => p_organization_id,
5777                 x_inv_item_name     => x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_name,
5778                 x_inv_item_id       => x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_id,
5779                 x_return_status     => l_return_status
5780         );
5781 
5782         -- If any errors happen abort API.
5783         IF l_return_status = L_FND_RET_STS_ERROR THEN
5784             RAISE L_FND_EXC_ERROR;
5785         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5786             RAISE L_FND_EXC_UNEXPECTED_ERROR;
5787         END IF;
5788         IF (l_response_int)
5789         THEN
5790             l_debug_info := 'True';
5791         ELSE
5792             l_debug_info := 'False';
5793             l_response := l_response_int;
5794             l_validate_inv_item := l_response_int;
5795         END IF;
5796         INL_LOGGING_PVT.Log_Variable(
5797             p_module_name    => g_module_name,
5798             p_procedure_name => l_program_name,
5799             p_var_name       => 'l_response_int',
5800             p_var_value      => l_debug_info);
5801 
5802         IF x_ship_ln_int_lst(l_ship_ln_int_idx).txn_uom_code IS NOT NULL
5803         AND p_validation_flag = 'Y'
5804         THEN
5805             l_debug_info := 'Calling Validate_TxnUomCode';
5806             INL_LOGGING_PVT.Log_Statement(
5807                 p_module_name      => g_module_name,
5808                 p_procedure_name   => l_program_name,
5809                 p_debug_info       => l_debug_info);
5810             l_response_int :=
5811                 Validate_TxnUomCode(
5812                     p_ship_line_int_id  => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
5813                     p_txn_uom_code      => x_ship_ln_int_lst(l_ship_ln_int_idx).txn_uom_code,
5814                     x_return_status     => l_return_status
5815             );
5816 
5817             -- If any errors happen abort API.
5818             IF l_return_status = L_FND_RET_STS_ERROR THEN
5819                 RAISE L_FND_EXC_ERROR;
5820             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5821                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5822             END IF;
5823             IF (l_response_int)
5824             THEN
5825                 l_debug_info := 'True';
5826             ELSE
5827                 l_debug_info := 'False';
5828                 l_response := l_response_int;
5829                 l_validate_txn_uom_code := l_response_int;
5830             END IF;
5831             INL_LOGGING_PVT.Log_Variable(
5832                 p_module_name    => g_module_name,
5833                 p_procedure_name => l_program_name,
5834                 p_var_name       => 'l_response_int',
5835                 p_var_value      => l_debug_info);
5836         END IF;
5837 
5838         IF l_validate_txn_uom_code AND l_validate_inv_item
5839         THEN
5840             l_debug_info := 'Call Validate_PriSecFields';
5841             INL_LOGGING_PVT.Log_Statement(
5842                 p_module_name      => g_module_name,
5843                 p_procedure_name   => l_program_name,
5844                 p_debug_info       => l_debug_info);
5845 
5846             l_response_int := Validate_PriSecFields(
5847                 p_ship_line_int_id      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
5848                 p_validation_flag       => p_validation_flag,
5849                 p_organization_id       => p_organization_id,
5850                 p_inventory_item_id     => x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_id,
5851                 p_txn_uom_code          => x_ship_ln_int_lst(l_ship_ln_int_idx).txn_uom_code,
5852                 p_txn_qty               => x_ship_ln_int_lst(l_ship_ln_int_idx).txn_qty,
5853                 p_txn_unit_price        => x_ship_ln_int_lst(l_ship_ln_int_idx).txn_unit_price,
5854                 p_ship_line_id          => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id,
5855                 p_interface_source_code => p_interface_source_code, -- Bug #8932386
5856                 p_interface_source_line_id => x_ship_ln_int_lst(l_ship_ln_int_idx).interface_source_line_id, -- Bug 11710754
5857                 x_1ary_uom_code         => x_ship_ln_int_lst(l_ship_ln_int_idx).primary_uom_code,
5858                 x_1ary_qty              => x_ship_ln_int_lst(l_ship_ln_int_idx).primary_qty,
5859                 x_1ary_unit_price       => x_ship_ln_int_lst(l_ship_ln_int_idx).primary_unit_price,
5860                 x_2ary_uom_code         => x_ship_ln_int_lst(l_ship_ln_int_idx).secondary_uom_code,
5861                 x_2ary_qty              => x_ship_ln_int_lst(l_ship_ln_int_idx).secondary_qty,
5862                 x_2ary_unit_price       => x_ship_ln_int_lst(l_ship_ln_int_idx).secondary_unit_price,
5863                 x_return_status         => l_return_status);
5864 
5865             -- If any errors happen abort API.
5866             IF l_return_status = L_FND_RET_STS_ERROR THEN
5867                 RAISE L_FND_EXC_ERROR;
5868             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5869                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5870             END IF;
5871             IF (l_response_int)
5872             THEN
5873                 l_debug_info := 'True';
5874             ELSE
5875                 l_debug_info := 'False';
5876                 l_response := l_response_int;
5877             END IF;
5878             INL_LOGGING_PVT.Log_Variable(
5879                 p_module_name    => g_module_name,
5880                 p_procedure_name => l_program_name,
5881                 p_var_name       => 'l_response_int',
5882                 p_var_value      => l_debug_info);
5883         END IF;
5884 
5885 
5886         IF p_validation_flag = 'Y'
5887         THEN
5888             l_debug_info := 'Call Validate_LandedCostFlag';
5889             INL_LOGGING_PVT.Log_Statement(
5890                 p_module_name      => g_module_name,
5891                 p_procedure_name   => l_program_name,
5892                 p_debug_info       => l_debug_info);
5893 
5894             l_response_int := Validate_LandedCostFlag(
5895                 p_ship_line_int_id      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
5896                 p_landed_cost_flag      => x_ship_ln_int_lst(l_ship_ln_int_idx).landed_cost_flag, -- # Bug 9866323 --ship_lin_int_list(p_line_index).landed_cost_flag,
5897                 x_return_status         => l_return_status);
5898 
5899             -- If any errors happen abort API.
5900             IF l_return_status = L_FND_RET_STS_ERROR THEN
5901                 RAISE L_FND_EXC_ERROR;
5902             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5903                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5904             END IF;
5905             IF (l_response_int)
5906             THEN
5907                 l_debug_info := 'True';
5908             ELSE
5909                 l_debug_info := 'False';
5910                 l_response := l_response_int;
5911             END IF;
5912             INL_LOGGING_PVT.Log_Variable(
5913                 p_module_name    => g_module_name,
5914                 p_procedure_name => l_program_name,
5915                 p_var_name       => 'l_response_int',
5916                 p_var_value      => l_debug_info);
5917 
5918             l_debug_info := 'Call Validate_AllocEnabledFlag';
5919             INL_LOGGING_PVT.Log_Statement(
5920                 p_module_name      => g_module_name,
5921                 p_procedure_name   => l_program_name,
5922                 p_debug_info       => l_debug_info);
5923 
5924             l_response_int := Validate_AllocEnabledFlag(
5925                 p_ship_line_int_id      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
5926                 p_alloc_enabled_flag    => x_ship_ln_int_lst(l_ship_ln_int_idx).allocation_enabled_flag, -- # Bug 9866323 ship_lin_int_list(p_line_index).allocation_enabled_flag,
5927                 x_return_status         => l_return_status);
5928 
5929             -- If any errors happen abort API.
5930             IF l_return_status = L_FND_RET_STS_ERROR THEN
5931                 RAISE L_FND_EXC_ERROR;
5932             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
5933                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
5934             END IF;
5935             IF (l_response_int)
5936             THEN
5937                 l_debug_info := 'True';
5938             ELSE
5939                 l_debug_info := 'False';
5940                 l_response := l_response_int;
5941             END IF;
5942             INL_LOGGING_PVT.Log_Variable(
5943                 p_module_name    => g_module_name,
5944                 p_procedure_name => l_program_name,
5945                 p_var_name       => 'l_response_int',
5946                 p_var_value      => l_debug_info);
5947 
5948         END IF;
5949     END LOOP;
5950 
5951     -- Standard End of Procedure/Function Logging
5952     INL_LOGGING_PVT.Log_EndProc(
5953         p_module_name    => g_module_name,
5954         p_procedure_name => l_program_name);
5955     RETURN l_response;
5956 EXCEPTION
5957     WHEN L_FND_EXC_ERROR THEN
5958         -- Standard Expected Error Logging
5959         INL_LOGGING_PVT.Log_ExpecError (
5960             p_module_name    => g_module_name,
5961             p_procedure_name => l_program_name);
5962         RETURN FND_API.to_boolean(L_FND_FALSE) ;
5963     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
5964         -- Standard Unexpected Error Logging
5965         INL_LOGGING_PVT.Log_UnexpecError (
5966             p_module_name    => g_module_name,
5967             p_procedure_name => l_program_name);
5968         RETURN FND_API.to_boolean(L_FND_FALSE) ;
5969     WHEN OTHERS THEN
5970         -- Standard Unexpected Error Logging
5971         INL_LOGGING_PVT.Log_UnexpecError (
5972             p_module_name    => g_module_name,
5973             p_procedure_name => l_program_name);
5974         IF FND_MSG_PUB.Check_Msg_Level(
5975             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
5976         ) THEN
5977             FND_MSG_PUB.Add_Exc_Msg(
5978                 p_pkg_name       => g_pkg_name,
5979                 p_procedure_name => l_program_name);
5980         END IF;
5981         RETURN FND_API.to_boolean(L_FND_FALSE) ;
5982 
5983 END  Validate_LnCreateTrxType;
5984 
5985 -- Utility name : Validate_RcvEnabledFlag
5986 -- Type       : Private
5987 -- Function   : Validate RCV enabled flag according to source
5988 --              defined in ship lines
5989 --
5990 -- Pre-reqs   : None
5991 -- Parameters :
5992 -- IN         : p_ship_header_int_id IN NUMBER
5993 --              p_transaction_type   IN VARCHAR2
5994 --              p_rcv_enabled_flag   IN VARCHAR2
5995 --
5996 -- IN OUT     : x_return_status      IN OUT NOCOPY VARCHAR2
5997 --
5998 -- Version    : Current version 1.0
5999 --
6000 -- Notes      :
6001 FUNCTION Validate_RcvEnabledFlag
6002        (p_ship_header_int_id IN NUMBER,
6003         p_rcv_enabled_flag   IN VARCHAR2,
6004         x_return_status      IN OUT NOCOPY VARCHAR2)
6005 RETURN BOOLEAN IS
6006     l_program_name               CONSTANT VARCHAR2(30) := 'Validate_RcvEnabledFlag';
6007     l_debug_info              VARCHAR2(400) ;
6008     l_response                BOOLEAN := TRUE;
6009     l_return_status           VARCHAR2(1) := L_FND_TRUE;
6010     l_ship_line_src_type_code VARCHAR2(10);
6011 
6012 BEGIN
6013     -- Standard Beginning of Procedure/Function Logging
6014     INL_LOGGING_PVT.Log_BeginProc(
6015         p_module_name    => g_module_name,
6016         p_procedure_name => l_program_name) ;
6017     --  Initialize API return status to success
6018     x_return_status      := L_FND_RET_STS_SUCCESS;
6019 
6020     l_debug_info := 'Validate RCV enabled flag';
6021     INL_LOGGING_PVT.Log_Statement(
6022         p_module_name      => g_module_name,
6023         p_procedure_name   => l_program_name,
6024         p_debug_info       => l_debug_info);
6025 
6026     INL_LOGGING_PVT.Log_Variable(
6027         p_module_name    => g_module_name,
6028         p_procedure_name => l_program_name,
6029         p_var_name       => 'p_rcv_enabled_flag',
6030         p_var_value      => p_rcv_enabled_flag);
6031 
6032     l_debug_info := 'Checking the source type against RCV enabled flag';
6033     INL_LOGGING_PVT.Log_Statement(
6034         p_module_name      => g_module_name,
6035         p_procedure_name   => l_program_name,
6036         p_debug_info       => l_debug_info);
6037 
6038     SELECT DISTINCT(sli.ship_line_src_type_code)
6039     INTO l_ship_line_src_type_code
6040     FROM inl_ship_lines_int sli
6041     WHERE sli.ship_header_int_id = p_ship_header_int_id;
6042 
6043     INL_LOGGING_PVT.Log_Variable(
6044         p_module_name    => g_module_name,
6045         p_procedure_name => l_program_name,
6046         p_var_name       => 'l_ship_line_src_type_code',
6047         p_var_value      => l_ship_line_src_type_code);
6048 
6049     IF p_rcv_enabled_flag = 'Y' THEN
6050         IF l_ship_line_src_type_code NOT IN ('PO', 'IR', 'RMA') THEN
6051              l_response := FALSE;
6052             -- Add a line into inl_ship_errors
6053             Handle_InterfError(
6054                 p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
6055                 p_parent_table_id    => p_ship_header_int_id,
6056                 p_column_name        => 'RCV_ENABLED_FLAG',
6057                 p_column_value       => p_rcv_enabled_flag,
6058                 p_error_message_name => 'INL_ERR_RECEIVED_SRC_LN_TYP',
6059                 p_token1_name        => 'SHIP_LN_SRC_TYPE_CODE',
6060                 p_token1_value       => l_ship_line_src_type_code,
6061                 p_token2_name        => 'ID_NAME',
6062                 p_token2_value       => 'INL_SHIP_HEADERS_INT',
6063                 p_token3_name        => 'ID_VAL',
6064                 p_token3_value       => p_ship_header_int_id,
6065                 x_return_status      => l_return_status) ;
6066             -- If unexpected errors happen abort
6067             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
6068                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
6069             END IF;
6070         END IF;
6071     ELSIF p_rcv_enabled_flag <> 'N' THEN
6072         l_response := FALSE;
6073         -- Add a line into inl_ship_errors
6074         Handle_InterfError(
6075             p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
6076             p_parent_table_id    => p_ship_header_int_id,
6077             p_column_name        => 'RCV_ENABLED_FLAG',
6078             p_column_value       => p_rcv_enabled_flag,
6079             p_error_message_name => 'INL_ERR_RCV_ENABLED_FLAG_INV',
6080             p_token1_name        => 'ID_NAME',
6081             p_token1_value       => 'INL_SHIP_HEADERS_INT',
6082             p_token2_name        => 'ID_VAL',
6083             p_token2_value       => p_ship_header_int_id,
6084             x_return_status      => l_return_status) ;
6085         -- If unexpected errors happen abort
6086         IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
6087             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6088         END IF;
6089     END IF;
6090     -- Standard End of Procedure/Function Logging
6091     INL_LOGGING_PVT.Log_EndProc(
6092         p_module_name    => g_module_name,
6093         p_procedure_name => l_program_name);
6094     RETURN l_response;
6095 EXCEPTION
6096     WHEN L_FND_EXC_ERROR THEN
6097         -- Standard Expected Error Logging
6098         INL_LOGGING_PVT.Log_ExpecError (
6099             p_module_name    => g_module_name,
6100             p_procedure_name => l_program_name);
6101         RETURN FND_API.to_boolean(L_FND_FALSE) ;
6102     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
6103         -- Standard Unexpected Error Logging
6104         INL_LOGGING_PVT.Log_UnexpecError (
6105             p_module_name    => g_module_name,
6106             p_procedure_name => l_program_name);
6107         RETURN FND_API.to_boolean(L_FND_FALSE) ;
6108     WHEN OTHERS THEN
6109         -- Standard Unexpected Error Logging
6110         INL_LOGGING_PVT.Log_UnexpecError (
6111             p_module_name    => g_module_name,
6112             p_procedure_name => l_program_name);
6113         IF FND_MSG_PUB.Check_Msg_Level(
6114             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
6115         ) THEN
6116             FND_MSG_PUB.Add_Exc_Msg(
6117                 p_pkg_name       => g_pkg_name,
6118                 p_procedure_name => l_program_name);
6119         END IF;
6120         RETURN FND_API.to_boolean(L_FND_FALSE) ;
6121 END Validate_RcvEnabledFlag;
6122 
6123 -- Utility name : Validate_HdrCreateTrxType
6124 -- Type       : Private
6125 -- Function   : Validate the CREATE transaction type
6126 --
6127 -- Pre-reqs   : None
6128 -- Parameters :
6129 -- IN         : p_ship_header_int_id    IN NUMBER
6130 --              p_ship_header_id        IN NUMBER
6131 --              p_ship_num              IN VARCHAR2
6132 --              p_ship_date             IN DATE
6133 --              p_ship_type_id          IN NUMBER
6134 --              p_ship_type_code        IN VARCHAR2
6135 --              p_rcv_enabled_flag      IN VARCHAR2
6136 --              p_organization_id       IN NUMBER
6137 --              p_organization_code     IN VARCHAR2
6138 --              p_last_task_code        IN VARCHAR2
6139 -- IN OUT     : x_return_status      IN OUT NOCOPY VARCHAR2
6140 --
6141 -- Version    : Current version 1.0
6142 --
6143 -- Notes
6144 FUNCTION Validate_HdrCreateTrxType(
6145         p_ship_header_int_id    IN NUMBER,
6146         p_ship_header_id        IN NUMBER,
6147         p_ship_num              IN VARCHAR2,
6148         p_ship_date             IN DATE,
6149         p_ship_type_id          IN NUMBER,
6150         p_ship_type_code        IN VARCHAR2,
6151         p_rcv_enabled_flag      IN VARCHAR2,
6152         p_organization_id       IN NUMBER,
6153         p_organization_code     IN VARCHAR2,
6154         p_last_task_code        IN VARCHAR2,
6155         x_return_status         IN OUT NOCOPY VARCHAR2
6156 )RETURN BOOLEAN IS
6157 
6158     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_HdrCreateTrxType';
6159     l_return_status VARCHAR2(1) ;
6160     l_debug_info    VARCHAR2(400) ;
6161     l_response      BOOLEAN := TRUE;
6162     l_response_int  BOOLEAN := TRUE;
6163     l_ship_line_int_id NUMBER;
6164 
6165 BEGIN
6166 
6167     -- Standard Beginning of Procedure/Function Logging
6168     INL_LOGGING_PVT.Log_BeginProc(
6169         p_module_name    => g_module_name,
6170         p_procedure_name => l_program_name) ;
6171     --  Initialize API return status to success
6172     x_return_status      := L_FND_RET_STS_SUCCESS;
6173     INL_LOGGING_PVT.Log_Variable(
6174         p_module_name    => g_module_name,
6175         p_procedure_name => l_program_name,
6176         p_var_name       => 'p_ship_header_int_id',
6177         p_var_value      => p_ship_header_int_id) ;
6178     INL_LOGGING_PVT.Log_Variable(
6179         p_module_name    => g_module_name,
6180         p_procedure_name => l_program_name,
6181         p_var_name       => 'p_ship_header_id',
6182         p_var_value      => p_ship_header_id) ;
6183     INL_LOGGING_PVT.Log_Variable(
6184         p_module_name    => g_module_name,
6185         p_procedure_name => l_program_name,
6186         p_var_name       => 'p_ship_num',
6187         p_var_value      => p_ship_num) ;
6188     INL_LOGGING_PVT.Log_Variable(
6189         p_module_name    => g_module_name,
6190         p_procedure_name => l_program_name,
6191         p_var_name       => 'p_ship_date',
6192         p_var_value      => p_ship_date) ;
6193     INL_LOGGING_PVT.Log_Variable(
6194         p_module_name    => g_module_name,
6195         p_procedure_name => l_program_name,
6196         p_var_name       => 'p_ship_type_id',
6197         p_var_value      => p_ship_type_id) ;
6198     INL_LOGGING_PVT.Log_Variable(
6199         p_module_name    => g_module_name,
6200         p_procedure_name => l_program_name,
6201         p_var_name       => 'p_ship_type_code',
6202         p_var_value      => p_ship_type_code) ;
6203     INL_LOGGING_PVT.Log_Variable(
6204         p_module_name    => g_module_name,
6205         p_procedure_name => l_program_name,
6206         p_var_name       => 'p_rcv_enabled_flag',
6207         p_var_value      => p_rcv_enabled_flag) ;
6208     INL_LOGGING_PVT.Log_Variable(
6209         p_module_name    => g_module_name,
6210         p_procedure_name => l_program_name,
6211         p_var_name       => 'p_organization_id',
6212         p_var_value      => p_organization_id) ;
6213     INL_LOGGING_PVT.Log_Variable(
6214         p_module_name    => g_module_name,
6215         p_procedure_name => l_program_name,
6216         p_var_name       => 'p_organization_code',
6217         p_var_value      => p_organization_code) ;
6218     INL_LOGGING_PVT.Log_Variable(
6219         p_module_name    => g_module_name,
6220         p_procedure_name => l_program_name,
6221         p_var_name       => 'p_last_task_code',
6222         p_var_value      => p_last_task_code) ;
6223 
6224     l_debug_info := 'Check columns for the CREATE transaction type (HDR)';
6225     INL_LOGGING_PVT.Log_Statement(
6226         p_module_name      => g_module_name,
6227         p_procedure_name   => l_program_name,
6228         p_debug_info       => l_debug_info);
6229 
6230     l_debug_info := 'Check for columns that should be populated and null for CREATE. ship_header_int_id: ' ||p_ship_header_int_id;
6231     INL_LOGGING_PVT.Log_Statement(
6232         p_module_name      => g_module_name,
6233         p_procedure_name   => l_program_name,
6234         p_debug_info       => l_debug_info);
6235 
6236     IF p_ship_date IS NULL THEN
6237         l_response := FALSE;
6238         -- Add a line into inl_ship_errors
6239         Handle_InterfError(
6240             p_parent_table_name => 'INL_SHIP_HEADERS_INT',
6241             p_parent_table_id   => p_ship_header_int_id,
6242             p_column_name       => 'TRANSACTION_TYPE',
6243             p_column_value      => 'CREATE',
6244             p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
6245             p_token1_name       => 'COLUMN',
6246             p_token1_value      => 'SHIP_DATE',
6247             p_token2_name       => 'ID_NAME',
6248             p_token2_value      => 'INL_SHIP_HEADERS_INT',
6249             p_token3_name       => 'ID_VAL',
6250             p_token3_value      => p_ship_header_int_id,
6251             x_return_status     => l_return_status) ;
6252         -- If any errors happen abort API.
6253         IF l_return_status = L_FND_RET_STS_ERROR THEN
6254             RAISE L_FND_EXC_ERROR;
6255         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6256             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6257         END IF;
6258     END IF;
6259 
6260     IF p_last_task_code IS NULL THEN
6261         l_response := FALSE;
6262         -- Add a line into inl_ship_errors
6263         Handle_InterfError(
6264             p_parent_table_name => 'INL_SHIP_HEADERS_INT',
6265             p_parent_table_id   => p_ship_header_int_id,
6266             p_column_name       => 'TRANSACTION_TYPE',
6267             p_column_value      => 'CREATE',
6268             p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
6269             p_token1_name       => 'COLUMN',
6270             p_token1_value      => 'LAST_TASK_CODE',
6271             p_token2_name       => 'ID_NAME',
6272             p_token2_value      => 'INL_SHIP_HEADERS_INT',
6273             p_token3_name       => 'ID_VAL',
6274             p_token3_value      => p_ship_header_int_id,
6275             x_return_status     => l_return_status) ;
6276         -- If any errors happen abort API.
6277         IF l_return_status = L_FND_RET_STS_ERROR THEN
6278             RAISE L_FND_EXC_ERROR;
6279         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6280             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6281         END IF;
6282     ELSIF p_last_task_code NOT IN ('10', '20', '30', '40', '50', '60') THEN
6283         l_response := FALSE;
6284         -- Add a line into inl_ship_errors
6285         Handle_InterfError(
6286             p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
6287             p_parent_table_id    => p_ship_header_int_id,
6288             p_column_name        => 'LAST_TASK_CODE',
6289             p_column_value       => p_last_task_code,
6290             p_error_message_name => 'INL_OI_LAST_TASK_CODE_INVL',
6291             p_token1_name        => 'LTC',
6292             p_token1_value       => p_last_task_code,
6293             x_return_status      => l_return_status);
6294 
6295         -- If unexpected errors happen abort
6296         IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
6297             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6298         END IF;
6299 
6300     END IF;
6301 
6302     IF p_ship_type_id   IS NULL AND
6303        p_ship_type_code IS NULL THEN
6304         l_response := FALSE;
6305         -- Add a line into inl_ship_errors
6306         Handle_InterfError(
6307             p_parent_table_name => 'INL_SHIP_HEADERS_INT',
6308             p_parent_table_id   => p_ship_header_int_id,
6309             p_column_name       => 'TRANSACTION_TYPE',
6310             p_column_value      => 'CREATE',
6311             p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
6312             p_token1_name       => 'COLUMN',
6313             p_token1_value      => 'SHIP_TYPE_ID OR SHIP_TYPE_CODE',
6314             p_token2_name       => 'ID_NAME',
6315             p_token2_value      => 'INL_SHIP_HEADERS_INT',
6316             p_token3_name       => 'ID_VAL',
6317             p_token3_value      => p_ship_header_int_id,
6318             x_return_status     => l_return_status) ;
6319         -- If any errors happen abort API.
6320         IF l_return_status = L_FND_RET_STS_ERROR THEN
6321             RAISE L_FND_EXC_ERROR;
6322         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6323             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6324         END IF;
6325     END IF;
6326 
6327     IF p_organization_id IS NULL AND
6328        p_organization_code IS NULL THEN
6329         l_response := FALSE;
6330         -- Add a line into inl_ship_errors
6331         Handle_InterfError(
6332             p_parent_table_name => 'INL_SHIP_HEADERS_INT',
6333             p_parent_table_id   => p_ship_header_int_id,
6334             p_column_name       => 'TRANSACTION_TYPE',
6335             p_column_value      => 'CREATE',
6336             p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
6337             p_token1_name       => 'COLUMN',
6338             p_token1_value      => 'ORGANIZATION_ID or ORGANIZATION_CODE',
6339             p_token2_name       => 'ID_NAME',
6340             p_token2_value      => 'INL_SHIP_HEADERS_INT',
6341             p_token3_name       => 'ID_VAL',
6342             p_token3_value      => p_ship_header_int_id,
6343             x_return_status     => l_return_status) ;
6344         -- If any errors happen abort API.
6345         IF l_return_status = L_FND_RET_STS_ERROR THEN
6346             RAISE L_FND_EXC_ERROR;
6347         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6348             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6349         END IF;
6350     END IF;
6351 
6352     IF p_rcv_enabled_flag IS NULL  THEN
6353         l_response := FALSE;
6354         -- Add a line into inl_ship_errors
6355         Handle_InterfError(
6356             p_parent_table_name => 'INL_SHIP_HEADERS_INT',
6357             p_parent_table_id   => p_ship_header_int_id,
6358             p_column_name       => 'TRANSACTION_TYPE',
6359             p_column_value      => 'CREATE',
6360             p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
6361             p_token1_name       => 'COLUMN',
6362             p_token1_value      => 'RCV_ENABLED_FLAG',
6363             p_token2_name       => 'ID_NAME',
6364             p_token2_value      => 'INL_SHIP_HEADERS_INT',
6365             p_token3_name       => 'ID_VAL',
6366             p_token3_value      => p_ship_header_int_id,
6367             x_return_status     => l_return_status) ;
6368         -- If any errors happen abort API.
6369         IF l_return_status = L_FND_RET_STS_ERROR THEN
6370             RAISE L_FND_EXC_ERROR;
6371         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6372             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6373         END IF;
6374     ELSE
6375         l_debug_info := 'Call Validate_RcvEnabledFlag';
6376         INL_LOGGING_PVT.Log_Statement(
6377             p_module_name      => g_module_name,
6378             p_procedure_name   => l_program_name,
6379             p_debug_info       => l_debug_info);
6380 
6381         l_response_int := Validate_RcvEnabledFlag
6382            (p_ship_header_int_id => p_ship_header_int_id,
6383             p_rcv_enabled_flag   => p_rcv_enabled_flag,
6384             x_return_status      => l_return_status);
6385 
6386         -- If any errors happen abort API.
6387         IF l_return_status = L_FND_RET_STS_ERROR THEN
6388             RAISE L_FND_EXC_ERROR;
6389         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6390             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6391         END IF;
6392         IF (l_response_int)
6393         THEN
6394             l_debug_info := 'True';
6395         ELSE
6396             l_debug_info := 'False';
6397             l_response := l_response_int;
6398         END IF;
6399         INL_LOGGING_PVT.Log_Variable(
6400             p_module_name    => g_module_name,
6401             p_procedure_name => l_program_name,
6402             p_var_name       => 'l_response_int',
6403             p_var_value      => l_debug_info);
6404 
6405     END IF;
6406 
6407     IF p_ship_header_id IS NOT NULL THEN
6408         l_response := FALSE;
6409         -- Add a line into inl_ship_errors
6410         Handle_InterfError(
6411             p_parent_table_name => 'INL_SHIP_HEADERS_INT',
6412             p_parent_table_id   => p_ship_header_int_id,
6413             p_column_name       => 'TRANSACTION_TYPE',
6414             p_column_value      => 'CREATE',
6415             p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
6416             p_token1_name       => 'COLUMN',
6417             p_token1_value      => 'SHIP_HEADER_ID',
6418             p_token2_name       => 'ID_NAME',
6419             p_token2_value      => 'INL_SHIP_HEADERS_INT',
6420             p_token3_name       => 'ID_VAL',
6421             p_token3_value      => p_ship_header_int_id,
6422             x_return_status     => l_return_status) ;
6423         -- If any errors happen abort API.
6424         IF l_return_status = L_FND_RET_STS_ERROR THEN
6425             RAISE L_FND_EXC_ERROR;
6426         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6427             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6428         END IF;
6429     END IF;
6430 
6431 
6432     -- Standard End of Procedure/Function Logging
6433     INL_LOGGING_PVT.Log_EndProc(
6434         p_module_name    => g_module_name,
6435         p_procedure_name => l_program_name);
6436     RETURN l_response;
6437 EXCEPTION
6438     WHEN L_FND_EXC_ERROR THEN
6439         -- Standard Expected Error Logging
6440         INL_LOGGING_PVT.Log_ExpecError (
6441             p_module_name    => g_module_name,
6442             p_procedure_name => l_program_name);
6443         RETURN FND_API.to_boolean(L_FND_FALSE) ;
6444     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
6445         -- Standard Unexpected Error Logging
6446         INL_LOGGING_PVT.Log_UnexpecError (
6447             p_module_name    => g_module_name,
6448             p_procedure_name => l_program_name);
6449         RETURN FND_API.to_boolean(L_FND_FALSE) ;
6450     WHEN OTHERS THEN
6451         -- Standard Unexpected Error Logging
6452         INL_LOGGING_PVT.Log_UnexpecError (
6453             p_module_name    => g_module_name,
6454             p_procedure_name => l_program_name);
6455         IF FND_MSG_PUB.Check_Msg_Level(
6456             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
6457         ) THEN
6458             FND_MSG_PUB.Add_Exc_Msg(
6459                 p_pkg_name       => g_pkg_name,
6460                 p_procedure_name => l_program_name);
6461         END IF;
6462         RETURN FND_API.to_boolean(L_FND_FALSE) ;
6463 
6464 END  Validate_HdrCreateTrxType;
6465 
6466 -- Utility name : Validate_HdrUpdateTrxType
6467 -- Type       : Private
6468 -- Function   : Validate the UPDATE transaction type
6469 --
6470 -- Pre-reqs   : None
6471 -- Parameters :
6472 -- IN         : p_ship_header_int_id IN NUMBER
6473 --              p_organization_id    IN NUMBER
6474 --              p_organization_code  IN VARCHAR2(3)
6475 --              p_ship_type_id       IN NUMBER
6476 --              p_ship_type_code     IN VARCHAR2(15)
6477 --              p_location_id        IN NUMBER
6478 --              p_location_code      IN VARCHAR2(60)
6479 --              p_rcv_enabled_flag   IN VARCHAR2(1)
6480 -- IN OUT     : x_return_status      IN OUT NOCOPY VARCHAR2
6481 --              x_ship_header_id     IN OUT NOCOPY NUMBER
6482 --              p_ship_num           IN OUT NOCOPY VARCHAR2(25)
6483 --
6484 -- Version    : Current version 1.0
6485 --
6486 -- Notes
6487 FUNCTION Validate_HdrUpdateTrxType(
6488         p_ship_header_int_id IN NUMBER,
6489         p_organization_id    IN NUMBER,
6490         p_organization_code  IN VARCHAR2,
6491         p_ship_type_id       IN NUMBER,
6492         p_ship_type_code     IN VARCHAR2,
6493         p_location_id        IN NUMBER,
6494         p_location_code      IN VARCHAR2,
6495         p_rcv_enabled_flag   IN VARCHAR2,
6496         x_ship_num           IN OUT NOCOPY VARCHAR2,
6497         x_ship_header_id     IN OUT NOCOPY NUMBER,
6498         x_return_status      IN OUT NOCOPY VARCHAR2
6499 ) RETURN BOOLEAN IS
6500 
6501     l_program_name        CONSTANT VARCHAR2(30) := 'Validate_HdrUpdateTrxType';
6502     l_return_status    VARCHAR2(1) ;
6503     l_debug_info       VARCHAR2(400) ;
6504     l_response         BOOLEAN := TRUE;
6505     l_ship_status_code VARCHAR2(30);
6506     l_organization_id  NUMBER;
6507     l_ship_line_int_id NUMBER;
6508 BEGIN
6509 
6510     -- Standard Beginning of Procedure/Function Logging
6511     INL_LOGGING_PVT.Log_BeginProc(
6512         p_module_name    => g_module_name,
6513         p_procedure_name => l_program_name) ;
6514     --  Initialize API return status to success
6515     x_return_status      := L_FND_RET_STS_SUCCESS;
6516 
6517     l_debug_info := 'Check columns for the UPDATE transaction type';
6518     INL_LOGGING_PVT.Log_Statement(
6519         p_module_name      => g_module_name,
6520         p_procedure_name   => l_program_name,
6521         p_debug_info       => l_debug_info);
6522 
6523     INL_LOGGING_PVT.Log_Variable(
6524         p_module_name    => g_module_name,
6525         p_procedure_name => l_program_name,
6526         p_var_name       => 'p_ship_header_int_id',
6527         p_var_value      => p_ship_header_int_id) ;
6528     INL_LOGGING_PVT.Log_Variable(
6529         p_module_name    => g_module_name,
6530         p_procedure_name => l_program_name,
6531         p_var_name       => 'x_ship_num',
6532         p_var_value      => x_ship_num) ;
6533     INL_LOGGING_PVT.Log_Variable(
6534         p_module_name    => g_module_name,
6535         p_procedure_name => l_program_name,
6536         p_var_name       => 'p_organization_id',
6537         p_var_value      => p_organization_id) ;
6538     INL_LOGGING_PVT.Log_Variable(
6539         p_module_name    => g_module_name,
6540         p_procedure_name => l_program_name,
6541         p_var_name       => 'p_organization_code',
6542         p_var_value      => p_organization_code) ;
6543     INL_LOGGING_PVT.Log_Variable(
6544         p_module_name    => g_module_name,
6545         p_procedure_name => l_program_name,
6546         p_var_name       => 'p_ship_type_id',
6547         p_var_value      => p_ship_type_id) ;
6548     INL_LOGGING_PVT.Log_Variable(
6549         p_module_name    => g_module_name,
6550         p_procedure_name => l_program_name,
6551         p_var_name       => 'p_ship_type_code',
6552         p_var_value      => p_ship_type_code) ;
6553     INL_LOGGING_PVT.Log_Variable(
6554         p_module_name    => g_module_name,
6555         p_procedure_name => l_program_name,
6556         p_var_name       => 'p_location_id',
6557         p_var_value      => p_location_id) ;
6558     INL_LOGGING_PVT.Log_Variable(
6559         p_module_name    => g_module_name,
6560         p_procedure_name => l_program_name,
6561         p_var_name       => 'p_location_code',
6562         p_var_value      => p_location_code) ;
6563     INL_LOGGING_PVT.Log_Variable(
6564         p_module_name    => g_module_name,
6565         p_procedure_name => l_program_name,
6566         p_var_name       => 'p_rcv_enabled_flag',
6567         p_var_value      => p_rcv_enabled_flag) ;
6568     INL_LOGGING_PVT.Log_Variable(
6569         p_module_name    => g_module_name,
6570         p_procedure_name => l_program_name,
6571         p_var_name       => 'x_ship_header_id',
6572         p_var_value      => x_ship_header_id) ;
6573 
6574 --    1- In order to identify the shipment ship_header_id should be informed OR (ship_num + (organization))
6575 
6576     IF x_ship_header_id IS NOT NULL
6577     THEN
6578         BEGIN
6579             SELECT
6580                 sh.ship_status_code
6581             INTO
6582                 l_ship_status_code
6583             FROM inl_ship_headers_all sh --Bug#10381495
6584             WHERE sh.ship_header_id = x_ship_header_id;
6585             x_ship_num := NULL;
6586         EXCEPTION
6587             WHEN NO_DATA_FOUND THEN
6588                 l_debug_info := 'x_ship_header_id: ' || x_ship_header_id || ' not found in inl_ship_headers_all';
6589                 INL_LOGGING_PVT.Log_Statement(
6590                     p_module_name      => g_module_name,
6591                     p_procedure_name   => l_program_name,
6592                     p_debug_info       => l_debug_info);
6593                 l_response := FALSE;
6594                 -- Add a line into inl_ship_errors
6595                 Handle_InterfError(
6596                     p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
6597                     p_parent_table_id    => p_ship_header_int_id,
6598                     p_column_name        => 'TRANSACTION_TYPE',
6599                     p_column_value       => 'UPDATE',
6600                     p_error_message_name => 'INL_ERR_OI_CHK_SHIP_HEADER_ID',
6601                     p_token1_name        => 'NAME',
6602                     p_token1_value       => 'INL_SHIP_HEADERS_INT',
6603                     p_token2_name        => 'ID',
6604                     p_token2_value       => p_ship_header_int_id,
6605                     x_return_status      => l_return_status);
6606                 -- If any errors happen abort API.
6607                 IF l_return_status = L_FND_RET_STS_ERROR THEN
6608                     RAISE L_FND_EXC_ERROR;
6609                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6610                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
6611                 END IF;
6612         END;
6613 
6614     ELSIF x_ship_num IS NULL
6615         OR p_organization_id IS NULL
6616     THEN
6617         l_response := FALSE;
6618         -- Add a line into inl_ship_errors
6619         Handle_InterfError(
6620             p_parent_table_name => 'INL_SHIP_HEADERS_INT',
6621             p_parent_table_id   => p_ship_header_int_id,
6622             p_column_name       => 'TRANSACTION_TYPE',
6623             p_column_value      => 'UPDATE',
6624             p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
6625             p_token1_name       => 'COLUMN',
6626             p_token1_value      => 'SHIP_HEADER_ID OR SHIP_NUM+ORG',
6627             p_token2_name       => 'ID_NAME',
6628             p_token2_value      => 'INL_SHIP_HEADERS_INT',
6629             p_token3_name       => 'ID_VAL',
6630             p_token3_value      => p_ship_header_int_id,
6631             x_return_status     => l_return_status) ;
6632         -- If any errors happen abort API.
6633         IF l_return_status = L_FND_RET_STS_ERROR THEN
6634             RAISE L_FND_EXC_ERROR;
6635         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6636             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6637         END IF;
6638     ELSE
6639         l_debug_info := 'Get shipment information : '|| x_ship_num  ;
6640         INL_LOGGING_PVT.Log_Statement(
6641             p_module_name      => g_module_name,
6642             p_procedure_name   => l_program_name,
6643             p_debug_info       => l_debug_info);
6644 
6645         BEGIN
6646             SELECT
6647                 sh.ship_status_code,
6648                 sh.ship_header_id
6649             INTO
6650                 l_ship_status_code,
6651                 x_ship_header_id
6652             FROM inl_ship_headers_all sh --Bug#10381495
6653             WHERE sh.ship_num = x_ship_num
6654             AND organization_id = l_organization_id;
6655         EXCEPTION
6656             WHEN NO_DATA_FOUND THEN
6657                 l_debug_info := 'Invalid reference to the Shipment: ' || x_ship_num ||
6658                                 ' and Organization: ' || l_organization_id ;
6659                 INL_LOGGING_PVT.Log_Statement(
6660                     p_module_name      => g_module_name,
6661                     p_procedure_name   => l_program_name,
6662                     p_debug_info       => l_debug_info);
6663                 l_response := FALSE;
6664                 -- Add a line into inl_ship_errors
6665                 Handle_InterfError(
6666                     p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
6667                     p_parent_table_id    => p_ship_header_int_id,
6668                     p_column_name        => 'TRANSACTION_TYPE',
6669                     p_column_value       => 'UPDATE',
6670                     p_error_message_name => 'INL_ERR_NO_SHIP_NUM',
6671                     p_token1_name        => 'SHIP_NUM',
6672                     p_token1_value       => x_ship_num,
6673                     p_token2_name        => 'ORGANIZATION_ID',
6674                     p_token2_value       => l_organization_id,
6675                     x_return_status      => l_return_status);
6676                 -- If any errors happen abort API.
6677                 IF l_return_status = L_FND_RET_STS_ERROR THEN
6678                     RAISE L_FND_EXC_ERROR;
6679                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6680                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
6681                 END IF;
6682         END;
6683 
6684     END IF;
6685     IF (l_response)
6686     THEN
6687         l_debug_info := 'Continuing';
6688     ELSE
6689         l_debug_info := 'Header has validation problem.';
6690     END IF;
6691     INL_LOGGING_PVT.Log_Statement(
6692         p_module_name      => g_module_name,
6693         p_procedure_name   => l_program_name,
6694         p_debug_info       => l_debug_info);
6695 
6696     IF l_response THEN
6697         IF l_ship_status_code = 'COMPLETED' THEN
6698             l_debug_info := 'COMPLETED Shipments cannot be updated';
6699             INL_LOGGING_PVT.Log_Statement(
6700                 p_module_name      => g_module_name,
6701                 p_procedure_name   => l_program_name,
6702                 p_debug_info       => l_debug_info);
6703 
6704             l_response := FALSE;
6705             -- Add a line into inl_ship_errors
6706             Handle_InterfError(
6707                 p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
6708                 p_parent_table_id    => p_ship_header_int_id,
6709                 p_column_name        => 'TRANSACTION_TYPE',
6710                 p_column_value       => 'UPDATE',
6711                 p_error_message_name => 'INL_ERR_OI_CHK_TRX_TP_STA_INVL',
6712                 p_token1_name        => 'SHIP_HEADER_INT_ID',
6713                 p_token1_value       => p_ship_header_int_id,
6714                 x_return_status      => l_return_status) ;
6715             -- If any errors happen abort API.
6716             IF l_return_status = L_FND_RET_STS_ERROR THEN
6717                 RAISE L_FND_EXC_ERROR;
6718             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6719                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
6720             END IF;
6721             RETURN FALSE;
6722         END IF;
6723     END IF;
6724 
6725     IF p_ship_type_id IS NOT NULL OR
6726         p_ship_type_code IS NOT NULL THEN
6727         l_response := FALSE;
6728         -- Add a line into inl_ship_errors
6729         Handle_InterfError(
6730             p_parent_table_name => 'INL_SHIP_HEADERS_INT',
6731             p_parent_table_id   => p_ship_header_int_id,
6732             p_column_name       => 'TRANSACTION_TYPE',
6733             p_column_value      => 'UPDATE',
6734             p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
6735             p_token1_name       => 'COLUMN',
6736             p_token1_value      => 'SHIP_TYPE_ID AND SHIP_TYPE_CODE',
6737             p_token2_name       => 'ID_NAME',
6738             p_token2_value      => 'INL_SHIP_HEADERS_INT',
6739             p_token3_name       => 'ID_VAL',
6740             p_token3_value      => p_ship_header_int_id,
6741             x_return_status     => l_return_status) ;
6742         -- If any errors happen abort API.
6743         IF l_return_status = L_FND_RET_STS_ERROR THEN
6744             RAISE L_FND_EXC_ERROR;
6745         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6746             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6747         END IF;
6748     END IF;
6749 
6750     IF p_location_id IS NOT NULL OR
6751         p_location_code IS NOT NULL THEN
6752         l_response := FALSE;
6753         -- Add a line into inl_ship_errors
6754         Handle_InterfError(
6755             p_parent_table_name => 'INL_SHIP_HEADERS_INT',
6756             p_parent_table_id   => p_ship_header_int_id,
6757             p_column_name       => 'TRANSACTION_TYPE',
6758             p_column_value      => 'UPDATE',
6759             p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
6760             p_token1_name       => 'COLUMN',
6761             p_token1_value      => 'LOCATION_ID AND LOCATION_CODE',
6762             p_token2_name       => 'ID_NAME',
6763             p_token2_value      => 'INL_SHIP_HEADERS_INT',
6764             p_token3_name       => 'ID_VAL',
6765             p_token3_value      => p_ship_header_int_id,
6766             x_return_status     => l_return_status) ;
6767         -- If any errors happen abort API.
6768         IF l_return_status = L_FND_RET_STS_ERROR THEN
6769             RAISE L_FND_EXC_ERROR;
6770         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6771             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6772         END IF;
6773     END IF;
6774 
6775     IF p_rcv_enabled_flag IS NOT NULL THEN
6776         l_response := FALSE;
6777         -- Add a line into inl_ship_errors
6778         Handle_InterfError(
6779             p_parent_table_name => 'INL_SHIP_HEADERS_INT',
6780             p_parent_table_id   => p_ship_header_int_id,
6781             p_column_name       => 'TRANSACTION_TYPE',
6782             p_column_value      => 'UPDATE',
6783             p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
6784             p_token1_name       => 'COLUMN',
6785             p_token1_value      => 'RCV_ENABLED_FLAG',
6786             p_token2_name       => 'ID_NAME',
6787             p_token2_value      => 'INL_SHIP_HEADERS_INT',
6788             p_token3_name       => 'ID_VAL',
6789             p_token3_value      => p_ship_header_int_id,
6790             x_return_status     => l_return_status) ;
6791         -- If any errors happen abort API.
6792         IF l_return_status = L_FND_RET_STS_ERROR THEN
6793             RAISE L_FND_EXC_ERROR;
6794         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
6795             RAISE L_FND_EXC_UNEXPECTED_ERROR;
6796         END IF;
6797     END IF;
6798 
6799     -- Standard End of Procedure/Function Logging
6800     INL_LOGGING_PVT.Log_EndProc(
6801         p_module_name    => g_module_name,
6802         p_procedure_name => l_program_name);
6803     RETURN l_response;
6804 EXCEPTION
6805     WHEN L_FND_EXC_ERROR THEN
6806         -- Standard Expected Error Logging
6807         INL_LOGGING_PVT.Log_ExpecError (
6808             p_module_name    => g_module_name,
6809             p_procedure_name => l_program_name);
6810         RETURN FND_API.to_boolean(L_FND_FALSE) ;
6811     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
6812         -- Standard Unexpected Error Logging
6813         INL_LOGGING_PVT.Log_UnexpecError (
6814             p_module_name    => g_module_name,
6815             p_procedure_name => l_program_name);
6816         RETURN FND_API.to_boolean(L_FND_FALSE) ;
6817     WHEN OTHERS THEN
6818         -- Standard Unexpected Error Logging
6819         INL_LOGGING_PVT.Log_UnexpecError (
6820             p_module_name    => g_module_name,
6821             p_procedure_name => l_program_name);
6822         IF FND_MSG_PUB.Check_Msg_Level(
6823             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
6824         ) THEN
6825             FND_MSG_PUB.Add_Exc_Msg(
6826                 p_pkg_name       => g_pkg_name,
6827                 p_procedure_name => l_program_name);
6828         END IF;
6829         RETURN FND_API.to_boolean(L_FND_FALSE) ;
6830 END  Validate_HdrUpdateTrxType;
6831 
6832 -- Utility name : Validate_LnUpdateTrxType
6833 -- Type       : Private
6834 -- Function   : Validate the UPDATE transaction type
6835 --
6836 -- Pre-reqs   : None
6837 -- Parameters :
6838 -- IN         :
6839 --             p_validation_flag   IN VARCHAR2,
6840 --             p_ship_header_id    IN NUMBER,
6841 --             p_organization_id   IN NUMBER,
6842 --             p_interface_source_code IN VARCHAR2,
6843 --
6844 -- IN OUT     : x_ship_ln_int_lst  IN OUT NOCOPY ship_ln_int_list_type,
6845 --              x_return_status    IN OUT NOCOPY VARCHAR2
6846 --
6847 -- Version    : Current version 1.0
6848 --
6849 -- Notes
6850 FUNCTION Validate_LnUpdateTrxType(
6851         p_validation_flag   IN VARCHAR2,
6852         p_ship_header_id    IN NUMBER,
6853         p_organization_id   IN NUMBER,
6854         p_interface_source_code IN VARCHAR2,
6855         x_ship_ln_int_lst   IN OUT NOCOPY ship_ln_int_list_type,
6856         x_return_status     OUT NOCOPY VARCHAR2
6857 )RETURN BOOLEAN IS
6858 
6859     l_program_name        CONSTANT VARCHAR2(30) := 'Validate_LnUpdateTrxType';
6860     l_return_status    VARCHAR2(1) ;
6861     l_debug_info       VARCHAR2(400) ;
6862     l_response         BOOLEAN := TRUE;
6863     l_response_int     BOOLEAN := TRUE;
6864 
6865     l_ship_line_int_id NUMBER;
6866     l_validate_txn_uom_code BOOLEAN := TRUE;
6867 
6868 BEGIN
6869 
6870     -- Standard Beginning of Procedure/Function Logging
6871     INL_LOGGING_PVT.Log_BeginProc(
6872         p_module_name    => g_module_name,
6873         p_procedure_name => l_program_name) ;
6874     --  Initialize API return status to success
6875     x_return_status      := L_FND_RET_STS_SUCCESS;
6876 
6877     l_debug_info := 'Check columns for the UPDATE transaction type';
6878     INL_LOGGING_PVT.Log_Statement(
6879         p_module_name      => g_module_name,
6880         p_procedure_name   => l_program_name,
6881         p_debug_info       => l_debug_info);
6882 
6883     l_debug_info := 'Check for columns that should be populated or null for UPDATE.';
6884     INL_LOGGING_PVT.Log_Statement(
6885         p_module_name      => g_module_name,
6886         p_procedure_name   => l_program_name,
6887         p_debug_info       => l_debug_info);
6888 
6889 
6890     FOR l_ship_ln_int_idx IN 1 .. x_ship_ln_int_lst.COUNT
6891     LOOP
6892         l_ship_line_int_id := x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id;
6893         l_debug_info := 'Check ship_line_int_id: ' || l_ship_line_int_id;
6894         INL_LOGGING_PVT.Log_Statement(
6895             p_module_name      => g_module_name,
6896             p_procedure_name   => l_program_name,
6897             p_debug_info       => l_debug_info);
6898 
6899 
6900         INL_LOGGING_PVT.Log_Variable(
6901             p_module_name    => g_module_name,
6902             p_procedure_name => l_program_name,
6903             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).currency_code ',
6904             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).currency_code) ;
6905 
6906         INL_LOGGING_PVT.Log_Variable(
6907             p_module_name    => g_module_name,
6908             p_procedure_name => l_program_name,
6909             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_date ',
6910             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_date) ;
6911         INL_LOGGING_PVT.Log_Variable(
6912             p_module_name    => g_module_name,
6913             p_procedure_name => l_program_name,
6914             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_rate ',
6915             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_rate) ;
6916         INL_LOGGING_PVT.Log_Variable(
6917             p_module_name    => g_module_name,
6918             p_procedure_name => l_program_name,
6919             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_type ',
6920             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_type) ;
6921         INL_LOGGING_PVT.Log_Variable(
6922             p_module_name    => g_module_name,
6923             p_procedure_name => l_program_name,
6924             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_id ',
6925             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_id) ;
6926         INL_LOGGING_PVT.Log_Variable(
6927             p_module_name    => g_module_name,
6928             p_procedure_name => l_program_name,
6929             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_name ',
6930             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_name) ;
6931         INL_LOGGING_PVT.Log_Variable(
6932             p_module_name    => g_module_name,
6933             p_procedure_name => l_program_name,
6934             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).party_id ',
6935             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).party_id) ;
6936         INL_LOGGING_PVT.Log_Variable(
6937             p_module_name    => g_module_name,
6938             p_procedure_name => l_program_name,
6939             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).party_number ',
6940             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).party_number) ;
6941         INL_LOGGING_PVT.Log_Variable(
6942             p_module_name    => g_module_name,
6943             p_procedure_name => l_program_name,
6944             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_id ',
6945             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_id) ;
6946         INL_LOGGING_PVT.Log_Variable(
6947             p_module_name    => g_module_name,
6948             p_procedure_name => l_program_name,
6949             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_number ',
6950             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_number) ;
6951         INL_LOGGING_PVT.Log_Variable(
6952             p_module_name    => g_module_name,
6953             p_procedure_name => l_program_name,
6954             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_id ',
6955             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_id) ;
6956         INL_LOGGING_PVT.Log_Variable(
6957             p_module_name    => g_module_name,
6958             p_procedure_name => l_program_name,
6959             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_num ',
6960             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_num) ;
6961         INL_LOGGING_PVT.Log_Variable(
6962             p_module_name    => g_module_name,
6963             p_procedure_name => l_program_name,
6964             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id ',
6965             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id) ;
6966         INL_LOGGING_PVT.Log_Variable(
6967             p_module_name    => g_module_name,
6968             p_procedure_name => l_program_name,
6969             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num ',
6970             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num) ;
6971         INL_LOGGING_PVT.Log_Variable(
6972             p_module_name    => g_module_name,
6973             p_procedure_name => l_program_name,
6974             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_source_id ',
6975             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_source_id) ;
6976         INL_LOGGING_PVT.Log_Variable(
6977             p_module_name    => g_module_name,
6978             p_procedure_name => l_program_name,
6979             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code ',
6980             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code) ;
6981         INL_LOGGING_PVT.Log_Variable(
6982             p_module_name    => g_module_name,
6983             p_procedure_name => l_program_name,
6984             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_code ',
6985             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_code) ;
6986         INL_LOGGING_PVT.Log_Variable(
6987             p_module_name    => g_module_name,
6988             p_procedure_name => l_program_name,
6989             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_id ',
6990             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_id) ;
6991         INL_LOGGING_PVT.Log_Variable(
6992             p_module_name    => g_module_name,
6993             p_procedure_name => l_program_name,
6994             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_code ',
6995             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_code) ;
6996         INL_LOGGING_PVT.Log_Variable(
6997             p_module_name    => g_module_name,
6998             p_procedure_name => l_program_name,
6999             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_id ',
7000             p_var_value      =>  x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_id) ;
7001 
7002         l_debug_info := 'Checking ship_line_id and ship_line_group_id ';
7003         INL_LOGGING_PVT.Log_Statement(
7004             p_module_name      => g_module_name,
7005             p_procedure_name   => l_program_name,
7006             p_debug_info       => l_debug_info);
7007 
7008         IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id IS NULL AND
7009            x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_id IS NULL AND
7010            x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_num IS NULL THEN
7011             l_response := FALSE;
7012             -- Add a line into inl_ship_errors
7013             Handle_InterfError(
7014                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7015                 p_parent_table_id   => l_ship_line_int_id,
7016                 p_column_name       => 'TRANSACTION_TYPE',
7017                 p_column_value      => 'UPDATE',
7018                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
7019                 p_token1_name       => 'COLUMN',
7020                 p_token1_value      => 'SHIP_LINE_GROUP_ID OR SHIP_LINE_GROUP_NUM',
7021                 p_token2_name       => 'ID_NAME',
7022                 p_token2_value      => 'INL_SHIP_LINES_INT',
7023                 p_token3_name       => 'ID_VAL',
7024                 p_token3_value      => l_ship_line_int_id,
7025                 x_return_status     => l_return_status) ;
7026             -- If any errors happen abort API.
7027             IF l_return_status = L_FND_RET_STS_ERROR THEN
7028                 RAISE L_FND_EXC_ERROR;
7029             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7030                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7031             END IF;
7032         END IF;
7033 
7034         l_debug_info := 'Checking ship_line_id and ship_line_num ';
7035         INL_LOGGING_PVT.Log_Statement(
7036             p_module_name      => g_module_name,
7037             p_procedure_name   => l_program_name,
7038             p_debug_info       => l_debug_info);
7039 
7040         IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id IS NULL AND
7041            x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num IS NULL THEN
7042             l_response := FALSE;
7043             -- Add a line into inl_ship_errors
7044             Handle_InterfError(
7045                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7046                 p_parent_table_id   => l_ship_line_int_id,
7047                 p_column_name       => 'TRANSACTION_TYPE',
7048                 p_column_value      => 'UPDATE',
7049                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NULL',
7050                 p_token1_name       => 'COLUMN',
7051                 p_token1_value      => 'SHIP_LINE_ID OR SHIP_LINE_NUM',
7052                 p_token2_name       => 'ID_NAME',
7053                 p_token2_value      => 'INL_SHIP_LINES_INT',
7054                 p_token3_name       => 'ID_VAL',
7055                 p_token3_value      => l_ship_line_int_id,
7056                 x_return_status     => l_return_status) ;
7057             -- If any errors happen abort API.
7058             IF l_return_status = L_FND_RET_STS_ERROR THEN
7059                 RAISE L_FND_EXC_ERROR;
7060             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7061                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7062             END IF;
7063         END IF;
7064 
7065         l_debug_info := 'Checking parties ';
7066         INL_LOGGING_PVT.Log_Statement(
7067             p_module_name      => g_module_name,
7068             p_procedure_name   => l_program_name,
7069             p_debug_info       => l_debug_info);
7070        IF x_ship_ln_int_lst(l_ship_ln_int_idx).party_id IS NOT NULL OR
7071            x_ship_ln_int_lst(l_ship_ln_int_idx).party_number IS NOT NULL THEN
7072             l_response := FALSE;
7073             -- Add a line into inl_ship_errors
7074             Handle_InterfError(
7075                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7076                 p_parent_table_id   => l_ship_line_int_id,
7077                 p_column_name       => 'TRANSACTION_TYPE',
7078                 p_column_value      => 'UPDATE',
7079                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
7080                 p_token1_name       => 'COLUMN',
7081                 p_token1_value      => 'PARTY_ID AND PARTY_NUMBER',
7082                 p_token2_name       => 'ID_NAME',
7083                 p_token2_value      => 'INL_SHIP_LINES_INT',
7084                 p_token3_name       => 'ID_VAL',
7085                 p_token3_value      => l_ship_line_int_id,
7086                 x_return_status     => l_return_status) ;
7087             -- If any errors happen abort API.
7088             IF l_return_status = L_FND_RET_STS_ERROR THEN
7089                 RAISE L_FND_EXC_ERROR;
7090             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7091                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7092             END IF;
7093         END IF;
7094 
7095         l_debug_info := 'Checking party site ';
7096         INL_LOGGING_PVT.Log_Statement(
7097             p_module_name      => g_module_name,
7098             p_procedure_name   => l_program_name,
7099             p_debug_info       => l_debug_info);
7100         IF x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_id IS NOT NULL OR
7101            x_ship_ln_int_lst(l_ship_ln_int_idx).party_site_number IS NOT NULL THEN
7102             l_response := FALSE;
7103             -- Add a line into inl_ship_errors
7104             Handle_InterfError(
7105                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7106                 p_parent_table_id   => l_ship_line_int_id,
7107                 p_column_name       => 'TRANSACTION_TYPE',
7108                 p_column_value      => 'UPDATE',
7109                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
7110                 p_token1_name       => 'COLUMN',
7111                 p_token1_value      => 'PARTY_SITE_ID AND PARTY_SITE_NUMBER',
7112                 p_token2_name       => 'ID_NAME',
7113                 p_token2_value      => 'INL_SHIP_LINES_INT',
7114                 p_token3_name       => 'ID_VAL',
7115                 p_token3_value      => l_ship_line_int_id,
7116                 x_return_status     => l_return_status) ;
7117             -- If any errors happen abort API.
7118             IF l_return_status = L_FND_RET_STS_ERROR THEN
7119                 RAISE L_FND_EXC_ERROR;
7120             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7121                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7122             END IF;
7123         END IF;
7124 
7125         l_debug_info := 'Checking source_organization ';
7126         INL_LOGGING_PVT.Log_Statement(
7127             p_module_name      => g_module_name,
7128             p_procedure_name   => l_program_name,
7129             p_debug_info       => l_debug_info);
7130         IF x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_id IS NOT NULL OR
7131            x_ship_ln_int_lst(l_ship_ln_int_idx).source_organization_code IS NOT NULL THEN
7132             l_response := FALSE;
7133             -- Add a line into inl_ship_errors
7134             Handle_InterfError(
7135                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7136                 p_parent_table_id   => l_ship_line_int_id,
7137                 p_column_name       => 'TRANSACTION_TYPE',
7138                 p_column_value      => 'UPDATE',
7139                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
7140                 p_token1_name       => 'COLUMN',
7141                 p_token1_value      => 'SOURCE_ORGANIZATION_ID AND SOURCE_ORGANIZATION_CODE',
7142                 p_token2_name       => 'ID_NAME',
7143                 p_token2_value      => 'INL_SHIP_LINES_INT',
7144                 p_token3_name       => 'ID_VAL',
7145                 p_token3_value      => l_ship_line_int_id,
7146                 x_return_status     => l_return_status) ;
7147             -- If any errors happen abort API.
7148             IF l_return_status = L_FND_RET_STS_ERROR THEN
7149                 RAISE L_FND_EXC_ERROR;
7150             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7151                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7152             END IF;
7153         END IF;
7154 
7155         l_debug_info := 'Checking ship_line_type ';
7156         INL_LOGGING_PVT.Log_Statement(
7157             p_module_name      => g_module_name,
7158             p_procedure_name   => l_program_name,
7159             p_debug_info       => l_debug_info);
7160         IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_id IS NOT NULL OR
7161            x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_code IS NOT NULL THEN
7162             l_response := FALSE;
7163             -- Add a line into inl_ship_errors
7164             Handle_InterfError(
7165                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7166                 p_parent_table_id   => l_ship_line_int_id,
7167                 p_column_name       => 'TRANSACTION_TYPE',
7168                 p_column_value      => 'UPDATE',
7169                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
7170                 p_token1_name       => 'COLUMN',
7171                 p_token1_value      => 'SHIP_LINE_TYPE_ID AND SHIP_LINE_TYPE_CODE',
7172                 p_token2_name       => 'ID_NAME',
7173                 p_token2_value      => 'INL_SHIP_HEADERS_INT',
7174                 p_token3_name       => 'ID_VAL',
7175                 p_token3_value      => l_ship_line_int_id,
7176                 x_return_status     => l_return_status) ;
7177             -- If any errors happen abort API.
7178             IF l_return_status = L_FND_RET_STS_ERROR THEN
7179                 RAISE L_FND_EXC_ERROR;
7180             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7181                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7182             END IF;
7183         END IF;
7184 
7185         l_debug_info := 'Checking ship_line_id and ship_line_src_type_code ';
7186         INL_LOGGING_PVT.Log_Statement(
7187             p_module_name      => g_module_name,
7188             p_procedure_name   => l_program_name,
7189             p_debug_info       => l_debug_info);
7190         IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code IS NOT NULL THEN
7191             l_response := FALSE;
7192             -- Add a line into inl_ship_errors
7193             Handle_InterfError(
7194                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7195                 p_parent_table_id   => l_ship_line_int_id,
7196                 p_column_name       => 'TRANSACTION_TYPE',
7197                 p_column_value      => 'UPDATE',
7198                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
7199                 p_token1_name       => 'COLUMN',
7200                 p_token1_value      => 'SHIP_LINE_SRC_TYPE_CODE',
7201                 p_token2_name       => 'ID_NAME',
7202                 p_token2_value      => 'INL_SHIP_LINES_INT',
7203                 p_token3_name       => 'ID_VAL',
7204                 p_token3_value      => l_ship_line_int_id,
7205                 x_return_status     => l_return_status) ;
7206             -- If any errors happen abort API.
7207             IF l_return_status = L_FND_RET_STS_ERROR THEN
7208                 RAISE L_FND_EXC_ERROR;
7209             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7210                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7211             END IF;
7212         END IF;
7213 
7214         l_debug_info := 'Checking ship_line_id and ship_line_source_id ';
7215         INL_LOGGING_PVT.Log_Statement(
7216             p_module_name      => g_module_name,
7217             p_procedure_name   => l_program_name,
7218             p_debug_info       => l_debug_info);
7219         IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_source_id IS NOT NULL THEN
7220             l_response := FALSE;
7221             -- Add a line into inl_ship_errors
7222             Handle_InterfError(
7223                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7224                 p_parent_table_id   => l_ship_line_int_id,
7225                 p_column_name       => 'TRANSACTION_TYPE',
7226                 p_column_value      => 'UPDATE',
7227                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
7228                 p_token1_name       => 'COLUMN',
7229                 p_token1_value      => 'SHIP_LINE_SOURCE_ID',
7230                 p_token2_name       => 'ID_NAME',
7231                 p_token2_value      => 'INL_SHIP_LINES_INT',
7232                 p_token3_name       => 'ID_VAL',
7233                 p_token3_value      => l_ship_line_int_id,
7234                 x_return_status     => l_return_status) ;
7235             -- If any errors happen abort API.
7236             IF l_return_status = L_FND_RET_STS_ERROR THEN
7237                 RAISE L_FND_EXC_ERROR;
7238             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7239                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7240             END IF;
7241         END IF;
7242 
7243         l_debug_info := 'Checking currency_code ';
7244         INL_LOGGING_PVT.Log_Statement(
7245             p_module_name      => g_module_name,
7246             p_procedure_name   => l_program_name,
7247             p_debug_info       => l_debug_info);
7248         IF x_ship_ln_int_lst(l_ship_ln_int_idx).currency_code IS NOT NULL THEN
7249             l_response := FALSE;
7250             -- Add a line into inl_ship_errors
7251             Handle_InterfError(
7252                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7253                 p_parent_table_id   => l_ship_line_int_id,
7254                 p_column_name       => 'TRANSACTION_TYPE',
7255                 p_column_value      => 'UPDATE',
7256                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
7257                 p_token1_name       => 'COLUMN',
7258                 p_token1_value      => 'CURRENCY_CODE',
7259                 p_token2_name       => 'ID_NAME',
7260                 p_token2_value      => 'INL_SHIP_LINES_INT',
7261                 p_token3_name       => 'ID_VAL',
7262                 p_token3_value      => l_ship_line_int_id,
7263                 x_return_status     => l_return_status) ;
7264             -- If any errors happen abort API.
7265             IF l_return_status = L_FND_RET_STS_ERROR THEN
7266                 RAISE L_FND_EXC_ERROR;
7267             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7268                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7269             END IF;
7270         END IF;
7271 
7272         l_debug_info := 'Checking currency_conversion_type ';
7273         INL_LOGGING_PVT.Log_Statement(
7274             p_module_name      => g_module_name,
7275             p_procedure_name   => l_program_name,
7276             p_debug_info       => l_debug_info);
7277         IF x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_type IS NOT NULL THEN
7278             l_response := FALSE;
7279             -- Add a line into inl_ship_errors
7280             Handle_InterfError(
7281                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7282                 p_parent_table_id   => l_ship_line_int_id,
7283                 p_column_name       => 'TRANSACTION_TYPE',
7284                 p_column_value      => 'UPDATE',
7285                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
7286                 p_token1_name       => 'COLUMN',
7287                 p_token1_value      => 'CURRENCY_CONVERSION_TYPE',
7288                 p_token2_name       => 'ID_NAME',
7289                 p_token2_value      => 'INL_SHIP_LINES_INT',
7290                 p_token3_name       => 'ID_VAL',
7291                 p_token3_value      => l_ship_line_int_id,
7292                 x_return_status     => l_return_status) ;
7293             -- If any errors happen abort API.
7294             IF l_return_status = L_FND_RET_STS_ERROR THEN
7295                 RAISE L_FND_EXC_ERROR;
7296             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7297                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7298             END IF;
7299         END IF;
7300 
7301         l_debug_info := 'Checking currency_conversion_date ';
7302         INL_LOGGING_PVT.Log_Statement(
7303             p_module_name      => g_module_name,
7304             p_procedure_name   => l_program_name,
7305             p_debug_info       => l_debug_info);
7306         IF x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_date IS NOT NULL THEN
7307             l_response := FALSE;
7308             -- Add a line into inl_ship_errors
7309             Handle_InterfError(
7310                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7311                 p_parent_table_id   => l_ship_line_int_id,
7312                 p_column_name       => 'TRANSACTION_TYPE',
7313                 p_column_value      => 'UPDATE',
7314                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
7315                 p_token1_name       => 'COLUMN',
7316                 p_token1_value      => 'CURRENCY_CONVERSION_DATE',
7317                 p_token2_name       => 'ID_NAME',
7318                 p_token2_value      => 'INL_SHIP_LINES_INT',
7319                 p_token3_name       => 'ID_VAL',
7320                 p_token3_value      => l_ship_line_int_id,
7321                 x_return_status     => l_return_status) ;
7322             -- If any errors happen abort API.
7323             IF l_return_status = L_FND_RET_STS_ERROR THEN
7324                 RAISE L_FND_EXC_ERROR;
7325             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7326                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7327             END IF;
7328         END IF;
7329 
7330         l_debug_info := 'Checking currency_conversion_rate ';
7331         INL_LOGGING_PVT.Log_Statement(
7332             p_module_name      => g_module_name,
7333             p_procedure_name   => l_program_name,
7334             p_debug_info       => l_debug_info);
7335         IF x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_rate IS NOT NULL THEN
7336             l_response := FALSE;
7337             -- Add a line into inl_ship_errors
7338             Handle_InterfError(
7339                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7340                 p_parent_table_id   => l_ship_line_int_id,
7341                 p_column_name       => 'TRANSACTION_TYPE',
7342                 p_column_value      => 'UPDATE',
7343                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
7344                 p_token1_name       => 'COLUMN',
7345                 p_token1_value      => 'CURRENCY_CONVERSION_RATE',
7346                 p_token2_name       => 'ID_NAME',
7347                 p_token2_value      => 'INL_SHIP_LINES_INT',
7348                 p_token3_name       => 'ID_VAL',
7349                 p_token3_value      => l_ship_line_int_id,
7350                 x_return_status     => l_return_status) ;
7351             -- If any errors happen abort API.
7352             IF l_return_status = L_FND_RET_STS_ERROR THEN
7353                 RAISE L_FND_EXC_ERROR;
7354             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7355                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7356             END IF;
7357         END IF;
7358 
7359         l_debug_info := 'Checking inventory_item_name and inventory_item_id';
7360         INL_LOGGING_PVT.Log_Statement(
7361             p_module_name      => g_module_name,
7362             p_procedure_name   => l_program_name,
7363             p_debug_info       => l_debug_info);
7364         IF x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_id IS NOT NULL OR
7365            x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_name IS NOT NULL THEN
7366             l_response := FALSE;
7367             -- Add a line into inl_ship_errors
7368             Handle_InterfError(
7369                 p_parent_table_name => 'INL_SHIP_LINES_INT',
7370                 p_parent_table_id   => l_ship_line_int_id,
7371                 p_column_name       => 'TRANSACTION_TYPE',
7372                 p_column_value      => 'UPDATE',
7373                 p_error_message_name => 'INL_ERR_TRX_TP_ID_NNULL',
7374                 p_token1_name       => 'COLUMN',
7375                 p_token1_value      => 'INVENTORY_ITEM_ID AND INVENTORY_ITEM_NAME',
7376                 p_token2_name       => 'ID_NAME',
7377                 p_token2_value      => 'INL_SHIP_LINES_INT',
7378                 p_token3_name       => 'ID_VAL',
7379                 p_token3_value      => l_ship_line_int_id,
7380                 x_return_status     => l_return_status) ;
7381             -- If any errors happen abort API.
7382             IF l_return_status = L_FND_RET_STS_ERROR THEN
7383                 RAISE L_FND_EXC_ERROR;
7384             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7385                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7386             END IF;
7387         END IF;
7388 
7389         l_debug_info := 'Calling Validate_ShipLineGrpNum';
7390         INL_LOGGING_PVT.Log_Statement(
7391             p_module_name      => g_module_name,
7392             p_procedure_name   => l_program_name,
7393             p_debug_info       => l_debug_info);
7394 
7395 
7396         l_response_int :=
7397             Validate_ShipLineGrpNum(
7398                 p_ship_header_int_id  => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_header_int_id,
7399                 p_ship_line_int_id    => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
7400                 p_validation_flag     => p_validation_flag,
7401                 p_ship_header_id      => p_ship_header_id,
7402                 p_ship_line_id        => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id,
7403                 x_ship_line_group_num => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_num,
7404                 x_ship_line_group_id  => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_id,
7405                 x_return_status       => l_return_status
7406         );
7407 
7408 
7409         -- If any errors happen abort API.
7410         IF l_return_status = L_FND_RET_STS_ERROR THEN
7411             RAISE L_FND_EXC_ERROR;
7412         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7413             RAISE L_FND_EXC_UNEXPECTED_ERROR;
7414         END IF;
7415         IF (l_response_int)
7416         THEN
7417             l_debug_info := 'True';
7418         ELSE
7419             l_debug_info := 'False';
7420             l_response := l_response_int;
7421         END IF;
7422         INL_LOGGING_PVT.Log_Variable(
7423             p_module_name    => g_module_name,
7424             p_procedure_name => l_program_name,
7425             p_var_name       => 'l_response_int',
7426             p_var_value      => l_debug_info);
7427 
7428 
7429         l_debug_info := 'Calling Validate_ShipLineNum';
7430         INL_LOGGING_PVT.Log_Statement(
7431             p_module_name      => g_module_name,
7432             p_procedure_name   => l_program_name,
7433             p_debug_info       => l_debug_info);
7434 
7435         l_response_int :=
7436             Validate_ShipLineNum(
7437                 p_ship_line_int_id    => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
7438                 p_validation_flag     => p_validation_flag,
7439                 p_ship_header_id      => p_ship_header_id,
7440                 p_ship_line_group_id  => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_id,
7441                 x_ship_line_num       => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num,
7442                 x_ship_line_id        => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id,
7443                 x_return_status       => l_return_status
7444         );
7445 
7446         -- If any errors happen abort API.
7447         IF l_return_status = L_FND_RET_STS_ERROR THEN
7448             RAISE L_FND_EXC_ERROR;
7449         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7450             RAISE L_FND_EXC_UNEXPECTED_ERROR;
7451         END IF;
7452         IF (l_response_int)
7453         THEN
7454             l_debug_info := 'True';
7455         ELSE
7456             l_debug_info := 'False';
7457             l_response := l_response_int;
7458         END IF;
7459         INL_LOGGING_PVT.Log_Variable(
7460             p_module_name    => g_module_name,
7461             p_procedure_name => l_program_name,
7462             p_var_name       => 'l_response_int',
7463             p_var_value      => l_debug_info);
7464 
7465         IF x_ship_ln_int_lst(l_ship_ln_int_idx).txn_uom_code IS NOT NULL
7466         AND p_validation_flag = 'Y'
7467         THEN
7468             l_debug_info := 'Calling Validate_TxnUomCode';
7469             INL_LOGGING_PVT.Log_Statement(
7470                 p_module_name      => g_module_name,
7471                 p_procedure_name   => l_program_name,
7472                 p_debug_info       => l_debug_info);
7473             l_response_int :=
7474                 Validate_TxnUomCode(
7475                     p_ship_line_int_id  => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
7476                     p_txn_uom_code      => x_ship_ln_int_lst(l_ship_ln_int_idx).txn_uom_code,
7477                     x_return_status     => l_return_status
7478             );
7479 
7480             -- If any errors happen abort API.
7481             IF l_return_status = L_FND_RET_STS_ERROR THEN
7482                 RAISE L_FND_EXC_ERROR;
7483             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7484                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7485             END IF;
7486             IF (l_response_int)
7487             THEN
7488                 l_debug_info := 'True';
7489             ELSE
7490                 l_debug_info := 'False';
7491                 l_response := l_response_int;
7492                 l_validate_txn_uom_code := l_response_int;
7493             END IF;
7494             INL_LOGGING_PVT.Log_Variable(
7495                 p_module_name    => g_module_name,
7496                 p_procedure_name => l_program_name,
7497                 p_var_name       => 'l_response_int',
7498                 p_var_value      => l_debug_info);
7499         END IF;
7500 
7501         IF l_validate_txn_uom_code
7502         THEN
7503 
7504             l_debug_info := 'Call Validate_PriSecFields';
7505             INL_LOGGING_PVT.Log_Statement(
7506                 p_module_name      => g_module_name,
7507                 p_procedure_name   => l_program_name,
7508                 p_debug_info       => l_debug_info);
7509 
7510             l_response_int := Validate_PriSecFields(
7511                 p_ship_line_int_id      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
7512                 p_validation_flag       => p_validation_flag,
7513                 p_organization_id       => p_organization_id,
7514                 p_inventory_item_id     => x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_id,
7515                 p_txn_uom_code          => x_ship_ln_int_lst(l_ship_ln_int_idx).txn_uom_code,
7516                 p_txn_qty               => x_ship_ln_int_lst(l_ship_ln_int_idx).txn_qty,
7517                 p_txn_unit_price        => x_ship_ln_int_lst(l_ship_ln_int_idx).txn_unit_price,
7518                 p_ship_line_id          => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id,
7519                 p_interface_source_code => p_interface_source_code, -- Bug #8932386
7520                 p_interface_source_line_id => x_ship_ln_int_lst(l_ship_ln_int_idx).interface_source_line_id, -- Bug 11710754
7521                 x_1ary_uom_code         => x_ship_ln_int_lst(l_ship_ln_int_idx).primary_uom_code,
7522                 x_1ary_qty              => x_ship_ln_int_lst(l_ship_ln_int_idx).primary_qty,
7523                 x_1ary_unit_price       => x_ship_ln_int_lst(l_ship_ln_int_idx).primary_unit_price,
7524                 x_2ary_uom_code         => x_ship_ln_int_lst(l_ship_ln_int_idx).secondary_uom_code,
7525                 x_2ary_qty              => x_ship_ln_int_lst(l_ship_ln_int_idx).secondary_qty,
7526                 x_2ary_unit_price       => x_ship_ln_int_lst(l_ship_ln_int_idx).secondary_unit_price,
7527                 x_return_status         => l_return_status);
7528 
7529             -- If any errors happen abort API.
7530             IF l_return_status = L_FND_RET_STS_ERROR THEN
7531                 RAISE L_FND_EXC_ERROR;
7532             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7533                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7534             END IF;
7535             IF (l_response_int)
7536             THEN
7537                 l_debug_info := 'True';
7538             ELSE
7539                 l_debug_info := 'False';
7540                 l_response := l_response_int;
7541             END IF;
7542             INL_LOGGING_PVT.Log_Variable(
7543                 p_module_name    => g_module_name,
7544                 p_procedure_name => l_program_name,
7545                 p_var_name       => 'l_response_int',
7546                 p_var_value      => l_debug_info);
7547         END IF;
7548 
7549 
7550         IF p_validation_flag = 'Y'
7551         THEN
7552             l_debug_info := 'Call Validate_LandedCostFlag';
7553             INL_LOGGING_PVT.Log_Statement(
7554                 p_module_name      => g_module_name,
7555                 p_procedure_name   => l_program_name,
7556                 p_debug_info       => l_debug_info);
7557 
7558             l_response_int := Validate_LandedCostFlag(
7559                 p_ship_line_int_id      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
7560                 p_landed_cost_flag      => x_ship_ln_int_lst(l_ship_ln_int_idx).landed_cost_flag, -- # Bug 9866323 --ship_lin_int_list(p_line_index).landed_cost_flag,
7561                 x_return_status         => l_return_status);
7562 
7563             -- If any errors happen abort API.
7564             IF l_return_status = L_FND_RET_STS_ERROR THEN
7565                 RAISE L_FND_EXC_ERROR;
7566             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7567                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7568             END IF;
7569             IF (l_response_int)
7570             THEN
7571                 l_debug_info := 'True';
7572             ELSE
7573                 l_debug_info := 'False';
7574                 l_response := l_response_int;
7575             END IF;
7576             INL_LOGGING_PVT.Log_Variable(
7577                 p_module_name    => g_module_name,
7578                 p_procedure_name => l_program_name,
7579                 p_var_name       => 'l_response_int',
7580                 p_var_value      => l_debug_info);
7581 
7582             l_debug_info := 'Call Validate_AllocEnabledFlag';
7583             INL_LOGGING_PVT.Log_Statement(
7584                 p_module_name      => g_module_name,
7585                 p_procedure_name   => l_program_name,
7586                 p_debug_info       => l_debug_info);
7587 
7588             l_response_int := Validate_AllocEnabledFlag(
7589                 p_ship_line_int_id      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,
7590                 p_alloc_enabled_flag    => x_ship_ln_int_lst(l_ship_ln_int_idx).allocation_enabled_flag, -- # Bug 9866323 ship_lin_int_list(p_line_index).allocation_enabled_flag,
7591                 x_return_status         => l_return_status);
7592 
7593             -- If any errors happen abort API.
7594             IF l_return_status = L_FND_RET_STS_ERROR THEN
7595                 RAISE L_FND_EXC_ERROR;
7596             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7597                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
7598             END IF;
7599             IF (l_response_int)
7600             THEN
7601                 l_debug_info := 'True';
7602             ELSE
7603                 l_debug_info := 'False';
7604                 l_response := l_response_int;
7605             END IF;
7606             INL_LOGGING_PVT.Log_Variable(
7607                 p_module_name    => g_module_name,
7608                 p_procedure_name => l_program_name,
7609                 p_var_name       => 'l_response_int',
7610                 p_var_value      => l_debug_info);
7611 
7612         END IF;
7613 
7614     END LOOP;
7615 
7616     -- Standard End of Procedure/Function Logging
7617     INL_LOGGING_PVT.Log_EndProc(
7618         p_module_name    => g_module_name,
7619         p_procedure_name => l_program_name);
7620     RETURN l_response;
7621 EXCEPTION
7622     WHEN L_FND_EXC_ERROR THEN
7623         -- Standard Expected Error Logging
7624         INL_LOGGING_PVT.Log_ExpecError (
7625             p_module_name    => g_module_name,
7626             p_procedure_name => l_program_name);
7627         RETURN FND_API.to_boolean(L_FND_FALSE) ;
7628     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
7629         -- Standard Unexpected Error Logging
7630         INL_LOGGING_PVT.Log_UnexpecError (
7631             p_module_name    => g_module_name,
7632             p_procedure_name => l_program_name);
7633         RETURN FND_API.to_boolean(L_FND_FALSE) ;
7634     WHEN OTHERS THEN
7635         -- Standard Unexpected Error Logging
7636         INL_LOGGING_PVT.Log_UnexpecError (
7637             p_module_name    => g_module_name,
7638             p_procedure_name => l_program_name);
7639         IF FND_MSG_PUB.Check_Msg_Level(
7640             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
7641         ) THEN
7642             FND_MSG_PUB.Add_Exc_Msg(
7643                 p_pkg_name       => g_pkg_name,
7644                 p_procedure_name => l_program_name);
7645         END IF;
7646         RETURN FND_API.to_boolean(L_FND_FALSE) ;
7647 END  Validate_LnUpdateTrxType;
7648 
7649 -- Utility name : Validate_AllProcessingStatus
7650 -- Type       : Private
7651 -- Function   : Validate the PROCESSING STATUS CODE for lines.
7652 --              None of them can be marked as ERROR
7653 --
7654 -- Pre-reqs   : None
7655 -- Parameters :
7656 -- IN         : p_ship_header_int_id IN NUMBER
7657 --              p_ship_header_id     IN NUMBER
7658 --
7659 -- IN OUT     : x_return_status      IN OUT NOCOPY VARCHAR2
7660 --
7661 -- Version    : Current version 1.0
7662 --
7663 -- Notes
7664 FUNCTION Validate_AllProcessingStatus(
7665         p_ship_header_int_id IN NUMBER,
7666         x_return_status      IN OUT NOCOPY VARCHAR2
7667 )RETURN BOOLEAN IS
7668 
7669     l_program_name           CONSTANT VARCHAR2(30) := 'Validate_AllProcessingStatus';
7670     l_return_status       VARCHAR2(1) ;
7671     l_debug_info          VARCHAR2(400) ;
7672     l_response            BOOLEAN := TRUE;
7673     l_count_ln_proc_error NUMBER;
7674 BEGIN
7675 
7676     -- Standard Beginning of Procedure/Function Logging
7677     INL_LOGGING_PVT.Log_BeginProc(
7678         p_module_name    => g_module_name,
7679         p_procedure_name => l_program_name) ;
7680     --  Initialize API return status to success
7681     x_return_status      := L_FND_RET_STS_SUCCESS;
7682 
7683     l_debug_info := 'Validate all ship line processins tatus code';
7684     INL_LOGGING_PVT.Log_Statement(
7685         p_module_name      => g_module_name,
7686         p_procedure_name   => l_program_name,
7687         p_debug_info       => l_debug_info);
7688 
7689     INL_LOGGING_PVT.Log_Variable(
7690         p_module_name    => g_module_name,
7691         p_procedure_name => l_program_name,
7692         p_var_name       => 'p_ship_header_int_id',
7693         p_var_value      => p_ship_header_int_id);
7694 
7695     SELECT COUNT(1)
7696     INTO   l_count_ln_proc_error
7697     FROM   inl_ship_lines_int sli
7698     WHERE  sli.ship_header_int_id = p_ship_header_int_id
7699     AND    sli.processing_status_code = 'ERROR';
7700 
7701     INL_LOGGING_PVT.Log_Variable(
7702         p_module_name    => g_module_name,
7703         p_procedure_name => l_program_name,
7704         p_var_name       => 'l_count_ln_proc_error',
7705         p_var_value      => l_count_ln_proc_error);
7706 
7707     IF NVL(l_count_ln_proc_error, 0) > 0 THEN
7708         l_debug_info := 'There are more than one source type code defined for the Shipment';
7709         INL_LOGGING_PVT.Log_Statement(
7710             p_module_name      => g_module_name,
7711             p_procedure_name   => l_program_name,
7712             p_debug_info       => l_debug_info);
7713             l_response := FALSE;
7714         -- Add a line into inl_ship_errors
7715         Handle_InterfError(
7716             p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
7717             p_parent_table_id    => p_ship_header_int_id,
7718             p_column_name        => NULL,
7719             p_column_value       => NULL,
7720             p_error_message_name => 'INL_ERR_ALL_PROCESSING_STATUS',
7721             p_token1_name        => 'ID_NAME',
7722             p_token1_value       => 'INL_SHIP_HEADERS_INT',
7723             p_token2_name        => 'ID_VAL',
7724             p_token2_value       => p_ship_header_int_id,
7725             x_return_status      => l_return_status) ;
7726         -- If any errors happen abort API.
7727         IF l_return_status = L_FND_RET_STS_ERROR THEN
7728             RAISE L_FND_EXC_ERROR;
7729         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7730             RAISE L_FND_EXC_UNEXPECTED_ERROR;
7731         END IF;
7732     END IF;
7733     -- Standard End of Procedure/Function Logging
7734     INL_LOGGING_PVT.Log_EndProc(
7735         p_module_name    => g_module_name,
7736         p_procedure_name => l_program_name);
7737     RETURN l_response;
7738 EXCEPTION
7739     WHEN L_FND_EXC_ERROR THEN
7740         -- Standard Expected Error Logging
7741         INL_LOGGING_PVT.Log_ExpecError (
7742             p_module_name    => g_module_name,
7743             p_procedure_name => l_program_name);
7744         RETURN FND_API.to_boolean(L_FND_FALSE) ;
7745     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
7746         -- Standard Unexpected Error Logging
7747         INL_LOGGING_PVT.Log_UnexpecError (
7748             p_module_name    => g_module_name,
7749             p_procedure_name => l_program_name);
7750         RETURN FND_API.to_boolean(L_FND_FALSE) ;
7751     WHEN OTHERS THEN
7752         -- Standard Unexpected Error Logging
7753         INL_LOGGING_PVT.Log_UnexpecError (
7754             p_module_name    => g_module_name,
7755             p_procedure_name => l_program_name);
7756         IF FND_MSG_PUB.Check_Msg_Level(
7757             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
7758         ) THEN
7759             FND_MSG_PUB.Add_Exc_Msg(
7760                 p_pkg_name       => g_pkg_name,
7761                 p_procedure_name => l_program_name);
7762         END IF;
7763         RETURN FND_API.to_boolean(L_FND_FALSE) ;
7764 END Validate_AllProcessingStatus;
7765 
7766 -- Utility name : Validate_AllShipLnSrcTypeCode
7767 -- Type       : Private
7768 -- Function   : Validate all shipment line source type code for a Shipment
7769 --
7770 -- Pre-reqs   : None
7771 -- Parameters :
7772 -- IN         : p_ship_header_int_id IN NUMBER
7773 --              p_transaction_type   IN VARCHAR2
7774 --
7775 -- IN OUT     : x_return_status      IN OUT NOCOPY VARCHAR2
7776 --
7777 -- Version    : Current version 1.0
7778 --
7779 -- Notes      :
7780 FUNCTION Validate_AllShipLnSrcTypeCode
7781        (p_ship_header_int_id IN NUMBER,
7782         x_return_status      IN OUT NOCOPY VARCHAR2)
7783     RETURN BOOLEAN IS
7784     l_program_name            CONSTANT VARCHAR2(30) := 'Validate_AllShipLnSrcTypeCode';
7785     l_debug_info           VARCHAR2(400) ;
7786     l_response             BOOLEAN := TRUE;
7787     l_return_status        VARCHAR2(1) := L_FND_TRUE;
7788     l_count_ln_src_tp_code NUMBER;
7789 
7790 BEGIN
7791     -- Standard Beginning of Procedure/Function Logging
7792     INL_LOGGING_PVT.Log_BeginProc(
7793         p_module_name    => g_module_name,
7794         p_procedure_name => l_program_name) ;
7795     --  Initialize API return status to success
7796     x_return_status      := L_FND_RET_STS_SUCCESS;
7797 
7798     l_debug_info := 'Checking ship line source type code of Shipment';
7799     INL_LOGGING_PVT.Log_Statement(
7800         p_module_name      => g_module_name,
7801         p_procedure_name   => l_program_name,
7802         p_debug_info       => l_debug_info);
7803 
7804     INL_LOGGING_PVT.Log_Variable(
7805         p_module_name    => g_module_name,
7806         p_procedure_name => l_program_name,
7807         p_var_name       => 'p_ship_header_int_id',
7808         p_var_value      => p_ship_header_int_id);
7809 
7810     SELECT COUNT(DISTINCT(sli.ship_line_src_type_code))
7811     INTO l_count_ln_src_tp_code
7812     FROM inl_ship_lines_int sli
7813     WHERE sli.ship_header_int_id = p_ship_header_int_id;
7814 
7815     INL_LOGGING_PVT.Log_Variable(
7816         p_module_name    => g_module_name,
7817         p_procedure_name => l_program_name,
7818         p_var_name       => 'l_count_ln_src_tp_code',
7819         p_var_value      => l_count_ln_src_tp_code);
7820 
7821     IF l_count_ln_src_tp_code > 1 THEN
7822         l_debug_info := 'There are more than one source type code defined for the Shipment';
7823         INL_LOGGING_PVT.Log_Statement(
7824             p_module_name      => g_module_name,
7825             p_procedure_name   => l_program_name,
7826             p_debug_info       => l_debug_info);
7827             l_response := FALSE;
7828         -- Add a line into inl_ship_errors
7829         Handle_InterfError(
7830             p_parent_table_name => 'INL_SHIP_HEADERS_INT',
7831             p_parent_table_id   => p_ship_header_int_id,
7832             p_column_name       => NULL,
7833             p_column_value      => NULL,
7834             p_error_message_name => 'INL_ERR_ALL_SRC_TYPE',
7835             p_token1_name        => 'ID_NAME',
7836             p_token1_value       => 'INL_SHIP_HEADERS_INT',
7837             p_token2_name        => 'ID_VAL',
7838             p_token2_value       => p_ship_header_int_id,
7839             x_return_status     => l_return_status) ;
7840         -- If any errors happen abort API.
7841         IF l_return_status = L_FND_RET_STS_ERROR THEN
7842             RAISE L_FND_EXC_ERROR;
7843         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7844             RAISE L_FND_EXC_UNEXPECTED_ERROR;
7845         END IF;
7846     END IF;
7847     -- Standard End of Procedure/Function Logging
7848     INL_LOGGING_PVT.Log_EndProc(
7849         p_module_name    => g_module_name,
7850         p_procedure_name => l_program_name);
7851     RETURN l_response;
7852 EXCEPTION
7853     WHEN L_FND_EXC_ERROR THEN
7854         -- Standard Expected Error Logging
7855         INL_LOGGING_PVT.Log_ExpecError (
7856             p_module_name    => g_module_name,
7857             p_procedure_name => l_program_name);
7858         RETURN FND_API.to_boolean(L_FND_FALSE) ;
7859     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
7860         -- Standard Unexpected Error Logging
7861         INL_LOGGING_PVT.Log_UnexpecError (
7862             p_module_name    => g_module_name,
7863             p_procedure_name => l_program_name);
7864         RETURN FND_API.to_boolean(L_FND_FALSE) ;
7865     WHEN OTHERS THEN
7866         -- Standard Unexpected Error Logging
7867         INL_LOGGING_PVT.Log_UnexpecError (
7868             p_module_name    => g_module_name,
7869             p_procedure_name => l_program_name);
7870         IF FND_MSG_PUB.Check_Msg_Level(
7871             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
7872         ) THEN
7873             FND_MSG_PUB.Add_Exc_Msg(
7874                 p_pkg_name       => g_pkg_name,
7875                 p_procedure_name => l_program_name);
7876         END IF;
7877         RETURN FND_API.to_boolean(L_FND_FALSE) ;
7878 END Validate_AllShipLnSrcTypeCode;
7879 
7880 
7881 -- Utility name : Validate_HdrTrxType
7882 -- Type       : Private
7883 -- Function   : Validate the transaction type
7884 --
7885 -- Pre-reqs   : None
7886 -- Parameters :
7887 -- IN         : p_ship_header_int_id IN NUMBER
7888 --              p_transaction_type   IN NUMBER
7889 --              p_ship_date          IN DATE
7890 --              p_organization_id    IN NUMBER
7891 --              p_organization_code  IN VARCHAR2
7892 --              p_location_id        IN NUMBER
7893 --              p_location_code      IN VARCHAR2
7894 --              p_rcv_enabled_flag   IN VARCHAR2
7895 --              p_last_task_code     IN VARCHAR2
7896 --              p_ship_type_id       IN NUMBER
7897 --              p_ship_type_code     IN VARCHAR2
7898 --
7899 -- IN OUT     : x_return_status      IN OUT NOCOPY VARCHAR2
7900 --              x_ship_header_id     IN NUMBER
7901 --              x_ship_num           OUT NOCOPY VARCHAR2,
7902 --
7903 -- Version    : Current version 1.0
7904 --
7905 -- Notes      :
7906 FUNCTION Validate_HdrTrxType(
7907     p_ship_header_int_id IN NUMBER,
7908     p_transaction_type   IN VARCHAR2,
7909     p_ship_date          IN DATE,
7910     p_organization_id    IN NUMBER,
7911     p_organization_code  IN VARCHAR2,
7912     p_location_id        IN NUMBER,
7913     p_location_code      IN VARCHAR2,
7914     p_rcv_enabled_flag   IN VARCHAR2,
7915     p_last_task_code     IN VARCHAR2,
7916     p_ship_type_id       IN NUMBER,
7917     p_ship_type_code     IN VARCHAR2,
7918     x_ship_num           IN OUT NOCOPY VARCHAR2,
7919     x_ship_header_id     IN OUT NOCOPY NUMBER,
7920     x_return_status      OUT NOCOPY VARCHAR2
7921 ) RETURN BOOLEAN IS
7922     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_HdrTrxType';
7923     l_return_status VARCHAR2(1) ;
7924     l_debug_info    VARCHAR2(400) ;
7925     l_response      BOOLEAN := TRUE;
7926     l_response_int  BOOLEAN := TRUE;
7927     l_column_null   VARCHAR2(300);
7928     l_column_nnull  VARCHAR2(300);
7929 
7930 BEGIN
7931     -- Standard Beginning of Procedure/Function Logging
7932     INL_LOGGING_PVT.Log_BeginProc(
7933         p_module_name    => g_module_name,
7934         p_procedure_name => l_program_name) ;
7935     --  Initialize API return status to success
7936     x_return_status      := L_FND_RET_STS_SUCCESS;
7937 
7938     l_debug_info := 'Check columns for the specified transaction type';
7939     INL_LOGGING_PVT.Log_Statement(
7940         p_module_name      => g_module_name,
7941         p_procedure_name   => l_program_name,
7942         p_debug_info       => l_debug_info);
7943 
7944     INL_LOGGING_PVT.Log_Variable(
7945         p_module_name    => g_module_name,
7946         p_procedure_name => l_program_name,
7947         p_var_name       => 'x_ship_num',
7948         p_var_value      => x_ship_num);
7949 
7950    IF p_transaction_type = 'CREATE' THEN
7951        l_response :=
7952             validate_HdrCreateTrxType(
7953                 p_ship_header_int_id => p_ship_header_int_id,
7954                 p_ship_header_id     => x_ship_header_id    ,
7955                 p_ship_num           => x_ship_num          ,
7956                 p_ship_date          => p_ship_date         ,
7957                 p_last_task_code     => p_last_task_code    ,
7958                 p_ship_type_id       => p_ship_type_id      ,
7959                 p_ship_type_code     => p_ship_type_code    ,
7960                 p_rcv_enabled_flag   => p_rcv_enabled_flag  ,
7961                 p_organization_id    => p_organization_id   ,
7962                 p_organization_code  => p_organization_code ,
7963                 x_return_status      => l_return_status);
7964         -- If any errors happen abort API.
7965         IF l_return_status = L_FND_RET_STS_ERROR THEN
7966             RAISE L_FND_EXC_ERROR;
7967         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7968             RAISE L_FND_EXC_UNEXPECTED_ERROR;
7969         END IF;
7970 
7971     ELSIF p_transaction_type = 'UPDATE' THEN
7972         l_response :=
7973             validate_HdrUpdateTrxType(
7974                 p_ship_header_int_id => p_ship_header_int_id,
7975                 p_organization_id    => p_organization_id   ,
7976                 p_organization_code  => p_organization_code ,
7977                 p_ship_type_id       => p_ship_type_id      ,
7978                 p_ship_type_code     => p_ship_type_code    ,
7979                 p_location_id        => p_location_id       ,
7980                 p_location_code      => p_location_code     ,
7981                 p_rcv_enabled_flag   => p_rcv_enabled_flag  ,
7982                 x_ship_num           => x_ship_num          ,
7983                 x_ship_header_id     => x_ship_header_id    ,
7984                 x_return_status      => l_return_status
7985         );
7986         -- If any errors happen abort API.
7987         IF l_return_status = L_FND_RET_STS_ERROR THEN
7988             RAISE L_FND_EXC_ERROR;
7989         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
7990             RAISE L_FND_EXC_UNEXPECTED_ERROR;
7991         END IF;
7992     END IF;
7993 
7994     IF l_response THEN
7995 
7996         l_debug_info := 'Call Validate_AllShipLnSrcTypeCode';
7997         INL_LOGGING_PVT.Log_Statement(
7998             p_module_name      => g_module_name,
7999             p_procedure_name   => l_program_name,
8000             p_debug_info       => l_debug_info);
8001 
8002         l_response_int :=  Validate_AllShipLnSrcTypeCode
8003             (p_ship_header_int_id => p_ship_header_int_id,
8004              x_return_status      => l_return_status);
8005 
8006         -- If any errors happen abort API.
8007         IF l_return_status = L_FND_RET_STS_ERROR THEN
8008             RAISE L_FND_EXC_ERROR;
8009         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
8010             RAISE L_FND_EXC_UNEXPECTED_ERROR;
8011         END IF;
8012         IF (l_response_int)
8013         THEN
8014             l_debug_info := 'True';
8015         ELSE
8016             l_debug_info := 'False';
8017             l_response := l_response_int;
8018         END IF;
8019         INL_LOGGING_PVT.Log_Variable(
8020             p_module_name    => g_module_name,
8021             p_procedure_name => l_program_name,
8022             p_var_name       => 'l_response_int',
8023             p_var_value      => l_debug_info);
8024 
8025         l_debug_info := 'Call Validate_AllProcessingStatus';
8026         INL_LOGGING_PVT.Log_Statement(
8027             p_module_name      => g_module_name,
8028             p_procedure_name   => l_program_name,
8029             p_debug_info       => l_debug_info);
8030 
8031         l_response_int := Validate_AllProcessingStatus(
8032             p_ship_header_int_id => p_ship_header_int_id,
8033             x_return_status      => l_return_status);
8034 
8035         -- If any errors happen abort API.
8036         IF l_return_status = L_FND_RET_STS_ERROR THEN
8037             RAISE L_FND_EXC_ERROR;
8038         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
8039             RAISE L_FND_EXC_UNEXPECTED_ERROR;
8040         END IF;
8041 
8042         IF (l_response_int)
8043         THEN
8044             l_debug_info := 'True';
8045         ELSE
8046             l_debug_info := 'False';
8047             l_response := l_response_int;
8048         END IF;
8049         INL_LOGGING_PVT.Log_Variable(
8050             p_module_name    => g_module_name,
8051             p_procedure_name => l_program_name,
8052             p_var_name       => 'l_response_int',
8053             p_var_value      => l_debug_info);
8054 
8055     END IF;
8056 
8057     INL_LOGGING_PVT.Log_Variable(
8058         p_module_name    => g_module_name,
8059         p_procedure_name => l_program_name,
8060         p_var_name       => 'x_ship_num',
8061         p_var_value      => x_ship_num);
8062 
8063     -- Standard End of Procedure/Function Logging
8064     INL_LOGGING_PVT.Log_EndProc(
8065         p_module_name    => g_module_name,
8066         p_procedure_name => l_program_name);
8067     RETURN l_response;
8068 EXCEPTION
8069     WHEN L_FND_EXC_ERROR THEN
8070         -- Standard Expected Error Logging
8071         INL_LOGGING_PVT.Log_ExpecError (
8072             p_module_name    => g_module_name,
8073             p_procedure_name => l_program_name);
8074         RETURN FND_API.to_boolean(L_FND_FALSE) ;
8075     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
8076         -- Standard Unexpected Error Logging
8077         INL_LOGGING_PVT.Log_UnexpecError (
8078             p_module_name    => g_module_name,
8079             p_procedure_name => l_program_name);
8080         RETURN FND_API.to_boolean(L_FND_FALSE) ;
8081     WHEN OTHERS THEN
8082         -- Standard Unexpected Error Logging
8083         INL_LOGGING_PVT.Log_UnexpecError (
8084             p_module_name    => g_module_name,
8085             p_procedure_name => l_program_name);
8086         IF FND_MSG_PUB.Check_Msg_Level(
8087             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
8088         ) THEN
8089             FND_MSG_PUB.Add_Exc_Msg(
8090                 p_pkg_name       => g_pkg_name,
8091                 p_procedure_name => l_program_name);
8092         END IF;
8093         RETURN FND_API.to_boolean(L_FND_FALSE) ;
8094 END Validate_HdrTrxType;
8095 
8096 -- Utility name : Delete_Ship
8097 -- Type       : Private
8098 -- Function   : Delete a LCM Shipment from inl_ship_holds, inl_associations, inl_matches, inl_match_amount
8099 --              inl_allocations, inl_tax_lines, inl_charge_lines,
8100 --              inl_ship_lines_all, inl_ship_line_groups and inl_ship_headers_all
8101 --              If a Charge/Tax is associated with more than one Shipment, only the associations
8102 --              of the current shipment are going to be deleted
8103 -- Pre-reqs   : None
8104 -- Parameters :
8105 -- IN         : p_ship_header_id IN  NUMBER
8106 --
8107 -- OUT        : x_return_status  OUT NOCOPY VARCHAR2
8108 --
8109 -- Version    : Current version 1.0
8110 --
8111 -- Notes      :
8112 PROCEDURE Delete_Ship (
8113     p_ship_header_id IN NUMBER,
8114     x_return_status OUT NOCOPY VARCHAR2
8115 ) IS
8116     l_program_name  CONSTANT VARCHAR2(100) := 'Delete_Ship';
8117     l_debug_info VARCHAR2(2000) ;
8118 BEGIN
8119     -- Standard Beginning of Procedure/Function Logging
8120     INL_LOGGING_PVT.Log_BeginProc(
8121         p_module_name    => g_module_name,
8122         p_procedure_name => l_program_name) ;
8123     --  Initialize API return status to success
8124     x_return_status := L_FND_RET_STS_SUCCESS;
8125 
8126 -- Table inl_ship_holds
8127     l_debug_info := 'Delete from inl_ship_holds';
8128     INL_LOGGING_PVT.Log_Statement(
8129         p_module_name      => g_module_name,
8130         p_procedure_name   => l_program_name,
8131         p_debug_info       => l_debug_info) ;
8132 
8133     INL_LOGGING_PVT.Log_Variable(
8134         p_module_name => g_module_name,
8135         p_procedure_name => l_program_name,
8136         p_var_name => 'p_ship_header_id',
8137         p_var_value => p_ship_header_id
8138     );
8139 
8140     DELETE FROM inl_ship_holds
8141     WHERE ship_header_id = p_ship_header_id;
8142 
8143 
8144     INL_LOGGING_PVT.Log_Variable(
8145         p_module_name => g_module_name,
8146         p_procedure_name => l_program_name,
8147         p_var_name => 'sql%rowcount',
8148         p_var_value => sql%rowcount
8149     );
8150 
8151 -- Table inl_match_amounts
8152 -- Bug#9279355
8153     l_debug_info := 'Delete inl_match_amounts';
8154     INL_LOGGING_PVT.Log_Statement(
8155         p_module_name      => g_module_name,
8156         p_procedure_name   => l_program_name,
8157         p_debug_info       => l_debug_info) ;
8158 
8159     DELETE FROM inl_match_amounts ma
8160     WHERE EXISTS (SELECT 1
8161                 FROM inl_matches m
8162                 WHERE m.ship_header_id = p_ship_header_id
8163                 AND ma.match_amount_id = m.match_amount_id
8164                 )
8165     AND NOT EXISTS (SELECT 1
8166                 FROM inl_matches m
8167                 WHERE m.ship_header_id <> p_ship_header_id
8168                 AND ma.match_amount_id = m.match_amount_id
8169                 )
8170     ;
8171 
8172     INL_LOGGING_PVT.Log_Variable(
8173         p_module_name => g_module_name,
8174         p_procedure_name => l_program_name,
8175         p_var_name => 'sql%rowcount',
8176         p_var_value => sql%rowcount
8177     );
8178 
8179 -- Table inl_matches
8180 -- Bug#9279355
8181     l_debug_info := 'Delete inl_matches';
8182     INL_LOGGING_PVT.Log_Statement(
8183         p_module_name      => g_module_name,
8184         p_procedure_name   => l_program_name,
8185         p_debug_info       => l_debug_info) ;
8186 
8187     DELETE FROM inl_matches m
8188     WHERE m.ship_header_id = p_ship_header_id;
8189 
8190     INL_LOGGING_PVT.Log_Variable(
8191         p_module_name => g_module_name,
8192         p_procedure_name => l_program_name,
8193         p_var_name => 'sql%rowcount',
8194         p_var_value => sql%rowcount
8195     );
8196 
8197 -- Table
8198     l_debug_info := 'Delete from inl_allocations';
8199     INL_LOGGING_PVT.Log_Statement(
8200         p_module_name      => g_module_name,
8201         p_procedure_name   => l_program_name,
8202         p_debug_info       => l_debug_info) ;
8203 
8204     DELETE FROM inl_allocations
8205     WHERE ship_header_id = p_ship_header_id;
8206 
8207     INL_LOGGING_PVT.Log_Variable(
8208         p_module_name => g_module_name,
8209         p_procedure_name => l_program_name,
8210         p_var_name => 'sql%rowcount',
8211         p_var_value => sql%rowcount
8212     );
8213 
8214 -- Table
8215     l_debug_info := 'Delete from inl_tax_lines';
8216     INL_LOGGING_PVT.Log_Statement(
8217         p_module_name      => g_module_name,
8218         p_procedure_name   => l_program_name,
8219         p_debug_info       => l_debug_info) ;
8220 
8221     DELETE FROM inl_tax_lines tl
8222     WHERE
8223         tl.ship_header_id = p_ship_header_id
8224         OR --Bug#9279355
8225         tl.ship_header_id IS NULL
8226         AND
8227         (
8228             EXISTS (
8229                     SELECT 1
8230                       FROM inl_associations assoc
8231                      WHERE assoc.from_parent_table_name     = 'INL_TAX_LINES'
8232                        AND (assoc.from_parent_table_id      = tl.tax_line_id
8233                             OR assoc.from_parent_table_id   = tl.parent_tax_line_id)
8234                        AND assoc.ship_header_id             = p_ship_header_id
8235                     )
8236             AND
8237             NOT EXISTS (
8238                     SELECT 1
8239                       FROM inl_associations assoc
8240                      WHERE assoc.from_parent_table_name     = 'INL_TAX_LINES'
8241                        AND (assoc.from_parent_table_id      = tl.tax_line_id
8242                             OR assoc.from_parent_table_id   = tl.parent_tax_line_id)
8243                        AND assoc.ship_header_id             <> p_ship_header_id
8244                     )
8245         )
8246     ;
8247 
8248 
8249     INL_LOGGING_PVT.Log_Variable(
8250         p_module_name => g_module_name,
8251         p_procedure_name => l_program_name,
8252         p_var_name => 'sql%rowcount',
8253         p_var_value => sql%rowcount
8254     );
8255 
8256 -- Table
8257     l_debug_info := 'Delete from inl_charge_lines';
8258     INL_LOGGING_PVT.Log_Statement(
8259         p_module_name      => g_module_name,
8260         p_procedure_name   => l_program_name,
8261         p_debug_info       => l_debug_info) ;
8262 
8263     DELETE
8264     FROM inl_charge_lines cl
8265     WHERE  --Bug#9279355
8266         (
8267             EXISTS (
8268                     SELECT 1
8269                       FROM inl_associations assoc
8270                      WHERE assoc.from_parent_table_name     = 'INL_CHARGE_LINES'
8271                        AND (assoc.from_parent_table_id      = cl.charge_line_id
8272                             OR assoc.from_parent_table_id   = cl.parent_charge_line_id)
8273                        AND assoc.ship_header_id             = p_ship_header_id
8274                     )
8275             AND
8276             NOT EXISTS (
8277                     SELECT 1
8278                       FROM inl_associations assoc
8279                      WHERE assoc.from_parent_table_name     = 'INL_CHARGE_LINES'
8280                        AND (assoc.from_parent_table_id      = cl.charge_line_id
8281                             OR assoc.from_parent_table_id   = cl.parent_charge_line_id)
8282                        AND assoc.ship_header_id             <> p_ship_header_id
8283                     )
8284         )
8285     ;
8286 
8287     INL_LOGGING_PVT.Log_Variable(
8288         p_module_name => g_module_name,
8289         p_procedure_name => l_program_name,
8290         p_var_name => 'sql%rowcount',
8291         p_var_value => sql%rowcount
8292     );
8293 
8294 -- Table
8295     l_debug_info := 'Delete from inl_associations';
8296     INL_LOGGING_PVT.Log_Statement(
8297         p_module_name      => g_module_name,
8298         p_procedure_name   => l_program_name,
8299         p_debug_info       => l_debug_info) ;
8300 
8301     DELETE FROM inl_associations
8302     WHERE ship_header_id = p_ship_header_id;
8303 
8304     INL_LOGGING_PVT.Log_Variable(
8305         p_module_name => g_module_name,
8306         p_procedure_name => l_program_name,
8307         p_var_name => 'sql%rowcount',
8308         p_var_value => sql%rowcount
8309     );
8310 
8311 -- Table
8312     l_debug_info := 'Delete from inl_ship_lines_all';
8313     INL_LOGGING_PVT.Log_Statement(
8314         p_module_name      => g_module_name,
8315         p_procedure_name   => l_program_name,
8316         p_debug_info       => l_debug_info) ;
8317 
8318     DELETE FROM inl_ship_lines_all
8319     WHERE ship_header_id = p_ship_header_id;
8320 
8321     INL_LOGGING_PVT.Log_Variable(
8322         p_module_name => g_module_name,
8323         p_procedure_name => l_program_name,
8324         p_var_name => 'sql%rowcount',
8325         p_var_value => sql%rowcount
8326     );
8327 
8328 -- Table
8329     l_debug_info := 'Delete from inl_ship_line_groups';
8330     INL_LOGGING_PVT.Log_Statement(
8331         p_module_name      => g_module_name,
8332         p_procedure_name   => l_program_name,
8333         p_debug_info       => l_debug_info) ;
8334 
8335     DELETE FROM inl_ship_line_groups
8336     WHERE ship_header_id = p_ship_header_id;
8337 
8338     INL_LOGGING_PVT.Log_Variable(
8339         p_module_name => g_module_name,
8340         p_procedure_name => l_program_name,
8341         p_var_name => 'sql%rowcount',
8342         p_var_value => sql%rowcount
8343     );
8344 
8345 -- Table
8346     l_debug_info := 'Delete from inl_ship_headers_all';
8347     INL_LOGGING_PVT.Log_Statement(
8348         p_module_name      => g_module_name,
8349         p_procedure_name   => l_program_name,
8350         p_debug_info       => l_debug_info) ;
8351 
8352     DELETE FROM inl_ship_headers_all
8353     WHERE ship_header_id = p_ship_header_id;
8354 
8355     INL_LOGGING_PVT.Log_Variable(
8356         p_module_name => g_module_name,
8357         p_procedure_name => l_program_name,
8358         p_var_name => 'sql%rowcount',
8359         p_var_value => sql%rowcount
8360     );
8361 
8362     -- Standard End of Procedure/Function Logging
8363     INL_LOGGING_PVT.Log_EndProc(
8364         p_module_name    => g_module_name,
8365         p_procedure_name => l_program_name);
8366 EXCEPTION
8367     WHEN L_FND_EXC_ERROR THEN
8368         -- Standard Expected Error Logging
8369         INL_LOGGING_PVT.Log_ExpecError (
8370             p_module_name    => g_module_name,
8371             p_procedure_name => l_program_name );
8372         x_return_status := L_FND_RET_STS_ERROR;
8373     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
8374         -- Standard Unexpected Error Logging
8375         INL_LOGGING_PVT.Log_UnexpecError (
8376             p_module_name    => g_module_name,
8377             p_procedure_name => l_program_name);
8378         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
8379     WHEN OTHERS THEN
8380         -- Standard Unexpected Error Logging
8381         INL_LOGGING_PVT.Log_UnexpecError (
8382             p_module_name    => g_module_name,
8383             p_procedure_name => l_program_name);
8384         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
8385         IF FND_MSG_PUB.Check_Msg_Level(
8386             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
8387         ) THEN
8388             FND_MSG_PUB.Add_Exc_Msg(
8389                 p_pkg_name       => g_pkg_name,
8390                 p_procedure_name => l_program_name);
8391         END IF;
8392 END Delete_Ship;
8393 
8394 -- Utility name : Handle_LineGroups
8395 -- Type       : Private
8396 -- Function   : Create a Line Group for a given Shipment Header only if
8397 --              it hasn't been created yet in the current transaction
8398 --
8399 -- Pre-reqs   : None
8400 -- Parameters :
8401 -- IN         : p_transaction_type IN  VARCHAR2
8402 --
8403 -- OUT        :  x_ship_ln_int_rec      IN OUT c_ship_ln_int%ROWTYPE,
8404 --               x_return_status        IN OUT NOCOPY VARCHAR2
8405 --
8406 -- Version    : Current version 1.0
8407 --
8408 -- Notes      :
8409 PROCEDURE Handle_LineGroups(
8410     p_transaction_type              IN VARCHAR2,
8411     x_ship_ln_int_rec               IN OUT NOCOPY c_ship_ln_int%ROWTYPE,
8412     x_return_status                 IN OUT NOCOPY VARCHAR2
8413 ) IS
8414     l_program_name  CONSTANT VARCHAR2(100) := 'Handle_LineGroups';
8415     l_debug_info VARCHAR2(2000) ;
8416 BEGIN
8417     -- Standard Beginning of Procedure/Function Logging
8418     INL_LOGGING_PVT.Log_BeginProc(
8419         p_module_name    => g_module_name,
8420         p_procedure_name => l_program_name) ;
8421 
8422     l_debug_info    := 'ship_header_id. LG:'||current_SLnGr_rec.ship_header_id||' SL:'||x_ship_ln_int_rec.ship_header_id;
8423     INL_LOGGING_PVT.Log_Statement(
8424         p_module_name      => g_module_name,
8425         p_procedure_name   => l_program_name,
8426         p_debug_info       => l_debug_info
8427     ) ;
8428     l_debug_info    := 'ship_line_group_reference. LG:'||current_SLnGr_rec.ship_line_group_reference||' SL:'||x_ship_ln_int_rec.ship_line_group_reference;
8429     INL_LOGGING_PVT.Log_Statement(
8430         p_module_name      => g_module_name,
8431         p_procedure_name   => l_program_name,
8432         p_debug_info       => l_debug_info
8433     ) ;
8434     l_debug_info    := 'src_type_code. LG:'||current_SLnGr_rec.src_type_code||' SL:'||x_ship_ln_int_rec.ship_line_src_type_code;
8435     INL_LOGGING_PVT.Log_Statement(
8436         p_module_name      => g_module_name,
8437         p_procedure_name   => l_program_name,
8438         p_debug_info       => l_debug_info
8439     ) ;
8440     l_debug_info    := 'party_id. LG:'||current_SLnGr_rec.party_id||' SL:'||x_ship_ln_int_rec.party_id;
8441     INL_LOGGING_PVT.Log_Statement(
8442         p_module_name      => g_module_name,
8443         p_procedure_name   => l_program_name,
8444         p_debug_info       => l_debug_info
8445     ) ;
8446     l_debug_info    := 'party_site_id. LG:'||current_SLnGr_rec.party_site_id||' SL:'||x_ship_ln_int_rec.party_site_id;
8447     INL_LOGGING_PVT.Log_Statement(
8448         p_module_name      => g_module_name,
8449         p_procedure_name   => l_program_name,
8450         p_debug_info       => l_debug_info
8451     ) ;
8452     l_debug_info    := 'source_organization_id. LG:'||current_SLnGr_rec.source_organization_id||' SL:'||x_ship_ln_int_rec.source_organization_id;
8453     INL_LOGGING_PVT.Log_Statement(
8454         p_module_name      => g_module_name,
8455         p_procedure_name   => l_program_name,
8456         p_debug_info       => l_debug_info
8457     ) ;
8458 
8459     IF p_transaction_type = 'CREATE'
8460     THEN
8461         IF(   NVL(current_SLnGr_rec.ship_header_id, L_FND_MISS_NUM)             <> x_ship_ln_int_rec.ship_header_id
8462            OR NVL(current_SLnGr_rec.ship_line_group_reference, L_FND_MISS_CHAR) <> NVL(x_ship_ln_int_rec.ship_line_group_reference, L_FND_MISS_CHAR)
8463            OR current_SLnGr_rec.src_type_code                                   <> x_ship_ln_int_rec.ship_line_src_type_code
8464            OR current_SLnGr_rec.party_id                                        <> x_ship_ln_int_rec.party_id
8465            OR current_SLnGr_rec.party_site_id                                   <> x_ship_ln_int_rec.party_site_id
8466            OR NVL(current_SLnGr_rec.source_organization_id, L_FND_MISS_NUM)     <> NVL(x_ship_ln_int_rec.source_organization_id, L_FND_MISS_NUM))
8467         THEN
8468 
8469             l_debug_info    := 'Is other group: Select Data from group';
8470             INL_LOGGING_PVT.Log_Statement(
8471                 p_module_name      => g_module_name,
8472                 p_procedure_name   => l_program_name,
8473                 p_debug_info       => l_debug_info) ;
8474 
8475             BEGIN
8476                  SELECT ship_line_group_id,                        /* 01 */
8477                        ship_line_group_reference,                  /* 02 */
8478                        ship_header_id,                             /* 03 */
8479 --                       ship_line_group_num,                      /* 04 */
8480                        src_type_code,                              /* 05 */
8481                        party_id,                                   /* 06 */
8482                        party_site_id,                              /* 07 */
8483                        source_organization_id                      /* 08 */
8484                    INTO
8485                        current_SLnGr_rec.ship_line_group_id,       /* 01 */
8486                        current_SLnGr_rec.ship_line_group_reference,/* 02 */
8487                        current_SLnGr_rec.ship_header_id,           /* 03 */
8488 --                       current_SLnGr_rec.ship_line_group_num,    /* 04 */
8489                        current_SLnGr_rec.src_type_code,            /* 05 */
8490                        current_SLnGr_rec.party_id,                 /* 06 */
8491                        current_SLnGr_rec.party_site_id,            /* 07 */
8492                        current_SLnGr_rec.source_organization_id    /* 08 */
8493                    FROM inl_ship_line_groups
8494                    WHERE ship_header_id                       = x_ship_ln_int_rec.ship_header_id
8495                    AND NVL(src_type_code, L_FND_MISS_CHAR)    = NVL(x_ship_ln_int_rec.ship_line_src_type_code, L_FND_MISS_CHAR)
8496                    AND party_id                               = x_ship_ln_int_rec.party_id
8497                    AND party_site_id                          = x_ship_ln_int_rec.party_site_id
8498                    AND source_organization_id                 = x_ship_ln_int_rec.source_organization_id
8499                    AND NVL(ship_line_group_reference, L_FND_MISS_NUM)= NVL(x_ship_ln_int_rec.ship_line_group_reference, L_FND_MISS_NUM) ;
8500 
8501                    INL_LOGGING_PVT.Log_Variable(
8502                         p_module_name    => g_module_name,
8503                         p_procedure_name => l_program_name,
8504                         p_var_name       => 'current_SLnGr_rec.ship_line_group_id',
8505                         p_var_value      => current_SLnGr_rec.ship_line_group_id) ;
8506 
8507                    x_ship_ln_int_rec.ship_line_group_id        := current_SLnGr_rec.ship_line_group_id;
8508 
8509             EXCEPTION
8510                 WHEN NO_DATA_FOUND THEN
8511                     -- Create a Line Group record
8512                     SELECT inl_ship_line_groups_s.NEXTVAL
8513                     INTO current_SLnGr_rec.ship_line_group_id
8514                     FROM dual;
8515                     SELECT MAX(ship_line_group_num)
8516                     INTO current_SLnGr_rec.ship_line_group_num
8517                     FROM inl_ship_line_groups
8518                     WHERE ship_header_id = x_ship_ln_int_rec.ship_header_id;
8519 
8520                     x_ship_ln_int_rec.ship_line_group_id        := current_SLnGr_rec.ship_line_group_id;
8521 
8522                     current_SLnGr_rec.ship_line_group_num       := NVL(current_SLnGr_rec.ship_line_group_num, 0) + 1;
8523                     current_SLnGr_rec.ship_line_group_reference := x_ship_ln_int_rec.ship_line_group_reference;
8524                     current_SLnGr_rec.ship_header_id            := x_ship_ln_int_rec.ship_header_id;
8525                     current_SLnGr_rec.src_type_code             := x_ship_ln_int_rec.ship_line_src_type_code;
8526                     current_SLnGr_rec.party_id                  := x_ship_ln_int_rec.party_id;
8527                     current_SLnGr_rec.party_site_id             := x_ship_ln_int_rec.party_site_id;
8528                     current_SLnGr_rec.source_organization_id    := x_ship_ln_int_rec.source_organization_id;
8529 
8530                     l_debug_info    := 'Inserting inl_ship_line_groups';
8531                     INL_LOGGING_PVT.Log_Statement(
8532                         p_module_name      => g_module_name,
8533                         p_procedure_name   => l_program_name,
8534                         p_debug_info       => l_debug_info) ;
8535                     INL_LOGGING_PVT.Log_Variable(
8536                         p_module_name    => g_module_name,
8537                         p_procedure_name => l_program_name,
8538                         p_var_name       => 'current_SLnGr_rec.ship_line_group_id',
8539                         p_var_value      => current_SLnGr_rec.ship_line_group_id) ;
8540                     INSERT INTO inl_ship_line_groups (
8541                         ship_line_group_id,                          --01
8542                         ship_line_group_reference,                   --02
8543                         ship_header_id,                              --03
8544                         ship_line_group_num,                         --04
8545                         src_type_code,                               --05
8546                         party_id,                                    --06
8547                         party_site_id,                               --07
8548                         source_organization_id,                      --08
8549                         ship_line_int_id,                            --09
8550                         interface_source_table,                      --10
8551                         interface_source_line_id,                    --11
8552                         created_by,                                  --12
8553                         creation_date,                               --13
8554                         last_updated_by,                             --14
8555                         last_update_date,                            --15
8556                         last_update_login,                           --16
8557                         program_id,                                  --17
8558                         program_update_date,                         --18
8559                         program_application_id,                      --19
8560                         request_id,                                  --20
8561                         attribute_category,                          --21
8562                         attribute1,                                  --22
8563                         attribute2,                                  --23
8564                         attribute3,                                  --24
8565                         attribute4,                                  --25
8566                         attribute5,                                  --26
8567                         attribute6,                                  --27
8568                         attribute7,                                  --28
8569                         attribute8,                                  --29
8570                         attribute9,                                  --30
8571                         attribute10,                                 --31
8572                         attribute11,                                 --32
8573                         attribute12,                                 --33
8574                         attribute13,                                 --34
8575                         attribute14,                                 --35
8576                         attribute15                                  --36
8577                         )
8578                     VALUES
8579                        (
8580                         x_ship_ln_int_rec.ship_line_group_id       , --01
8581                         x_ship_ln_int_rec.ship_line_group_reference, --02
8582                         x_ship_ln_int_rec.ship_header_id           , --03
8583                         current_SLnGr_rec.ship_line_group_num   , --04
8584                         current_SLnGr_rec.src_type_code         , --05
8585                         current_SLnGr_rec.party_id              , --06
8586                         current_SLnGr_rec.party_site_id         , --07
8587                         current_SLnGr_rec.source_organization_id, --08
8588                         x_ship_ln_int_rec.ship_line_int_id         , --09
8589                         x_ship_ln_int_rec.interface_source_table   , --10
8590                         x_ship_ln_int_rec.interface_source_line_id , --11
8591                         L_FND_USER_ID                              , --12
8592                         SYSDATE                                    , --13
8593                         L_FND_USER_ID                              , --14
8594                         SYSDATE                                    , --15
8595                         L_FND_LOGIN_ID                             , --16
8596                         L_FND_CONC_PROGRAM_ID                      , --17
8597                         SYSDATE                                    , --18
8598                         L_FND_PROG_APPL_ID                         , --19
8599                         L_FND_CONC_REQUEST_ID                      , --20
8600                         x_ship_ln_int_rec .attribute_category_lg   , --21
8601                         x_ship_ln_int_rec .attribute1_lg           , --22
8602                         x_ship_ln_int_rec .attribute2_lg           , --23
8603                         x_ship_ln_int_rec .attribute3_lg           , --24
8604                         x_ship_ln_int_rec .attribute4_lg           , --25
8605                         x_ship_ln_int_rec .attribute5_lg           , --26
8606                         x_ship_ln_int_rec .attribute6_lg           , --27
8607                         x_ship_ln_int_rec .attribute7_lg           , --28
8608                         x_ship_ln_int_rec .attribute8_lg           , --29
8609                         x_ship_ln_int_rec .attribute9_lg           , --30
8610                         x_ship_ln_int_rec .attribute10_lg          , --31
8611                         x_ship_ln_int_rec .attribute11_lg          , --32
8612                         x_ship_ln_int_rec .attribute12_lg          , --33
8613                         x_ship_ln_int_rec .attribute13_lg          , --34
8614                         x_ship_ln_int_rec .attribute14_lg          , --35
8615                         x_ship_ln_int_rec .attribute15_lg            --36
8616                       );
8617             END;
8618         ELSE
8619            INL_LOGGING_PVT.Log_Variable(
8620                 p_module_name    => g_module_name,
8621                 p_procedure_name => l_program_name,
8622                 p_var_name       => 'current_SLnGr_rec.ship_line_group_id',
8623                 p_var_value      => current_SLnGr_rec.ship_line_group_id) ;
8624 
8625            x_ship_ln_int_rec.ship_line_group_id        := current_SLnGr_rec.ship_line_group_id;
8626 
8627         END IF;
8628     ELSIF p_transaction_type = 'UPDATE' THEN
8629 
8630         l_debug_info    := 'Updating Ship Line Group';
8631         INL_LOGGING_PVT.Log_Statement(
8632             p_module_name      => g_module_name,
8633             p_procedure_name   => l_program_name,
8634             p_debug_info       => l_debug_info) ;
8635 
8636         UPDATE inl_ship_line_groups
8637         SET
8638             ship_line_group_reference  = NVL(x_ship_ln_int_rec.ship_line_group_reference,ship_line_group_reference),
8639             ship_line_int_id           = NVL(x_ship_ln_int_rec.ship_line_int_id         ,ship_line_int_id        ),
8640             interface_source_table     = NVL(x_ship_ln_int_rec.interface_source_table   ,interface_source_table  ),
8641             interface_source_line_id   = NVL(x_ship_ln_int_rec.interface_source_line_id ,interface_source_line_id),
8642             last_updated_by            = L_FND_USER_ID,
8643             last_update_date           = SYSDATE,
8644             last_update_login          = L_FND_LOGIN_ID,
8645             program_id                 = L_FND_CONC_PROGRAM_ID,
8646             program_update_date        = SYSDATE,
8647             program_application_id     = L_FND_PROG_APPL_ID,
8648             request_id                 = L_FND_CONC_REQUEST_ID,
8649             attribute_category         = NVL(x_ship_ln_int_rec.attribute_category_lg    ,attribute_category      ),
8650             attribute1                 = NVL(x_ship_ln_int_rec.attribute1_lg            ,attribute1              ),
8651             attribute2                 = NVL(x_ship_ln_int_rec.attribute2_lg            ,attribute2              ),
8652             attribute3                 = NVL(x_ship_ln_int_rec.attribute3_lg            ,attribute3              ),
8653             attribute4                 = NVL(x_ship_ln_int_rec.attribute4_lg            ,attribute4              ),
8654             attribute5                 = NVL(x_ship_ln_int_rec.attribute5_lg            ,attribute5              ),
8655             attribute6                 = NVL(x_ship_ln_int_rec.attribute6_lg            ,attribute6              ),
8656             attribute7                 = NVL(x_ship_ln_int_rec.attribute7_lg            ,attribute7              ),
8657             attribute8                 = NVL(x_ship_ln_int_rec.attribute8_lg            ,attribute8              ),
8658             attribute9                 = NVL(x_ship_ln_int_rec.attribute9_lg            ,attribute9              ),
8659             attribute10                = NVL(x_ship_ln_int_rec.attribute10_lg           ,attribute10             ),
8660             attribute11                = NVL(x_ship_ln_int_rec.attribute11_lg           ,attribute11             ),
8661             attribute12                = NVL(x_ship_ln_int_rec.attribute12_lg           ,attribute12             ),
8662             attribute13                = NVL(x_ship_ln_int_rec.attribute13_lg           ,attribute13             ),
8663             attribute14                = NVL(x_ship_ln_int_rec.attribute14_lg           ,attribute14             ),
8664             attribute15                = NVL(x_ship_ln_int_rec.attribute15_lg           ,attribute15             )
8665         WHERE ship_line_group_id = x_ship_ln_int_rec.ship_line_group_id
8666         ;
8667     END IF;
8668     -- Standard End of Procedure/Function Logging
8669     INL_LOGGING_PVT.Log_EndProc(
8670         p_module_name    => g_module_name,
8671         p_procedure_name => l_program_name);
8672 EXCEPTION
8673     WHEN L_FND_EXC_ERROR THEN
8674         -- Standard Expected Error Logging
8675         INL_LOGGING_PVT.Log_ExpecError (
8676             p_module_name    => g_module_name,
8677             p_procedure_name => l_program_name);
8678         x_return_status := L_FND_RET_STS_ERROR;
8679     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
8680         -- Standard Unexpected Error Logging
8681         INL_LOGGING_PVT.Log_UnexpecError (
8682             p_module_name    => g_module_name,
8683             p_procedure_name => l_program_name);
8684         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
8685     WHEN OTHERS THEN
8686         -- Standard Unexpected Error Logging
8687         INL_LOGGING_PVT.Log_UnexpecError (
8688             p_module_name    => g_module_name,
8689             p_procedure_name => l_program_name);
8690         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
8691         IF FND_MSG_PUB.Check_Msg_Level(
8692             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
8693         ) THEN
8694             FND_MSG_PUB.Add_Exc_Msg(
8695                 p_pkg_name       => g_pkg_name,
8696                 p_procedure_name => l_program_name
8697             );
8698         END IF;
8699 END Handle_LineGroups;
8700 
8701 -- Utility name : Run_ProcesstAction
8702 -- Type       : Private
8703 -- Function   : Set Shipment action
8704 --
8705 -- Pre-reqs   : None
8706 -- Parameters :
8707 -- IN         : p_ship_header_id IN NUMBER
8708 --              p_last_task_code IN NUMBER
8709 --
8710 -- OUT        : x_return_status  OUT NOCOPY VARCHAR2
8711 --
8712 -- Version    : Current version 1.0
8713 --
8714 -- Notes      :
8715 PROCEDURE Run_ProcessAction(p_ship_header_id IN NUMBER,
8716                             p_last_task_code IN NUMBER,
8717                             x_return_status  OUT NOCOPY VARCHAR2) IS
8718 
8719     l_program_name        CONSTANT VARCHAR2(100) := 'Run_ProcessAction';
8720     l_debug_info       VARCHAR2(2000);
8721     l_return_status    VARCHAR2(1);
8722     l_init_msg_list    VARCHAR2(2000) := L_FND_FALSE;
8723     l_commit           VARCHAR2(1)    := L_FND_FALSE;
8724     l_validation_level NUMBER         := L_FND_VALID_LEVEL_FULL;
8725     l_msg_data         VARCHAR2(2000) ;
8726     l_msg_count        NUMBER;
8727 
8728 BEGIN
8729     -- Standard Beginning of Procedure/Function Logging
8730     INL_LOGGING_PVT.Log_BeginProc(
8731         p_module_name    => g_module_name,
8732         p_procedure_name => l_program_name) ;
8733     --  Initialize API return status to success
8734     x_return_status := L_FND_RET_STS_SUCCESS;
8735 
8736     INL_LOGGING_PVT.Log_Variable(
8737                     p_module_name    => g_module_name,
8738                     p_procedure_name => l_program_name,
8739                     p_var_name       => 'p_ship_header_id',
8740                     p_var_value      => p_ship_header_id);
8741 
8742     INL_LOGGING_PVT.Log_Variable(
8743                     p_module_name    => g_module_name,
8744                     p_procedure_name => l_program_name,
8745                     p_var_name       => 'p_last_task_code',
8746                     p_var_value      => p_last_task_code);
8747 
8748     -- Generate Charges and Integration with QP
8749     IF p_last_task_code >= '20' THEN
8750         l_debug_info    := 'Generate Charges(Integration with QP). Call INL_CHARGE_PVT.Generate_Charges';
8751         INL_LOGGING_PVT.Log_Statement(
8752             p_module_name      => g_module_name,
8753             p_procedure_name   => l_program_name,
8754             p_debug_info       => l_debug_info);
8755 
8756         INL_CHARGE_PVT.Generate_Charges(
8757             p_api_version    => 1.0,
8758             p_init_msg_list  => l_init_msg_list,
8759             p_commit         => l_commit,
8760             p_ship_header_id => p_ship_header_id,
8761             x_return_status  => l_return_status,
8762             x_msg_count      => l_msg_count,
8763             x_msg_data       => l_msg_data) ;
8764         -- If any errors happen abort the process.
8765         -- Bug #8304106
8766         IF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
8767             RAISE L_FND_EXC_UNEXPECTED_ERROR;
8768         END IF;
8769 
8770     END IF;
8771     -- Process LCM Shipment Actions
8772     IF p_last_task_code >= '30' THEN
8773         l_debug_info  := 'Call INL_SHIPMENT_PVT.ProcessAction';
8774         INL_LOGGING_PVT.Log_Statement(
8775             p_module_name    => g_module_name,
8776             p_procedure_name => l_program_name,
8777             p_debug_info     => l_debug_info);
8778 
8779         INL_SHIPMENT_PVT.ProcessAction(
8780             p_api_version => 1.0,
8781             p_init_msg_list => l_init_msg_list,
8782             p_commit => l_commit,
8783             p_ship_header_id => p_ship_header_id,
8784             p_task_code => p_last_task_code,
8785             p_caller => 'C',  -- SCM-051
8786             x_return_status => l_return_status,
8787             x_msg_count => l_msg_count,
8788             x_msg_data => l_msg_data
8789         );
8790 
8791         -- If any errors happen abort the process.
8792         IF l_return_status = L_FND_RET_STS_ERROR THEN
8793             RAISE L_FND_EXC_ERROR;
8794         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
8795             RAISE L_FND_EXC_UNEXPECTED_ERROR;
8796         END IF;
8797     END IF;
8798 
8799     -- Standard End of Procedure/Function Logging
8800     INL_LOGGING_PVT.Log_EndProc(
8801         p_module_name    => g_module_name,
8802         p_procedure_name => l_program_name);
8803 
8804 EXCEPTION
8805     WHEN L_FND_EXC_ERROR THEN
8806         -- Standard Expected Error Logging
8807         INL_LOGGING_PVT.Log_ExpecError (
8808             p_module_name    => g_module_name,
8809             p_procedure_name => l_program_name);
8810         x_return_status := L_FND_RET_STS_ERROR;
8811     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
8812         -- Standard Unexpected Error Logging
8813         INL_LOGGING_PVT.Log_UnexpecError (
8814             p_module_name    => g_module_name,
8815             p_procedure_name => l_program_name);
8816         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
8817     WHEN OTHERS THEN
8818         -- Standard Unexpected Error Logging
8819         INL_LOGGING_PVT.Log_UnexpecError (
8820             p_module_name    => g_module_name,
8821             p_procedure_name => l_program_name);
8822         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
8823         IF FND_MSG_PUB.Check_Msg_Level(
8824             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
8825         ) THEN
8826             FND_MSG_PUB.Add_Exc_Msg(
8827                 p_pkg_name       => g_pkg_name,
8828                 p_procedure_name => l_program_name);
8829         END IF;
8830 END Run_ProcessAction;
8831 
8832 
8833 -- Utility name : Import_Lines
8834 -- Type       : Private
8835 -- Function   : Import Shipment Lines from the Interface table
8836 --
8837 -- Pre-reqs   : None
8838 -- Parameters :
8839 -- IN         : p_transaction_type      IN VARCHAR2,
8840 --              p_ship_header_int_id    IN NUMBER,
8841 --              p_ship_header_id        IN NUMBER,
8842 --
8843 -- OUT        : x_ship_ln_int_lst       IN OUT NOCOPY ship_ln_int_list_type
8844 --              x_return_status  OUT NOCOPY VARCHAR2
8845 --
8846 -- Version    : Current version 1.0
8847 --
8848 -- Notes      :
8849 PROCEDURE Import_Lines (
8850     p_transaction_type      IN VARCHAR2,
8851     p_ship_header_int_id    IN NUMBER,
8852     p_ship_header_id        IN NUMBER,
8853     x_ship_ln_int_lst       IN OUT NOCOPY ship_ln_int_list_type,
8854     x_return_status            OUT NOCOPY VARCHAR2) IS
8855 
8856     l_program_name CONSTANT VARCHAR2(100) := 'Import_Lines';
8857 
8858     l_debug_info         VARCHAR2(2000);
8859     l_return_status      VARCHAR2(1);
8860 
8861 BEGIN
8862     -- Standard Beginning of Procedure/Function Logging
8863     INL_LOGGING_PVT.Log_BeginProc(
8864         p_module_name    => g_module_name,
8865         p_procedure_name => l_program_name) ;
8866     --  Initialize API return status to success
8867     x_return_status := L_FND_RET_STS_SUCCESS;
8868 
8869     l_debug_info := 'Processing Lines, p_transaction_type: '||p_transaction_type;
8870     INL_LOGGING_PVT.Log_Statement(
8871         p_module_name      => g_module_name,
8872         p_procedure_name   => l_program_name,
8873         p_debug_info       => l_debug_info) ;
8874 
8875     FOR l_ship_ln_int_idx IN 1 .. x_ship_ln_int_lst.COUNT
8876     LOOP
8877         INL_LOGGING_PVT.Log_Variable(
8878             p_module_name    => g_module_name,
8879             p_procedure_name => l_program_name,
8880             p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).ship_Line_int_id',
8881             p_var_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_Line_int_id) ;
8882 
8883         x_ship_ln_int_lst(l_ship_ln_int_idx).ship_header_id := p_ship_header_id;
8884 
8885         l_debug_info := 'Handle Import of Shipment Line Groups';
8886         INL_LOGGING_PVT.Log_Statement(
8887             p_module_name      => g_module_name,
8888             p_procedure_name   => l_program_name,
8889             p_debug_info       => l_debug_info);
8890         -- Check if the Line Group has already been imported
8891         Handle_LineGroups(
8892             p_transaction_type  => p_transaction_type,
8893             x_ship_ln_int_rec   => x_ship_ln_int_lst(l_ship_ln_int_idx),
8894             x_return_status     => l_return_status)
8895         ;
8896 
8897         -- If any errors happen abort API.
8898         IF l_return_status = L_FND_RET_STS_ERROR THEN
8899             RAISE L_FND_EXC_ERROR;
8900         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
8901             RAISE L_FND_EXC_UNEXPECTED_ERROR;
8902         END IF;
8903 
8904         IF p_transaction_type = 'CREATE'
8905         THEN
8906 
8907             l_debug_info := 'Getting the next Shipment Line Number';
8908             INL_LOGGING_PVT.Log_Statement(
8909                 p_module_name      => g_module_name,
8910                 p_procedure_name   => l_program_name,
8911                 p_debug_info       => l_debug_info);
8912 
8913             IF x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num IS NULL THEN
8914                 -- Get the next Ship Line Number
8915                  SELECT MAX(ship_line_num)
8916                    INTO x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num
8917                    FROM inl_ship_lines_all
8918                   WHERE ship_header_id = x_ship_ln_int_lst(l_ship_ln_int_idx).ship_header_id
8919                     AND ship_line_group_id = x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_id;
8920 
8921                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num := NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num, 0) + 1;
8922 
8923                 INL_LOGGING_PVT.Log_Variable(
8924                     p_module_name    => g_module_name,
8925                     p_procedure_name => l_program_name,
8926                     p_var_name       => 'x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num',
8927                     p_var_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num) ;
8928             END IF;
8929             l_debug_info  := 'Getting Shipment Line Id';
8930             INL_LOGGING_PVT.Log_Statement(
8931                 p_module_name      => g_module_name,
8932                 p_procedure_name   => l_program_name,
8933                 p_debug_info       => l_debug_info) ;
8934             -- Get the next Shipment Line Id
8935             SELECT inl_ship_Lines_all_s.NEXTVAL
8936             INTO x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id
8937             FROM dual;
8938 
8939             INL_LOGGING_PVT.Log_Variable(
8940                 p_module_name    => g_module_name,
8941                 p_procedure_name => l_program_name,
8942                 p_var_name       => 'ship_line_id',
8943                 p_var_value      => x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id);
8944 
8945             l_debug_info := 'Insert into Shipment Lines table';
8946             INL_LOGGING_PVT.Log_Statement(
8947                 p_module_name      => g_module_name,
8948                 p_procedure_name   => l_program_name,
8949                 p_debug_info       => l_debug_info);
8950 
8951             --  Insert an INL SHIP LINE record
8952             INSERT INTO inl_ship_lines_all (
8953                 ship_header_id,                                                --01
8954                 ship_line_group_id,                                            --02
8955                 ship_line_id,                                                  --03
8956                 ship_line_num,                                                 --04
8957                 ship_line_type_id,                                             --05
8958                 ship_line_src_type_code,                                       --06
8959                 ship_line_source_id,                                           --07
8960                 parent_ship_line_id,                                           --08
8961                 adjustment_num,                                                --09
8962                 match_id,                                                      --10
8963                 currency_code,                                                 --12
8964                 currency_conversion_type,                                      --13
8965                 currency_conversion_date,                                      --14
8966                 currency_conversion_rate,                                      --15
8967                 inventory_item_id,                                             --16
8968                 txn_qty,                                                       --17
8969                 txn_uom_code,                                                  --18
8970                 txn_unit_price,                                                --19
8971                 primary_qty,                                                   --20
8972                 primary_uom_code,                                              --21
8973                 primary_unit_price,                                            --22
8974                 secondary_qty,                                                 --23
8975                 secondary_uom_code,                                            --24
8976                 secondary_unit_price,                                          --25
8977                 landed_cost_flag,                                              --30
8978                 allocation_enabled_flag,                                       --31
8979                 trx_business_category,                                         --32
8980                 intended_use,                                                  --33
8981                 product_fiscal_class,                                          --34
8982                 product_category,                                              --35
8983                 product_type,                                                  --36
8984                 user_def_fiscal_class,                                         --37
8985                 tax_classification_code,                                       --38
8986                 assessable_value,                                              --39
8987                 tax_already_calculated_flag,                                   --40
8988                 ship_from_party_id,                                            --41
8989                 ship_from_party_site_id,                                       --42
8990                 ship_to_organization_id,                                       --43
8991                 ship_to_location_id,                                           --44
8992                 bill_from_party_id,                                            --45
8993                 bill_from_party_site_id,                                       --46
8994                 bill_to_organization_id,                                       --47
8995                 bill_to_location_id,                                           --48
8996                 poa_party_id,                                                  --49
8997                 poa_party_site_id,                                             --50
8998                 poo_organization_id,                                           --51
8999                 poo_location_id,                                               --52
9000                 org_id,                                                        --53
9001                 ship_line_int_id,                                              --54
9002                 interface_source_table,                                        --55
9003                 interface_source_line_id,                                      --56
9004                 created_by,                                                    --57
9005                 creation_date,                                                 --58
9006                 last_updated_by,                                               --59
9007                 last_update_date,                                              --60
9008                 last_update_login,                                             --61
9009                 program_id,                                                    --62
9010                 program_update_date,                                           --63
9011                 program_application_id,                                        --64
9012                 request_id,                                                    --65
9013                 attribute_category,                                            --66
9014                 attribute1,                                                    --67
9015                 attribute2,                                                    --68
9016                 attribute3,                                                    --69
9017                 attribute4,                                                    --70
9018                 attribute5,                                                    --71
9019                 attribute6,                                                    --72
9020                 attribute7,                                                    --73
9021                 attribute8,                                                    --74
9022                 attribute9,                                                    --75
9023                 attribute10,                                                   --76
9024                 attribute11,                                                   --77
9025                 attribute12,                                                   --78
9026                 attribute13,                                                   --79
9027                 attribute14,                                                   --80
9028                 attribute15                                                    --81
9029                 )
9030             VALUES
9031                 (
9032                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_header_id,           --01
9033                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_id,       --02
9034                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id,             --03
9035                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_num,            --04
9036                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_type_id,        --05
9037                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_src_type_code,  --06
9038                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_source_id,      --07
9039                 NULL,                                                          --08
9040                 0,                                                             --09
9041                 NULL,                                                          --10
9042                 x_ship_ln_int_lst(l_ship_ln_int_idx).currency_code,            --12
9043                 x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_type, --13
9044                 x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_date, --14
9045                 x_ship_ln_int_lst(l_ship_ln_int_idx).currency_conversion_rate, --15
9046                 x_ship_ln_int_lst(l_ship_ln_int_idx).inventory_item_id,        --16
9047                 x_ship_ln_int_lst(l_ship_ln_int_idx).txn_qty,                  --17
9048                 x_ship_ln_int_lst(l_ship_ln_int_idx).txn_uom_code,             --18
9049                 x_ship_ln_int_lst(l_ship_ln_int_idx).txn_unit_price,           --19
9050                 x_ship_ln_int_lst(l_ship_ln_int_idx).primary_qty,              --20
9051                 x_ship_ln_int_lst(l_ship_ln_int_idx).primary_uom_code,         --21
9052                 x_ship_ln_int_lst(l_ship_ln_int_idx).primary_unit_price,       --22
9053                 x_ship_ln_int_lst(l_ship_ln_int_idx).secondary_qty,            --23
9054                 x_ship_ln_int_lst(l_ship_ln_int_idx).secondary_uom_code,       --24
9055                 x_ship_ln_int_lst(l_ship_ln_int_idx).secondary_unit_price,     --25
9056                 x_ship_ln_int_lst(l_ship_ln_int_idx).landed_cost_flag,         --30
9057                 x_ship_ln_int_lst(l_ship_ln_int_idx).allocation_enabled_flag,  --31
9058                 x_ship_ln_int_lst(l_ship_ln_int_idx).trx_business_category,    --32
9059                 x_ship_ln_int_lst(l_ship_ln_int_idx).intended_use,             --33
9060                 x_ship_ln_int_lst(l_ship_ln_int_idx).product_fiscal_class,     --34
9061                 x_ship_ln_int_lst(l_ship_ln_int_idx).product_category,         --35
9062                 x_ship_ln_int_lst(l_ship_ln_int_idx).product_type,             --36
9063                 x_ship_ln_int_lst(l_ship_ln_int_idx).user_def_fiscal_class,    --37
9064                 x_ship_ln_int_lst(l_ship_ln_int_idx).tax_classification_code,  --38
9065                 x_ship_ln_int_lst(l_ship_ln_int_idx).assessable_value,         --39
9066                 'N',                                                           --40
9067                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_from_party_id,       --41
9068                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_from_party_site_id,  --42
9069                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_to_organization_id,  --43
9070                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_to_location_id,      --44
9071                 x_ship_ln_int_lst(l_ship_ln_int_idx).bill_from_party_id,       --45
9072                 x_ship_ln_int_lst(l_ship_ln_int_idx).bill_from_party_site_id,  --46
9073                 x_ship_ln_int_lst(l_ship_ln_int_idx).bill_to_organization_id,  --47
9074                 x_ship_ln_int_lst(l_ship_ln_int_idx).bill_to_location_id,      --48
9075                 x_ship_ln_int_lst(l_ship_ln_int_idx).poa_party_id,             --49
9076                 x_ship_ln_int_lst(l_ship_ln_int_idx).poa_party_site_id,        --50
9077                 x_ship_ln_int_lst(l_ship_ln_int_idx).poo_organization_id,      --51
9078                 x_ship_ln_int_lst(l_ship_ln_int_idx).poo_location_id,          --52
9079                 x_ship_ln_int_lst(l_ship_ln_int_idx).org_id,                   --53
9080                 x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id,         --54
9081                 x_ship_ln_int_lst(l_ship_ln_int_idx).interface_source_table,   --55
9082                 x_ship_ln_int_lst(l_ship_ln_int_idx).interface_source_line_id, --56
9083                 L_FND_USER_ID,                                                 --57
9084                 SYSDATE,                                                       --58
9085                 L_FND_USER_ID,                                                 --59
9086                 SYSDATE,                                                       --60
9087                 L_FND_LOGIN_ID,                                                --61
9088                 L_FND_CONC_PROGRAM_ID,                                         --62
9089                 SYSDATE,                                                       --63
9090                 L_FND_PROG_APPL_ID,                                            --64
9091                 L_FND_CONC_REQUEST_ID,                                         --65
9092                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute_category_sl,    --66
9093                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute1_sl,            --67
9094                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute2_sl,            --68
9095                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute3_sl,            --69
9096                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute4_sl,            --70
9097                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute5_sl,            --71
9098                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute6_sl,            --72
9099                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute7_sl,            --73
9100                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute8_sl,            --74
9101                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute9_sl,            --75
9102                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute10_sl,           --76
9103                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute11_sl,           --77
9104                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute12_sl,           --78
9105                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute13_sl,           --79
9106                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute14_sl,           --80
9107                 x_ship_ln_int_lst(l_ship_ln_int_idx).attribute15_sl            --81
9108                 ) ;
9109         ELSIF p_transaction_type = 'UPDATE' THEN
9110             l_debug_info := 'Update Shipment Lines table';
9111             INL_LOGGING_PVT.Log_Statement(
9112                 p_module_name      => g_module_name,
9113                 p_procedure_name   => l_program_name,
9114                 p_debug_info       => l_debug_info) ;
9115 
9116             --  update the INL SHIP LINE record
9117             UPDATE inl_ship_lines_all sl
9118             SET adjustment_num           = 0,
9119                 match_id                 = NULL,
9120                 txn_qty                  = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).txn_qty                   , sl.txn_qty)                 ,
9121                 txn_uom_code             = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).txn_uom_code              , sl.txn_uom_code)            ,
9122                 txn_unit_price           = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).txn_unit_price            , sl.txn_unit_price)          ,
9123                 primary_qty              = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).primary_qty               , sl.primary_qty)             ,
9124                 primary_uom_code         = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).primary_uom_code          , sl.primary_uom_code)        ,
9125                 primary_unit_price       = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).primary_unit_price        , sl.primary_unit_price)      ,
9126                 secondary_qty            = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).secondary_qty             , sl.secondary_qty)           ,
9127                 secondary_uom_code       = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).secondary_uom_code        , sl.secondary_uom_code)      ,
9128                 secondary_unit_price     = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).secondary_unit_price      , sl.secondary_unit_price)    ,
9129                 landed_cost_flag         = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).landed_cost_flag          , sl.landed_cost_flag)        ,
9130                 allocation_enabled_flag  = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).allocation_enabled_flag   , sl.allocation_enabled_flag) ,
9131                 trx_business_category    = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).trx_business_category     , sl.trx_business_category)   ,
9132                 intended_use             = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).intended_use              , sl.intended_use)            ,
9133                 product_fiscal_class     = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).product_fiscal_class      , sl.product_fiscal_class)    ,
9134                 product_category         = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).product_category          , sl.product_category)        ,
9135                 product_type             = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).product_type              , sl.product_type)            ,
9136                 user_def_fiscal_class    = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).user_def_fiscal_class     , sl.user_def_fiscal_class)   ,
9137                 tax_classification_code  = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).tax_classification_code   , sl.tax_classification_code) ,
9138                 assessable_value         = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).assessable_value          , sl.assessable_value)        ,
9139                 ship_from_party_id       = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).ship_from_party_id        , sl.ship_from_party_id)      ,
9140                 ship_from_party_site_id  = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).ship_from_party_site_id   , sl.ship_from_party_site_id) ,
9141                 ship_to_organization_id  = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).ship_to_organization_id   , sl.ship_to_organization_id) ,
9142                 ship_to_location_id      = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).ship_to_location_id       , sl.ship_to_location_id)     ,
9143                 bill_from_party_id       = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).bill_from_party_id        , sl.bill_from_party_id)      ,
9144                 bill_from_party_site_id  = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).bill_from_party_site_id   , sl.bill_from_party_site_id) ,
9145                 bill_to_organization_id  = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).bill_to_organization_id   , sl.bill_to_organization_id) ,
9146                 bill_to_location_id      = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).bill_to_location_id       , sl.bill_to_location_id)     ,
9147                 poa_party_id             = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).poa_party_id              , sl.poa_party_id)            ,
9148                 poa_party_site_id        = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).poa_party_site_id         , sl.poa_party_site_id)       ,
9149                 poo_organization_id      = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).poo_organization_id       , sl.poo_organization_id)     ,
9150                 poo_location_id          = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).poo_location_id           , sl.poo_location_id)         ,
9151                 org_id                   = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).org_id           , sl.org_id)                           , --NVL(p_org_id,org_id)
9152                 ship_line_int_id         = x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id                                            ,
9153                 interface_source_table   = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).interface_source_table    , sl.interface_source_table)  ,
9154                 interface_source_line_id = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).interface_source_line_id  , sl.interface_source_line_id),
9155                 last_updated_by          = L_FND_USER_ID                                                                                    ,
9156                 last_update_date         = SYSDATE                                                                                          ,
9157                 last_update_login        = L_FND_LOGIN_ID                                                                                   ,
9158                 program_id               = L_FND_CONC_PROGRAM_ID                                                                            ,
9159                 program_update_date      = SYSDATE                                                                                          ,
9160                 program_application_id   = L_FND_PROG_APPL_ID                                                                               ,
9161                 request_id               = L_FND_CONC_REQUEST_ID                                                                            ,
9162                 attribute_category       = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute_category_sl     , sl.attribute_category)      ,
9163                 attribute1               = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute1_sl             , sl.attribute1)              ,
9164                 attribute2               = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute2_sl             , sl.attribute2)              ,
9165                 attribute3               = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute3_sl             , sl.attribute3)              ,
9166                 attribute4               = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute4_sl             , sl.attribute4)              ,
9167                 attribute5               = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute5_sl             , sl.attribute5)              ,
9168                 attribute6               = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute6_sl             , sl.attribute6)              ,
9169                 attribute7               = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute7_sl             , sl.attribute7)              ,
9170                 attribute8               = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute8_sl             , sl.attribute8)              ,
9171                 attribute9               = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute9_sl             , sl.attribute9)              ,
9172                 attribute10              = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute10_sl            , sl.attribute10)             ,
9173                 attribute11              = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute11_sl            , sl.attribute11)             ,
9174                 attribute12              = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute12_sl            , sl.attribute12)             ,
9175                 attribute13              = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute13_sl            , sl.attribute13)             ,
9176                 attribute14              = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute14_sl            , sl.attribute14)             ,
9177                 attribute15              = NVL(x_ship_ln_int_lst(l_ship_ln_int_idx).attribute15_sl            , sl.attribute15)
9178             WHERE ship_line_id = x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id;
9179         END IF;
9180         l_debug_info  := 'Set Shipment Line Interface status and imported Ids';
9181         INL_LOGGING_PVT.Log_Statement(
9182             p_module_name    => g_module_name,
9183             p_procedure_name => l_program_name,
9184             p_debug_info     => l_debug_info) ;
9185         -- Set processing status code to COMPLETED
9186         -- for a given and imported Shipment Line
9187         UPDATE inl_ship_lines_int
9188         SET processing_status_code = 'COMPLETED'                                             ,
9189             ship_header_id         = x_ship_ln_int_lst(l_ship_ln_int_idx).ship_header_id     ,
9190             ship_line_group_id     = x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_group_id ,
9191             ship_line_id           = x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_id       ,
9192             request_id             = L_FND_CONC_REQUEST_ID                                   ,
9193             last_updated_by        = L_FND_USER_ID                                           ,
9194             last_update_date       = SYSDATE                                                 ,
9195             last_update_login      = L_FND_LOGIN_ID                                          ,
9196             program_id             = L_FND_CONC_PROGRAM_ID                                   ,
9197             program_update_date    = SYSDATE                                                 ,
9198             program_application_id = L_FND_PROG_APPL_ID
9199         WHERE ship_line_int_id     = x_ship_ln_int_lst(l_ship_ln_int_idx).ship_line_int_id   ;
9200     END LOOP;
9201 
9202     -- Standard End of Procedure/Function Logging
9203     INL_LOGGING_PVT.Log_EndProc(
9204         p_module_name    => g_module_name,
9205         p_procedure_name => l_program_name);
9206 EXCEPTION
9207     WHEN L_FND_EXC_ERROR THEN
9208         -- Standard Expected Error Logging
9209         INL_LOGGING_PVT.Log_ExpecError (
9210             p_module_name    => g_module_name,
9211             p_procedure_name => l_program_name);
9212         x_return_status := L_FND_RET_STS_ERROR;
9213     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
9214         -- Standard Unexpected Error Logging
9215         INL_LOGGING_PVT.Log_UnexpecError (
9216             p_module_name    => g_module_name,
9217             p_procedure_name => l_program_name);
9218         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
9219     WHEN OTHERS THEN
9220         -- Standard Unexpected Error Logging
9221         INL_LOGGING_PVT.Log_UnexpecError (
9222             p_module_name    => g_module_name,
9223             p_procedure_name => l_program_name);
9224         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
9225         IF FND_MSG_PUB.Check_Msg_Level(
9226             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
9227         ) THEN
9228             FND_MSG_PUB.Add_Exc_Msg(
9229                 p_pkg_name       => g_pkg_name,
9230                 p_procedure_name => l_program_name);
9231         END IF;
9232 END Import_Lines;
9233 
9234 -- Utility name : Import_Headers
9235 -- Type       : Private
9236 -- Function   : Import Shipment Headers from Interface
9237 --              table to INL_SHIP_HEADERS_ALL
9238 --
9239 -- Pre-reqs   : None
9240 -- Parameters :
9241 -- IN         : p_simulation_id    IN            NUMBER,
9242 --
9243 --
9244 -- OUT        : x_ship_hdr_int_rec IN OUT NOCOPY c_ship_hdr_int%ROWTYPE,
9245 --              x_return_status       OUT NOCOPY VARCHAR2
9246 --
9247 -- Version    : Current version 1.0
9248 --
9249 -- Notes      :
9250 PROCEDURE Import_Headers (
9251     p_simulation_id    IN            NUMBER,
9252     x_ship_hdr_int_rec IN OUT NOCOPY c_ship_hdr_int%ROWTYPE,
9253     x_return_status       OUT NOCOPY VARCHAR2) IS
9254 
9255     l_user_defined_ship_num_code VARCHAR2(30) ;
9256     l_next_ship_num              NUMBER;
9257     l_ship_num                   VARCHAR2(25);
9258     l_program_name                  CONSTANT VARCHAR2(100) := 'Import_Headers';
9259     l_debug_info                 VARCHAR2(2000);
9260     l_return_status              VARCHAR2(1);
9261 BEGIN
9262     -- Standard Beginning of Procedure/Function Logging
9263     INL_LOGGING_PVT.Log_BeginProc(
9264         p_module_name    => g_module_name,
9265         p_procedure_name => l_program_name) ;
9266 
9267     --  Initialize API return status to success
9268     x_return_status := L_FND_RET_STS_SUCCESS;
9269 
9270     INL_LOGGING_PVT.Log_Variable(
9271         p_module_name    => g_module_name,
9272         p_procedure_name => l_program_name,
9273         p_var_name       => 'ship_header_int_id',
9274         p_var_value      => x_ship_hdr_int_rec.ship_header_int_id) ;
9275 
9276     IF x_ship_hdr_int_rec.transaction_type = 'DELETE' THEN
9277         IF x_ship_hdr_int_rec.last_task_code > 10 THEN --Bug#11794483C
9278             Delete_Ship(
9279                 p_ship_header_id => x_ship_hdr_int_rec.ship_header_id,
9280                 x_return_status  => l_return_status);
9281             -- If any errors happen abort API.
9282             IF l_return_status = L_FND_RET_STS_ERROR THEN
9283                 RAISE L_FND_EXC_ERROR;
9284             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
9285                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
9286             END IF;
9287         END IF;
9288     ELSIF x_ship_hdr_int_rec.transaction_type = 'UPDATE' THEN
9289         l_debug_info  := 'Updating the Shipment Header';
9290         INL_LOGGING_PVT.Log_Statement(
9291             p_module_name      => g_module_name,
9292             p_procedure_name   => l_program_name,
9293             p_debug_info       => l_debug_info) ;
9294 
9295         UPDATE inl_ship_headers_all sh --Bug#10381495
9296         SET ship_date                = NVL(x_ship_hdr_int_rec.ship_date               ,sh.ship_date               ),
9297             taxation_country         = NVL(x_ship_hdr_int_rec.taxation_country        ,sh.taxation_country        ),
9298             document_sub_type        = NVL(x_ship_hdr_int_rec.document_sub_type       ,sh.document_sub_type       ),
9299             ship_header_int_id       = NVL(x_ship_hdr_int_rec.ship_header_int_id      ,sh.ship_header_int_id      ),
9300             interface_source_code    = NVL(x_ship_hdr_int_rec.interface_source_code   ,sh.interface_source_code   ),
9301             interface_source_table   = NVL(x_ship_hdr_int_rec.interface_source_table  ,sh.interface_source_table  ),
9302             interface_source_line_id = NVL(x_ship_hdr_int_rec.interface_source_line_id,sh.interface_source_line_id),
9303             simulation_id            = NVL(p_simulation_id                            ,sh.simulation_id           ),  -- Bug#9279355
9304             ship_status_code         = 'VALIDATION REQ'                                                            ,
9305             last_updated_by          = L_FND_USER_ID                                                               ,
9306             last_update_date         = SYSDATE                                                                     ,
9307             last_update_login        = L_FND_LOGIN_ID                                                              ,
9308             program_id               = L_FND_CONC_PROGRAM_ID                                                       ,
9309             program_update_date      = SYSDATE                                                                     ,
9310             program_application_id   = L_FND_PROG_APPL_ID                                                          ,
9311             request_id               = L_FND_CONC_REQUEST_ID                                                       ,
9312             attribute_category       = NVL(x_ship_hdr_int_rec.attribute_category      ,sh.attribute_category      ),
9313             attribute1               = NVL(x_ship_hdr_int_rec.attribute1              ,sh.attribute1              ),
9314             attribute2               = NVL(x_ship_hdr_int_rec.attribute2              ,sh.attribute2              ),
9315             attribute3               = NVL(x_ship_hdr_int_rec.attribute3              ,sh.attribute3              ),
9316             attribute4               = NVL(x_ship_hdr_int_rec.attribute4              ,sh.attribute4              ),
9317             attribute5               = NVL(x_ship_hdr_int_rec.attribute5              ,sh.attribute5              ),
9318             attribute6               = NVL(x_ship_hdr_int_rec.attribute6              ,sh.attribute6              ),
9319             attribute7               = NVL(x_ship_hdr_int_rec.attribute7              ,sh.attribute7              ),
9320             attribute8               = NVL(x_ship_hdr_int_rec.attribute8              ,sh.attribute8              ),
9321             attribute9               = NVL(x_ship_hdr_int_rec.attribute9              ,sh.attribute9              ),
9322             attribute10              = NVL(x_ship_hdr_int_rec.attribute10             ,sh.attribute10             ),
9323             attribute11              = NVL(x_ship_hdr_int_rec.attribute11             ,sh.attribute11             ),
9324             attribute12              = NVL(x_ship_hdr_int_rec.attribute12             ,sh.attribute12             ),
9325             attribute13              = NVL(x_ship_hdr_int_rec.attribute13             ,sh.attribute13             ),
9326             attribute14              = NVL(x_ship_hdr_int_rec.attribute14             ,sh.attribute14             ),
9327             attribute15              = NVL(x_ship_hdr_int_rec.attribute15             ,sh.attribute15)
9328         WHERE ship_header_id       = x_ship_hdr_int_rec .ship_header_id;
9329     ELSIF x_ship_hdr_int_rec.transaction_type = 'CREATE' THEN
9330         l_debug_info  := 'Check if Shipment Number setup is AUTOMATIC or MANUAL';
9331         INL_LOGGING_PVT.Log_Statement(
9332             p_module_name      => g_module_name,
9333             p_procedure_name   => l_program_name,
9334             p_debug_info       => l_debug_info) ;
9335         --  Check if Shipment Number is setup as(AUTOMATIC or MANUAL)
9336         SELECT user_defined_ship_num_code,
9337                next_ship_num,
9338                inl_ship_headers_all_s.NEXTVAL
9339         INTO l_user_defined_ship_num_code,
9340              l_next_ship_num,
9341              x_ship_hdr_int_rec.ship_header_id
9342         FROM inl_parameters
9343         WHERE organization_id = x_ship_hdr_int_rec.organization_id
9344         FOR UPDATE OF next_ship_num;
9345 
9346         INL_LOGGING_PVT.Log_Variable(
9347             p_module_name    => g_module_name,
9348             p_procedure_name => l_program_name,
9349             p_var_name       => 'l_user_defined_ship_num_code',
9350             p_var_value      => l_user_defined_ship_num_code) ;
9351 
9352         INL_LOGGING_PVT.Log_Variable(
9353             p_module_name    => g_module_name,
9354             p_procedure_name => l_program_name,
9355             p_var_name       => 'l_next_ship_num',
9356             p_var_value      => l_next_ship_num) ;
9357 
9358         INL_LOGGING_PVT.Log_Variable(
9359             p_module_name    => g_module_name,
9360             p_procedure_name => l_program_name,
9361             p_var_name       => 'x_ship_hdr_int_rec.ship_header_id',
9362             p_var_value      => x_ship_hdr_int_rec.ship_header_id) ;
9363 
9364         l_debug_info := 'Setting the next Shipment Number in INL_PARAMETERS';
9365         INL_LOGGING_PVT.Log_Statement(
9366             p_module_name      => g_module_name,
9367             p_procedure_name   => l_program_name,
9368             p_debug_info       => l_debug_info) ;
9369 
9370         IF l_user_defined_ship_num_code = 'AUTOMATIC'
9371             AND p_simulation_id IS NULL
9372         THEN -- Bug #9279355
9373             l_ship_num  := l_next_ship_num;
9374             UPDATE inl_parameters
9375             SET next_ship_num              = l_next_ship_num + 1,
9376                 last_updated_by            = L_FND_USER_ID ,
9377                 last_update_date           = SYSDATE            ,
9378                 last_update_login          = L_FND_LOGIN_ID
9379               WHERE organization_id        = x_ship_hdr_int_rec.organization_id;
9380         ELSIF l_user_defined_ship_num_code = 'MANUAL' THEN
9381             l_ship_num   := x_ship_hdr_int_rec.ship_num;
9382             l_debug_info := 'Ship Number is MANUAL: ' || l_ship_num;
9383             INL_LOGGING_PVT.Log_Statement(
9384                 p_module_name      => g_module_name,
9385                 p_procedure_name   => l_program_name,
9386                 p_debug_info       => l_debug_info) ;
9387         ELSIF p_simulation_id IS NOT NULL THEN
9388             l_ship_num   := x_ship_hdr_int_rec.ship_num;
9389             l_debug_info := 'Ship Number for a Simulated Shipment: ' || l_ship_num;
9390             INL_LOGGING_PVT.Log_Statement(
9391                 p_module_name      => g_module_name,
9392                 p_procedure_name   => l_program_name,
9393                 p_debug_info       => l_debug_info) ;
9394         END IF;
9395 
9396         INL_LOGGING_PVT.Log_Variable(
9397             p_module_name    => g_module_name,
9398             p_procedure_name => l_program_name,
9399             p_var_name       => 'l_ship_num',
9400             p_var_value      => l_ship_num) ;
9401 
9402         l_debug_info := 'Insert into Shipment Headers table';
9403         INL_LOGGING_PVT.Log_Statement(
9404             p_module_name      => g_module_name,
9405             p_procedure_name   => l_program_name,
9406             p_debug_info       => l_debug_info) ;
9407 
9408         INL_LOGGING_PVT.Log_Variable(
9409             p_module_name    => g_module_name,
9410             p_procedure_name => l_program_name,
9411             p_var_name       => 'rcv_enabled_flag',
9412             p_var_value      => x_ship_hdr_int_rec.rcv_enabled_flag);
9413 
9414         --  Insert an INL SHIP HEADER record
9415         INSERT
9416         INTO inl_ship_headers_all (                     --Bug#10381495
9417             ship_header_id                             ,-- 01
9418             ship_num                                   ,-- 02
9419             ship_date                                  ,-- 03
9420             ship_type_id                               ,-- 04
9421             ship_status_code                           ,-- 05
9422             pending_matching_flag                      ,-- 06
9423             rcv_enabled_flag                           ,-- 07
9424             legal_entity_id                            ,-- 08
9425             organization_id                            ,-- 09
9426             location_id                                ,-- 10
9427             org_id                                     ,-- 11
9428             taxation_country                           ,-- 12
9429             document_sub_type                          ,-- 13
9430             ship_header_int_id                         ,-- 14
9431             interface_source_code                      ,-- 15
9432             interface_source_table                     ,-- 16
9433             interface_source_line_id                   ,-- 17
9434             simulation_id                              ,-- 18  -- Bug#9279355
9435             adjustment_num                             ,-- 19
9436             created_by                                 ,-- 20
9437             creation_date                              ,-- 21
9438             last_updated_by                            ,-- 22
9439             last_update_date                           ,-- 23
9440             last_update_login                          ,-- 24
9441             program_id                                 ,-- 25
9442             program_update_date                        ,-- 26
9443             program_application_id                     ,-- 27
9444             request_id                                 ,-- 28
9445             attribute_category                         ,-- 29
9446             attribute1                                 ,-- 30
9447             attribute2                                 ,-- 31
9448             attribute3                                 ,-- 32
9449             attribute4                                 ,-- 33
9450             attribute5                                 ,-- 34
9451             attribute6                                 ,-- 35
9452             attribute7                                 ,-- 36
9453             attribute8                                 ,-- 37
9454             attribute9                                 ,-- 38
9455             attribute10                                ,-- 39
9456             attribute11                                ,-- 40
9457             attribute12                                ,-- 41
9458             attribute13                                ,-- 42
9459             attribute14                                ,-- 43
9460             attribute15                                 -- 44
9461         ) VALUES  (
9462             x_ship_hdr_int_rec.ship_header_id          ,--01
9463             l_ship_num                                 ,--02
9464             x_ship_hdr_int_rec.ship_date               ,--03
9465             x_ship_hdr_int_rec.ship_type_id            ,--04
9466             'INCOMPLETE'                               ,--05
9467             NULL                                       ,--06
9468             x_ship_hdr_int_rec.rcv_enabled_flag        ,--07
9469             x_ship_hdr_int_rec.legal_entity_id         ,--08
9470             x_ship_hdr_int_rec.organization_id         ,--09
9471             x_ship_hdr_int_rec.location_id             ,--10
9472             x_ship_hdr_int_rec.org_id                  ,--11
9473             x_ship_hdr_int_rec.taxation_country        ,--12
9474             x_ship_hdr_int_rec.document_sub_type       ,--13
9475             x_ship_hdr_int_rec.ship_header_int_id      ,--14
9476             x_ship_hdr_int_rec.interface_source_code   ,--15
9477             x_ship_hdr_int_rec.interface_source_table  ,--16
9478             x_ship_hdr_int_rec.interface_source_line_id,--17
9479             p_simulation_id                            ,--18 -- Bug#9279355
9480             0                                          ,--19
9481             L_FND_USER_ID                              ,--20
9482             SYSDATE                                    ,--21
9483             L_FND_USER_ID                              ,--22
9484             SYSDATE                                    ,--23
9485             L_FND_LOGIN_ID                             ,--24
9486             L_FND_CONC_PROGRAM_ID                      ,--25
9487             SYSDATE                                    ,--26
9488             L_FND_PROG_APPL_ID                         ,--27
9489             L_FND_CONC_REQUEST_ID                      ,--28
9490             x_ship_hdr_int_rec .attribute_category     ,--29
9491             x_ship_hdr_int_rec .attribute1             ,--30
9492             x_ship_hdr_int_rec .attribute2             ,--31
9493             x_ship_hdr_int_rec .attribute3             ,--32
9494             x_ship_hdr_int_rec .attribute4             ,--33
9495             x_ship_hdr_int_rec .attribute5             ,--34
9496             x_ship_hdr_int_rec .attribute6             ,--35
9497             x_ship_hdr_int_rec .attribute7             ,--36
9498             x_ship_hdr_int_rec .attribute8             ,--37
9499             x_ship_hdr_int_rec .attribute9             ,--38
9500             x_ship_hdr_int_rec .attribute10            ,--39
9501             x_ship_hdr_int_rec .attribute11            ,--40
9502             x_ship_hdr_int_rec .attribute12            ,--41
9503             x_ship_hdr_int_rec .attribute13            ,--42
9504             x_ship_hdr_int_rec .attribute14            ,--43
9505             x_ship_hdr_int_rec .attribute15             --44
9506         ) ;
9507     END IF;
9508 
9509     -- Bug 16310024
9510      x_ship_hdr_int_rec.ship_num := l_ship_num;
9511 
9512     -- Standard End of Procedure/Function Logging
9513     INL_LOGGING_PVT.Log_EndProc(
9514         p_module_name    => g_module_name,
9515         p_procedure_name => l_program_name);
9516 EXCEPTION
9517     WHEN L_FND_EXC_ERROR THEN
9518         -- Standard Expected Error Logging
9519         INL_LOGGING_PVT.Log_ExpecError (
9520             p_module_name    => g_module_name,
9521             p_procedure_name => l_program_name);
9522         x_return_status := L_FND_RET_STS_ERROR;
9523     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
9524         -- Standard Unexpected Error Logging
9525         INL_LOGGING_PVT.Log_UnexpecError (
9526             p_module_name    => g_module_name,
9527             p_procedure_name => l_program_name);
9528         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
9529     WHEN OTHERS THEN
9530         -- Standard Unexpected Error Logging
9531         INL_LOGGING_PVT.Log_UnexpecError (
9532             p_module_name    => g_module_name,
9533             p_procedure_name => l_program_name);
9534         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
9535         IF FND_MSG_PUB.Check_Msg_Level(
9536             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
9537         ) THEN
9538             FND_MSG_PUB.Add_Exc_Msg(
9539                 p_pkg_name       => g_pkg_name,
9540                 p_procedure_name => l_program_name);
9541         END IF;
9542 END Import_Headers;
9543 
9544 -- Utility name : Set_existingMatchInfoFlag
9545 -- Type       : Private
9546 -- Function   : Import Match Lines
9547 --
9548 --
9549 -- Pre-reqs   : None
9550 -- Parameters :
9551 -- IN         : p_from_parent_table_name
9552 --              p_from_parent_table_id
9553 --              p_to_parent_table_name
9554 --              p_to_parent_table_id
9555 --
9556 -- OUT        : x_existing_match_info_flag
9557 --              x_parent_match_id
9558 --              x_return_status
9559 -- Version    : Current version 1.0
9560 --
9561 -- Notes      :
9562 PROCEDURE Set_existingMatchInfoFlag(
9563     p_from_parent_table_name    IN VARCHAR2,
9564     p_from_parent_table_id      IN NUMBER,
9565     p_to_parent_table_name      IN VARCHAR2,
9566     p_to_parent_table_id        IN NUMBER,
9567     x_existing_match_info_flag  OUT NOCOPY VARCHAR2,
9568     x_parent_match_id           OUT NOCOPY NUMBER,
9569     x_return_status             OUT NOCOPY VARCHAR2
9570 ) IS
9571     l_program_name CONSTANT VARCHAR2(100) := 'Set_existingMatchInfoFlag';
9572     l_debug_info    VARCHAR2(2000) ;
9573     l_return_status VARCHAR2(1) ;
9574 BEGIN
9575     -- Standard Beginning of Procedure/Function Logging
9576     INL_LOGGING_PVT.Log_BeginProc(
9577         p_module_name    => g_module_name,
9578         p_procedure_name => l_program_name) ;
9579     -- Initialize API return status to success
9580     x_return_status := L_FND_RET_STS_SUCCESS;
9581     -- Include the lines with transaction_type = 'CREATE'
9582     l_debug_info := 'Deriving Existing_Match_Info_Flag';
9583     INL_LOGGING_PVT.Log_Statement(
9584         p_module_name       => g_module_name,
9585         p_procedure_name    => l_program_name,
9586         p_debug_info        => l_debug_info
9587     ) ;
9588     SELECT MIN(match_id)
9589     INTO   x_parent_match_id
9590     FROM inl_matches
9591     WHERE to_parent_table_id = p_to_parent_table_id
9592     AND to_parent_table_name = p_to_parent_table_name
9593     AND from_parent_table_id = p_from_parent_table_id
9594     AND from_parent_table_name = p_from_parent_table_name
9595     ;
9596     IF x_parent_match_id IS NOT NULL THEN
9597         x_existing_match_info_flag:='Y';
9598     ELSE
9599         x_existing_match_info_flag:='N';
9600     END IF;
9601     -- Standard End of Procedure/Function Logging
9602     INL_LOGGING_PVT.Log_EndProc(
9603         p_module_name    => g_module_name,
9604         p_procedure_name => l_program_name
9605     );
9606 EXCEPTION
9607     WHEN L_FND_EXC_ERROR THEN
9608         -- Standard Expected Error Logging
9609         INL_LOGGING_PVT.Log_ExpecError (
9610             p_module_name    => g_module_name,
9611             p_procedure_name => l_program_name
9612         );
9613         x_return_status := L_FND_RET_STS_ERROR;
9614     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
9615         -- Standard Unexpected Error Logging
9616         INL_LOGGING_PVT.Log_UnexpecError (
9617             p_module_name    => g_module_name,
9618             p_procedure_name => l_program_name
9619         );
9620         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
9621     WHEN OTHERS THEN
9622         -- Standard Unexpected Error Logging
9623         INL_LOGGING_PVT.Log_UnexpecError (
9624             p_module_name    => g_module_name,
9625             p_procedure_name => l_program_name
9626         );
9627         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
9628         IF FND_MSG_PUB.Check_Msg_Level(
9629             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
9630         ) THEN
9631             FND_MSG_PUB.Add_Exc_Msg(
9632                 p_pkg_name       => g_pkg_name,
9633                 p_procedure_name => l_program_name
9634             );
9635         END IF;
9636 END Set_existingMatchInfoFlag;
9637 
9638 -- Utility name : Derive_FromAP
9639 -- Type       : Private
9640 -- Function   : Make AP derivation
9641 --
9642 --
9643 -- Pre-reqs   : None
9644 -- Parameters :
9645 -- IN         : p_from_parent_table_name  VARCHAR2,
9646 --              p_from_parent_table_id    NUMBER,
9647 --              p_match_type_code         VARCHAR2,
9648 --
9649 -- IN/OUT     : x_matched_amt                   NUMBER,
9650 --              x_matched_qty                   NUMBER,
9651 --              x_nrec_tax_amt                  NUMBER,
9652 --              x_matched_uom_code              VARCHAR2,
9653 --              x_new_to_parent_table_name      VARCHAR2,
9654 --              x_new_to_parent_table_id        NUMBER,
9655 --              x_matched_curr_code             VARCHAR2,
9656 --              x_matched_curr_conversion_type  VARCHAR2,
9657 --              x_matched_curr_conversion_date  DATE,
9658 --              x_matched_curr_conversion_rate  NUMBER,
9659 --              x_ship_header_id                NUMBER,
9660 --              x_org_id                        NUMBER, --Bug#10381495
9661 --
9662 -- OUT        : x_existing_match_info_flag      VARCHAR2,
9663 --              x_parent_match_id               NUMBER,
9664 --              x_return_status                 VARCHAR2
9665 --
9666 -- Version    : Current version 1.0
9667 --
9668 -- Notes      : When the information come from AP the amounts variations
9669 --              are recorded in interface tables by the INL_MATCHES_GRP package
9670 --              and the adjustment program wait for final amounts.
9671 --              In order to equalize the information in this proc we:
9672 --              - receive the values of the new match
9673 PROCEDURE Derive_FromAP(
9674     p_from_parent_table_name        IN VARCHAR2,
9675     p_from_parent_table_id          IN NUMBER,
9676     p_match_type_code               IN VARCHAR2,
9677     x_matched_amt                   IN OUT NOCOPY NUMBER,
9678     x_matched_qty                   IN OUT NOCOPY NUMBER,
9679     x_nrec_tax_amt                  IN OUT NOCOPY NUMBER,
9680     x_matched_uom_code              IN OUT NOCOPY VARCHAR2,
9681     x_new_to_parent_table_name      IN OUT NOCOPY VARCHAR2,
9682     x_new_to_parent_table_id        IN OUT NOCOPY NUMBER,
9683     x_matched_curr_code             IN OUT NOCOPY VARCHAR2,
9684     x_matched_curr_conversion_type  IN OUT NOCOPY VARCHAR2,
9685     x_matched_curr_conversion_date  IN OUT NOCOPY DATE,
9686     x_matched_curr_conversion_rate  IN OUT NOCOPY NUMBER,
9687     x_ship_header_id                IN OUT NOCOPY NUMBER,
9688     x_org_id                        IN OUT NOCOPY NUMBER, --Bug#10381495
9689     x_existing_match_info_flag      OUT NOCOPY VARCHAR2,
9690     x_parent_match_id               OUT NOCOPY NUMBER,
9691     x_return_status                 OUT NOCOPY VARCHAR2
9692 ) IS
9693     l_program_name CONSTANT VARCHAR2(100) := 'Derive_FromAP';
9694     l_debug_info    VARCHAR2(2000) ;
9695     l_return_status VARCHAR2(1) ;
9696 
9697     l_inventory_item_id NUMBER;
9698     l_match_type VARCHAR2(30);
9699     l_line_type_lookup_code VARCHAR2(30);
9700     l_mat_curr_code_P VARCHAR2(30);
9701     l_mat_curr_rate_P NUMBER;
9702     l_mat_curr_type_P VARCHAR2(30);
9703     l_mat_curr_date_P DATE;
9704     l_mat_nrec_tax_amt_P NUMBER;
9705     l_mat_charge_line_type_id_P NUMBER;
9706     l_mat_qty_P NUMBER;
9707     l_mat_uom_code_P VARCHAR2(30);
9708     l_mat_amt_P NUMBER;
9709     l_mat_par_mat_id_P  NUMBER;
9710     l_ship_header_id_tab inl_int_table := inl_int_table() ;
9711     l_corr_from_parent_table_name VARCHAR2(30);
9712     l_corr_from_parent_table_id NUMBER;
9713     l_currency_conversion_rate NUMBER;
9714 
9715 BEGIN
9716     -- Standard Beginning of Procedure/Function Logging
9717     INL_LOGGING_PVT.Log_BeginProc(
9718         p_module_name    => g_module_name,
9719         p_procedure_name => l_program_name) ;
9720 
9721     -- Initialize API return status to success
9722     x_return_status := L_FND_RET_STS_SUCCESS;
9723     -- Include the lines with transaction_type = 'CREATE'
9724     l_debug_info := 'Include the lines with transaction_type = CREATE';
9725     INL_LOGGING_PVT.Log_Statement(
9726         p_module_name       => g_module_name,
9727         p_procedure_name    => l_program_name,
9728         p_debug_info        => l_debug_info
9729     ) ;
9730     IF x_new_to_parent_table_name = 'RCV_TRANSACTIONS' THEN
9731         x_new_to_parent_table_name := 'INL_SHIP_LINES';
9732         SELECT  lcm_shipment_line_id
9733         INTO x_new_to_parent_table_id
9734         FROM rcv_transactions rt
9735         WHERE rt.transaction_id = x_new_to_parent_table_id
9736         ;
9737     END IF;
9738     Set_existingMatchInfoFlag(
9739         p_from_parent_table_name    => p_from_parent_table_name,
9740         p_from_parent_table_id      => p_from_parent_table_id,
9741         p_to_parent_table_name      => x_new_to_parent_table_name,
9742         p_to_parent_table_id        => x_new_to_parent_table_id,
9743         x_existing_match_info_flag  => x_existing_match_info_flag,
9744         x_parent_match_id           => x_parent_match_id,
9745         x_return_status             => x_return_status
9746     );
9747 
9748      -- If any errors happen abort API.
9749     IF l_return_status = L_FND_RET_STS_ERROR THEN
9750         RAISE L_FND_EXC_ERROR;
9751     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
9752         RAISE L_FND_EXC_UNEXPECTED_ERROR;
9753     END IF;
9754 -- Migrated from matche_grp
9755     SELECT l.line_type_lookup_code,
9756            d.org_id,
9757            l.inventory_item_id,
9758            l.match_type
9759     INTO   l_line_type_lookup_code,
9760            x_org_id, --Bug#10381495
9761            l_inventory_item_id,
9762            l_match_type
9763     FROM   ap_invoice_distributions_all d, --Bug#10381495
9764            ap_invoice_lines_all l          --Bug#10381495
9765     WHERE  d.invoice_distribution_id = p_from_parent_table_id
9766     AND    d.invoice_id = l.invoice_id
9767     AND    d.invoice_line_number = l.line_number
9768     ;
9769 
9770     l_debug_info := 'Getting from inl_corr_matches_v the current value for transaction.';
9771     INL_LOGGING_PVT.Log_Statement(
9772         p_module_name    => g_module_name,
9773         p_procedure_name => l_program_name,
9774         p_debug_info     => l_debug_info
9775     );
9776 
9777     IF p_match_type_code = 'CORRECTION'
9778     THEN
9779         l_debug_info := 'Is a correction. Type: '||l_match_type;
9780         INL_LOGGING_PVT.Log_Statement(
9781             p_module_name    => g_module_name,
9782             p_procedure_name => l_program_name,
9783             p_debug_info     => l_debug_info) ;
9784 
9785         IF l_line_type_lookup_code = 'ITEM' THEN
9786             IF x_existing_match_info_flag = 'Y' THEN   -- RESUBMIT A CORRECTION
9787                -- select based on inl_corr_matches_v
9788                 SELECT
9789                     mat1.matched_curr_code       ,
9790                     mat1.matched_curr_conversion_rate,
9791                     mat1.matched_curr_conversion_type,
9792                     mat1.matched_curr_conversion_date,
9793                     NULL nrec_tax_amt             ,
9794                     NULL charge_line_type_id      ,
9795                     mat1.matched_qty                ,
9796                     mat1.matched_uom_code           ,
9797                     NVL(DECODE(mat1.matched_curr_code, mat2.matched_curr_code, mat2.matched_amt,
9798                                                             inl_landedcost_pvt.Converted_Amt(
9799                                                                 mat2.matched_amt,
9800                                                                 mat2.matched_curr_code,
9801                                                                 mat1.matched_curr_code,
9802                                                                 mat1.matched_curr_conversion_type,
9803                                                                 mat1.matched_curr_conversion_date))
9804                                                                 , mat1.matched_amt) AS matched_amt,
9805                     mat1.match_id,
9806                     mat2.from_parent_table_name,
9807                     mat2.from_parent_table_id
9808                 INTO
9809                     l_mat_curr_code_P          ,
9810                     l_mat_curr_rate_P          ,
9811                     l_mat_curr_type_P          ,
9812                     l_mat_curr_date_P          ,
9813                     l_mat_nrec_tax_amt_P       ,
9814                     l_mat_charge_line_type_id_P,
9815                     l_mat_qty_P                ,
9816                     l_mat_uom_code_P           ,
9817                     l_mat_amt_P                ,
9818                     l_mat_par_mat_id_P         ,
9819                     l_corr_from_parent_table_name,
9820                     l_corr_from_parent_table_id
9821                 FROM
9822                     inl_matches mat1,
9823                     (select *
9824                        from inl_matches m2
9825                        where NOT (m2.from_parent_table_name = p_from_parent_table_name
9826                              AND m2.from_parent_table_id = p_from_parent_table_id)
9827                     ) mat2
9828                 WHERE
9829                     mat2.parent_match_id (+) = mat1.match_id
9830                     AND mat2.match_type_code (+) = 'CORRECTION'
9831                     AND mat1.from_parent_table_name = x_new_to_parent_table_name
9832                     AND mat1.from_parent_table_id   = x_new_to_parent_table_id
9833                     AND mat1.match_id
9834                     =(
9835                         SELECT MAX(mat1B.match_id)
9836                         FROM inl_matches mat1B
9837                         WHERE mat1B.to_parent_table_name = mat1.to_parent_table_name
9838                         AND mat1B.to_parent_table_id     = mat1.to_parent_table_id
9839                         AND mat1B.from_parent_table_name = mat1.from_parent_table_name
9840                         AND mat1B.from_parent_table_id   = mat1.from_parent_table_id
9841                     )
9842                     AND (mat2.match_id is null
9843                          OR mat2.match_id = mat1.match_id
9844                          OR mat2.match_id
9845                         =(
9846                             SELECT MAX(DECODE(mat2.match_id, mat1.match_id, NULL, mat2.match_id))
9847                             FROM inl_matches mat1C,
9848                                  inl_matches mat2C
9849                             WHERE mat2C.parent_match_id (+) = mat1C.match_id
9850                             AND mat2C.match_type_code (+) = 'CORRECTION'
9851                             AND NOT (mat2C.from_parent_table_name = p_from_parent_table_name
9852                                      AND mat2C.from_parent_table_id = p_from_parent_table_id)
9853                             AND mat1C.from_parent_table_name = mat1.from_parent_table_name
9854                             AND mat1C.from_parent_table_id   = mat1.from_parent_table_id
9855                          ))
9856                 ;
9857             ELSE
9858                 l_corr_from_parent_table_name := NULL;
9859                 l_corr_from_parent_table_id := NULL;
9860                 SELECT
9861                     mP.matched_curr_code       ,
9862                     mP.matched_curr_conversion_rate,
9863                     mP.matched_curr_conversion_type,
9864                     mP.matched_curr_conversion_date,
9865                     NULL nrec_tax_amt             ,
9866                     NULL charge_line_type_id      ,
9867                     mP.matched_qty                ,
9868                     mP.matched_uom_code           ,
9869                     mP.matched_amt                ,
9870                     mP.match_id
9871                 INTO
9872                     l_mat_curr_code_P          ,
9873                     l_mat_curr_rate_P          ,
9874                     l_mat_curr_type_P          ,
9875                     l_mat_curr_date_P          ,
9876                     l_mat_nrec_tax_amt_P       ,
9877                     l_mat_charge_line_type_id_P,
9878                     l_mat_qty_P                ,
9879                     l_mat_uom_code_P           ,
9880                     l_mat_amt_P                ,
9881                     l_mat_par_mat_id_P
9882                 FROM
9883                     inl_corr_matches_v mP -- 1 get the parent
9884                 WHERE mP.from_parent_table_name = x_new_to_parent_table_name
9885                 AND mP.from_parent_table_id   = x_new_to_parent_table_id
9886                 AND mP.match_id
9887                     =(
9888                         SELECT MAX(m1P.match_id)
9889                         FROM inl_corr_matches_v m1P
9890                         WHERE m1P.from_parent_table_name = mP.from_parent_table_name
9891                         AND m1P.from_parent_table_id   = mP.from_parent_table_id
9892                 )
9893                 AND (mP.correction_match_id IS NULL
9894                      OR mP.correction_match_id
9895                     =(
9896                         SELECT MAX(m1P.correction_match_id)
9897                         FROM inl_corr_matches_v m1P
9898                         WHERE m1P.from_parent_table_name = mP.from_parent_table_name
9899                         AND m1P.from_parent_table_id   = mP.from_parent_table_id
9900                 ))
9901                 ;
9902             END IF;
9903 
9904             l_debug_info := 'match_type: '||l_match_type;
9905             INL_LOGGING_PVT.Log_Statement(
9906                 p_module_name    => g_module_name,
9907                 p_procedure_name => l_program_name,
9908                 p_debug_info     => l_debug_info
9909             );
9910 
9911             IF l_match_type = 'PRICE_CORRECTION' THEN
9912                 x_matched_qty := l_mat_qty_P;
9913 
9914             ELSE
9915                 IF l_mat_uom_code_P <> x_matched_uom_code THEN
9916                     x_matched_qty :=
9917                         INL_LANDEDCOST_PVT.Converted_Qty(
9918                             p_organization_id   => x_org_id,--Bug#10381495
9919                             p_inventory_item_id => l_inventory_item_id,
9920                             p_qty               => x_matched_qty,
9921                             p_from_uom_code     => x_matched_uom_code,
9922                             P_to_uom_code       => l_mat_uom_code_P
9923                         )
9924                     ;
9925 
9926                 END IF;
9927                 x_matched_qty := x_matched_qty + NVL(l_mat_qty_P, 0) ;
9928             END IF;
9929             x_matched_uom_code := l_mat_uom_code_P;
9930         ELSE -- isn't a ITEM
9931             SELECT
9932                 m.matched_curr_code           ,
9933                 m.matched_curr_conversion_rate,
9934                 m.matched_curr_conversion_type,
9935                 m.matched_curr_conversion_date,
9936                 m.nrec_tax_amt                ,
9937                 m.charge_line_type_id         ,
9938                 m.matched_qty                 ,
9939                 m.matched_uom_code            ,
9940                 m.matched_amt                 ,
9941                 m.match_id
9942             INTO
9943                 l_mat_curr_code_P          ,
9944                 l_mat_curr_rate_P          ,
9945                 l_mat_curr_type_P          ,
9946                 l_mat_curr_date_P          ,
9947                 l_mat_nrec_tax_amt_P       ,
9948                 l_mat_charge_line_type_id_P,
9949                 l_mat_qty_P                ,
9950                 l_mat_uom_code_P           ,
9951                 l_mat_amt_P                ,
9952                 l_mat_par_mat_id_P
9953             FROM inl_corr_matches_v m
9954             WHERE m.from_parent_table_name = x_new_to_parent_table_name
9955             AND m.from_parent_table_id   = x_new_to_parent_table_id
9956             AND m.match_id               =
9957                (
9958                      SELECT MAX(m1.match_id)
9959                        FROM inl_corr_matches_v m1
9960                       WHERE m1.from_parent_table_name = x_new_to_parent_table_name
9961                         AND m1.from_parent_table_id   = x_new_to_parent_table_id
9962                 )
9963             ;
9964         END IF;
9965 
9966         IF l_mat_curr_code_P <> x_matched_curr_code THEN
9967             --correction
9968             l_debug_info := 'conversion required.';
9969             INL_LOGGING_PVT.Log_Statement(
9970                 p_module_name    => g_module_name,
9971                 p_procedure_name => l_program_name,
9972                 p_debug_info     => l_debug_info
9973             );
9974             x_matched_amt := INL_LANDEDCOST_PVT.Converted_Amt(
9975                                 p_amt                       => NVL(x_matched_amt, 0),
9976                                 p_from_currency_code        => x_matched_curr_code,
9977                                 p_to_currency_code          => l_mat_curr_code_P,
9978                                 p_currency_conversion_type  => NVL(l_mat_curr_type_P,x_matched_curr_conversion_type),
9979                                 p_currency_conversion_date  => NVL(l_mat_curr_date_P,x_matched_curr_conversion_date),
9980                                 x_currency_conversion_rate  => l_currency_conversion_rate
9981                             )
9982             ;
9983             IF NVL(x_nrec_tax_amt, 0) <> 0 THEN
9984                 l_debug_info := 'conversion required for Not recoverable tax.';
9985                 INL_LOGGING_PVT.Log_Statement(
9986                     p_module_name    => g_module_name,
9987                     p_procedure_name => l_program_name,
9988                     p_debug_info     => l_debug_info
9989                 );
9990 
9991                 x_nrec_tax_amt := inl_landedcost_pvt.Converted_Amt(
9992                                       p_amt                       => NVL(x_nrec_tax_amt, 0),
9993                                       p_from_currency_code        => x_matched_curr_code,
9994                                       p_to_currency_code          => l_mat_curr_code_P,
9995                                       p_currency_conversion_type  => NVL(l_mat_curr_type_P,x_matched_curr_conversion_type),
9996                                       p_currency_conversion_date  => NVL(l_mat_curr_date_P,x_matched_curr_conversion_date),
9997                                       x_currency_conversion_rate  => l_currency_conversion_rate
9998                                   )
9999                 ;
10000             END IF;
10001         END IF;
10002         x_matched_curr_code            := l_mat_curr_code_P;
10003         x_matched_curr_conversion_type := l_mat_curr_type_P;
10004         x_matched_curr_conversion_date := l_mat_curr_date_P;
10005         x_matched_curr_conversion_rate := l_currency_conversion_rate; --l_mat_curr_rate_P;
10006 
10007         IF x_existing_match_info_flag = 'Y'
10008             AND l_corr_from_parent_table_id IS NOT NULL
10009             AND l_corr_from_parent_table_id > p_from_parent_table_id
10010         THEN
10011             x_matched_amt := NVL(x_matched_amt,0) + NVL(x_nrec_tax_amt, 0); -- RESUBMIT A CORRECTION THAT ISN'T THE LAST CORRECTION
10012         ELSE
10013             x_matched_amt := NVL(x_matched_amt,0) + NVL(x_nrec_tax_amt, 0) + NVL(l_mat_amt_P, 0);
10014         END IF;
10015         x_parent_match_id := l_mat_par_mat_id_P;
10016         IF NVL(x_nrec_tax_amt, 0) <> 0 OR NVL(l_mat_nrec_tax_amt_P, 0) <> 0 THEN
10017             x_nrec_tax_amt := NVL(x_nrec_tax_amt, 0) + NVL(l_mat_nrec_tax_amt_P, 0) ;
10018         END IF;
10019     END IF;
10020 
10021     IF x_new_to_parent_table_name = 'INL_SHIP_HEADERS' THEN
10022         SELECT ship_header_id
10023         INTO x_ship_header_id
10024         FROM inl_ship_headers_all --Bug#10381495
10025         WHERE ship_header_id = x_new_to_parent_table_id;
10026     ELSIF x_new_to_parent_table_name = 'INL_SHIP_LINES' THEN
10027         SELECT ship_header_id
10028         INTO x_ship_header_id
10029         FROM inl_ship_lines_all --Bug#10381495
10030         WHERE ship_line_id  = x_new_to_parent_table_id;
10031     ELSIF x_new_to_parent_table_name = 'INL_SHIP_LINE_GROUPS' THEN
10032         SELECT ship_header_id
10033         INTO x_ship_header_id
10034         FROM inl_ship_line_groups
10035         WHERE ship_line_group_id = x_new_to_parent_table_id;
10036     ELSIF x_new_to_parent_table_name = 'INL_CHARGE_LINES' THEN
10037         l_ship_header_id_tab.DELETE;
10038         SELECT DISTINCT(a.ship_header_id) BULK COLLECT
10039         INTO l_ship_header_id_tab
10040         FROM inl_charge_lines c,
10041         inl_associations a
10042         WHERE c.charge_line_id              = x_new_to_parent_table_id
10043         AND a.from_parent_table_name      = 'INL_CHARGE_LINES'
10044         AND a.from_parent_table_id        = c.charge_line_id;
10045         IF NVL(l_ship_header_id_tab.COUNT, 0) = 1 THEN
10046             x_ship_header_id                 := l_ship_header_id_tab(1) ;
10047         END IF;
10048     ELSIF x_new_to_parent_table_name = 'INL_TAX_LINES' THEN
10049         SELECT ship_header_id
10050         INTO x_ship_header_id
10051         FROM inl_tax_lines
10052         WHERE tax_line_id   = x_new_to_parent_table_id;
10053     ELSE -- In case of correction, the table is out of LCM limit
10054         SELECT ship_header_id
10055         INTO x_ship_header_id
10056         FROM inl_matches
10057         WHERE match_id     = l_mat_par_mat_id_P;
10058     END IF;
10059 --
10060     -- Standard End of Procedure/Function Logging
10061     INL_LOGGING_PVT.Log_EndProc(
10062         p_module_name    => g_module_name,
10063         p_procedure_name => l_program_name
10064     );
10065 EXCEPTION
10066     WHEN L_FND_EXC_ERROR THEN
10067         -- Standard Expected Error Logging
10068         INL_LOGGING_PVT.Log_ExpecError (
10069             p_module_name    => g_module_name,
10070             p_procedure_name => l_program_name
10071         );
10072         x_return_status := L_FND_RET_STS_ERROR;
10073     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
10074         -- Standard Unexpected Error Logging
10075         INL_LOGGING_PVT.Log_UnexpecError (
10076             p_module_name    => g_module_name,
10077             p_procedure_name => l_program_name
10078         );
10079         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
10080     WHEN OTHERS THEN
10081         -- Standard Unexpected Error Logging
10082         INL_LOGGING_PVT.Log_UnexpecError (
10083             p_module_name    => g_module_name,
10084             p_procedure_name => l_program_name
10085         );
10086         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
10087         IF FND_MSG_PUB.Check_Msg_Level(
10088             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
10089         ) THEN
10090             FND_MSG_PUB.Add_Exc_Msg(
10091                 p_pkg_name       => g_pkg_name,
10092                 p_procedure_name => l_program_name
10093             );
10094         END IF;
10095 END Derive_FromAP;
10096 
10097 
10098 -- Utility name : call_ShpmtPvtAdjLin    --BUG#8198498
10099 -- Type       : Private
10100 -- Function   : Call INL_SHIPMENT_PVT.Adjust_Lines in order to get all
10101 --              adjustment lines created in submit's time
10102 --
10103 -- Pre-reqs   : None
10104 -- Parameters :
10105 -- IN         : p_group_id      IN  NUMBER
10106 --
10107 -- OUT        : x_return_status OUT NOCOPY VARCHAR2
10108 --
10109 -- Version    : Current version 1.0
10110 --
10111 -- Notes      :
10112 PROCEDURE call_ShpmtPvtAdjLin(      --BUG#8198498
10113     p_match_type_code       IN VARCHAR2,
10114     p_to_parent_table_name  IN VARCHAR2,
10115     p_to_parent_table_id    IN NUMBER,
10116     p_ship_header_id        IN NUMBER,
10117     x_return_status        OUT NOCOPY VARCHAR2
10118 ) IS
10119     l_program_name CONSTANT VARCHAR2(100) := 'call_ShpmtPvtAdjLin';
10120     l_debug_info    VARCHAR2(2000) ;
10121     l_return_status VARCHAR2(1) ;
10122     l_msg_count NUMBER;
10123     l_msg_data VARCHAR2 (2000);
10124 
10125     Cursor c_prorates_affctdByItem is
10126 --Bug#14044298 BEG
10127     SELECT DISTINCT assoc2.ship_header_id
10128     FROM inl_associations assoc2
10129     WHERE (assoc2.from_parent_table_name,assoc2.from_parent_table_id)
10130             IN (select assoc.from_parent_table_name,assoc.from_parent_table_id
10131                 from inl_associations assoc
10132                WHERE assoc.to_parent_table_name = p_to_parent_table_name
10133                 AND assoc.to_parent_table_id    = p_to_parent_table_id
10134               )
10135     ;
10136 
10137 /*
10138     SELECT DISTINCT assoc2.ship_header_id
10139     FROM inl_associations assoc2
10140     WHERE CONNECT_BY_ISLEAF = 1
10141     START WITH (assoc2.from_parent_table_name,assoc2.from_parent_table_id)
10142             IN (select assoc.from_parent_table_name,assoc.from_parent_table_id
10143                 from inl_associations assoc
10144                WHERE assoc.to_parent_table_name = p_to_parent_table_name
10145                 AND assoc.to_parent_table_id    = p_to_parent_table_id
10146               )
10147     CONNECT BY PRIOR assoc2.from_parent_table_name = assoc2.to_parent_table_name
10148                  AND assoc2.from_parent_table_id = assoc2.to_parent_table_id
10149     ;
10150 */
10151 --Bug#14044298 END
10152     TYPE c_prorates_affctdByItem_Type IS
10153         TABLE OF c_prorates_affctdByItem%ROWTYPE;
10154     prorates_affctdByItem_lin c_prorates_affctdByItem_Type;
10155 
10156     l_count_unproc_match NUMBER; --Bug#14044298
10157 BEGIN
10158     -- Standard Beginning of Procedure/Function Logging
10159     INL_LOGGING_PVT.Log_BeginProc(
10160         p_module_name    => g_module_name,
10161         p_procedure_name => l_program_name
10162     ) ;
10163     -- Initialize API return status to success
10164     x_return_status := L_FND_RET_STS_SUCCESS;
10165     l_debug_info := 'Processing Match Amounts';
10166     INL_LOGGING_PVT.Log_Statement(
10167         p_module_name      => g_module_name,
10168         p_procedure_name   => l_program_name,
10169         p_debug_info       => l_debug_info
10170     ) ;
10171 --
10172     IF p_match_type_code = 'ITEM' THEN
10173         OPEN c_prorates_affctdByItem;
10174         FETCH c_prorates_affctdByItem BULK COLLECT INTO prorates_affctdByItem_lin;
10175         CLOSE c_prorates_affctdByItem;
10176         l_debug_info := prorates_affctdByItem_lin.COUNT||' lines have been retrieved.';
10177         INL_LOGGING_PVT.Log_Statement (
10178             p_module_name => g_module_name,
10179             p_procedure_name => l_program_name,
10180             p_debug_info => l_debug_info
10181         ) ;
10182         FOR i IN 1 .. prorates_affctdByItem_lin.COUNT
10183         LOOP
10184                 l_debug_info := 'Updating : '||prorates_affctdByItem_lin(i).ship_header_id;
10185                 INL_LOGGING_PVT.Log_Statement (
10186                     p_module_name => g_module_name,
10187                     p_procedure_name => l_program_name,
10188                     p_debug_info => l_debug_info
10189                 ) ;
10190                 -- Set Shipment Header's pending_matching_flag to 'Y'
10191                 inl_shipment_pvt.Update_PendingMatchingFlag(  --BUG#8198498
10192                     p_ship_header_id        => prorates_affctdByItem_lin(i).ship_header_id,
10193                     p_pending_matching_flag => 'Y',
10194                     x_return_status         => l_return_status
10195                 );
10196                 -- If any errors happen abort API.
10197                 IF l_return_status = L_FND_RET_STS_ERROR THEN
10198                     RAISE L_FND_EXC_ERROR;
10199                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
10200                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
10201                 END IF;
10202         END LOOP;
10203     END IF;
10204 
10205     --Bug#14044298 BEGING
10206 
10207     l_debug_info := 'Verify if call to Adjust Lines is required';
10208     INL_LOGGING_PVT.Log_Statement (
10209         p_module_name => g_module_name,
10210         p_procedure_name => l_program_name,
10211         p_debug_info => l_debug_info
10212     ) ;
10213     SELECT COUNT(*)
10214     INTO l_count_unproc_match
10215     FROM inl_matches m
10216     WHERE m.ship_header_id = p_ship_header_id
10217     AND NVL(m.adj_already_generated_flag, 'N') = 'N';
10218 
10219     l_debug_info := p_ship_header_id||' => '|| l_count_unproc_match ||' unprocessed match(es) ';
10220     INL_LOGGING_PVT.Log_Statement (
10221         p_module_name => g_module_name,
10222         p_procedure_name => l_program_name,
10223         p_debug_info => l_debug_info
10224     ) ;
10225     IF NVL(l_count_unproc_match,0) > 0 THEN
10226     --Bug#14044298 END
10227         l_debug_info := 'Run INL_SHIPMENT_PVT.Adjust_Lines';
10228         INL_LOGGING_PVT.Log_Statement (
10229             p_module_name => g_module_name,
10230             p_procedure_name => l_program_name,
10231             p_debug_info => l_debug_info
10232        ) ;
10233 
10234         inl_shipment_pvt.Adjust_Lines (
10235             p_api_version       => 1.0,
10236             p_init_msg_list     => L_FND_FALSE,
10237             p_commit            => L_FND_FALSE,
10238             p_ship_header_id    => p_ship_header_id,
10239             x_return_status     => l_return_status,
10240             x_msg_count         => l_msg_count,
10241             x_msg_data          => l_msg_data
10242         ) ;
10243 
10244         -- If any errors happen abort the process.
10245         IF l_return_status = L_FND_RET_STS_ERROR THEN
10246             RAISE L_FND_EXC_ERROR;
10247         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
10248             RAISE L_FND_EXC_UNEXPECTED_ERROR;
10249         END IF;
10250     END IF;
10251 --
10252     -- Standard End of Procedure/Function Logging
10253     INL_LOGGING_PVT.Log_EndProc(
10254         p_module_name    => g_module_name,
10255         p_procedure_name => l_program_name
10256     );
10257 EXCEPTION
10258     WHEN L_FND_EXC_ERROR THEN
10259         -- Standard Expected Error Logging
10260         INL_LOGGING_PVT.Log_ExpecError (
10261             p_module_name    => g_module_name,
10262             p_procedure_name => l_program_name
10263         );
10264         x_return_status := L_FND_RET_STS_ERROR;
10265     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
10266         -- Standard Unexpected Error Logging
10267         INL_LOGGING_PVT.Log_UnexpecError (
10268             p_module_name    => g_module_name,
10269             p_procedure_name => l_program_name
10270         );
10271         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
10272     WHEN OTHERS THEN
10273         -- Standard Unexpected Error Logging
10274         INL_LOGGING_PVT.Log_UnexpecError (
10275             p_module_name    => g_module_name,
10276             p_procedure_name => l_program_name
10277         );
10278         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
10279         IF FND_MSG_PUB.Check_Msg_Level(
10280             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
10281         ) THEN
10282             FND_MSG_PUB.Add_Exc_Msg(
10283                 p_pkg_name       => g_pkg_name,
10284                 p_procedure_name => l_program_name
10285             );
10286         END IF;
10287 END call_ShpmtPvtAdjLin;
10288 
10289 -- Utility name : Import_Matches
10290 -- Type       : Private
10291 -- Function   : Import Match Lines
10292 --
10293 --
10294 -- Pre-reqs   : None
10295 -- Parameters :
10296 -- IN         : p_group_id      IN  NUMBER
10297 --
10298 -- OUT        : x_return_status OUT NOCOPY VARCHAR2
10299 --
10300 -- Version    : Current version 1.0
10301 --
10302 -- Notes      :
10303 PROCEDURE Import_Matches(
10304     p_group_id      IN NUMBER,
10305     p_commit        IN VARCHAR2, --Bug#11794442
10306     x_return_status OUT NOCOPY VARCHAR2
10307 ) IS
10308     l_program_name CONSTANT VARCHAR2(100) := 'Import_Matches';
10309     l_debug_info    VARCHAR2(2000) ;
10310     l_return_status VARCHAR2(1) ;
10311 
10312     --Bug#11794442 begin
10313     -- in case of error during the processing of a match all matches belong to the same group_id should be rolled back
10314     -- in order to control this situation whe should run sepparetly each group id because we have 2 cursors that are run sepparetly
10315     -- one for match amounts creation and another for matches creation
10316 
10317     CURSOR c_distgroupid (p_initial_sysdate date)
10318     IS
10319         SELECT
10320             MIN(DECODE(mp.process_enabled_flag,'Y',NVL(mi.adj_group_date,p_initial_sysdate),p_initial_sysdate)) adj_group_date,  -- OPM Integration
10321             mi.group_id
10322         FROM inl_matches_int mi,
10323              rcv_transactions rt, -- OPM Integration
10324              mtl_parameters mp
10325         WHERE mi.processing_status_code = 'RUNNING' /* Point 1: If any change occur here the other 4 points might be affected */
10326         AND   (p_group_id   IS NULL
10327                 OR p_group_id = mi.group_id)
10328         AND mi.to_parent_table_name = 'RCV_TRANSACTIONS'
10329         AND mi.to_parent_table_id = rt.transaction_id
10330         AND rt.organization_id = mp.organization_id
10331         AND mi.request_id = l_fnd_conc_request_id_int --Bug#11794442
10332         group by mi.group_id
10333         order by MIN(DECODE(mp.process_enabled_flag,'Y',NVL(mi.adj_group_date,p_initial_sysdate),p_initial_sysdate)), mi.group_id
10334     ;
10335 
10336     TYPE distgroupid_ListType IS TABLE OF c_distgroupid%ROWTYPE;
10337     distgroupid_List distgroupid_ListType;
10338 
10339     --Bug#11794442 end
10340 
10341     -- Cursor to get all valid and possible Matches
10342     -- that will be used in the import process
10343     CURSOR matchAmountsToProcess (pc_initial_sysdate DATE,
10344                                   pc_group_id NUMBER) --Bug#11794442
10345     IS
10346         SELECT NULL new_match_Amount_id, -- BUG#8411723 => MURALI --BUG#8264388
10347            max(DECODE(mp.process_enabled_flag,'Y',
10348                       NVL(mi.adj_group_date,pc_initial_sysdate),pc_initial_sysdate)) adj_group_date,  -- OPM Integration,
10349                                                                        -- if an freight invoice has 2 lines to different organization can have 2
10350                                                                        -- different dates but need to be consider as an unic match amount in order to be re-prorated
10351            sum(mi.matched_amt) matched_amt,
10352            sum(mi.nrec_tax_amt) nrec_tax_amt,
10353            count(distinct(
10354                DECODE(mp.process_enabled_flag,'Y',
10355                       NVL(mi.adj_group_date,pc_initial_sysdate),pc_initial_sysdate))) count_adj_group_date,
10356            mi.matched_curr_code           ,
10357            mi.matched_curr_conversion_type,
10358            mi.matched_curr_conversion_date,
10359            mi.matched_curr_conversion_rate,
10360            mi.transaction_type,
10361            mi.group_id,                --BUG#8264388
10362            mi.charge_line_type_id,     --BUG#8264388
10363            mi.tax_code                 --BUG#8264388
10364         FROM inl_matches_int mi,
10365              rcv_transactions rt, -- OPM Integration
10366              mtl_parameters mp    -- OPM Integration
10367         WHERE mi.processing_status_code = 'RUNNING'
10368         AND   ((pc_group_id IS NULL AND mi.group_id IS NULL)
10369                OR mi.group_id = pc_group_id) --Bug#11794442
10370         AND mi.match_amounts_flag = 'Y'
10371         AND mi.to_parent_table_name = 'RCV_TRANSACTIONS'
10372         AND mi.to_parent_table_id = rt.transaction_id
10373         AND rt.organization_id = mp.organization_id
10374         AND mi.request_id = l_fnd_conc_request_id_int --Bug#11794442
10375         GROUP BY
10376            mi.matched_curr_code           ,
10377            mi.matched_curr_conversion_type,
10378            mi.matched_curr_conversion_date,
10379            mi.matched_curr_conversion_rate,
10380            mi.transaction_type,
10381            mi.group_id,
10382            mi.charge_line_type_id,
10383            mi.tax_code
10384         ORDER BY mi.group_id  -- BUG#8411723 => MURALI  --BUG#8264388
10385 ;
10386 
10387     TYPE matchAmountsToProcess_ListType IS TABLE OF matchAmountsToProcess%ROWTYPE;
10388     matchAmountsToProcess_List matchAmountsToProcess_ListType;
10389 
10390     CURSOR matchesToProcess (pc_initial_sysdate date,
10391                              pc_group_id NUMBER) --Bug#11794442
10392     IS
10393          SELECT NULL new_match_id, -- BUG#8411723 => MURALI
10394            DECODE(mp.process_enabled_flag,'Y',NVL(mi.adj_group_date,pc_initial_sysdate),pc_initial_sysdate) adj_group_date,  -- OPM Integration
10395             mi.match_type_code       ,
10396             mi.from_parent_table_name,
10397             mi.from_parent_table_id  ,
10398             mi.to_parent_table_name  ,
10399             mi.to_parent_table_id    ,
10400             mi.matched_qty                 ,
10401             mi.matched_uom_code            ,
10402             mi.matched_amt                 ,
10403             mi.matched_curr_code           ,
10404             mi.matched_curr_conversion_type,
10405             mi.matched_curr_conversion_date,
10406             mi.matched_curr_conversion_rate,
10407             mi.replace_estim_qty_flag      ,
10408             mi.charge_line_type_id  ,
10409             mi.party_id             ,
10410             mi.party_site_id        ,
10411             mi.tax_code             ,
10412             mi.nrec_tax_amt         ,
10413             mi.tax_amt_included_flag,
10414             mi.match_int_id         ,
10415             mi.transaction_type     ,
10416             NULL ship_header_id     ,
10417             NULL org_id             , --Bug#10381495
10418             mi.match_amounts_flag   , --BUG#8264388
10419             mi.group_id               --BUG#8264388
10420          FROM inl_matches_int mi,
10421              rcv_transactions rt, -- OPM Integration
10422              mtl_parameters mp
10423          WHERE mi.processing_status_code = 'RUNNING' /* Point 1: If any change occur here the other 4 points might be affected */
10424         AND   ((pc_group_id IS NULL AND mi.group_id IS NULL)
10425                OR mi.group_id = pc_group_id) --Bug#11794442
10426          AND mi.to_parent_table_name = 'RCV_TRANSACTIONS'
10427          AND mi.to_parent_table_id = rt.transaction_id
10428          AND rt.organization_id = mp.organization_id
10429          AND mi.request_id = l_fnd_conc_request_id_int --Bug#11794442
10430         order by DECODE(mp.process_enabled_flag,'Y',NVL(mi.adj_group_date,pc_initial_sysdate),pc_initial_sysdate), -- OPM Integration
10431                  mi.match_int_id -- BUG#8411723 => MURALI
10432     ;
10433 
10434     TYPE matchesToProcess_ListType IS TABLE OF matchesToProcess%ROWTYPE;
10435     matchesToProcess_List matchesToProcess_ListType;
10436 
10437     -- SCM-051
10438     CURSOR c_shipToProcess(pc_group_id NUMBER)IS
10439     SELECT sh.ship_num
10440     FROM inl_ship_lines sl,
10441          inl_ship_headers sh,
10442          inl_matches_int mi,
10443          rcv_transactions rt
10444     WHERE sh.ship_header_id = sl.ship_header_id
10445     AND sl.ship_line_id = rt.lcm_shipment_line_id
10446     AND mi.to_parent_table_name = 'RCV_TRANSACTIONS'
10447     AND mi.to_parent_table_id = rt.transaction_id
10448     AND mi.group_id = pc_group_id
10449     FOR UPDATE OF sh.ship_header_id NOWAIT;
10450 
10451     TYPE shipToProcess IS TABLE OF c_shipToProcess%ROWTYPE;
10452     l_shipToProcess shipToProcess;
10453     -- /SCM-051
10454 
10455     l_ship_line_id  NUMBER;
10456     l_ship_header_id  NUMBER;
10457     l_parent_match_id  NUMBER;
10458     l_existing_match_info_flag VARCHAR2(1) ;
10459     l_match_id  NUMBER;
10460     l_new_to_parent_table_name VARCHAR2(30) ;
10461     l_new_to_parent_table_id NUMBER;
10462     l_matched_qty NUMBER;
10463     l_matched_amt NUMBER;
10464     l_nrec_tax_amt NUMBER;
10465     l_matched_uom_code VARCHAR2(30) ;
10466     l_matched_curr_code VARCHAR2(30) ;
10467     l_matched_curr_conversion_type  VARCHAR2(30);
10468     l_matched_curr_conversion_date DATE;
10469     l_matched_curr_conversion_rate  NUMBER;
10470     l_initial_sysdate date:= TRUNC(SYSDATE);
10471 
10472     --Bug#10381495
10473     l_previous_access_mode  VARCHAR2(1) :=mo_global.get_access_mode();
10474     l_previous_org_id       NUMBER(15)  :=mo_global.get_current_org_id();
10475     l_current_org_id        NUMBER(15);
10476     l_g_records_inserted_bkp NUMBER;
10477     --Bug#10381495
10478 
10479     -- SCM-051
10480     -- ORA-00054 is the resource busy exception, which is raised when trying
10481     -- to lock a row that is already locked by another session.
10482     RESOURCE_BUSY EXCEPTION;
10483     PRAGMA EXCEPTION_INIT(RESOURCE_BUSY, -00054);
10484     l_resource_busy BOOLEAN := FALSE;
10485     l_lock_error BOOLEAN := FALSE;
10486 
10487 BEGIN
10488     -- Standard Beginning of Procedure/Function Logging
10489     INL_LOGGING_PVT.Log_BeginProc(
10490         p_module_name    => g_module_name,
10491         p_procedure_name => l_program_name
10492     ) ;
10493     -- Initialize API return status to success
10494     x_return_status := L_FND_RET_STS_SUCCESS;
10495     l_debug_info := 'Processing Match Amounts';
10496     INL_LOGGING_PVT.Log_Statement(
10497         p_module_name      => g_module_name,
10498         p_procedure_name   => l_program_name,
10499         p_debug_info       => l_debug_info
10500     ) ;
10501     l_current_org_id      := NVL(l_previous_org_id,-999);--Bug#10381495
10502     INL_LOGGING_PVT.Log_Variable(
10503         p_module_name    => g_module_name,
10504         p_procedure_name => l_program_name,
10505         p_var_name       => 'l_current_org_id',
10506         p_var_value      => l_current_org_id
10507     ) ;
10508 
10509 --Bug#11794442 Begin
10510     OPEN c_distgroupid (l_initial_sysdate);
10511     FETCH c_distgroupid BULK COLLECT INTO distgroupid_List;
10512     CLOSE c_distgroupid;
10513     l_debug_info := 'Fetched '||NVL(distgroupid_List.COUNT, 0)||' groups.';
10514     INL_LOGGING_PVT.Log_Statement(
10515         p_module_name      => g_module_name,
10516         p_procedure_name   => l_program_name,
10517         p_debug_info       => l_debug_info
10518     ) ;
10519 
10520     FOR iGroup IN 1 .. distgroupid_List.COUNT
10521     LOOP
10522         l_debug_info := 'Processing Group_id: '||distgroupid_List(iGroup).group_id;
10523         INL_LOGGING_PVT.Log_Statement(
10524             p_module_name      => g_module_name,
10525             p_procedure_name   => l_program_name,
10526             p_debug_info       => l_debug_info
10527         ) ;
10528         BEGIN
10529             SAVEPOINT Import_MatchbyGroupId;
10530 
10531             -- SCM-051 Get Ship Header Id for p_group_id
10532             l_debug_info := 'Get lock for shipments Group_id: '||distgroupid_List(iGroup).group_id;
10533             INL_LOGGING_PVT.Log_Statement(
10534                 p_module_name      => g_module_name,
10535                 p_procedure_name   => l_program_name,
10536                 p_debug_info       => l_debug_info) ;
10537 
10538             BEGIN
10539                 -- Fetch Ship to Process
10540                 OPEN c_shipToProcess(distgroupid_List(iGroup).group_id);
10541                 FETCH c_shipToProcess BULK COLLECT INTO l_shipToProcess;
10542                 CLOSE c_shipToProcess;
10543             EXCEPTION
10544                 --Handling deadlock with proper error message
10545                 WHEN RESOURCE_BUSY THEN
10546                     l_debug_info := 'Record for group_id ' || distgroupid_List(iGroup).group_id || 'cannot be reserved for update. It has already been reserved by another user.';
10547                     INL_LOGGING_PVT.Log_Statement(
10548                         p_module_name => g_module_name,
10549                         p_procedure_name => l_program_name,
10550                         p_debug_info => l_debug_info);
10551 
10552                     FND_MESSAGE.set_name('INL','INL_ERR_OI_CHK_LCK_SHIPMENT');
10553                     FND_MESSAGE.set_token('GROUP_ID',distgroupid_List(iGroup).group_id);
10554                     FND_MSG_PUB.ADD;
10555 
10556                     l_debug_info := 'Set Interface Status to PENDING for group id: '||distgroupid_List(iGroup).group_id;
10557 
10558                     UPDATE inl_matches_int mi
10559                     SET mi.processing_status_code = 'PENDING',
10560                         mi.request_id = L_FND_CONC_REQUEST_ID,
10561                         mi.last_updated_by = L_FND_USER_ID,
10562                         mi.last_update_date = SYSDATE,
10563                         mi.last_update_login = L_FND_LOGIN_ID,
10564                         mi.program_id = L_FND_CONC_PROGRAM_ID,
10565                         mi.program_update_date = SYSDATE,
10566                         mi.program_application_id = L_FND_PROG_APPL_ID
10567                     WHERE mi.group_id = distgroupid_List(iGroup).group_id;
10568                     l_resource_busy := TRUE;
10569                     l_lock_error := TRUE;
10570             END;
10571             -- /SCM-051
10572 
10573             IF NOT l_resource_busy THEN -- SCM-051
10574                 l_g_records_inserted_bkp:= nvl(g_records_inserted,0);
10575 --Bug#11794442 End
10576 
10577                 l_debug_info := 'Openning Match Amounts Cursor: ';
10578                 INL_LOGGING_PVT.Log_Statement(
10579                     p_module_name      => g_module_name,
10580                     p_procedure_name   => l_program_name,
10581                     p_debug_info       => l_debug_info
10582                 ) ;
10583 
10584                 OPEN matchAmountsToProcess (l_initial_sysdate,distgroupid_List(iGroup).group_id);
10585                 FETCH matchAmountsToProcess BULK COLLECT INTO matchAmountsToProcess_List;
10586                 CLOSE matchAmountsToProcess;
10587                 l_debug_info := 'Fetched '||NVL(matchAmountsToProcess_List.COUNT, 0)||' records.';
10588                 INL_LOGGING_PVT.Log_Statement(
10589                     p_module_name      => g_module_name,
10590                     p_procedure_name   => l_program_name,
10591                     p_debug_info       => l_debug_info
10592                 ) ;
10593 
10594                 FOR iMatch IN 1 .. matchAmountsToProcess_List.COUNT
10595                 LOOP
10596                         l_debug_info := 'Processing Match Amount: '||iMatch;
10597                         INL_LOGGING_PVT.Log_Statement(
10598                             p_module_name      => g_module_name,
10599                             p_procedure_name   => l_program_name,
10600                             p_debug_info       => l_debug_info
10601                         ) ;
10602 
10603                         IF matchAmountsToProcess_List(iMatch).transaction_type <> 'CREATE' THEN
10604                             l_debug_info := 'Transaction_type '||matchAmountsToProcess_List(iMatch).transaction_type||'not supported.';
10605                                     INL_LOGGING_PVT.Log_Statement(
10606                                         p_module_name      => g_module_name,
10607                                         p_procedure_name   => l_program_name,
10608                                         p_debug_info       => l_debug_info
10609                                     ) ;
10610 
10611                             RAISE L_FND_EXC_UNEXPECTED_ERROR;
10612                         ELSE
10613                             SELECT inl_match_Amounts_s.NEXTVAL
10614                               INTO matchAmountsToProcess_List(iMatch).new_match_Amount_id
10615                               FROM dual; -- BUG#8411723 => MURALI
10616 
10617                             INL_LOGGING_PVT.Log_Variable(
10618                                 p_module_name    => g_module_name,
10619                                 p_procedure_name => l_program_name,
10620                                 p_var_name       => 'matchAmountsToProcess_List(iMatch).new_match_Amount_id',
10621                                 p_var_value      => matchAmountsToProcess_List(iMatch).new_match_Amount_id
10622                             ) ;
10623 
10624                             INSERT INTO inl_match_Amounts(
10625                                 match_amount_id             ,
10626                                 adj_group_date              ,-- OPM Integration
10627                                 matched_amt                 ,
10628                                 matched_curr_code           ,
10629                                 matched_curr_conversion_type,
10630                                 matched_curr_conversion_date,
10631                                 matched_curr_conversion_rate,
10632                                 group_id                    , --BUG#8264388
10633                                 charge_line_type_id         , --BUG#8264388
10634                                 tax_code                    , --BUG#8264388
10635                                 nrec_tax_amt                , --BUG#8264388
10636                                 program_id                  ,
10637                                 program_update_date         ,
10638                                 program_application_id      ,
10639                                 request_id                  ,
10640                                 created_by                  ,
10641                                 creation_date               ,
10642                                 last_updated_by             ,
10643                                 last_update_date            ,
10644                                 last_update_login
10645                             )   VALUES
10646                            (
10647                                 matchAmountsToProcess_List(iMatch).new_match_Amount_id          ,
10648                                 DECODE(matchAmountsToProcess_List(iMatch).count_adj_group_date,1
10649                                         ,matchAmountsToProcess_List(iMatch).adj_group_date
10650                                         ,NULL)                                                  , -- OPM Integration
10651                                 matchAmountsToProcess_List(iMatch).matched_amt                  ,
10652                                 matchAmountsToProcess_List(iMatch).matched_curr_code            ,
10653                                 matchAmountsToProcess_List(iMatch).matched_curr_conversion_type ,
10654                                 matchAmountsToProcess_List(iMatch).matched_curr_conversion_date ,
10655                                 matchAmountsToProcess_List(iMatch).matched_curr_conversion_rate ,
10656                                 matchAmountsToProcess_List(iMatch).group_id                     , --BUG#8264388
10657                                 matchAmountsToProcess_List(iMatch).charge_line_type_id          , --BUG#8264388
10658                                 matchAmountsToProcess_List(iMatch).tax_code                     , --BUG#8264388
10659                                 matchAmountsToProcess_List(iMatch).nrec_tax_amt                 , --BUG#8264388
10660                                 L_FND_CONC_PROGRAM_ID                                      ,
10661                                 SYSDATE                                                         ,
10662                                 L_FND_PROG_APPL_ID                                         ,
10663                                 L_FND_CONC_REQUEST_ID                                      ,
10664                                 L_FND_USER_ID                                              ,
10665                                 SYSDATE                                                         ,
10666                                 L_FND_USER_ID                                              ,
10667                                 SYSDATE                                                         ,
10668                                 L_FND_LOGIN_ID
10669                             );
10670                         END IF;
10671                 END LOOP;
10672 
10673                 l_debug_info := 'Processing Matches';
10674                 INL_LOGGING_PVT.Log_Statement(
10675                     p_module_name      => g_module_name,
10676                     p_procedure_name   => l_program_name,
10677                     p_debug_info       => l_debug_info
10678                 ) ;
10679 
10680                 OPEN matchesToProcess (l_initial_sysdate, distgroupid_List(iGroup).group_id);
10681                 FETCH matchesToProcess BULK COLLECT INTO matchesToProcess_List;
10682                 CLOSE matchesToProcess;
10683 
10684                 IF NVL(matchesToProcess_List.COUNT, 0) > 0 THEN
10685                     FOR iMatch IN 1 .. matchesToProcess_List.COUNT
10686                     LOOP
10687 
10688                         IF matchesToProcess_List(iMatch).from_parent_table_name = 'AP_INVOICE_DISTRIBUTIONS'
10689                         THEN
10690                             l_matched_qty                  := matchesToProcess_List(iMatch).matched_qty                    ;
10691                             l_matched_uom_code             := matchesToProcess_List(iMatch).matched_uom_code               ;
10692                             l_new_to_parent_table_name     := matchesToProcess_List(iMatch).to_parent_table_name           ;
10693                             l_new_to_parent_table_id       := matchesToProcess_List(iMatch).to_parent_table_id             ;
10694                             l_matched_curr_code            := matchesToProcess_List(iMatch).matched_curr_code              ;
10695                             l_matched_curr_conversion_type := matchesToProcess_List(iMatch).matched_curr_conversion_type   ;
10696                             l_matched_curr_conversion_date := matchesToProcess_List(iMatch).matched_curr_conversion_date   ;
10697                             l_matched_curr_conversion_rate := matchesToProcess_List(iMatch).matched_curr_conversion_rate   ;
10698                             l_matched_amt                  := matchesToProcess_List(iMatch).matched_amt                    ;
10699                             l_nrec_tax_amt                 := matchesToProcess_List(iMatch).nrec_tax_amt                   ;
10700                             Derive_FromAP(
10701                                 p_from_parent_table_name        => matchesToProcess_List(iMatch).from_parent_table_name,
10702                                 p_from_parent_table_id          => matchesToProcess_List(iMatch).from_parent_table_id,
10703                                 p_match_type_code               => matchesToProcess_List(iMatch).match_type_code,
10704                                 x_matched_amt                   => l_matched_amt,
10705                                 x_matched_qty                   => l_matched_qty,
10706                                 x_nrec_tax_amt                  => l_nrec_tax_amt,
10707                                 x_matched_uom_code              => l_matched_uom_code,
10708                                 x_new_to_parent_table_name      => l_new_to_parent_table_name,
10709                                 x_new_to_parent_table_id        => l_new_to_parent_table_id,
10710                                 x_matched_curr_code             => l_matched_curr_code,
10711                                 x_matched_curr_conversion_type  => l_matched_curr_conversion_type,
10712                                 x_matched_curr_conversion_date  => l_matched_curr_conversion_date,
10713                                 x_matched_curr_conversion_rate  => l_matched_curr_conversion_rate,
10714                                 x_ship_header_id                => matchesToProcess_List(iMatch).ship_header_id,
10715                                 x_org_id                        => matchesToProcess_List(iMatch).org_id, --Bug#10381495
10716                                 x_existing_match_info_flag      => l_existing_match_info_flag,
10717                                 x_parent_match_id               => l_parent_match_id,
10718                                 x_return_status                 => l_return_status
10719                             );
10720 
10721                              -- If any errors happen abort API.
10722                             IF l_return_status = L_FND_RET_STS_ERROR THEN
10723                                 RAISE L_FND_EXC_ERROR;
10724                             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
10725                                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
10726                             END IF;
10727                         ELSE
10728                             l_new_to_parent_table_name := matchesToProcess_List(iMatch).to_parent_table_name;
10729                             l_new_to_parent_table_id := matchesToProcess_List(iMatch).to_parent_table_id;
10730                             Set_existingMatchInfoFlag(
10731                                 p_from_parent_table_name    => matchesToProcess_List(iMatch).from_parent_table_name,
10732                                 p_from_parent_table_id      => matchesToProcess_List(iMatch).from_parent_table_id,
10733                                 p_to_parent_table_name      => l_new_to_parent_table_name,
10734                                 p_to_parent_table_id        => l_new_to_parent_table_id,
10735                                 x_existing_match_info_flag  => l_existing_match_info_flag,
10736                                 x_parent_match_id           => l_parent_match_id,
10737                                 x_return_status             => l_return_status
10738                             );
10739                              -- If any errors happen abort API.
10740                             IF l_return_status = L_FND_RET_STS_ERROR THEN
10741                                 RAISE L_FND_EXC_ERROR;
10742                             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
10743                                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
10744                             END IF;
10745                         END IF;
10746                         l_debug_info := 'Processing Match: '||iMatch||'('||matchesToProcess_List(iMatch) .transaction_type||')';
10747                         INL_LOGGING_PVT.Log_Statement(
10748                             p_module_name      => g_module_name,
10749                             p_procedure_name   => l_program_name,
10750                             p_debug_info       => l_debug_info
10751                         ) ;
10752 
10753                         INL_LOGGING_PVT.Log_Variable(
10754                             p_module_name    => g_module_name,
10755                             p_procedure_name => l_program_name,
10756                             p_var_name       => 'matchesToProcess_List(iMatch).match_int_id',
10757                             p_var_value      => matchesToProcess_List(iMatch).match_int_id
10758                         ) ;
10759                         IF matchesToProcess_List(iMatch) .transaction_type <> 'CREATE' THEN
10760                             l_debug_info := 'Transaction_type '||matchesToProcess_List(iMatch) .transaction_type||'not supported.';
10761                             INL_LOGGING_PVT.Log_Statement(
10762                                 p_module_name      => g_module_name,
10763                                 p_procedure_name   => l_program_name,
10764                                 p_debug_info       => l_debug_info
10765                             ) ;
10766                             RAISE L_FND_EXC_UNEXPECTED_ERROR;
10767                         ELSE
10768                             SELECT inl_matches_s.NEXTVAL
10769                               INTO matchesToProcess_List(iMatch).new_match_id
10770                               FROM dual;  -- BUG#8411723 => MURALI
10771 
10772                             INSERT INTO inl_matches(
10773                                 match_id                     ,  /* 01 */
10774                                 adj_group_date               ,  /* 01A*/  --OPM Integration
10775                                 match_type_code              ,  /* 02 */
10776                                 ship_header_id               ,  /* 03 */
10777                                 from_parent_table_name       ,  /* 04 */
10778                                 from_parent_table_id         ,  /* 05 */
10779                                 to_parent_table_name         ,  /* 06 */
10780                                 to_parent_table_id           ,  /* 07 */
10781                                 parent_match_id              ,  /* 08 */
10782                                 matched_qty                  ,  /* 09 */
10783                                 matched_uom_code             ,  /* 10 */
10784                                 matched_amt                  ,  /* 11 */
10785                                 matched_curr_code            ,  /* 12 */
10786                                 matched_curr_conversion_type ,  /* 13 */
10787                                 matched_curr_conversion_date ,  /* 14 */
10788                                 matched_curr_conversion_rate ,  /* 15 */
10789                                 adj_already_generated_flag   ,  /* 16 */
10790                                 replace_estim_qty_flag       ,  /* 17 */
10791                                 existing_match_info_flag     ,  /* 18 */
10792                                 charge_line_type_id          ,  /* 19 */
10793                                 party_id                     ,  /* 20 */
10794                                 party_site_id                ,  /* 21 */
10795                                 tax_code                     ,  /* 22 */
10796                                 nrec_tax_amt                 ,  /* 23 */
10797                                 tax_amt_included_flag        ,  /* 24 */
10798                                 match_amount_id              ,  /* 25 */
10799                                 match_int_id                 ,  /* 26 */
10800                                 program_id                   ,  /* 27 */
10801                                 program_update_date          ,  /* 28 */
10802                                 program_application_id       ,  /* 29 */
10803                                 request_id                   ,  /* 30 */
10804                                 created_by                   ,  /* 31 */
10805                                 creation_date                ,  /* 32 */
10806                                 last_updated_by              ,  /* 33 */
10807                                 last_update_date             ,  /* 34 */
10808                                 last_update_login               /* 35 */
10809                             )
10810                             VALUES(
10811                                 matchesToProcess_List(iMatch).new_match_id           ,             /* 01 */
10812                                 matchesToProcess_List(iMatch).adj_group_date         ,             /* 01A */   --OPM Integration
10813                                 matchesToProcess_List(iMatch).match_type_code        ,             /* 02 */
10814                                 matchesToProcess_List(iMatch).ship_header_id         ,             /* 03 */
10815                                 matchesToProcess_List(iMatch).from_parent_table_name ,             /* 04 */
10816                                 matchesToProcess_List(iMatch).from_parent_table_id   ,             /* 05 */
10817                                 l_new_to_parent_table_name                           ,             /* 06 */
10818                                 l_new_to_parent_table_id                             ,             /* 07 */
10819                                 l_parent_match_id                                    ,             /* 08 */
10820                                 l_matched_qty                                        ,             /* 09 */
10821                                 l_matched_uom_code                                   ,             /* 10 */
10822                                 l_matched_amt                                        ,             /* 11 */
10823                                 l_matched_curr_code                                  ,             /* 12 */
10824                                 l_matched_curr_conversion_type                       ,             /* 13 */
10825                                 l_matched_curr_conversion_date                       ,             /* 14 */
10826                                 l_matched_curr_conversion_rate                       ,             /* 15 */
10827                                 'N'   ,                                                            /* 16 */
10828                                 matchesToProcess_List(iMatch).replace_estim_qty_flag ,             /* 17 */
10829                                 l_existing_match_info_flag                           ,             /* 18 */
10830                                 matchesToProcess_List(iMatch).charge_line_type_id    ,             /* 19 */
10831                                 matchesToProcess_List(iMatch).party_id               ,             /* 20 */
10832                                 matchesToProcess_List(iMatch).party_site_id          ,             /* 21 */
10833                                 matchesToProcess_List(iMatch).tax_code               ,             /* 22 */
10834                                 l_nrec_tax_amt                                       ,             /* 23 */
10835                                 matchesToProcess_List(iMatch).tax_amt_included_flag  ,             /* 24 */
10836                                 DECODE(matchesToProcess_List(iMatch).match_amounts_flag,
10837                                         'Y',
10838                                        (SELECT ima.match_amount_id
10839                                          FROM inl_match_amounts ima
10840                                          WHERE ima.group_id = matchesToProcess_List(iMatch).group_id
10841                                            AND nvl(ima.charge_line_type_id,-9) = nvl(matchesToProcess_List(iMatch).charge_line_type_id,-9)
10842                                            AND nvl(ima.tax_code,'XxX') = nvl(matchesToProcess_List(iMatch).tax_code,'XxX')
10843                                            AND ima.matched_curr_code = matchesToProcess_List(iMatch).matched_curr_code
10844                                          )
10845                                          , NULL
10846                                         ),                                                         /* 25 */
10847                                 matchesToProcess_List(iMatch).match_int_id           ,             /* 26 */
10848                                 L_FND_CONC_PROGRAM_ID                                ,             /* 27 */
10849                                 SYSDATE                                              ,             /* 28 */
10850                                 L_FND_PROG_APPL_ID                                   ,             /* 29 */
10851                                 L_FND_CONC_REQUEST_ID                                ,             /* 30 */
10852                                 L_FND_USER_ID                                        ,             /* 31 */
10853                                 SYSDATE                                              ,             /* 32 */
10854                                 L_FND_USER_ID                                        ,             /* 33 */
10855                                 SYSDATE                                              ,             /* 34 */
10856                                 L_FND_LOGIN_ID                                                     /* 35 */
10857                             );
10858 
10859                             l_debug_info := 'Call Set LCM Shipment pending_matching_flag to Y rotine';
10860                             INL_LOGGING_PVT.Log_Statement(
10861                                 p_module_name => g_module_name,
10862                                 p_procedure_name => l_program_name,
10863                                 p_debug_info => l_debug_info
10864                             );
10865                             -- Set Shipment Header's pending_matching_flag to 'Y'
10866                             inl_shipment_pvt.Update_PendingMatchingFlag(  --BUG#8198498
10867                                 p_ship_header_id        => matchesToProcess_List(iMatch).ship_header_id,
10868                                 p_pending_matching_flag => 'Y',
10869                                 x_return_status         => l_return_status
10870                             );
10871                             -- If any errors happen abort API.
10872                             IF l_return_status = L_FND_RET_STS_ERROR THEN
10873                                 RAISE L_FND_EXC_ERROR;
10874                             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
10875                                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
10876                             END IF;
10877 
10878                         END IF;
10879                         l_debug_info  := 'Set Shipment Line Interface status and imported Ids';
10880                         INL_LOGGING_PVT.Log_Statement(
10881                             p_module_name      => g_module_name,
10882                             p_procedure_name   => l_program_name,
10883                             p_debug_info       => l_debug_info
10884                         ) ;
10885                         -- Set processing status to COMPLETED for
10886                         -- the current and imported Match Line
10887                         UPDATE inl_matches_int m
10888                         SET m.processing_status_code = 'COMPLETED'               ,
10889                             m.request_id             = L_FND_CONC_REQUEST_ID,
10890                             m.last_updated_by        = L_FND_USER_ID        ,
10891                             m.last_update_date       = SYSDATE                   ,
10892                             m.last_update_login      = L_FND_LOGIN_ID       ,
10893                             m.program_id             = L_FND_CONC_PROGRAM_ID,
10894                             m.program_update_date    = SYSDATE                   ,
10895                             m.program_application_id = L_FND_PROG_APPL_ID
10896                           WHERE m.match_int_id       = matchesToProcess_List(iMatch).match_int_id;
10897 
10898                         -- Set the number of INL Macth records created successfully.
10899                         -- This value will be latter stamped in the concurrent log
10900                         g_records_inserted := g_records_inserted + 1;
10901                     END LOOP;
10902 
10903                     --BUG#8198498
10904                     -- In order to generate tax and charge lines correctly
10905                     -- all matches should be created before call inl_shipment_pvt.Adjust_Lines
10906                     FOR iMatch IN 1 .. matchesToProcess_List.COUNT
10907                     LOOP
10908                         IF matchesToProcess_List(iMatch).transaction_type = 'CREATE' THEN
10909                             -- Generate Adjust Lines
10910                             -- BUG#8198498 we have to change the order and the adjustment lines
10911                             -- have been generated before the submit action
10912                             l_debug_info := 'Generate Adjustment Lines';
10913                             INL_LOGGING_PVT.Log_Statement(
10914                                 p_module_name => g_module_name,
10915                                 p_procedure_name => l_program_name,
10916                                 p_debug_info => l_debug_info
10917                             );
10918 
10919                             INL_LOGGING_PVT.Log_Statement(
10920                                 p_module_name => g_module_name,
10921                                 p_procedure_name => l_program_name,
10922                                 p_debug_info => 'Comparing l_current_org_id: '||l_current_org_id||' with matchesToProcess_List(iMatch).org_id:'||matchesToProcess_List(iMatch).org_id
10923                             );
10924                             --Bug#10381495
10925                             IF (l_current_org_id <> matchesToProcess_List(iMatch).org_id) THEN
10926                                 INL_LOGGING_PVT.Log_Statement(
10927                                     p_module_name => g_module_name,
10928                                     p_procedure_name => l_program_name,
10929                                     p_debug_info => 'Seting a new context from '||l_current_org_id||' to '||matchesToProcess_List(iMatch).org_id
10930                                 );
10931                                 mo_global.set_policy_context( 'S', matchesToProcess_List(iMatch).org_id);
10932                                 l_current_org_id := matchesToProcess_List(iMatch).org_id;
10933                                 INL_LOGGING_PVT.Log_Statement(
10934                                     p_module_name => g_module_name,
10935                                     p_procedure_name => l_program_name,
10936                                     p_debug_info => 'l_current_org_id: '||l_current_org_id
10937                                 );
10938                             END IF;
10939                             --Bug#10381495
10940 
10941                             --BUG#8198498
10942                             call_ShpmtPvtAdjLin(
10943                                 p_match_type_code       => matchesToProcess_List(iMatch).match_type_code,
10944                                 p_to_parent_table_name  => l_new_to_parent_table_name,
10945                                 p_to_parent_table_id    => l_new_to_parent_table_id,
10946                                 p_ship_header_id        => matchesToProcess_List(iMatch).ship_header_id,
10947                                 x_return_status         => l_return_status
10948                             );
10949                              -- If any errors happen abort API.
10950                             IF l_return_status = L_FND_RET_STS_ERROR THEN
10951                                 RAISE L_FND_EXC_ERROR;
10952                             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
10953                                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
10954                             END IF;
10955                         END IF;
10956                     END LOOP;
10957                     --Bug#10381495
10958                     IF (l_current_org_id <> NVL(l_previous_org_id,l_current_org_id)) THEN --Bug#11931295
10959                         INL_LOGGING_PVT.Log_Statement(
10960                             p_module_name => g_module_name,
10961                             p_procedure_name => l_program_name,
10962                             p_debug_info => 'Restore previous context: from '||l_current_org_id||' to '||l_previous_org_id
10963                         );
10964                         mo_global.set_policy_context( l_previous_access_mode, l_previous_org_id);
10965                     END IF;
10966                     --Bug#10381495
10967                 END IF;
10968             END IF; -- SCM-051
10969 --Bug#11794442 Begin
10970         EXCEPTION
10971             WHEN OTHERS THEN
10972                 ROLLBACK TO Import_MatchbyGroupId;
10973                 g_records_inserted := l_g_records_inserted_bkp;
10974                 l_debug_info := 'Set Interface Status to ERROR for group id(1): '||distgroupid_List(iGroup).group_id||sqlerrm; --Bug#14044298
10975                 INL_LOGGING_PVT.Log_Statement(
10976                     p_module_name      => g_module_name,
10977                     p_procedure_name   => l_program_name,
10978                     p_debug_info       => l_debug_info
10979                 );
10980                 UPDATE inl_matches_int mi
10981                 SET mi.processing_status_code = 'ERROR'         ,
10982                     mi.request_id             = L_FND_CONC_REQUEST_ID       ,
10983                     mi.last_updated_by        = L_FND_USER_ID               ,
10984                     mi.last_update_date       = SYSDATE                          ,
10985                     mi.last_update_login      = L_FND_LOGIN_ID              ,
10986                     mi.program_id             = L_FND_CONC_PROGRAM_ID       ,
10987                     mi.program_update_date    = SYSDATE                          ,
10988                     mi.program_application_id = L_FND_PROG_APPL_ID
10989                 WHERE  mi.request_id = l_fnd_conc_request_id_int  --Bug#11794442
10990                 AND   ((distgroupid_List(iGroup).group_id IS NULL AND mi.group_id IS NULL)
10991                         OR mi.group_id = distgroupid_List(iGroup).group_id);
10992         END;
10993 
10994 --Bug#11794442 End
10995     END LOOP;
10996     --Bug#14707257/16198838 Begin
10997     IF (l_current_org_id <> NVL(l_previous_org_id,l_current_org_id)) THEN --Bug#11931295
10998         INL_LOGGING_PVT.Log_Statement(
10999             p_module_name => g_module_name,
11000             p_procedure_name => l_program_name,
11001             p_debug_info => 'Restore previous context: from '||l_current_org_id||' to '||l_previous_org_id
11002         );
11003         mo_global.set_policy_context( l_previous_access_mode, l_previous_org_id);
11004         l_current_org_id := l_previous_org_id;
11005     END IF;
11006     --Bug#14707257/16198838 End
11007 
11008     /*
11009     IF l_lock_error THEN
11010         RAISE L_FND_EXC_ERROR;
11011     END IF;
11012     */
11013     -- Standard End of Procedure/Function Logging
11014     INL_LOGGING_PVT.Log_EndProc(
11015         p_module_name    => g_module_name,
11016         p_procedure_name => l_program_name
11017     );
11018 EXCEPTION
11019     WHEN L_FND_EXC_ERROR THEN
11020         -- Standard Expected Error Logging
11021         INL_LOGGING_PVT.Log_ExpecError (
11022             p_module_name    => g_module_name,
11023             p_procedure_name => l_program_name
11024         );
11025         x_return_status := L_FND_RET_STS_ERROR;
11026         --Bug#10381495
11027         IF (l_current_org_id <> NVL(l_previous_org_id,-999)) THEN
11028             INL_LOGGING_PVT.Log_Statement(
11029                 p_module_name => g_module_name,
11030                 p_procedure_name => l_program_name,
11031                 p_debug_info => 'Restore previous context: from '||l_current_org_id||' to '||l_previous_org_id
11032             );
11033             mo_global.set_policy_context( l_previous_access_mode, l_previous_org_id);
11034         END IF;
11035         --Bug#10381495
11036     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
11037         -- Standard Unexpected Error Logging
11038         INL_LOGGING_PVT.Log_UnexpecError (
11039             p_module_name    => g_module_name,
11040             p_procedure_name => l_program_name
11041         );
11042         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
11043         --Bug#10381495
11044         IF (l_current_org_id <> NVL(l_previous_org_id,-999)) THEN
11045             INL_LOGGING_PVT.Log_Statement(
11046                 p_module_name => g_module_name,
11047                 p_procedure_name => l_program_name,
11048                 p_debug_info => 'Restore previous context: from '||l_current_org_id||' to '||l_previous_org_id
11049             );
11050             mo_global.set_policy_context( l_previous_access_mode, l_previous_org_id);
11051         END IF;
11052         --Bug#10381495
11053     WHEN OTHERS THEN
11054         -- Standard Unexpected Error Logging
11055         INL_LOGGING_PVT.Log_UnexpecError (
11056             p_module_name    => g_module_name,
11057             p_procedure_name => l_program_name
11058         );
11059         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
11060         IF FND_MSG_PUB.Check_Msg_Level(
11061             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
11062         ) THEN
11063             FND_MSG_PUB.Add_Exc_Msg(
11064                 p_pkg_name       => g_pkg_name,
11065                 p_procedure_name => l_program_name
11066             );
11067         END IF;
11068         --Bug#10381495
11069         IF (l_current_org_id <> NVL(l_previous_org_id,-999)) THEN
11070             INL_LOGGING_PVT.Log_Statement(
11071                 p_module_name => g_module_name,
11072                 p_procedure_name => l_program_name,
11073                 p_debug_info => 'Restore previous context: from '||l_current_org_id||' to '||l_previous_org_id
11074             );
11075             mo_global.set_policy_context( l_previous_access_mode, l_previous_org_id);
11076         END IF;
11077         --Bug#10381495
11078 END Import_Matches;
11079 
11080 -- Utility name : Derive_MatchCols
11081 -- Type         : Private
11082 -- Function     : Get and Set Match Line values
11083 --                before the first set of validations.
11084 --
11085 -- Pre-reqs     : None
11086 -- Parameters   :
11087 -- IN           : p_party_number      VARCHAR2
11088 --                p_party_site_number VARCHAR2
11089 --
11090 --
11091 -- IN OUT       : p_party_id          NUMBER
11092 --                p_party_site_id     NUMBER
11093 --
11094 -- OUT          : x_return_status     VARCHAR2
11095 --
11096 -- Version      : Current version 1.0
11097 --
11098 -- Notes        :
11099 PROCEDURE Derive_MatchCols(
11100     p_party_number          IN VARCHAR2,
11101     p_party_site_number     IN VARCHAR2,
11102     p_match_type_code       IN VARCHAR2,
11103     p_to_parent_table_name  IN VARCHAR2,
11104     p_to_parent_table_id    IN NUMBER,
11105     p_party_id              IN OUT NOCOPY NUMBER,
11106     p_party_site_id         IN OUT NOCOPY NUMBER,
11107     p_parent_match_id       IN OUT NOCOPY NUMBER,
11108     x_return_status            OUT NOCOPY VARCHAR2
11109 ) IS
11110     l_program_name     CONSTANT VARCHAR2(100) := 'Derive_MatchCols';
11111     l_debug_info    VARCHAR2(200) ;
11112     l_return_status VARCHAR2(1) ;
11113 BEGIN
11114 
11115     -- Standard Beginning of Procedure/Function Logging
11116     INL_LOGGING_PVT.Log_BeginProc(
11117         p_module_name    => g_module_name,
11118         p_procedure_name => l_program_name
11119     ) ;
11120     --  Initialize API return status to success
11121     x_return_status                             := L_FND_RET_STS_SUCCESS;
11122     l_debug_info := 'Derive values for Match Lines';
11123     INL_LOGGING_PVT.Log_Statement(
11124         p_module_name      => g_module_name,
11125         p_procedure_name   => l_program_name,
11126         p_debug_info       => l_debug_info
11127     ) ;
11128     IF p_party_number IS NOT NULL AND p_party_id IS NULL THEN
11129         p_party_id  := Derive_PartyID(
11130                             p_party_number => p_party_number,
11131                             x_return_status => l_return_status
11132                        )
11133         ;
11134         -- If any errors happen abort the process.
11135         IF l_return_status = L_FND_RET_STS_ERROR THEN
11136             RAISE L_FND_EXC_ERROR;
11137         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
11138             RAISE L_FND_EXC_UNEXPECTED_ERROR;
11139         END IF;
11140     END IF;
11141     IF p_party_site_number IS NOT NULL AND p_party_site_id IS NULL THEN
11142         p_party_site_id :=
11143             Derive_PartySiteID(p_party_site_number => p_party_site_number,
11144                                x_return_status     => l_return_status
11145                                )
11146         ;
11147         -- If any errors happen abort the process.
11148         IF l_return_status = L_FND_RET_STS_ERROR THEN
11149             RAISE L_FND_EXC_ERROR;
11150         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
11151             RAISE L_FND_EXC_UNEXPECTED_ERROR;
11152         END IF;
11153     END IF;
11154 
11155     IF p_parent_match_id IS NULL
11156         AND p_match_type_code = 'CORRECTION'
11157     THEN
11158         SELECT MIN(match_id)
11159         INTO p_parent_match_id
11160         FROM inl_matches
11161         WHERE from_parent_table_id = p_to_parent_table_id
11162         AND from_parent_table_name = p_to_parent_table_name
11163         ;
11164     END IF;
11165 
11166     -- Standard End of Procedure/Function Logging
11167     INL_LOGGING_PVT.Log_EndProc(
11168         p_module_name    => g_module_name,
11169         p_procedure_name => l_program_name
11170     );
11171 EXCEPTION
11172     WHEN L_FND_EXC_ERROR THEN
11173         -- Standard Expected Error Logging
11174         INL_LOGGING_PVT.Log_ExpecError (
11175             p_module_name    => g_module_name,
11176             p_procedure_name => l_program_name
11177         );
11178         x_return_status := L_FND_RET_STS_ERROR;
11179     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
11180         -- Standard Unexpected Error Logging
11181         INL_LOGGING_PVT.Log_UnexpecError (
11182             p_module_name    => g_module_name,
11183             p_procedure_name => l_program_name
11184         );
11185         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
11186     WHEN OTHERS THEN
11187         -- Standard Unexpected Error Logging
11188         INL_LOGGING_PVT.Log_UnexpecError (
11189             p_module_name    => g_module_name,
11190             p_procedure_name => l_program_name
11191         );
11192         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
11193         IF FND_MSG_PUB.Check_Msg_Level(
11194             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
11195         ) THEN
11196             FND_MSG_PUB.Add_Exc_Msg(
11197                 p_pkg_name       => g_pkg_name,
11198                 p_procedure_name => l_program_name
11199             );
11200         END IF;
11201 END Derive_MatchCols;
11202 -- Funct name : Validate_MatchChLnTpID
11203 -- Type       : Private
11204 -- Function   : Validate a given Charge Line Type that was used
11205 --              by the Matching Process
11206 --
11207 -- Pre-reqs   : None
11208 -- Parameters :
11209 -- IN         : p_match_int_id               IN NUMBER
11210 --              p_match_type_code            IN VARCHAR2
11211 --              p_parent_match_type_code     IN VARCHAR2
11212 --              p_charge_line_type_id        IN NUMBER
11213 --              p_match_amount_int_id        IN NUMBER
11214 --
11215 -- OUT        : x_return_status              OUT NOCOPY VARCHAR2
11216 --
11217 -- Version    : Current version 1.0
11218 --
11219 -- Notes      :
11220 FUNCTION Validate_MatchChLnTpID(
11221     p_match_int_id           IN NUMBER,
11222     p_match_type_code        IN VARCHAR2,
11223     p_parent_match_type_code IN VARCHAR2,
11224     p_charge_line_type_id    IN NUMBER,
11225     p_match_amounts_flag     IN VARCHAR2,
11226     x_return_status          OUT NOCOPY VARCHAR2
11227 ) RETURN BOOLEAN IS
11228     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_MatchChLnTpID';
11229     l_debug_info    VARCHAR2(400) ;
11230     l_return_status VARCHAR2(1) ;
11231     l_result        VARCHAR2(1) := L_FND_TRUE;
11232     l_allocation_basis VARCHAR2(30);
11233     l_allocation_basis_uom_class VARCHAR2(30);
11234 BEGIN
11235     -- Standard Beginning of Procedure/Function Logging
11236     INL_LOGGING_PVT.Log_BeginProc(
11237         p_module_name    => g_module_name,
11238         p_procedure_name => l_program_name
11239     ) ;
11240     --  Initialize API return status to success
11241     x_return_status := L_FND_RET_STS_SUCCESS;
11242     l_debug_info := 'Check if CHARGE_LINE_TYPE_ID is valid';
11243     INL_LOGGING_PVT.Log_Statement(
11244         p_module_name      => g_module_name,
11245         p_procedure_name   => l_program_name,
11246         p_debug_info       => l_debug_info
11247     ) ;
11248     IF NVL(p_parent_match_type_code, p_match_type_code) = 'CHARGE' THEN
11249         IF p_charge_line_type_id IS NULL THEN
11250             l_result := L_FND_FALSE;
11251             -- Add a line into inl_ship_errors
11252             Handle_InterfError(
11253                 p_parent_table_name  => 'INL_MATCHES_INT',
11254                 p_parent_table_id    => p_match_int_id,
11255                 p_column_name        => 'CHARGE_LINE_TYPE_ID',
11256                 p_column_value       => p_charge_line_type_id,
11257                 p_error_message_name => 'INL_ERR_OI_MAT_CH_LN_TP_ID_N',
11258                 p_token1_name        => 'MATCH_INT_ID',
11259                 p_token1_value       => p_match_int_id,
11260                 x_return_status      => l_return_status
11261             ) ;
11262             -- If unexpected errors happen abort
11263             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
11264                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
11265             END IF;
11266         ELSE
11267             SELECT UPPER(clt.allocation_basis)
11268             INTO l_allocation_basis
11269             FROM inl_charge_line_types_vl clt
11270             WHERE clt.charge_line_type_id = p_charge_line_type_id;
11271             --Bug#8898208
11272             l_debug_info:= '';
11273             IF l_allocation_basis = 'VOLUME' THEN
11274                 FND_PROFILE.GET('INL_VOLUME_UOM_CLASS',l_allocation_basis_uom_class);
11275                 IF l_allocation_basis_uom_class IS NULL THEN
11276                     l_debug_info:= 'INL_ERR_CHK_VOL_UOM_CLASS_PROF';
11277                 END IF;
11278             ELSIF l_allocation_basis = 'QUANTITY' THEN
11279 
11280                 FND_PROFILE.GET('INL_QUANTITY_UOM_CLASS',l_allocation_basis_uom_class);
11281                 IF l_allocation_basis_uom_class IS NULL THEN
11282                     l_debug_info:= 'INL_ERR_CHK_QTY_UOM_CLASS_PROF';
11283                 END IF;
11284             ELSIF l_allocation_basis = 'WEIGHT' THEN
11285 
11286                 FND_PROFILE.GET('INL_WEIGHT_UOM_CLASS',l_allocation_basis_uom_class);
11287                 IF l_allocation_basis_uom_class IS NULL THEN
11288                     l_debug_info:= 'INL_ERR_CHK_WEI_UOM_CLASS_PROF';
11289                 END IF;
11290             END IF;
11291             IF l_debug_info IS NOT NULL THEN
11292                 l_result := L_FND_FALSE;
11293                 -- Add a line into inl_ship_errors
11294                 Handle_InterfError(
11295                     p_parent_table_name  => 'INL_MATCHES_INT',
11296                     p_parent_table_id    => p_match_int_id,
11297                     p_column_name        => 'CHARGE_LINE_TYPE_ID',
11298                     p_column_value       => p_charge_line_type_id,
11299                     p_error_message_name => l_debug_info,
11300                     x_return_status      => l_return_status
11301                 ) ;
11302                 -- If unexpected errors happen abort
11303 
11304                 IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
11305                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
11306                 END IF;
11307             END IF;
11308             --Bug#8898208
11309         END IF;
11310     ELSE
11311         IF p_charge_line_type_id IS NOT NULL
11312         AND p_match_amounts_flag IS NULL
11313         THEN
11314             l_result := L_FND_FALSE;
11315             -- Add a line into inl_ship_errors
11316             Handle_InterfError(
11317                 p_parent_table_name  => 'INL_MATCHES_INT',
11318                 p_parent_table_id    => p_match_int_id,
11319                 p_column_name        => 'CHARGE_LINE_TYPE_ID',
11320                 p_column_value       => p_charge_line_type_id,
11321                 p_error_message_name => 'INL_ERR_OI_MAT_CH_LN_TP_ID_NN',
11322                 p_token1_name        => 'MATCH_INT_ID',
11323                 p_token1_value       => p_match_int_id,
11324                 x_return_status      => l_return_status
11325             ) ;
11326             -- If unexpected errors happen abort
11327 
11328             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
11329                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
11330             END IF;
11331         END IF;
11332     END IF;
11333     -- Standard End of Procedure/Function Logging
11334     INL_LOGGING_PVT.Log_EndProc(
11335         p_module_name    => g_module_name,
11336         p_procedure_name => l_program_name
11337     );
11338     RETURN FND_API.to_boolean(l_result) ;
11339 EXCEPTION
11340     WHEN L_FND_EXC_ERROR THEN
11341         -- Standard Expected Error Logging
11342         INL_LOGGING_PVT.Log_ExpecError (
11343             p_module_name    => g_module_name,
11344             p_procedure_name => l_program_name
11345         );
11346         RETURN FND_API.to_boolean(L_FND_FALSE) ;
11347     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
11348         -- Standard Unexpected Error Logging
11349         INL_LOGGING_PVT.Log_UnexpecError (
11350             p_module_name    => g_module_name,
11351             p_procedure_name => l_program_name
11352         );
11353         RETURN FND_API.to_boolean(L_FND_FALSE) ;
11354     WHEN OTHERS THEN
11355           -- Standard Unexpected Error Logging
11356           INL_LOGGING_PVT.Log_UnexpecError (
11357               p_module_name    => g_module_name,
11358               p_procedure_name => l_program_name
11359           );
11360           IF FND_MSG_PUB.Check_Msg_Level(
11361             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
11362         ) THEN
11363             FND_MSG_PUB.Add_Exc_Msg(
11364                 p_pkg_name       => g_pkg_name,
11365                 p_procedure_name => l_program_name
11366             );
11367         END IF;
11368     RETURN FND_API.to_boolean(L_FND_FALSE) ;
11369 END Validate_MatchChLnTpID;
11370 -- Funct name : Validate_MatchFlags
11371 -- Type       : Private
11372 -- Function   : Validate Matching Flags
11373 --
11374 -- Pre-reqs   : None
11375 -- Parameters :
11376 -- IN         : p_match_int_id               IN NUMBER
11377 --              p_match_type_code            IN VARCHAR2
11378 --              p_parent_match_type_code     IN VARCHAR2
11379 --              p_replace_estim_qty_flag     IN VARCHAR2
11380 --              p_existing_match_info_flag   IN VARCHAR2
11381 --
11382 -- OUT        : x_return_status              OUT NOCOPY VARCHAR2
11383 --
11384 -- Version    : Current version 1.0
11385 --
11386 -- Notes      :
11387 FUNCTION Validate_MatchFlags(
11388     p_match_int_id             IN NUMBER,
11389     p_match_type_code          IN VARCHAR2,
11390     p_parent_match_type_code   IN VARCHAR2,
11391     p_replace_estim_qty_flag   IN VARCHAR2,
11392     p_existing_match_info_flag IN VARCHAR2,
11393     x_return_status            OUT NOCOPY VARCHAR2
11394 ) RETURN BOOLEAN IS
11395     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_MatchFlags';
11396     l_debug_info    VARCHAR2(400) ;
11397     l_return_status VARCHAR2(1) ;
11398     l_result        VARCHAR2(1) := L_FND_TRUE;
11399 BEGIN
11400     -- Standard Beginning of Procedure/Function Logging
11401     INL_LOGGING_PVT.Log_BeginProc(
11402         p_module_name    => g_module_name,
11403         p_procedure_name => l_program_name
11404     ) ;
11405     --  Initialize API return status to success
11406     x_return_status := L_FND_RET_STS_SUCCESS;
11407     l_debug_info    := 'Check if replace_estim_qty_flag = "Y" and it is not about an ITEM match';
11408     INL_LOGGING_PVT.Log_Statement(
11409         p_module_name      => g_module_name,
11410         p_procedure_name   => l_program_name,
11411         p_debug_info       => l_debug_info
11412     ) ;
11413     IF p_replace_estim_qty_flag = 'Y' THEN
11414         IF NVL(p_parent_match_type_code, p_match_type_code) <> 'ITEM' THEN
11415             l_result          := L_FND_FALSE;
11416             -- Add a line into inl_ship_errors
11417             Handle_InterfError(
11418                 p_parent_table_name  => 'INL_MATCHES_INT',
11419                 p_parent_table_id    => p_match_int_id,
11420                 p_column_name        => 'REPLACE_ESTIM_QTY_FLAG',
11421                 p_column_value       => p_replace_estim_qty_flag,
11422                 p_error_message_name => 'INL_ERR_OI_CHK_RPL_EST_QT_FLAG',
11423                 p_token1_name        => 'MATCH_INT_ID',
11424                 p_token1_value       => p_match_int_id,
11425                 x_return_status      => l_return_status) ;
11426             -- If unexpected errors happen abort
11427             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
11428                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
11429             END IF;
11430         END IF;
11431     END IF;
11432     -- Standard End of Procedure/Function Logging
11433     INL_LOGGING_PVT.Log_EndProc(
11434         p_module_name    => g_module_name,
11435         p_procedure_name => l_program_name
11436     );
11437     RETURN FND_API.to_boolean(l_result) ;
11438 EXCEPTION
11439     WHEN L_FND_EXC_ERROR THEN
11440         -- Standard Expected Error Logging
11441         INL_LOGGING_PVT.Log_ExpecError (
11442             p_module_name    => g_module_name,
11443             p_procedure_name => l_program_name
11444         );
11445         RETURN FND_API.to_boolean(L_FND_FALSE) ;
11446     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
11447         -- Standard Unexpected Error Logging
11448         INL_LOGGING_PVT.Log_UnexpecError (
11449             p_module_name    => g_module_name,
11450             p_procedure_name => l_program_name
11451         );
11452         RETURN FND_API.to_boolean(L_FND_FALSE) ;
11453     WHEN OTHERS THEN
11454         -- Standard Unexpected Error Logging
11455         INL_LOGGING_PVT.Log_UnexpecError (
11456             p_module_name    => g_module_name,
11457             p_procedure_name => l_program_name
11458         );
11459         IF FND_MSG_PUB.Check_Msg_Level(
11460             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
11461         ) THEN
11462             FND_MSG_PUB.Add_Exc_Msg(
11463                 p_pkg_name       => g_pkg_name,
11464                 p_procedure_name => l_program_name
11465             );
11466         END IF;
11467         RETURN FND_API.to_boolean(L_FND_FALSE) ;
11468 END Validate_MatchFlags;
11469 -- Funct name : Validate_MatchQty
11470 -- Type       : Private
11471 -- Function   : Validate a given Match Quantity
11472 --
11473 -- Pre-reqs   : None
11474 -- Parameters :
11475 -- IN         : p_match_int_id           IN NUMBER
11476 --              p_corrected_match_id     IN NUMBER
11477 --              p_updated_match_id       IN NUMBER
11478 --              p_ship_line_id           IN NUMBER
11479 --              p_matched_qty            IN NUMBER
11480 --              p_matched_uom_code       IN VARCHAR2
11481 --              p_replace_estim_qty_flag IN VARCHAR2
11482 --              p_match_type_code        IN VARCHAR2
11483 --
11484 -- OUT        : x_return_status          IN OUT NOCOPY VARCHAR2
11485 --
11486 -- Version    : Current version 1.0
11487 --
11488 -- Notes      :
11489 FUNCTION Validate_MatchQty(
11490     p_match_int_id           IN NUMBER,
11491     p_corrected_match_id     IN NUMBER,
11492     p_updated_match_id       IN NUMBER,
11493     p_ship_line_id           IN NUMBER,
11494     p_matched_qty            IN NUMBER,
11495     p_matched_uom_code       IN VARCHAR2,
11496     p_replace_estim_qty_flag IN VARCHAR2,
11497     p_match_type_code        IN VARCHAR2,
11498     x_return_status          OUT NOCOPY VARCHAR2
11499 ) RETURN BOOLEAN IS
11500     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_MatchQty';
11501     l_debug_info    VARCHAR2(400) ;
11502     l_return_status VARCHAR2(1) ;
11503     l_result        VARCHAR2(1) := L_FND_TRUE;
11504     CURSOR processed_matches
11505     IS
11506          SELECT m1.match_id,
11507             m1.matched_qty ,
11508             m1.matched_uom_code
11509          FROM inl_corr_matches_v m1
11510          WHERE m1.to_parent_table_name   = 'INL_SHIP_LINES'
11511          AND m1.to_parent_table_id     = p_ship_line_id
11512          AND m1.match_type_code        = 'ITEM'
11513          AND m1.replace_estim_qty_flag = 'N'
11514          -- In case of resubmit the same actual value more than once, the
11515          -- new line is created as existing_match_info_flag = 'Y'.
11516          -- For checking purposes, it will consider only the latest record
11517          AND m1.match_id IN (SELECT MAX(m2.match_id)
11518                              FROM inl_corr_matches_v m2
11519                              WHERE m2.to_parent_table_name   = m1.to_parent_table_name
11520                              AND m2.to_parent_table_id     = m1.to_parent_table_id
11521                              AND m2.from_parent_table_name = m1.from_parent_table_name
11522                              AND m2.from_parent_table_id   = m1.from_parent_table_id
11523                              AND m2.match_type_code        = 'ITEM'
11524                              AND m2.replace_estim_qty_flag = 'N'
11525                             )
11526     ;
11527 
11528     TYPE processed_matches_List_Type IS TABLE OF processed_matches%ROWTYPE;
11529     processed_matches_List processed_matches_List_Type;
11530     CURSOR OI_matches
11531     IS
11532         SELECT m1.transaction_type,
11533             m1.match_type_code    ,
11534             m1.match_int_id       ,
11535             m1.matched_qty        ,
11536             m1.matched_uom_code   ,
11537             m1.replace_estim_qty_flag
11538         FROM inl_matches_int m1
11539         WHERE m1.to_parent_table_name   = 'INL_SHIP_LINES'
11540         AND m1.to_parent_table_id     = p_ship_line_id
11541         AND m1.match_int_id          <> NVL(p_updated_match_id, 0)
11542         AND m1.processing_status_code = 'RUNNING'
11543         ORDER BY m1.match_int_id
11544     ;
11545 
11546     TYPE OI_matches_List_Type IS TABLE OF OI_matches%ROWTYPE;
11547     OI_matches_List OI_matches_List_Type;
11548 --Bug#9660043     l_ship_header_id     NUMBER;
11549 --Bug#9660043     l_ship_line_num      NUMBER;
11550 --Bug#9660043     l_ship_line_group_id NUMBER;
11551     l_qty                NUMBER;
11552     l_actual_qty         NUMBER := 0;
11553     l_aux_qty            NUMBER;
11554     l_match_qty          NUMBER;
11555     l_UOM_code           VARCHAR2(3) ;
11556     l_organization_id    NUMBER;
11557     l_inventory_item_id  NUMBER;
11558     l_matches            VARCHAR2(20000);
11559     l_unproc_actual_qty  NUMBER;
11560     l_unproc_UOM_code    VARCHAR2(3);
11561     l_unproc_match_id    NUMBER;
11562     OI_matches_qty       NUMBER;
11563     OI_matches_UOM_code  VARCHAR2(3);
11564     OI_match_type_code   VARCHAR2(30);
11565 BEGIN
11566     -- Standard Beginning of Procedure/Function Logging
11567     INL_LOGGING_PVT.Log_BeginProc(
11568         p_module_name    => g_module_name,
11569         p_procedure_name => l_program_name
11570     ) ;
11571     --  Initialize API return status to success
11572     x_return_status := L_FND_RET_STS_SUCCESS;
11573     -- Get ship_header_id and the ship_line_num from Shipment Lines table
11574     -- to be used as criteria in the search for estimated values(Adjustment View)
11575     -- Get Organization_Id for UOM conversion purpose
11576     l_debug_info := 'Getting:  Organization_Id, Inventory_item_id and transaction qty and uom ';
11577     INL_LOGGING_PVT.Log_Statement(
11578         p_module_name      => g_module_name,
11579         p_procedure_name   => l_program_name,
11580         p_debug_info       => l_debug_info
11581     ) ;
11582     SELECT
11583         sh.organization_id      ,--Bug#9660043
11584 --Bug#9660043         sl.ship_header_id       ,
11585 --Bug#9660043         sl.ship_line_num        ,
11586         sl.inventory_item_id    ,
11587 --Bug#9660043         sl.ship_line_group_id   ,
11588         sla.txn_qty             , --Bug#9660043
11589         sla.txn_uom_code          --Bug#9660043
11590     INTO
11591         l_organization_id   , --Bug#9660043
11592 --Bug#9660043         l_ship_header_id    ,
11593 --Bug#9660043         l_ship_line_num     ,
11594         l_inventory_item_id ,
11595 --Bug#9660043         l_ship_line_group_id,
11596         l_qty               , --Bug#9660043
11597         l_uom_code            --Bug#9660043
11598     FROM
11599         inl_ship_lines_all sl, --Bug#10381495
11600         inl_ship_headers_all sh, --Bug#9660043 --Bug#10381495
11601         inl_adj_ship_lines_v sla
11602     WHERE sl.ship_line_id       = p_ship_line_id
11603     AND   sh.ship_header_id     = sl.ship_header_id --Bug#9660043
11604     AND   sla.ship_header_id    = sl.ship_header_id --Bug#9660043
11605     AND   sla.ship_line_group_id= sl.ship_line_group_id --Bug#9660043
11606     AND   sla.ship_line_num     = sl.ship_line_num; --Bug#9660043
11607 /* --Bug#9660043
11608     -- Get Organization_Id for UOM conversion purpose
11609     SELECT sh.organization_id
11610     INTO l_organization_id
11611     FROM inl_ship_headers sh
11612     WHERE sh.ship_header_id = l_ship_header_id;
11613     l_debug_info := 'Get from Adjustment View the TXN_QTY and TXN_UOM_CODE';
11614     INL_LOGGING_PVT.Log_Statement(
11615         p_module_name      => g_module_name,
11616         p_procedure_name   => l_program_name,
11617         p_debug_info       => l_debug_info
11618     ) ;
11619     SELECT sla.txn_qty,
11620            sla.txn_uom_code
11621     INTO l_qty,
11622          l_uom_code
11623     FROM inl_adj_ship_lines_v sla
11624     WHERE sla.ship_header_id = l_ship_header_id
11625     AND sla.ship_line_group_id = l_ship_line_group_id
11626     AND sla.ship_line_num      = l_ship_line_num;
11627 */
11628 
11629     INL_LOGGING_PVT.Log_Variable(
11630         p_module_name    => g_module_name,
11631         p_procedure_name => l_program_name,
11632         p_var_name       => 'l_qty',
11633         p_var_value      => l_qty
11634     ) ;
11635     INL_LOGGING_PVT.Log_Variable(
11636         p_module_name    => g_module_name,
11637         p_procedure_name => l_program_name,
11638         p_var_name       => 'l_UOM_code',
11639         p_var_value      => l_UOM_code
11640     ) ;
11641     -- Check if there is any match line as
11642     -- replace_estim_qty_flag = 'Y' and adj_already_generated_flag = 'N'
11643     -- In this case it will affect the estimated quantity when processed
11644     l_debug_info := 'Get values from unprocessed matches';
11645     INL_LOGGING_PVT.Log_Statement(
11646         p_module_name      => g_module_name,
11647         p_procedure_name   => l_program_name,
11648         p_debug_info       => l_debug_info
11649     ) ;
11650     BEGIN
11651         SELECT m1.matched_qty,
11652                m1.matched_uom_code,
11653                m1.match_id
11654         INTO l_unproc_actual_qty,
11655              l_unproc_uom_code,
11656              l_unproc_match_id
11657         FROM inl_corr_matches_v m1
11658         WHERE m1.to_parent_table_name = 'INL_SHIP_LINES'
11659         AND m1.to_parent_table_id = p_ship_line_id
11660         AND m1.match_type_code = 'ITEM'
11661         AND m1.replace_estim_qty_flag = 'Y'
11662         AND m1.adj_already_generated_flag = 'N'
11663         -- For checking purposes, it will consider only
11664         -- the latest and not processed record
11665         AND m1.match_id IN (SELECT MAX(m2.match_id)
11666                             FROM inl_corr_matches_v m2
11667                             WHERE m2.to_parent_table_name     = m1.to_parent_table_name
11668                             AND m2.to_parent_table_id         = m1.to_parent_table_id
11669                             AND m2.match_type_code            = 'ITEM'
11670                             AND m2.replace_estim_qty_flag     = 'Y'
11671                             AND m2.adj_already_generated_flag = 'N'
11672                             )
11673         ;
11674         l_qty        := l_unproc_actual_qty;
11675         l_UOM_code   := l_unproc_UOM_code;
11676         l_debug_info := 'Unprocessed value as replace_estim_qty_flag = Y:';
11677         INL_LOGGING_PVT.Log_Statement(
11678             p_module_name    => g_module_name,
11679             p_procedure_name => l_program_name,
11680             p_debug_info     => l_debug_info
11681         ) ;
11682         INL_LOGGING_PVT.Log_Variable(
11683             p_module_name    => g_module_name,
11684             p_procedure_name => l_program_name,
11685             p_var_name       => 'l_qty',
11686             p_var_value      => l_qty
11687         ) ;
11688         INL_LOGGING_PVT.Log_Variable(
11689             p_module_name    => g_module_name,
11690             p_procedure_name => l_program_name,
11691             p_var_name       => 'l_uom_code',
11692             p_var_value      => l_uom_code
11693         ) ;
11694         IF p_updated_match_id = l_unproc_match_id THEN
11695             l_qty := p_matched_qty;
11696             l_UOM_code := p_matched_uom_code;
11697             l_debug_info := 'Unprocessed value will be updated by the current record(replace_estim_qty_flag = Y):';
11698             INL_LOGGING_PVT.Log_Statement(
11699                 p_module_name      => g_module_name,
11700                 p_procedure_name   => l_program_name,
11701                 p_debug_info       => l_debug_info
11702             ) ;
11703                     INL_LOGGING_PVT.Log_Variable(
11704                         p_module_name    => g_module_name,
11705                         p_procedure_name => l_program_name,
11706                         p_var_name       => 'l_qty',
11707                         p_var_value      => l_qty
11708                     ) ;
11709                     INL_LOGGING_PVT.Log_Variable(
11710                         p_module_name    => g_module_name,
11711                         p_procedure_name => l_program_name,
11712                         p_var_name       => 'l_UOM_code',
11713                         p_var_value      => l_UOM_code
11714                     ) ;
11715         END IF;
11716     EXCEPTION
11717     WHEN NO_DATA_FOUND THEN
11718         NULL;
11719     END;
11720     -- Check if there is any match line as
11721     -- replace_estim_qty_flag = 'N' and adj_already_generated_flag = 'N'
11722     l_debug_info := 'Get actual values from unprocessed matches';
11723     INL_LOGGING_PVT.Log_Statement(
11724         p_module_name      => g_module_name,
11725         p_procedure_name   => l_program_name,
11726         p_debug_info       => l_debug_info
11727     ) ;
11728     BEGIN
11729         SELECT SUM(decode(m1.matched_uom_code,
11730                           l_uom_code, m1.matched_qty,
11731                           NVL(inl_landedcost_pvt.Converted_Qty(l_organization_id,
11732                                                                l_inventory_item_id,
11733                                                                m1.matched_qty,
11734                                                                m1.matched_uom_code,
11735                                                                l_uom_code
11736                                                               )
11737                              ,0)
11738                          )
11739                   )
11740         INTO l_unproc_actual_qty
11741         FROM inl_corr_matches_v m1
11742         WHERE m1.to_parent_table_name = 'INL_SHIP_LINES'
11743         AND m1.to_parent_table_id     = p_ship_line_id
11744         AND m1.match_type_code        = 'ITEM'
11745         AND m1.replace_estim_qty_flag = 'N'
11746         AND m1.adj_already_generated_flag = 'N'
11747         ;
11748         l_debug_info := 'Actuals from unprocessed Matches(replace_estim_qty_flag = N):';
11749         INL_LOGGING_PVT.Log_Statement(
11750             p_module_name      => g_module_name,
11751             p_procedure_name   => l_program_name,
11752             p_debug_info       => l_debug_info
11753         ) ;
11754         INL_LOGGING_PVT.Log_Variable(
11755             p_module_name    => g_module_name,
11756             p_procedure_name => l_program_name,
11757             p_var_name       => 'l_unproc_actual_qty',
11758             p_var_value      => l_unproc_actual_qty
11759         ) ;
11760         l_actual_qty := l_actual_qty + l_unproc_actual_qty;
11761     EXCEPTION
11762         WHEN NO_DATA_FOUND THEN
11763             NULL;
11764     END;
11765     l_debug_info := 'Get values from processed matches';
11766     INL_LOGGING_PVT.Log_Statement(
11767         p_module_name      => g_module_name,
11768         p_procedure_name   => l_program_name,
11769         p_debug_info       => l_debug_info
11770     ) ;
11771     OPEN processed_matches;
11772     FETCH processed_matches BULK COLLECT INTO processed_matches_List;
11773     CLOSE processed_matches;
11774     FOR iMat IN 1 .. processed_matches_List.COUNT
11775     LOOP
11776             IF NVL(processed_matches_List(iMat).matched_qty, 0) <> 0 THEN
11777                 l_matches := l_matches ||processed_matches_List(iMat) .match_id||', ';
11778                 IF processed_matches_List(iMat).matched_uom_code <> l_UOM_code THEN
11779                     l_actual_qty := NVL(l_actual_qty, 0) +
11780                                     NVL(inl_landedcost_pvt.Converted_Qty( p_organization_id => l_organization_id,
11781                                                                           p_inventory_item_id => l_inventory_item_id,
11782                                                                           p_qty => processed_matches_List(iMat) .matched_qty,
11783                                                                           p_from_uom_code => processed_matches_List(iMat) .matched_uom_code,
11784                                                                           P_to_uom_code => l_UOM_code), 0) ;
11785                 ELSE
11786                     l_actual_qty := NVL(l_actual_qty, 0) + NVL(processed_matches_List(iMat).matched_qty, 0) ;
11787                 END IF;
11788             END IF;
11789     END LOOP;
11790     l_debug_info := 'Actuals from processed matches:';
11791     INL_LOGGING_PVT.Log_Statement(
11792         p_module_name      => g_module_name,
11793         p_procedure_name   => l_program_name,
11794         p_debug_info       => l_debug_info
11795     ) ;
11796     INL_LOGGING_PVT.Log_Variable(
11797         p_module_name    => g_module_name,
11798         p_procedure_name => l_program_name,
11799         p_var_name       => 'l_actual_qty',
11800         p_var_value      => l_actual_qty
11801     ) ;
11802     l_debug_info := 'Get values from not interfaced matches';
11803     INL_LOGGING_PVT.Log_Statement(
11804         p_module_name      => g_module_name,
11805         p_procedure_name   => l_program_name,
11806         p_debug_info       => l_debug_info
11807     ) ;
11808     OPEN OI_matches;
11809     FETCH OI_matches BULK COLLECT INTO OI_matches_List;
11810     CLOSE OI_matches;
11811     l_matches := l_matches ||'/ OI_mathes: ';
11812     IF NVL(OI_matches_List.COUNT, 0) > 0 THEN
11813         FOR iMat IN 1 .. OI_matches_List.COUNT
11814         LOOP
11815             l_debug_info := 'Get values from not interfaced matches';
11816             INL_LOGGING_PVT.Log_Statement(
11817                 p_module_name      => g_module_name,
11818                 p_procedure_name   => l_program_name,
11819                 p_debug_info       => l_debug_info
11820             ) ;
11821             l_matches := l_matches ||OI_matches_List(iMat) .MATCH_INT_ID ;
11822             IF OI_matches_List(iMat) .replace_estim_qty_flag = 'Y' THEN
11823                 IF OI_matches_List(iMat).transaction_type <> 'DELETE' THEN
11824                     l_qty := OI_matches_List(iMat) .matched_qty;
11825                     l_UOM_code := OI_matches_List(iMat) .matched_UOM_code;
11826                     l_debug_info := 'New estimated values from match interface:';
11827                     INL_LOGGING_PVT.Log_Statement(
11828                         p_module_name      => g_module_name,
11829                         p_procedure_name   => l_program_name,
11830                         p_debug_info       => l_debug_info
11831                     ) ;
11832                     INL_LOGGING_PVT.Log_Variable(
11833                         p_module_name    => g_module_name,
11834                         p_procedure_name => l_program_name,
11835                         p_var_name       => 'l_qty',
11836                         p_var_value      => l_qty
11837                     ) ;
11838                     INL_LOGGING_PVT.Log_Variable(
11839                         p_module_name    => g_module_name,
11840                         p_procedure_name => l_program_name,
11841                         p_var_name       => 'l_uom_code',
11842                         p_var_value      => l_uom_code
11843                     ) ;
11844 
11845                 END IF;
11846             ELSIF OI_matches_List(iMat).match_type_code   = 'ITEM' THEN
11847                 IF OI_matches_List(iMat).transaction_type = 'CREATE' THEN
11848                     OI_matches_qty := OI_matches_List(iMat) .matched_qty;
11849                     OI_matches_UOM_code := OI_matches_List(iMat).matched_UOM_code;
11850                 END IF;
11851                 IF OI_matches_UOM_code <> l_UOM_code THEN
11852                     l_actual_qty := NVL(l_actual_qty, 0)
11853                                     + NVL(inl_landedcost_pvt.Converted_Qty(
11854                                               p_organization_id => l_organization_id,
11855                                               p_inventory_item_id => l_inventory_item_id,
11856                                               p_qty => OI_matches_qty,
11857                                               p_from_uom_code => OI_matches_UOM_code,
11858                                               P_to_uom_code => l_UOM_code)
11859                                     , 0)
11860                     ;
11861                 ELSE
11862                     l_actual_qty := NVL(l_actual_qty, 0) + NVL(OI_matches_qty, 0) ;
11863                 END IF;
11864             END IF;
11865             l_debug_info := 'End Loop';
11866             INL_LOGGING_PVT.Log_Statement(
11867                 p_module_name      => g_module_name,
11868                 p_procedure_name   => l_program_name,
11869                 p_debug_info       => l_debug_info
11870             );
11871                     INL_LOGGING_PVT.Log_Variable(
11872                         p_module_name    => g_module_name,
11873                         p_procedure_name => l_program_name,
11874                         p_var_name       => 'l_actual_qty',
11875                         p_var_value      => l_actual_qty
11876                     ) ;
11877 
11878         END LOOP;
11879     END IF;
11880     IF p_matched_uom_code <> l_UOM_code THEN
11881         l_match_qty := NVL(inl_landedcost_pvt.Converted_Qty(
11882                             p_organization_id   => l_organization_id,
11883                             p_inventory_item_id => l_inventory_item_id,
11884                             p_qty               => p_matched_qty,
11885                             p_from_uom_code     => p_matched_uom_code,
11886                             P_to_uom_code       => l_UOM_code), 0)
11887         ;
11888     ELSE
11889         l_match_qty := NVL(p_matched_qty, 0) ;
11890     END IF;
11891     IF p_replace_estim_qty_flag = 'Y' THEN
11892         l_qty := NVL(l_match_qty, 0) ;
11893     ELSIF p_match_type_code <> 'CORRECTION' THEN
11894         l_actual_qty := NVL(l_actual_qty, 0) + NVL(l_match_qty, 0) ;
11895     END IF;
11896     IF NVL(l_actual_qty, 0) > NVL(l_qty, 0) THEN
11897         l_result := L_FND_FALSE;
11898         l_debug_info := 'Insufficient estimated quantity('||l_qty||') for the actuals received('||l_actual_qty||')'|| l_matches;
11899         INL_LOGGING_PVT.Log_Statement(
11900             p_module_name      => g_module_name,
11901             p_procedure_name   => l_program_name,
11902             p_debug_info       => l_debug_info
11903         );
11904         -- Add a line into inl_ship_errors
11905         Handle_InterfError(
11906             p_parent_table_name  => 'INL_MATCHES_INT',
11907             p_parent_table_id    => p_match_int_id,
11908             p_column_name        => 'MATCHED_QTY',
11909             p_column_value       => p_matched_qty,
11910             p_error_message_name => 'INL_ERR_OI_MAT_INSUF_EST_QTY',
11911             p_token1_name        => 'EST_QTY',
11912             p_token1_value       => l_qty,
11913             p_token2_name        => 'ACT_QTY',
11914             p_token2_value       => l_actual_qty,
11915             p_token3_name        => 'MATCH_INT_ID',
11916             p_token3_value       => p_match_int_id,
11917             x_return_status      => l_return_status
11918         ) ;
11919         -- If unexpected errors happen abort
11920         IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
11921             RAISE L_FND_EXC_UNEXPECTED_ERROR;
11922         END IF;
11923     END IF;
11924     l_debug_info := 'Trace: '||l_matches;
11925     INL_LOGGING_PVT.Log_Statement(
11926         p_module_name      => g_module_name,
11927         p_procedure_name   => l_program_name,
11928         p_debug_info       => l_debug_info
11929     );
11930     -- Standard End of Procedure/Function Logging
11931     INL_LOGGING_PVT.Log_EndProc(
11932         p_module_name    => g_module_name,
11933         p_procedure_name => l_program_name
11934     );
11935     RETURN FND_API.to_boolean(l_result) ;
11936 EXCEPTION
11937     WHEN L_FND_EXC_ERROR THEN
11938         -- Standard Expected Error Logging
11939         INL_LOGGING_PVT.Log_ExpecError (
11940             p_module_name    => g_module_name,
11941             p_procedure_name => l_program_name
11942         );
11943         RETURN FND_API.to_boolean(L_FND_FALSE) ;
11944     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
11945         -- Standard Unexpected Error Logging
11946         INL_LOGGING_PVT.Log_UnexpecError (
11947             p_module_name    => g_module_name,
11948             p_procedure_name => l_program_name
11949         );
11950         RETURN FND_API.to_boolean(L_FND_FALSE) ;
11951     WHEN OTHERS THEN
11952         -- Standard Unexpected Error Logging
11953         INL_LOGGING_PVT.Log_UnexpecError (
11954             p_module_name    => g_module_name,
11955             p_procedure_name => l_program_name
11956         );
11957         IF FND_MSG_PUB.Check_Msg_Level(
11958             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
11959         ) THEN
11960             FND_MSG_PUB.Add_Exc_Msg(
11961                 p_pkg_name       => g_pkg_name,
11962                 p_procedure_name => l_program_name
11963             );
11964         END IF;
11965         RETURN FND_API.to_boolean(L_FND_FALSE) ;
11966 END Validate_MatchQty;
11967 -- Funct name : Validate_MatchTax
11968 -- Type       : Private
11969 -- Function   : Validate a given Match Tax
11970 --
11971 -- Pre-reqs   : None
11972 -- Parameters :
11973 -- IN         : p_match_int_id           IN NUMBER
11974 --              p_tax_code               IN VARCHAR2
11975 --              p_nrec_tax_amt           IN NUMBER
11976 --              p_tax_amt_included_flag  IN VARCHAR2
11977 --              p_matched_amt            IN NUMBER
11978 --              p_match_type_code        IN VARCHAR2
11979 --              p_parent_match_type_code IN VARCHAR2
11980 --
11981 -- OUT        : x_return_status          OUT NOCOPY VARCHAR2
11982 --
11983 -- Version    : Current version 1.0
11984 --
11985 -- Notes      :
11986 FUNCTION Validate_MatchTax(
11987     p_match_int_id           IN NUMBER,
11988     p_tax_code               IN VARCHAR2,
11989     p_nrec_tax_amt           IN NUMBER,
11990     p_tax_amt_included_flag  IN VARCHAR2,
11991     p_matched_amt            IN NUMBER,
11992     p_match_type_code        IN VARCHAR2,
11993     p_parent_match_type_code IN VARCHAR2,
11994     x_return_status          OUT NOCOPY VARCHAR2
11995 ) RETURN BOOLEAN IS
11996     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_MatchTax';
11997     l_debug_info    VARCHAR2(400) ;
11998     l_return_status VARCHAR2(1) ;
11999     l_result        VARCHAR2(1) := L_FND_TRUE;
12000 BEGIN
12001     -- Standard Beginning of Procedure/Function Logging
12002     INL_LOGGING_PVT.Log_BeginProc(
12003         p_module_name    => g_module_name,
12004         p_procedure_name => l_program_name
12005     ) ;
12006     --  Initialize API return status to success
12007     x_return_status := L_FND_RET_STS_SUCCESS;
12008     IF NVL(p_parent_match_type_code, p_match_type_code) = 'TAX' THEN
12009         l_debug_info     := 'Check: The unrecoverable amount should be smaller or equal to matched amount';
12010         INL_LOGGING_PVT.Log_Statement(
12011             p_module_name      => g_module_name,
12012             p_procedure_name   => l_program_name,
12013             p_debug_info       => l_debug_info
12014         );
12015         IF (NVL(p_nrec_tax_amt, 0) > NVL(p_matched_amt, 0) --BUG#8198265
12016             AND NVL(p_nrec_tax_amt, 0) > 0)
12017             OR
12018             (NVL(p_nrec_tax_amt, 0) < NVL(p_matched_amt, 0)
12019             AND NVL(p_matched_amt, 0) < 0
12020             AND NVL(p_nrec_tax_amt, 0) < 0)
12021         THEN
12022             l_result     := L_FND_FALSE;
12023             -- Add a line into inl_ship_errors
12024             Handle_InterfError(
12025                 p_parent_table_name  => 'INL_MATCHES_INT',
12026                 p_parent_table_id    => p_match_int_id,
12027                 p_column_name        => 'NREC_TAX_AMT',
12028                 p_column_value       => p_nrec_tax_amt,
12029                 p_error_message_name => 'INL_ERR_OI_CHK_NREC_TAX_AMT',
12030                 p_token1_name        => 'MATCH_INT_ID',
12031                 p_token1_value       => p_match_int_id,
12032                 x_return_status      => l_return_status
12033             ) ;
12034             -- If unexpected errors happen abort
12035             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12036                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
12037             END IF;
12038         END IF;
12039         l_debug_info := 'Check: TAX_CODE cannot be null';
12040         INL_LOGGING_PVT.Log_Statement(
12041             p_module_name      => g_module_name,
12042             p_procedure_name   => l_program_name,
12043             p_debug_info       => l_debug_info
12044         );
12045         IF p_tax_code                               IS NULL THEN
12046             l_result := L_FND_FALSE;
12047             -- Add a line into inl_ship_errors
12048             Handle_InterfError(
12049                 p_parent_table_name  => 'INL_MATCHES_INT',
12050                 p_parent_table_id    => p_match_int_id,
12051                 p_column_name        => 'TAX_CODE',
12052                 p_column_value       => p_tax_code,
12053                 p_error_message_name => 'INL_ERR_OI_CHK_TX_CODE_NULL',
12054                 p_token1_name        => 'MATCH_INT_ID',
12055                 p_token1_value       => p_match_int_id,
12056                 x_return_status      => l_return_status
12057             ) ;
12058             -- If unexpected errors happen abort
12059             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12060                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
12061             END IF;
12062         END IF;
12063         l_debug_info := 'Check: TAX_AMT_INCLUDED_FLAG cannot be null';
12064         INL_LOGGING_PVT.Log_Statement(
12065             p_module_name      => g_module_name,
12066             p_procedure_name   => l_program_name,
12067             p_debug_info       => l_debug_info
12068         );
12069         IF p_tax_amt_included_flag IS NULL THEN
12070             l_result := L_FND_FALSE;
12071             -- Add a line into inl_ship_errors
12072             Handle_InterfError(
12073                 p_parent_table_name  => 'INL_MATCHES_INT',
12074                 p_parent_table_id    => p_match_int_id,
12075                 p_column_name        => 'TAX_AMT_INCLUDED_FLAG',
12076                 p_column_value       => p_tax_amt_included_flag,
12077                 p_error_message_name => 'INL_ERR_OI_CHK_TX_AMT_FLG_NULL',
12078                 p_token1_name        => 'MATCH_INT_ID',
12079                 p_token1_value       => p_match_int_id,
12080                 x_return_status      => l_return_status
12081             ) ;
12082             -- If unexpected errors happen abort
12083             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12084                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
12085             END IF;
12086         END IF;
12087     ELSIF p_tax_amt_included_flag IS NOT NULL OR p_tax_code IS NOT NULL OR NVL(p_nrec_tax_amt, 0) <> 0 THEN
12088         l_result := L_FND_FALSE;
12089         -- Add a line into inl_ship_errors
12090         Handle_InterfError(
12091             p_parent_table_name  => 'INL_MATCHES_INT',
12092             p_parent_table_id    => p_match_int_id,
12093             p_column_name        => 'TAX_INT_ID',
12094             p_column_value       => p_match_int_id,
12095             p_error_message_name => 'INL_ERR_OI_CHK_TX_FIELD_NNULL',
12096             p_token1_name        => 'MATCH_INT_ID',
12097             p_token1_value       => p_match_int_id,
12098             x_return_status      => l_return_status
12099         ) ;
12100         -- If unexpected errors happen abort
12101         IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12102             RAISE L_FND_EXC_UNEXPECTED_ERROR;
12103         END IF;
12104     END IF;
12105     -- Standard End of Procedure/Function Logging
12106     INL_LOGGING_PVT.Log_EndProc(
12107         p_module_name    => g_module_name,
12108         p_procedure_name => l_program_name
12109     );
12110     RETURN FND_API.to_boolean(l_result) ;
12111 EXCEPTION
12112     WHEN L_FND_EXC_ERROR THEN
12113         -- Standard Expected Error Logging
12114         INL_LOGGING_PVT.Log_ExpecError (
12115             p_module_name    => g_module_name,
12116             p_procedure_name => l_program_name
12117         );
12118         RETURN FND_API.to_boolean(L_FND_FALSE) ;
12119     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
12120         -- Standard Unexpected Error Logging
12121         INL_LOGGING_PVT.Log_UnexpecError (
12122             p_module_name    => g_module_name,
12123             p_procedure_name => l_program_name
12124         );
12125         RETURN FND_API.to_boolean(L_FND_FALSE) ;
12126     WHEN OTHERS THEN
12127         -- Standard Unexpected Error Logging
12128         INL_LOGGING_PVT.Log_UnexpecError (
12129             p_module_name    => g_module_name,
12130             p_procedure_name => l_program_name
12131         );
12132         IF FND_MSG_PUB.Check_Msg_Level(
12133             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
12134         ) THEN
12135             FND_MSG_PUB.Add_Exc_Msg(
12136                 p_pkg_name       => g_pkg_name,
12137                 p_procedure_name => l_program_name
12138             );
12139         END IF;
12140         RETURN FND_API.to_boolean(L_FND_FALSE) ;
12141 END Validate_MatchTax;
12142 -- Funct name : Validate_MatchAmt
12143 -- Type       : Private
12144 -- Function   : Validate a given Match Amount
12145 --
12146 -- Pre-reqs   : None
12147 -- Parameters :
12148 -- IN         : p_match_int_id             IN NUMBER
12149 --              p_parent_matched_curr_code IN VARCHAR2
12150 --              p_parent_match_type_code   IN VARCHAR2
12151 --              p_match_type_code          IN VARCHAR2
12152 --              p_matched_amt              IN NUMBER
12153 --              p_matched_curr_code        IN VARCHAR2
12154 --              p_matched_curr_conv_type   IN VARCHAR2
12155 --              p_matched_curr_conv_date   IN DATE
12156 --              p_matched_curr_conv_rate   IN NUMBER
12157 --              p_replace_estim_qty_flag   IN VARCHAR2
12158 --
12159 -- IN OUT     : x_return_status            OUT NOCOPY VARCHAR2
12160 --
12161 -- Version    : Current version 1.0
12162 --
12163 -- Notes      :
12164 FUNCTION Validate_MatchAmt(
12165     p_match_int_id             IN NUMBER,
12166     p_parent_matched_curr_code IN VARCHAR2,
12167     p_parent_match_type_code   IN VARCHAR2,
12168     p_match_type_code          IN VARCHAR2,
12169     p_matched_amt              IN NUMBER,
12170     p_matched_curr_code        IN VARCHAR2,
12171     p_matched_curr_conv_type   IN VARCHAR2,
12172     p_matched_curr_conv_date   IN DATE,
12173     p_matched_curr_conv_rate   IN NUMBER,
12174     p_replace_estim_qty_flag   IN VARCHAR2,
12175     x_return_status            OUT NOCOPY VARCHAR2
12176 ) RETURN BOOLEAN IS
12177     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_MatchAmt';
12178     l_debug_info    VARCHAR2(400) ;
12179     l_return_status VARCHAR2(1) ;
12180     l_result        VARCHAR2(1) := L_FND_TRUE;
12181 BEGIN
12182     -- Standard Beginning of Procedure/Function Logging
12183     INL_LOGGING_PVT.Log_BeginProc(
12184         p_module_name    => g_module_name,
12185         p_procedure_name => l_program_name
12186     ) ;
12187     --  Initialize API return status to success
12188     x_return_status := L_FND_RET_STS_SUCCESS;
12189     l_debug_info := 'Check in case of correction, the currency must be the same of the original';
12190     INL_LOGGING_PVT.Log_Statement(
12191         p_module_name      => g_module_name,
12192         p_procedure_name   => l_program_name,
12193         p_debug_info       => l_debug_info
12194     );
12195     IF p_match_type_code = 'CORRECTION' THEN
12196         IF p_parent_matched_curr_code           <> p_matched_curr_code THEN
12197             l_result                            := L_FND_FALSE;
12198             -- Add a line into inl_ship_errors
12199             Handle_InterfError(
12200                 p_parent_table_name  => 'INL_MATCHES_INT',
12201                 p_parent_table_id    => p_match_int_id,
12202                 p_column_name        => 'MATCHED_AMT',
12203                 p_column_value       => p_matched_amt,
12204                 p_error_message_name => 'INL_ERR_OI_CHK_CURR_INV',
12205                 p_token1_name        => 'CURR1',
12206                 p_token1_value       => p_matched_curr_code,
12207                 p_token2_name        => 'CURR2',
12208                 p_token2_value       => p_parent_matched_curr_code,
12209                 p_token3_name        => 'MATCH_INT_ID',
12210                 p_token3_value       => p_match_int_id,
12211                 x_return_status      => l_return_status) ;
12212             -- If unexpected errors happen abort
12213             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12214                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
12215             END IF;
12216         END IF;
12217     END IF;
12218     l_debug_info := 'When replace_estim_qty_flag = "Y", the final Amount cannot be null';
12219     INL_LOGGING_PVT.Log_Statement(
12220         p_module_name      => g_module_name,
12221         p_procedure_name   => l_program_name,
12222         p_debug_info       => l_debug_info
12223     );
12224     IF p_replace_estim_qty_flag = 'Y'
12225        AND (p_matched_amt IS NULL OR NVL(p_matched_amt, 0) < 0)
12226     THEN
12227         l_result := L_FND_FALSE;
12228         -- Add a line into inl_ship_errors
12229         Handle_InterfError(
12230             p_parent_table_name  => 'INL_MATCHES_INT',
12231             p_parent_table_id    => p_match_int_id,
12232             p_column_name        => 'MATCHED_AMT',
12233             p_column_value       => p_matched_amt,
12234             p_error_message_name => 'INL_ERR_OI_CHK_AMT_NULL',
12235             p_token1_name        => 'MATCH_INT_ID',
12236             p_token1_value       => p_match_int_id,
12237             x_return_status      => l_return_status
12238         ) ;
12239         -- If unexpected errors happen abort
12240         IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12241             RAISE L_FND_EXC_UNEXPECTED_ERROR;
12242         END IF;
12243     END IF;
12244     -- Standard End of Procedure/Function Logging
12245     INL_LOGGING_PVT.Log_EndProc(
12246         p_module_name    => g_module_name,
12247         p_procedure_name => l_program_name
12248     );
12249     RETURN FND_API.to_boolean(l_result) ;
12250 EXCEPTION
12251     WHEN L_FND_EXC_ERROR THEN
12252         -- Standard Expected Error Logging
12253         INL_LOGGING_PVT.Log_ExpecError (
12254             p_module_name    => g_module_name,
12255             p_procedure_name => l_program_name
12256         );
12257         RETURN FND_API.to_boolean(L_FND_FALSE) ;
12258     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
12259         -- Standard Unexpected Error Logging
12260         INL_LOGGING_PVT.Log_UnexpecError (
12261             p_module_name    => g_module_name,
12262             p_procedure_name => l_program_name
12263         );
12264         RETURN FND_API.to_boolean(L_FND_FALSE) ;
12265     WHEN OTHERS THEN
12266         -- Standard Unexpected Error Logging
12267         INL_LOGGING_PVT.Log_UnexpecError (
12268             p_module_name    => g_module_name,
12269             p_procedure_name => l_program_name
12270         );
12271         IF FND_MSG_PUB.Check_Msg_Level(
12272             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
12273         ) THEN
12274             FND_MSG_PUB.Add_Exc_Msg(
12275                 p_pkg_name       => g_pkg_name,
12276                 p_procedure_name => l_program_name
12277             );
12278         END IF;
12279         RETURN FND_API.to_boolean(L_FND_FALSE) ;
12280 END Validate_MatchAmt;
12281 --/ SCM-051 Begin
12282 -- Funct name : Validate_MatchElcOnGoing
12283 -- Type       : Private
12284 -- Function   : Validate a given UOM code used by the Matching Process
12285 --
12286 -- Pre-reqs   : None
12287 -- Parameters :
12288 -- IN         : p_match_int_id              IN NUMBER
12289 --              p_matched_uom_code          IN VARCHAR2
12290 --              p_match_type_code           IN VARCHAR2
12291 --              p_parent_match_type_code    IN VARCHAR2
12292 --
12293 -- IN OUT     : x_return_status      OUT NOCOPY VARCHAR2
12294 --
12295 -- Version    : Current version 1.0
12296 --
12297 -- Notes      :
12298 FUNCTION Validate_MatchElcOnGoing(
12299     p_match_int_id           IN NUMBER,
12300     p_to_parent_table_name   IN VARCHAR2,
12301     p_to_parent_table_id     IN VARCHAR2,
12302     p_match_type_code        IN VARCHAR2,
12303     p_charge_line_type_id    IN VARCHAR2,
12304     x_return_status          OUT NOCOPY VARCHAR2
12305 )RETURN BOOLEAN IS
12306     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_MatchElcOnGoing';
12307     l_debug_info    VARCHAR2(400) ;
12308     l_return_status VARCHAR2(1) ;
12309     l_result        VARCHAR2(1) := L_FND_TRUE;
12310 
12311     l_new_currency_conversion_rate NUMBER;
12312     l_new_currency_conversion_date DATE;
12313     l_new_currency_conversion_type VARCHAR2(30);
12314     l_new_txn_unit_price           NUMBER;
12315     l_count_elc_ong                NUMBER;
12316     l_ship_num                     VARCHAR2(25); -- SCM-051
12317     l_group_id                     NUMBER; -- SCM-051
12318 
12319   -- ORA-00054 is the resource busy exception, which is raised when trying
12320   -- to lock a row that is already locked by another session.
12321   RESOURCE_BUSY EXCEPTION;
12322   PRAGMA EXCEPTION_INIT(RESOURCE_BUSY, -00054);
12323 
12324 BEGIN
12325     -- Standard Beginning of Procedure/Function Logging
12326     INL_LOGGING_PVT.Log_BeginProc(
12327         p_module_name    => g_module_name,
12328         p_procedure_name => l_program_name
12329     ) ;
12330     --  Initialize API return status to success
12331     x_return_status := L_FND_RET_STS_SUCCESS;
12332     l_debug_info         := 'Validate if exist any ELC update on going.';
12333     INL_LOGGING_PVT.Log_Statement(
12334         p_module_name      => g_module_name,
12335         p_procedure_name   => l_program_name,
12336         p_debug_info       => l_debug_info
12337     );
12338 
12339     INL_LOGGING_PVT.Log_Variable(
12340         p_module_name    => g_module_name,
12341         p_procedure_name => l_program_name,
12342         p_var_name       => 'p_match_int_id',
12343         p_var_value      =>  p_match_int_id);
12344 
12345     INL_LOGGING_PVT.Log_Variable(
12346         p_module_name    => g_module_name,
12347         p_procedure_name => l_program_name,
12348         p_var_name       => 'p_to_parent_table_name',
12349         p_var_value      =>  p_to_parent_table_name);
12350 
12351     INL_LOGGING_PVT.Log_Variable(
12352         p_module_name    => g_module_name,
12353         p_procedure_name => l_program_name,
12354         p_var_name       => 'p_to_parent_table_id',
12355         p_var_value      =>  p_to_parent_table_id);
12356 
12357     INL_LOGGING_PVT.Log_Variable(
12358         p_module_name    => g_module_name,
12359         p_procedure_name => l_program_name,
12360         p_var_name       => 'p_match_type_code',
12361         p_var_value      =>  p_match_type_code);
12362 
12363     INL_LOGGING_PVT.Log_Variable(
12364         p_module_name    => g_module_name,
12365         p_procedure_name => l_program_name,
12366         p_var_name       => 'p_charge_line_type_id',
12367         p_var_value      =>  p_charge_line_type_id);
12368 
12369     INL_LOGGING_PVT.Log_Statement(
12370         p_module_name      => g_module_name,
12371         p_procedure_name   => l_program_name,
12372         p_debug_info       => 'Verify if Ship Line has an ELC update'
12373     );
12374     -- If ship line has ELC on going any actual is unnacceptable
12375     IF p_match_type_code = 'ITEM' THEN
12376 
12377         INL_LOGGING_PVT.Log_Statement(
12378             p_module_name => g_module_name,
12379             p_procedure_name => l_program_name,
12380             p_debug_info => 'Verify if any related Ship Line has an ELC update');
12381 
12382         IF p_to_parent_table_name = 'RCV_TRANSACTIONS' THEN
12383 
12384             INL_LOGGING_PVT.Log_Statement(
12385                 p_module_name => g_module_name,
12386                 p_procedure_name => l_program_name,
12387                 p_debug_info => 'Verify if Ship Line has an ELC update to parent RCV_TRANSACTIONS with FOR UPDATE of inl_ship_headers');
12388 
12389             SELECT
12390                 sl.new_currency_conversion_rate,
12391                 sl.new_currency_conversion_date,
12392                 sl.new_currency_conversion_type,
12393                 sl.new_txn_unit_price,
12394                 sh.ship_num
12395             INTO
12396                 l_new_currency_conversion_rate,
12397                 l_new_currency_conversion_date,
12398                 l_new_currency_conversion_type,
12399                 l_new_txn_unit_price,
12400                 l_ship_num -- SCM-051
12401             FROM
12402                 rcv_transactions rt,
12403                 inl_adj_ship_lines_v sl,
12404                 inl_ship_headers_all sh -- SCM-051
12405             WHERE
12406                 rt.transaction_id = p_to_parent_table_id
12407             AND sh.ship_header_id = sl.ship_header_id -- SCM-051
12408             AND NVL(sl.parent_ship_line_id,sl.ship_line_id)   = rt.lcm_shipment_line_id
12409             FOR UPDATE of sh.ship_header_id NOWAIT; -- SCM-051
12410         ELSIF p_to_parent_table_name = 'INL_SHIP_LINES' THEN
12411 
12412             INL_LOGGING_PVT.Log_Statement(
12413                 p_module_name => g_module_name,
12414                 p_procedure_name => l_program_name,
12415                 p_debug_info => 'Verify if Ship Line has an ELC update to parent INL_SHIP_LINES with FOR UPDATE of inl_ship_headers');
12416 
12417             SELECT
12418                 sl.new_currency_conversion_rate,
12419                 sl.new_currency_conversion_date,
12420                 sl.new_currency_conversion_type,
12421                 sl.new_txn_unit_price,
12422                 sh.ship_num
12423             INTO
12424                 l_new_currency_conversion_rate,
12425                 l_new_currency_conversion_date,
12426                 l_new_currency_conversion_type,
12427                 l_new_txn_unit_price,
12428                 l_ship_num
12429             FROM
12430                 inl_adj_ship_lines_v sl,
12431                 inl_ship_headers_all sh -- SCM-051
12432             WHERE
12433                  sh.ship_header_id = sl.ship_header_id -- SCM-051
12434             AND  NVL(sl.parent_ship_line_id,sl.ship_line_id)   = p_to_parent_table_id
12435             FOR UPDATE of sh.ship_header_id NOWAIT; -- SCM-051
12436 
12437         END IF;
12438         IF l_new_currency_conversion_rate IS NOT NULL
12439         OR l_new_currency_conversion_date IS NOT NULL
12440         OR l_new_currency_conversion_type IS NOT NULL
12441         OR l_new_txn_unit_price IS NOT NULL
12442         THEN
12443 
12444             INL_LOGGING_PVT.Log_Statement(
12445                 p_module_name => g_module_name,
12446                 p_procedure_name => l_program_name,
12447                 p_debug_info => 'ELC Update on going to p_to_parent_table_id: ' || p_to_parent_table_id);
12448 
12449             INL_LOGGING_PVT.Log_Variable(
12450                 p_module_name    => g_module_name,
12451                 p_procedure_name => l_program_name,
12452                 p_var_name       => 'l_new_currency_conversion_rate',
12453                 p_var_value      =>  l_new_currency_conversion_rate);
12454             INL_LOGGING_PVT.Log_Variable(
12455                 p_module_name    => g_module_name,
12456                 p_procedure_name => l_program_name,
12457                 p_var_name       => 'l_new_currency_conversion_date',
12458                 p_var_value      =>  l_new_currency_conversion_date);
12459             INL_LOGGING_PVT.Log_Variable(
12460                 p_module_name    => g_module_name,
12461                 p_procedure_name => l_program_name,
12462                 p_var_name       => 'l_new_currency_conversion_type',
12463                 p_var_value      =>  l_new_currency_conversion_type);
12464             INL_LOGGING_PVT.Log_Variable(
12465                 p_module_name    => g_module_name,
12466                 p_procedure_name => l_program_name,
12467                 p_var_name       => 'l_new_txn_unit_price',
12468                 p_var_value      =>  l_new_txn_unit_price);
12469             l_result := L_FND_FALSE;
12470             -- Add a line into inl_ship_errors
12471             Handle_InterfError(
12472                 p_parent_table_name  => 'INL_MATCHES_INT',
12473                 p_parent_table_id    => p_match_int_id,
12474                 p_column_name        => 'p_match_int_id',
12475                 p_column_value       => p_match_int_id,
12476                 p_error_message_name => 'INL_ERR_OI_CHK_ELC_UPDATE',
12477                 p_token1_name        => 'MATCH_INT_ID',
12478                 p_token1_value       => p_match_int_id,
12479                 p_token2_name        => 'SHIP_NUM',
12480                 p_token2_value       => l_ship_num,
12481                 p_token3_name        => 'SHIP_NUM',
12482                 p_token3_value       => l_ship_num,
12483                 x_return_status      => l_return_status
12484             ) ;
12485             -- If unexpected errors happen abort
12486             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12487                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
12488             END IF;
12489         END IF;
12490     ELSIF p_match_type_code = 'CHARGE' THEN
12491 
12492         INL_LOGGING_PVT.Log_Statement(
12493             p_module_name => g_module_name,
12494             p_procedure_name => l_program_name,
12495             p_debug_info => 'Verify if any related charge Line has an ELC update');
12496 
12497         IF p_to_parent_table_name = 'RCV_TRANSACTIONS' THEN
12498 
12499             INL_LOGGING_PVT.Log_Statement(
12500                 p_module_name => g_module_name,
12501                 p_procedure_name => l_program_name,
12502                 p_debug_info => 'Select FOR UPDATE of inl_ship_headers');
12503 
12504             -- SCM-051
12505             SELECT sh.ship_num
12506             INTO l_ship_num
12507             FROM inl_ship_headers_all sh,
12508                  inl_ship_lines_all sl,
12509                  rcv_transactions rt
12510             WHERE sh.ship_header_id = sl.ship_header_id
12511             AND rt.transaction_id = p_to_parent_table_id
12512             AND NVL(sl.parent_ship_line_id,sl.ship_line_id) = rt.lcm_shipment_line_id
12513             AND ROWNUM = 1
12514             FOR UPDATE OF sh.ship_header_id NOWAIT;
12515             -- /SCM-051
12516 
12517             INL_LOGGING_PVT.Log_Statement(
12518                 p_module_name => g_module_name,
12519                 p_procedure_name => l_program_name,
12520                 p_debug_info => 'Verify if Charge Line has an ELC update to parent RCV_TRANSACTIONS');
12521 
12522             SELECT
12523                 NVL(COUNT(*),0)
12524             INTO
12525                 l_count_elc_ong
12526             FROM
12527                 inl_adj_charge_lines_v cl,
12528                 inl_associations a,
12529                 inl_ship_lines_all sl,
12530                 rcv_transactions rt
12531             WHERE
12532                 rt.transaction_id = p_to_parent_table_id
12533             AND NVL(sl.parent_ship_line_id,sl.ship_line_id) = rt.lcm_shipment_line_id
12534             AND a.from_parent_table_name = 'INL_CHARGE_LINES'
12535             AND (
12536                  (a.to_parent_table_name = 'INL_SHIP_HEADERS'
12537                   AND a.to_parent_table_id = sl.ship_header_id)
12538                  OR
12539                  (a.to_parent_table_name = 'INL_SHIP_LINE_GROUPS'
12540                   AND a.to_parent_table_id = sl.ship_line_group_id)
12541                  OR
12542                  (a.to_parent_table_name = 'INL_SHIP_LINES'
12543                   AND a.to_parent_table_id = NVL(sl.parent_ship_line_id,sl.ship_line_id))
12544                  )
12545             AND cl.charge_line_type_id = p_charge_line_type_id
12546             AND cl.adjustment_num <= 0
12547             AND cl.charge_line_id IN
12548                 (
12549                     SELECT
12550                         cl1.charge_line_id
12551                      FROM
12552                         inl_charge_lines cl1
12553                     WHERE
12554                     CONNECT_BY_ISLEAF = 1
12555                     START WITH cl1.charge_line_id = a.from_parent_table_id
12556                     CONNECT BY PRIOR cl1.charge_line_id = cl1.parent_charge_line_id
12557                 )
12558             AND (cl.new_currency_conversion_rate IS NOT NULL
12559                  OR cl.new_currency_conversion_date IS NOT NULL
12560                  OR cl.new_currency_conversion_type IS NOT NULL
12561                  OR cl.new_charge_amt IS NOT NULL
12562                  OR cl.adjustment_type_flag = 'A') -- new ELC charge line waiting for submit
12563             ;
12564 
12565         ELSIF p_to_parent_table_name = 'INL_SHIP_LINES' THEN
12566 
12567             INL_LOGGING_PVT.Log_Statement(
12568                 p_module_name => g_module_name,
12569                 p_procedure_name => l_program_name,
12570                 p_debug_info => 'Verify if Charge Line has an ELC update to parent INL_SHIP_LINES');
12571 
12572             -- SCM-051
12573             SELECT sh.ship_num
12574             INTO l_ship_num
12575             FROM inl_ship_headers_all sh,
12576                  inl_ship_lines_all sl
12577             WHERE sh.ship_header_id = sl.ship_header_id
12578             AND sl.ship_line_id = p_to_parent_table_id
12579             AND ROWNUM = 1
12580             FOR UPDATE OF sh.ship_header_id NOWAIT;
12581             -- /SCM-051
12582 
12583             INL_LOGGING_PVT.Log_Statement(
12584                 p_module_name => g_module_name,
12585                 p_procedure_name => l_program_name,
12586                 p_debug_info => 'Verify if Charge Line has an ELC update to parent INL_SHIP_LINES');
12587 
12588             SELECT
12589                 NVL(COUNT(*),0)
12590             INTO
12591                 l_count_elc_ong
12592             FROM
12593                 inl_adj_charge_lines_v cl,
12594                 inl_associations a,
12595                 inl_ship_lines_all sl
12596             WHERE
12597                 sl.ship_line_id = p_to_parent_table_id
12598             AND a.from_parent_table_name = 'INL_CHARGE_LINES'
12599             AND (
12600                  (a.to_parent_table_name = 'INL_SHIP_HEADERS'
12601                   AND a.to_parent_table_id = sl.ship_header_id)
12602                  OR
12603                  (a.to_parent_table_name = 'INL_SHIP_LINE_GROUPS'
12604                   AND a.to_parent_table_id = sl.ship_line_group_id)
12605                  OR
12606                  (a.to_parent_table_name = 'INL_SHIP_LINES'
12607                   AND a.to_parent_table_id = NVL(sl.parent_ship_line_id,sl.ship_line_id))
12608                  )
12609             AND cl.charge_line_type_id = p_charge_line_type_id
12610             AND cl.adjustment_num <= 0
12611             AND (cl.new_currency_conversion_rate IS NOT NULL
12612                  OR cl.new_currency_conversion_date IS NOT NULL
12613                  OR cl.new_charge_amt IS NOT NULL
12614                  OR cl.adjustment_type_flag = 'A') -- new ELC charge line waiting for submit
12615             ;
12616         END IF;
12617 
12618         IF l_count_elc_ong > 0
12619         THEN
12620             INL_LOGGING_PVT.Log_Variable(
12621                 p_module_name    => g_module_name,
12622                 p_procedure_name => l_program_name,
12623                 p_var_name       => 'l_count_elc_ong',
12624                 p_var_value      =>  l_count_elc_ong);
12625             l_result     := L_FND_FALSE;
12626             -- Add a line into inl_ship_errors
12627             Handle_InterfError(
12628                 p_parent_table_name  => 'INL_MATCHES_INT',
12629                 p_parent_table_id    => p_match_int_id,
12630                 p_column_name        => 'p_match_int_id',
12631                 p_column_value       => p_match_int_id,
12632                 p_error_message_name => 'INL_ERR_OI_CHK_ELC_UPDATE',
12633                 p_token1_name        => 'MATCH_INT_ID',
12634                 p_token1_value       => p_match_int_id,
12635                 p_token2_name        => 'SHIP_NUM',
12636                 p_token2_value       => l_ship_num,
12637                 p_token3_name        => 'SHIP_NUM',
12638                 p_token3_value       => l_ship_num,
12639                 x_return_status      => l_return_status
12640             ) ;
12641             -- If unexpected errors happen abort
12642             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12643                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
12644             END IF;
12645         END IF;
12646     END IF;
12647     -- Standard End of Procedure/Function Logging
12648     INL_LOGGING_PVT.Log_EndProc(
12649         p_module_name    => g_module_name,
12650         p_procedure_name => l_program_name
12651     );
12652     RETURN FND_API.to_boolean(l_result) ;
12653 EXCEPTION
12654 --Handling deadlock with proper error message
12655     WHEN RESOURCE_BUSY THEN
12656 
12657         SELECT m.group_id
12658         INTO l_group_id
12659         FROM inl_matches_int m
12660         WHERE m.match_int_id = p_match_int_id;
12661 
12662         x_return_status := FND_API.g_ret_sts_error;
12663         FND_MESSAGE.set_name('INL','INL_ERR_OI_CHK_LCK_SHIPMENT');
12664         FND_MESSAGE.set_token('GROUP_ID',l_group_id);
12665         FND_MSG_PUB.ADD;
12666 
12667         -- Standard Expected Error Logging
12668         INL_LOGGING_PVT.Log_ExpecError (
12669             p_module_name    => g_module_name,
12670             p_procedure_name => l_program_name);
12671         RETURN FND_API.to_boolean(L_FND_FALSE);
12672     WHEN L_FND_EXC_ERROR THEN
12673         -- Standard Expected Error Logging
12674         INL_LOGGING_PVT.Log_ExpecError (
12675             p_module_name    => g_module_name,
12676             p_procedure_name => l_program_name
12677         );
12678         RETURN FND_API.to_boolean(L_FND_FALSE) ;
12679     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
12680         -- Standard Unexpected Error Logging
12681         INL_LOGGING_PVT.Log_UnexpecError (
12682             p_module_name    => g_module_name,
12683             p_procedure_name => l_program_name
12684         );
12685         RETURN FND_API.to_boolean(L_FND_FALSE) ;
12686     WHEN OTHERS THEN
12687         -- Standard Unexpected Error Logging
12688         INL_LOGGING_PVT.Log_UnexpecError (
12689             p_module_name    => g_module_name,
12690             p_procedure_name => l_program_name
12691         );
12692         IF FND_MSG_PUB.Check_Msg_Level(
12693             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
12694         ) THEN
12695             FND_MSG_PUB.Add_Exc_Msg(
12696                 p_pkg_name       => g_pkg_name,
12697                 p_procedure_name => l_program_name
12698             );
12699         END IF;
12700         RETURN FND_API.to_boolean(L_FND_FALSE) ;
12701 END Validate_MatchElcOnGoing;
12702 --/ SCM-051 End
12703 
12704 -- Funct name : Validate_MatchUOM
12705 -- Type       : Private
12706 -- Function   : Validate a given UOM code used by the Matching Process
12707 --
12708 -- Pre-reqs   : None
12709 -- Parameters :
12710 -- IN         : p_match_int_id              IN NUMBER
12711 --              p_matched_uom_code          IN VARCHAR2
12712 --              p_match_type_code           IN VARCHAR2
12713 --              p_parent_match_type_code    IN VARCHAR2
12714 --
12715 -- IN OUT     : x_return_status      OUT NOCOPY VARCHAR2
12716 --
12717 -- Version    : Current version 1.0
12718 --
12719 -- Notes      :
12720 FUNCTION Validate_MatchUOM(
12721     p_match_int_id           IN NUMBER,
12722     p_matched_uom_code       IN VARCHAR2,
12723     p_match_type_code        IN VARCHAR2,
12724     p_parent_match_type_code IN VARCHAR2,
12725     x_return_status          OUT NOCOPY VARCHAR2
12726 )RETURN BOOLEAN IS
12727     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_MatchUOM';
12728     l_debug_info    VARCHAR2(400) ;
12729     l_return_status VARCHAR2(1) ;
12730     l_result        VARCHAR2(1) := L_FND_TRUE;
12731     l_uom           VARCHAR2(100) ;
12732 BEGIN
12733     -- Standard Beginning of Procedure/Function Logging
12734     INL_LOGGING_PVT.Log_BeginProc(
12735         p_module_name    => g_module_name,
12736         p_procedure_name => l_program_name
12737     ) ;
12738     --  Initialize API return status to success
12739     x_return_status := L_FND_RET_STS_SUCCESS;
12740     l_debug_info         := 'Validate the type of the corrected match in case of correction process.';
12741     INL_LOGGING_PVT.Log_Statement(
12742         p_module_name      => g_module_name,
12743         p_procedure_name   => l_program_name,
12744         p_debug_info       => l_debug_info
12745     );
12746     IF NVL(p_parent_match_type_code, p_match_type_code) = 'ITEM' THEN
12747         IF p_matched_uom_code IS NULL THEN
12748             l_result     := L_FND_FALSE;
12749             -- Add a line into inl_ship_errors
12750             Handle_InterfError(
12751                 p_parent_table_name  => 'INL_MATCHES_INT',
12752                 p_parent_table_id    => p_match_int_id,
12753                 p_column_name        => 'MATCHED_UOM_CODE',
12754                 p_column_value       => p_matched_uom_code,
12755                 p_error_message_name => 'INL_ERR_OI_CHK_UOM_NULL',
12756                 p_token1_name        => 'TYPE',
12757                 p_token1_value       => p_match_type_code,
12758                 p_token2_name        => 'MATCH_INT_ID',
12759                 p_token2_value       => p_match_int_id,
12760                 x_return_status      => l_return_status
12761             ) ;
12762             -- If unexpected errors happen abort
12763             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12764                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
12765             END IF;
12766         ELSE
12767             BEGIN
12768                 -- Get UOM Code
12769                 SELECT unit_of_measure
12770                 INTO l_uom
12771                 FROM mtl_units_of_measure
12772                 WHERE uom_code = p_matched_uom_code;
12773             EXCEPTION
12774             WHEN NO_DATA_FOUND THEN
12775                 l_result := L_FND_FALSE;
12776                 -- Add a line into inl_ship_errors
12777                 Handle_InterfError(
12778                     p_parent_table_name  => 'INL_MATCHES_INT',
12779                     p_parent_table_id    => p_match_int_id,
12780                     p_column_name        => 'MATCHED_UOM_CODE',
12781                     p_column_value       => p_matched_uom_code,
12782                     p_error_message_name => 'INL_ERR_OI_CHK_UOM_INV',
12783                     p_token1_name        => 'MATCH_INT_ID',
12784                     p_token1_value       => p_match_int_id,
12785                     x_return_status      => l_return_status
12786                 ) ;
12787                 -- If unexpected errors happen abort
12788                 IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12789                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
12790                 END IF;
12791             END;
12792         END IF;
12793     ELSE
12794         IF p_matched_uom_code IS NOT NULL THEN
12795             l_result := L_FND_FALSE;
12796             -- Add a line into inl_ship_errors
12797             Handle_InterfError(
12798                 p_parent_table_name  => 'INL_MATCHES_INT',
12799                 p_parent_table_id    => p_match_int_id,
12800                 p_column_name        => 'MATCHED_UOM_CODE',
12801                 p_column_value       => p_matched_uom_code,
12802                 p_error_message_name => 'INL_ERR_OI_CHK_UOM_NNULL',
12803                 p_token1_name        => 'TYPE',
12804                 p_token1_value       => p_match_type_code,
12805                 p_token2_name        => 'MATCH_INT_ID',
12806                 p_token2_value       => p_match_int_id,
12807                 x_return_status      => l_return_status
12808             ) ;
12809             -- If unexpected errors happen abort
12810             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12811                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
12812             END IF;
12813         END IF;
12814     END IF;
12815     -- Standard End of Procedure/Function Logging
12816     INL_LOGGING_PVT.Log_EndProc(
12817         p_module_name    => g_module_name,
12818         p_procedure_name => l_program_name
12819     );
12820     RETURN FND_API.to_boolean(l_result) ;
12821 EXCEPTION
12822     WHEN L_FND_EXC_ERROR THEN
12823         -- Standard Expected Error Logging
12824         INL_LOGGING_PVT.Log_ExpecError (
12825             p_module_name    => g_module_name,
12826             p_procedure_name => l_program_name
12827         );
12828         RETURN FND_API.to_boolean(L_FND_FALSE) ;
12829     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
12830         -- Standard Unexpected Error Logging
12831         INL_LOGGING_PVT.Log_UnexpecError (
12832             p_module_name    => g_module_name,
12833             p_procedure_name => l_program_name
12834         );
12835         RETURN FND_API.to_boolean(L_FND_FALSE) ;
12836     WHEN OTHERS THEN
12837         -- Standard Unexpected Error Logging
12838         INL_LOGGING_PVT.Log_UnexpecError (
12839             p_module_name    => g_module_name,
12840             p_procedure_name => l_program_name
12841         );
12842         IF FND_MSG_PUB.Check_Msg_Level(
12843             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
12844         ) THEN
12845             FND_MSG_PUB.Add_Exc_Msg(
12846                 p_pkg_name       => g_pkg_name,
12847                 p_procedure_name => l_program_name
12848             );
12849         END IF;
12850         RETURN FND_API.to_boolean(L_FND_FALSE) ;
12851 END Validate_MatchUOM;
12852 -- Funct name : Validate_MatchMatIDS
12853 -- Type       : Private
12854 -- Function   : Validate Match Id and Parent Match Id
12855 --
12856 -- Pre-reqs   : None
12857 -- Parameters :
12858 -- IN         : p_transaction_type IN VARCHAR2
12859 --              p_match_int_id     IN NUMBER
12860 --              p_match_id         IN NUMBER
12861 --              p_parent_match_id  IN NUMBER
12862 --              p_match_type_code  IN VARCHAR2
12863 --              p_existing_match_info_flag IN VARCHAR2
12864 --
12865 -- IN OUT     : x_return_status    IN OUT NOCOPY VARCHAR2
12866 --
12867 -- Version    : Current version 1.0
12868 --
12869 -- Notes      :
12870 FUNCTION Validate_MatchMatIDS(
12871     p_transaction_type         IN VARCHAR2,
12872     p_match_int_id             IN NUMBER,
12873     p_match_id                 IN NUMBER,
12874     p_parent_match_id          IN NUMBER,
12875     p_match_type_code          IN VARCHAR2,
12876     p_existing_match_info_flag IN VARCHAR2,
12877     x_return_status            OUT NOCOPY VARCHAR2
12878 ) RETURN BOOLEAN IS
12879     l_program_name        CONSTANT VARCHAR2(30) := 'Validate_MatchMatIDS';
12880     l_debug_info       VARCHAR2(400) ;
12881     l_return_status    VARCHAR2(1) ;
12882     l_result           VARCHAR2(1) := L_FND_TRUE;
12883     l_adj_alr_gen_flag VARCHAR2(1) ;
12884 BEGIN
12885     -- Standard Beginning of Procedure/Function Logging
12886     INL_LOGGING_PVT.Log_BeginProc(
12887         p_module_name    => g_module_name,
12888         p_procedure_name => l_program_name
12889     ) ;
12890     --  Initialize API return status to success
12891     x_return_status := L_FND_RET_STS_SUCCESS;
12892     l_debug_info := 'Check: When match type code is CORRECTION, parent_match_id cannot be null';
12893     INL_LOGGING_PVT.Log_Statement(
12894         p_module_name      => g_module_name,
12895         p_procedure_name   => l_program_name,
12896         p_debug_info       => l_debug_info
12897     );
12898     IF p_match_type_code = 'CORRECTION' THEN
12899         IF p_parent_match_id IS NULL THEN
12900             l_result := L_FND_FALSE;
12901             -- Add a line into inl_ship_errors
12902             Handle_InterfError(
12903                 p_parent_table_name  => 'INL_MATCHES_INT',
12904                 p_parent_table_id    => p_match_int_id,
12905                 p_column_name        => 'PARENT_MATCH_ID',
12906                 p_column_value       => p_parent_match_id,
12907                 p_error_message_name => 'INL_ERR_OI_CHK_MAT_ID_NULL',
12908                 p_token1_name        => 'OPER',
12909                 p_token1_value       => p_match_type_code,
12910                 p_token2_name        => 'COL',
12911                 p_token2_value       => 'PARENT_MATCH_ID',
12912                 p_token3_name        => 'MATCH_INT_ID',
12913                 p_token3_value       => p_match_int_id,
12914                 x_return_status      => l_return_status
12915             ) ;
12916             -- If unexpected errors happen abort
12917             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12918                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
12919             END IF;
12920         ELSE
12921             BEGIN
12922                  SELECT adj_already_generated_flag
12923                    INTO l_adj_alr_gen_flag
12924                    FROM inl_matches
12925                   WHERE match_id = p_parent_match_id;
12926             EXCEPTION
12927                 WHEN NO_DATA_FOUND THEN
12928                     l_result := L_FND_FALSE;
12929                     -- Add a line into inl_ship_errors
12930                     Handle_InterfError(
12931                         p_parent_table_name  => 'INL_MATCHES_INT',
12932                         p_parent_table_id    => p_match_int_id,
12933                         p_column_name        => 'PARENT_MATCH_ID',
12934                         p_column_value       => p_parent_match_id,
12935                         p_error_message_name => 'INL_ERR_OI_CHK_PAR_MAT_ID_NF',
12936                         p_token1_name        => 'COL_NAME',
12937                         p_token1_value       => 'PARENT_MATCH_ID',
12938                         p_token2_name        => 'COL_ID',
12939                         p_token2_value       => p_parent_match_id,
12940                         x_return_status      => l_return_status
12941                     ) ;
12942                     -- If unexpected errors happen abort
12943                     IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12944                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
12945                     END IF;
12946             END;
12947         END IF;
12948     ELSE -- p_match_type_code <> 'CORRECTION'
12949         IF p_parent_match_id IS NOT NULL AND p_existing_match_info_flag <> 'Y' THEN
12950             l_result := L_FND_FALSE;
12951             -- Add a line into inl_ship_errors
12952             Handle_InterfError(
12953                 p_parent_table_name  => 'INL_MATCHES_INT',
12954                 p_parent_table_id    => p_match_int_id,
12955                 p_column_name        => 'PARENT_MATCH_ID',
12956                 p_column_value       => p_parent_match_id,
12957                 p_error_message_name => 'INL_ERR_OI_CHK_MAT_ID_NNULL',
12958                 p_token1_name        => 'OPER',
12959                 p_token1_value       => p_match_type_code,
12960                 p_token2_name        => 'COL',
12961                 p_token2_value       => 'PARENT_MATCH_ID',
12962                 p_token3_name        => 'MATCH_INT_ID',
12963                 p_token3_value       => p_match_int_id,
12964                 x_return_status      => l_return_status
12965             ) ;
12966             -- If unexpected errors happen abort
12967             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12968                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
12969             END IF;
12970         END IF;
12971         IF p_transaction_type <> 'CREATE' THEN
12972             l_debug_info := 'Check: When transaction type is not CREATE, match_id cannot be null';
12973             INL_LOGGING_PVT.Log_Statement(
12974                 p_module_name      => g_module_name,
12975                 p_procedure_name   => l_program_name,
12976                 p_debug_info       => l_debug_info
12977             );
12978             IF p_match_id IS NULL THEN
12979                 l_result := L_FND_FALSE;
12980                 -- Add a line into inl_ship_errors
12981                 Handle_InterfError(
12982                     p_parent_table_name  => 'INL_MATCHES_INT',
12983                     p_parent_table_id    => p_match_int_id,
12984                     p_column_name        => 'MATCH_ID',
12985                     p_column_value       => p_match_id,
12986                     p_error_message_name => 'INL_ERR_OI_CHK_MAT_ID_NULL',
12987                     p_token1_name        => 'OPER',
12988                     p_token1_value       => p_transaction_type,
12989                     p_token2_name        => 'COL',
12990                     p_token2_value       => 'MATCH_ID',
12991                     p_token3_name        => 'MATCH_INT_ID',
12992                     p_token3_value       => p_match_int_id,
12993                     x_return_status      => l_return_status
12994                 ) ;
12995                 -- If unexpected errors happen abort
12996                 IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
12997                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
12998                 END IF;
12999             ELSE
13000                 BEGIN
13001                      SELECT adj_already_generated_flag
13002                        INTO l_adj_alr_gen_flag
13003                        FROM inl_matches
13004                       WHERE match_id = p_match_id;
13005                     IF l_adj_alr_gen_flag <> 'N' THEN
13006                         l_result := L_FND_FALSE;
13007                         -- Add a line into inl_ship_errors
13008                         Handle_InterfError(
13009                             p_parent_table_name  => 'INL_MATCHES_INT',
13010                             p_parent_table_id    => p_match_int_id,
13011                             p_column_name        => 'MATCH_ID',
13012                             p_column_value       => p_match_id,
13013                             p_error_message_name => 'INL_ERR_OI_CHK_MAT_ADJUSTED',
13014                             p_token1_name        => 'MATCH_INT_ID',
13015                             p_token1_value       => p_match_int_id,
13016                             x_return_status      => l_return_status
13017                         ) ;
13018                         -- If unexpected errors happen abort
13019                         IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13020                             RAISE L_FND_EXC_UNEXPECTED_ERROR;
13021                         END IF;
13022                     END IF;
13023                 EXCEPTION
13024                 WHEN NO_DATA_FOUND THEN
13025                     l_result := L_FND_FALSE;
13026                     -- Add a line into inl_ship_errors
13027                     Handle_InterfError(
13028                         p_parent_table_name  => 'INL_MATCHES_INT',
13029                         p_parent_table_id    => p_match_int_id,
13030                         p_column_name        => 'MATCH_ID',
13031                         p_column_value       => p_match_id,
13032                         p_error_message_name => 'INL_ERR_OI_CHK_MAT_ID_NF',
13033                         p_token1_name        => 'COL_NAME',
13034                         p_token1_value       => 'MATCH_ID',
13035                         p_token2_name        => 'COL_ID',
13036                         p_token2_value       => p_match_id,
13037                         p_token3_name        => 'MATCH_INT_ID',
13038                         p_token3_value       => p_match_int_id,
13039                         x_return_status      => l_return_status
13040                     ) ;
13041                     -- If unexpected errors happen abort
13042                     IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13043                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
13044                     END IF;
13045                 END;
13046             END IF;
13047         END IF;
13048     END IF;
13049     -- Standard End of Procedure/Function Logging
13050     INL_LOGGING_PVT.Log_EndProc(
13051         p_module_name    => g_module_name,
13052         p_procedure_name => l_program_name
13053     );
13054     RETURN FND_API.to_boolean(l_result) ;
13055 EXCEPTION
13056     WHEN L_FND_EXC_ERROR THEN
13057         -- Standard Expected Error Logging
13058         INL_LOGGING_PVT.Log_ExpecError (
13059             p_module_name    => g_module_name,
13060             p_procedure_name => l_program_name
13061         );
13062         RETURN FND_API.to_boolean(L_FND_FALSE) ;
13063     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
13064         -- Standard Unexpected Error Logging
13065         INL_LOGGING_PVT.Log_UnexpecError (
13066             p_module_name    => g_module_name,
13067             p_procedure_name => l_program_name
13068         );
13069         RETURN FND_API.to_boolean(L_FND_FALSE) ;
13070     WHEN OTHERS THEN
13071       -- Standard Unexpected Error Logging
13072         INL_LOGGING_PVT.Log_UnexpecError (
13073             p_module_name    => g_module_name,
13074             p_procedure_name => l_program_name
13075         );
13076         IF FND_MSG_PUB.Check_Msg_Level(
13077             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
13078         ) THEN
13079             FND_MSG_PUB.Add_Exc_Msg(
13080                 p_pkg_name       => g_pkg_name,
13081                 p_procedure_name => l_program_name
13082             );
13083         END IF;
13084         RETURN FND_API.to_boolean(L_FND_FALSE) ;
13085 END Validate_MatchMatIDS;
13086 -- Funct name : Validate_MatchToParTab
13087 -- Type       : Private
13088 -- Function   : Validate Match To_Parent values
13089 --
13090 -- Pre-reqs   : None
13091 -- Parameters :
13092 -- IN         : p_transaction_type      IN VARCHAR2
13093 --              p_match_int_id          IN NUMBER
13094 --              p_match_id              IN NUMBER
13095 --              p_parent_match_id       IN NUMBER
13096 --              p_ship_header_id        IN NUMBER
13097 --              p_to_parent_table_name  IN VARCHAR2
13098 --              p_to_parent_table_id    IN NUMBER
13099 --              p_match_type_code       IN VARCHAR2
13100 --
13101 -- IN OUT     : x_return_status         OUT NOCOPY VARCHAR2
13102 --
13103 -- Version    : Current version 1.0
13104 --
13105 -- Notes      :
13106 FUNCTION Validate_MatchToParTab(
13107     p_transaction_type     IN VARCHAR2,
13108     p_match_int_id         IN NUMBER,
13109     p_match_id             IN NUMBER,
13110     p_parent_match_id      IN NUMBER,
13111     p_ship_header_id       IN NUMBER,
13112     p_to_parent_table_name IN VARCHAR2,
13113     p_to_parent_table_id   IN NUMBER,
13114     p_match_type_code      IN VARCHAR2,
13115     x_return_status        OUT NOCOPY VARCHAR2
13116 ) RETURN BOOLEAN IS
13117     l_program_name      CONSTANT VARCHAR2(30) := 'Validate_MatchToParTab';
13118     l_debug_info     VARCHAR2(400) ;
13119     l_return_status  VARCHAR2(1) ;
13120     l_result         VARCHAR2(1) := L_FND_TRUE;
13121     l_ship_header_id NUMBER;
13122     l_ship_line_id NUMBER;
13123     l_ship_header_id_tab inl_int_table := inl_int_table() ;
13124     l_nameOk         VARCHAR2(1) ;
13125     l_idOk           VARCHAR2(1) ;
13126     l_SHidOk         VARCHAR2(1) ;
13127     l_INT_importedOk VARCHAR2(1) ;
13128     l_matchTpCdOk    VARCHAR2(1) ;
13129 BEGIN
13130     -- Standard Beginning of Procedure/Function Logging
13131     INL_LOGGING_PVT.Log_BeginProc(
13132         p_module_name    => g_module_name,
13133         p_procedure_name => l_program_name
13134     ) ;
13135     --  Initialize API return status to success
13136     x_return_status                             := L_FND_RET_STS_SUCCESS;
13137     l_debug_info := 'Check to_parent_table value and all related information.';
13138     INL_LOGGING_PVT.Log_Statement(
13139         p_module_name      => g_module_name,
13140         p_procedure_name   => l_program_name,
13141         p_debug_info       => l_debug_info
13142     );
13143     l_nameOk          := 'N';
13144     l_idOk            := 'N';
13145     l_SHidOk          := 'N';
13146     l_matchTpCdOk     := 'N';
13147     l_INT_importedOk  := 'N';
13148     INL_LOGGING_PVT.Log_Variable(
13149         p_module_name    => g_module_name,
13150         p_procedure_name => l_program_name,
13151         p_var_name       => 'p_to_parent_table_name',
13152         p_var_value      => p_to_parent_table_name
13153     ) ;
13154 
13155     INL_LOGGING_PVT.Log_Variable(
13156         p_module_name    => g_module_name,
13157         p_procedure_name => l_program_name,
13158         p_var_name       => 'p_to_parent_table_id',
13159         p_var_value      => p_to_parent_table_id
13160     ) ;
13161 
13162     INL_LOGGING_PVT.Log_Variable(
13163         p_module_name    => g_module_name,
13164         p_procedure_name => l_program_name,
13165         p_var_name       => 'p_transaction_type',
13166         p_var_value      => p_transaction_type
13167     ) ;
13168 
13169     INL_LOGGING_PVT.Log_Variable(
13170         p_module_name    => g_module_name,
13171         p_procedure_name => l_program_name,
13172         p_var_name       => 'p_match_type_code',
13173         p_var_value      => p_match_type_code
13174     ) ;
13175 
13176     IF p_to_parent_table_name IN('INL_SHIP_HEADERS',
13177                                  'INL_SHIP_LINES',
13178                                  'INL_SHIP_LINE_GROUPS',
13179                                  'INL_CHARGE_LINES',
13180                                  'INL_TAX_LINES',
13181                                  'RCV_TRANSACTIONS'
13182                                  )
13183     OR (p_transaction_type = 'CREATE'
13184         AND p_to_parent_table_name IN('INL_SHIP_LINES_INT',
13185                                       'INL_SHIP_HEADERS_INT')
13186        )
13187     OR(p_match_type_code = 'CORRECTION'
13188        AND p_to_parent_table_name IN('AP_INVOICE_DISTRIBUTIONS')
13189       )
13190     THEN
13191         l_nameOk := 'Y';
13192         BEGIN
13193             IF p_to_parent_table_name = 'INL_SHIP_HEADERS' THEN
13194 
13195                 l_INT_importedOk     := 'Y';
13196                 SELECT ship_header_id
13197                 INTO l_ship_header_id
13198                 FROM inl_ship_headers_all --Bug#10381495
13199                 WHERE ship_header_id = p_to_parent_table_id;
13200                 IF p_match_type_code   = 'CHARGE' THEN
13201                     l_matchTpCdOk     := 'Y';
13202                 END IF;
13203             ELSIF p_to_parent_table_name = 'INL_SHIP_LINES' THEN
13204                 l_INT_importedOk        := 'Y';
13205                 SELECT ship_header_id
13206                 INTO l_ship_header_id
13207                 FROM inl_ship_lines_all --Bug#10381495
13208                 WHERE ship_line_id  = p_to_parent_table_id;
13209                 IF p_match_type_code IN('ITEM', 'CHARGE', 'TAX') THEN
13210                     l_matchTpCdOk    := 'Y';
13211                 END IF;
13212             ELSIF p_to_parent_table_name = 'INL_SHIP_LINE_GROUPS' THEN
13213                 l_INT_importedOk        := 'Y';
13214                 SELECT ship_header_id
13215                 INTO l_ship_header_id
13216                 FROM inl_ship_line_groups
13217                 WHERE ship_line_group_id = p_to_parent_table_id;
13218                 IF p_match_type_code       = 'CHARGE' THEN
13219                     l_matchTpCdOk         := 'Y';
13220                 END IF;
13221             ELSIF p_to_parent_table_name = 'INL_CHARGE_LINES' THEN
13222                 l_INT_importedOk        := 'Y';
13223                 l_ship_header_id_tab.DELETE;
13224                 SELECT DISTINCT(a.ship_header_id)
13225                 BULK COLLECT INTO l_ship_header_id_tab
13226                 FROM inl_charge_lines c,
13227                 inl_associations a
13228                 WHERE c.charge_line_id              = p_to_parent_table_id
13229                 AND a.from_parent_table_name      = 'INL_CHARGE_LINES'
13230                 AND a.from_parent_table_id        = c.charge_line_id;
13231                 IF NVL(l_ship_header_id_tab.COUNT, 0) = 1 THEN
13232                     l_ship_header_id                 := l_ship_header_id_tab(1) ;
13233                 END IF;
13234                 IF p_match_type_code IN('CHARGE', 'TAX') THEN
13235                     l_matchTpCdOk    := 'Y';
13236                 END IF;
13237             ELSIF p_to_parent_table_name = 'INL_TAX_LINES' THEN
13238                 l_INT_importedOk        := 'Y';
13239                 SELECT ship_header_id
13240                 INTO l_ship_header_id
13241                 FROM inl_tax_lines
13242                 WHERE tax_line_id   = p_to_parent_table_id;
13243                 IF p_match_type_code IN('TAX') THEN
13244                     l_matchTpCdOk    := 'Y';
13245                 END IF;
13246             ELSIF p_to_parent_table_name = 'INL_SHIP_LINES_INT' THEN
13247 --Bug#9660043
13248                 IF p_match_type_code IN('ITEM', 'CHARGE', 'TAX') THEN
13249                     l_matchTpCdOk       := 'Y';
13250                 END IF;
13251 
13252                 SELECT
13253                     NVL(sl.ship_header_id, sli.ship_header_id),
13254                     DECODE(sl.ship_header_id, NULL, 'N', 'Y')
13255                 INTO
13256                     l_ship_header_id,
13257                     l_INT_importedOk
13258                 FROM
13259                     inl_ship_lines_int sli,
13260                     inl_ship_lines_all sl --Bug#10381495
13261                 WHERE
13262                     sli.ship_line_int_id = p_to_parent_table_id
13263                 AND sl.ship_line_int_id  = p_to_parent_table_id;
13264 --Bug#9660043
13265 
13266 /* --Bug#9660043
13267                 SELECT sli.ship_header_id
13268                 INTO l_ship_header_id
13269                 FROM inl_ship_lines_int sli
13270                 WHERE sli.ship_line_int_id = p_to_parent_table_id;
13271                 IF p_match_type_code IN('ITEM', 'CHARGE', 'TAX') THEN
13272                     l_matchTpCdOk       := 'Y';
13273                 END IF;
13274                 -- Check if the Interface has been imported
13275                 SELECT sl.ship_header_id
13276                 INTO l_ship_header_id
13277                 FROM inl_ship_lines sl
13278                 WHERE sl.ship_line_int_id = p_to_parent_table_id;
13279                 l_INT_importedOk        := 'Y';
13280 */--Bug#9660043
13281 
13282             ELSIF p_to_parent_table_name = 'INL_SHIP_HEADERS_INT' THEN
13283 --Bug#9660043
13284                 IF p_match_type_code      IN('CHARGE') THEN
13285                     l_matchTpCdOk         := 'Y';
13286                 END IF;
13287 
13288                 SELECT
13289                     NVL(sh.ship_header_id, shi.ship_header_id),
13290                     DECODE(sh.ship_header_id, NULL, 'N', 'Y')
13291                 INTO
13292                     l_ship_header_id,
13293                     l_INT_importedOk
13294                 FROM
13295                     inl_ship_headers_int shi,
13296                     inl_ship_headers_all sh --Bug#10381495
13297                 WHERE
13298                     shi.ship_header_int_id   = p_to_parent_table_id
13299                 AND sh.ship_header_int_id    = p_to_parent_table_id
13300                 ;
13301 --Bug#9660043
13302 /*--Bug#9660043
13303                 SELECT shi.ship_header_id
13304                 INTO l_ship_header_id
13305                 FROM inl_ship_headers_int shi
13306                 WHERE shi.ship_header_int_id = p_to_parent_table_id;
13307 
13308                 IF p_match_type_code      IN('CHARGE') THEN
13309                     l_matchTpCdOk         := 'Y';
13310                 END IF;
13311 
13312                 -- Check if the Interface record has been imported
13313                 SELECT sh.ship_header_id
13314                 INTO l_ship_header_id
13315                 FROM inl_ship_headers sh
13316                 WHERE sh.ship_header_int_id = p_to_parent_table_id;
13317                 l_INT_importedOk := 'Y';
13318 */--Bug#9660043
13319 
13320             ELSIF p_to_parent_table_name = 'RCV_TRANSACTIONS' THEN
13321 --Bug#9660043
13322                 l_INT_importedOk        := 'Y';
13323 
13324                 IF p_match_type_code IN('ITEM', 'CHARGE', 'TAX') THEN
13325                     l_matchTpCdOk    := 'Y';
13326                 END IF;
13327 
13328                 SELECT
13329                     rt.lcm_shipment_line_id,
13330                     sl.ship_header_id
13331                 INTO
13332                     l_ship_line_id,
13333                     l_ship_header_id
13334                 FROM
13335                     rcv_transactions rt,
13336                     inl_ship_lines_all sl --Bug#10381495
13337                 WHERE
13338                     rt.transaction_id = p_to_parent_table_id
13339                 AND sl.ship_line_id   = rt.lcm_shipment_line_id
13340                 ;
13341 --Bug#9660043
13342 /*--Bug#9660043
13343                 SELECT  lcm_shipment_line_id
13344                 INTO l_ship_line_id
13345                 FROM rcv_transactions rt
13346                 WHERE rt.transaction_id = p_to_parent_table_id;
13347 
13348                SELECT sl.ship_header_id
13349                 INTO l_ship_header_id
13350                 FROM inl_ship_lines sl
13351                 WHERE sl.ship_line_id  = l_ship_line_id;
13352                 IF p_match_type_code IN('ITEM', 'CHARGE', 'TAX') THEN
13353                     l_matchTpCdOk    := 'Y';
13354                 END IF;
13355 */--Bug#9660043
13356             ELSE -- In case of correction, the table is out of LCM limit
13357                 l_idOk           := 'Y';
13358                 l_INT_importedOk := 'Y';
13359                 SELECT ship_header_id
13360                 INTO l_ship_header_id
13361                 FROM inl_matches
13362                 WHERE match_id     = p_parent_match_id;
13363                 IF p_match_type_code = 'CORRECTION' THEN
13364                     l_matchTpCdOk   := 'Y';
13365                 END IF;
13366             END IF;
13367             l_idOk              := 'Y';
13368             IF p_ship_header_id IS NULL OR l_ship_header_id = p_ship_header_id THEN
13369                 l_SHidOk        := 'Y';
13370             END IF;
13371         EXCEPTION
13372         WHEN NO_DATA_FOUND THEN
13373             NULL;
13374         END;
13375     END IF;
13376     IF(l_nameOk  = 'N') THEN
13377         l_result := L_FND_FALSE;
13378         -- Add a line into inl_ship_errors
13379         Handle_InterfError(
13380             p_parent_table_name  => 'INL_MATCHES_INT',
13381             p_parent_table_id    => p_match_int_id,
13382             p_column_name        => 'TO_PARENT_TABLE_NAME',
13383             p_column_value       => p_to_parent_table_name,
13384             p_error_message_name => 'INL_ERR_OI_CHK_TO_PAR_TAB_NAME',
13385             p_token1_name        => 'NAME',
13386             p_token1_value       => 'INL_MATCHES_INT',
13387             p_token2_name        => 'ID',
13388             p_token2_value       => p_match_int_id,
13389             x_return_status      => l_return_status
13390         ) ;
13391         -- If unexpected errors happen abort
13392 
13393         IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13394             RAISE L_FND_EXC_UNEXPECTED_ERROR;
13395         END IF;
13396     ELSIF(l_idOk = 'N') THEN
13397         l_result := L_FND_FALSE;
13398         -- Add a line into inl_ship_errors
13399         Handle_InterfError(
13400             p_parent_table_name  => 'INL_MATCHES_INT',
13401             p_parent_table_id    => p_match_int_id,
13402             p_column_name        => 'TO_PARENT_TABLE_NAME',
13403             p_column_value       => p_to_parent_table_name,
13404             p_error_message_name => 'INL_ERR_OI_CHK_TO_PAR_TAB_ID',
13405             p_token1_name        => 'NAME',
13406             p_token1_value       => 'INL_MATCHES_INT',
13407             p_token2_name        => 'ID',
13408             p_token2_value       => p_match_int_id,
13409             x_return_status      => l_return_status
13410         ) ;
13411         -- If unexpected errors happen abort
13412         IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13413             RAISE L_FND_EXC_UNEXPECTED_ERROR;
13414         END IF;
13415     ELSE
13416         IF(l_SHidOk  = 'N') THEN
13417             l_result := L_FND_FALSE;
13418             -- Add a line into inl_ship_errors
13419             Handle_InterfError(
13420                 p_parent_table_name  => 'INL_MATCHES_INT',
13421                 p_parent_table_id    => p_match_int_id,
13422                 p_column_name        => 'SHIP_HEADER_ID',
13423                 p_column_value       => p_ship_header_id,
13424                 p_error_message_name => 'INL_ERR_OI_CHK_SHIP_HEADER_ID',
13425                 p_token1_name        => 'NAME',
13426                 p_token1_value       => 'INL_MATCHES_INT',
13427                 p_token2_name        => 'ID',
13428                 p_token2_value       => p_match_int_id,
13429                 x_return_status      => l_return_status) ;
13430             -- If unexpected errors happen abort
13431             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13432                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
13433             END IF;
13434         END IF;
13435         IF(l_matchTpCdOk = 'N') THEN
13436             l_result     := L_FND_FALSE;
13437             -- Add a line into inl_ship_errors
13438             Handle_InterfError(
13439                 p_parent_table_name  => 'INL_MATCHES_INT',
13440                 p_parent_table_id    => p_match_int_id,
13441                 p_column_name        => 'MATCH_TYPE_CODE',
13442                 p_column_value       => p_match_type_code,
13443                 p_error_message_name => 'INL_ERR_OI_CHK_MATCH_TP_CD',
13444                 p_token1_name        => 'NAME',
13445                 p_token1_value       => 'INL_MATCHES_INT',
13446                 p_token2_name        => 'ID',
13447                 p_token2_value       => p_match_int_id,
13448                 x_return_status      => l_return_status
13449             ) ;
13450             -- If unexpected errors happen abort
13451             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13452                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
13453             END IF;
13454         END IF;
13455         IF(l_INT_importedOk = 'N') THEN
13456             l_result        := L_FND_FALSE;
13457             -- Add a line into inl_ship_errors
13458             Handle_InterfError(
13459                 p_parent_table_name  => 'INL_MATCHES_INT',
13460                 p_parent_table_id    => p_match_int_id,
13461                 p_column_name        => 'MATCH_TYPE_CODE',
13462                 p_column_value       => p_match_type_code,
13463                 p_error_message_name => 'INL_ERR_OI_CHK_TO_PAR_TAB_ID2',
13464                 p_token1_name        => 'NAME',
13465                 p_token1_value       => p_to_parent_table_name,
13466                 p_token2_name        => 'ID',
13467                 p_token2_value       => p_to_parent_table_id,
13468                 p_token3_name        => 'MATCH_INT_ID',
13469                 p_token3_value       => p_match_int_id,
13470                 x_return_status      => l_return_status
13471             ) ;
13472             -- If unexpected errors happen abort
13473             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13474                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
13475             END IF;
13476         END IF;
13477     END IF;
13478     -- Standard End of Procedure/Function Logging
13479     INL_LOGGING_PVT.Log_EndProc(
13480         p_module_name    => g_module_name,
13481         p_procedure_name => l_program_name
13482     );
13483     RETURN FND_API.to_boolean(l_result) ;
13484 EXCEPTION
13485     WHEN L_FND_EXC_ERROR THEN
13486         -- Standard Expected Error Logging
13487         INL_LOGGING_PVT.Log_ExpecError (
13488             p_module_name    => g_module_name,
13489             p_procedure_name => l_program_name
13490         );
13491         RETURN FND_API.to_boolean(L_FND_FALSE) ;
13492     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
13493         -- Standard Unexpected Error Logging
13494         INL_LOGGING_PVT.Log_UnexpecError (
13495             p_module_name    => g_module_name,
13496             p_procedure_name => l_program_name
13497         );
13498         RETURN FND_API.to_boolean(L_FND_FALSE) ;
13499     WHEN OTHERS THEN
13500         -- Standard Unexpected Error Logging
13501         INL_LOGGING_PVT.Log_UnexpecError (
13502             p_module_name    => g_module_name,
13503             p_procedure_name => l_program_name
13504         );
13505         IF FND_MSG_PUB.Check_Msg_Level(
13506             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
13507         ) THEN
13508             FND_MSG_PUB.Add_Exc_Msg(
13509                 p_pkg_name       => g_pkg_name,
13510                 p_procedure_name => l_program_name
13511             );
13512         END IF;
13513         RETURN FND_API.to_boolean(L_FND_FALSE) ;
13514 END Validate_MatchToParTab;
13515 -- Funct name : Validate_MatchTrxType
13516 -- Type       : Private
13517 -- Function   : Validate Match Transaction Type
13518 --
13519 -- Pre-reqs   : None
13520 -- Parameters :
13521 -- IN         : p_transaction_type       IN VARCHAR2
13522 --              p_match_int_id           IN NUMBER
13523 --              p_to_parent_table_name   IN VARCHAR2
13524 --              p_to_parent_table_id     IN NUMBER
13525 --              p_match_id               IN NUMBER
13526 --              p_replace_estim_qty_flag IN VARCHAR2
13527 --
13528 -- OUT        : x_return_status          OUT NOCOPY VARCHAR2
13529 --
13530 -- Version    : Current version 1.0
13531 --
13532 -- Notes      :
13533 FUNCTION Validate_MatchTrxType(
13534     p_transaction_type       IN VARCHAR2,
13535     p_match_int_id           IN NUMBER,
13536     p_to_parent_table_name   IN VARCHAR2,
13537     p_to_parent_table_id     IN NUMBER,
13538     p_match_id               IN NUMBER,
13539     p_replace_estim_qty_flag IN VARCHAR2,
13540     x_return_status          OUT NOCOPY VARCHAR2
13541 ) RETURN BOOLEAN IS
13542     l_program_name                  CONSTANT VARCHAR2(30) := 'Validate_MatchTrxType';
13543     l_debug_info                 VARCHAR2(400) ;
13544     l_return_status              VARCHAR2(1) ;
13545     l_result                     VARCHAR2(1) := L_FND_TRUE;
13546     l_adj_already_generated_flag VARCHAR2(1) ;
13547     l_replace_estim_qty_flag     VARCHAR2(1) ;
13548     l_other_REQF_Y_match_id      NUMBER;
13549 BEGIN
13550     -- Standard Beginning of Procedure/Function Logging
13551     INL_LOGGING_PVT.Log_BeginProc(
13552         p_module_name    => g_module_name,
13553         p_procedure_name => l_program_name
13554     ) ;
13555     --  Initialize API return status to success
13556     x_return_status := L_FND_RET_STS_SUCCESS;
13557     INL_LOGGING_PVT.Log_Variable(
13558         p_module_name    => g_module_name,
13559         p_procedure_name => l_program_name,
13560         p_var_name       => 'p_transaction_type',
13561         p_var_value      => p_transaction_type
13562     ) ;
13563 
13564     IF p_transaction_type = 'CREATE' THEN
13565         IF p_match_id IS NOT NULL THEN
13566             l_result := L_FND_FALSE;
13567             -- Add a line into inl_ship_errors
13568             Handle_InterfError(
13569                 p_parent_table_name  => 'INL_MATCHES_INT',
13570                 p_parent_table_id    => p_match_int_id,
13571                 p_column_name        => 'MATCH_ID',
13572                 p_column_value       => p_match_id,
13573                 p_error_message_name => 'INL_ERR_OI_CHK_MAT_ID_NNULL',
13574                 p_token1_name        => 'OPER',
13575                 p_token1_value       => p_transaction_type,
13576                 p_token2_name        => 'COL',
13577                 p_token2_value       => 'MATCH_ID',
13578                 p_token3_name        => 'MATCH_INT_ID',
13579                 p_token3_value       => p_match_int_id,
13580                 x_return_status      => l_return_status) ;
13581             -- If unexpected errors happen abort
13582             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13583                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
13584             END IF;
13585         END IF;
13586     ELSIF p_transaction_type IN('UPDATE', 'DELETE') THEN
13587         IF p_match_id IS NULL THEN
13588             l_result := L_FND_FALSE;
13589             -- Add a line into inl_ship_errors
13590             Handle_InterfError(
13591                 p_parent_table_name  => 'INL_MATCHES_INT',
13592                 p_parent_table_id    => p_match_int_id,
13593                 p_column_name        => 'MATCH_ID',
13594                 p_column_value       => p_match_id,
13595                 p_error_message_name => 'INL_ERR_OI_CHK_TRX_TP_ID_NULL',
13596                 p_token1_name        => 'COLUMN',
13597                 p_token1_value       => 'MATCH_ID',
13598                 p_token2_name        => 'ID_NAME',
13599                 p_token2_value       => 'MATCH_INT_ID',
13600                 p_token3_name        => 'ID_VAL',
13601                 p_token3_value       => p_match_int_id,
13602                 x_return_status      => l_return_status
13603             ) ;
13604             -- If unexpected errors happen abort
13605             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13606                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
13607             END IF;
13608         ELSE
13609             SELECT adj_already_generated_flag,
13610             replace_estim_qty_flag
13611             INTO l_adj_already_generated_flag,
13612             l_replace_estim_qty_flag
13613             FROM inl_matches m
13614             WHERE m.match_id = p_match_id;
13615 
13616             INL_LOGGING_PVT.Log_Variable(
13617                 p_module_name    => g_module_name,
13618                 p_procedure_name => l_program_name,
13619                 p_var_name       => 'l_adj_already_generated_flag',
13620                 p_var_value      => l_adj_already_generated_flag
13621             ) ;
13622 
13623             IF l_adj_already_generated_flag = 'Y' THEN
13624                 l_debug_info := 'Matches that has adjustments already generated, cannot be changed.';
13625                 INL_LOGGING_PVT.Log_Statement(
13626                     p_module_name      => g_module_name,
13627                     p_procedure_name   => l_program_name,
13628                     p_debug_info       => l_debug_info
13629                 );
13630                 l_result := L_FND_FALSE;
13631                 -- Add a line into inl_ship_errors
13632                 Handle_InterfError(
13633                     p_parent_table_name  => 'INL_MATCHES_INT',
13634                     p_parent_table_id    => p_match_int_id,
13635                     p_column_name        => 'TRANSACTION_TYPE',
13636                     p_column_value       => p_transaction_type,
13637                     p_error_message_name => 'INL_ERR_OI_CHK_PROC_MAT_INVL',
13638                     p_token1_name        => 'MATCH_INT_ID',
13639                     p_token1_value       => p_match_int_id,
13640                     x_return_status      => l_return_status
13641                 ) ;
13642                 -- If unexpected errors happen abort
13643                 IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13644                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
13645                 END IF;
13646             END IF;
13647             IF p_replace_estim_qty_flag <> l_replace_estim_qty_flag THEN
13648                 l_debug_info := 'Matches that has adjustments already generated, cannot be changed.';
13649                 INL_LOGGING_PVT.Log_Statement(
13650                     p_module_name      => g_module_name,
13651                     p_procedure_name   => l_program_name,
13652                     p_debug_info       => l_debug_info
13653                 );
13654                 l_result := L_FND_FALSE;
13655                 -- Add a line into inl_ship_errors
13656                 Handle_InterfError(
13657                     p_parent_table_name  => 'INL_MATCHES_INT',
13658                     p_parent_table_id    => p_match_int_id,
13659                     p_column_name        => 'REPLACE_ESTIM_QTY_FLAG',
13660                     p_column_value       => p_replace_estim_qty_flag,
13661                     p_error_message_name => 'INL_ERR_OI_CHK_TRX_TP_INVL',
13662                     p_token1_name        => 'MATCH_INT_ID',
13663                     p_token1_value       => p_match_int_id,
13664                     x_return_status      => l_return_status
13665                 ) ;
13666                 -- If unexpected errors happen abort
13667                 IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13668                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
13669                 END IF;
13670             END IF;
13671             INL_LOGGING_PVT.Log_Variable(
13672                 p_module_name    => g_module_name,
13673                 p_procedure_name => l_program_name,
13674                 p_var_name       => 'l_replace_estim_qty_flag',
13675                 p_var_value      => l_replace_estim_qty_flag
13676             ) ;
13677             IF l_replace_estim_qty_flag                 = 'Y' THEN
13678                 -- Check if there is any new record as
13679                 -- replace_estim_qty_flag = 'Y' and adj_already_generated_flag = 'N'
13680                 BEGIN
13681                     SELECT m1.match_id
13682                     INTO l_other_REQF_Y_match_id
13683                     FROM inl_matches m1
13684                     WHERE m1.to_parent_table_name       = p_to_parent_table_name
13685                     AND m1.to_parent_table_id         = p_to_parent_table_id
13686                     AND m1.match_type_code            = 'ITEM'
13687                     AND m1.replace_estim_qty_flag     = 'Y'
13688                     AND m1.adj_already_generated_flag = 'N'
13689                     --For validation purpose, it will consider only the latest and not processed record
13690                     AND m1.match_id IN (SELECT MAX(m2.match_id)
13691                                         FROM inl_matches m2
13692                                         WHERE m2.to_parent_table_name       = m1.to_parent_table_name
13693                                          AND m2.to_parent_table_id         = m1.to_parent_table_id
13694                                          AND m2.match_type_code            = 'ITEM'
13695                                          AND m2.replace_estim_qty_flag     = 'Y'
13696                                          AND m2.adj_already_generated_flag = 'N'
13697                                         )
13698                     ;
13699                 EXCEPTION
13700                     WHEN NO_DATA_FOUND THEN
13701                         l_other_REQF_Y_match_id := 0;
13702                 END;
13703                 INL_LOGGING_PVT.Log_Variable(
13704                     p_module_name    => g_module_name,
13705                     p_procedure_name => l_program_name,
13706                     p_var_name       => 'p_match_id',
13707                     p_var_value      => p_match_id
13708                 ) ;
13709 
13710                 INL_LOGGING_PVT.Log_Variable(
13711                     p_module_name    => g_module_name,
13712                     p_procedure_name => l_program_name,
13713                     p_var_name       => 'l_other_REQF_Y_match_id',
13714                     p_var_value      => l_other_REQF_Y_match_id
13715                 ) ;
13716 
13717                 IF p_match_id < l_other_REQF_Y_match_id THEN
13718                     l_result := L_FND_FALSE;
13719                     -- Add a line into inl_ship_errors
13720                     Handle_InterfError(
13721                         p_parent_table_name  => 'INL_MATCHES_INT',
13722                         p_parent_table_id    => p_match_int_id,
13723                         p_column_name        => 'TRANSACTION_TYPE',
13724                         p_column_value       => p_transaction_type,
13725                         p_error_message_name => 'INL_ERR_OI_CHK_MAT_NO_EFFECT',
13726                         p_token1_name        => 'MATCH_INT_ID',
13727                         p_token1_value       => p_match_int_id,
13728                         x_return_status      => l_return_status
13729                     ) ;
13730                     -- If unexpected errors happen abort
13731                     IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13732                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
13733                     END IF;
13734                 END IF;
13735             END IF;
13736         END IF;
13737     ELSE
13738         l_result := L_FND_FALSE;
13739         -- Add a line into inl_ship_errors
13740         Handle_InterfError(
13741             p_parent_table_name  => 'INL_MATCHES_INT',
13742             p_parent_table_id    => p_match_int_id,
13743             p_column_name        => 'TRANSACTION_TYPE',
13744             p_column_value       => p_transaction_type,
13745             p_error_message_name => 'INL_ERR_OI_CHK_TRX_TP_INVL',
13746             p_token1_name        => 'TTYPE',
13747             p_token1_value       => p_transaction_type,
13748             p_token2_name        => 'ID_NAME',
13749             p_token2_value       => 'MATCH_INT_ID',
13750             p_token3_name        => 'ID_VAL',
13751             p_token3_value       => p_match_int_id,
13752             x_return_status      => l_return_status
13753         ) ;
13754         -- If unexpected errors happen abort
13755         IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13756             RAISE L_FND_EXC_UNEXPECTED_ERROR;
13757         END IF;
13758     END IF;
13759     -- Standard End of Procedure/Function Logging
13760     INL_LOGGING_PVT.Log_EndProc(
13761         p_module_name    => g_module_name,
13762         p_procedure_name => l_program_name
13763     );
13764     RETURN FND_API.to_boolean(l_result) ;
13765 EXCEPTION
13766     WHEN L_FND_EXC_ERROR THEN
13767         -- Standard Expected Error Logging
13768         INL_LOGGING_PVT.Log_ExpecError (
13769             p_module_name    => g_module_name,
13770             p_procedure_name => l_program_name
13771         );
13772         RETURN FND_API.to_boolean(L_FND_FALSE) ;
13773     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
13774         -- Standard Unexpected Error Logging
13775         INL_LOGGING_PVT.Log_UnexpecError (
13776             p_module_name    => g_module_name,
13777             p_procedure_name => l_program_name
13778         );
13779         RETURN FND_API.to_boolean(L_FND_FALSE) ;
13780     WHEN OTHERS THEN
13781         -- Standard Unexpected Error Logging
13782         INL_LOGGING_PVT.Log_UnexpecError (
13783             p_module_name    => g_module_name,
13784             p_procedure_name => l_program_name
13785         );
13786         IF FND_MSG_PUB.Check_Msg_Level(
13787             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
13788         ) THEN
13789             FND_MSG_PUB.Add_Exc_Msg(
13790                 p_pkg_name       => g_pkg_name,
13791                 p_procedure_name => l_program_name
13792             );
13793         END IF;
13794         RETURN FND_API.to_boolean(L_FND_FALSE) ;
13795 END Validate_MatchTrxType;
13796 -- Funct Name : Validate_MatchParty
13797 -- Type       : Private
13798 -- Function   : Validate Match Party and Party Site
13799 --
13800 -- Pre-reqs   : None
13801 -- Parameters :
13802 -- IN         : p_match_int_id           IN NUMBER
13803 --              p_match_type_code        IN VARCHAR2
13804 --              p_parent_match_type_code IN VARCHAR2
13805 --              p_party_id               IN NUMBER
13806 --              p_party_site_id          IN NUMBER
13807 --
13808 -- IN OUT     : x_return_status          OUT NOCOPY VARCHAR2
13809 --
13810 -- Version    : Current version 1.0
13811 --
13812 -- Notes      :
13813 FUNCTION Validate_MatchParty(
13814     p_match_int_id           IN NUMBER,
13815     p_match_type_code        IN VARCHAR2,
13816     p_parent_match_type_code IN VARCHAR2,
13817     p_party_id               IN NUMBER,
13818     p_party_site_id          IN NUMBER,
13819     x_return_status          OUT NOCOPY VARCHAR2
13820 ) RETURN BOOLEAN IS
13821     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_MatchParty';
13822     l_debug_info    VARCHAR2(400) ;
13823     l_return_status VARCHAR2(1) ;
13824     l_result        VARCHAR2(1) := L_FND_TRUE;
13825     l_field         VARCHAR2(30) ;
13826     l_field_id      NUMBER;
13827 BEGIN
13828     -- Standard Beginning of Procedure/Function Logging
13829     INL_LOGGING_PVT.Log_BeginProc(
13830         p_module_name    => g_module_name,
13831         p_procedure_name => l_program_name
13832     ) ;
13833     --  Initialize API return status to success
13834     x_return_status := L_FND_RET_STS_SUCCESS;
13835     l_debug_info := 'Check if the Party information should be included based on a given Match Type Code ';
13836     INL_LOGGING_PVT.Log_Statement(
13837         p_module_name      => g_module_name,
13838         p_procedure_name   => l_program_name,
13839         p_debug_info       => l_debug_info
13840     );
13841     INL_LOGGING_PVT.Log_Variable(
13842         p_module_name    => g_module_name,
13843         p_procedure_name => l_program_name,
13844         p_var_name       => 'p_parent_match_type_code',
13845         p_var_value      => p_parent_match_type_code
13846     ) ;
13847 
13848     INL_LOGGING_PVT.Log_Variable(
13849         p_module_name    => g_module_name,
13850         p_procedure_name => l_program_name,
13851         p_var_name       => 'p_match_type_code',
13852         p_var_value      => p_match_type_code
13853     ) ;
13854 
13855     IF NVL(p_parent_match_type_code, p_match_type_code) = 'CHARGE' THEN
13856         l_field := 'x';
13857         INL_LOGGING_PVT.Log_Variable(
13858             p_module_name    => g_module_name,
13859             p_procedure_name => l_program_name,
13860             p_var_name       => 'p_party_id',
13861             p_var_value      => p_party_id
13862         ) ;
13863 
13864         l_debug_info     := 'party_id: ';
13865         IF p_party_id IS NOT NULL THEN
13866             BEGIN
13867                 l_debug_info := 'Chech Party_Id in HZ_PARTIES table';
13868                 INL_LOGGING_PVT.Log_Statement(
13869                     p_module_name      => g_module_name,
13870                     p_procedure_name   => l_program_name,
13871                     p_debug_info       => l_debug_info
13872                 );
13873                 SELECT 'x'
13874                 INTO l_field
13875                 FROM hz_parties
13876                 WHERE p_party_id = party_id;
13877 
13878                 l_debug_info := l_debug_info||'(OK) ';
13879             EXCEPTION
13880                 WHEN OTHERS THEN
13881                     l_field      := 'PARTY_ID';
13882                     l_field_id   := p_party_id;
13883                     l_debug_info := l_debug_info||'(NOT OK) ';
13884             END;
13885         ELSE
13886             l_field    := 'PARTY_ID';
13887             l_field_id := NULL;
13888         END IF;
13889         INL_LOGGING_PVT.Log_Statement(
13890             p_module_name      => g_module_name,
13891             p_procedure_name   => l_program_name,
13892             p_debug_info       => l_debug_info
13893         );
13894         INL_LOGGING_PVT.Log_Variable(
13895             p_module_name    => g_module_name,
13896             p_procedure_name => l_program_name,
13897             p_var_name       => 'p_party_site_id',
13898             p_var_value      => p_party_site_id
13899         ) ;
13900         l_debug_info := 'p_party_site_id: ';
13901         IF p_party_site_id IS NOT NULL THEN
13902             BEGIN
13903                  SELECT 'x'
13904                  INTO l_field
13905                  FROM hz_party_sites
13906                  WHERE party_site_id = p_party_site_id;
13907 
13908                 l_debug_info := l_debug_info||'(OK) ';
13909             EXCEPTION
13910             WHEN OTHERS THEN
13911                 l_field      := 'PARTY_SITE_ID';
13912                 l_field_id   := p_party_site_id;
13913                 l_debug_info := l_debug_info||'(NOT OK) ';
13914             END;
13915         ELSE
13916             IF l_field     <> 'x' THEN
13917                 l_field    := 'PARTY_SITE_ID';
13918                 l_field_id := NULL;
13919             END IF;
13920         END IF;
13921         INL_LOGGING_PVT.Log_Statement(
13922             p_module_name    => g_module_name,
13923             p_procedure_name => l_program_name,
13924             p_debug_info     => l_debug_info
13925         );
13926         IF l_field                                      <> 'x' THEN
13927             l_debug_info := 'ERROR l_field: '||l_field;
13928             INL_LOGGING_PVT.Log_Statement(
13929                 p_module_name    => g_module_name,
13930                 p_procedure_name => l_program_name,
13931                 p_debug_info     => l_debug_info
13932             );
13933             l_result     := L_FND_FALSE;
13934             -- Add a line into inl_ship_errors
13935             Handle_InterfError(
13936                 p_parent_table_name  => 'INL_MATCHES_INT',
13937                 p_parent_table_id    => p_match_int_id,
13938                 p_column_name        => l_field,
13939                 p_column_value       => l_field_id,
13940                 p_error_message_name => 'INL_ERR_OI_CHK_PARTY_INVAL',
13941                 p_token1_name        => 'MATCH_INT_ID',
13942                 p_token1_value       => p_match_int_id,
13943                 x_return_status      => l_return_status
13944             ) ;
13945             -- If unexpected errors happen abort
13946             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13947                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
13948             END IF;
13949         END IF;
13950     ELSE
13951         l_field := 'x';
13952         IF p_party_id  IS NOT NULL THEN
13953             l_field    := 'PARTY_ID';
13954             l_field_id := p_party_id;
13955         END IF;
13956         IF p_party_site_id IS NOT NULL THEN
13957             l_field    := 'PARTY_SITE_ID';
13958             l_field_id := p_party_site_id;
13959         END IF;
13960         IF l_field   <> 'x' THEN
13961             l_result := L_FND_FALSE;
13962             -- Add a line into inl_ship_errors
13963             Handle_InterfError(
13964                 p_parent_table_name  => 'INL_MATCHES_INT',
13965                 p_parent_table_id    => p_match_int_id,
13966                 p_column_name        => l_field,
13967                 p_column_value       => l_field_id,
13968                 p_error_message_name => 'INL_ERR_OI_CHK_PARTY_NNULL',
13969                 p_token1_name        => 'MATCH_INT_ID',
13970                 p_token1_value       => p_match_int_id,
13971                 x_return_status      => l_return_status
13972             ) ;
13973             -- If unexpected errors happen abort
13974             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
13975                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
13976             END IF;
13977         END IF;
13978     END IF;
13979     -- Standard End of Procedure/Function Logging
13980     INL_LOGGING_PVT.Log_EndProc(
13981         p_module_name    => g_module_name,
13982         p_procedure_name => l_program_name
13983     );
13984     RETURN FND_API.to_boolean(l_result) ;
13985 EXCEPTION
13986     WHEN L_FND_EXC_ERROR THEN
13987         -- Standard Expected Error Logging
13988         INL_LOGGING_PVT.Log_ExpecError (
13989             p_module_name    => g_module_name,
13990             p_procedure_name => l_program_name
13991         );
13992         RETURN FND_API.to_boolean(L_FND_FALSE) ;
13993     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
13994         -- Standard Unexpected Error Logging
13995         INL_LOGGING_PVT.Log_UnexpecError (
13996             p_module_name    => g_module_name,
13997             p_procedure_name => l_program_name
13998         );
13999         RETURN FND_API.to_boolean(L_FND_FALSE) ;
14000     WHEN OTHERS THEN
14001         -- Standard Unexpected Error Logging
14002         INL_LOGGING_PVT.Log_UnexpecError (
14003             p_module_name    => g_module_name,
14004             p_procedure_name => l_program_name
14005         );
14006         IF FND_MSG_PUB.Check_Msg_Level(
14007             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
14008         ) THEN
14009             FND_MSG_PUB.Add_Exc_Msg(
14010                 p_pkg_name       => g_pkg_name,
14011                 p_procedure_name => l_program_name
14012             );
14013         END IF;
14014         RETURN FND_API.to_boolean(L_FND_FALSE) ;
14015 END Validate_MatchParty;
14016 
14017 -- Utility name   : Validate_MatchInt
14018 -- Type       : Private
14019 -- Function   : Validate a Match before import it from interface to INL Tables
14020 --
14021 -- Pre-reqs   : None
14022 -- Parameters :
14023 -- IN         : p_match_int_rec  IN  match_int_type%TYPE
14024 --
14025 -- OUT        : x_return_status  OUT NOCOPY VARCHAR2
14026 --
14027 -- Version    : Current version 1.0
14028 --
14029 -- Notes      :
14030 FUNCTION Validate_MatchInt(
14031     p_match_int_rec IN match_int_type,
14032     x_return_status OUT NOCOPY VARCHAR2
14033 ) RETURN BOOLEAN IS
14034     l_program_name                   CONSTANT VARCHAR2(30) := 'Validate_MatchInt';
14035     l_return_status               VARCHAR2(1) ;
14036     l_debug_info                  VARCHAR2(400) ;
14037     x_result                      VARCHAR2(1) := L_FND_TRUE;
14038     l_result                      BOOLEAN;
14039     l_parent_match_type_code      VARCHAR2(100) ;
14040     l_parent_matched_curr_code    VARCHAR2(15) ;
14041     l_parent_to_parent_table_name VARCHAR2(100) ;
14042     l_parent_to_parent_table_ID   NUMBER;
14043 BEGIN
14044     -- Standard Beginning of Procedure/Function Logging
14045     INL_LOGGING_PVT.Log_BeginProc(
14046         p_module_name    => g_module_name,
14047         p_procedure_name => l_program_name
14048     ) ;
14049     --  Initialize API return status to success
14050     x_return_status := L_FND_RET_STS_SUCCESS;
14051     l_debug_info := 'Validate Transaction Type. Call Validate_MatchTrxType';
14052     INL_LOGGING_PVT.Log_Statement(
14053         p_module_name      => g_module_name,
14054         p_procedure_name   => l_program_name,
14055         p_debug_info       => l_debug_info
14056     );
14057 
14058     l_result     := Validate_MatchTrxType(
14059                         p_transaction_type          => p_match_int_rec.transaction_type,
14060                         p_match_int_id              => p_match_int_rec.match_int_id,
14061                         p_to_parent_table_name => p_match_int_rec.to_parent_table_name,
14062                         p_to_parent_table_id => p_match_int_rec.to_parent_table_id,
14063                         p_match_id => p_match_int_rec.match_id,
14064                         p_replace_estim_qty_flag => p_match_int_rec.replace_estim_qty_flag,
14065                         x_return_status => l_return_status
14066     ) ;
14067     IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
14068         RAISE L_FND_EXC_UNEXPECTED_ERROR;
14069     END IF;
14070     l_debug_info     := l_debug_info||': ';
14071     IF l_result       = FALSE THEN
14072         x_result     := L_FND_FALSE;
14073         l_debug_info := l_debug_info||'FALSE';
14074     ELSE
14075         l_debug_info := l_debug_info||'OK';
14076     END IF;
14077     INL_LOGGING_PVT.Log_Statement(
14078         p_module_name      => g_module_name,
14079         p_procedure_name   => l_program_name,
14080         p_debug_info       => l_debug_info
14081     );
14082 
14083     l_debug_info := 'Get Match Type Code from Parent Match when processing corrections.';
14084     INL_LOGGING_PVT.Log_Statement(
14085         p_module_name      => g_module_name,
14086         p_procedure_name   => l_program_name,
14087         p_debug_info       => l_debug_info
14088     );
14089 
14090     INL_LOGGING_PVT.Log_Variable(
14091         p_module_name    => g_module_name,
14092         p_procedure_name => l_program_name,
14093         p_var_name       => 'p_match_int_rec.parent_match_id',
14094         p_var_value      => p_match_int_rec.parent_match_id
14095     ) ;
14096     IF p_match_int_rec.match_type_code = 'CORRECTION' THEN
14097          SELECT match_type_code ,
14098             matched_curr_code   ,
14099             to_parent_table_name,
14100             to_parent_table_id
14101            INTO l_parent_match_type_code ,
14102             l_parent_matched_curr_code   ,
14103             l_parent_to_parent_table_name,
14104             l_parent_to_parent_table_ID
14105            FROM inl_matches
14106           WHERE match_id = p_match_int_rec.parent_match_id;
14107     ELSE
14108         l_parent_match_type_code      := NULL;
14109         l_parent_matched_curr_code    := NULL;
14110         l_parent_to_parent_table_name := NULL;
14111         l_parent_to_parent_table_ID   := NULL;
14112     END IF;
14113     l_debug_info := 'Validate TO_PARENT_TABLE information. Call Validate_MatchToParTab.';
14114     INL_LOGGING_PVT.Log_Statement(
14115         p_module_name      => g_module_name,
14116         p_procedure_name   => l_program_name,
14117         p_debug_info       => l_debug_info
14118     );
14119     l_result     := Validate_MatchToParTab(
14120                         p_transaction_type => p_match_int_rec.transaction_type,
14121                         p_match_int_id => p_match_int_rec.match_int_id,
14122                         p_match_id => p_match_int_rec.match_id,
14123                         p_parent_match_id => p_match_int_rec.parent_match_id,
14124                         p_ship_header_id => p_match_int_rec.ship_header_id,
14125                         p_to_parent_table_name => p_match_int_rec.to_parent_table_name,
14126                         p_to_parent_table_id => p_match_int_rec.to_parent_table_id,
14127                         p_match_type_code => p_match_int_rec.match_type_code,
14128                         x_return_status => l_return_status
14129     ) ;
14130     IF l_return_status                          <> L_FND_RET_STS_SUCCESS THEN
14131         RAISE L_FND_EXC_UNEXPECTED_ERROR;
14132     END IF;
14133     l_debug_info := l_debug_info||': ';
14134     IF l_result = FALSE THEN
14135         x_result     := L_FND_FALSE;
14136         l_debug_info := l_debug_info||'FALSE';
14137     ELSE
14138         l_debug_info := l_debug_info||'OK';
14139     END IF;
14140     INL_LOGGING_PVT.Log_Statement(
14141         p_module_name      => g_module_name,
14142         p_procedure_name   => l_program_name,
14143         p_debug_info       => l_debug_info
14144     );
14145     l_debug_info := 'Validate Match IDs. Call Validate_MatchMatIDS';
14146     INL_LOGGING_PVT.Log_Statement(
14147         p_module_name      => g_module_name,
14148         p_procedure_name   => l_program_name,
14149         p_debug_info       => l_debug_info
14150     );
14151     l_result := Validate_MatchMatIDS(
14152                     p_transaction_type         => p_match_int_rec.transaction_type,
14153                     p_match_int_id             => p_match_int_rec.match_int_id,
14154                     p_match_id                 => p_match_int_rec.match_id,
14155                     p_parent_match_id          => p_match_int_rec.parent_match_id,
14156                     p_match_type_code          => p_match_int_rec.match_type_code,
14157                     p_existing_match_info_flag => p_match_int_rec.existing_match_info_flag,
14158                     x_return_status            => l_return_status
14159                     )
14160     ;
14161     IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
14162         RAISE L_FND_EXC_UNEXPECTED_ERROR;
14163     END IF;
14164     l_debug_info := l_debug_info||': ';
14165     IF l_result = FALSE THEN
14166         x_result     := L_FND_FALSE;
14167         l_debug_info := l_debug_info||'FALSE';
14168     ELSE
14169         l_debug_info := l_debug_info||'OK';
14170     END IF;
14171     INL_LOGGING_PVT.Log_Statement(
14172         p_module_name      => g_module_name,
14173         p_procedure_name   => l_program_name,
14174         p_debug_info       => l_debug_info
14175     );
14176     IF p_match_int_rec.matched_qty IS NOT NULL
14177     THEN
14178         l_debug_info := 'Validate Matched UOM Code. Call Validate_MatchUOM';
14179         INL_LOGGING_PVT.Log_Statement(
14180             p_module_name      => g_module_name,
14181             p_procedure_name   => l_program_name,
14182             p_debug_info       => l_debug_info
14183         );
14184         l_result := Validate_MatchUOM(
14185                         p_match_int_id           => p_match_int_rec.match_int_id,
14186                         p_matched_uom_code       => p_match_int_rec.matched_uom_code,
14187                         p_match_type_code        => p_match_int_rec.match_type_code,
14188                         p_parent_match_type_code => l_parent_match_type_code,
14189                         x_return_status          => l_return_status
14190                     )
14191         ;
14192         IF l_return_status                          <> L_FND_RET_STS_SUCCESS THEN
14193             RAISE L_FND_EXC_UNEXPECTED_ERROR;
14194         END IF;
14195         l_debug_info := l_debug_info||': ';
14196         IF l_result = FALSE THEN
14197             x_result     := L_FND_FALSE;
14198             l_debug_info := l_debug_info||'FALSE';
14199         ELSE
14200             l_debug_info := l_debug_info||'OK';
14201         END IF;
14202         INL_LOGGING_PVT.Log_Statement(
14203             p_module_name      => g_module_name,
14204             p_procedure_name   => l_program_name,
14205             p_debug_info       => l_debug_info
14206         );
14207     END IF;
14208     l_debug_info := 'Validate Matched Amount. Call Validate_MatchAmt';
14209     INL_LOGGING_PVT.Log_Statement(
14210         p_module_name      => g_module_name,
14211         p_procedure_name   => l_program_name,
14212         p_debug_info       => l_debug_info
14213     );
14214     l_result := Validate_MatchAmt(
14215                     p_match_int_id             => p_match_int_rec.match_int_id,
14216                     p_parent_matched_curr_code => l_parent_matched_curr_code,
14217                     p_match_type_code          => p_match_int_rec.match_type_code,
14218                     p_parent_match_type_code   => l_parent_match_type_code,
14219                     p_matched_amt              => p_match_int_rec.matched_amt,
14220                     p_matched_curr_code        => p_match_int_rec.matched_curr_code,
14221                     p_matched_curr_conv_type   => p_match_int_rec.matched_curr_conversion_type,
14222                     p_matched_curr_conv_date   => p_match_int_rec.matched_curr_conversion_date,
14223                     p_matched_curr_conv_rate   => p_match_int_rec.matched_curr_conversion_rate,
14224                     p_replace_estim_qty_flag   => p_match_int_rec.replace_estim_qty_flag,
14225                     x_return_status            => l_return_status) ;
14226     IF l_return_status                          <> L_FND_RET_STS_SUCCESS THEN
14227         RAISE L_FND_EXC_UNEXPECTED_ERROR;
14228     END IF;
14229     l_debug_info     := l_debug_info||': ';
14230     IF l_result       = FALSE THEN
14231         x_result     := L_FND_FALSE;
14232         l_debug_info := l_debug_info||'FALSE';
14233     ELSE
14234         l_debug_info := l_debug_info||'OK';
14235     END IF;
14236     INL_LOGGING_PVT.Log_Statement(
14237         p_module_name      => g_module_name,
14238         p_procedure_name   => l_program_name,
14239         p_debug_info       => l_debug_info
14240     );
14241     l_debug_info := 'Validate Matched Quantity. Call Validate_MatchQty';
14242     INL_LOGGING_PVT.Log_Statement(
14243         p_module_name      => g_module_name,
14244         p_procedure_name   => l_program_name,
14245         p_debug_info       => l_debug_info
14246     );
14247     IF((p_match_int_rec.to_parent_table_name = 'INL_SHIP_LINES'
14248          AND p_match_int_rec.match_type_code = 'ITEM')
14249       OR (l_parent_to_parent_table_name = 'INL_SHIP_LINES'
14250           AND l_parent_match_type_code = 'ITEM'
14251          )
14252       ) AND p_match_int_rec.matched_qty IS NOT NULL
14253     THEN
14254         l_result := Validate_MatchQty(
14255                         p_match_int_id           => p_match_int_rec.match_int_id,
14256                         p_corrected_match_id     => p_match_int_rec.parent_match_id,
14257                         p_updated_match_id       => p_match_int_rec.match_id,
14258                         p_ship_line_id           => NVL(l_parent_to_parent_table_id,
14259                                                         p_match_int_rec.to_parent_table_id),
14260                         p_matched_qty            => p_match_int_rec.matched_qty,
14261                         p_matched_uom_code       => p_match_int_rec.matched_uom_code,
14262                         p_replace_estim_qty_flag => p_match_int_rec.replace_estim_qty_flag,
14263                         p_match_type_code        => p_match_int_rec.match_type_code,
14264                         x_return_status          => l_return_status) ;
14265         IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
14266             RAISE L_FND_EXC_UNEXPECTED_ERROR;
14267         END IF;
14268     END IF;
14269     l_debug_info     := l_debug_info||': ';
14270     IF l_result       = FALSE THEN
14271         x_result     := L_FND_FALSE;
14272         l_debug_info := l_debug_info||'FALSE';
14273     ELSE
14274         l_debug_info := l_debug_info||'OK';
14275     END IF;
14276     INL_LOGGING_PVT.Log_Statement(
14277         p_module_name      => g_module_name,
14278         p_procedure_name   => l_program_name,
14279         p_debug_info       => l_debug_info
14280     );
14281     l_debug_info := 'Validate Match Tax. Call Validate_MatchTax';
14282     INL_LOGGING_PVT.Log_Statement(
14283         p_module_name      => g_module_name,
14284         p_procedure_name   => l_program_name,
14285         p_debug_info       => l_debug_info
14286     );
14287     l_result := Validate_MatchTax(
14288                     p_match_int_id           => p_match_int_rec.match_int_id,
14289                     p_tax_code               => p_match_int_rec.tax_code,
14290                     p_nrec_tax_amt           => p_match_int_rec.nrec_tax_amt,
14291                     p_tax_amt_included_flag  => p_match_int_rec.tax_amt_included_flag,
14292                     p_matched_amt            => p_match_int_rec.matched_amt,
14293                     p_match_type_code        => p_match_int_rec.match_type_code,
14294                     p_parent_match_type_code => l_parent_match_type_code, x_return_status => l_return_status) ;
14295     IF l_return_status                          <> L_FND_RET_STS_SUCCESS THEN
14296         RAISE L_FND_EXC_UNEXPECTED_ERROR;
14297     END IF;
14298     l_debug_info     := l_debug_info||': ';
14299     IF l_result       = FALSE THEN
14300         x_result     := L_FND_FALSE;
14301         l_debug_info := l_debug_info||'FALSE';
14302     ELSE
14303         l_debug_info := l_debug_info||'OK';
14304     END IF;
14305     INL_LOGGING_PVT.Log_Statement(
14306         p_module_name      => g_module_name,
14307         p_procedure_name   => l_program_name,
14308         p_debug_info       => l_debug_info
14309     );
14310     l_debug_info := 'Validate Matching Flags. Call Validate_MatchFlags';
14311     INL_LOGGING_PVT.Log_Statement(
14312         p_module_name      => g_module_name,
14313         p_procedure_name   => l_program_name,
14314         p_debug_info       => l_debug_info
14315     );
14316     l_result := Validate_MatchFlags(
14317                     p_match_int_id             => p_match_int_rec.match_int_id,
14318                     p_match_type_code          => p_match_int_rec.match_type_code,
14319                     p_parent_match_type_code   => l_parent_match_type_code,
14320                     p_replace_estim_qty_flag   => p_match_int_rec.replace_estim_qty_flag,
14321                     p_existing_match_info_flag => p_match_int_rec.existing_match_info_flag,
14322                     x_return_status            => l_return_status) ;
14323     IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
14324         RAISE L_FND_EXC_UNEXPECTED_ERROR;
14325     END IF;
14326     l_debug_info     := l_debug_info||': ';
14327     IF l_result       = FALSE THEN
14328         x_result     := L_FND_FALSE;
14329         l_debug_info := l_debug_info||'FALSE';
14330     ELSE
14331         l_debug_info := l_debug_info||'OK';
14332     END IF;
14333     INL_LOGGING_PVT.Log_Statement(
14334         p_module_name      => g_module_name,
14335         p_procedure_name   => l_program_name,
14336         p_debug_info       => l_debug_info
14337     );
14338     l_debug_info := 'Validate Charge Line Type Id. Call Validate_MatchChLnTpID';
14339     INL_LOGGING_PVT.Log_Statement(
14340         p_module_name      => g_module_name,
14341         p_procedure_name   => l_program_name,
14342         p_debug_info       => l_debug_info
14343     );
14344     l_result := Validate_MatchChLnTpID(
14345                     p_match_int_id           => p_match_int_rec.match_int_id,
14346                     p_match_type_code        => p_match_int_rec.match_type_code,
14347                     p_parent_match_type_code => l_parent_match_type_code,
14348                     p_charge_line_type_id    => p_match_int_rec.charge_line_type_id,
14349                     p_match_amounts_flag     => p_match_int_rec.match_amounts_flag,
14350                     x_return_status          => l_return_status)
14351     ;
14352     IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
14353         RAISE L_FND_EXC_UNEXPECTED_ERROR;
14354     END IF;
14355     l_debug_info     := l_debug_info||': ';
14356     IF l_result       = FALSE THEN
14357         x_result     := L_FND_FALSE;
14358         l_debug_info := l_debug_info||'FALSE';
14359     ELSE
14360         l_debug_info := l_debug_info||'OK';
14361     END IF;
14362     INL_LOGGING_PVT.Log_Statement(
14363         p_module_name      => g_module_name,
14364         p_procedure_name   => l_program_name,
14365         p_debug_info       => l_debug_info
14366     );
14367     l_debug_info := 'Validate Party and Party Site. Call Validate_MatchParty';
14368     INL_LOGGING_PVT.Log_Statement(
14369         p_module_name      => g_module_name,
14370         p_procedure_name   => l_program_name,
14371         p_debug_info       => l_debug_info
14372     );
14373     l_result := Validate_MatchParty(
14374                     p_match_int_id           => p_match_int_rec.match_int_id,
14375                     p_match_type_code        => p_match_int_rec.match_type_code,
14376                     p_parent_match_type_code => l_parent_match_type_code,
14377                     p_party_id               => p_match_int_rec.party_id,
14378                     p_party_site_id          => p_match_int_rec.party_site_id,
14379                     x_return_status          => l_return_status) ;
14380     IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
14381         RAISE L_FND_EXC_UNEXPECTED_ERROR;
14382     END IF;
14383     l_debug_info     := l_debug_info||': ';
14384     IF l_result       = FALSE THEN
14385         x_result     := L_FND_FALSE;
14386         l_debug_info := l_debug_info||'FALSE';
14387     ELSE
14388         l_debug_info := l_debug_info||'OK';
14389     END IF;
14390     INL_LOGGING_PVT.Log_Statement(
14391         p_module_name      => g_module_name,
14392         p_procedure_name   => l_program_name,
14393         p_debug_info       => l_debug_info
14394     );
14395     -- SCM-051 Begin
14396     l_debug_info := 'Validate any ELC Update on going. Call Validate_MatchElcOnGoing';
14397     INL_LOGGING_PVT.Log_Statement(
14398         p_module_name      => g_module_name,
14399         p_procedure_name   => l_program_name,
14400         p_debug_info       => l_debug_info
14401     );
14402     l_result := Validate_MatchElcOnGoing(
14403                     p_match_int_id          => p_match_int_rec.match_int_id,
14404                     p_to_parent_table_name  => p_match_int_rec.to_parent_table_name,
14405                     p_to_parent_table_id    => p_match_int_rec.to_parent_table_id,
14406                     p_match_type_code       => p_match_int_rec.match_type_code,
14407                     p_charge_line_type_id   => p_match_int_rec.charge_line_type_id,
14408                     x_return_status         => l_return_status
14409                 ) ;
14410     IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
14411         RAISE L_FND_EXC_UNEXPECTED_ERROR;
14412     END IF;
14413     l_debug_info     := l_debug_info||': ';
14414     IF l_result       = FALSE THEN
14415         x_result     := L_FND_FALSE;
14416         l_debug_info := l_debug_info||'FALSE';
14417     ELSE
14418         l_debug_info := l_debug_info||'OK';
14419     END IF;
14420     INL_LOGGING_PVT.Log_Statement(
14421         p_module_name      => g_module_name,
14422         p_procedure_name   => l_program_name,
14423         p_debug_info       => l_debug_info
14424     );
14425     -- SCM-051 End
14426     INL_LOGGING_PVT.Log_Variable(
14427         p_module_name    => g_module_name,
14428         p_procedure_name => l_program_name,
14429         p_var_name       => 'p_match_int_rec.transaction_type',
14430         p_var_value      => p_match_int_rec.transaction_type
14431     ) ;
14432 
14433     INL_LOGGING_PVT.Log_Variable(
14434         p_module_name    => g_module_name,
14435         p_procedure_name => l_program_name,
14436         p_var_name       => 'p_match_int_rec.match_int_id',
14437         p_var_value      => p_match_int_rec.match_int_id
14438     ) ;
14439 
14440     INL_LOGGING_PVT.Log_Variable(
14441         p_module_name    => g_module_name,
14442         p_procedure_name => l_program_name,
14443         p_var_name       => 'p_match_int_rec.match_id',
14444         p_var_value      => p_match_int_rec.match_id
14445     ) ;
14446 
14447     l_debug_info := 'Validate Transaction Type. Call Validate_MatchTrxType';
14448     INL_LOGGING_PVT.Log_Statement(
14449         p_module_name      => g_module_name,
14450         p_procedure_name   => l_program_name,
14451         p_debug_info       => l_debug_info
14452     );
14453 
14454 /* this code appear twice in this procedure!     --Bug#10381495
14455     l_result := Validate_MatchTrxType(
14456                     p_transaction_type       => p_match_int_rec.transaction_type,
14457                     p_match_int_id           => p_match_int_rec.match_int_id,
14458                     p_to_parent_table_name   => p_match_int_rec.to_parent_table_name,
14459                     p_to_parent_table_id     => p_match_int_rec.to_parent_table_id,
14460                     p_match_id               => p_match_int_rec.match_id,
14461                     p_replace_estim_qty_flag => p_match_int_rec.replace_estim_qty_flag,
14462                     x_return_status          => l_return_status) ;
14463     IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
14464         RAISE L_FND_EXC_UNEXPECTED_ERROR;
14465     END IF;
14466     l_debug_info := 'Consistency of Transaction Type: ';
14467     IF l_result THEN
14468         l_debug_info := l_debug_info||'OK';
14469     ELSE
14470         x_result     := L_FND_FALSE;
14471         l_debug_info := l_debug_info||'FALSE';
14472     END IF;
14473     -- If unexpected errors happen abort
14474     IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
14475         RAISE L_FND_EXC_UNEXPECTED_ERROR;
14476     END IF;
14477 */
14478     -- Standard End of Procedure/Function Logging
14479     INL_LOGGING_PVT.Log_EndProc(
14480         p_module_name    => g_module_name,
14481         p_procedure_name => l_program_name
14482     );
14483     RETURN FND_API.to_boolean(x_result) ;
14484 EXCEPTION
14485     WHEN L_FND_EXC_ERROR THEN
14486         -- Standard Expected Error Logging
14487         INL_LOGGING_PVT.Log_ExpecError (
14488             p_module_name    => g_module_name,
14489             p_procedure_name => l_program_name
14490         );
14491         RETURN FND_API.to_boolean(L_FND_FALSE) ;
14492     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
14493         -- Standard Unexpected Error Logging
14494         INL_LOGGING_PVT.Log_UnexpecError (
14495             p_module_name    => g_module_name,
14496             p_procedure_name => l_program_name
14497         );
14498         RETURN FND_API.to_boolean(L_FND_FALSE) ;
14499     WHEN OTHERS THEN
14500         -- Standard Unexpected Error Logging
14501         INL_LOGGING_PVT.Log_UnexpecError (
14502             p_module_name    => g_module_name,
14503             p_procedure_name => l_program_name
14504         );
14505         IF FND_MSG_PUB.Check_Msg_Level(
14506             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
14507         ) THEN
14508             FND_MSG_PUB.Add_Exc_Msg(
14509                 p_pkg_name       => g_pkg_name,
14510                 p_procedure_name => l_program_name
14511             );
14512         END IF;
14513         RETURN FND_API.to_boolean(L_FND_FALSE) ;
14514 END Validate_MatchInt;
14515 
14516 -- Utility name : Select_MatchesToProc --Bug#11794442
14517 -- Type         : Private
14518 -- Function     : Select the interface records to process
14519 -- Pre-reqs     :
14520 -- Version    : Current version 1.0
14521 --
14522 -- IN         : p_group_id IN NUMBER
14523 --
14524 -- OUT        : x_return_status  OUT NOCOPY VARCHAR2
14525 --
14526 -- Notes      :
14527 
14528 FUNCTION Select_MatchesToProc(
14529     p_group_id      IN NUMBER,
14530     p_commit        IN VARCHAR2,
14531     x_return_status OUT NOCOPY VARCHAR2
14532 ) RETURN NUMBER IS
14533     l_program_name     CONSTANT VARCHAR2(30) := 'Select_MatchesToProc';
14534 
14535     l_lines         CONSTANT NUMBER:=50; --NUMBER of lines to process in each iteration
14536 
14537     l_return_status VARCHAR2(1);
14538     l_debug_info    VARCHAR2(200);
14539     l_return_value  NUMBER:=0;
14540     l_count_records NUMBER;
14541     l_lock_name     VARCHAR2(50) := 'select_MatchesToProc';
14542     l_lock_handle   VARCHAR2(100);
14543     l_lock_status   NUMBER;
14544 BEGIN
14545     -- Standard Beginning of Procedure/Function Logging
14546     INL_LOGGING_PVT.Log_BeginProc(
14547         p_module_name    => g_module_name,
14548         p_procedure_name => l_program_name
14549     ) ;
14550     --  Initialize API return status to success
14551     x_return_status := L_FND_RET_STS_SUCCESS;
14552 
14553     INL_LOGGING_PVT.Log_Variable(
14554         p_module_name    => g_module_name,
14555         p_procedure_name => l_program_name,
14556         p_var_name       => 'p_group_id',
14557         p_var_value      => p_group_id);
14558 
14559     INL_LOGGING_PVT.Log_Statement (
14560         p_module_name => g_module_name,
14561         p_procedure_name => l_program_name,
14562         p_debug_info => 'Acquiring lock (Allocate_Unique) on: ' || l_lock_name
14563     );
14564 
14565     DBMS_LOCK.Allocate_Unique(
14566         lockname   => l_lock_name,
14567         lockhandle => l_lock_handle
14568     );
14569 
14570     INL_LOGGING_PVT.Log_Statement (
14571         p_module_name => g_module_name,
14572         p_procedure_name => l_program_name,
14573         p_debug_info => 'Acquiring lock (Request)'
14574     );
14575 
14576     l_lock_status := DBMS_LOCK.Request(
14577                         lockhandle => l_lock_handle,
14578                         lockmode => DBMS_LOCK.x_mode
14579                      );
14580 
14581     IF l_lock_status <> 0 THEN
14582         INL_LOGGING_PVT.Log_Statement (
14583             p_module_name    => g_module_name,
14584             p_procedure_name => l_program_name,
14585             p_debug_info     => 'Failled to get the lock '||l_lock_name||' status: '||l_lock_status);
14586 
14587         RAISE FND_API.G_EXC_ERROR;
14588     END IF;
14589 
14590     UPDATE inl_matches_int m
14591         SET m.request_id = l_fnd_conc_request_id_int
14592         WHERE (nvl(m.request_id,1) > 0
14593                 OR m.request_id = -1)
14594         AND m.processing_status_code = 'PENDING'
14595         AND (p_group_id IS NULL
14596              OR m.group_id = p_group_id)
14597         AND (ROWNUM < l_lines
14598              OR p_group_id IS NOT NULL)
14599         --Bug#16198838/14707257 Mark only records complying with hr:sec profile
14600         --Begin
14601         AND EXISTS
14602         (
14603             SELECT 1
14604             FROM
14605                 rcv_transactions rt,
14606                 org_organization_definitions ood
14607             WHERE
14608                 rt.transaction_id = m.to_parent_table_id
14609             AND ood.organization_id = rt.organization_id
14610         )
14611         --Bug#16198838/14707257 End
14612     ; -- same group id should be process together
14613 
14614     l_return_value := NVL(SQL%ROWCOUNT,0);
14615 
14616     IF p_group_id IS NULL THEN
14617 
14618         --same origin should be processed together
14619 
14620         UPDATE inl_matches_int mi
14621             SET mi.request_id = l_fnd_conc_request_id_int
14622             WHERE (nvl(mi.request_id,1) > 0
14623                     OR mi.request_id = -1)
14624             AND mi.processing_status_code = 'PENDING'
14625             AND EXISTS (
14626                 SELECT 1
14627                 FROM inl_matches_int mi2
14628                 WHERE mi2.processing_status_code = 'PENDING'
14629                 AND   mi2.request_id             = l_fnd_conc_request_id_int
14630                 AND   mi2.from_parent_table_name = mi.from_parent_table_name
14631                 AND   mi2.from_parent_table_id   = mi.from_parent_table_id
14632                 AND   mi2.match_int_id           <> mi.match_int_id
14633             );
14634         l_return_value := l_return_value + NVL(SQL%ROWCOUNT,0);
14635 
14636         --item matches to the same ship_line should be processed together
14637 
14638         UPDATE inl_matches_int mi
14639             SET mi.request_id = l_fnd_conc_request_id_int
14640             WHERE (nvl(mi.request_id,1) > 0
14641                     OR mi.request_id = -1)
14642             AND mi.processing_status_code = 'PENDING'
14643             AND mi.to_parent_table_name = 'RCV_TRANSACTIONS'
14644             AND EXISTS (
14645                 SELECT 1
14646                 FROM inl_matches_int mi2
14647                 WHERE mi2.processing_status_code = 'PENDING'
14648                 AND   mi2.request_id             = l_fnd_conc_request_id_int
14649                 AND   mi2.match_int_id           <> mi.match_int_id
14650                 AND   mi2.to_parent_table_name = 'RCV_TRANSACTIONS'
14651                 AND   mi2.to_parent_table_id   = mi.to_parent_table_id
14652             );
14653         l_return_value := l_return_value + NVL(SQL%ROWCOUNT,0);
14654 
14655 
14656         --same group_id should be processed together
14657 
14658         UPDATE inl_matches_int mi
14659             SET mi.request_id = l_fnd_conc_request_id_int
14660             WHERE (nvl(mi.request_id,1) > 0
14661                     OR mi.request_id = -1)
14662             AND mi.processing_status_code = 'PENDING'
14663             AND EXISTS (
14664                 SELECT 1
14665                 FROM inl_matches_int mi2
14666                 WHERE mi2.processing_status_code = 'PENDING'
14667                 AND   mi2.request_id             = l_fnd_conc_request_id_int
14668                 AND   mi2.group_id               = mi.group_id
14669                 AND   mi2.match_int_id           <> mi.match_int_id
14670             );
14671         l_return_value := l_return_value + NVL(SQL%ROWCOUNT,0);
14672 
14673     END IF;
14674 
14675     --Bug#14707257/16198838 If any record aren't complying with hr:sec profile the group should be unmarked
14676     --Begin
14677     FOR l_non_hrs IN
14678       (
14679           SELECT DISTINCT
14680               mi.group_id
14681           FROM
14682               inl_matches_int mi
14683           WHERE
14684               mi.processing_status_code = 'PENDING'
14685           AND mi.request_id             = l_fnd_conc_request_id_int
14686           AND NOT EXISTS
14687           (
14688             SELECT 1
14689             FROM
14690                 rcv_transactions rt,
14691                 org_organization_definitions ood
14692             WHERE
14693                 rt.transaction_id = mi.to_parent_table_id
14694             AND ood.organization_id = rt.organization_id
14695           )
14696       )
14697     LOOP
14698         INL_LOGGING_PVT.Log_Statement (
14699             p_module_name    => g_module_name,
14700             p_procedure_name => l_program_name,
14701             p_debug_info     => ' Group unmarked:'||l_non_hrs.group_id);
14702         UPDATE
14703             inl_matches_int mi
14704         SET mi.request_id = ABS(l_fnd_conc_request_id_int)
14705         WHERE mi.group_id = l_non_hrs.group_id
14706         AND   mi.processing_status_code = 'PENDING';
14707         l_return_value := l_return_value - NVL(SQL%ROWCOUNT,0);
14708     END LOOP;
14709     --Bug#14707257/16198838 END
14710 
14711     INL_LOGGING_PVT.Log_Statement (
14712         p_module_name    => g_module_name,
14713         p_procedure_name => l_program_name,
14714         p_debug_info     => l_return_value||' selected records');
14715 
14716     -- Standard check of p_commit.
14717     IF FND_API.To_Boolean(p_commit) THEN
14718         COMMIT WORK;
14719     END IF;
14720 
14721     -- Release the lock
14722     l_lock_status := DBMS_LOCK.RELEASE(l_lock_handle);
14723     l_lock_handle := NULL;
14724 
14725     RETURN l_return_value;
14726 
14727 EXCEPTION
14728     WHEN L_FND_EXC_ERROR THEN
14729         -- Standard Expected Error Logging
14730         INL_LOGGING_PVT.Log_ExpecError (
14731             p_module_name    => g_module_name,
14732             p_procedure_name => l_program_name
14733         );
14734         x_return_status := L_FND_RET_STS_ERROR;
14735         IF l_lock_handle IS NOT NULL THEN
14736             l_lock_status := DBMS_LOCK.Release(l_lock_handle);
14737         END IF;
14738         RETURN 0;
14739     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
14740         -- Standard Unexpected Error Logging
14741         INL_LOGGING_PVT.Log_UnexpecError (
14742             p_module_name    => g_module_name,
14743             p_procedure_name => l_program_name
14744         );
14745         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
14746         IF l_lock_handle IS NOT NULL THEN
14747             l_lock_status := DBMS_LOCK.Release(l_lock_handle);
14748         END IF;
14749         RETURN 0;
14750     WHEN OTHERS THEN
14751         -- Standard Unexpected Error Logging
14752         INL_LOGGING_PVT.Log_UnexpecError (
14753             p_module_name    => g_module_name,
14754             p_procedure_name => l_program_name
14755         );
14756         IF FND_MSG_PUB.Check_Msg_Level(
14757             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
14758         ) THEN
14759             FND_MSG_PUB.Add_Exc_Msg(
14760                 p_pkg_name       => g_pkg_name,
14761                 p_procedure_name => l_program_name
14762             );
14763         END IF;
14764         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
14765         IF l_lock_handle IS NOT NULL THEN
14766             l_lock_status := DBMS_LOCK.Release(l_lock_handle);
14767         END IF;
14768         RETURN 0;
14769 END Select_MatchesToProc;
14770 
14771 -- Utility name : Run_MatchPreProcessor
14772 -- Type       : Private
14773 -- Function   : Executes the first set of validations before import.
14774 --
14775 -- Pre-reqs   : None
14776 -- Parameters :
14777 -- IN         : p_group_id       IN  NUMBER
14778 --
14779 -- OUT        : x_return_status  OUT NOCOPY VARCHAR2
14780 --
14781 -- Version    : Current version 1.0
14782 --
14783 -- Notes      :
14784 PROCEDURE Run_MatchPreProcessor(
14785     p_group_id      IN NUMBER,
14786     p_commit        IN VARCHAR2, --Bug#11794442
14787     x_return_status OUT NOCOPY VARCHAR2
14788 ) IS
14789 
14790     --Bug#16198838/14707257 BEGIN
14791     CURSOR c_unproc_match_int (pc_max_id NUMBER)
14792     IS
14793         SELECT DISTINCT group_id
14794         FROM inl_matches_int
14795         WHERE match_int_id < pc_max_id
14796         AND (nvl(request_id,1) > 0
14797                  OR request_id = -1)
14798         AND processing_status_code = 'PENDING'
14799         AND (p_group_id IS NULL
14800              OR group_id = p_group_id)
14801     ;
14802     TYPE unproc_match_int_tp IS
14803       TABLE OF c_unproc_match_int%ROWTYPE INDEX BY BINARY_INTEGER;
14804     l_unproc_match_int_lst unproc_match_int_tp;
14805     --Bug#16198838/14707257 END
14806 
14807     -- Cursor to get all PENDING matches from the
14808     -- Interface table based on a given group id
14809     CURSOR c_match_int
14810     IS
14811          SELECT match_int_id      ,
14812             group_id              ,
14813             processing_status_code,
14814             transaction_type      ,
14815             match_type_code       ,
14816             null,
14817             from_parent_table_name,
14818             from_parent_table_id  ,
14819             to_parent_table_name  ,
14820             to_parent_table_id    ,
14821             null,
14822             matched_qty                 ,
14823             matched_uom_code            ,
14824             matched_amt                 ,
14825             matched_curr_code           ,
14826             matched_curr_conversion_type,
14827             matched_curr_conversion_date,
14828             matched_curr_conversion_rate,
14829             replace_estim_qty_flag      ,
14830             null,
14831             charge_line_type_id  ,
14832             party_id             ,
14833             party_number         ,
14834             party_site_id        ,
14835             party_site_number    ,
14836             tax_code             ,
14837             nrec_tax_amt         ,
14838             tax_amt_included_flag,
14839             match_amounts_flag,
14840             null
14841           FROM inl_matches_int m
14842           WHERE (p_group_id   IS NULL
14843                  OR m.group_id = p_group_id)
14844           AND m.processing_status_code = 'PENDING'
14845           AND m.request_id = l_fnd_conc_request_id_int  --Bug#11794442
14846           ORDER BY group_id,match_int_id;               --Bug#11794442
14847     match_int_list match_int_list_type;
14848 
14849     l_rec_num       NUMBER; --Bug#11794442
14850 
14851     l_program_name      CONSTANT VARCHAR2(100) := 'Run_MatchPreProcessor';
14852     l_return_status     VARCHAR2(1) ;
14853     l_msg_count         NUMBER;
14854     l_msg_data          VARCHAR2(2000) ;
14855     l_debug_info        VARCHAR2(200) ;
14856     l_import_validation BOOLEAN;
14857     l_amt_sum           NUMBER;
14858 --    l_processing_status_code VARCHAR2(30) ; --Bug#11794442
14859     l_varchardate       VARCHAR2(10) := TO_CHAR(SYSDATE,'DDDSSSS'); --Bug#11794442
14860     l_bad_group_id      NUMBER; --Bug#11794442
14861     l_last_group_id     NUMBER; --Bug#11794442
14862     l_max_match_int_id  NUMBER; --Bug#16198838/14707257
14863     l_max_match_int_id2  NUMBER; --Bug#16198838/14707257
14864 
14865 BEGIN
14866     -- Standard Beginning of Procedure/Function Logging
14867     INL_LOGGING_PVT.Log_BeginProc(
14868         p_module_name    => g_module_name,
14869         p_procedure_name => l_program_name
14870     ) ;
14871     --  Initialize API return status to success
14872     x_return_status := L_FND_RET_STS_SUCCESS;
14873 
14874     --Bug#16198838/14707257
14875     SELECT NVL(MAX(match_int_id),0)
14876     INTO l_max_match_int_id
14877     FROM inl_matches_int;
14878     INL_LOGGING_PVT.Log_Variable(
14879         p_module_name    => g_module_name,
14880         p_procedure_name => l_program_name,
14881         p_var_name       => 'l_max_match_int_id',
14882         p_var_value      => l_max_match_int_id
14883     ) ;
14884     --Bug#16198838/14707257
14885 
14886 --Bug#11794442 Begin
14887 
14888     INL_LOGGING_PVT.Log_Statement(
14889         p_module_name      => g_module_name,
14890         p_procedure_name   => l_program_name,
14891         p_debug_info       => 'Verify if request ID is generic:'||l_fnd_conc_request_id);
14892 
14893     IF l_fnd_conc_request_id = -1 THEN
14894         l_fnd_conc_request_id_int := TO_NUMBER(l_varchardate||TO_CHAR(SYSDATE,'DDDSSSS'))*-1;
14895         INL_LOGGING_PVT.Log_Variable(
14896             p_module_name    => g_module_name,
14897             p_procedure_name => l_program_name,
14898             p_var_name       => 'l_fnd_conc_request_id_int',
14899             p_var_value      => l_fnd_conc_request_id_int
14900         ) ;
14901     ELSE
14902         l_fnd_conc_request_id_int := l_fnd_conc_request_id*-1;
14903     END IF;
14904 
14905     LOOP
14906         INL_LOGGING_PVT.Log_Statement(
14907             p_module_name      => g_module_name,
14908             p_procedure_name   => l_program_name,
14909             p_debug_info       => 'Getting Matches_interface records to process');
14910 
14911         l_rec_num:= NVL(Select_MatchesToProc(
14912             p_group_id      => p_group_id,
14913             p_commit        => p_commit,
14914             x_return_status => l_return_status
14915         ),0);
14916         -- If any errors happen abort API.
14917         IF l_return_status = L_FND_RET_STS_ERROR THEN
14918             RAISE L_FND_EXC_ERROR;
14919         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
14920             RAISE L_FND_EXC_UNEXPECTED_ERROR;
14921         END IF;
14922         INL_LOGGING_PVT.Log_Statement(
14923             p_module_name      => g_module_name,
14924             p_procedure_name   => l_program_name,
14925             p_debug_info       => l_rec_num||' records to process');
14926 
14927         IF l_rec_num > 0  THEN
14928 --Bug#11794442 End
14929             OPEN c_match_int;
14930             FETCH c_match_int
14931             BULK COLLECT INTO match_int_list;
14932             CLOSE c_match_int;
14933 
14934             -- Set the number of LCM Shipments to be processed
14935             -- This value will be latter stamped in the concurrent log
14936             g_records_processed := g_records_processed + match_int_list.COUNT();
14937 
14938             FOR i IN 1 .. match_int_list.COUNT
14939             LOOP
14940                 --Bug#11794442 begin
14941                 BEGIN
14942                     IF match_int_list(i).group_id IS NULL
14943                         OR l_last_group_id IS NULL
14944                         OR match_int_list(i).group_id <> l_last_group_id
14945                     THEN
14946                         SAVEPOINT Run_MatchPreProcSVPNT;
14947                         l_bad_group_id  := NULL;
14948                         l_last_group_id :=  match_int_list(i).group_id;
14949                     END IF;
14950 --                    l_processing_status_code := 'RUNNING';
14951                 --Bug#11794442 end
14952 
14953                     INL_LOGGING_PVT.Log_Variable(
14954                         p_module_name    => g_module_name,
14955                         p_procedure_name => l_program_name,
14956                         p_var_name       => 'match_int_list('||i||').group_id',
14957                         p_var_value      => match_int_list(i).group_id
14958                     ) ;
14959 
14960                     INL_LOGGING_PVT.Log_Variable(
14961                         p_module_name    => g_module_name,
14962                         p_procedure_name => l_program_name,
14963                         p_var_name       => 'match_int_list(i).match_int_id',
14964                         p_var_value      => match_int_list(i).match_int_id
14965                     ) ;
14966 
14967                     INL_LOGGING_PVT.Log_Variable(
14968                         p_module_name    => g_module_name,
14969                         p_procedure_name => l_program_name,
14970                         p_var_name       => 'match_int_list(i).transaction_type',
14971                         p_var_value      => match_int_list(i).transaction_type
14972                     ) ;
14973 
14974                     INL_LOGGING_PVT.Log_Variable(
14975                         p_module_name    => g_module_name,
14976                         p_procedure_name => l_program_name,
14977                         p_var_name       => 'match_int_list(i).to_parent_table_name',
14978                         p_var_value      => match_int_list(i).to_parent_table_name
14979                     ) ;
14980 
14981                     INL_LOGGING_PVT.Log_Variable(
14982                         p_module_name    => g_module_name,
14983                         p_procedure_name => l_program_name,
14984                         p_var_name       => 'match_int_list(i).to_parent_table_id',
14985                         p_var_value      => match_int_list(i).to_parent_table_id
14986                     ) ;
14987 
14988                     l_debug_info := 'Delete errors from previous analysis performed on the current line. Call Reset_InterfError';
14989                     INL_LOGGING_PVT.Log_Statement(
14990                         p_module_name      => g_module_name,
14991                         p_procedure_name   => l_program_name,
14992                         p_debug_info       => l_debug_info
14993                     );
14994                     Reset_InterfError(
14995                         p_parent_table_name       => 'INL_MATCHES_INT',
14996                         p_parent_table_id => match_int_list(i) .match_int_id,
14997                         x_return_status => l_return_status
14998                     ) ;
14999                     -- If any errors happen abort the process.
15000                     IF l_return_status = L_FND_RET_STS_ERROR THEN
15001                         RAISE L_FND_EXC_ERROR;
15002                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
15003                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
15004                     END IF;
15005                     l_debug_info := 'Call Derive_MatchCols';
15006                     INL_LOGGING_PVT.Log_Statement(
15007                         p_module_name      => g_module_name,
15008                         p_procedure_name   => l_program_name,
15009                         p_debug_info       => l_debug_info
15010                     );
15011                     Derive_MatchCols(
15012                         p_party_number          => match_int_list(i).party_number,
15013                         p_party_site_number     => match_int_list(i).party_site_number,
15014                         p_match_type_code       => match_int_list(i).match_type_code,
15015                         p_to_parent_table_name  => match_int_list(i).to_parent_table_name,
15016                         p_to_parent_table_id    => match_int_list(i).to_parent_table_id,
15017                         p_party_id              => match_int_list(i).party_id,
15018                         p_party_site_id         => match_int_list(i).party_site_id,
15019                         p_parent_match_id       => match_int_list(i).parent_match_id,
15020                         x_return_status         => l_return_status) ;
15021                     -- If any errors happen abort the process.
15022                     IF l_return_status = L_FND_RET_STS_ERROR THEN
15023                         RAISE L_FND_EXC_ERROR;
15024                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
15025                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
15026                     END IF;
15027                     l_debug_info := 'Validate Match before import it from interface. Call Validate_MatchInt';
15028                     INL_LOGGING_PVT.Log_Statement(
15029                         p_module_name      => g_module_name,
15030                         p_procedure_name   => l_program_name,
15031                         p_debug_info       => l_debug_info
15032                     );
15033 
15034                     l_import_validation := Validate_MatchInt(
15035                                             p_match_int_rec => match_int_list(i),
15036                                             x_return_status => l_return_status)
15037                     ;
15038                     -- If any errors happen abort the process.
15039 
15040                     IF l_return_status = L_FND_RET_STS_ERROR THEN
15041                         RAISE L_FND_EXC_ERROR;
15042                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
15043                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
15044                     END IF;
15045                     -- Validation has been executed successfully and
15046                     -- processing status code has been changed to RUNNING
15047 --Bug#11794442
15048                 EXCEPTION
15049                     WHEN OTHERS THEN
15050                         l_import_validation := FALSE;
15051                         Handle_InterfError(
15052                             p_parent_table_name  => 'INL_MATCHES_INT',
15053                             p_parent_table_id    => match_int_list(i).match_int_id,
15054                             p_column_name        => 'match_int_list('||i||').match_int_id',
15055                             p_column_value       => match_int_list(i).match_int_id,
15056                             p_error_message_name => 'INL_FAILED_ON_CONC_SUB',
15057                             p_token1_name        => 'CONC',
15058                             p_token1_value       => 'Import_Matches exception',
15059                             x_return_status      => l_return_status);
15060                         -- If unexpected errors happen abort
15061                         IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
15062                             RAISE L_FND_EXC_UNEXPECTED_ERROR;
15063                         END IF;
15064                 END; --Bug#11794442
15065                 IF (l_import_validation = TRUE) THEN
15066                     INL_LOGGING_PVT.Log_Statement(
15067                         p_module_name      => g_module_name,
15068                         p_procedure_name   => l_program_name,
15069                         p_debug_info       => 'l_import_validation: TRUE'
15070                     );
15071                 ELSE
15072                     INL_LOGGING_PVT.Log_Statement(
15073                         p_module_name      => g_module_name,
15074                         p_procedure_name   => l_program_name,
15075                         p_debug_info       => 'l_import_validation: FALSE'
15076                     );
15077                 END IF;
15078 
15079                 INL_LOGGING_PVT.Log_Variable(p_module_name => g_module_name,
15080                                  p_procedure_name => l_program_name,
15081                                  p_var_name => 'l_bad_group_id',
15082                                  p_var_value => l_bad_group_id);
15083 
15084                 IF (l_import_validation = TRUE)
15085                 AND (l_bad_group_id IS NULL
15086                      OR match_int_list(i).group_id IS NULL
15087                      OR match_int_list(i).group_id <> l_bad_group_id)
15088                 THEN
15089                     l_debug_info := 'Set Interface Status to RUNNING';
15090                     INL_LOGGING_PVT.Log_Statement(
15091                         p_module_name      => g_module_name,
15092                         p_procedure_name   => l_program_name,
15093                         p_debug_info       => l_debug_info
15094                     );
15095 
15096                     UPDATE inl_matches_int
15097                     SET processing_status_code = 'RUNNING'         ,
15098                         party_id               = match_int_list(i).party_id       ,
15099                         party_site_id          = match_int_list(i).party_site_id  ,
15100 --                        request_id             = L_FND_CONC_REQUEST_ID       ,--Bug#11794442
15101                         last_updated_by        = L_FND_USER_ID               ,
15102                         last_update_date       = SYSDATE                          ,
15103                         last_update_login      = L_FND_LOGIN_ID              ,
15104                         program_id             = L_FND_CONC_PROGRAM_ID       ,
15105                         program_update_date    = SYSDATE                          ,
15106                         program_application_id = L_FND_PROG_APPL_ID
15107                     WHERE match_int_id       = match_int_list(i).match_int_id;
15108 
15109                 ELSIF (match_int_list(i).group_id IS NULL
15110                         OR l_bad_group_id IS NULL --SCM-051
15111                         OR match_int_list(i).group_id <> l_bad_group_id)
15112                 THEN
15113                     l_bad_group_id := match_int_list(i).group_id;
15114                     ROLLBACK TO Run_MatchPreProcSVPNT;
15115                     SAVEPOINT Run_MatchPreProcSVPNT;
15116                     l_debug_info := 'Set Interface Status to ERROR for group id(2): '||match_int_list(i).group_id||sqlerrm; --Bug#14044298
15117                     INL_LOGGING_PVT.Log_Statement(
15118                         p_module_name      => g_module_name,
15119                         p_procedure_name   => l_program_name,
15120                         p_debug_info       => l_debug_info
15121                     );
15122                     UPDATE inl_matches_int mi
15123                     SET mi.processing_status_code = 'ERROR'         ,
15124                         mi.request_id             = L_FND_CONC_REQUEST_ID       ,
15125                         mi.last_updated_by        = L_FND_USER_ID               ,
15126                         mi.last_update_date       = SYSDATE                          ,
15127                         mi.last_update_login      = L_FND_LOGIN_ID              ,
15128                         mi.program_id             = L_FND_CONC_PROGRAM_ID       ,
15129                         mi.program_update_date    = SYSDATE                          ,
15130                         mi.program_application_id = L_FND_PROG_APPL_ID
15131                     WHERE (match_int_list(i).group_id IS NOT NULL
15132                             AND mi.group_id = match_int_list(i).group_id)
15133                     OR (match_int_list(i).group_id IS NULL
15134                         AND mi.match_int_id = match_int_list(i).match_int_id);
15135                 ELSE
15136                     l_debug_info := 'Error in marked group id: '||match_int_list(i).group_id;
15137                     INL_LOGGING_PVT.Log_Statement(
15138                         p_module_name      => g_module_name,
15139                         p_procedure_name   => l_program_name,
15140                         p_debug_info       => l_debug_info
15141                     );
15142                 END IF;
15143 
15144 --Bug#11794442
15145             END LOOP;
15146             -- Standard check of p_commit.
15147             IF FND_API.To_Boolean(p_commit) THEN
15148                 COMMIT WORK;
15149             END IF;
15150 
15151         ELSE
15152             IF g_records_processed = 0 THEN
15153                 -- Add a line into inl_ship_errors
15154                 -- Bug 13920858: Commented the code to avoid Error Messages getting Inserted into INL_INTERFACE_ERRORS table.
15155                 l_debug_info := 'Error Mesage: No records found for processing.';
15156                 INL_LOGGING_PVT.Log_Statement(
15157                     p_module_name      => g_module_name,
15158                     p_procedure_name   => l_program_name,
15159                     p_debug_info       => l_debug_info
15160                 );
15161 
15162  /*               Handle_InterfError(
15163                     p_parent_table_name  => 'INL_MATCHES_INT',
15164                     p_parent_table_id    => 0,
15165                     p_column_name        => 'P_GROUP_ID',
15166                     p_column_value       => p_group_id,
15167                     p_error_message_name => 'INL_NO_RECORDS_FOUND_ERR',
15168                     x_return_status      => l_return_status
15169                 );
15170                 -- If unexpected errors happen abort
15171                 IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
15172                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
15173                 END IF;
15174 */
15175             END IF;
15176 
15177             --Bug#16198838/14707257 BEGIN
15178             SELECT NVL(MAX(match_int_id),0)
15179             INTO l_max_match_int_id2
15180             FROM inl_matches_int
15181             WHERE match_int_id < l_max_match_int_id+1
15182             AND (nvl(request_id,1) > 0
15183                  OR request_id = -1)
15184             AND processing_status_code = 'PENDING'
15185             AND (p_group_id IS NULL
15186                  OR group_id = p_group_id)
15187             ;
15188             IF l_max_match_int_id2 > 0
15189             THEN
15190                 OPEN c_unproc_match_int(l_max_match_int_id+1);
15191                 FETCH c_unproc_match_int BULK COLLECT INTO l_unproc_match_int_lst;
15192                 CLOSE c_unproc_match_int;
15193 
15194                 IF NVL(l_unproc_match_int_lst.LAST, 0) > 0 THEN
15195                     l_debug_info := 'Unable to process the following groups (group_id): (review HR:security profile restriction)';
15196                     INL_LOGGING_PVT.Log_Statement(
15197                         p_module_name      => g_module_name,
15198                         p_procedure_name   => l_program_name,
15199                         p_debug_info       => l_debug_info
15200                     );
15201                     FND_FILE.put_line( FND_FILE.log, l_debug_info);
15202                     l_debug_info := '';
15203                     FOR i IN NVL(l_unproc_match_int_lst.FIRST, 0)..NVL(l_unproc_match_int_lst.LAST, 0)
15204                     LOOP
15205                         l_debug_info:=l_debug_info||l_unproc_match_int_lst(i).group_id||',';
15206                         IF LENGTH(l_debug_info)>70 THEN
15207                             INL_LOGGING_PVT.Log_Statement(
15208                                 p_module_name      => g_module_name,
15209                                 p_procedure_name   => l_program_name,
15210                                 p_debug_info       => l_debug_info
15211                             );
15212                             FND_FILE.put_line( FND_FILE.log, SUBSTR(l_debug_info,1,LENGTH(l_debug_info)-1));
15213                             l_debug_info:=NULL;
15214                         END IF;
15215                     END LOOP;
15216                     IF LENGTH(l_debug_info)>1 THEN
15217                         INL_LOGGING_PVT.Log_Statement(
15218                             p_module_name      => g_module_name,
15219                             p_procedure_name   => l_program_name,
15220                             p_debug_info       => l_debug_info
15221                         );
15222                         FND_FILE.put_line( FND_FILE.log, SUBSTR(l_debug_info,1,LENGTH(l_debug_info)-1));
15223                         l_debug_info:=NULL;
15224                     END IF;
15225                 END IF;
15226             END IF;
15227             --Bug#16198838/14707257 END
15228 
15229             EXIT;
15230         END IF;
15231     END LOOP; --Bug#11794442
15232 
15233     -- Standard End of Procedure/Function Logging
15234     INL_LOGGING_PVT.Log_EndProc(
15235         p_module_name    => g_module_name,
15236         p_procedure_name => l_program_name
15237     );
15238 EXCEPTION
15239     WHEN L_FND_EXC_ERROR THEN
15240         -- Standard Expected Error Logging
15241         INL_LOGGING_PVT.Log_ExpecError (
15242             p_module_name    => g_module_name,
15243             p_procedure_name => l_program_name
15244         );
15245         x_return_status := L_FND_RET_STS_ERROR;
15246     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
15247         -- Standard Unexpected Error Logging
15248         INL_LOGGING_PVT.Log_UnexpecError (
15249             p_module_name    => g_module_name,
15250             p_procedure_name => l_program_name
15251         );
15252         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
15253     WHEN OTHERS THEN
15254         -- Standard Unexpected Error Logging
15255         INL_LOGGING_PVT.Log_UnexpecError (
15256             p_module_name    => g_module_name,
15257             p_procedure_name => l_program_name
15258         );
15259         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
15260         IF FND_MSG_PUB.Check_Msg_Level(
15261             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
15262         ) THEN
15263             FND_MSG_PUB.Add_Exc_Msg(
15264                 p_pkg_name       => g_pkg_name,
15265                 p_procedure_name => l_program_name
15266             );
15267         END IF;
15268 END Run_MatchPreProcessor;
15269 
15270 -- Bug #8264427
15271 -- API name : Purge_LCMShipInt
15272 -- Type       : Public
15273 -- Function   : API that purges completed records
15274 --              from LCM Shipment Interface tables.
15275 --
15276 -- Pre-reqs   : None
15277 -- Parameters :
15278 -- IN         : p_api_version   IN NUMBER
15279 --              p_init_msg_list IN VARCHAR2 := L_FND_FALSE
15280 --              p_commit        IN VARCHAR2 := L_FND_FALSE
15281 --              p_group_id      IN NUMBER
15282 --
15283 -- OUT        : x_return_status OUT NOCOPY VARCHAR2
15284 --              x_msg_count     OUT NOCOPY NUMBER
15285 --              x_msg_data      OUT NOCOPY VARCHAR2
15286 --
15287 -- Version    : Current version 1.0
15288 --
15289 -- Notes      :
15290 PROCEDURE Purge_LCMShipInt(p_api_version   IN NUMBER,
15291                            p_init_msg_list IN VARCHAR2 := L_FND_FALSE,
15292                            p_commit        IN VARCHAR2 := L_FND_FALSE,
15293                            p_group_id      IN NUMBER,
15294                            x_return_status OUT NOCOPY VARCHAR2,
15295                            x_msg_count     OUT NOCOPY NUMBER,
15296                            x_msg_data      OUT NOCOPY VARCHAR2) IS
15297 
15298     l_program_name      CONSTANT VARCHAR2(30) := 'Purge_LCMShipInt';
15299     l_api_version   CONSTANT NUMBER := 1.0;
15300     l_return_status VARCHAR2(1) ;
15301     l_msg_count     NUMBER;
15302     l_msg_data      VARCHAR2(2000);
15303     l_debug_info    VARCHAR2(200);
15304 
15305     CURSOR c_shipToDelete IS
15306         SELECT shi.ship_header_int_id
15307           FROM inl_ship_headers_int shi
15308          WHERE (p_group_id IS NULL OR shi.group_id = p_group_id)
15309            AND processing_status_code = 'COMPLETED';
15310 
15311     TYPE shipToDelete_ListType IS TABLE OF c_shipToDelete%ROWTYPE;
15312     shipToDelete_List shipToDelete_ListType;
15313 
15314 BEGIN
15315     -- Standard Beginning of Procedure/Function Logging
15316     INL_LOGGING_PVT.Log_BeginProc(p_module_name => g_module_name,
15317                                   p_procedure_name => l_program_name ) ;
15318 
15319     -- Standard Start of API savepoint
15320     SAVEPOINT Purge_LCMShipInt_PVT;
15321 
15322     -- Initialize message list if p_init_msg_list is set to TRUE.
15323     IF FND_API.to_Boolean(p_init_msg_list) THEN
15324         FND_MSG_PUB.initialize;
15325     END IF;
15326 
15327     -- Standard call to check for call compatibility
15328     IF NOT FND_API.Compatible_API_Call(p_current_version_number => l_api_version,
15329                                        p_caller_version_number => p_api_version,
15330                                        p_api_name => l_program_name,
15331                                        p_pkg_name => g_pkg_name)
15332     THEN
15333         RAISE L_FND_EXC_UNEXPECTED_ERROR;
15334     END IF;
15335 
15336     --  Initialize API return status to success
15337     x_return_status := L_FND_RET_STS_SUCCESS;
15338 
15339     -- Logging variables
15340     INL_LOGGING_PVT.Log_Variable(p_module_name => g_module_name,
15341                                  p_procedure_name => l_program_name,
15342                                  p_var_name => 'p_group_id',
15343                                  p_var_value => p_group_id);
15344 
15345     OPEN c_shipToDelete;
15346     FETCH c_shipToDelete BULK COLLECT INTO shipToDelete_List;
15347 
15348     CLOSE c_shipToDelete;
15349     IF NVL(shipToDelete_List.COUNT, 0) > 0 THEN
15350         FOR iHead IN 1 .. shipToDelete_List.COUNT
15351         LOOP
15352 
15353           l_debug_info := 'Delete from INL_SHIP_HEADERS_INT ';
15354           INL_LOGGING_PVT.Log_Statement (p_module_name => g_module_name,
15355                                          p_procedure_name => l_program_name,
15356                                          p_debug_info => l_debug_info);
15357 
15358           DELETE FROM inl_ship_headers_int
15359           WHERE ship_header_int_id = shipToDelete_List(iHead).ship_header_int_id;
15360 
15361           l_debug_info := 'Delete from INL_SHIP_LINES_INT ';
15362           INL_LOGGING_PVT.Log_Statement (p_module_name => g_module_name,
15363                                          p_procedure_name => l_program_name,
15364                                          p_debug_info => l_debug_info);
15365 
15366           DELETE FROM inl_ship_lines_int
15367           WHERE ship_header_int_id = shipToDelete_List(iHead).ship_header_int_id;
15368 
15369         END LOOP;
15370     END IF;
15371 
15372     -- Standard check of p_commit.
15373     IF FND_API.To_Boolean(p_commit) THEN
15374         COMMIT WORK;
15375     END IF;
15376 
15377     -- Standard call to get message count and if count is 1, get message info.
15378     FND_MSG_PUB.Count_And_Get(p_encoded => L_FND_FALSE,
15379                               p_count => x_msg_count,
15380                               p_data => x_msg_data) ;
15381 
15382     -- Standard End of Procedure/Function Logging
15383     INL_LOGGING_PVT.Log_EndProc(p_module_name    => g_module_name,
15384                                 p_procedure_name => l_program_name);
15385 
15386 EXCEPTION
15387     WHEN L_FND_EXC_ERROR THEN
15388         -- Standard Expected Error Logging
15389         INL_LOGGING_PVT.Log_ExpecError (p_module_name => g_module_name,
15390                                         p_procedure_name => l_program_name);
15391         ROLLBACK TO Purge_LCMShipInt_PVT;
15392         x_return_status := L_FND_RET_STS_ERROR;
15393         FND_MSG_PUB.Count_And_Get(p_encoded => L_FND_FALSE,
15394                                   p_count => x_msg_count,
15395                                   p_data => x_msg_data);
15396     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
15397         -- Standard Unexpected Error Logging
15398         INL_LOGGING_PVT.Log_UnexpecError (p_module_name => g_module_name,
15399                                           p_procedure_name => l_program_name);
15400         ROLLBACK TO Purge_LCMShipInt_PVT;
15401         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
15402         FND_MSG_PUB.Count_And_Get(p_encoded => L_FND_FALSE,
15403                                   p_count => x_msg_count,
15404                                   p_data => x_msg_data);
15405     WHEN OTHERS THEN
15406         -- Standard Unexpected Error Logging
15407         INL_LOGGING_PVT.Log_UnexpecError (p_module_name => g_module_name,
15408                                           p_procedure_name => l_program_name);
15409         ROLLBACK TO Purge_LCMShipInt_PVT;
15410         x_return_status := L_FND_RET_STS_UNEXP_ERROR ;
15411         IF FND_MSG_PUB.Check_Msg_Level(
15412             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
15413         ) THEN
15414             FND_MSG_PUB.Add_Exc_Msg(p_pkg_name => g_pkg_name,
15415                                     p_procedure_name => l_program_name );
15416         END IF;
15417         FND_MSG_PUB.Count_And_Get(p_encoded => L_FND_FALSE,
15418                                   p_count => x_msg_count,
15419                                   p_data => x_msg_data);
15420 END Purge_LCMShipInt;
15421 
15422 -- Bug #8264437
15423 -- API name   : Purge_LCMMatchesInt
15424 -- Type       : Public
15425 -- Function   : API that purges completed records
15426 --              from LCM Match Interface tables.
15427 --
15428 -- Pre-reqs   : None
15429 -- Parameters :
15430 -- IN         : p_api_version   IN NUMBER
15431 --              p_init_msg_list IN VARCHAR2 := L_FND_FALSE
15432 --              p_commit        IN VARCHAR2 := L_FND_FALSE
15433 --              p_group_id      IN NUMBER
15434 --
15435 -- OUT        : x_return_status OUT NOCOPY VARCHAR2
15436 --              x_msg_count     OUT NOCOPY NUMBER
15437 --              x_msg_data      OUT NOCOPY VARCHAR2
15438 --
15439 -- Version    : Current version 1.0
15440 --
15441 -- Notes      :
15442 PROCEDURE Purge_LCMMatchesInt(
15443     p_api_version   IN NUMBER,
15444     p_init_msg_list IN VARCHAR2 := L_FND_FALSE,
15445     p_commit        IN VARCHAR2 := L_FND_FALSE,
15446     p_group_id      IN NUMBER,
15447     x_return_status OUT NOCOPY VARCHAR2,
15448     x_msg_count     OUT NOCOPY NUMBER,
15449     x_msg_data      OUT NOCOPY VARCHAR2
15450 ) IS
15451 
15452     l_program_name      CONSTANT VARCHAR2(30) := 'Purge_LCMMatchesInt';
15453     l_api_version   CONSTANT NUMBER := 1.0;
15454     l_return_status VARCHAR2(1) ;
15455     l_msg_count     NUMBER;
15456     l_msg_data      VARCHAR2(2000);
15457     l_debug_info    VARCHAR2(200);
15458 
15459 BEGIN
15460 
15461     -- Standard Beginning of Procedure/Function Logging
15462     INL_LOGGING_PVT.Log_BeginProc(p_module_name => g_module_name,
15463                                   p_procedure_name => l_program_name ) ;
15464 
15465     -- Standard Start of API savepoint
15466     SAVEPOINT Purge_LCMMatchesInt_PVT;
15467 
15468     -- Initialize message list if p_init_msg_list is set to TRUE.
15469     IF FND_API.to_Boolean(p_init_msg_list) THEN
15470         FND_MSG_PUB.initialize;
15471     END IF;
15472 
15473     -- Standard call to check for call compatibility
15474     IF NOT FND_API.Compatible_API_Call(p_current_version_number => l_api_version,
15475                                        p_caller_version_number => p_api_version,
15476                                        p_api_name => l_program_name,
15477                                        p_pkg_name => g_pkg_name)
15478     THEN
15479         RAISE L_FND_EXC_UNEXPECTED_ERROR;
15480     END IF;
15481 
15482     --  Initialize API return status to success
15483     x_return_status := L_FND_RET_STS_SUCCESS;
15484 
15485     -- Logging variables
15486     INL_LOGGING_PVT.Log_Variable(p_module_name => g_module_name,
15487                                  p_procedure_name => l_program_name,
15488                                  p_var_name => 'p_group_id',
15489                                  p_var_value => p_group_id);
15490 
15491     l_debug_info := 'Delete from INL_MATCHES_INT';
15492     INL_LOGGING_PVT.Log_Statement (p_module_name => g_module_name,
15493                                    p_procedure_name => l_program_name,
15494                                    p_debug_info => l_debug_info) ;
15495 
15496     DELETE FROM inl_matches_int
15497           WHERE (p_group_id IS NULL OR group_id = p_group_id)
15498             AND processing_status_code = 'COMPLETED';
15499 
15500     -- Standard check of p_commit.
15501     IF FND_API.To_Boolean(p_commit) THEN
15502         COMMIT WORK;
15503     END IF;
15504 
15505     -- Standard call to get message count and if count is 1, get message info.
15506     FND_MSG_PUB.Count_And_Get(p_encoded => L_FND_FALSE,
15507                               p_count => x_msg_count,
15508                               p_data => x_msg_data) ;
15509 
15510     -- Standard End of Procedure/Function Logging
15511     INL_LOGGING_PVT.Log_EndProc(p_module_name    => g_module_name,
15512                                 p_procedure_name => l_program_name);
15513 
15514 EXCEPTION
15515     WHEN L_FND_EXC_ERROR THEN
15516         -- Standard Expected Error Logging
15517         INL_LOGGING_PVT.Log_ExpecError (p_module_name => g_module_name,
15518                                         p_procedure_name => l_program_name);
15519         ROLLBACK TO Purge_LCMMatchesInt_PVT;
15520         x_return_status := L_FND_RET_STS_ERROR;
15521         FND_MSG_PUB.Count_And_Get(p_encoded => L_FND_FALSE,
15522                                   p_count => x_msg_count,
15523                                   p_data => x_msg_data);
15524     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
15525         -- Standard Unexpected Error Logging
15526         INL_LOGGING_PVT.Log_UnexpecError (p_module_name => g_module_name,
15527                                           p_procedure_name => l_program_name);
15528         ROLLBACK TO Purge_LCMMatchesInt_PVT;
15529         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
15530         FND_MSG_PUB.Count_And_Get(p_encoded => L_FND_FALSE,
15531                                   p_count => x_msg_count,
15532                                   p_data => x_msg_data);
15533     WHEN OTHERS THEN
15534         -- Standard Unexpected Error Logging
15535         INL_LOGGING_PVT.Log_UnexpecError (p_module_name => g_module_name,
15536                                           p_procedure_name => l_program_name);
15537         ROLLBACK TO Purge_LCMMatchesInt_PVT;
15538         x_return_status := L_FND_RET_STS_UNEXP_ERROR ;
15539         IF FND_MSG_PUB.Check_Msg_Level(
15540             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
15541         ) THEN
15542             FND_MSG_PUB.Add_Exc_Msg(p_pkg_name => g_pkg_name,
15543                                     p_procedure_name => l_program_name );
15544         END IF;
15545         FND_MSG_PUB.Count_And_Get(p_encoded => L_FND_FALSE,
15546                                   p_count => x_msg_count,
15547                                   p_data => x_msg_data);
15548 END Purge_LCMMatchesInt;
15549 
15550 -- Utility name : Run_MatchPostProcessor
15551 -- Type       : Private
15552 -- Function   : Post processor to import Match Lines.
15553 --
15554 -- Pre-reqs   : None
15555 -- Parameters :
15556 -- IN         : p_group_id      IN NUMBER
15557 --
15558 -- OUT        : x_return_status OUT NOCOPY VARCHAR2
15559 --
15560 -- Version    : Current version 1.0
15561 --
15562 -- Notes      :
15563 PROCEDURE Run_MatchPostProcessor(
15564     p_group_id      IN NUMBER,
15565     p_commit        IN VARCHAR2, --Bug#11794442
15566     x_return_status OUT NOCOPY VARCHAR2
15567 ) IS
15568 
15569     l_program_name     CONSTANT VARCHAR2(100) := 'Run_MatchPostProcessor';
15570     l_return_status VARCHAR2(1) ;
15571     l_debug_info    VARCHAR2(200);
15572     l_msg_data      VARCHAR2(2000) ;
15573     l_msg_count     NUMBER;
15574     l_init_msg_list VARCHAR2(2000) := L_FND_FALSE;
15575 
15576 BEGIN
15577     -- Standard Beginning of Procedure/Function Logging
15578     INL_LOGGING_PVT.Log_BeginProc(
15579         p_module_name    => g_module_name,
15580         p_procedure_name => l_program_name
15581     ) ;
15582     --  Initialize API return status to success
15583     x_return_status := L_FND_RET_STS_SUCCESS;
15584     l_debug_info := 'Import Matches. Call Import_Matches';
15585     INL_LOGGING_PVT.Log_Statement(
15586         p_module_name      => g_module_name,
15587         p_procedure_name   => l_program_name,
15588         p_debug_info       => l_debug_info
15589     );
15590     Import_Matches(
15591         p_group_id      => p_group_id,
15592         p_commit        => p_commit, --Bug#11794442
15593         x_return_status => l_return_status
15594     );
15595     -- If any errors happen abort API.
15596     IF l_return_status = L_FND_RET_STS_ERROR THEN
15597         RAISE L_FND_EXC_ERROR;
15598     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
15599         RAISE L_FND_EXC_UNEXPECTED_ERROR;
15600     END IF;
15601 
15602     -- Standard check of p_commit.
15603     IF FND_API.To_Boolean(p_commit) THEN
15604         COMMIT WORK;
15605     END IF;
15606 
15607     -- Bug #8264437
15608     -- Interface records that got completed successfully
15609     -- are removed from INL_MACHES_INT
15610     Purge_LCMMatchesInt(p_api_version   => 1.0,
15611                         p_init_msg_list => l_init_msg_list,
15612                         p_commit        => p_commit,
15613                         p_group_id      => p_group_id,
15614                         x_return_status => l_return_status,
15615                         x_msg_count     => l_msg_count,
15616                         x_msg_data      => l_msg_data);
15617 
15618     -- If any errors happen abort API.
15619     IF l_return_status = L_FND_RET_STS_ERROR THEN
15620         RAISE L_FND_EXC_ERROR;
15621     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
15622         RAISE L_FND_EXC_UNEXPECTED_ERROR;
15623     END IF;
15624 
15625     -- Standard End of Procedure/Function Logging
15626     INL_LOGGING_PVT.Log_EndProc(
15627         p_module_name    => g_module_name,
15628         p_procedure_name => l_program_name
15629     );
15630 EXCEPTION
15631     WHEN L_FND_EXC_ERROR THEN
15632         -- Standard Expected Error Logging
15633         INL_LOGGING_PVT.Log_ExpecError (
15634             p_module_name    => g_module_name,
15635             p_procedure_name => l_program_name
15636         );
15637         x_return_status := L_FND_RET_STS_ERROR;
15638     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
15639         -- Standard Unexpected Error Logging
15640         INL_LOGGING_PVT.Log_UnexpecError (
15641             p_module_name    => g_module_name,
15642             p_procedure_name => l_program_name
15643         );
15644         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
15645     WHEN OTHERS THEN
15646         -- Standard Unexpected Error Logging
15647         INL_LOGGING_PVT.Log_UnexpecError (
15648             p_module_name    => g_module_name,
15649             p_procedure_name => l_program_name
15650         );
15651         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
15652         IF FND_MSG_PUB.Check_Msg_Level(
15653             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
15654         ) THEN
15655             FND_MSG_PUB.Add_Exc_Msg(
15656                 p_pkg_name       => g_pkg_name,
15657                 p_procedure_name => l_program_name
15658             );
15659         END IF;
15660 END Run_MatchPostProcessor;
15661 
15662 -- Utility name   : Import_LCMShipments
15663 -- Type       : Public
15664 -- Function   : This is called by a concurrent program to Import Shipments.
15665 --
15666 -- Pre-reqs   : None
15667 -- Parameters :
15668 -- IN         : p_group_id      IN NUMBER
15669 --
15670 -- OUT        : errbuf          OUT NOCOPY VARCHAR2
15671 --              retcode         OUT NOCOPY VARCHAR2
15672 --
15673 -- Version    : Current version 1.0
15674 --
15675 -- Notes      :
15676 PROCEDURE Import_LCMShipments(
15677     errbuf     OUT NOCOPY  VARCHAR2,
15678     retcode    OUT NOCOPY VARCHAR2,
15679     p_group_id IN NUMBER
15680     --  p_org_id   IN NUMBER
15681 )  IS
15682 
15683     l_program_name CONSTANT VARCHAR2(30) := 'Import_LCMShipments';
15684     l_return_status VARCHAR2(1) ;
15685     l_msg_data VARCHAR2(2000) ;
15686     l_debug_info VARCHAR2(200) ;
15687     l_msg_count NUMBER;
15688 
15689 BEGIN
15690 
15691     errbuf  := NULL;
15692     retcode := 0;
15693     g_records_processed := 0;
15694     g_records_inserted := 0;
15695 
15696     -- Standard Beginning of Procedure/Function Logging
15697     INL_LOGGING_PVT.Log_BeginProc(
15698         p_module_name    => g_module_name,
15699         p_procedure_name => l_program_name) ;
15700 
15701     l_debug_info := 'Call Import_LCMShipments';
15702     INL_LOGGING_PVT.Log_Statement(
15703         p_module_name => g_module_name,
15704         p_procedure_name => l_program_name,
15705         p_debug_info => l_debug_info
15706     );
15707 
15708     Import_LCMShipments(
15709         p_api_version   => 1.0,
15710         p_init_msg_list => L_FND_TRUE,
15711         p_commit        => L_FND_TRUE,
15712         p_group_id      => p_group_id,
15713         x_return_status => l_return_status,
15714         x_msg_count     => l_msg_count,
15715         x_msg_data      => l_msg_data
15716     ) ;
15717 
15718     IF l_msg_count = 1 THEN
15719         FND_FILE.PUT_LINE(FND_FILE.LOG, l_msg_data);
15720         retcode := 1;
15721     ELSIF l_msg_count > 1 THEN
15722         FND_FILE.PUT_LINE(FND_FILE.LOG, l_msg_count|| ' warnings found.' );
15723         FOR i IN 1 ..l_msg_count
15724         LOOP
15725             FND_FILE.PUT_LINE(FND_FILE.LOG,FND_MSG_PUB.get (i, L_FND_FALSE) );
15726         END LOOP;
15727         retcode := 1;
15728     ELSIF NVL(G_RECORDS_COMPLETED,0) <> NVL(G_RECORDS_INSERTED,0) THEN -- Bug #16310024
15729         retcode := 1;
15730     END IF;
15731 
15732     -- Write the number of records processed and inserted by this concurrent process
15733     FND_FILE.put_line( FND_FILE.log, '< **************************************>');
15734     FND_FILE.put_line( FND_FILE.log, '< ***** ' || 'LCM Shipments Processed: ' || g_records_processed); -- Bug #9258936
15735     FND_FILE.put_line( FND_FILE.log, '< ***** ' || 'LCM Shipments Inserted: ' || g_records_inserted);   -- Bug #9258936
15736     FND_FILE.put_line( FND_FILE.log, '< ***** ' || 'LCM Shipments Completed: ' || g_records_completed);   -- Bug #16310024
15737     FND_FILE.put_line( FND_FILE.log, '< **************************************>');
15738 
15739     -- If any errors happen abort API.
15740     IF l_return_status = L_FND_RET_STS_ERROR THEN
15741         RAISE L_FND_EXC_ERROR;
15742     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
15743         RAISE L_FND_EXC_UNEXPECTED_ERROR;
15744     END IF;
15745 
15746     -- Standard End of Procedure/Function Logging
15747     INL_LOGGING_PVT.Log_EndProc(
15748         p_module_name    => g_module_name,
15749         p_procedure_name => l_program_name);
15750 
15751 EXCEPTION
15752     WHEN L_FND_EXC_ERROR THEN
15753         -- Standard Expected Error Logging
15754         INL_LOGGING_PVT.Log_ExpecError (
15755             p_module_name    => g_module_name,
15756             p_procedure_name => l_program_name);
15757         retcode := 1;
15758         errbuf := errbuf ||' G_EXC_ERROR '||SQLERRM;
15759     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
15760         -- Standard Unexpected Error Logging
15761         INL_LOGGING_PVT.Log_UnexpecError(
15762             p_module_name    => g_module_name,
15763             p_procedure_name => l_program_name);
15764         retcode := 2;
15765         errbuf := errbuf ||' G_EXC_UNEXPECTED_ERROR '||SQLERRM;
15766     WHEN OTHERS THEN
15767         -- Standard Unexpected Error Logging
15768         INL_LOGGING_PVT.Log_UnexpecError(
15769             p_module_name    => g_module_name,
15770             p_procedure_name => l_program_name);
15771         retcode := 2;
15772         errbuf := errbuf ||' OTHERS '||SQLERRM;
15773 END Import_LCMShipments;
15774 
15775 -- Utility name   : Import_LCMMatches
15776 -- Type       : Public
15777 -- Function   : This is called by a concurrent
15778 --              program to import LCM Match Lines.
15779 --
15780 -- Pre-reqs   : None
15781 -- Parameters :
15782 -- IN         : p_group_id      IN NUMBER
15783 --
15784 -- OUT        : errbuf          OUT NOCOPY VARCHAR2
15785 --              retcode         OUT NOCOPY VARCHAR2
15786 --
15787 -- Version    : Current version 1.0
15788 --
15789 -- Notes      :
15790 PROCEDURE Import_LCMMatches(errbuf     OUT NOCOPY  VARCHAR2,
15791                             retcode    OUT NOCOPY VARCHAR2,
15792                             p_group_id IN NUMBER)
15793 IS
15794 
15795     l_program_name     CONSTANT VARCHAR2(30) := 'Import_LCMMatches';
15796     l_return_status VARCHAR2(1) ;
15797     l_msg_data      VARCHAR2(2000) ;
15798     l_debug_info    VARCHAR2(200) ;
15799     l_msg_count     NUMBER;
15800 
15801 BEGIN
15802 
15803     errbuf  := NULL;
15804     retcode := 0;
15805     g_records_processed := 0;
15806     g_records_inserted := 0;
15807 
15808     -- Standard Beginning of Procedure/Function Logging
15809     INL_LOGGING_PVT.Log_BeginProc(p_module_name => g_module_name,
15810                                   p_procedure_name => l_program_name);
15811 
15812     l_debug_info := 'Call Import_LCMMatches';
15813     INL_LOGGING_PVT.Log_Statement(
15814         p_module_name => g_module_name,
15815         p_procedure_name => l_program_name,
15816         p_debug_info => l_debug_info
15817     );
15818 
15819     Import_LCMMatches(
15820         p_api_version     => 1.0,
15821         p_init_msg_list   => L_FND_TRUE,
15822         p_commit          => L_FND_TRUE,
15823         p_group_id        => p_group_id,
15824         x_return_status   => l_return_status,
15825         x_msg_count       => l_msg_count,
15826         x_msg_data        => l_msg_data
15827     );
15828 
15829     IF l_msg_count = 1 THEN
15830         FND_FILE.PUT_LINE(FND_FILE.LOG, l_msg_data);
15831         retcode := 1;
15832     ELSIF l_msg_count > 1 THEN
15833         FND_FILE.PUT_LINE(FND_FILE.LOG, l_msg_count|| ' warnings found.' );
15834         FOR i IN 1 ..l_msg_count
15835         LOOP
15836             FND_FILE.PUT_LINE(FND_FILE.LOG,FND_MSG_PUB.get (i, L_FND_FALSE) );
15837         END LOOP;
15838         retcode := 1;
15839     END IF;
15840 
15841     -- Write the number of records processed and inserted by this concurrent process
15842     FND_FILE.put_line( FND_FILE.log, '< **************************************>');
15843     FND_FILE.put_line( FND_FILE.log, '< ***** ' || 'Records Processed: ' || g_records_processed);  -- Bug #9258936
15844     FND_FILE.put_line( FND_FILE.log, '< ***** ' || 'Records Inserted: ' || g_records_inserted);    -- Bug #9258936
15845     FND_FILE.put_line( FND_FILE.log, '< **************************************>');
15846 
15847     -- If any errors happen abort API.
15848     IF l_return_status = L_FND_RET_STS_ERROR THEN
15849         RAISE L_FND_EXC_ERROR;
15850     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
15851         RAISE L_FND_EXC_UNEXPECTED_ERROR;
15852     END IF;
15853 
15854     -- Standard End of Procedure/Function Logging
15855     INL_LOGGING_PVT.Log_EndProc(p_module_name => g_module_name,
15856                                 p_procedure_name => l_program_name);
15857 EXCEPTION
15858     WHEN L_FND_EXC_ERROR THEN
15859         -- Standard Expected Error Logging
15860         INL_LOGGING_PVT.Log_ExpecError (
15861             p_module_name    => g_module_name,
15862             p_procedure_name => l_program_name
15863         );
15864         retcode := 1;
15865     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
15866         -- Standard Unexpected Error Logging
15867         INL_LOGGING_PVT.Log_UnexpecError(
15868             p_module_name    => g_module_name,
15869             p_procedure_name => l_program_name
15870         );
15871         retcode := 2;
15872     WHEN OTHERS THEN
15873         -- Standard Unexpected Error Logging
15874         INL_LOGGING_PVT.Log_UnexpecError(
15875             p_module_name    => g_module_name,
15876             p_procedure_name => l_program_name
15877         );
15878         retcode := 2;
15879 END Import_LCMMatches;
15880 
15881 -- API name   : Import_LCMMatches
15882 -- Type       : Public
15883 -- Function   : Main Import procedure. It calls the
15884 --              Pre and Post processors to import Match Lines
15885 --
15886 -- Pre-reqs   : None
15887 -- Parameters :
15888 -- IN         : p_api_version   IN NUMBER
15889 --              p_init_msg_list IN VARCHAR2 := L_FND_FALSE
15890 --              p_commit        IN VARCHAR2 := L_FND_FALSE
15891 --              p_group_id      IN NUMBER
15892 --
15893 -- OUT        : x_return_status OUT NOCOPY VARCHAR2
15894 --              x_msg_count     OUT NOCOPY NUMBER
15895 --              x_msg_data      OUT NOCOPY VARCHAR2
15896 --
15897 -- Version    : Current version 1.0
15898 --
15899 -- Notes      :
15900 PROCEDURE Import_LCMMatches(
15901     p_api_version   IN NUMBER,
15902     p_init_msg_list IN VARCHAR2 := L_FND_FALSE,
15903     p_commit        IN VARCHAR2 := L_FND_FALSE,
15904     p_group_id      IN NUMBER,
15905     x_return_status OUT NOCOPY VARCHAR2,
15906     x_msg_count     OUT NOCOPY NUMBER,
15907     x_msg_data      OUT NOCOPY VARCHAR2
15908 ) IS
15909     l_program_name      CONSTANT VARCHAR2(30) := 'Import_LCMMatches';
15910     l_api_version   CONSTANT NUMBER := 1.0;
15911     l_return_status VARCHAR2(1) ;
15912     l_msg_count     NUMBER;
15913     l_msg_data      VARCHAR2(2000) ;
15914     l_debug_info    VARCHAR2(200) ;
15915 BEGIN
15916     -- Standard Beginning of Procedure/Function Logging
15917     INL_LOGGING_PVT.Log_BeginProc(
15918         p_module_name    => g_module_name,
15919         p_procedure_name => l_program_name
15920     ) ;
15921 
15922     -- Standard Start of API savepoint
15923     SAVEPOINT Import_LCMMatches_PVT;
15924     -- Initialize message list if p_init_msg_list is set to TRUE.
15925     IF FND_API.to_Boolean(p_init_msg_list) THEN
15926         FND_MSG_PUB.initialize;
15927     END IF;
15928     -- Standard call to check for call compatibility
15929     IF NOT FND_API.Compatible_API_Call(
15930                 p_current_version_number => l_api_version,
15931                 p_caller_version_number => p_api_version,
15932                 p_api_name => l_program_name,
15933                 p_pkg_name => g_pkg_name)
15934     THEN
15935         RAISE L_FND_EXC_UNEXPECTED_ERROR;
15936     END IF;
15937     --  Initialize API return status to success
15938     x_return_status := L_FND_RET_STS_SUCCESS;
15939     l_debug_info := 'Run Match Pre-Processor(first level validation). Call Run_MatchPreProcessor';
15940     INL_LOGGING_PVT.Log_Statement(
15941         p_module_name      => g_module_name,
15942         p_procedure_name   => l_program_name,
15943         p_debug_info       => l_debug_info
15944     );
15945 
15946     Run_MatchPreProcessor(
15947         p_group_id      => p_group_id,
15948         p_commit        => p_commit,
15949         x_return_status => l_return_status
15950     );
15951     -- If any errors happen abort API.
15952     IF l_return_status = L_FND_RET_STS_ERROR THEN
15953         RAISE L_FND_EXC_ERROR;
15954     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
15955         RAISE L_FND_EXC_UNEXPECTED_ERROR;
15956     END IF;
15957     l_debug_info := 'Run Match Post-Processor. Call Run_MatchPostProcessor';
15958     INL_LOGGING_PVT.Log_Statement(
15959         p_module_name   => g_module_name,
15960         p_procedure_name=> l_program_name,
15961         p_debug_info    => l_debug_info
15962     );
15963     Run_MatchPostProcessor(
15964         p_group_id      => p_group_id,
15965         p_commit        => p_commit,
15966         x_return_status => l_return_status
15967     ) ;
15968     -- If any errors happen abort API.
15969     IF l_return_status = L_FND_RET_STS_ERROR THEN
15970         RAISE L_FND_EXC_ERROR;
15971     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
15972         RAISE L_FND_EXC_UNEXPECTED_ERROR;
15973     END IF;
15974     -- Standard check of p_commit.
15975     IF FND_API.To_Boolean(p_commit) THEN
15976         COMMIT WORK;
15977     END IF;
15978     -- Standard call to get message count and if count is 1, get message info.
15979     FND_MSG_PUB.Count_And_Get(
15980         p_encoded   => L_FND_FALSE,
15981         p_count     => x_msg_count,
15982         p_data      => x_msg_data
15983     ) ;
15984     -- Standard End of Procedure/Function Logging
15985     INL_LOGGING_PVT.Log_EndProc(
15986         p_module_name    => g_module_name,
15987         p_procedure_name => l_program_name
15988     );
15989 EXCEPTION
15990     WHEN L_FND_EXC_ERROR THEN
15991         -- Standard Expected Error Logging
15992         INL_LOGGING_PVT.Log_ExpecError (
15993             p_module_name    => g_module_name,
15994             p_procedure_name => l_program_name
15995         );
15996         ROLLBACK TO Import_LCMMatches_PVT;
15997         x_return_status := L_FND_RET_STS_ERROR;
15998         FND_MSG_PUB.Count_And_Get(
15999             p_encoded        =>      L_FND_FALSE,
16000             p_count          =>      x_msg_count,
16001             p_data           =>      x_msg_data
16002         );
16003     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
16004         -- Standard Unexpected Error Logging
16005         INL_LOGGING_PVT.Log_UnexpecError (
16006             p_module_name    => g_module_name,
16007             p_procedure_name => l_program_name
16008         );
16009         ROLLBACK TO Import_LCMMatches_PVT;
16010         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
16011         FND_MSG_PUB.Count_And_Get(
16012             p_encoded        =>      L_FND_FALSE,
16013             p_count          =>      x_msg_count,
16014             p_data           =>      x_msg_data
16015         );
16016     WHEN OTHERS THEN
16017         -- Standard Unexpected Error Logging
16018         INL_LOGGING_PVT.Log_UnexpecError (
16019             p_module_name    => g_module_name,
16020             p_procedure_name => l_program_name
16021         );
16022         ROLLBACK TO Import_LCMMatches_PVT;
16023         x_return_status := L_FND_RET_STS_UNEXP_ERROR ;
16024         IF FND_MSG_PUB.Check_Msg_Level(
16025             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
16026         ) THEN
16027             FND_MSG_PUB.Add_Exc_Msg(
16028                 p_pkg_name       => g_pkg_name,
16029                 p_procedure_name => l_program_name
16030             );
16031         END IF;
16032         FND_MSG_PUB.Count_And_Get(
16033             p_encoded        =>      L_FND_FALSE,
16034             p_count          =>      x_msg_count,
16035             p_data           =>      x_msg_data
16036         );
16037 
16038 END Import_LCMMatches;
16039 
16040 -- Utility name : select_LCMShipToProc
16041 -- Type         : Private
16042 -- Function     : Select the interface records to process
16043 -- Pre-reqs     :
16044 -- Version    : Current version 1.0
16045 --
16046 -- IN         : p_group_id IN NUMBER
16047 --              p_simulation_id IN NUMBER
16048 --
16049 -- OUT        : x_return_status  OUT NOCOPY VARCHAR2
16050 --
16051 -- Notes      :
16052 
16053 FUNCTION Select_LCMShipToProc(
16054     p_group_id          IN NUMBER,
16055     p_simulation_id     IN NUMBER,
16056     x_return_status     OUT NOCOPY VARCHAR2
16057 ) RETURN NUMBER IS
16058     l_program_name     CONSTANT VARCHAR2(30) := 'select_LCMShipToProc';
16059 
16060     l_lines         CONSTANT NUMBER:=50; --NUMBER of lines to process in each iteration
16061 
16062     l_return_status VARCHAR2(1);
16063     l_debug_info    VARCHAR2(200);
16064     l_return_value  NUMBER:=0;
16065     l_count_records NUMBER;
16066     l_lock_name     VARCHAR2(50) := 'select_LCMShipToProc';
16067     l_lock_handle   VARCHAR2(100);
16068     l_lock_status   NUMBER;
16069 BEGIN
16070     -- Standard Beginning of Procedure/Function Logging
16071     INL_LOGGING_PVT.Log_BeginProc(
16072         p_module_name    => g_module_name,
16073         p_procedure_name => l_program_name
16074     ) ;
16075     --  Initialize API return status to success
16076     x_return_status := L_FND_RET_STS_SUCCESS;
16077 
16078     INL_LOGGING_PVT.Log_Variable(
16079         p_module_name    => g_module_name,
16080         p_procedure_name => l_program_name,
16081         p_var_name       => 'p_group_id',
16082         p_var_value      => p_group_id);
16083 
16084     INL_LOGGING_PVT.Log_Statement (
16085         p_module_name => g_module_name,
16086         p_procedure_name => l_program_name,
16087         p_debug_info => 'Acquiring lock (Allocate_Unique) on: ' || l_lock_name
16088     );
16089 
16090     DBMS_LOCK.Allocate_Unique(
16091         lockname   => l_lock_name,
16092         lockhandle => l_lock_handle
16093     );
16094 
16095     INL_LOGGING_PVT.Log_Statement (
16096         p_module_name => g_module_name,
16097         p_procedure_name => l_program_name,
16098         p_debug_info => 'Acquiring lock (Request)'
16099     );
16100 
16101     l_lock_status := DBMS_LOCK.Request(
16102                         lockhandle => l_lock_handle,
16103                         lockmode => DBMS_LOCK.x_mode
16104                      );
16105 
16106     IF l_lock_status <> 0 THEN
16107         INL_LOGGING_PVT.Log_Statement (
16108             p_module_name    => g_module_name,
16109             p_procedure_name => l_program_name,
16110             p_debug_info     => 'Failled to get the lock '||l_lock_name||' status: '||l_lock_status);
16111 
16112         RAISE FND_API.G_EXC_ERROR;
16113     END IF;
16114 
16115     UPDATE inl_ship_headers_int
16116         SET request_id = l_fnd_conc_request_id_int
16117         WHERE (nvl(request_id,1) > 0
16118                 OR request_id = -1) --Bug#11794483B
16119         AND processing_status_code = 'PENDING'
16120         AND (p_group_id IS NULL
16121              OR group_id = p_group_id)
16122         AND ROWNUM < l_lines;
16123     l_return_value := SQL%ROWCOUNT;
16124     INL_LOGGING_PVT.Log_Statement (
16125         p_module_name    => g_module_name,
16126         p_procedure_name => l_program_name,
16127         p_debug_info     => l_return_value||' selected records');
16128 
16129     -- Release the lock
16130     l_lock_status := DBMS_LOCK.RELEASE(l_lock_handle);
16131     l_lock_handle := NULL;
16132 
16133     RETURN l_return_value;
16134 
16135 EXCEPTION
16136     WHEN L_FND_EXC_ERROR THEN
16137         -- Standard Expected Error Logging
16138         INL_LOGGING_PVT.Log_ExpecError (
16139             p_module_name    => g_module_name,
16140             p_procedure_name => l_program_name
16141         );
16142         x_return_status := L_FND_RET_STS_ERROR;
16143         IF l_lock_handle IS NOT NULL THEN
16144             l_lock_status := DBMS_LOCK.Release(l_lock_handle);
16145         END IF;
16146         RETURN 0;
16147     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
16148         -- Standard Unexpected Error Logging
16149         INL_LOGGING_PVT.Log_UnexpecError (
16150             p_module_name    => g_module_name,
16151             p_procedure_name => l_program_name
16152         );
16153         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
16154         IF l_lock_handle IS NOT NULL THEN
16155             l_lock_status := DBMS_LOCK.Release(l_lock_handle);
16156         END IF;
16157         RETURN 0;
16158     WHEN OTHERS THEN
16159         -- Standard Unexpected Error Logging
16160         INL_LOGGING_PVT.Log_UnexpecError (
16161             p_module_name    => g_module_name,
16162             p_procedure_name => l_program_name
16163         );
16164         IF FND_MSG_PUB.Check_Msg_Level(
16165             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
16166         ) THEN
16167             FND_MSG_PUB.Add_Exc_Msg(
16168                 p_pkg_name       => g_pkg_name,
16169                 p_procedure_name => l_program_name
16170             );
16171         END IF;
16172         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
16173         IF l_lock_handle IS NOT NULL THEN
16174             l_lock_status := DBMS_LOCK.Release(l_lock_handle);
16175         END IF;
16176         RETURN 0;
16177 END Select_LCMShipToProc;
16178 
16179 
16180 
16181 -- Utility name : Check_HeaderWithoutLine
16182 -- Type         : Private
16183 -- Function     : Select the interface records to process
16184 -- Pre-reqs     :
16185 -- Version    : Current version 1.0
16186 --
16187 -- Notes      :
16188 
16189 FUNCTION Check_HeaderWithoutLine(
16190     x_return_status     OUT NOCOPY VARCHAR2
16191 ) RETURN NUMBER IS
16192     l_program_name     CONSTANT VARCHAR2(30) := 'Check_HeaderWithoutLine';
16193 
16194     l_return_status VARCHAR2(1);
16195     l_debug_info    VARCHAR2(200);
16196 
16197     l_count_records NUMBER;
16198 
16199 BEGIN
16200     -- Standard Beginning of Procedure/Function Logging
16201     INL_LOGGING_PVT.Log_BeginProc(
16202         p_module_name    => g_module_name,
16203         p_procedure_name => l_program_name
16204     ) ;
16205     --  Initialize API return status to success
16206     x_return_status := L_FND_RET_STS_SUCCESS;
16207 
16208     l_debug_info := 'Header records with transaction_type = CREATE should have at least one line, verifying...';
16209     INL_LOGGING_PVT.Log_Statement(
16210         p_module_name      => g_module_name,
16211         p_procedure_name   => l_program_name,
16212         p_debug_info       => l_debug_info
16213     ) ;
16214 
16215     INSERT INTO inl_interface_errors (
16216             interface_error_id,             /*01*/
16217             parent_table_name,              /*02*/
16218             parent_table_id,                /*03*/
16219             column_name,                    /*04*/
16220             column_value,                   /*05*/
16221             processing_date,                /*06*/
16222             error_message_name,             /*07*/
16223             error_message,                  /*08*/
16224             token1_name,                    /*09*/
16225             token1_value,                   /*10*/
16226             created_by,                     /*11*/
16227             creation_date,                  /*12*/
16228             last_updated_by,                /*13*/
16229             last_update_date,               /*14*/
16230             last_update_login,              /*15*/
16231             program_id,                     /*16*/
16232             program_application_id,         /*17*/
16233             program_update_date,            /*18*/
16234             request_id                      /*19*/
16235         )
16236         SELECT
16237             inl_interface_errors_s.NEXTVAL, /*01*/
16238             'INL_SHIP_HEADERS_INT',         /*02*/
16239             h.ship_header_int_id,           /*03*/
16240             'ship_header_int_id',           /*04*/
16241             h.ship_header_int_id,           /*05*/
16242             SYSDATE,                        /*06*/
16243             'INL_FAILED_ON_CONC_SUB',       /*07*/
16244             'No Line has been found',       /*08*/
16245             'CONC',                         /*09*/
16246             'Run_ShipPreProcessor (step0)', /*10*/
16247             L_FND_USER_ID,                  /*11*/
16248             SYSDATE,                        /*12*/
16249             L_FND_USER_ID,                  /*13*/
16250             SYSDATE,                        /*14*/
16251             L_FND_USER_ID,                  /*15*/
16252             L_FND_CONC_PROGRAM_ID,          /*16*/
16253             L_FND_PROG_APPL_ID,             /*17*/
16254             SYSDATE,                        /*18*/
16255             L_FND_CONC_REQUEST_ID           /*19*/
16256     FROM inl_ship_headers_int h
16257     WHERE NVL(h.request_id,1) > 0
16258     AND h.processing_status_code = 'PENDING'
16259     AND h.transaction_type = 'CREATE'
16260     AND NOT EXISTS
16261         (SELECT 1
16262          FROM inl_ship_lines_int l
16263          WHERE l.ship_header_int_id = h.ship_header_int_id
16264          AND ROWNUM < 2);
16265 
16266     l_debug_info := 'Inserted '||SQL%ROWCOUNT ||' error messages into Interface Error table.';
16267     INL_LOGGING_PVT.Log_Statement(
16268         p_module_name      => g_module_name,
16269         p_procedure_name   => l_program_name,
16270         p_debug_info       => l_debug_info) ;
16271     IF SQL%ROWCOUNT > 0 THEN
16272         l_debug_info := 'Set Shipment Header Interface status to ERROR.';
16273         INL_LOGGING_PVT.Log_Statement(
16274             p_module_name      => g_module_name,
16275             p_procedure_name   => l_program_name,
16276             p_debug_info       => l_debug_info) ;
16277 
16278 
16279 
16280         UPDATE inl_ship_headers_int h
16281         SET h.processing_status_code      = 'ERROR'              ,
16282             h.request_id                  = L_FND_CONC_REQUEST_ID,
16283             h.last_updated_by             = L_FND_USER_ID        ,
16284             h.last_update_date            = SYSDATE              ,
16285             h.last_update_login           = L_FND_LOGIN_ID       ,
16286             h.program_id                  = L_FND_CONC_PROGRAM_ID,
16287             h.program_update_date         = SYSDATE              ,
16288             h.program_application_id      = L_FND_PROG_APPL_ID
16289         WHERE NVL(h.request_id,1) > 0
16290         AND processing_status_code = 'PENDING'
16291         AND transaction_type = 'CREATE'
16292         AND NOT EXISTS
16293             (SELECT 1
16294              FROM inl_ship_lines_int l
16295              WHERE l.ship_header_int_id = h.ship_header_int_id
16296              AND ROWNUM < 2);
16297     END IF;
16298     -- Standard End of Procedure/Function Logging
16299     INL_LOGGING_PVT.Log_EndProc(
16300         p_module_name    => g_module_name,
16301         p_procedure_name => l_program_name);
16302 
16303     RETURN NVL(sql%ROWCOUNT,0);
16304 EXCEPTION
16305     WHEN L_FND_EXC_ERROR THEN
16306         -- Standard Expected Error Logging
16307         INL_LOGGING_PVT.Log_ExpecError (
16308             p_module_name    => g_module_name,
16309             p_procedure_name => l_program_name
16310         );
16311         x_return_status := L_FND_RET_STS_ERROR;
16312         RETURN 0;
16313     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
16314         -- Standard Unexpected Error Logging
16315         INL_LOGGING_PVT.Log_UnexpecError (
16316             p_module_name    => g_module_name,
16317             p_procedure_name => l_program_name
16318         );
16319         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
16320         RETURN 0;
16321     WHEN OTHERS THEN
16322         -- Standard Unexpected Error Logging
16323         INL_LOGGING_PVT.Log_UnexpecError (
16324             p_module_name    => g_module_name,
16325             p_procedure_name => l_program_name
16326         );
16327         IF FND_MSG_PUB.Check_Msg_Level(
16328             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
16329         ) THEN
16330             FND_MSG_PUB.Add_Exc_Msg(
16331                 p_pkg_name       => g_pkg_name,
16332                 p_procedure_name => l_program_name
16333             );
16334         END IF;
16335         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
16336         RETURN 0;
16337 END Check_HeaderWithoutLine;
16338 
16339 -- Utility name : Validate_shipHdrInt
16340 -- Type       : Private
16341 -- Function   : Validate the transaction type
16342 --
16343 -- Pre-reqs   : None
16344 -- Parameters :
16345 -- IN         :
16346 --
16347 -- IN OUT     : p_ship_hdr_int_rec  IN c_ship_hdr_int%ROWTYPE
16348 --              x_return_status      IN OUT NOCOPY VARCHAR2
16349 
16350 -- Version    : Current version 1.0
16351 --
16352 -- Notes      :
16353 FUNCTION Validate_ShipHdrInt(
16354     x_ship_hdr_int_rec   IN OUT NOCOPY c_ship_hdr_int%ROWTYPE,
16355     x_return_status      IN OUT NOCOPY VARCHAR2
16356 ) RETURN BOOLEAN IS
16357     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_ShipHdrInt';
16358     l_return_status VARCHAR2(1) ;
16359     l_debug_info    VARCHAR2(400) ;
16360     l_response_int      BOOLEAN := TRUE;
16361     l_response      BOOLEAN := TRUE;
16362     l_ship_header_id NUMBER;
16363 BEGIN
16364     -- Standard Beginning of Procedure/Function Logging
16365     INL_LOGGING_PVT.Log_BeginProc(
16366         p_module_name    => g_module_name,
16367         p_procedure_name => l_program_name) ;
16368     --  Initialize API return status to success
16369     x_return_status      := L_FND_RET_STS_SUCCESS;
16370 
16371     IF x_ship_hdr_int_rec.transaction_type IN ('UPDATE','DELETE') --Bug#11794483C
16372     THEN
16373         l_ship_header_id := x_ship_hdr_int_rec.ship_header_id;
16374     END IF;
16375 
16376     l_debug_info := 'Call Validate_Organization';
16377     INL_LOGGING_PVT.Log_Statement(
16378         p_module_name    => g_module_name,
16379         p_procedure_name => l_program_name,
16380         p_debug_info     => l_debug_info) ;
16381 
16382     l_response_int := Validate_Organization(
16383         p_ship_header_int_id            => x_ship_hdr_int_rec.ship_header_int_id,
16384         p_validation_flag               => x_ship_hdr_int_rec.validation_flag,
16385         p_ship_header_id                => l_ship_header_id,
16386         x_organization_id               => x_ship_hdr_int_rec.organization_id,
16387         x_organization_code             => x_ship_hdr_int_rec.organization_code,
16388         x_org_id                        => x_ship_hdr_int_rec.org_id,
16389         x_user_defined_ship_num_code    => x_ship_hdr_int_rec.user_defined_ship_num_code,
16390         x_manual_ship_num_type          => x_ship_hdr_int_rec.manual_ship_num_type,
16391         x_LCM_FLOW                      => x_ship_hdr_int_rec.LCM_FLOW,
16392         x_legal_entity_id               => x_ship_hdr_int_rec.legal_entity_id,
16393         x_return_status                 => l_return_status) ;
16394 
16395     -- If any errors happen abort API.
16396     IF l_return_status = L_FND_RET_STS_ERROR THEN
16397         RAISE L_FND_EXC_ERROR;
16398     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
16399         RAISE L_FND_EXC_UNEXPECTED_ERROR;
16400     END IF;
16401     IF (l_response_int)
16402     THEN
16403         l_debug_info := 'True';
16404     ELSE
16405         l_debug_info := 'False';
16406         l_response := l_response_int;
16407     END IF;
16408     INL_LOGGING_PVT.Log_Variable(
16409         p_module_name    => g_module_name,
16410         p_procedure_name => l_program_name,
16411         p_var_name       => 'l_response_int',
16412         p_var_value      => l_debug_info);
16413 
16414     INL_LOGGING_PVT.Log_Variable(
16415         p_module_name    => g_module_name,
16416         p_procedure_name => l_program_name,
16417         p_var_name       => 'x_ship_hdr_int_rec.ship_num',
16418         p_var_value      => x_ship_hdr_int_rec.ship_num);
16419 
16420     l_debug_info := 'Transaction Type validation';
16421     INL_LOGGING_PVT.Log_Statement(
16422         p_module_name      => g_module_name,
16423         p_procedure_name   => l_program_name,
16424         p_debug_info       => l_debug_info);
16425 
16426     l_response_int :=
16427         Validate_HdrTrxType(
16428                     p_ship_header_int_id => x_ship_hdr_int_rec.ship_header_int_id                ,
16429                     p_transaction_type   => x_ship_hdr_int_rec.transaction_type ,
16430                     p_ship_date          => x_ship_hdr_int_rec.ship_date        ,
16431                     p_organization_id    => x_ship_hdr_int_rec.organization_id  ,
16432                     p_organization_code  => x_ship_hdr_int_rec.organization_code,
16433                     p_location_id        => x_ship_hdr_int_rec.location_id      ,
16434                     p_location_code      => x_ship_hdr_int_rec.location_code    ,
16435                     p_rcv_enabled_flag   => x_ship_hdr_int_rec.rcv_enabled_flag ,
16436                     p_last_task_code     => x_ship_hdr_int_rec.last_task_code   ,
16437                     p_ship_type_id       => x_ship_hdr_int_rec.ship_type_id     ,
16438                     p_ship_type_code     => x_ship_hdr_int_rec.ship_type_code   ,
16439                     x_ship_num           => x_ship_hdr_int_rec.ship_num         ,
16440                     x_ship_header_id     => x_ship_hdr_int_rec.ship_header_id   ,
16441                     x_return_status      => l_return_status)
16442     ;
16443 
16444     -- If any errors happen abort API.
16445     IF l_return_status = L_FND_RET_STS_ERROR THEN
16446         RAISE L_FND_EXC_ERROR;
16447     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
16448         RAISE L_FND_EXC_UNEXPECTED_ERROR;
16449     END IF;
16450     IF (l_response_int)
16451     THEN
16452         l_debug_info := 'True';
16453     ELSE
16454         l_debug_info := 'False';
16455         l_response := l_response_int;
16456     END IF;
16457     INL_LOGGING_PVT.Log_Variable(
16458         p_module_name    => g_module_name,
16459         p_procedure_name => l_program_name,
16460         p_var_name       => 'l_response_int',
16461         p_var_value      => l_debug_info);
16462     INL_LOGGING_PVT.Log_Variable(
16463         p_module_name    => g_module_name,
16464         p_procedure_name => l_program_name,
16465         p_var_name       => 'x_ship_hdr_int_rec.ship_num',
16466         p_var_value      => x_ship_hdr_int_rec.ship_num);
16467 
16468 
16469 
16470     IF (l_response)
16471     THEN
16472         IF x_ship_hdr_int_rec.validation_flag NOT IN ('Y', 'N') THEN --FROM Validate_ValidationFlag
16473             l_response := FALSE;
16474             IF (l_response)
16475             THEN
16476                 l_debug_info := 'True';
16477             ELSE
16478                 l_debug_info := 'False';
16479             END IF;
16480             INL_LOGGING_PVT.Log_Variable(
16481                 p_module_name    => g_module_name,
16482                 p_procedure_name => l_program_name,
16483                 p_var_name       => 'l_response',
16484                 p_var_value      => l_debug_info);
16485             -- Add a line into inl_ship_errors
16486             Handle_InterfError(
16487                 p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
16488                 p_parent_table_id    => x_ship_hdr_int_rec.ship_header_int_id,
16489                 p_column_name        => 'VALIDATION_FLAG',
16490                 p_column_value       => x_ship_hdr_int_rec.validation_flag,
16491                 p_error_message_name => 'INL_ERR_VALIDATION_FLAG_INV',
16492                 x_return_status      => l_return_status) ;
16493             -- If unexpected errors happen abort
16494             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
16495                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
16496             END IF;
16497         END IF;
16498         -- Shipment Number validation
16499         l_debug_info := 'Call Validate_ShipNum ';
16500         INL_LOGGING_PVT.Log_Statement(
16501             p_module_name    => g_module_name,
16502             p_procedure_name => l_program_name,
16503             p_debug_info     => l_debug_info);
16504 
16505         l_response_int :=
16506             Validate_ShipNum(
16507                     p_ship_header_int_id            => x_ship_hdr_int_rec.ship_header_int_id,
16508                     p_organization_id               => x_ship_hdr_int_rec.organization_id,
16509                     p_validation_flag               => x_ship_hdr_int_rec.validation_flag,
16510                     p_transaction_type              => x_ship_hdr_int_rec.transaction_type,
16511                     p_user_defined_ship_num_code    => x_ship_hdr_int_rec.user_defined_ship_num_code,
16512                     p_LCM_FLOW                      => x_ship_hdr_int_rec.LCM_FLOW,
16513                     p_manual_ship_num_type          => x_ship_hdr_int_rec.manual_ship_num_type,
16514                     p_ship_num                      => x_ship_hdr_int_rec.ship_num,
16515                     x_return_status                 => l_return_status
16516         ) ;
16517 
16518         -- If any errors happen abort API.
16519         IF l_return_status = L_FND_RET_STS_ERROR THEN
16520             RAISE L_FND_EXC_ERROR;
16521         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
16522             RAISE L_FND_EXC_UNEXPECTED_ERROR;
16523         END IF;
16524         IF (l_response_int)
16525         THEN
16526             l_debug_info := 'True';
16527         ELSE
16528             l_debug_info := 'False';
16529             l_response := l_response_int;
16530         END IF;
16531         INL_LOGGING_PVT.Log_Variable(
16532             p_module_name    => g_module_name,
16533             p_procedure_name => l_program_name,
16534             p_var_name       => 'l_response_int',
16535             p_var_value      => l_debug_info);
16536 
16537         IF x_ship_hdr_int_rec.transaction_type = 'CREATE'
16538         THEN
16539             -- Shipment Type validation
16540             l_debug_info := 'Call Validate_ShipType';
16541             INL_LOGGING_PVT.Log_Statement(
16542                 p_module_name      => g_module_name,
16543                 p_procedure_name   => l_program_name,
16544                 p_debug_info       => l_debug_info) ;
16545 
16546             l_response_int :=
16547                     Validate_ShipType(
16548                             p_ship_header_int_id => x_ship_hdr_int_rec.ship_header_int_id,
16549                             p_validation_flag    => x_ship_hdr_int_rec.validation_flag,
16550                             x_ship_type_id       => x_ship_hdr_int_rec.ship_type_id,
16551                             x_ship_type_code     => x_ship_hdr_int_rec.ship_type_code,
16552                             x_return_status      => l_return_status);
16553             -- If any errors happen abort API.
16554             IF l_return_status = L_FND_RET_STS_ERROR THEN
16555                 RAISE L_FND_EXC_ERROR;
16556             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
16557                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
16558             END IF;
16559             IF (l_response_int)
16560             THEN
16561                 l_debug_info := 'True';
16562             ELSE
16563                 l_debug_info := 'False';
16564                 l_response := l_response_int;
16565             END IF;
16566             INL_LOGGING_PVT.Log_Variable(
16567                 p_module_name    => g_module_name,
16568                 p_procedure_name => l_program_name,
16569                 p_var_name       => 'l_response_int',
16570                 p_var_value      => l_debug_info);
16571 
16572             -- Location derivation and validation
16573             l_debug_info := 'Call Validate_Location';
16574             INL_LOGGING_PVT.Log_Statement(
16575                 p_module_name      => g_module_name,
16576                 p_procedure_name   => l_program_name,
16577                 p_debug_info       => l_debug_info) ;
16578 
16579             l_response_int :=
16580                     Validate_Location(
16581                             p_ship_header_int_id => x_ship_hdr_int_rec.ship_header_int_id,
16582                             p_validation_flag    => x_ship_hdr_int_rec.validation_flag,
16583                             p_organization_id    => x_ship_hdr_int_rec.organization_id,
16584                             x_location_id        => x_ship_hdr_int_rec.location_id,
16585                             x_location_code      => x_ship_hdr_int_rec.location_code,
16586                             x_dflt_country       => x_ship_hdr_int_rec.dflt_country,
16587                             x_return_status      => l_return_status);
16588 
16589             -- If any errors happen abort API.
16590             IF l_return_status = L_FND_RET_STS_ERROR THEN
16591                 RAISE L_FND_EXC_ERROR;
16592             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
16593                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
16594             END IF;
16595             IF (l_response_int)
16596             THEN
16597                 l_debug_info := 'True';
16598             ELSE
16599                 l_debug_info := 'False';
16600                 l_response := l_response_int;
16601             END IF;
16602             INL_LOGGING_PVT.Log_Variable(
16603                 p_module_name    => g_module_name,
16604                 p_procedure_name => l_program_name,
16605                 p_var_name       => 'l_response_int',
16606                 p_var_value      => l_debug_info);
16607 
16608         END IF;
16609     END IF;
16610 
16611     -- Standard End of Procedure/Function Logging
16612     INL_LOGGING_PVT.Log_EndProc(
16613         p_module_name    => g_module_name,
16614         p_procedure_name => l_program_name);
16615     RETURN l_response;
16616 EXCEPTION
16617     WHEN L_FND_EXC_ERROR THEN
16618         -- Standard Expected Error Logging
16619         INL_LOGGING_PVT.Log_ExpecError (
16620             p_module_name    => g_module_name,
16621             p_procedure_name => l_program_name);
16622         RETURN FND_API.to_boolean(L_FND_FALSE) ;
16623     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
16624         -- Standard Unexpected Error Logging
16625         INL_LOGGING_PVT.Log_UnexpecError (
16626             p_module_name    => g_module_name,
16627             p_procedure_name => l_program_name);
16628         RETURN FND_API.to_boolean(L_FND_FALSE) ;
16629     WHEN OTHERS THEN
16630         -- Standard Unexpected Error Logging
16631         INL_LOGGING_PVT.Log_UnexpecError (
16632             p_module_name    => g_module_name,
16633             p_procedure_name => l_program_name);
16634         IF FND_MSG_PUB.Check_Msg_Level(
16635             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
16636         ) THEN
16637             FND_MSG_PUB.Add_Exc_Msg(
16638                 p_pkg_name       => g_pkg_name,
16639                 p_procedure_name => l_program_name);
16640         END IF;
16641         RETURN FND_API.to_boolean(L_FND_FALSE) ;
16642 END Validate_shipHdrInt;
16643 
16644 -- Utility name : Validate_shipLinInt
16645 -- Type       : Private
16646 -- Function   : Validate the transaction type
16647 --
16648 -- Pre-reqs   : None
16649 -- Parameters :
16650 -- IN         :
16651 --              p_transaction_type  IN VARCHAR2,
16652 --              p_validation_flag   IN VARCHAR2,
16653 --              p_dflt_country      IN VARCHAR2,
16654 --              p_ship_type_id      IN NUMBER,
16655 --              p_organization_id   IN NUMBER,
16656 --              p_org_id            IN NUMBER,
16657 --              p_ship_header_id    IN NUMBER,
16658 --              p_interface_source_code IN VARCHAR2
16659 --
16660 -- IN OUT     : x_ship_ln_int_lst   IN OUT NOCOPY ship_ln_int_list_type,
16661 --          .   x_return_status      IN OUT NOCOPY VARCHAR2
16662 --
16663 -- Version    : Current version 1.0
16664 --
16665 -- Notes      :
16666 FUNCTION Validate_ShipLinInt(
16667     p_transaction_type  IN VARCHAR2,
16668     p_validation_flag   IN VARCHAR2,
16669     p_dflt_country      IN VARCHAR2,
16670     p_ship_type_id      IN NUMBER,
16671     p_organization_id   IN NUMBER,
16672     p_org_id            IN NUMBER,
16673     p_ship_header_id    IN NUMBER,
16674     p_interface_source_code IN VARCHAR2,
16675     x_ship_ln_int_lst   IN OUT NOCOPY ship_ln_int_list_type,
16676     x_return_status     IN OUT NOCOPY VARCHAR2
16677 ) RETURN BOOLEAN IS
16678     l_program_name     CONSTANT VARCHAR2(30) := 'Validate_ShipLinInt';
16679     l_return_status VARCHAR2(1) ;
16680     l_debug_info    VARCHAR2(400) ;
16681     l_response_int  BOOLEAN := TRUE;
16682     l_response      BOOLEAN := TRUE;
16683 
16684 BEGIN
16685     -- Standard Beginning of Procedure/Function Logging
16686     INL_LOGGING_PVT.Log_BeginProc(
16687         p_module_name    => g_module_name,
16688         p_procedure_name => l_program_name) ;
16689     --  Initialize API return status to success
16690     x_return_status      := L_FND_RET_STS_SUCCESS;
16691 
16692     l_debug_info := 'Transaction Type validation: '||p_transaction_type;
16693     INL_LOGGING_PVT.Log_Statement(
16694         p_module_name      => g_module_name,
16695         p_procedure_name   => l_program_name,
16696         p_debug_info       => l_debug_info);
16697 
16698    IF p_transaction_type = 'CREATE' THEN
16699        l_response_int :=
16700             validate_LnCreateTrxType(
16701                 p_validation_flag => p_validation_flag,
16702                 p_dflt_country    => p_dflt_country,
16703                 p_ship_type_id    => p_ship_type_id,
16704                 p_organization_id => p_organization_id,
16705                 p_org_id          => p_org_id,
16706                 p_interface_source_code => p_interface_source_code,
16707                 x_ship_ln_int_lst => x_ship_ln_int_lst,
16708                 x_return_status   => l_return_status
16709             );
16710         -- If any errors happen abort API.
16711     ELSIF p_transaction_type = 'UPDATE' THEN
16712         l_response_int :=
16713             validate_LnUpdateTrxType(
16714                 p_validation_flag => p_validation_flag,
16715                 p_ship_header_id  => p_ship_header_id,
16716                 p_organization_id => p_organization_id,
16717                 p_interface_source_code => p_interface_source_code,
16718                 x_ship_ln_int_lst => x_ship_ln_int_lst,
16719                 x_return_status   => l_return_status
16720             );
16721     END IF;
16722     -- If any errors happen abort API.
16723     IF l_return_status = L_FND_RET_STS_ERROR THEN
16724         RAISE L_FND_EXC_ERROR;
16725     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
16726         RAISE L_FND_EXC_UNEXPECTED_ERROR;
16727     END IF;
16728     IF (l_response_int)
16729     THEN
16730         l_debug_info := 'True';
16731     ELSE
16732         l_debug_info := 'False';
16733         l_response := l_response_int;
16734     END IF;
16735     INL_LOGGING_PVT.Log_Variable(
16736         p_module_name    => g_module_name,
16737         p_procedure_name => l_program_name,
16738         p_var_name       => 'l_response_int',
16739         p_var_value      => l_debug_info);
16740 
16741     -- Standard End of Procedure/Function Logging
16742     INL_LOGGING_PVT.Log_EndProc(
16743         p_module_name    => g_module_name,
16744         p_procedure_name => l_program_name);
16745     RETURN l_response;
16746 EXCEPTION
16747     WHEN L_FND_EXC_ERROR THEN
16748         -- Standard Expected Error Logging
16749         INL_LOGGING_PVT.Log_ExpecError (
16750             p_module_name    => g_module_name,
16751             p_procedure_name => l_program_name);
16752         RETURN FND_API.to_boolean(L_FND_FALSE) ;
16753     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
16754         -- Standard Unexpected Error Logging
16755         INL_LOGGING_PVT.Log_UnexpecError (
16756             p_module_name    => g_module_name,
16757             p_procedure_name => l_program_name);
16758         RETURN FND_API.to_boolean(L_FND_FALSE) ;
16759     WHEN OTHERS THEN
16760         -- Standard Unexpected Error Logging
16761         INL_LOGGING_PVT.Log_UnexpecError (
16762             p_module_name    => g_module_name,
16763             p_procedure_name => l_program_name);
16764         IF FND_MSG_PUB.Check_Msg_Level(
16765             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
16766         ) THEN
16767             FND_MSG_PUB.Add_Exc_Msg(
16768                 p_pkg_name       => g_pkg_name,
16769                 p_procedure_name => l_program_name);
16770         END IF;
16771         RETURN FND_API.to_boolean(L_FND_FALSE) ;
16772 END Validate_shipLinInt;
16773 
16774 -- API name   : Import_LCMShipments
16775 -- Type       : Public
16776 -- Function   : Main Import procedure. It calls the Pre and Post
16777 --              processors to validate and import a Shipment.
16778 --
16779 -- Pre-reqs   : None
16780 -- Parameters :
16781 -- IN         : p_api_version   IN NUMBER
16782 --              p_init_msg_list IN VARCHAR2 := L_FND_FALSE
16783 --              p_commit        IN VARCHAR2 := L_FND_FALSE
16784 --              p_group_id      IN NUMBER
16785 --              p_simulation_id IN NUMBER DEFAULT NULL
16786 --
16787 -- OUT        : x_return_status OUT NOCOPY VARCHAR2
16788 -- OUT        : x_msg_count     OUT NOCOPY NUMBER
16789 -- OUT        : x_msg_data      OUT NOCOPY VARCHAR2
16790 --
16791 -- Version    : Current version 1.0
16792 --
16793 -- Notes      :
16794 PROCEDURE Import_LCMShipments(
16795     p_api_version   IN NUMBER,
16796     p_init_msg_list IN VARCHAR2 := L_FND_FALSE,
16797     p_commit        IN VARCHAR2 := L_FND_FALSE,
16798     p_group_id      IN NUMBER,
16799     p_simulation_id IN NUMBER DEFAULT NULL,
16800     x_return_status OUT NOCOPY VARCHAR2,
16801     x_msg_count     OUT NOCOPY NUMBER,
16802     x_msg_data      OUT NOCOPY VARCHAR2
16803 ) IS
16804 
16805     l_ship_hdr_idx      NUMBER:=0;
16806     l_ship_ln_grp_idx   NUMBER;
16807     l_ship_ln_idx       NUMBER;
16808 
16809     l_program_name      CONSTANT VARCHAR2(30) := 'Import_LCMShipments2';
16810     l_api_version   CONSTANT NUMBER       := 1.0;
16811     l_return_status VARCHAR2(1);
16812     l_init_msg_list      VARCHAR2(2000) := L_FND_FALSE;
16813     l_commit             VARCHAR2(1)    := L_FND_FALSE;
16814     l_msg_count     NUMBER;
16815     l_msg_data      VARCHAR2(2000);
16816     l_debug_info    VARCHAR2(200);
16817 
16818     CURSOR c_ship_hdr_int_err
16819     IS
16820         SELECT
16821             ship_header_int_id
16822         FROM inl_ship_headers_int h
16823         WHERE request_id = l_fnd_conc_request_id_int
16824         AND processing_status_code = 'PENDING';
16825 
16826     TYPE ship_hdr_int_err_list_type
16827         IS
16828         TABLE OF c_ship_hdr_int_err%ROWTYPE INDEX BY BINARY_INTEGER;
16829 
16830     l_ship_hdr_int_err_list ship_hdr_int_err_list_type;
16831 
16832     l_commit_cycle  VARCHAR2(1);
16833     l_rec_num       NUMBER;
16834     l_ship_hdr_int_validation BOOLEAN;
16835     l_ship_ln_int_validation  BOOLEAN;
16836 
16837     l_ship_hdr_int_list ship_hdr_int_list_type;
16838     l_ship_ln_int_list   ship_ln_int_list_type;
16839 
16840     l_previous_access_mode  VARCHAR2(1) :=mo_global.get_access_mode();
16841     l_previous_org_id       NUMBER(15)  :=mo_global.get_current_org_id();
16842     l_current_org_id        NUMBER(15);
16843     l_varchardate           VARCHAR2(10) := TO_CHAR(SYSDATE,'DDDSSSS');
16844 
16845     -- Bug #16310024
16846     l_check_submit VARCHAR2(1);
16847     l_last_task_code VARCHAR2(25);
16848     l_organization_id NUMBER;
16849     l_rule_package_name VARCHAR2(100);
16850     -- Bug #16310024
16851 BEGIN
16852     -- Standard Beginning of Procedure/Function Logging
16853     INL_LOGGING_PVT.Log_BeginProc(
16854         p_module_name    => g_module_name,
16855         p_procedure_name => l_program_name) ;
16856     -- Standard Start of API savepoint
16857     SAVEPOINT Import_LCMShipments_PVT;
16858     -- Initialize message list if p_init_msg_list is set to TRUE.
16859     IF FND_API.to_Boolean(p_init_msg_list) THEN
16860         FND_MSG_PUB.initialize;
16861     END IF;
16862     -- Standard call to check for call compatibility
16863     IF NOT FND_API.Compatible_API_Call(
16864             p_current_version_number => l_api_version,
16865             p_caller_version_number => p_api_version,
16866             p_api_name => l_program_name,
16867             p_pkg_name => g_pkg_name ) THEN
16868         RAISE L_FND_EXC_UNEXPECTED_ERROR;
16869     END IF;
16870     --  Initialize API return status to success
16871     x_return_status := L_FND_RET_STS_SUCCESS;
16872 
16873 --Bug#11794483B
16874     INL_LOGGING_PVT.Log_Statement(
16875         p_module_name      => g_module_name,
16876         p_procedure_name   => l_program_name,
16877         p_debug_info       => 'Verify if request ID is generic:'||l_fnd_conc_request_id);
16878 
16879     IF l_fnd_conc_request_id = -1 THEN
16880         l_fnd_conc_request_id_int := TO_NUMBER(l_varchardate||TO_CHAR(SYSDATE,'DDDSSSS'))*-1;
16881         INL_LOGGING_PVT.Log_Variable(
16882             p_module_name    => g_module_name,
16883             p_procedure_name => l_program_name,
16884             p_var_name       => 'l_fnd_conc_request_id_int',
16885             p_var_value      => l_fnd_conc_request_id_int
16886         ) ;
16887     ELSE
16888         l_fnd_conc_request_id_int := l_fnd_conc_request_id*-1;
16889     END IF;
16890 --Bug#11794483B
16891 
16892     l_current_org_id      := NVL(l_previous_org_id,-999);--Bug#10381495
16893     INL_LOGGING_PVT.Log_Variable(
16894         p_module_name    => g_module_name,
16895         p_procedure_name => l_program_name,
16896         p_var_name       => 'l_current_org_id',
16897         p_var_value      => l_current_org_id
16898     ) ;
16899     INL_LOGGING_PVT.Log_Variable(
16900         p_module_name    => g_module_name,
16901         p_procedure_name => l_program_name,
16902         p_var_name       => 'p_group_id',
16903         p_var_value      => p_group_id
16904     ) ;
16905     INL_LOGGING_PVT.Log_Variable(
16906         p_module_name    => g_module_name,
16907         p_procedure_name => l_program_name,
16908         p_var_name       => 'p_simulation_id',
16909         p_var_value      => p_simulation_id
16910     ) ;
16911 
16912 -- <#Bug 8979947>
16913 /*
16914     l_debug_info := 'Check profile INL_INTERFACE_IMPORT_COMMIT_CYCLE';
16915     INL_LOGGING_PVT.Log_Statement (
16916         p_module_name => g_module_name,
16917         p_procedure_name => l_program_name,
16918         p_debug_info => l_debug_info
16919     );
16920 
16921     IF FND_API.To_Boolean(p_commit) THEN
16922         l_commit_cycle := NVL(FND_PROFILE.VALUE('INL_SHIP_IMPORT_COMMIT_CYCLE'),'F');  -- dependence
16923     END IF;
16924 
16925 */
16926 
16927     IF FND_API.To_Boolean(p_commit) THEN
16928         l_commit_cycle := 'P';
16929     END IF;
16930 
16931 -- <#Bug /8979947>
16932 
16933     INL_LOGGING_PVT.Log_Statement(
16934         p_module_name      => g_module_name,
16935         p_procedure_name   => l_program_name,
16936         p_debug_info       => 'Verify if exist any header record without line');
16937 
16938     G_RECORDS_PROCESSED:= Check_HeaderWithoutLine(
16939                                 x_return_status => l_return_status
16940                             );
16941 
16942     -- If any errors happen abort API.
16943     IF l_return_status = L_FND_RET_STS_ERROR THEN
16944         RAISE L_FND_EXC_ERROR;
16945     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
16946         RAISE L_FND_EXC_UNEXPECTED_ERROR;
16947     END IF;
16948 
16949     LOOP
16950         INL_LOGGING_PVT.Log_Statement(
16951             p_module_name      => g_module_name,
16952             p_procedure_name   => l_program_name,
16953             p_debug_info       => 'Getting header_interface records to process');
16954 
16955         l_rec_num:= select_LCMShipToProc(
16956             p_group_id      => p_group_id,
16957             p_simulation_id => p_simulation_id,
16958             x_return_status => l_return_status
16959         );
16960         -- If any errors happen abort API.
16961         IF l_return_status = L_FND_RET_STS_ERROR THEN
16962             RAISE L_FND_EXC_ERROR;
16963         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
16964             RAISE L_FND_EXC_UNEXPECTED_ERROR;
16965         END IF;
16966         INL_LOGGING_PVT.Log_Statement(
16967             p_module_name      => g_module_name,
16968             p_procedure_name   => l_program_name,
16969             p_debug_info       => l_rec_num||' records to process');
16970 
16971         OPEN c_ship_hdr_int;
16972         FETCH c_ship_hdr_int BULK COLLECT INTO l_ship_hdr_int_list;
16973         CLOSE c_ship_hdr_int;
16974 
16975         G_RECORDS_PROCESSED := G_RECORDS_PROCESSED + NVL(l_ship_hdr_int_list.COUNT, 0);
16976 
16977         INL_LOGGING_PVT.Log_Statement(
16978             p_module_name      => g_module_name,
16979             p_procedure_name   => l_program_name,
16980             p_debug_info       => NVL(l_ship_hdr_int_list.COUNT, 0)||' records have been found.');
16981 
16982         IF NVL(l_ship_hdr_int_list.COUNT, 0) > 0 THEN
16983             FOR l_ship_hdr_int_idx IN 1 .. l_ship_hdr_int_list.COUNT
16984             LOOP
16985                 BEGIN
16986                     l_ship_hdr_int_validation := TRUE;
16987                     l_ship_ln_int_validation  := TRUE;
16988 /*
16989                     IF l_commit_cycle = 'P'
16990                     THEN
16991 */
16992                         SAVEPOINT InlInterfacePvt_ILCMShip;
16993 /*
16994                     END IF;
16995 */
16996                     INL_LOGGING_PVT.Log_Variable(
16997                         p_module_name    => g_module_name,
16998                         p_procedure_name => l_program_name,
16999                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')ship_header_int_id',
17000                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_int_id) ;
17001 
17002                     INL_LOGGING_PVT.Log_Variable(
17003                         p_module_name    => g_module_name,
17004                         p_procedure_name => l_program_name,
17005                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')group_id',
17006                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).group_id) ;
17007 
17008                     INL_LOGGING_PVT.Log_Variable(
17009                         p_module_name    => g_module_name,
17010                         p_procedure_name => l_program_name,
17011                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')transaction_type',
17012                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).transaction_type) ;
17013 
17014                     INL_LOGGING_PVT.Log_Variable(
17015                         p_module_name    => g_module_name,
17016                         p_procedure_name => l_program_name,
17017                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')interface_source_code',
17018                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).interface_source_code) ;
17019 
17020                     INL_LOGGING_PVT.Log_Variable(
17021                         p_module_name    => g_module_name,
17022                         p_procedure_name => l_program_name,
17023                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')interface_source_table',
17024                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).interface_source_table) ;
17025 
17026                     INL_LOGGING_PVT.Log_Variable(
17027                         p_module_name    => g_module_name,
17028                         p_procedure_name => l_program_name,
17029                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')interface_source_line_id',
17030                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).interface_source_line_id) ;
17031 
17032                     INL_LOGGING_PVT.Log_Variable(
17033                         p_module_name    => g_module_name,
17034                         p_procedure_name => l_program_name,
17035                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')validation_flag',
17036                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).validation_flag) ;
17037 
17038                     INL_LOGGING_PVT.Log_Variable(
17039                         p_module_name    => g_module_name,
17040                         p_procedure_name => l_program_name,
17041                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')ship_num',
17042                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_num) ;
17043 
17044                     INL_LOGGING_PVT.Log_Variable(
17045                         p_module_name    => g_module_name,
17046                         p_procedure_name => l_program_name,
17047                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')ship_date',
17048                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_date) ;
17049 
17050                     INL_LOGGING_PVT.Log_Variable(
17051                         p_module_name    => g_module_name,
17052                         p_procedure_name => l_program_name,
17053                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')ship_type_id',
17054                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_type_id) ;
17055 
17056                     INL_LOGGING_PVT.Log_Variable(
17057                         p_module_name    => g_module_name,
17058                         p_procedure_name => l_program_name,
17059                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')legal_entity_id',
17060                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).legal_entity_id) ;
17061 
17062                     INL_LOGGING_PVT.Log_Variable(
17063                         p_module_name    => g_module_name,
17064                         p_procedure_name => l_program_name,
17065                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')organization_id',
17066                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).organization_id) ;
17067 
17068                     INL_LOGGING_PVT.Log_Variable(
17069                         p_module_name    => g_module_name,
17070                         p_procedure_name => l_program_name,
17071                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')location_id',
17072                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).location_id) ;
17073 
17074                     INL_LOGGING_PVT.Log_Variable(
17075                         p_module_name    => g_module_name,
17076                         p_procedure_name => l_program_name,
17077                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')org_id',
17078                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).org_id) ;
17079 
17080                     INL_LOGGING_PVT.Log_Variable(
17081                         p_module_name    => g_module_name,
17082                         p_procedure_name => l_program_name,
17083                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')last_task_code',
17084                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).last_task_code) ;
17085 
17086                     INL_LOGGING_PVT.Log_Variable(
17087                         p_module_name    => g_module_name,
17088                         p_procedure_name => l_program_name,
17089                         p_var_name       => 'l_ship_hdr_int_list('||l_ship_hdr_int_idx||')rcv_enabled_flag',
17090                         p_var_value      => l_ship_hdr_int_list(l_ship_hdr_int_idx).rcv_enabled_flag) ;
17091 
17092                     Reset_InterfError(
17093                         p_parent_table_name => 'INL_SHIP_HEADERS_INT',
17094                         p_parent_table_id => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_int_id,
17095                         x_return_status => l_return_status
17096                     );
17097                     -- If any errors happen abort API.
17098                     IF l_return_status = L_FND_RET_STS_ERROR THEN
17099                         RAISE L_FND_EXC_ERROR;
17100                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
17101                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
17102                     END IF;
17103 
17104                     l_debug_info := 'Validate Ship Header Int';
17105                     INL_LOGGING_PVT.Log_Statement(
17106                         p_module_name      => g_module_name,
17107                         p_procedure_name   => l_program_name,
17108                         p_debug_info       => l_debug_info);
17109 
17110                     l_ship_hdr_int_validation :=
17111                         Validate_shipHdrInt(
17112                             x_ship_hdr_int_rec   => l_ship_hdr_int_list(l_ship_hdr_int_idx),
17113                             x_return_status      => l_return_status);
17114 
17115                     -- If any errors happen abort API.
17116                     IF l_return_status = L_FND_RET_STS_ERROR THEN
17117                         RAISE L_FND_EXC_ERROR;
17118                     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
17119                         RAISE L_FND_EXC_UNEXPECTED_ERROR;
17120                     END IF;
17121 
17122                     OPEN c_ship_ln_int(l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_int_id);
17123                     FETCH c_ship_ln_int BULK COLLECT INTO l_ship_ln_int_list;
17124                     CLOSE c_ship_ln_int;
17125 
17126                     INL_LOGGING_PVT.Log_Statement(
17127                         p_module_name      => g_module_name,
17128                         p_procedure_name   => l_program_name,
17129                         p_debug_info       => NVL(l_ship_ln_int_list.COUNT, 0)||' lines have been found.');
17130 
17131                     IF NVL(l_ship_ln_int_list.COUNT, 0) > 0 THEN
17132                         l_ship_ln_int_validation :=
17133                             Validate_shipLinInt(
17134                                 p_transaction_type   => l_ship_hdr_int_list(l_ship_hdr_int_idx).transaction_type,
17135                                 p_validation_flag    => l_ship_hdr_int_list(l_ship_hdr_int_idx).validation_flag,
17136                                 p_dflt_country       => l_ship_hdr_int_list(l_ship_hdr_int_idx).dflt_country,
17137                                 p_ship_type_id       => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_type_id,
17138                                 p_organization_id    => l_ship_hdr_int_list(l_ship_hdr_int_idx).organization_id,
17139                                 p_org_id             => l_ship_hdr_int_list(l_ship_hdr_int_idx).org_id,
17140                                 p_ship_header_id     => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_id,
17141                                 p_interface_source_code => l_ship_hdr_int_list(l_ship_hdr_int_idx).interface_source_code,
17142                                 x_ship_ln_int_lst    => l_ship_ln_int_list,
17143                                 x_return_status      => l_return_status);
17144                         -- If any errors happen abort API.
17145                         IF l_return_status = L_FND_RET_STS_ERROR THEN
17146                             RAISE L_FND_EXC_ERROR;
17147                         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
17148                             RAISE L_FND_EXC_UNEXPECTED_ERROR;
17149                         END IF;
17150                     END IF;
17151 
17152                     IF l_ship_ln_int_validation
17153                         AND l_ship_hdr_int_validation
17154                     THEN
17155                         IF l_ship_hdr_int_list(l_ship_hdr_int_idx).last_task_code >= '10' THEN -- check if import should be executed
17156 
17157                             l_debug_info := 'Import Shipment Headers. Call Import_Headers';
17158                             INL_LOGGING_PVT.Log_Statement(
17159                                 p_module_name      => g_module_name,
17160                                 p_procedure_name   => l_program_name,
17161                                 p_debug_info       => l_debug_info);
17162 
17163                             Import_Headers(
17164                                 p_simulation_id    => p_simulation_id,
17165                                 x_ship_hdr_int_rec => l_ship_hdr_int_list(l_ship_hdr_int_idx),
17166                                 x_return_status    => l_return_status);
17167 
17168                             -- If any errors happen abort API.
17169                             IF l_return_status = L_FND_RET_STS_ERROR THEN
17170                                 RAISE L_FND_EXC_ERROR;
17171                             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
17172                                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
17173                             END IF;
17174 
17175                             IF l_ship_hdr_int_list(l_ship_hdr_int_idx).transaction_type = 'CREATE'
17176                                 OR l_ship_hdr_int_list(l_ship_hdr_int_idx).transaction_type = 'UPDATE'
17177                             THEN
17178                                 l_debug_info := 'Import Shipment Lines. Call Import_Lines for ship_header_id: ' || l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_int_id;
17179                                 INL_LOGGING_PVT.Log_Statement(
17180                                         p_module_name => g_module_name,
17181                                         p_procedure_name => l_program_name,
17182                                         p_debug_info => l_debug_info);
17183 
17184                                 Import_Lines(
17185                                     p_transaction_type  => l_ship_hdr_int_list(l_ship_hdr_int_idx).transaction_type,
17186                                     p_ship_header_int_id=> l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_int_id,
17187                                     p_ship_header_id    => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_id,
17188                                     x_ship_ln_int_lst   => l_ship_ln_int_list,
17189                                     x_return_status     => l_return_status
17190                                 );
17191 
17192                                 -- If any errors happen abort API.
17193                                 IF l_return_status = L_FND_RET_STS_ERROR THEN
17194                                     RAISE L_FND_EXC_ERROR;
17195                                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
17196                                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
17197                                 END IF;
17198                             END IF;
17199 
17200                             INL_LOGGING_PVT.Log_Statement(
17201                                 p_module_name => g_module_name,
17202                                 p_procedure_name => l_program_name,
17203                                 p_debug_info => 'Comparing l_current_org_id: '||l_current_org_id||' with l_ship_hdr_int_list(l_ship_hdr_int_idx).org_id:'||l_ship_hdr_int_list(l_ship_hdr_int_idx).org_id
17204                             );
17205                             --Bug#10381495
17206                             IF (l_current_org_id <> l_ship_hdr_int_list(l_ship_hdr_int_idx).org_id) THEN
17207                                 INL_LOGGING_PVT.Log_Statement(
17208                                     p_module_name => g_module_name,
17209                                     p_procedure_name => l_program_name,
17210                                     p_debug_info => 'Seting a new context from '||l_current_org_id||' to '||l_ship_hdr_int_list(l_ship_hdr_int_idx).org_id
17211                                 );
17212                                 mo_global.set_policy_context( 'S', l_ship_hdr_int_list(l_ship_hdr_int_idx).org_id);
17213                                 l_current_org_id := l_ship_hdr_int_list(l_ship_hdr_int_idx).org_id;
17214                                 INL_LOGGING_PVT.Log_Statement(
17215                                     p_module_name => g_module_name,
17216                                     p_procedure_name => l_program_name,
17217                                     p_debug_info => 'l_current_org_id: '||l_current_org_id
17218                                 );
17219                             END IF;
17220                             --Bug#10381495
17221 
17222                             -- Bug #16310024
17223                             IF l_organization_id IS NULL OR
17224                                l_organization_id <> l_ship_hdr_int_list(l_ship_hdr_int_idx).organization_id THEN
17225 
17226                                 l_organization_id := l_ship_hdr_int_list(l_ship_hdr_int_idx).organization_id;
17227                                 l_rule_package_name := NULL;
17228 
17229                                 INL_LOGGING_PVT.Log_Statement(
17230                                     p_module_name => g_module_name,
17231                                     p_procedure_name => l_program_name,
17232                                     p_debug_info => 'Get Rule package name for organization: ' || l_organization_id);
17233 
17234                                     SELECT r.package_name
17235                                     INTO l_rule_package_name
17236                                     FROM inl_rules_vl r,
17237                                         inl_parameters p
17238                                     WHERE r.rule_id (+) = p.rule_id
17239                                     AND r.enabled_flag (+) = 'Y'
17240                                     AND p.organization_id = l_organization_id;
17241 
17242                                 INL_LOGGING_PVT.Log_Variable(
17243                                     p_module_name => g_module_name,
17244                                     p_procedure_name => g_module_name,
17245                                     p_var_name => 'l_rule_package_name',
17246                                     p_var_value => l_rule_package_name);
17247 
17248                             END IF;
17249 
17250                             l_last_task_code := l_ship_hdr_int_list(l_ship_hdr_int_idx).last_task_code;
17251 
17252                             IF l_ship_hdr_int_list(l_ship_hdr_int_idx).interface_source_code = 'RCV' AND
17253                                l_ship_hdr_int_list(l_ship_hdr_int_idx).last_task_code = '60' AND
17254                                (l_rule_package_name IS NOT NULL)THEN
17255 
17256                                 l_debug_info := 'Call INL_RULE_GRP.Check_Condition.';
17257                                 INL_LOGGING_PVT.Log_Statement(
17258                                         p_module_name => g_module_name,
17259                                         p_procedure_name => l_program_name,
17260                                         p_debug_info => l_debug_info);
17261 
17262                                 l_check_submit := INL_RULE_GRP.Check_Condition(
17263                                                       p_api_version => 1.0,
17264                                                       p_init_msg_list => L_FND_FALSE,
17265                                                       p_commit =>  L_FND_FALSE,
17266                                                       p_ship_header_id => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_id,
17267                                                       p_rule_package_name => l_rule_package_name,
17268                                                       x_return_status => l_return_status,
17269                                                       x_msg_count => l_msg_count,
17270                                                       x_msg_data => l_msg_data);
17271 
17272                                 -- If any errors happen abort API.
17273                                 IF l_return_status = L_FND_RET_STS_ERROR THEN
17274                                     RAISE L_FND_EXC_ERROR;
17275                                 ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
17276                                     RAISE L_FND_EXC_UNEXPECTED_ERROR;
17277                                 END IF;
17278 
17279                                 INL_LOGGING_PVT.Log_Statement(
17280                                     p_module_name => g_module_name,
17281                                     p_procedure_name => l_program_name,
17282                                     p_debug_info => 'l_check_submit: '||l_check_submit);
17283 
17284                                 IF l_check_submit = 'N'  THEN
17285                                     l_last_task_code := '50';
17286                                 END IF;
17287                             END IF;
17288                             -- Bug #16310024
17289 
17290 
17291                             l_debug_info := 'Run the process action for each imported Shipment.';
17292                             INL_LOGGING_PVT.Log_Statement(
17293                                     p_module_name => g_module_name,
17294                                     p_procedure_name => l_program_name,
17295                                     p_debug_info => l_debug_info);
17296 
17297                             Run_ProcessAction(
17298                                 p_ship_header_id => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_id,
17299                                 p_last_task_code =>  l_last_task_code, -- l_ship_hdr_int_list(l_ship_hdr_int_idx).last_task_code, -- Bug #16310024
17300                                 x_return_status  => l_return_status
17301                             );
17302 
17303                             -- If any errors happen abort API.
17304                             IF l_return_status = L_FND_RET_STS_ERROR THEN
17305                                 RAISE L_FND_EXC_ERROR;
17306                             ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
17307                                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
17308                             END IF;
17309                             -- Set the number of LCM Shipments imported successfully.
17310                             -- This value will be latter stamped in the concurrent log
17311                             g_records_inserted := g_records_inserted + 1;
17312 
17313                             -- Bug #16310024
17314                             IF l_last_task_code = 60 THEN
17315                                 g_records_completed := g_records_completed + 1;
17316                             END IF;
17317                             -- Bug #16310024
17318 
17319                         END IF;
17320                         l_debug_info := 'Change Interface Status Code to COMPLETED';
17321                         INL_LOGGING_PVT.Log_Statement(
17322                             p_module_name      => g_module_name,
17323                             p_procedure_name   => l_program_name,
17324                             p_debug_info       => l_debug_info);
17325 
17326                         UPDATE inl_ship_headers_int
17327                         SET processing_status_code = 'COMPLETED'           ,
17328                             request_id             = L_FND_CONC_REQUEST_ID ,
17329                             last_updated_by        = L_FND_USER_ID         ,
17330                             last_update_date       = SYSDATE               ,
17331                             last_update_login      = L_FND_LOGIN_ID        ,
17332                             program_id             = L_FND_CONC_PROGRAM_ID ,
17333                             program_update_date    = SYSDATE               ,
17334                             program_application_id = L_FND_PROG_APPL_ID    ,
17335                             ship_header_id         = l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_id
17336                           WHERE ship_header_int_id = l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_int_id;
17337                     ELSE
17338                         Handle_InterfError(
17339                             p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
17340                             p_parent_table_id    => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_int_id,
17341                             p_column_name        => 'ship_header_int_id('||l_ship_hdr_int_idx||')',
17342                             p_column_value       => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_int_id,
17343                             p_error_message_name => 'INL_FAILED_ON_CONC_SUB',
17344                             p_token1_name        => 'CONC',
17345                             p_token1_value       => 'Validation failed',
17346                             x_return_status      => l_return_status);
17347                         -- If any errors happen abort API.
17348                         IF l_return_status = L_FND_RET_STS_ERROR THEN
17349                             RAISE L_FND_EXC_ERROR;
17350                         ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
17351                             RAISE L_FND_EXC_UNEXPECTED_ERROR;
17352                         END IF;
17353 
17354                     END IF;
17355                     IF l_commit_cycle = 'P' THEN
17356                         l_debug_info := 'Commit cycle is partial. Commiting every imported Shipment';
17357                         INL_LOGGING_PVT.Log_Statement(
17358                             p_module_name => g_module_name,
17359                             p_procedure_name => l_program_name,
17360                             p_debug_info => l_debug_info);
17361                         COMMIT WORK;
17362                     END IF;
17363                 --Bug#10436018
17364                 EXCEPTION
17365                     WHEN OTHERS THEN
17366 --                        IF L_commit_cycle = 'P' THEN
17367                             ROLLBACK TO InlInterfacePvt_ILCMShip;
17368                             Handle_InterfError(
17369                                 p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
17370                                 p_parent_table_id    => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_int_id,
17371                                 p_column_name        => 'ship_header_int_id('||l_ship_hdr_int_idx||')',
17372                                 p_column_value       => l_ship_hdr_int_list(l_ship_hdr_int_idx).ship_header_int_id,
17373                                 p_error_message_name => 'INL_FAILED_ON_CONC_SUB',
17374                                 p_token1_name        => 'CONC',
17375                                 p_token1_value       => 'Import_Headers exception',
17376                                 x_return_status      => l_return_status);
17377                             -- If unexpected errors happen abort
17378                             IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
17379                                 RAISE L_FND_EXC_UNEXPECTED_ERROR;
17380                             END IF;
17381                         IF L_commit_cycle = 'P' THEN
17382                               COMMIT WORK;
17383 --                        ELSE
17384 --                            RAISE L_FND_EXC_UNEXPECTED_ERROR;
17385                         END IF;
17386                 END;
17387                 --Bug#10436018
17388             END LOOP;
17389         ELSE
17390             EXIT;
17391         END IF;
17392     END LOOP;
17393 
17394     --Bug#10381495
17395     IF (l_current_org_id <> NVL(l_previous_org_id,-999)) THEN
17396         INL_LOGGING_PVT.Log_Statement(
17397             p_module_name => g_module_name,
17398             p_procedure_name => l_program_name,
17399             p_debug_info => 'Restore previous context: from '||l_current_org_id||' to '||l_previous_org_id
17400         );
17401         mo_global.set_policy_context( l_previous_access_mode, l_previous_org_id);
17402         l_current_org_id:= l_previous_org_id; --Bug#16198838/14707257
17403     END IF;
17404     --Bug#10381495
17405 
17406     IF NVL(G_RECORDS_PROCESSED,0) = 0 THEN
17407         -- Add a line into inl_ship_errors, No records found for processing
17408         -- -- Bug 13920858: Commented the code to avoid Error Messages getting Inserted into INL_INTERFACE_ERRORS table.
17409         l_debug_info := 'Error Mesage: No records found for processing.';
17410             INL_LOGGING_PVT.Log_Statement(
17411                 p_module_name      => g_module_name,
17412                 p_procedure_name   => l_program_name,
17413                 p_debug_info       => l_debug_info
17414             ) ;
17415 /*
17416         Handle_InterfError(
17417             p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
17418             p_parent_table_id    => 0,
17419             p_column_name        => 'P_GROUP_ID',
17420             p_column_value       => p_group_id,
17421             p_error_message_name => 'INL_NO_RECORDS_FOUND_ERR',
17422             x_return_status      => l_return_status);
17423         -- If unexpected errors happen abort
17424         IF l_return_status <> L_FND_RET_STS_SUCCESS THEN
17425             RAISE L_FND_EXC_UNEXPECTED_ERROR;
17426         END IF;
17427 */
17428 
17429     END IF;
17430 
17431     l_debug_info := 'Checking if any record remain from the selected records.';
17432     INL_LOGGING_PVT.Log_Statement(
17433         p_module_name      => g_module_name,
17434         p_procedure_name   => l_program_name,
17435         p_debug_info       => l_debug_info
17436     ) ;
17437 
17438     OPEN c_ship_hdr_int_err;
17439     FETCH c_ship_hdr_int_err BULK COLLECT INTO l_ship_hdr_int_err_list;
17440     CLOSE c_ship_hdr_int_err;
17441 
17442     IF NVL(l_ship_hdr_int_err_list.COUNT, 0) > 0 THEN
17443         l_debug_info := l_ship_hdr_int_err_list.COUNT||' records remain from the previous selected records('||l_fnd_conc_request_id_int||').';
17444         INL_LOGGING_PVT.Log_Statement(
17445             p_module_name      => g_module_name,
17446             p_procedure_name   => l_program_name,
17447             p_debug_info       => l_debug_info);
17448 
17449         FOR l_ship_hdr_int_idx IN 1 .. l_ship_hdr_int_err_list.COUNT
17450         LOOP
17451             Handle_InterfError(
17452                 p_parent_table_name  => 'INL_SHIP_HEADERS_INT',
17453                 p_parent_table_id    => l_ship_hdr_int_err_list(l_ship_hdr_int_idx).ship_header_int_id,
17454                 p_column_name        => 'l_ship_hdr_int_err_list('||l_ship_hdr_int_idx||')',
17455                 p_column_value       => l_ship_hdr_int_err_list(l_ship_hdr_int_idx).ship_header_int_id,
17456                 p_error_message_name => 'INL_FAILED_ON_CONC_SUB',
17457                 p_token1_name        => 'CONC',
17458                 p_token1_value       => 'Import_Headers problem',
17459                 x_return_status      => l_return_status);
17460 
17461         END LOOP;
17462 
17463     END IF;
17464 
17465     -- Bug #8264427
17466     -- Interface records that got completed successfully are removed
17467     -- from INL_SHIP_HEADERS_INT and INL_SHIP_LINES_INT
17468     Purge_LCMShipInt(
17469         p_api_version   => 1.0,
17470         p_init_msg_list => l_init_msg_list,
17471         p_commit        => l_commit,
17472         p_group_id      => p_group_id,
17473         x_return_status => l_return_status,
17474         x_msg_count     => l_msg_count,
17475         x_msg_data      => l_msg_data
17476     );
17477 
17478     -- If any errors happen abort API.
17479     IF l_return_status = L_FND_RET_STS_ERROR THEN
17480         RAISE L_FND_EXC_ERROR;
17481     ELSIF l_return_status = L_FND_RET_STS_UNEXP_ERROR THEN
17482         RAISE L_FND_EXC_UNEXPECTED_ERROR;
17483     END IF;
17484 
17485     -- Standard check of p_commit.
17486     IF FND_API.To_Boolean(p_commit) THEN
17487         COMMIT WORK;
17488     END IF;
17489     -- Standard call to get message count and if count is 1, get message info.
17490     FND_MSG_PUB.Count_And_Get(
17491         p_encoded => L_FND_FALSE,
17492         p_count => x_msg_count,
17493         p_data => x_msg_data) ;
17494     -- Standard End of Procedure/Function Logging
17495     INL_LOGGING_PVT.Log_EndProc(
17496         p_module_name    => g_module_name,
17497         p_procedure_name => l_program_name);
17498 
17499 EXCEPTION
17500     WHEN L_FND_EXC_ERROR THEN
17501         -- Standard Expected Error Logging
17502         INL_LOGGING_PVT.Log_ExpecError (
17503             p_module_name    => g_module_name,
17504             p_procedure_name => l_program_name);
17505         ROLLBACK TO Import_LCMShipments_PVT;
17506         x_return_status := L_FND_RET_STS_ERROR;
17507         FND_MSG_PUB.Count_And_Get(
17508             p_encoded => L_FND_FALSE,
17509             p_count   => x_msg_count,
17510             p_data    => x_msg_data);
17511         --Bug#10381495
17512         IF (l_current_org_id <> NVL(l_previous_org_id,-999)) THEN
17513             INL_LOGGING_PVT.Log_Statement(
17514                 p_module_name => g_module_name,
17515                 p_procedure_name => l_program_name,
17516                 p_debug_info => 'Restore previous context: from '||l_current_org_id||' to '||l_previous_org_id
17517             );
17518             mo_global.set_policy_context( l_previous_access_mode, l_previous_org_id);
17519         END IF;
17520         --Bug#10381495
17521     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
17522         -- Standard Unexpected Error Logging
17523         INL_LOGGING_PVT.Log_UnexpecError (
17524             p_module_name    => g_module_name,
17525             p_procedure_name => l_program_name);
17526         ROLLBACK TO Import_LCMShipments_PVT;
17527         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
17528         FND_MSG_PUB.Count_And_Get(
17529             p_encoded  => L_FND_FALSE,
17530             p_count    => x_msg_count,
17531             p_data     => x_msg_data);
17532         --Bug#10381495
17533         IF (l_current_org_id <> NVL(l_previous_org_id,-999)) THEN
17534             INL_LOGGING_PVT.Log_Statement(
17535                 p_module_name => g_module_name,
17536                 p_procedure_name => l_program_name,
17537                 p_debug_info => 'Restore previous context: from '||l_current_org_id||' to '||l_previous_org_id
17538             );
17539             mo_global.set_policy_context( l_previous_access_mode, l_previous_org_id);
17540         END IF;
17541         --Bug#10381495
17542     WHEN OTHERS THEN
17543         -- Standard Unexpected Error Logging
17544         INL_LOGGING_PVT.Log_UnexpecError (
17545             p_module_name    => g_module_name,
17546             p_procedure_name => l_program_name);
17547         ROLLBACK TO Import_LCMShipments_PVT;
17548         x_return_status := L_FND_RET_STS_UNEXP_ERROR ;
17549         IF FND_MSG_PUB.Check_Msg_Level(
17550             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
17551         ) THEN
17552             FND_MSG_PUB.Add_Exc_Msg(
17553                 p_pkg_name       => g_pkg_name,
17554                 p_procedure_name => l_program_name);
17555         END IF;
17556         FND_MSG_PUB.Count_And_Get(
17557             p_encoded => L_FND_FALSE,
17558             p_count   => x_msg_count,
17559             p_data    => x_msg_data);
17560         --Bug#10381495
17561         IF (l_current_org_id <> NVL(l_previous_org_id,-999)) THEN
17562             INL_LOGGING_PVT.Log_Statement(
17563                 p_module_name => g_module_name,
17564                 p_procedure_name => l_program_name,
17565                 p_debug_info => 'Restore previous context: from '||l_current_org_id||' to '||l_previous_org_id
17566             );
17567             mo_global.set_policy_context( l_previous_access_mode, l_previous_org_id);
17568         END IF;
17569         --Bug#10381495
17570 END Import_LCMShipments;
17571 
17572 -- SCM-051
17573 -- Utility name : Reset_MatchInt
17574 -- Type       : Private
17575 -- Function   : Reset Matches Interface records that got rejected because of
17576 --              the existence of Pending Update shipments.
17577 -- Pre-reqs   : None
17578 -- Parameters :
17579 -- IN         : p_ship_header_id IN NUMBER
17580 --
17581 -- OUT          x_return_status OUT NOCOPY VARCHAR2
17582 --
17583 -- Version    : Current version 1.0
17584 --
17585 -- Notes      :
17586 PROCEDURE Reset_MatchInt (p_ship_header_id IN NUMBER,
17587                           x_return_status OUT NOCOPY VARCHAR2
17588 ) IS
17589     l_program_name CONSTANT VARCHAR2(30):= 'Reset_MatchInt';
17590     l_return_status VARCHAR2(1);
17591     l_debug_info VARCHAR2(200);
17592     l_count_elc_pend_shipment NUMBER;
17593 
17594     CURSOR c_matches_int_error IS
17595     SELECT DISTINCT m.group_id
17596     FROM inl_matches_int m,
17597         rcv_transactions rt,
17598         inl_ship_lines_all sl
17599     WHERE sl.ship_line_id = rt.lcm_shipment_line_id
17600     AND rt.transaction_id = m.to_parent_table_id
17601     AND m.to_parent_table_name = 'RCV_TRANSACTIONS'
17602     AND m.processing_status_code = 'ERROR'
17603     AND sl.ship_header_id = p_ship_header_id;
17604 
17605     TYPE matches_int_error IS TABLE OF c_matches_int_error%ROWTYPE;
17606     l_matches_int_error matches_int_error;
17607 
17608 BEGIN
17609     -- Standard Beginning of Procedure/Function Logging
17610     INL_LOGGING_PVT.Log_BeginProc(p_module_name => g_module_name,
17611                                   p_procedure_name => l_program_name);
17612 
17613     INL_LOGGING_PVT.Log_Variable(p_module_name => g_module_name,
17614                                  p_procedure_name => l_program_name,
17615                                  p_var_name => 'p_ship_header_id',
17616                                  p_var_value => p_ship_header_id);
17617 
17618     --  Initialize API return status to success
17619     x_return_status := L_FND_RET_STS_SUCCESS;
17620 
17621     l_debug_info := 'Open cursor c_matches_int_error';
17622     INL_LOGGING_PVT.Log_Statement(p_module_name => g_module_name,
17623                                   p_procedure_name => l_program_name,
17624                                   p_debug_info => l_debug_info);
17625 
17626     -- Fetch Match records with error for shipment
17627     OPEN c_matches_int_error;
17628     FETCH c_matches_int_error BULK COLLECT INTO l_matches_int_error;
17629     CLOSE c_matches_int_error;
17630 
17631     IF NVL (l_matches_int_error.LAST, 0) > 0 THEN -- exists record with status = ERROR
17632         FOR i IN NVL(l_matches_int_error.FIRST, 0)..NVL(l_matches_int_error.LAST, 0)
17633         LOOP
17634             INL_LOGGING_PVT.Log_Variable(p_module_name => g_module_name,
17635                                  p_procedure_name => l_program_name,
17636                                  p_var_name => 'group_id',
17637                                  p_var_value => l_matches_int_error(i).group_id);
17638             SELECT COUNT(1)
17639             INTO l_count_elc_pend_shipment
17640             FROM inl_matches_int m,
17641                  rcv_transactions rt,
17642                  inl_ship_lines_all sl,
17643                  inl_ship_headers_all sh
17644             WHERE sh.ship_header_id = sl.ship_header_id
17645             AND sl.ship_line_id = rt.lcm_shipment_line_id
17646             AND rt.transaction_id = m.to_parent_table_id
17647             AND m.group_id = l_matches_int_error(i).group_id
17648             AND m.to_parent_table_name = 'RCV_TRANSACTIONS'
17649             AND sh.pending_update_flag = 'Y';
17650 
17651             INL_LOGGING_PVT.Log_Variable(p_module_name => g_module_name,
17652                                  p_procedure_name => l_program_name,
17653                                  p_var_name => 'l_count_elc_pend_shipment',
17654                                  p_var_value => l_count_elc_pend_shipment);
17655 
17656             IF NVL(l_count_elc_pend_shipment,0) = 0 THEN
17657                 l_debug_info := 'Update inl_matches_int to PENDING for group ID: ' || l_matches_int_error(i).group_id;
17658                 INL_LOGGING_PVT.Log_Statement(p_module_name => g_module_name,
17659                                               p_procedure_name => l_program_name,
17660                                               p_debug_info => l_debug_info);
17661 
17662                 UPDATE inl_matches_int mi
17663                 SET processing_status_code = 'PENDING',
17664                     mi.last_updated_by = L_FND_USER_ID,
17665                     mi.last_update_date = SYSDATE,
17666                     mi.last_update_login = L_FND_LOGIN_ID
17667                 WHERE group_id = l_matches_int_error(i).group_id;
17668              END IF;
17669         END LOOP;
17670     END IF;
17671     -- Standard End of Procedure/Function Logging
17672     INL_LOGGING_PVT.Log_EndProc(
17673         p_module_name    => g_module_name,
17674         p_procedure_name => l_program_name);
17675 EXCEPTION
17676     WHEN L_FND_EXC_ERROR THEN
17677         -- Standard Expected Error Logging
17678         INL_LOGGING_PVT.Log_ExpecError (
17679             p_module_name    => g_module_name,
17680             p_procedure_name => l_program_name);
17681         x_return_status := L_FND_RET_STS_ERROR;
17682     WHEN L_FND_EXC_UNEXPECTED_ERROR THEN
17683         -- Standard Unexpected Error Logging
17684         INL_LOGGING_PVT.Log_UnexpecError (
17685             p_module_name    => g_module_name,
17686             p_procedure_name => l_program_name);
17687         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
17688     WHEN OTHERS THEN
17689         -- Standard Unexpected Error Logging
17690         INL_LOGGING_PVT.Log_UnexpecError (
17691             p_module_name    => g_module_name,
17692             p_procedure_name => l_program_name);
17693         x_return_status := L_FND_RET_STS_UNEXP_ERROR;
17694         IF FND_MSG_PUB.Check_Msg_Level(
17695             p_message_level =>FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR
17696         ) THEN
17697             FND_MSG_PUB.Add_Exc_Msg(
17698                 p_pkg_name       => g_pkg_name,
17699                 p_procedure_name => l_program_name);
17700         END IF;
17701 END Reset_MatchInt;
17702 -- /SCM-051
17703 
17704 END INL_INTERFACE_PVT;