SELECT POH.SEGMENT1 "Po Number"
, POH.TYPE_LOOKUP_CODE "Po Type"
, POH.AUTHORIZATION_STATUS "Po Status"
, POV.VENDOR_NAME "Supplier Name"
, POVS.VENDOR_SITE_CODE "Location"
, HRLS.LOCATION_CODE "Ship To"
, HRLB.LOCATION_CODE "Bill To"
, POL.LINE_NUM "Line Number"
, MSIB.SEGMENT1 "Item"
, POL.UNIT_PRICEm "Unit Price"
, POL.QUANTITY "Quantity"
, POD.AMOUNT_BILLED "Amount"
, POD.DESTINATION_SUBINVENTORY
, PPF.FULL_NAME "Buyer Name"
, POH.CLOSED_CODE
FROM PO_HEADERS_ALL POH
, PO_LINES_ALL POL
, MTL_SYSTEM_ITEMS_B MSIB
, PO_LINE_LOCATIONS_ALL POLL
, PO_DISTRIBUTIONS_ALL POD
, PO_VENDORS POV
, PO_VENDOR_SITES_ALL POVS
, HR_LOCATIONS_ALL HRLS
, HR_LOCATIONS_ALL HRLB
, PER_ALL_PEOPLE_F PPF
, PO_LINE_TYPES POLT
WHERE POLT.LINE_TYPE_ID = POL.LINE_TYPE_ID
AND POVS.VENDOR_SITE_ID = POH.VENDOR_SITE_ID
AND POV.VENDOR_ID = POH.VENDOR_ID
AND POL.ITEM_ID = MSIB.INVENTORY_ITEM_ID
AND MSIB.ORGANIZATION_ID = 204
AND POH.PO_HEADER_ID = POL.PO_HEADER_ID
AND POL.PO_LINE_ID = POD.PO_LINE_ID
AND POLL.LINE_LOCATION_ID = POD.LINE_LOCATION_ID
AND POH.SHIP_TO_LOCATION_ID = HRLS.LOCATION_ID
AND POH.BILL_TO_LOCATION_ID = HRLB.LOCATION_ID
AND POH.AGENT_ID = PPF.PERSON_ID
AND POH.SEGMENT1 = NVL (:PO_NUMBER, POH.SEGMENT1); -- Enter Purchase Order Number
, POH.TYPE_LOOKUP_CODE "Po Type"
, POH.AUTHORIZATION_STATUS "Po Status"
, POV.VENDOR_NAME "Supplier Name"
, POVS.VENDOR_SITE_CODE "Location"
, HRLS.LOCATION_CODE "Ship To"
, HRLB.LOCATION_CODE "Bill To"
, POL.LINE_NUM "Line Number"
, MSIB.SEGMENT1 "Item"
, POL.UNIT_PRICEm "Unit Price"
, POL.QUANTITY "Quantity"
, POD.AMOUNT_BILLED "Amount"
, POD.DESTINATION_SUBINVENTORY
, PPF.FULL_NAME "Buyer Name"
, POH.CLOSED_CODE
FROM PO_HEADERS_ALL POH
, PO_LINES_ALL POL
, MTL_SYSTEM_ITEMS_B MSIB
, PO_LINE_LOCATIONS_ALL POLL
, PO_DISTRIBUTIONS_ALL POD
, PO_VENDORS POV
, PO_VENDOR_SITES_ALL POVS
, HR_LOCATIONS_ALL HRLS
, HR_LOCATIONS_ALL HRLB
, PER_ALL_PEOPLE_F PPF
, PO_LINE_TYPES POLT
WHERE POLT.LINE_TYPE_ID = POL.LINE_TYPE_ID
AND POVS.VENDOR_SITE_ID = POH.VENDOR_SITE_ID
AND POV.VENDOR_ID = POH.VENDOR_ID
AND POL.ITEM_ID = MSIB.INVENTORY_ITEM_ID
AND MSIB.ORGANIZATION_ID = 204
AND POH.PO_HEADER_ID = POL.PO_HEADER_ID
AND POL.PO_LINE_ID = POD.PO_LINE_ID
AND POLL.LINE_LOCATION_ID = POD.LINE_LOCATION_ID
AND POH.SHIP_TO_LOCATION_ID = HRLS.LOCATION_ID
AND POH.BILL_TO_LOCATION_ID = HRLB.LOCATION_ID
AND POH.AGENT_ID = PPF.PERSON_ID
AND POH.SEGMENT1 = NVL (:PO_NUMBER, POH.SEGMENT1); -- Enter Purchase Order Number