CREATE OR REPLACE FUNCTION APPS.XX_ON_HAND_QTY_FUN(P_INVENTORY_ITEM_ID number)
RETURN NUMBER
IS
L_API_RETURN_STATUS VARCHAR2 (1);
L_QTY_OH NUMBER;
L_QTY_RES_OH NUMBER;
L_QTY_RES NUMBER;
L_QTY_SUG NUMBER;
L_QTY_ATT NUMBER;
L_QTY_ATR NUMBER;
L_MSG_COUNT NUMBER;
L_MSG_DATA VARCHAR2 (1000);
L_QTY_OH_ALL NUMBER :=0;
CURSOR CUR_ON_HAND IS
SELECT OOD.ORGANIZATION_ID,OOD.ORGANIZATION_CODE, OOD.ORGANIZATION_NAME,
MSI.SEGMENT1,MSI.INVENTORY_ITEM_ID
FROM ORG_ORGANIZATION_DEFINITIONS OOD,
MTL_SYSTEM_ITEMS_B MSI,
FND_LOOKUP_VALUES FLV
WHERE OOD.ORGANIZATION_CODE = LOOKUP_CODE
AND OOD.ORGANIZATION_ID = MSI.ORGANIZATION_ID
AND FLV.LOOKUP_TYPE = 'CORR_DS_PUR_WH'
AND FLV.ENABLED_FLAG = 'Y'
AND FLV.END_DATE_ACTIVE IS NULL
AND MSI.INVENTORY_ITEM_ID = P_INVENTORY_ITEM_ID;
/*SELECT OOD.ORGANIZATION_ID,OOD.ORGANIZATION_CODE, OOD.ORGANIZATION_NAME,
MSI.SEGMENT1,MSI.INVENTORY_ITEM_ID
FROM ORG_ORGANIZATION_DEFINITIONS OOD,
MTL_SYSTEM_ITEMS_B MSI
WHERE OOD.ORGANIZATION_CODE LIKE 'W%'
AND OOD.ORGANIZATION_ID = MSI.ORGANIZATION_ID
AND MSI.INVENTORY_ITEM_ID = P_INVENTORY_ITEM_ID;
--AND MSI.SEGMENT1 = '3020004431'
*/
BEGIN
BEGIN
FOR CUR_REC_ON_HAND IN CUR_ON_HAND
LOOP
INV_QUANTITY_TREE_GRP.CLEAR_QUANTITY_CACHE;
DBMS_OUTPUT.PUT_LINE ('TRANSACTION MODE');
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 => L_API_RETURN_STATUS,
X_MSG_COUNT => L_MSG_COUNT,
X_MSG_DATA => L_MSG_DATA,
P_ORGANIZATION_ID => CUR_REC_ON_HAND.ORGANIZATION_ID, --P_INV_ORGANIZATION_ID,
P_INVENTORY_ITEM_ID => CUR_REC_ON_HAND.INVENTORY_ITEM_ID, --P_INVENTORY_ITEM_ID,
P_TREE_MODE => APPS.INV_QUANTITY_TREE_PUB.G_TRANSACTION_MODE,
P_ONHAND_SOURCE => 3, --NULL- CHANGED PER NOTE 296015.1 ,
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 => NULL, --'RMWH-NR-RT'---NULL
P_LOCATOR_ID => NULL,
X_QOH => L_QTY_OH,
X_RQOH => L_QTY_RES_OH,
X_QR => L_QTY_RES,
X_QS => L_QTY_SUG,
X_ATT => L_QTY_ATT,
X_ATR => L_QTY_ATR
);
/*
DBMS_OUTPUT.put_line ('================================');
DBMS_OUTPUT.put_line ('Quantity on hand = ' || TO_CHAR (L_QTY_OH));
DBMS_OUTPUT.put_line ('Quantity res oh = ' || TO_CHAR (L_QTY_RES_OH));
DBMS_OUTPUT.put_line ('Quantity res = ' || TO_CHAR (L_QTY_RES));
DBMS_OUTPUT.put_line ('Quantity sug = ' || TO_CHAR (L_QTY_SUG));
DBMS_OUTPUT.put_line ('Quantity ATT = ' || TO_CHAR (L_QTY_ATT));
DBMS_OUTPUT.put_line ('Quantity ATR = ' || TO_CHAR (L_QTY_ATR));
DBMS_OUTPUT.put_line ('ORGANIZATION_ID = ' || CUR_REC_ON_HAND.ORGANIZATION_ID);
DBMS_OUTPUT.put_line ('INVENTORY_ITEM_ID = ' || CUR_REC_ON_HAND.INVENTORY_ITEM_ID);
DBMS_OUTPUT.put_line ('ALL Quantity on hand = ' || TO_CHAR (L_QTY_OH_ALL));
*/
L_QTY_OH_ALL := NVL(L_QTY_OH,0) + NVL(L_QTY_OH_ALL,0);
END LOOP;
END;
RETURN L_QTY_OH_ALL;
--L_QTY_OH;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END;
/
No comments:
Post a Comment