mtl_reservations

 SELECT X.ORGANIZATION_ID ORGANIZATION_ID , X.INVENTORY_ITEM_ID INVENTORY_ITEM_ID , X.REVISION REVISION , NULL LOT_NUMBER , NULL LOT_EXPIRATION_DATE , X.SUBINVENTORY_CODE SUBINVENTORY_CODE , SUB.RESERVABLE_TYPE RESERVABLE_TYPE , X.LOCATOR_ID LOCATOR_ID , SUM(X.PRIMARY_QUANTITY) PRIMARY_QUANTITY , SUM(X.SECONDARY_QUANTITY) SECONDARY_QUANTITY , X.QUANTITY_TYPE QUANTITY_TYPE , X.COST_GROUP_ID COST_GROUP_ID , X.LPN_ID LPN_ID , X.TRANSACTION_ACTION_ID TRANSACTION_ACTION_ID , X.TRANSFER_SUBINVENTORY_CODE TRANSFER_SUBINVENTORY_CODE , X.TRANSFER_LOCATOR_ID TRANSFER_LOCATOR_ID FROM ( SELECT X.ORGANIZATION_ID ORGANIZATION_ID , X.INVENTORY_ITEM_ID INVENTORY_ITEM_ID , DECODE(:B10 , 2, NULL , X.REVISION) REVISION , NULL LOT_NUMBER , X.SUBINVENTORY_CODE SUBINVENTORY_CODE , X.LOCATOR_ID LOCATOR_ID , SUM(X.PRIMARY_QUANTITY) PRIMARY_QUANTITY , SUM(X.SECONDARY_QUANTITY) SECONDARY_QUANTITY , X.QUANTITY_TYPE QUANTITY_TYPE , X.COST_GROUP_ID COST_GROUP_ID , X.LPN_ID LPN_ID , X.TRANSACTION_ACTION_ID TRANSACTION_ACTION_ID , X.TRANSFER_SUBINVENTORY_CODE TRANSFER_SUBINVENTORY_CODE , X.TRANSFER_LOCATOR_ID TRANSFER_LOCATOR_ID FROM ( SELECT MR.ORGANIZATION_ID ORGANIZATION_ID , MR.INVENTORY_ITEM_ID INVENTORY_ITEM_ID , MR.REVISION REVISION , MR.LOT_NUMBER LOT_NUMBER , MR.SUBINVENTORY_CODE SUBINVENTORY_CODE , MR.LOCATOR_ID LOCATOR_ID , MR.PRIMARY_RESERVATION_QUANTITY - NVL(MR.DETAILED_QUANTITY, 0) PRIMARY_QUANTITY , MR.SECONDARY_RESERVATION_QUANTITY - NVL(MR.SECONDARY_DE TAILED_QUANTITY, 0) SECONDARY_QUANTITY , 3 QUANTITY_TYPE , TO_NUMBER(NULL) COST_GROUP_ID , LPN_ID LPN_ID , TO_NUMBER(NULL) TRANSACTION_ACTION_ID , TO_CHAR(NULL) TRANSFER_SUBINVENTORY_CODE , TO_NUMBER(NULL) TRANSFER_LOCATOR_ID FROM MTL_RESERVATIONS MR WHERE NVL(MR.SUPPLY_SOURCE_TYPE_ID, 13) = 13 AND MR.PRIMARY_RESERVATION_QUANTITY > NVL(MR.DETAILED_QUANTITY, 0) AND ((:B7 <>1) OR (:B7 = 1 AND MR.LPN_ID IS NULL)) AND (:B6 <> 3 OR (:B6 = 3 AND NOT (:B5 = MR.DEMAND_SOURCE_TYPE_ID AND :B4 = MR.DEMAND_SOURCE_HEADER_ID AND NVL(:B3 , -9999) = NVL(MR.DEMAND_SOURCE_LINE_ID, -9999) AND NVL(:B2 , '@@@###@@#') = NVL(MR.DEMAND_SOURCE_NAME, '@@@###@@#') AND NVL(:B1 , -9999) = NVL(MR.DEMAND_SOURCE_DELIVERY, -9999) ) )) UNION ALL SELECT MOQ.ORGANIZATION_ID ORGANIZATION_ID , MOQ.INVENTORY_ITEM_ID INVENTORY_ITEM_ID , MOQ.REVISION REVISION , MOQ.LOT_NUMBER LOT_NUMBER , MOQ.SUBINVENTORY_CODE SUBINVENTORY_CODE , MOQ.LOCATOR_ID LOCATOR_ID , MOQ.PRIMARY_TRANSACTION_QUANTITY , MOQ.SECONDARY_TRANSACTION_QUANTITY , 1 QUANTITY_TYPE , MOQ.COST_GROUP_ID COST_GROUP_ID , MOQ.LPN_ID LPN_ID , TO_NUMBER(NULL) TRANSACTION_ACTION_ID , TO_CHAR(NULL) TRANSFER_SUBINVENTORY_CODE , TO_NUMBER(NULL) TRANSFER_LOCATOR_ID FROM MTL_ONHAND_QUANTITIES_DETAIL MOQ UNION ALL SELECT MMTT.ORGANIZATION_ID ORGANIZATION_ID , MMTT.INVENTORY_ITEM_ID INVENTORY_ITEM_ID , MMTT.REVISION REVISION , NULL LOT_NUMBER , MMTT.SUBINVENTORY_CODE SUBINVENTORY_CODE , MMTT.LOCATOR_ID LOCATOR_ID , DECODE(DECO DE(MMTT.TRANSACTION_STATUS, 2, DECODE(NVL(MMTT.WMS_TASK_STATUS, -1), 4, -1, 2), MMTT.TRANSACTION_STATUS), 2, 1, DECODE(MMTT.TRANSACTION_ACTION_ID, 1, -1, 2, -1, 28, -1, 3, -1, SIGN(MMTT.PRIMARY_QUANTITY))) * ROUND(ABS(MMTT.PRIMARY_QUANTITY), 5) , DECODE(DECODE(MMTT.TRANSACTION_STATUS, 2, DECODE(NVL(MMTT.WMS_TASK_STATUS, -1), 4, -1, 2), MMTT.TRANSACTION_STATUS), 2, 1, DECODE(MMTT.TRANSACTION_ACTION_ID, 1, -1, 2, -1, 28, -1, 3, -1, SIGN(MMTT.SECONDARY_TRANSACTION_QUANTITY))) * ROUND(ABS(MMTT.SECONDARY_TRANSACTION_QUANTITY), 5) , DECODE(MMTT.TRANSACTION_STATUS, 2, DECODE(NVL(MMTT.WMS_TASK_STATUS, -1), 4, 1, 5), 1) QUANTITY_TYPE , MMTT.COST_GROUP_ID COST_GROUP_ID , NVL(MMTT.ALLOCATED_LPN_ID, NVL(MMTT.CONTENT_LPN_ID, MMTT.LPN_ID)) LPN_ID , DECODE(MMTT.TRANSACTION_STATUS, 2 , MMTT.TRANSACTION_ACTION_ID, TO_NUMBER(NULL)) TRANSACTION_ACTION_ID , DECODE(MMTT.TRANSACTION_STATUS, 2 , MMTT.TRANSFER_SUBINVENTORY, TO_CHAR(NULL)) TRANSFER_SUBINVENTORY_CODE , DECODE(MMTT.TRANSACTION_STATUS, 2 , MMTT.TRANSFER_TO_LOCATION, TO_NUMBER(NULL)) TRANSFER_LOCATOR_ID FROM MTL_MATERIAL_TRANSACTIONS_TEMP MMTT WHERE MMTT.POSTING_FLAG = 'Y' AND MMTT.SUBINVENTORY_CODE IS NOT NULL AND (NVL(MMTT.TRANSACTION_STATUS, 0) <> 2 OR NVL(MMTT.TRANSACTION_STATUS, 0) = 2 AND MMTT.TRANSACTION_ACTION_ID IN (1, 2, 28, 3, 21, 29, 32, 34) ) AND MMTT.TRANSACTION_ACTION_ID NOT IN (5, 6, 24, 30) UNION ALL SELECT DECODE(MMTT.TRANSACTION_ACTION_ID , 3, MMTT.TRANSFER_ORGANIZATION , MMTT .ORGANIZATION_ID) ORGANIZATION_ID , MMTT.INVENTORY_ITEM_ID INVENTORY_ITEM_ID , MMTT.REVISION REVISION , NULL LOT_NUMBER , MMTT.TRANSFER_SUBINVENTORY SUBINVENTORY_CODE , MMTT.TRANSFER_TO_LOCATION LOCATOR_ID , ROUND(ABS(MMTT.PRIMARY_QUANTITY), 5) , ROUND(ABS(MMTT.SECONDARY_TRANSACTION_QUANTITY), 5) , 1 QUANTITY_TYPE , MMTT.TRANSFER_COST_GROUP_ID COST_GROUP_ID , NVL(MMTT.CONTENT_LPN_ID, MMTT.TRANSFER_LPN_ID) LPN_ID , TO_NUMBER(NULL) TRANSACTION_ACTION_ID , TO_CHAR(NULL) TRANSFER_SUBINVENTORY_CODE , TO_NUMBER(NULL) TRANSFER_LOCATOR_ID FROM MTL_MATERIAL_TRANSACTIONS_TEMP MMTT WHERE MMTT.POSTING_FLAG = 'Y' AND NVL(MMTT.TRANSACTION_STATUS, 0) <> 2 AND MMTT.TRANSACTION_ACTION_ID IN (2, 28, 3) AND MMTT.WIP_SUPPLY_TYPE IS NULL ) X WHERE X.ORGANIZATION_ID = :B9 AND X.INVENTORY_ITEM_ID = :B8 GROUP BY X.ORGANIZATION_ID, X.INVENTORY_ITEM_ID, X.REVISION , X.LOT_NUMBER, X.SUBINVENTORY_CODE, X.LOCATOR_ID , X.QUANTITY_TYPE, X.COST_GROUP_ID, X.LPN_ID , X.TRANSACTION_ACTION_ID, X.TRANSFER_SUBINVENTORY_CODE , X.TRANSFER_LOCATOR_ID ) X , MTL_SECONDARY_INVENTORIES SUB WHERE X.ORGANIZATION_ID = SUB.ORGANIZATION_ID (+) AND X.SUBINVENTORY_CODE = SUB.SECONDARY_INVENTORY_NAME (+) AND (:B12 = 2 OR NVL(SUB.ASSET_INVENTORY, 1) = 1) AND ((:B11 =1 AND NVL(SUB.INVENTORY_ATP_CODE, 1) = 1 ) OR (:B11 = 2 AND NVL(SUB.AVAILABILITY_TYPE, 1) = 1 ) OR :B11 =3 OR (:B11 = 4 AND (NVL(SUB.INVENTORY_ATP_CODE, 1) = 1 AND NVL(SUB.AVAILABILITY_TYPE, 1)=1)) ) GROUP BY X.ORGANIZATION_ID , X.IN VENTORY_ITEM_ID , X.REVISION , NULL , NULL , SUB.RESERVABLE_TYPE , X.SUBINVENTORY_CODE , NULL , X.LOCATOR_ID , X.QUANTITY_TYPE , X.COST_GROUP_ID , X.LPN_ID , X.TRANSACTION_ACTION_ID , X.TRANSFER_SUBINVENTORY_CODE , X.TRANSFER_LOCATOR_ID

你可能感兴趣的:(oracle,pl/sql,Oracle,EBS)