Tuesday 13 January 2015

Query to find out the customer, line item, ordered qty and price info of the order :

SELECT   h.order_number,
           org.name customer_name,
           h.ordered_date order_date,
           ot.name order_type,
           s.name sales_rep,
           l.line_id,
           l.line_number,
           l.inventory_item_id,
           si.segment1,
           l.ordered_quantity,
           l.unit_selling_price,
           NVL (l.ordered_quantity, 0) * NVL (l.unit_selling_price, 0) amount,
           h.transactional_curr_code currency_code
    FROM   ra_salesreps s,
           oe_transaction_types_tl ot,
           oe_sold_to_orgs_v org,
           mtl_system_items_vl si,
           oe_order_lines_all l,
           oe_order_headers_all h
   WHERE       h.order_number = 14463
           AND h.org_id = 204
           AND l.header_id = h.header_id
           AND h.sold_to_org_id = org.organization_id
           AND (h.cancelled_flag IS NULL OR h.cancelled_flag = 'N')
           AND h.open_flag = 'Y'
           AND l.open_flag = 'Y'
           AND l.service_reference_line_id IS NULL
           AND l.inventory_item_id = si.inventory_item_id
           AND NVL (si.organization_id, 0) = 204            --Item master orgn
           AND h.order_type_id = ot.transaction_type_id
           AND h.salesrep_id = s.salesrep_id
           AND h.org_id = s.org_id
ORDER BY   l.line_id
/

a: Oe_sold_to_orgs_v is a view based on hz_parties and hz_cust_accounts.

b: Ra_salesreps is a view based on JTF_RS_SALESREPS and JTF_RS_RESOURCE_EXTNS_VL.

You must set the org context for the views to function properly as..

BEGIN
   fnd_client_info.set_org_context ('204');
END;

No comments:

Post a Comment