Você está na página 1de 9

Onhand Quantity Conversion in Oracle apps-R12

In this Article,you will be knowing,


* What are the base tables?
* What are the interface tables?
* What are the mandatory validations
* How to validate from given data?
* How to insert records into interface tables?
* How we move interface records into corresponding base tables.
Onhand Quantity Conversion:
base tables:
mtl_onhand_quantities
mtl_lot_numbers
mtl_serial_numbers
interface tables:
mtl_transactions_interface
mtl_transaction_lots_interface
mtl_serial_numbers_interface
note:
our stage table should have all the required mandatory columns and also should h
ave who columns,and error_code,error_message to know whter that record is valid
or not
.so that we can uptade our stage table if it is valid it is 'V',if it is invalid
,it is 'E'.
ALL THE ABOVE CAN BE CLARIFIED BELOW;
stage table columns:
ORGANIZATION_CODE
,ITEM_NUMBER
,SUBINVENTORY
,LOCATOR_SEGMENTS
,SERIAL_NUMBER
,LOT_NUMBER
,TRANSACTION_DATE
,TRANSACTION_TYPE
,UOM_CODE
,QUANTITY
,DIST_ACCOUNT
,ERROR_CODE
,EXPIRATION_DATE
,SUB_DESCRIPTION
,LOC_DESCRIPTION
,INVENTORY_LOCATION_TYPE_11I
,INV_LOC_TYPE_R12
,LICENSE_PLATE_NUMBER
,LPN_CONTEXT
,LOC_STATUS_ID_11I
,LOC_STATUS_11I
,ONHAND_STATUS_R12
,FF_PICK_STATUS
,FF_ACTIVE_DATE
,FF_CLOSED_DATE
,CREATED_BY
,CREATION_DATE
,LAST_UPDATE_DATE
,LAST_UPDATED_BY
,LAST_UPDATE_LOGIN
Validations:
1)organization code validation(check organization code exist or not AND IF exist
derive ORGANIZATION_ID,if it goes to exception update error_code='not valid')
i.e
SELECT mp.organization_id,
'V'
INTO x_organization_id,
error_code
FROM mtl_parameters mp
WHERE mp.organization_code = cursor.organization_code;
exception
update stg_table set error_code='E';
2)Item name(number) Validation(check item is valid for perticular organization o
r not) i.e
SELECT msi.inventory_item_id
, msi.primary_uom_code
, msi.lot_control_code
, msi.serial_number_control_code
, 'V'
, msi.MTL_TRANSACTIONS_ENABLED_FLAG
INTO x_inv_item_id
, x_primary_uom_code
, x_lot_control_code
, x_serial_number_control_code
, error_code
, v_txn
FROM mtl_system_items msi
WHERE msi.organization_id = cursor.organization_code
AND msi.segment1 = cursor.item_number;
exception
update stg_table set error_code='E';
3)Sub Inventory Code validation(check secondary_inventory_name is exist for orga
nization or not)
i.e
SELECT msi.secondary_inventory_name,
'V'
INTO v_subinventory,
error_code
FROM mtl_secondary_inventories msi
WHERE msi.organization_id = p_organization_id--(get from org_code)
AND msi.secondary_inventory_name = cursor.SUBINVENTORY;
exception
update stg_table set error_code='E';
4)Locator Validation(validate locator segment AND get inventory location id) i.
e
SELECT mil.inventory_location_id
, 'V'
INTO x_locator_id
, error_code
FROM mtl_item_locations_kfv mil
WHERE mil.organization_id = p_organization_id--(get from org_code)
AND mil.subinventory_code = cursor.SUBINVENTORY;
AND mil.concatenated_segments= cursor.LOCATOR_SEGMENTS
AND mil.enabled_flag = 'Y'
AND NVL(mil.start_date_active, SYSDATE) <= SYSDATE
AND NVL(mil.END_date_active, SYSDATE) >= SYSDATE;
exception
update stg_table set error_code='E';
5)Transaction Type Validation(with Transaction Type get Transaction Type Id) i.e
SELECT mtt.transaction_type_id
, mtt.transaction_source_type_id
, 'V'
INTO x_transaction_type_id
, x_txn_source_type_id
, error_code
FROM mtl_transaction_types mtt
WHERE UPPER ( mtt.transaction_type_name ) = UPPER (cursor.TRANSACTION_TYPE )
AND nvl ( mtt.disable_date, sysdate +1 ) > SYSDATE ;
exception
update stg_table set error_code='E';
6)if they dont give any distribution id then,we need to create miscellenous rece
ipt from front-end,if they dont give us any code combination id,example,we wil b
e taking one hard coded value i.e
l_const_misc_acc CONSTANT VARCHAR2(100) := '00-00-11222-111211-00000-00111' valu
e we get as soon as we create miscellenous receipt;
declare
v_expense_account := null;
BEGIN
select code_combination_id
into v_expense_account
from gl_code_combinations_kfv gcc
where concatenated_segments =l_const_misc_acc;
EXCEPTION
WHEN OTHERS
THEN
update stg_table set error_code='E'
END;
--WITH ABOVE ALL VALIDATIONS WE CAN UPDATE BOTH VALID RECORD AND INVALID RECORDS
IN OUR STAGE TABLE ITSELF,AND WE CAN PROCESS ONLY VALID RECORD TO INTERFACE TAB
LE BY SELETING STAGE TABLE WHERE ERROR_CODE='V'
---------------------------------------------------
---BELOW IS CODE TO INSERT INTO INTERFACE TABLES---
---------------------------------------------------
Procedure PROC_INSERT_INTO_INTERFACE
is
v_transaction_interface_id Number;
v_serial_transaction_temp_id Number;
v_message VARCHAR2(2000):=null;
v_Isuccess Number:=0;
v_Ierror Number:=0;
v_Itotal Number:=0;
v_return_status VARCHAR2(1):=null;
v_flag Number:=0;
v_sflag Number:=0;
v_lflag Number:=0;
v_reason_id Number:=null;
v_inventory_item_id Number:=NULL;
v_organization_id Number:=NULL;
v_primary_uom_code VARCHAR2(30):=NULL;
v_lot_control_code VARCHAR2(90):=NULL;
v_serial_number_control_code VARCHAR2(90):=NULL;
v_Distribution_Account number:=0;
v_inventory_location_id number:=0;
v_project_id number:=null;
v_task_id number:=null;
--
l_return_status VARCHAR2(1000);
l_msg_count NUMBER;
l_msg_data VARCHAR2(1000);
l_lpn_id NUMBER;
--
cursor C is
SELECT
ROWID AS row_id
,stg_table.ORGANIZATION_CODE
,stg_table.ITEM_NUMBER
,stg_table.SUBINVENTORY
,stg_table.LOCATOR_SEGMENTS
,stg_table.SERIAL_NUMBER
,stg_table.LOT_NUMBER
,stg_table.TRANSACTION_DATE
,stg_table.TRANSACTION_TYPE
,stg_table.UOM_CODE
,stg_table.QUANTITY
,stg_table.DIST_ACCOUNT
,stg_table.PROCESS_FLAG
,stg_table.SUB_DESCRIPTION
,stg_table.LOC_SEGMENT1
,stg_table.LOC_SEGMENT2
,stg_table.LOC_SEGMENT3
,stg_table.LOC_DESCRIPTION
,stg_table.INVENTORY_LOCATION_TYPE_11I
,stg_table.INV_LOC_TYPE_R12
,stg_table.LICENSE_PLATE_NUMBER
,stg_table.LPN_CONTEXT
,stg_table.CREATED_BY
,stg_table.CREATION_DATE
,stg_table.LAST_UPDATED_BY
,stg_table.LAST_UPDATE_DATE
,stg_table.LAST_UPDATE_LOGIN
,stg_table.ERROR_MESSAGE
,stg_table.REQUEST_ID
,stg_table.EXPIRATION_DATE
,stg_table.FF_PICK_STATUS
,stg_table.FF_ACTIVE_DATE
,stg_table.FF_CLOSED_DATE
,mtt.transaction_type_id
,mtt.transaction_source_type_id
FROM XX_INV_ONHAND_QTY_STG stg_table,
mtl_transaction_types mtt
Where stg_table.Process_Flag = 'V'
And Upper ( Mtt.Transaction_Type_Name ) = Upper ( Transaction_Type)
AND nvl ( mtt.disable_date, sysdate +1 ) > SYSDATE;
BEGIN
FOR I in C loop
v_inventory_item_id:=NULL;
v_organization_id:=NULL;
v_primary_uom_code:=NULL;
v_lot_control_code:=NULL;
v_serial_number_control_code:=NULL;
v_Distribution_Account:=NULL;
v_inventory_location_id:=null;
v_project_id:=null;
v_task_id:=null;
BEGIN
Select Organization_Id
Into v_organization_id
From
org_organization_definitions ood
Where
ood.Organization_Code=I.Organization_Code;
update stg_table set error_code='S';
EXCEPTION
WHEN OTHERS THEN
update stg_table set error_code='US';
END;
BEGIN
Select Msi.Inventory_Item_Id,msi.primary_uom_code,msi.lot_contro
l_code,msi.serial_number_control_code
Into v_inventory_item_id,v_primary_uom_code,v_lot_control_code,v_serial_numb
er_control_code
From
Mtl_System_Items_B Msi
Where
msi.organization_id=v_organization_id
and msi.segment1=I.item_number;
update stg_table set error_code='S';
EXCEPTION
WHEN OTHERS THEN
update stg_table set error_code='US';
END;
BEGIN
Select Mil.Inventory_Location_Id,Mil.Project_Id,Mil.Task_Id
into v_inventory_location_id,v_project_id,v_task_id
From Mtl_Item_Locations_Kfv Mil
Where Mil.Organization_Id = V_Organization_Id
And Mil.Subinventory_Code = I.Subinventory
AND mil.concatenated_segments= I.locator_segments
AND mil.enabled_flag = 'Y'
And Nvl(Mil.Start_Date_Active, Sysdate) <= Sysdate
AND NVL(mil.END_date_active, SYSDATE) >= SYSDATE;
update stg_table set error_code='S';
EXCEPTION
WHEN OTHERS THEN
update stg_table set error_code='US';
END;
If I.license_plate_number is not null then
Begin
select lpn_id
into l_lpn_id
from wms_license_plate_numbers wlpn
where wlpn.LICENSE_PLATE_NUMBER = I.license_plate_number
and wlpn.organization_id = v_organization_id
and rownum =1
and nvl(wlpn.lot_number,0) =nvl(I.lot_number,0) ;
Exception
when others then
l_lpn_id := NULL;
end;
If l_lpn_id is null then
begin
wms_container_pub.Create_LPN (
p_api_version =>1.0,
x_return_status =>l_return_status,
x_msg_count => l_msg_count ,
x_msg_data => l_msg_data,
p_lpn => I.license_plate_number,
p_organization_id => v_organization_id,
p_container_item_id => NULL, --v_inventory_item_id,
p_subinventory => I.subinventory,
p_locator_id => v_inventory_location_id,
p_serial_number => null,
p_lot_number => I.lot_number,
x_lpn_id => l_lpn_id) ;
commit;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('to create lpn number using API');
l_lpn_id := null;
end;
end if;
end if;
SELECT MTL_SYSTEM_ITEMS_INTF_SETS_S.NEXTVAL
INTO v_transaction_interface_id
FROM dual;
SELECT MTL_SYSTEM_ITEMS_INTF_SETS_S.NEXTVAL
INTO v_serial_transaction_temp_id
FROM dual;
--inserting into interface tables from above derived values(i.e we got value
s to declared variables)
BEGIN
INSERT INTO mtl_transactions_interface
( source_header_id
, source_line_id
, transaction_mode
, source_code
, process_flag
, transaction_interface_id
, transaction_date
, inventory_item_id
, transaction_uom
, organization_id
, subinventory_code
, locator_id
, transfer_lPN_ID
, project_id
, task_id
, reason_id
, transaction_quantity
, transaction_type_id
, transaction_source_type_id
, distribution_account_id
, created_by
, creation_date
, last_updated_by
, last_update_date
, last_update_login
)
VALUES
( 10701
, 0
, 3
, 'On HAND Qty Load'
, 1
, nvl(v_transaction_interface_id,10003918)
, cv_process_rec.transaction_date
, v_inventory_item_id
, v_primary_uom_code
, v_organization_id
, cv_process_rec.subinventory
, v_inventory_location_id
, l_lpn_id
, v_project_id
, v_task_id
, v_reason_id
, cv_process_rec.quantity
, cv_process_rec.transaction_type_id
, cv_process_rec.transaction_source_type_id
, cv_process_rec.dist_account
, NVL(fnd_global.user_id,-1)
, SYSDATE
, NVL(fnd_global.user_id,-1)
, SYSDATE
, NVL(fnd_global.login_id,-1)
);
update stg_table set error_code='P';
else
DELETE
FROM mtl_transactions_interface
WHERE transaction_interface_id = v_transaction_interface_id;
DELETE
FROM mtl_transaction_lots_interface
WHERE transaction_interface_id = v_transaction_interface_id;
DELETE
FROM mtl_serial_numbers_interface
WHERE transaction_interface_id = v_serial_transaction_temp_id;
update stg_table set error_code='UP';
END IF;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('RECORDS Insertion into MTL_TRANSACTION_INTERFACE fa
iled');
END;
IF I.lot_number is not null THEN
BEGIN
INSERT INTO mtl_transaction_lots_interface
( transaction_interface_id
, serial_transaction_temp_id
, lot_number
, transaction_quantity
, created_by
, creation_date
, last_updated_by
, last_update_date
, last_update_login
, primary_quantity
, LOT_EXPIRATION_DATE
, C_ATTRIBUTE1
, D_ATTRIBUTE1
, D_ATTRIBUTE2
)
VALUES
( v_transaction_interface_id
, v_serial_transaction_temp_id
, I.lot_number
, I.quantity
, NVL(fnd_global.user_id,-1)
, SYSDATE
, NVL(fnd_global.user_id,-1)
, SYSDATE
, NVL(fnd_global.login_id,-1)
, I.quantity
, I.EXPIRATION_DATE
, I.FF_PICK_STATUS
, I.FF_ACTIVE_DATE
, I.FF_CLOSED_DATE
);
update stg_table set error_code='P';
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('RECORDS Insertion into MTL_LOT_NUMBERS_INTERFACE
failed');
END;
END IF;
IF I.serial_number is not null THEN
BEGIN
INSERT INTO mtl_serial_numbers_interface
( transaction_interface_id
, fm_serial_number
, to_serial_number
, created_by
, creation_date
, last_updated_by
, last_update_date
, last_update_login
)
VALUES
( DECODE ( v_lot_control_code, 2, v_serial_transaction_temp_id,
v_transaction_interface_id )
, I.serial_number
, I.serial_number
, NVL(fnd_global.user_id,-1)
, SYSDATE
, NVL(fnd_global.user_id,-1)
, SYSDATE
, NVL(fnd_global.login_id,-1)
);
update stg_table set error_code='P';
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('RECORDS Insertion into MTL_TRANSACTION_SERIAL_INT
ERFACE failed');
END;
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('PROC_INSERT_INTO_INTERFACE FAILED TO INSERT');
END PROC_INSERT_INTO_INTERFACE;

---------------------------------------------------
---BELOW TO INSERT DATA FROM INTERFACE TO BASE TABLES---
---------------------------------------------------
Go to front-end,
inventory responsibility->SETUP->transactions->Interface Manager,now screen open
s,in that u will have tools,press tools and click launch manager,now it will sta
rt hitting base tables
note:
If error is occurring go to Transactions -> Open Transaction Interface -> Error
-> See error
After correcting the error apply the below code
/* update mtl_transactions_interface
set process_flag = 1,
lock_flag = 2,
transaction_mode = 3,
validation_required = null,
error_code = null,
error_explanation = null
where process_flag in (1,3); */
and run procedure,and once again launch manager
once it completed,please check corresponding base tables i.e
select *from mtl_onhand_quantities where trunc(creation_date)=trunc(sysdate);
select *from mtl_lot_numbers where trunc(creation_date)=trunc(sysdate);
select *from mtl_serial_numbers where trunc(creation_date)=trunc(sysdate)

Você também pode gostar