Hi Guys,
I Recently , got a requirement to make sub inventory transfer using the standard API.
So Here is the code.
PROCEDURE call_subinv_transfer (p_qty IN NUMBER,
p_subinv IN VARCHAR2,
p_item_id IN NUMBER,
p_organziation_id IN NUMBER,
p_uom_code IN VARCHAR2,
p_transaction_ref IN VARCHAR2,
p_lot_number IN VARCHAR2,
p_exp_date DATE,
p_status_id NUMBER)
IS
lv_transaction_source_name VARCHAR2 (30);
ln_trnasaction_type_id NUMBER;
lv_source_code VARCHAR2 (30)
:= 'XXX_Subinventory_Source_Name';
gv_reservation_subinv VARCHAR2(30) := 'XXX_SUBINV_CODE';
gd_date DATE := SYSDATE;
re_exception EXCEPTION;
ln_transaction_interface_id NUMBER;
lv_return_value VARCHAR2 (50);
lv_pt_return_status VARCHAR2 (10);
ln_msg_idx_cnt NUMBER;
lv_pt_msg_data VARCHAR2 (4000);
ln_trans_count NUMBER;
ln_row_count NUMBER;
l_rowid NUMBER;
ln_qty NUMBER;
lv_subinv VARCHAR2 (100);
ln_item_id NUMBER;
ln_organization_id NUMBER;
lv_uom_code VARCHAR2 (30);
lv_transaction_ref VARCHAR2 (100);
lv_lot_number VARCHAR2 (100);
ld_exp_date DATE;
ln_status_id NUMBER;
ln_adj_qty NUMBER;
x_retcode NUMBER;
x_errbuf VARCHAR2 (250);
BEGIN
x_retcode := 0;
x_errbuf := NULL;
ln_qty := p_qty;
lv_subinv := p_subinv;
ln_item_id := p_item_id;
ln_organization_id := p_organziation_id;
lv_uom_code := p_uom_code;
lv_transaction_ref := p_transaction_ref;
lv_lot_number := p_lot_number;
ld_exp_date := p_exp_Date;
ln_status_id := p_status_id;
-- xxx_FNDLOG.LOG ('Starting Subinv Procedure');
ln_transaction_interface_id := mtl_material_transactions_s.NEXTVAL;
--------------------Store transaction type id in Any lookup, so that it can be used in future customizations---------
SELECT LOOKUP_CODE
INTO ln_trnasaction_type_id
FROM fnd_lookup_values
WHERE lookup_type = 'XXX_LOOKUP_CODE'-------------
AND enabled_flag = 'Y'
AND TAG = 'SUB_INV_TRANSFER'
AND LANGUAGE(+) = USERENV ('LANG')
AND TRUNC (SYSDATE) BETWEEN NVL (start_date_active, SYSDATE - 1)
AND NVL (end_date_active, SYSDATE + 1);
BEGIN
INSERT INTO MTL_TRANSACTIONS_INTERFACE (transaction_interface_id,
transaction_header_id,
distribution_account_id,
inventory_item_id,
source_code,
source_header_id,
source_line_id,
transaction_source_name,
transaction_source_id,
process_flag,
transaction_mode,
transaction_quantity,
organization_id,
subinventory_code,
locator_id,
transfer_organization,
transfer_subinventory,
transfer_locator,
transaction_type_id,
transaction_date,
transaction_uom,
reason_id,
created_by,
creation_date,
last_updated_by,
last_update_date,
transaction_reference)
VALUES (
ln_transaction_interface_id,
ln_transaction_interface_id,
'',
ln_item_id,
lv_source_code,
ln_transaction_interface_id,
ln_transaction_interface_id,
'',
'',
1,
2,
ln_qty,
ln_organization_id,
gv_reservation_subinv,
find_location (ln_organization_id,---------------------Function created to fetch locator id , based on organization id and subinventory code
gv_reservation_subinv),
'',
p_subinv,
find_location (ln_organization_id, p_subinv),
ln_trnasaction_type_id,
gd_date,
lv_uom_code,
'',
gn_user_id,
gd_Date,
gn_user_id,
gd_Date,
lv_transaction_ref);
EXCEPTION
WHEN OTHERS
THEN
xxx_FNDLOG.LOG ('Error in Interface ' || SQLERRM);
END;
-- xxx_fndlog.LOG ('Inserting data in LoT interface Table');
BEGIN
INSERT
INTO MTL_TRANSACTION_LOTS_INTERFACE (transaction_interface_id,
last_update_date,
last_updated_by,
creation_date,
created_by,
lot_number,
lot_expiration_date,
transaction_quantity,
status_id)
VALUES (ln_transaction_interface_id,
gd_Date,
gn_user_id,
gd_Date,
gn_user_id,
lv_lot_number,
ld_exp_date,
ln_qty,
ln_status_id);
EXCEPTION
WHEN OTHERS
THEN
xxx_FNDLOG.LOG ('Error in Lot Interface ' || SQLERRM);
END;
-- Call the Inventory Transaction Manager for the specific transaction
lv_return_value :=
inv_txn_manager_pub.process_transactions (
p_api_version => 1.0,
x_return_status => lv_pt_return_status,
x_msg_count => ln_msg_idx_cnt,
x_msg_data => lv_pt_msg_data,
x_trans_count => ln_trans_count,
p_table => 1,
p_header_id => ln_transaction_interface_id);
xxx_FNDLOG.LOG (
' Standard API Starts lv_pt_return_status' || lv_pt_return_status);
IF NVL (lv_pt_return_status, 'E') = 'E'
THEN
BEGIN
SELECT error_explanation
INTO lv_pt_msg_data
FROM mtl_transactions_interface
WHERE transaction_interface_id = ln_transaction_interface_id;
xxx_FNDLOG.LOG (
' Error in call_subinv_transfer For Lot : '
|| lv_lot_number
|| ' - '
|| lv_pt_msg_data);
END;
x_errbuf :=
'Error Occurred in inv_txn_manager_pub.process_transactions.. Error Details -'
|| lv_pt_msg_data;
RAISE re_exception;
END IF;
IF lv_pt_return_status = 'S'
THEN
xxx_log_messages_pkg.display_msg (
'Material Transaction Processor Successfully Transfered:'
|| x_errbuf);
END IF;
xxx_log_messages_pkg.display_msg (
'Error in Material Transaction Processor: ' || x_errbuf);
-- END LOOP;
EXCEPTION
WHEN re_exception
THEN
x_retcode := 2;
xxx_FNDLOG.LOG (' Error in Process data ' || SQLERRM);
WHEN OTHERS
THEN
x_retcode := 2;
x_errbuf := ' Error Occured in Process data .-' || SQLERRM;
END;
I Recently , got a requirement to make sub inventory transfer using the standard API.
So Here is the code.
PROCEDURE call_subinv_transfer (p_qty IN NUMBER,
p_subinv IN VARCHAR2,
p_item_id IN NUMBER,
p_organziation_id IN NUMBER,
p_uom_code IN VARCHAR2,
p_transaction_ref IN VARCHAR2,
p_lot_number IN VARCHAR2,
p_exp_date DATE,
p_status_id NUMBER)
IS
lv_transaction_source_name VARCHAR2 (30);
ln_trnasaction_type_id NUMBER;
lv_source_code VARCHAR2 (30)
:= 'XXX_Subinventory_Source_Name';
gv_reservation_subinv VARCHAR2(30) := 'XXX_SUBINV_CODE';
gd_date DATE := SYSDATE;
re_exception EXCEPTION;
ln_transaction_interface_id NUMBER;
lv_return_value VARCHAR2 (50);
lv_pt_return_status VARCHAR2 (10);
ln_msg_idx_cnt NUMBER;
lv_pt_msg_data VARCHAR2 (4000);
ln_trans_count NUMBER;
ln_row_count NUMBER;
l_rowid NUMBER;
ln_qty NUMBER;
lv_subinv VARCHAR2 (100);
ln_item_id NUMBER;
ln_organization_id NUMBER;
lv_uom_code VARCHAR2 (30);
lv_transaction_ref VARCHAR2 (100);
lv_lot_number VARCHAR2 (100);
ld_exp_date DATE;
ln_status_id NUMBER;
ln_adj_qty NUMBER;
x_retcode NUMBER;
x_errbuf VARCHAR2 (250);
BEGIN
x_retcode := 0;
x_errbuf := NULL;
ln_qty := p_qty;
lv_subinv := p_subinv;
ln_item_id := p_item_id;
ln_organization_id := p_organziation_id;
lv_uom_code := p_uom_code;
lv_transaction_ref := p_transaction_ref;
lv_lot_number := p_lot_number;
ld_exp_date := p_exp_Date;
ln_status_id := p_status_id;
-- xxx_FNDLOG.LOG ('Starting Subinv Procedure');
ln_transaction_interface_id := mtl_material_transactions_s.NEXTVAL;
--------------------Store transaction type id in Any lookup, so that it can be used in future customizations---------
SELECT LOOKUP_CODE
INTO ln_trnasaction_type_id
FROM fnd_lookup_values
WHERE lookup_type = 'XXX_LOOKUP_CODE'-------------
AND enabled_flag = 'Y'
AND TAG = 'SUB_INV_TRANSFER'
AND LANGUAGE(+) = USERENV ('LANG')
AND TRUNC (SYSDATE) BETWEEN NVL (start_date_active, SYSDATE - 1)
AND NVL (end_date_active, SYSDATE + 1);
BEGIN
INSERT INTO MTL_TRANSACTIONS_INTERFACE (transaction_interface_id,
transaction_header_id,
distribution_account_id,
inventory_item_id,
source_code,
source_header_id,
source_line_id,
transaction_source_name,
transaction_source_id,
process_flag,
transaction_mode,
transaction_quantity,
organization_id,
subinventory_code,
locator_id,
transfer_organization,
transfer_subinventory,
transfer_locator,
transaction_type_id,
transaction_date,
transaction_uom,
reason_id,
created_by,
creation_date,
last_updated_by,
last_update_date,
transaction_reference)
VALUES (
ln_transaction_interface_id,
ln_transaction_interface_id,
'',
ln_item_id,
lv_source_code,
ln_transaction_interface_id,
ln_transaction_interface_id,
'',
'',
1,
2,
ln_qty,
ln_organization_id,
gv_reservation_subinv,
find_location (ln_organization_id,---------------------Function created to fetch locator id , based on organization id and subinventory code
gv_reservation_subinv),
'',
p_subinv,
find_location (ln_organization_id, p_subinv),
ln_trnasaction_type_id,
gd_date,
lv_uom_code,
'',
gn_user_id,
gd_Date,
gn_user_id,
gd_Date,
lv_transaction_ref);
EXCEPTION
WHEN OTHERS
THEN
xxx_FNDLOG.LOG ('Error in Interface ' || SQLERRM);
END;
-- xxx_fndlog.LOG ('Inserting data in LoT interface Table');
BEGIN
INSERT
INTO MTL_TRANSACTION_LOTS_INTERFACE (transaction_interface_id,
last_update_date,
last_updated_by,
creation_date,
created_by,
lot_number,
lot_expiration_date,
transaction_quantity,
status_id)
VALUES (ln_transaction_interface_id,
gd_Date,
gn_user_id,
gd_Date,
gn_user_id,
lv_lot_number,
ld_exp_date,
ln_qty,
ln_status_id);
EXCEPTION
WHEN OTHERS
THEN
xxx_FNDLOG.LOG ('Error in Lot Interface ' || SQLERRM);
END;
-- Call the Inventory Transaction Manager for the specific transaction
lv_return_value :=
inv_txn_manager_pub.process_transactions (
p_api_version => 1.0,
x_return_status => lv_pt_return_status,
x_msg_count => ln_msg_idx_cnt,
x_msg_data => lv_pt_msg_data,
x_trans_count => ln_trans_count,
p_table => 1,
p_header_id => ln_transaction_interface_id);
xxx_FNDLOG.LOG (
' Standard API Starts lv_pt_return_status' || lv_pt_return_status);
IF NVL (lv_pt_return_status, 'E') = 'E'
THEN
BEGIN
SELECT error_explanation
INTO lv_pt_msg_data
FROM mtl_transactions_interface
WHERE transaction_interface_id = ln_transaction_interface_id;
xxx_FNDLOG.LOG (
' Error in call_subinv_transfer For Lot : '
|| lv_lot_number
|| ' - '
|| lv_pt_msg_data);
END;
x_errbuf :=
'Error Occurred in inv_txn_manager_pub.process_transactions.. Error Details -'
|| lv_pt_msg_data;
RAISE re_exception;
END IF;
IF lv_pt_return_status = 'S'
THEN
xxx_log_messages_pkg.display_msg (
'Material Transaction Processor Successfully Transfered:'
|| x_errbuf);
END IF;
xxx_log_messages_pkg.display_msg (
'Error in Material Transaction Processor: ' || x_errbuf);
-- END LOOP;
EXCEPTION
WHEN re_exception
THEN
x_retcode := 2;
xxx_FNDLOG.LOG (' Error in Process data ' || SQLERRM);
WHEN OTHERS
THEN
x_retcode := 2;
x_errbuf := ' Error Occured in Process data .-' || SQLERRM;
END;
No comments:
Post a Comment