Search This Blog

Sunday, November 21, 2010

PO’S Which Does Not Have Any PR’S

SELECT
,prh.segment1 "PR NUM"
,trunc(prh.creation_date) "CREATED ON"
,trunc(prl.creation_date) "Line Creation Date"
,prl.line_num "Seq #"
,msi.segment1 "Item Num"
,prl.item_description "Description"
,prl.quantity "Qty"
,trunc(prl.need_by_date) "Required By"
,ppf1.full_name "REQUESTOR"
,ppf2.agent_name "BUYER"
FROM
,po.po_requisition_headers_all prh
,po.po_requisition_lines_all prl
,apps.per_people_f ppf1
,(select distinct agent_id,agent_name from apps.po_agents_v ) ppf2
,po.po_req_distributions_all prd
,inv.mtl_system_items_b msi
,po.po_line_locations_all pll
,po.po_lines_all pl
,po.po_headers_all ph
WHERE
prh.requisition_header_id = prl.requisition_header_id and
prl.requisition_line_id = prd.requisition_line_id and
ppf1.person_id = prh.preparer_id and
prh.creation_date between ppf1.effective_start_date and ppf1.effective_end_date and
ppf2.agent_id(+) = msi.buyer_id and
msi.inventory_item_id = prl.item_id and
msi.organization_id = prl.destination_organization_id and
pll.line_location_id(+) = prl.line_location_id and
pll.po_header_id = ph.po_header_id(+) and
pll.po_line_id = pl.po_line_id(+) and
prh.authorization_status = 'APPROVED' and
pll.line_location_id is NULL and
prl.closed_code is NULL and
nvl(prl.cancel_flag,'N') <> 'Y'
ORDER BY 1,2

Requisition moved from different stages till converting into PR

SELECT DISTINCT
,u.description "Requestor"
,porh.segment1 as "Req Number"
,trunc(porh.Creation_Date) "Created On"
,pord.LAST_UPDATED_BY
,porh.Authorization_Status "Status"
,porh.Description "Description"
,poh.segment1 "PO Number"
,trunc(poh.Creation_date) "PO Creation Date"
,poh.AUTHORIZATION_STATUS "PO Status"
,trunc(poh.Approved_Date) "Approved Date"
FROM
,apps.po_headers_all poh
,apps.po_distributions_all pod
,apps.po_req_distributions_all pord
,apps.po_requisition_lines_all porl
,apps.po_requisition_headers_all porh
,apps.fnd_user u
WHERE
porh.requisition_header_id = porl.requisition_header_id and porl.requisition_line_id = pord.requisition_line_id and
pord.distribution_id = pod.req_distribution_id(+) and
pod.po_header_id = poh.po_header_id(+) and
porh.created_by = u.user_id
order by 2

Purchase Requisition without a Purchase Order

SELECT
,prh.segment1 "PR NUM"
,trunc(prh.creation_date) "CREATED ON"
,trunc(prl.creation_date) "Line Creation Date"
,prl.line_num "Seq #"
,msi.segment1 "Item Num"
,prl.item_description "Description"
,prl.quantity "Qty"
,trunc(prl.need_by_date) "Required By"
,ppf1.full_name "REQUESTOR"
,ppf2.agent_name "BUYER"
FROM
,po.po_requisition_headers_all prh
,po.po_requisition_lines_all prl
,apps.per_people_f ppf1
,(select distinct agent_id,agent_name from apps.po_agents_v ) ppf2
,po.po_req_distributions_all prd
,inv.mtl_system_items_b msi
,po.po_line_locations_all pll
,po.po_lines_all pl
,po.po_headers_all ph
WHERE
prh.requisition_header_id = prl.requisition_header_id and
prl.requisition_line_id = prd.requisition_line_id and
ppf1.person_id = prh.preparer_id and
prh.creation_date between ppf1.effective_start_date and ppf1.effective_end_date and
ppf2.agent_id(+) = msi.buyer_id and
msi.inventory_item_id = prl.item_id and
msi.organization_id = prl.destination_organization_id and
pll.line_location_id(+) = prl.line_location_id and
pll.po_header_id = ph.po_header_id(+) and
pll.pl_line_id = pl.po_line_id(+) and
prh.authorization_status = 'APPROVED' and
pll.line_location_id is NULL and
prl.closed_code is NULL and
nvl(prl.cancel_flag,'N') <> 'Y'
ORDER BY 1,2

SELECT
prh.segment1 "PR NUM"
,prh.authorization_status
,trunc(prh.creation_date) "CREATED ON"
,trunc(prl.creation_date) "Line Creation Date"
,prl.line_num
,prl.item_description "Description"
,prl.quantity "Qty"
FROM
po.po_requisition_headers_all prh
,po.po_requisition_lines_all prl
,po.po_req_distributions_all prd
,po.po_line_locations_all pll
,po.po_lines_all pl
,po.po_headers_all ph
WHERE
prh.requisition_header_id = prl.requisition_header_id and
prl.requisition_line_id = prd.requisition_line_id and
pll.line_location_id(+) = prl.line_location_id and
pll.po_header_id = ph.po_header_id(+) and
pll.po_line_id = pl.po_line_id(+) and
prh.authorization_status in ('INCOMPLETE','IN PROCESS','REJECTED','RETURNED') and
pll.line_location_id is NULL and
prl.closed_code is NULL and
nvl(prl.cancel_flag,'N') <> 'Y'
ORDER BY 2,1,4

Relation between Requisition And PO

 SELECT
,r.segment1 "Req Num"
,p.segment1 "PO Num"
from
,po_headers_all p
,po_distributions_all d
,po_req_distributions_all rd
,po_requisition_lines_all rl
,po_requisition_headers_all r
WHERE
p.po_header_id = d.po_header_id and
d.req_distribution_id = rd.distribution_id and
rd.requisition_line_id = rl.requisition_line_id and
rl.requisition_header_id = r.requisition_header_id

Internal Requisitions That Do Not Have An Associated Internal Sales Order

SELECT
,RQH.SEGMENT1
,RQL.LINE_NUM
,RQL.REQUISITION_HEADER_ID
,RQL.REQUISITION_LINE_ID
,RQL.ITEM_ID
,RQL.UNIT_MEAS_LOOKUP_CODE
,RQL.UNIT_PRICE
,RQL.QUANTITY
,RQL.QUANTITY_CANCELLED
,RQL.QUANTITY_DELIVERED
,RQL.CANCEL_FLAG
,RQL.SOURCE_TYPE_CODE
,RQL.SOURCE_ORGANIZATION_ID
,RQL.DESTINATION_ORGANIZATION_ID
,RQH.TRANSFERRED_TO_OE_FLAG
FROM
,PO_REQUISITION_LINES_ALL RQL
,PO_REQUISITION_HEADERS_ALL RQH
WHERE
RQL.REQUISITION_HEADER_ID = RQH.REQUISITION_HEADER_ID and
RQL.SOURCE_TYPE_CODE = 'INVENTORY' and
RQL.SOURCE_ORGANIZATION_ID is not null and not exists
(select 'existing internal order'from OE_ORDER_LINES_ALL LIN where LIN.SOURCE_DOCUMENT_LINE_ID = RQL.REQUISITION_LINE_ID and LIN.SOURCE_DOCUMENT_TYPE_ID = 10)
ORDER BY RQH.REQUISITION_HEADER_ID, RQL.LINE_NUM

Cancelled Requisitions Query

SELECT
prh.REQUISITION_HEADER_ID
,prh.PREPARER_ID
,prh.SEGMENT1 "REQ NUM"
,trunc(prh.CREATION_DATE)
,prh.DESCRIPTION
,prh.NOTE_TO_AUTHORIZER
FROM
apps.Po_Requisition_headers_all prh
,apps.po_action_history pah
WHERE
action_code='CANCEL' and
pah.object_type_code='REQUISITION' and
pah.object_id=prh.REQUISITION_HEADER_ID

How to Find Remainder in Oracle

SELECT MOD(7,5) FROM DUAL;

Ans - 2