在Oracle Application中,standard 功能是調用下面API來計算Onhand Quantity的:inv_quantity_tree_pub.query_quantities
( p_api_version_number => 1.0,
p_init_msg_lst => 'F',
x_return_status => x_return_status,
x_msg_count => x_msg_count,
x_msg_data => x_msg_data,
p_organization_id => p_organization_id,
p_inventory_item_id => p_inventory_item_id,
p_tree_mode => tree_mode,
p_is_revision_control => is_revision_control,
p_is_lot_control => is_lot_control,
p_is_serial_control => FALSE,
p_revision => p_revision,
p_lot_number => p_lot_number,
p_lot_expiration_date => sysdate,
p_subinventory_code => p_subinventory_code,
p_locator_id => p_locator_id,
p_cost_group_id => cg_id,
p_onhand_source => 3,
x_qoh => qoh,
x_rqoh => rqoh,
x_qr => qr,
x_qs => qs,
x_att => att,
x_atr => atr,
p_grade_code => p_grade_code,
x_sqoh => sqoh,
x_satt => satt,
x_satr => satr ,
x_srqoh => x_srqoh,
x_sqr => x_sqr,
x_sqs => x_sqs,
p_demand_source_type_id => -1 ,
p_demand_source_header_id => -1 ,
p_demand_source_line_id => -1 ,
p_demand_source_name => NULL ,
p_transfer_subinventory_code => NULL ,
p_transfer_locator_id => NULL
);參數基本上一看能猜出大概意思,對幾個特殊的參數解釋說明一下:【1】
p_tree_modeR12的standard form後台是這樣解釋的:* The parameter p_tree_mode determines which values to fetch:
* 2 => Fetch both packed and loose quantities
* 3 => Fetch only loose quantities
* To determine whether ONLY loose quantities are to be displayed:
* a) Subinventory, cost group for the current record (in QUANTITY_FOLDER block) are not NULL
* b) QUANTITY_FOLDER.PACKED is NOT NULL (for WMS org) and is equal to 0
* c) The current record does not have VMI or consigned stock
* d) For a lot controlled item, the QUANTITY_FOLDER.LOT_NUMBER is not null.
* When the above conditions are TRUE, then call the quantity tree with tree_mode = 3 and default
* the on-hand quantity to :QUANTITY_FOLDER.ON_HAND.
* If the current node has VMI or consigned stock, am showing the entire quantity(both packed and loose)【2】
p_onhand_sourceUsed to determine which subs are included in calculation of onhand qty有4個可選值:inv_quantity_tree_pvt.g_atpable_only CONSTANT NUMBER := 1;
inv_quantity_tree_pvt.g_nettable_only CONSTANT NUMBER := 2;
inv_quantity_tree_pvt.g_all_subs CONSTANT NUMBER := 3;
inv_quantity_tree_pvt.g_atpable_nettable_only CONSTANT NUMBER := 4;這幾個值是在Lookup code中設定的,lookup type: MTL_ONHAND_SOURCE【3】x_att傳回值。available to transact 【4】x_atr傳回值。available to reserve
在計算物料的可保留量的時候,我們通常的做法是MTL_ONHAND_QUANTITIES
中的TRANSACTION_QUANTITY的數量按照組織+物料+子庫+貨位+批次…的方式
進行累計,然後再減去物料在MTL_RESERVATIONS 中對應的保留。很多的時候沒有去考
慮此時庫存交易處理介面表(MTL_MATERIAL_TRANSACTIONS_TEMP)中物料數量,這樣計算
出來的數量可能會不準確。以下是考慮了庫存交易處理介面表的物料數量的計算方
式。大家不妨可以參考一下。
/*--------------------------------------------------------------------------------
$ Header PTAC , SKip Siman He , 2008.03.25
* Procedure GET_ITEM_ATT_QTY
* Purpose :
計算物料的可用量
---------------------------------------------------------------------------- */
FUNCTION get_item_att_qty(p_item_id NUMBER,
p_organization_id NUMBER,
p_subinventory_code VARCHAR2) RETURN NUMBER IS
l_onhand_qty NUMBER;
l_resv_qty NUMBER;
l_qoh NUMBER;
l_rqoh NUMBER;
l_qr NUMBER;
l_qs NUMBER;
l_att NUMBER;
l_atr NUMBER;
l_tree_mode NUMBER;
l_msg_count VARCHAR2(100);
l_msg_data VARCHAR2(1000);
l_return_status VARCHAR2(1);
x_return VARCHAR2(1);
BEGIN
-- Transact mode
l_tree_mode := 2;
inv_quantity_tree_pub.clear_quantity_cache;
inv_quantity_tree_pub.query_quantities
p_api_version_number => 1.0,
p_init_msg_lst => 'F',
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
p_organization_id => p_organization_id,
p_inventory_item_id => p_item_id,
p_tree_mode => l_tree_mode,
p_is_revision_control => FALSE,
p_is_lot_control => FALSE,
p_is_serial_control => FALSE,
p_revision => NULL,
p_lot_number => NULL,
p_lot_expiration_date => NULL,
p_subinventory_code => p_subinventory_code,
p_locator_id => NULL,
p_onhand_source => inv_quantity_tree_pvt.g_all_subs,
x_qoh => l_qoh,
x_rqoh => l_rqoh,
x_qr => l_qr,
Oracle ERP R12實用技術開發.doc
x_qs => l_qs,
x_att => l_att, --可用量
x_atr => l_atr); --可保留量
RETURN l_att;
END;
在INV模組,使用者查看物料數量最多的三個欄位是現用量,可保留量,可處理量。下面的procedure是漢得技術顧問在公司上線時候提供的。
CREATE OR REPLACE PROCEDURE get_inv_quantity(p_organization_id IN NUMBER
, p_inventory_item_id IN NUMBER
, p_lot_number IN VARCHAR2
, p_subinventory_code IN VARCHAR2
, p_locator_id IN NUMBER
, x_onhand_qty OUT NUMBER
, x_reservable_qty OUT NUMBER
, x_transactable_qty OUT NUMBER) IS
l_return_status VARCHAR2(1) ;
l_msg_count NUMBER;
l_msg_data VARCHAR2(2000);
l_is_revision_control BOOLEAN := TRUE ;
l_is_lot_control BOOLEAN := TRUE ;
l_is_serial_control BOOLEAN := FALSE ;
p_revision VARCHAR2(100); l_qoh NUMBER;
l_rqoh NUMBER;
l_qr NUMBER;
l_qs NUMBER;
l_att NUMBER;
l_atr NUMBER;
p_lpn_id NUMBER; BEGIN IF p_lot_number IS NULL THEN
l_is_lot_control := FALSE ;
END IF; IF p_locator_id IS NULL THEN
l_is_lot_control := FALSE ;
END IF; inv_quantity_tree_pub.query_quantities
( p_api_version_number => 1.0
, p_init_msg_lst => 'F'
, x_return_status => l_return_status
, x_msg_count => l_msg_count
, x_msg_data => l_msg_data
, p_organization_id => p_organization_id
, p_inventory_item_id => p_inventory_item_id
, p_tree_mode => 1
, p_is_revision_control => FALSE -- No Revision Control
, p_is_lot_control => l_is_lot_control
, p_is_serial_control => l_is_serial_control
, p_demand_source_type_id => 2
, p_revision => NULL
, p_lot_number => p_lot_number
, p_lot_expiration_date => sysdate
, p_subinventory_code => p_subinventory_code
, p_locator_id => p_locator_id
, p_onhand_source => 3
, x_qoh => l_qoh
, x_rqoh => l_rqoh
, x_qr => l_qr
, x_qs => l_qs
, x_att => l_att
, x_atr => l_atr
, p_lpn_id => NULL); IF (l_return_status = 'S') THEN
x_onhand_qty := l_qoh;
x_reservable_qty := l_atr;
ELSE
l_return_status :='F';
RETURN ;
END IF ; inv_quantity_tree_pub.query_quantities
( p_api_version_number => 1.0
, p_init_msg_lst => 'F'
, x_return_status => l_return_status
, x_msg_count => l_msg_count
, x_msg_data => l_msg_data
, p_organization_id => p_organization_id
, p_inventory_item_id => p_inventory_item_id
, p_tree_mode => 2
, p_is_revision_control => FALSE -- No Revision Control
, p_is_lot_control => l_is_lot_control
, p_is_serial_control => l_is_serial_control
, p_demand_source_type_id => 2
, p_revision => NULL
, p_lot_number => p_lot_number
, p_lot_expiration_date => sysdate
, p_subinventory_code => p_subinventory_code
, p_locator_id => p_locator_id
, p_onhand_source => 3
, x_qoh => l_qoh
, x_rqoh => l_rqoh
, x_qr => l_qr
, x_qs => l_qs
, x_att => l_att
, x_atr => l_atr
, p_lpn_id => NULL); IF (l_return_status = 'S') THEN
x_onhand_qty := l_qoh;
x_transactable_qty := l_att;
ELSE
l_return_status :='F';
RETURN;
END IF ; END get_inv_quantity ; create or replace function get_reservable_qty(p_organization_id number,p_inventory_item_id number,p_sub varchar2) return number is
l_onhand_qty number;
l_reservable_qty number;
l_transactable_qty number;
begin
--p_sub可以為空白,為空白時,所有庫別的可保留數量
get_inv_quantity(p_organization_id => p_organization_id,
p_inventory_item_id => p_inventory_item_id,
p_lot_number => null,
p_subinventory_code => p_sub,
p_locator_id => null,
x_onhand_qty => l_onhand_qty,
x_reservable_qty => l_reservable_qty,
x_transactable_qty => l_transactable_qty);
return l_reservable_qty;
end get_reservable_qty;