Sei sulla pagina 1di 17

CREATE OR REPLACE PACKAGE BODY APPS.

BSDM_OM_UPD_BPR_PKG
AS
/*$Header: BSDM_OM_UPD_BPR_PKG.PKB 1.0 2013/02/04 10:00:00 $ */
-- +=========================================================================
+|
-- | Koyo US
|
-- + ========================================================================
+|
-- |Owner : JTEKT
|
-- |Application : Oracle All Application
|
-- |Name : BSDM_OM_UPD_BPR_PKG.PKB
|
-- |Doc Ref :
|
-- |File Name : BSDM_OM_UPD_BPR_PKG.PKB
|
-- |Author : VIKAS MEHRA
|
-- |Date : 04-Feb-2013
|
-- |Description : OM Order Update Before Pick Release Interface
|
-- | This interface will updated the attributes at header and
|
-- | line level and freight terms.
|
-- |Pre-Req : Following setups are required prior to converstion
|
-- | 1. Customer
|
-- | 2. Item
|
-- |Usage :1. Interface should be completed.
|
-- | 2. Oracle public API will be used to import data from stagin
g|
-- | table into Oracle EBS base tables.
|
-- |
|
-- |Modification History:
|
-- |-------------------------------------------------------------------------
-|
-- |Modified By Date Ver Description
|
-- |SJINDAL 25-MAR-2013 1.1 ADDED attribute5 as per mail
|
-- | from Samir reference
|
-- | dkhosla_250313_1
|
-- |VMEHRA 21-MAY-2013 1.2 Modified query to fetch
|
-- | operating unit. refer to
|
-- | vmehra_21052013_1
|
-- |VMEHRA 05-Aug-2013 1.3 look for vmehra_08032013
|
-- |DKHOSLA 20-Aug-2013 1.4 look for dkhosla_0820
|
-- |VMEHRA 05-Sep-2013 1.5 Look for vmehra_05092013 ,
|
-- | as per mail from Samir
|
-- |DKHOSLA 21-OCT-2013 1.6 Restrict freight terms on the
|
-- | basis of AM STOCK AND AM SPORT
|
-- | Look for dkhosla_1021
|
-- |DKHOSLA 12-NOV-2013 1.7 Change order header attribute3
|
-- | rule as skayande dkhosla_12no
v|
-- |DKHOSLA 12-NOV-2013 1.8 Change order line attribute7 t
o|
-- | attribute6,ref dkhosla_12nov_
1|
-- |PSRIVASTAVA 04-FEB-2014 1.9 Updated for Freight Forwarder
|
-- | and Pool Point ID as per mail
|
-- | from DKHOSLA- psrivastava_4feb
|
-- |DKHOSLA 29-APR-2014 2.0 dkhosla_04292014 AS PER VICKI
E|
-- |DKHOSLA 30-MAY-2014 2.1 Replace 60 days with paramete
r|
-- |DKHOSLA 30-MAY-2014 2.1 Replace 60 days with paramete
r|
-- |DKHOSLA 15-JUL-2014 2.2 look for dkhosla_140714
-- |-------------------------------------------------------------------------
-|
-- +=========================================================================
=|
-------------------
--Global Variables
-------------------
--Record Status
g_yes VARCHAR2 (1) DEFAULT 'Y';
g_no VARCHAR2 (1) DEFAULT 'N';
g_error VARCHAR2 (1) DEFAULT 'E';
g_success VARCHAR2 (1) DEFAULT 'S';
g_package_name VARCHAR2 (50) DEFAULT 'BSDM_OM_UPD_BPR_PKG';
g_pos VARCHAR2 (4000);
g_mst_org_id NUMBER;
g_operating_unit NUMBER;
g_oper_unit_name VARCHAR2 (100);
--
--------------------------------------------------------------------------
-- Procedure Name : PROCESS_PRC
-- Description : This procedure validates the records and process
-- the sales order base tables for freight terms and
-- attributes at header and line level.
-- Parameters IN : p_order_number NUMBER
-- Parameters Out : x_errbuf VARCHAR2
-- x_retcode NUMBER
--------------------------------------------------------------------------
PROCEDURE process_prc(
x_errbuf OUT VARCHAR2,
x_retcode OUT NUMBER,
p_debug_flag IN VARCHAR2,
p_org_id IN NUMBER,
p_order_number IN NUMBER,
p_no_of_days IN NUMBER
)
IS
l_hdr_attr1 VARCHAR2 (100);
l_hdr_attr3 VARCHAR2 (100);
l_line_attr1 VARCHAR2 (100);
l_line_attr2 VARCHAR2 (100);
l_line_attr3 VARCHAR2 (100);
l_line_attr4 VARCHAR2 (100);
l_line_attr5 VARCHAR2 (100);
l_dollar_value NUMBER;
l_hdr_id NUMBER;
l_freight_term VARCHAR2 (20);
l_proc_name VARCHAR2 (50) DEFAULT 'PROCESS_PRC';
l_conc_request_id NUMBER;
l_count NUMBER := 0;
l_rec_status VARCHAR2 (1) := g_error;
l_open_flag VARCHAR2 (1) := g_no;
l_status VARCHAR2 (10);
l_error_mesg VARCHAR2 (4000);
L_SAM_CNT NUMBER;
-- API variables
v_api_version_number NUMBER := 1.0;
lv_msg_index NUMBER;
pvg_stmt NUMBER;
v_return_status VARCHAR2 (2000);
v_msg_count NUMBER;
v_message VARCHAR2 (2000);
v_header_rec oe_order_pub.header_rec_type;
v_line_tbl oe_order_pub.line_tbl_type;
v_line_tbl1 oe_order_pub.line_tbl_type;
v_action_request_tbl oe_order_pub.request_tbl_type;
v_line_adj_tbl oe_order_pub.line_adj_tbl_type;
v_header_rec_out oe_order_pub.header_rec_type;
v_header_val_rec_out oe_order_pub.header_val_rec_type;
v_header_adj_tbl_out oe_order_pub.header_adj_tbl_type;
v_header_adj_val_tbl_out oe_order_pub.header_adj_val_tbl_type;
v_header_price_att_tbl_out oe_order_pub.header_price_att_tbl_type;
v_header_adj_att_tbl_out oe_order_pub.header_adj_att_tbl_type;
v_header_adj_assoc_tbl_out oe_order_pub.header_adj_assoc_tbl_type;
v_header_scredit_tbl_out oe_order_pub.header_scredit_tbl_type;
v_header_scredit_val_tbl_out oe_order_pub.header_scredit_val_tbl_type;
v_line_tbl_out oe_order_pub.line_tbl_type;
v_line_val_tbl_out oe_order_pub.line_val_tbl_type;
v_line_adj_tbl_out oe_order_pub.line_adj_tbl_type;
v_line_adj_val_tbl_out oe_order_pub.line_adj_val_tbl_type;
v_line_price_att_tbl_out oe_order_pub.line_price_att_tbl_type;
v_line_adj_att_tbl_out oe_order_pub.line_adj_att_tbl_type;
v_line_adj_assoc_tbl_out oe_order_pub.line_adj_assoc_tbl_type;
v_line_scredit_tbl_out oe_order_pub.line_scredit_tbl_type;
v_line_scredit_val_tbl_out oe_order_pub.line_scredit_val_tbl_type;
v_lot_serial_tbl_out oe_order_pub.lot_serial_tbl_type;
v_lot_serial_val_tbl_out oe_order_pub.lot_serial_val_tbl_type;
v_action_request_tbl_out oe_order_pub.request_tbl_type;
l_type_cnt NUMBER;
l_hdr_attr13 VARCHAR2 (100); --psrivastava_4feb
l_intmed_ship_to_org_id NUMBER; --psrivastava_4feb
l_intmen_id NUMBER; -- dkhosla_0212
--
-- Header Cursor : It will pick the order which is in BOOKED AWAITING_SHI
PPING status
CURSOR hdr_cur
IS
SELECT DISTINCT ooha.header_id,
ooha.flow_status_code,
ooha.attribute1,
ooha.attribute2, -- added , vmehra_05092013
--ooha.attribute3, -- commented, vmehra_05092013
oola.sold_to_org_id,
oola.ship_to_org_id,
ooha.freight_terms_code,
ooha.order_number,
ooha.order_type_id,
ooha.attribute13 --psrivastava_4feb
FROM oe_order_headers_all ooha,
oe_order_lines_all oola,
wsh_delivery_details c
WHERE 1 = 1
AND ooha.header_id = oola.header_id
AND ooha.org_id = p_org_id -- dkhosla_0820
AND ooha.order_number =
NVL (p_order_number, ooha.order_number)
AND ooha.flow_status_code IN ('ENTERED', 'BOOKED')
AND oola.flow_status_code IN
('ENTERED', 'AWAITING_SHIPPING', 'BOOKED')
AND c.source_line_id = oola.line_id
AND c.released_status IN ('B', 'R')
AND c.source_header_id = oola.header_id
AND oola.request_date < TRUNC (SYSDATE) + p_no_of_days
UNION --union clause added by dkhosla_04292014
SELECT DISTINCT ooha.header_id,
ooha.flow_status_code,
ooha.attribute1,
ooha.attribute2, -- added , vmehra_05092013
--ooha.attribute3, -- commented, vmehra_05092013
oola.sold_to_org_id,
oola.ship_to_org_id,
ooha.freight_terms_code,
ooha.order_number,
ooha.order_type_id,
ooha.attribute13 --psrivastava_4feb
FROM oe_order_headers_all ooha,
oe_order_lines_all oola
WHERE ooha.header_id = oola.header_id
AND ooha.org_id = p_org_id -- dkhosla_0820
AND ooha.order_number =
NVL (p_order_number, ooha.order_number)
AND ooha.flow_status_code = 'ENTERED'
AND oola.flow_status_code = 'ENTERED'
AND oola.request_date < TRUNC (SYSDATE) + p_no_of_days;
--
-- Line Cursor : It will pick the order line attributes on the basis of he
ader_id passed
CURSOR line_cur (
p_header_id NUMBER
)
IS
SELECT oola.line_id,
oola.inventory_item_id,
oola.ordered_item_id,
oola.ordered_item, -- skayande
oola.item_identifier_type,
oola.attribute1,
oola.attribute2,
oola.attribute3,
oola.attribute4,
-- oola.attribute7, -- dkhosla_250313_
1
oola.attribute6,
oola.freight_terms_code,
oola.sold_to_org_id,
intmed_ship_to_org_id,
oola.global_attribute6, -- dkhosla_140714
oola.order_source_id -- dkhosla_140714
FROM oe_order_lines_all oola, wsh_delivery_details c
WHERE oola.item_identifier_type != 'INT'
AND oola.header_id = p_header_id
AND oola.flow_status_code IN
('ENTERED', 'AWAITING_SHIPPING', 'BOOKED')
AND c.source_line_id = oola.line_id
AND c.released_status IN ('B', 'R')
AND c.source_header_id = oola.header_id
AND oola.request_date < TRUNC (SYSDATE) + p_no_of_days
-- and oola.order_source_id <> 0 -- dkhosla_140714
UNION --union clause added by dkhosla_04292014
SELECT oola.line_id,
oola.inventory_item_id,
oola.ordered_item_id,
oola.ordered_item, -- skayande
oola.item_identifier_type,
oola.attribute1,
oola.attribute2,
oola.attribute3,
oola.attribute4,
-- oola.attribute7, -- dkhosla_250313_
1
oola.attribute6,
oola.freight_terms_code,
oola.sold_to_org_id,
intmed_ship_to_org_id,
oola.global_attribute6, -- dkhosla_140714
oola.order_source_id -- dkhosla_140714
FROM oe_order_lines_all oola
WHERE oola.item_identifier_type != 'INT'
AND oola.flow_status_code = 'ENTERED'
AND oola.request_date < TRUNC (SYSDATE) + p_no_of_days
AND oola.header_id = p_header_id
-- and oola.order_source_id <> 0 dkhosla_140714
;
-- dkhosla_12nov_1 changed attribute7 to attribute6
BEGIN
BEGIN
IF p_debug_flag = 'N' THEN
bsdm_com_util_pkg.set_global_var_in_iface ('N');
ELSE
bsdm_com_util_pkg.set_global_var_in_iface ('Y');
END IF;
--
-- Getting master org id from oracle
SELECT organization_id
INTO g_mst_org_id
FROM mtl_parameters
WHERE organization_code = 'MST' AND ROWNUM = 1;
END;
g_operating_unit := NVL (p_org_id, fnd_profile.VALUE ('ORG_ID'));
-- added vmehra_05082013
--
bsdm_com_util_pkg.write_debug ('Operating Unit- ' || g_operating_unit);
--
BEGIN
SELECT name
INTO g_oper_unit_name
FROM hr_operating_units
WHERE organization_id =
NVL (p_org_id, fnd_profile.VALUE ('ORG_ID'));
EXCEPTION
WHEN OTHERS
THEN
bsdm_com_util_pkg.write_debug (
'Error in getting Operating Unit Name'
);
END;
--
bsdm_com_util_pkg.write_out('Date: '
|| TO_CHAR (SYSDATE,
'DD-Mon-YYYY HH24:MI:SS')
|| ' '
|| 'Conc Req Id: '
|| apps.fnd_global.conc_request_id);
--
bsdm_com_util_pkg.write_out (
'BSDM OM Order Update Before Pick Release Report '
);
bsdm_com_util_pkg.write_out (
'========================================================== '
);
bsdm_com_util_pkg.write_out( RPAD ('Operating Unit', 15, ' ')
|| ' '
|| LPAD ('Order Number', 15, ' ')
|| ' '
|| RPAD ('Error/Success', 15, ' ')
|| ' '
|| RPAD ('Error Message', 50, ' '));
bsdm_com_util_pkg.write_out( RPAD ('------------', 15, ' ')
|| ' '
|| LPAD ('------------', 15, ' ')
|| ' '
|| RPAD ('--------------', 15, ' ')
|| ' '
|| RPAD ('--------------', 50, ' '));
--
bsdm_com_util_pkg.write_debug ('process-001');
bsdm_com_util_pkg.write_debug ('-----------');
bsdm_com_util_pkg.write_debug('Order Attributes Update : Start :'
|| TO_CHAR (SYSDATE,
'dd-Mon-yyyy HH24:MI:ss'));
--
l_open_flag := g_no;
--
-- Setting enviroment values
-- Process Starts
FOR hdr_rec IN hdr_cur
LOOP
l_error_mesg := NULL;
l_status := NULL;
l_hdr_id := hdr_rec.header_id;
l_rec_status := g_success;
--
bsdm_com_util_pkg.write_debug ('~Inside Header Loop');
bsdm_com_util_pkg.write_debug ('~Header ID : ' || hdr_rec.header_id);
bsdm_com_util_pkg.write_debug (
'~Order Number : ' || hdr_rec.order_number
);
--
l_open_flag := g_yes;
--
g_pos := '~Header Attribute1 Attribute2';
l_hdr_attr1 := NULL;
l_hdr_attr3 := NULL;
l_hdr_attr13 := NULL; --psrivastava_4feb
BEGIN
--
-- -- psrivastava_4feb
BEGIN
SELECT hcsu.attribute8 -- Freight Forwarder
INTO l_hdr_attr13
FROM oe_order_headers_all ooha, hz_cust_site_uses_all hcsu
WHERE ooha.ship_to_org_id = hcsu.site_use_id
AND ooha.header_id = hdr_rec.header_id
AND hcsu.site_use_id = hdr_rec.ship_to_org_id;
EXCEPTION
WHEN OTHERS
THEN
l_error_mesg :=
'~Error while l_hdr_attr13 ' || SUBSTR (SQLERRM, 1, 250);
l_rec_status := g_error;
END; -- psrivastava_4feb
-- dkhosla_12nov
SELECT DISTINCT hcasa.attribute1, hcasa.attribute13 --hca.attribut
e1
INTO l_hdr_attr1, l_hdr_attr3
FROM hz_parties hp,
hz_cust_profile_classes hcpc,
hz_customer_profiles hcp,
hz_cust_accounts hca,
hz_cust_acct_sites_all hcasa,
hz_cust_site_uses_all site,
hz_party_sites hps,
oe_order_lines_all oola,
oe_order_headers_all oha
WHERE 1 = 1
AND hca.party_id = hp.party_id(+)
AND hcpc.profile_class_id(+) = hcp.profile_class_id
AND hcp.cust_account_id(+) = hca.cust_account_id
AND hca.cust_account_id = hdr_rec.sold_to_org_id
AND hca.cust_account_id = hcasa.cust_account_id(+)
AND site.cust_acct_site_id = hcasa.cust_acct_site_id
AND site.site_use_code = 'SHIP_TO'
AND hcasa.party_site_id = hps.party_site_id
AND site.site_use_id = hdr_rec.ship_to_org_id
AND oha.header_id = oola.header_id
AND oha.header_id = hdr_rec.header_id;
--
bsdm_com_util_pkg.write_debug (
'~Query Header Attribute1 - ' || l_hdr_attr1
);
bsdm_com_util_pkg.write_debug (
'~Query Header Attribute3 - ' || l_hdr_attr3
);
-- psrivastava_4feb
bsdm_com_util_pkg.write_debug (
'~Query Header Attribute13 - ' || l_hdr_attr13
);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_rec_status := g_error;
bsdm_com_util_pkg.write_debug('~No Data Found ~Header Attributes
does not exists For Header~'
|| hdr_rec.header_id);
l_error_mesg :=
'No Data Found While fetching header attributes..';
WHEN OTHERS
THEN
l_rec_status := g_error;
bsdm_com_util_pkg.write_debug('~When Others Then ~Header Attribut
es does not exists For Header'
|| hdr_rec.header_id);
l_error_mesg := 'Error while fetching header attributes..';
END;
--
-- Find freight term
g_pos := '~Find Freight Term';
l_freight_term := NULL;
l_dollar_value := 0;
--
l_type_cnt := 0;
BEGIN
SELECT COUNT ( * )
INTO l_type_cnt
FROM oe_transaction_types_tl
WHERE (UPPER (name) LIKE '%AM%STOCK%'
OR UPPER (name) LIKE '%AM%SPOT%')
AND transaction_type_id = hdr_rec.order_type_id;
--dkhosla_1021
--
IF l_type_cnt > 0
THEN --dkhosla_1021
BEGIN
SELECT SUM(NVL (ola.ordered_QUANTITY, 0)
* NVL (ola.unit_selling_price, 0))
DOLLAR_VALUE
INTO l_dollar_value
FROM oe_order_headers_all oha, oe_order_lines_all ola
WHERE 1 = 1
AND oha.header_id = ola.header_id --AND oha.orde
r_number = hdr_rec.order_number -- p_order_number
AND oha.header_id = hdr_rec.header_id
AND ola.flow_status_code NOT IN
('AWAITING_RETURN', 'CANCELLED')
GROUP BY oha.order_number;
--
bsdm_com_util_pkg.write_debug (
'Total Dollar Value - ' || l_dollar_value
);
--
IF l_dollar_value < 500 OR l_dollar_value IS NULL
THEN
l_freight_term := 'COLLECT';
ELSE
l_freight_term := 'Paid';
END IF;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_mesg := '~Invalid Dollar value';
l_rec_status := g_error;
bsdm_com_util_pkg.write_debug('~NO Data Found~Invalid Dolla
r value~'
|| hdr_rec.header_id);
WHEN OTHERS
THEN
l_error_mesg :=
'~When-Others- While fetching dollor value';
l_rec_status := g_error;
bsdm_com_util_pkg.write_debug('~When-Others-~Invalid Dollar
value~'
|| hdr_rec.header_id);
END;
END IF;
EXCEPTION
WHEN OTHERS
THEN
bsdm_com_util_pkg.write_debug (
'~Invalid Transaction Typee~' || hdr_rec.order_type_id
);
END;
--
bsdm_com_util_pkg.write_debug (
'~Original HDR Freight - ' || hdr_rec.freight_terms_code
);
bsdm_com_util_pkg.write_debug (
'Calculated Freight - ' || l_freight_term
);
IF l_freight_term IS NULL
THEN
l_freight_term := hdr_rec.freight_terms_code;
END IF; --dkhosla_1021
--
-- insert header values
v_header_rec := oe_order_pub.g_miss_header_rec;
v_header_rec.operation := oe_globals.g_opr_update;
v_header_rec.header_id := hdr_rec.header_id;
--
-- Checking if attributes are NULL
IF hdr_rec.attribute1 IS NULL
THEN
v_header_rec.attribute1 := l_hdr_attr1;
END IF;
--
IF --hdr_rec.attribute3 IS NULL -- commented , vmehra_05092013
hdr_rec.attribute2 IS NULL -- added, vmehra_05092013
THEN
--v_header_rec.attribute3 := l_hdr_attr3; -- commented , vmehra_050
92013
v_header_rec.attribute2 := l_hdr_attr3; -- added , vmehra_05092013
END IF;
--psrivastava_4feb
IF hdr_rec.attribute13 IS NULL
THEN
v_header_rec.attribute13 := l_hdr_attr13;
END IF;
--
-- Checking if freight term code is same
IF NVL (hdr_rec.freight_terms_code, 'X') <> l_freight_term
THEN
v_header_rec.freight_terms_code := l_freight_term;
END IF;
-- Sarting Line Loop
FOR line_rec IN line_cur (hdr_rec.header_id)
LOOP
--BEGIN --- saurabh
--
l_line_attr1 := NULL;
l_line_attr2 := NULL;
l_line_attr3 := NULL;
l_line_attr4 := NULL;
l_line_attr5 := NULL;
l_intmed_ship_to_org_id := NULL; --psrivastava_4feb
-- Line Attribute1
BEGIN
SELECT msi.cumulative_total_lead_time
INTO l_line_attr1
FROM mtl_system_items_b msi, mtl_parameters mp
WHERE 1 = 1
AND msi.inventory_item_id =
line_rec.inventory_item_id
AND msi.organization_id = mp.organization_id
AND mp.organization_code = 'MST';
--
bsdm_com_util_pkg.write_debug (
'~l_line_attr1 - ' || l_line_attr1
);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_mesg := '~Line Attribute1 No Data Found';
l_rec_status := g_error;
bsdm_com_util_pkg.write_debug('~No Data Found~Line Attribute d
oes not exists for item:'
|| line_rec.inventory_item_id);
WHEN OTHERS
THEN
l_error_mesg :=
'~When-Others then - Line Attribute1 does not exists';
l_rec_status := g_error;
bsdm_com_util_pkg.write_debug('~When Oters then ~Line Attribut
e does not exists for item:'
|| line_rec.inventory_item_id);
END;
bsdm_com_util_pkg.write_debug (
'~Identifier - ' || line_rec.item_identifier_type
);
--
IF line_rec.item_identifier_type = 'CUST'
THEN
BEGIN
SELECT xref.attribute2,
xref.attribute3,
xref.attribute4,
xref.attribute5 -- dkhosla_250313_1
INTO l_line_attr2,
l_line_attr3,
l_line_attr4,
l_line_attr5
FROM mtl_customer_item_xrefs xref,
mtl_system_items_kfv msi,
mtl_customer_items mci
WHERE 1 = 1
AND xref.customer_item_id = mci.customer_item_id
AND mci.customer_id = line_rec.sold_to_org_id
AND xref.master_organization_id =
msi.organization_id
AND xref.inventory_item_id = msi.inventory_item_id
AND xref.inventory_item_id =
line_rec.inventory_item_id -- skayande
AND mci.customer_item_id =
line_rec.ordered_item_id
AND msi.organization_id = g_mst_org_id;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_mesg :=
'~Line Attribute2, Attribute3 , Attribute4, Attribute5 d
oes not exists';
l_rec_status := g_error;
bsdm_com_util_pkg.write_debug('~Line Attributes not found f
or ordered Item'
|| line_rec.ordered_item_id);
WHEN OTHERS
THEN
l_error_mesg :=
'When others then~Line Attributes does not exists';
l_rec_status := g_error;
bsdm_com_util_pkg.write_debug('~When Others Then~Line Attri
butes ordered Item'
|| line_rec.ordered_item_id);
END;
ELSE
BEGIN
/*SELECT xref.attribute2,
xref.attribute3,
xref.attribute4,
xref.attribute5 -- dkhosla_250313_1
INTO l_line_attr2,
l_line_attr3,
l_line_attr4,
l_line_attr5
FROM mtl_customer_item_xrefs xref,
mtl_system_items_kfv msi,
mtl_customer_items mci
WHERE 1 = 1
AND xref.customer_item_id = mci.customer_item_id
AND mci.customer_id = line_rec.sold_to_org_id
AND xref.master_organization_id =
msi.organization_id
AND xref.inventory_item_id = msi.inventory_item_id
AND xref.inventory_item_id =
line_rec.ordered_item_id
AND msi.organization_id = g_mst_org_id;*/
--skayande
SELECT mxref.attribute2,
mxref.attribute3,
mxref.attribute4,
mxref.attribute5 -- dkhosla_250313_1
INTO l_line_attr2,
l_line_attr3,
l_line_attr4,
l_line_attr5
FROM mtl_cross_references mxref
WHERE 1 =
1
AND mxref.cross_reference_type =
line_rec.item_identifier_type
AND mxref.cross_reference =
line_rec.ordered_item
AND mxref.inventory_item_id =
line_rec.inventory_item_id;
--skayande
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_mesg :=
'~Line Attribute2, Attribute3 , Attribute4, Attribute5 n
o data found';
l_rec_status := g_error;
bsdm_com_util_pkg.write_debug('~Line Attributes not found f
or ordered Item'
|| line_rec.ordered_item_id);
WHEN OTHERS
THEN
l_error_mesg :=
'~Line Attribute2, Attribute3 , Attribute4, Attribute5 w
hen others then';
l_rec_status := g_error;
bsdm_com_util_pkg.write_debug('~Line Attributes when others
then'
|| line_rec.ordered_item_id);
END;
END IF;
--
BEGIN
SELECT hcsu.attribute2 -- Pool Point ID
INTO l_intmed_ship_to_org_id
FROM oe_order_lines_all oola, hz_cust_site_uses_all hcsu
WHERE oola.ship_to_org_id = hcsu.site_use_id
AND oola.line_id = line_rec.line_id;
EXCEPTION
WHEN OTHERS
THEN
l_error_mesg :=
'~Error Occurred: l_intmed_ship_to_org_id '
|| SUBSTR (SQLERRM, 1, 250);
l_rec_status := g_error;
END;
--
bsdm_com_util_pkg.write_debug (
'~Query Line Attribute2 - ' || l_line_attr2
);
bsdm_com_util_pkg.write_debug (
'~Query Line Attribute3 - ' || l_line_attr3
);
bsdm_com_util_pkg.write_debug (
'~Query Line Attribute4 - ' || l_line_attr4
);
bsdm_com_util_pkg.write_debug (
'~Query Line Attribute5 - ' || l_line_attr5
);
bsdm_com_util_pkg.write_debug (
'~line_rec.line_id - ' || line_rec.line_id
);
--psrivastava_4feb
bsdm_com_util_pkg.write_debug (
'~l_intmed_ship_to_org_id - ' || l_intmed_ship_to_org_id
);
--
--
l_count := 1;
v_line_tbl (l_count) := oe_order_pub.g_miss_line_rec;
v_line_tbl (l_count).operation := oe_globals.g_opr_update;
v_line_tbl (l_count).header_id := l_hdr_id; -- hdr_rec.header_id ;
v_line_tbl (l_count).line_id := line_rec.line_id;
-- Checking line attribute values
IF l_rec_status = g_error -- END IF line# 533
THEN
bsdm_com_util_pkg.write_debug ('Error:' || l_error_mesg);
l_status := 'ERROR';
ELSE
--
IF line_rec.attribute1 IS NULL
THEN
v_line_tbl (l_count).attribute1 := l_line_attr1;
END IF;
--
IF line_rec.attribute2 IS NULL
THEN
v_line_tbl (l_count).attribute2 := l_line_attr2;
END IF;
--
IF line_rec.attribute3 IS NULL
THEN
v_line_tbl (l_count).attribute3 := l_line_attr3;
END IF;
--
IF line_rec.attribute4 IS NULL
THEN
v_line_tbl (l_count).attribute4 := l_line_attr4;
END IF;
--
-- IF line_rec.attribute7 IS NULL dkhosla_12nov_1
IF line_rec.attribute6 IS NULL
THEN
-- v_line_tbl (l_count).attribute7 := l_line_attr5;
v_line_tbl (l_count).attribute6 := l_line_attr5;
END IF;
--
L_SAM_CNT := 0 ;
SELECT COUNT ( * )
INTO L_SAM_CNT
FROM OE_ORDER_LINES_ALL OOLA
WHERE OOLA.INDUSTRY_CONTEXT IS NULL
AND OOLA.LINE_ID = LINE_REC.LINE_ID;
IF L_SAM_CNT > 0
THEN
IF line_rec.intmed_ship_to_org_id IS NULL
THEN
--psrivastava_4feb
v_line_tbl (l_count).intermed_ship_to_org_id :=
l_intmed_ship_to_org_id;
END IF;
END IF;
-- dkhosla_140714
IF line_rec.order_source_id <> 0 then
-- checking if freight terms are same
IF NVL (line_rec.freight_terms_code, 'X') <> l_freight_term
AND line_rec.global_attribute6 IS NULL
THEN
v_line_tbl (l_count).freight_terms_code := l_freight_term;
v_line_tbl (l_count).global_attribute6 := l_freight_term;
END IF;
ELSE
v_line_tbl (l_count).freight_terms_code := line_rec.freight_terms
_code;
END IF;
-- end of dkhosla_140714

--
v_msg_count := NULL;
v_message := NULL;
-- Calling API to process records
mo_global.init ('ONT');
oe_msg_pub.initialize;
oe_order_pub.process_order (
p_org_id => g_operating_unit, --84,
p_api_version_number => v_api_version_number,
p_header_rec => v_header_rec,
p_line_tbl => v_line_tbl,
p_action_request_tbl => v_action_request_tbl,
p_line_adj_tbl => v_line_adj_tbl,
x_header_rec => v_header_rec_out,
x_header_val_rec => v_header_val_rec_out,
x_header_adj_tbl => v_header_adj_tbl_out,
x_header_adj_val_tbl => v_header_adj_val_tbl_out,
x_header_price_att_tbl => v_header_price_att_tbl_out,
x_header_adj_att_tbl => v_header_adj_att_tbl_out,
x_header_adj_assoc_tbl => v_header_adj_assoc_tbl_out,
x_header_scredit_tbl => v_header_scredit_tbl_out,
x_header_scredit_val_tbl => v_header_scredit_val_tbl_out,
x_line_tbl => v_line_tbl_out,
x_line_val_tbl => v_line_val_tbl_out,
x_line_adj_tbl => v_line_adj_tbl_out,
x_line_adj_val_tbl => v_line_adj_val_tbl_out,
x_line_price_att_tbl => v_line_price_att_tbl_out,
x_line_adj_att_tbl => v_line_adj_att_tbl_out,
x_line_adj_assoc_tbl => v_line_adj_assoc_tbl_out,
x_line_scredit_tbl => v_line_scredit_tbl_out,
x_line_scredit_val_tbl => v_line_scredit_val_tbl_out,
x_lot_serial_tbl => v_lot_serial_tbl_out,
x_lot_serial_val_tbl => v_lot_serial_val_tbl_out,
x_action_request_tbl => v_action_request_tbl_out,
x_return_status => v_return_status,
x_msg_count => v_msg_count,
x_msg_data => v_message
);
--
bsdm_com_util_pkg.write_debug ('Status IS: ' || v_return_status);
IF v_return_status != fnd_api.g_ret_sts_success
THEN
l_status := 'ERROR';
bsdm_com_util_pkg.write_debug ('Error in API.');
IF v_msg_count > 0
THEN
BEGIN
FOR lv_index IN 1 .. v_msg_count
LOOP
oe_msg_pub.get (p_msg_index => lv_index,
p_encoded => 'F',
p_data => v_message,
p_msg_index_out => lv_msg_index);
l_error_mesg := l_error_mesg || v_message;
END LOOP;
bsdm_com_util_pkg.write_debug (
'Order Number : ' || p_order_number
);
bsdm_com_util_pkg.write_debug (
'Error : ' || l_error_mesg
);
--
EXCEPTION
WHEN OTHERS
THEN
l_error_mesg :=
'Error while fetching API error message';
bsdm_com_util_pkg.write_debug (
'Error while fetching API error message'
);
END;
END IF;
ELSE
l_status := 'SUCCESS';
bsdm_com_util_pkg.write_debug (
'Records Processed Successfully.'
);
--
END IF;
END IF; -- IF l_rec_status = g_error
v_line_tbl := v_line_tbl1;
END LOOP;
COMMIT;
-- Reseting line type variable
--
bsdm_com_util_pkg.write_out( RPAD (g_oper_unit_name, 15, ' ')
|| ' '
|| LPAD (hdr_rec.order_number, 15, ' ')
|| ' '
|| RPAD (l_status, 15, ' ')
|| ' '
|| RPAD (l_error_mesg, 150, ' '));
END LOOP;
bsdm_com_util_pkg.write_out (' ');
bsdm_com_util_pkg.write_out (' ');
bsdm_com_util_pkg.write_out ('+++End of Report+++');
bsdm_com_util_pkg.write_out (' ');
bsdm_com_util_pkg.write_out (' ');
--
-- Process Ends
EXCEPTION
WHEN OTHERS
THEN
-- ROLLBACK; dkhosla_0820
RAISE;
END PROCESS_PRC;
END BSDM_OM_UPD_BPR_PKG; --End of Pkg body
/

Potrebbero piacerti anche