Purchase Order Report Query

Purchase Order Report Query, www.askhareesh.com
Header level
SELECT      PHA.SEGMENT1            PONUM
            ,PHA.TYPE_LOOKUP_CODE   POTYPE
            ,H1.LOCATION_CODE       BILLTO
            ,H2.LOCATION_CODE       SHIPTO
            ,PHA.CREATION_DATE      CDATE
            ,PPF.LAST_NAME||','||PPF.FIRST_NAME BUYER
            ,APS.VENDOR_NAME        SUPPLIER
            ,APSS.VENDOR_SITE_CODE  SUPPLIERSITE
            ,APSC.LAST_NAME||','||APSC.FIRST_NAME   CONTACT
            ,PHA.AUTHORIZATION_STATUS   STATUS
            ,APT.NAME               PAYMENTTERMS
            ,PHA.FREIGHT_TERMS_LOOKUP_CODE  FRIEGHT
            ,PHA.FOB_LOOKUP_CODE        FOB
            ,PHA.SHIP_VIA_LOOKUP_CODE   CARRIER
            ,PHA.PO_HEADER_ID
FROM        PO_HEADERS_ALL          PHA
            ,HR_LOCATIONS           H1
            ,HR_LOCATIONS           H2
            ,PER_ALL_PEOPLE_F       PPF
            ,AP_SUPPLIERS           APS
            ,AP_SUPPLIER_SITES_ALL  APSS
            ,AP_SUPPLIER_CONTACTS   APSC
            ,AP_TERMS               APT
WHERE       PHA.SEGMENT1            =   '6042'
AND         PHA.BILL_TO_LOCATION_ID =   H1.LOCATION_ID
AND         PHA.SHIP_TO_LOCATION_ID =   H2.LOCATION_ID
AND         PHA.AGENT_ID            =   PPF.PERSON_ID
AND         PHA.VENDOR_ID           =   APS.VENDOR_ID
AND         PHA.VENDOR_SITE_ID      =   APSS.VENDOR_SITE_ID
AND         PHA.VENDOR_CONTACT_ID   =   APSC.VENDOR_CONTACT_ID
AND         PHA.TERMS_ID            =   APT.TERM_ID

Line level
SELECT      PLA.LINE_NUM    LINENO
            ,MSI.SEGMENT1   ITEM
            ,MSI.DESCRIPTION    DESCRIPTION
            ,PLA.QUANTITY
            ,PLA.UNIT_PRICE PRICE
            ,PLA.PO_LINE_ID
FROM        PO_LINES_ALL        PLA
            ,MTL_SYSTEM_ITEMS_B MSI
WHERE       PO_HEADER_ID        =     110371
AND         PLA.ITEM_ID         =     MSI.INVENTORY_ITEM_ID
AND         MSI.ORGANIZATION_ID =   204

Shipment level
SELECT      PLLA.SHIPMENT_NUM
            ,H1.LOCATION_CODE
            ,HRO.NAME
            ,PLLA.LINE_LOCATION_ID
FROM        PO_LINE_LOCATIONS_ALL   PLLA
            ,HR_LOCATIONS            H1
            ,HR_OPERATING_UNITS     HRO
WHERE       PLLA.PO_LINE_ID     IN   (173300,173301)
AND         PLLA.SHIP_TO_LOCATION_ID    =   H1.LOCATION_ID
AND         PLLA.ORG_ID                 =   HRO.ORGANIZATION_ID

Distributions level
SELECT      PDA.QUANTITY_ORDERED    QTY
            ,PDA.DISTRIBUTION_NUM   DNO
            ,PPF.FULL_NAME          REQUESTOR
FROM        PO_DISTRIBUTIONS_ALL    PDA
            ,PER_ALL_PEOPLE_F        PPF
WHERE       PDA.LINE_LOCATION_ID    IN (264474,264475,264476)
AND         PDA.DELIVER_TO_PERSON_ID = PPF.PERSON_ID

Also Read : Procure to Pay Cycle


*/