Monday, 20 November 2017

Query to extract PO Requisitions Details

SELECT HOU.NAME "Operating unit"
     , PRH.SEGMENT1 "Requisition Number"
     , PRH.DESCRIPTION "Description"
     , PRH.TYPE_LOOKUP_CODE "Requisition Type"
     , PRH.AUTHORIZATION_STATUS "Requisition Status"
     , PPF.FULL_NAME "Preparer"
     , MSI2.SEGMENT1 "Item Number"
     , PRL.LINE_NUM "Requisition Line Num"
     , PRL.ITEM_DESCRIPTION "Requisition Line Desc"
     , PRL.UNIT_MEAS_LOOKUP_CODE "UOM"
     , PRL.QUANTITY
     , PRL.UNIT_PRICE "Unit cost"
     , MIC.SEGMENT1 || '.' || MIC.SEGMENT2 || '.' || MIC.SEGMENT3 || '.' || MIC.SEGMENT4 CATEGORY
     , HOUT.NAME ORGANIZATION
     , HLA.LOCATION_CODE LOCATION
     , PRL.DESTINATION_SUBINVENTORY DEPARTMENT
     , PPF2.FULL_NAME REQUISITER
FROM   APPS.PO_REQUISITION_HEADERS_ALL PRH
     , APPS.PO_REQUISITION_LINES_ALL PRL
     , APPS.PER_ALL_PEOPLE_F PPF
     , APPS.PER_ALL_PEOPLE_F PPF2
     , APPS.MTL_SYSTEM_ITEMS_B MSI2
     , APPS.HR_LOCATIONS_ALL HLA
     , APPS.HR_ALL_ORGANIZATION_UNITS_TL HOUT
     , APPS.MTL_CATEGORIES MIC
     , APPS.HR_OPERATING_UNITS HOU
WHERE  1 = 1
AND    HOU.ORGANIZATION_ID = PRH.ORG_ID
AND    HOUT.ORGANIZATION_ID(+) = PRL.DESTINATION_ORGANIZATION_ID
AND    HOUT.LANGUAGE(+) = USERENV ('LANG')
AND    PPF2.PERSON_ID(+) = PRL.TO_PERSON_ID
AND    TRUNC (SYSDATE) BETWEEN PPF2.EFFECTIVE_START_DATE(+) AND PPF2.EFFECTIVE_END_DATE(+)
AND    HLA.LOCATION_ID(+) = PRL.DELIVER_TO_LOCATION_ID
AND    MIC.CATEGORY_ID(+) = PRL.CATEGORY_ID
AND    MSI2.INVENTORY_ITEM_ID = PRL.ITEM_ID
AND    MSI2.INVENTORY_ITEM_ID(+) = PRL.ITEM_ID
AND    MSI2.ORGANIZATION_ID(+) = PRL.DESTINATION_ORGANIZATION_ID
AND    NVL (PRH.CANCEL_FLAG, 'N') <> 'Y'
AND    NVL (PRL.CANCEL_FLAG, 'N') <> 'Y'
AND    PRL.REQUISITION_HEADER_ID = PRH.REQUISITION_HEADER_ID
AND    PPF.PERSON_ID = PRH.PREPARER_ID
AND    TRUNC (SYSDATE) BETWEEN PPF.EFFECTIVE_START_DATE AND PPF.EFFECTIVE_END_DATE
AND    PRH.ORG_ID = 204
AND    PRH.SEGMENT1 = NVL (:REQ_NUMBER   ,PRH.SEGMENT1)                                                         -- ENTER REQUISITION NUMBER

1 comment: