hi All,
I have the requirement to populate mtl_supply_demand_temp table while running a custom process.
I am doing so by executing the belo code:
DECLARE
CURSOR C1 IS
SELECT cpr.organization_id, CPR.INVENTORY_ITEM_ID --, cpr.item_no
FROM mtl_system_items_b cpr
WHERE cpr.organization_id = 1 AND segment1 = 'XXXX';
-- AND cpr.need_by_date BETWEEN TO_CHAR (p_need_by_date_s,
-- 'YYYY/MM/DD')
-- AND TO_CHAR (p_need_by_date_e,
-- 'YYYY/MM/DD');
V_SEQ_NUM NUMBER;
V_CUTOFF_DATE_J NUMBER;
V_TOTAL_TEMP VARCHAR2 (30);
V_AVAIL_QTY_TEMP VARCHAR2 (30);
--V_ORGANIZATION_ID NUMBER := 11;
V_ITEM_NO VARCHAR2 (100) := '';
V_USER_NAME VARCHAR2 (10) := 'UDIT.JAIN';
--V_DELETE_TEMP VARCHAR2(1):='Y';
V_USER_ID NUMBER;
V_RESPONSIBILITY_ID NUMBER;
V_APPLICATION_ID NUMBER;
v_quantity NUMBER := 0;
V_SUPPLY_DEMAND NUMBER := 0;
timeout NUMBER := 300;
BEGIN
-- ?? CLIENT ? PROFILE ?
SELECT a.user_id
INTO V_USER_ID
FROM APPS.fnd_user a
WHERE a.user_name = V_USER_NAME;
SELECT R.RESPONSIBILITY_ID, R.APPLICATION_ID
INTO V_RESPONSIBILITY_ID, V_APPLICATION_ID
FROM APPS.FND_RESPONSIBILITY_TL R
WHERE R.RESPONSIBILITY_NAME = 'Inventory' AND R.LANGUAGE = 'US';
-- ?? CLIENT ? PROFILE ?
FND_GLOBAL.APPS_INITIALIZE (V_USER_ID,
V_RESPONSIBILITY_ID,
V_APPLICATION_ID);
-- ??????
--INV_GLOBALS.SET_ORG_ID (V_ORGANIZATION_ID);
mo_global.set_policy_context ('S', i.ORGANIZATION_ID);
V_CUTOFF_DATE_J := NULL;
DBMS_OUTPUT.PUT_LINE ('V_CUTOFF_DATE_J=' || V_CUTOFF_DATE_J);
SELECT MTL_DEMAND_INTERFACE_S.NEXTVAL INTO V_SEQ_NUM FROM DUAL;
DBMS_OUTPUT.PUT_LINE ('V_SEQ_NUM=' || V_SEQ_NUM);
V_TOTAL_TEMP := -1;
V_AVAIL_QTY_TEMP := -1;
FOR I IN C1
LOOP
IF (APPS.INV_TM.LAUNCH (
'INXDSD', ---
'INXDSD'
|| ' '
|| 'GROUP_ID='
|| TO_CHAR (V_SEQ_NUM)
|| ' '
|| 'ORGANIZATION_ID='
|| TO_CHAR (i.ORGANIZATION_ID)
|| ' '
|| 'INVENTORY_ITEM_ID='
|| TO_CHAR (I.INVENTORY_ITEM_ID)
|| ' '
|| 'ONHAND_SOURCE='
|| '3'
|| ' '
|| 'CUTOFF_DATE="'
|| TO_CHAR (V_CUTOFF_DATE_J)
|| '" '
|| 'MRP_STATUS='
|| '1'
|| ' '
|| 'ONHAND_FIELD=V_TOTAL_TEMP '
|| 'AVAIL_FIELD=V_AVAIL_QTY_TEMP',
'V_TOTAL_TEMP',
'V_AVAIL_QTY_TEMP',
timeout => timeout) = FALSE)
THEN
DBMS_OUTPUT.PUT_LINE ('FAILED');
ELSE
BEGIN
SELECT NVL (SUM (quantity), 0)
INTO V_SUPPLY_DEMAND
FROM APPS.MTL_SUPPLY_DEMAND_TEMP
WHERE SEQ_NUM = V_SEQ_NUM
AND ORGANIZATION_ID = V_ORGANIZATION_ID
AND INVENTORY_ITEM_ID = I.INVENTORY_ITEM_ID;
EXCEPTION
WHEN OTHERS
THEN
V_SUPPLY_DEMAND := 0;
END;
END IF;
END LOOP;
DBMS_OUTPUT.put_line ('V_SUPPLY_DEMAND ' || V_SUPPLY_DEMAND);
DBMS_OUTPUT.put_line ('V_TOTAL_TEMP ' || V_TOTAL_TEMP); --- prints -1
DBMS_OUTPUT.put_line ('V_AVAIL_QTY_TEMP ' || V_AVAIL_QTY_TEMP); --- prints -1
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Error: ' || SQLERRM);
END;
--select * from MTL_SUPPLY_DEMAND_TEMP
--where seq_num = 190937583
--AND supply_demand_source_type = 5
--order by on_hand_quantity desc
Unfortunately even though the values do get populated the quantity and onhand quantity field values are not matching when the similar data is queried on the supply demand form.
Has anyone had a similar requirement to populate this table or if anyone could provide me a query which fetches similar data.