SET SERVEROUTPUT ON SIZE 900000;
ALTER SESSION SET current_schema = apps;
DECLARE
v_api_return_status VARCHAR2 (500);
v_qty_oh NUMBER;
v_qty_res_oh NUMBER;
v_qty_res NUMBER;
v_qty_sug NUMBER;
v_qty_att NUMBER;
v_qty_atr NUMBER;
v_msg_count NUMBER;
v_msg_data VARCHAR2 (1000);
CURSOR c_item_info (
l_subinventory_code VARCHAR2,
l_organization_id NUMBER,
l_inventory_item_id NUMBER
)
IS
SELECT inventory_item_id, subinventory_code, organization_id
FROM apps.mtl_onhand_quantities_detail
WHERE inventory_item_id =
NVL (l_inventory_item_id, inventory_item_id)
AND organization_id = l_organization_id
AND subinventory_code = l_subinventory_code
GROUP BY inventory_item_id, organization_id, subinventory_code;
ln_subinventory_code VARCHAR2 (100);
ln_organization_id NUMBER;
ln_inventory_item_id NUMBER;
l_item VARCHAR2 (15);
BEGIN
/*Mandatory */
ln_subinventory_code := 'LAAC11'; --:p_subinventory_code;
/*Mandatory*/
ln_organization_id := 331; --:p_organization_id;
/*Optional*/
ln_inventory_item_id := NULL; --:p_inventory_item_id;
inv_quantity_tree_grp.clear_quantity_cache;
DBMS_OUTPUT.put_line ('Sub Inventory|Organization Id|Item|Onhand Qty|Available To Transact|Available To Reserve');
FOR i IN c_item_info (ln_subinventory_code,
ln_organization_id,
ln_inventory_item_id
)
LOOP
BEGIN
SELECT segment1
INTO l_item
FROM mtl_system_items_b
WHERE inventory_item_id = i.inventory_item_id
AND organization_id = i.organization_id;
EXCEPTION
WHEN OTHERS
THEN
l_item := NULL;
END;
APPS.INV_QUANTITY_TREE_PUB.QUERY_QUANTITIES
(p_api_version_number => 1.0,
p_init_msg_lst => apps.fnd_api.g_false,
x_return_status => v_api_return_status,
x_msg_count => v_msg_count,
x_msg_data => v_msg_data,
p_organization_id => i.organization_id,
p_inventory_item_id => i.inventory_item_id,
p_tree_mode => apps.inv_quantity_tree_pub.g_transaction_mode,
p_onhand_source => apps.inv_quantity_tree_pvt.g_all_subs,
--3,
p_is_revision_control => FALSE,
p_is_lot_control => FALSE,
p_is_serial_control => FALSE,
p_revision => NULL,
p_lot_number => NULL,
p_subinventory_code => i.subinventory_code,
p_locator_id => NULL,
x_qoh => v_qty_oh,
x_rqoh => v_qty_res_oh,
x_qr => v_qty_res,
x_qs => v_qty_sug,
x_att => v_qty_att,
x_atr => v_qty_atr
);
DBMS_OUTPUT.put_line (i.subinventory_code||'|'||i.organization_id||'|'||l_item||'|'||v_qty_oh||'|'||v_qty_att||'|'||v_qty_atr);
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
raise_application_error (-20001, 'An error was encountered - ' || SQLCODE || ' -ERROR- '|| SQLERRM);
END;
/