DECLARE
L_ITEM_ID NUMBER;
L_ORGANIZATION_ID NUMBER := 0;
L_ITEM_COUNT NUMBER;
M_EXISTS VARCHAR2 (1);
L_ERR_FLAG CHAR (1) := 'N';
M_ITEM VARCHAR2 (240);
M_ORG_CODE VARCHAR2 (240);
M_SUBINV VARCHAR2 (240);
CURSOR C
IS
SELECT SEGMENT1, INVENTORY_ITEM_ID, ORGANIZATION_ID
FROM APPS.MTL_SYSTEM_ITEMS
WHERE ORGANIZATION_ID = 122 -- organization wise
AND STOCK_ENABLED_FLAG = 'Y'
AND CREATION_DATE > '01-JUN-2011'; -- CUT OF DATE
CURSOR SUB_INVS (
P_ORGANIZATION_ID IN NUMBER
)
IS
SELECT DISTINCT SECONDARY_INVENTORY_NAME
FROM APPS.MTL_SECONDARY_INVENTORIES
WHERE ORGANIZATION_ID = 122
AND SECONDARY_INVENTORY_NAME IN ('EL-HA', 'STAGING');
-- Subinventories defined for organization
BEGIN
DBMS_OUTPUT.PUT_LINE('Started populating interface tables at : '
|| TO_CHAR (SYSDATE, 'DD-MON-RRRR HH:MI:SS'));
L_ITEM_COUNT := 0;
FOR R IN C
LOOP
L_ITEM_ID := NULL;
L_ORGANIZATION_ID := NULL;
IF (L_ERR_FLAG <> 'Y')
THEN
FOR R1 IN SUB_INVS (R.ORGANIZATION_ID)
LOOP
BEGIN
-- CHECK IF THE ITEM- ORGANIZATION - SUBINVENTORY COMBINATION IS ALREADY EXISTING --
SELECT 'm'
INTO M_EXISTS
FROM APPS.MTL_ITEM_SUB_INVENTORIES
WHERE INVENTORY_ITEM_ID = R.INVENTORY_ITEM_ID
AND ORGANIZATION_ID = R.ORGANIZATION_ID
AND SECONDARY_INVENTORY = R1.SECONDARY_INVENTORY_NAME;
--DBMS_OUTPUT.PUT_LINE('INVENTORY_ITEM_ID :'||R.INVENTORY_ITEM_ID);
--DBMS_OUTPUT.PUT_LINE('ORGANIZATION_ID :'||R.ORGANIZATION_ID);
--DBMS_OUTPUT.PUT_LINE('SUB INVENTORY :'||R1.SECONDARY_INVENTORY_NAME);
----- IF THE COMBINATION DOESNOT EXIST THEN POPULATE TO THE SUBINVENTORY TABLE ----------------
SELECT SEGMENT1
INTO M_ITEM
FROM MTL_SYSTEM_ITEMS_B
WHERE INVENTORY_ITEM_ID = R.INVENTORY_ITEM_ID
AND ORGANIZATION_ID = R.ORGANIZATION_ID;
SELECT ORGANIZATION_CODE
INTO M_ORG_CODE
FROM ORG_ORGANIZATION_DEFINITIONS
WHERE ORGANIZATION_ID = R.ORGANIZATION_ID;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.PUT_LINE( M_ITEM
|| '-'
|| M_ORG_CODE
|| '-'
|| R1.SECONDARY_INVENTORY_NAME);
/* Commented to Verify first
INSERT INTO APPS.MTL_ITEM_SUB_INVENTORIES (
INVENTORY_ITEM_ID,
ORGANIZATION_ID,
SECONDARY_INVENTORY,
LAST_UPDATE_DATE,
LAST_UPDATED_BY,
CREATION_DATE,
CREATED_BY,
LAST_UPDATE_LOGIN,
INVENTORY_PLANNING_CODE
)
VALUES (R.INVENTORY_ITEM_ID,
R.ORGANIZATION_ID,
R1.SECONDARY_INVENTORY_NAME,
SYSDATE,
-1,
SYSDATE,
-1,
-1,
6);
COMMIT;
*/
L_ITEM_COUNT := L_ITEM_COUNT + 1;
WHEN OTHERS
THEN
NULL;
END;
END LOOP;
END IF;
-- END IF;
END LOOP;
END;
No comments:
Post a Comment