Quando você achar que sua vida anda difícil...
Autor: Alceu Rodrigues de Freitas Junior | Publicado: 2015-12-09T16:17:00-02:00

Lembre-se da query abaixo. Sim, é uma única query e está em produção, mas eu não consigo imaginar que mente doentia pode criar algo assim.
Se achou pouco, eu ainda editei a query e tirei fora a maior parte dos comentários (o que incluía alguns statements também).

SELECT DISTINCT 'A' USE_TEMPLATE,
&nbsp; wpsv.pick_slip_number ,
&nbsp; (SELECT listagg(fdst.short_text, ', ') WITHIN GROUP (
&nbsp; ORDER BY fad.seq_num)
&nbsp; FROM fnd_attached_documents fad ,
&nbsp; &nbsp; fnd_documents_vl fd ,
&nbsp; &nbsp; FND_DOCUMENTS_SHORT_TEXT fdst,
&nbsp; &nbsp; fnd_document_categories_vl fdc--, Defect 4322
&nbsp; WHERE fad.document_id = fd.document_id
&nbsp; AND fdst.media_id &nbsp; &nbsp; = fd.media_id
&nbsp; AND SYSDATE BETWEEN NVL(fd.start_date_active, SYSDATE - 1) AND NVL(fd.end_date_active, SYSDATE + 1)
&nbsp; AND fad.entity_name &nbsp;= 'OE_ORDER_LINES'
&nbsp; AND fd.category_id &nbsp; = fdc.category_id(+)
&nbsp; AND fd.datatype_name = 'Short Text'
&nbsp; AND fdc.user_name &nbsp; &nbsp;='Printed Pick Slip'
&nbsp; AND fad.pk1_value &nbsp; &nbsp;= wdd.source_line_id
&nbsp; ) PICKING_INSTRUCTION,
&nbsp; (SELECT listagg(fdst.short_text, ', ') WITHIN GROUP (
&nbsp; ORDER BY fad.seq_num)
&nbsp; FROM fnd_attached_documents fad ,
&nbsp; &nbsp; fnd_documents_vl fd ,
&nbsp; &nbsp; fnd_documents_short_text fdst,
&nbsp; &nbsp; fnd_document_categories_vl fdc
&nbsp; WHERE fad.document_id = fd.document_id
&nbsp; AND fdst.media_id &nbsp; &nbsp; = fd.media_id
&nbsp; AND SYSDATE BETWEEN NVL(fd.start_date_active, SYSDATE - 1) AND NVL(fd.end_date_active, SYSDATE + 1)
&nbsp; AND fad.entity_name &nbsp;= 'OE_ORDER_HEADERS'
&nbsp; AND fd.category_id &nbsp; = fdc.category_id(+)
&nbsp; AND fd.datatype_name = 'Short Text'
&nbsp; AND fdc.user_name &nbsp; &nbsp;='Printed Pick Slip'
&nbsp; AND fad.pk1_value &nbsp; &nbsp;= ooha.header_id
&nbsp; ) HEADER_PICK_INSTR ,
&nbsp; ooha.attribute20 ir_delivery_note,
&nbsp; (SELECT fl.meaning shipping_method
&nbsp; FROM fnd_lookup_values fl
&nbsp; WHERE ooha.shipping_method_code = fl.lookup_code(+)
&nbsp; AND fl.language &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = userenv('LANG')
&nbsp; AND fl.lookup_type &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'SHIP_METHOD'
&nbsp; AND fl.enabled_flag &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'Y'
&nbsp; AND SYSDATE BETWEEN fl.start_date_active AND NVL (fl.end_date_active, SYSDATE + 1 )
&nbsp; ) freight_code ,
&nbsp; DECODE(msik.reservable_type,2,wdd.subinventory,wpsv.subinventory_code) from_subinventory,
&nbsp; DECODE(msik.reservable_type,2,wdd.locator_id,wpsv.from_locator_id) from_locator_id ,
&nbsp; wpsv.to_subinventory ,
&nbsp; wpsv.to_locator_id ,
&nbsp; NVL(wpsv.transaction_id ,-99) transaction_id ,
&nbsp; NVL(wdd.transaction_id, &nbsp;-99) rev_txn_id ,
&nbsp; wpsv.move_order_line_id ,
&nbsp; wpsv.detailing_date ,
&nbsp; 'PICKED' line_status ,
&nbsp; NVL(wdd.picked_quantity,wdd.requested_quantity) primary_qty ,
&nbsp; mtrh.request_number mo_number ,
&nbsp; (SELECT USER_NAME
&nbsp; FROM fnd_user
&nbsp; WHERE user_id = ooha.created_by
&nbsp; ) entered_by ,
&nbsp; wpsv.line_id mo_line_id ,
&nbsp; wpsv.line_number mo_line_number ,
&nbsp; wdd.delivery_detail_id delivery_detail_id1 ,
&nbsp; wdd.delivery_detail_id ser_dd_id ,
&nbsp; wdd.source_header_number ,
&nbsp; TO_CHAR(wdd.source_header_id) order_n_header_char,
&nbsp; TO_CHAR(wdd.source_line_id) order_n_line_char1 ,
&nbsp; wdd.source_header_id ,
&nbsp; wdd.source_line_id ,
&nbsp; TO_CHAR(wdd.source_header_id) source_header_chr ,
&nbsp; TO_CHAR(wdd.source_line_id) source_line_chr ,
&nbsp; wdd.shipping_instructions ,
&nbsp; wdd.ship_tolerance_above ,
&nbsp; wdd.ship_tolerance_below ,
&nbsp; wdd.inventory_item_id ,
&nbsp; wdd.inventory_item_id WDD_INV_ITEM ,
&nbsp; wdd.organization_id WDD_ORGANIZATION ,
&nbsp; wdd.requested_quantity_uom ,
&nbsp; NVL(
&nbsp; (SELECT listagg(xiab.trade_attribute13, ', ') WITHIN GROUP (
&nbsp; ORDER BY wdd.inventory_item_id)
&nbsp; FROM foobar_1 xiab
&nbsp; WHERE xiab.organization_id = wdd.organization_id
&nbsp; AND wdd.inventory_item_id &nbsp;= xiab.inventory_item_id
&nbsp; AND :P_ECCN_CTY_ORIGIN &nbsp; &nbsp; = 'Y'
&nbsp; ) ,
&nbsp; (SELECT listagg(xiab.trade_attribute13, ', ') WITHIN GROUP (
&nbsp; ORDER BY wdd.inventory_item_id)
&nbsp; FROM foobar_1 xiab
&nbsp; WHERE xiab.organization_id =
&nbsp; &nbsp; (SELECT organization_id FROM foobar_2 WHERE organization_code ='000'
&nbsp; &nbsp; )
&nbsp; AND wdd.inventory_item_id = xiab.inventory_item_id
&nbsp; AND :P_ECCN_CTY_ORIGIN &nbsp; &nbsp;= 'Y'
&nbsp; ) ) CF_ECCN,
&nbsp; NVL(
&nbsp; (SELECT listagg(xiab.trade_attribute14, ', ') WITHIN GROUP (
&nbsp; ORDER BY wdd.inventory_item_id)
&nbsp; FROM foobar_1 xiab
&nbsp; WHERE xiab.organization_id = wdd.organization_id
&nbsp; AND wdd.inventory_item_id &nbsp;= xiab.inventory_item_id
&nbsp; AND :P_ECCN_CTY_ORIGIN &nbsp; &nbsp; = 'Y'
&nbsp; ) ,
&nbsp; (SELECT listagg(xiab.trade_attribute14, ', ') WITHIN GROUP (
&nbsp; ORDER BY wdd.inventory_item_id)
&nbsp; FROM foobar_1 xiab
&nbsp; WHERE xiab.organization_id =
&nbsp; &nbsp; (SELECT organization_id FROM foobar_2 WHERE organization_code ='000'
&nbsp; &nbsp; )
&nbsp; AND wdd.inventory_item_id = xiab.inventory_item_id
&nbsp; AND :P_ECCN_CTY_ORIGIN &nbsp; &nbsp;= 'Y'
&nbsp; ) ) HTS,
&nbsp; NVL(
&nbsp; (SELECT listagg(xiab.trade_attribute18, ', ') WITHIN GROUP (
&nbsp; ORDER BY wdd.inventory_item_id)
&nbsp; FROM foobar_1 xiab
&nbsp; WHERE xiab.organization_id = wdd.organization_id
&nbsp; AND wdd.inventory_item_id &nbsp;= xiab.inventory_item_id
&nbsp; AND :P_ECCN_CTY_ORIGIN &nbsp; &nbsp; = 'Y'
&nbsp; ) ,
&nbsp; (SELECT listagg(xiab.trade_attribute18, ', ') WITHIN GROUP (
&nbsp; ORDER BY wdd.inventory_item_id)
&nbsp; FROM foobar_1 xiab
&nbsp; WHERE xiab.organization_id =
&nbsp; &nbsp; (SELECT organization_id FROM foobar_2 WHERE organization_code ='000'
&nbsp; &nbsp; )
&nbsp; AND wdd.inventory_item_id = xiab.inventory_item_id
&nbsp; AND :P_ECCN_CTY_ORIGIN &nbsp; &nbsp;= 'Y'
&nbsp; ) ) CF_CTY_ORIGIN,
&nbsp; wnd.delivery_id ,
&nbsp; TO_CHAR(wnd.delivery_id) delivery_chr ,
&nbsp; wnd.name delivery_name ,
&nbsp; wnd.initial_pickup_location_id ,
&nbsp; oola.ordered_quantity line_ordered_quantity ,
&nbsp; f_currency.symbol currency_symbol ,
&nbsp; oola.unit_selling_price ,
&nbsp; (oola.unit_selling_price * oola.ordered_quantity) line_extended_total,
&nbsp; oola.line_number sales_line_number ,
&nbsp; (SELECT DECODE(ship_loc.country,'US',xiab.attribute1, 'CA',xiab.attribute2, 'MX',xiab.attribute11, 'TT',xiab.attribute12, xiab.attribute1)
&nbsp; FROM foobar_1 xiab,
&nbsp; &nbsp; mtl_parameters mp
&nbsp; WHERE xiab.inventory_item_id = oola.inventory_item_id
&nbsp; AND xiab.organization_id &nbsp; &nbsp; = mp.master_organization_id
&nbsp; AND mp.organization_id &nbsp; &nbsp; &nbsp; = oola.ship_from_org_id
&nbsp; ) us_sds_num,
&nbsp; TO_CHAR(wdd.inventory_item_id) item_info ,
&nbsp; DECODE(:P_ITEM_DISPLAY,'F',NULL,msitl.description) item_desc ,
&nbsp; msik.revision_qty_control_code ,
&nbsp; DECODE(:P_ITEM_DISPLAY,'D',NULL,msik.segment1) segment1 ,
&nbsp; DECODE(wdd.released_status,'B', '(Backorder line)',NULL) BACKORDER,
&nbsp; os.set_name ,
&nbsp; wpgr.customer_flag CUSTOMER_FLAG1 ,
&nbsp; wpgr.order_number_flag ,
&nbsp; wpgr.subinventory_flag ,
&nbsp; wpgr.customer_flag ,
&nbsp; wpgr.ship_to_flag ,
&nbsp; wpgr.carrier_flag ,
&nbsp; wpgr.shipment_priority_flag ,
&nbsp; wpgr.trip_stop_flag ,
&nbsp; wpgr.delivery_flag ,
&nbsp; wpgr.name ,
&nbsp; wdd.ship_method_code carrier ,
&nbsp; wdd.shipment_priority_code priority ,
&nbsp; wdd.organization_id ,
&nbsp; wdd.requested_quantity2 secondary_qty_requested ,
&nbsp; wdd.requested_quantity_uom2 secondary_qty_requested_uom ,
&nbsp; wdd.shipped_quantity2 secondary_qty_shipped ,
&nbsp; wdd.requested_quantity_uom2 secondary_qty_shipped_uom ,
&nbsp; wdd.preferred_grade grade ,
&nbsp; wdd.freight_terms_code freight_terms ,
&nbsp; wdd.date_requested requested_ship_date ,
&nbsp; wdd.attribute1 wdd_attribute1 ,
&nbsp; wdd.attribute2 wdd_attribute2 ,
&nbsp; wdd.attribute3 wdd_attribute3 ,
&nbsp; wdd.attribute4 wdd_attribute4 ,
&nbsp; wdd.attribute5 wdd_attribute5 ,
&nbsp; wdd.attribute6 wdd_attribute6 ,
&nbsp; wdd.attribute7 wdd_attribute7 ,
&nbsp; wdd.attribute8 wdd_attribute8 ,
&nbsp; wdd.attribute9 wdd_attribute9 ,
&nbsp; wdd.attribute10 wdd_attribute10 ,
&nbsp; wdd.attribute11 wdd_attribute11 ,
&nbsp; wdd.attribute12 wdd_attribute12 ,
&nbsp; wdd.attribute13 wdd_attribute13 ,
&nbsp; wdd.attribute14 wdd_attribute14 ,
&nbsp; wdd.attribute15 wdd_attribute15 ,
&nbsp; wnd.attribute1 wnd_attribute1 ,
&nbsp; wnd.attribute2 wnd_attribute2 ,
&nbsp; wnd.attribute3 wnd_attribute3 ,
&nbsp; wnd.attribute4 wnd_attribute4 ,
&nbsp; wnd.attribute5 wnd_attribute5 ,
&nbsp; wnd.attribute6 wnd_attribute6 ,
&nbsp; wnd.attribute7 wnd_attribute7 ,
&nbsp; wnd.attribute8 wnd_attribute8 ,
&nbsp; wnd.attribute9 wnd_attribute9 ,
&nbsp; wnd.attribute10 wnd_attribute10 ,
&nbsp; wnd.attribute11 wnd_attribute11 ,
&nbsp; wnd.attribute12 wnd_attribute12 ,
&nbsp; wnd.attribute13 wnd_attribute13 ,
&nbsp; wnd.attribute14 wnd_attribute14 ,
&nbsp; wnd.attribute15 wnd_attribute15 ,
&nbsp; msik.concatenated_segments item_name ,
&nbsp; wdd.source_code source_code ,
&nbsp; ooha.cust_po_number cust_po_number ,
&nbsp; NVL( bill_acct_site.translated_customer_name,bill_party.party_name) bill_customer,
&nbsp; bill_su.location b_location ,
&nbsp; bill_loc.address1 b_address1 ,
&nbsp; bill_loc.address2 b_address2 ,
&nbsp; bill_loc.address3 b_address3 ,
&nbsp; bill_loc.city
&nbsp; || DECODE( bill_loc.city,NULL,NULL, DECODE(bill_loc.state,NULL,NULL,', '
&nbsp; || bill_loc.state))
&nbsp; || DECODE(bill_loc.province,NULL,NULL,', '
&nbsp; || bill_loc.province)
&nbsp; || ' '
&nbsp; || bill_loc.postal_code
&nbsp; || ', '
&nbsp; || bill_loc.country b_city_st_zip ,
&nbsp; bill_loc.country b_country ,
&nbsp; terr1.territory_short_name b_country_name ,
&nbsp; NVL( ship_acct_site.translated_customer_name,ship_party.party_name) ship_customer,
&nbsp; DECODE(ooha.deliver_to_org_id,NULL,ship_party.party_name,NULL) S_PARTY_NAME,
&nbsp; ship_su.location s_location ,
&nbsp; ship_loc.address1 s_address1 ,
&nbsp; ship_loc.address2 s_address2 ,
&nbsp; ship_loc.city
&nbsp; || DECODE( ship_loc.city,NULL,NULL, DECODE(ship_loc.state,NULL,NULL,', '
&nbsp; || ship_loc.state))
&nbsp; || DECODE(ship_loc.province,NULL,NULL,', '
&nbsp; || ship_loc.province)
&nbsp; || ' '
&nbsp; || ship_loc.postal_code
&nbsp; || ', '
&nbsp; || ship_loc.country s_city_st_zip,
&nbsp; foobar_3.cf_warehouseformula(wdd.organization_id) CF_warehouse,
&nbsp; (SELECT fl.meaning
&nbsp; FROM fnd_lookup_values fl
&nbsp; WHERE ooha.shipment_priority_code = fl.lookup_code(+)
&nbsp; AND fl.language &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = userenv('LANG')
&nbsp; AND fl.lookup_type &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'SHIPMENT_PRIORITY'
&nbsp; AND fl.enabled_flag &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'Y'
&nbsp; AND SYSDATE BETWEEN fl.start_date_active AND NVL (fl.end_date_active, SYSDATE + 1 )
&nbsp; ) CF_temp ,
&nbsp; foobar_3.cf_requisition_numberformula(wdd.source_header_id) CF_requisition_number ,
&nbsp; foobar_3.cf_ship_to_addressformula(wpgr.ship_to_flag, wpsv.pick_slip_number) CF_ship_to_address ,
&nbsp; foobar_3.cf_carrierformula(wpgr.carrier_flag, wdd.ship_method_code) CF_carrier ,
&nbsp; foobar_3.cf_shipment_priorityformula(wpgr.shipment_priority_flag, wdd.shipment_priority_code) CF_shipment_priority ,
&nbsp; foobar_3.cf_subinventoryformula(wpgr.subinventory_flag, DECODE ( msik.reservable_type , 2 , wdd.subinventory , wpsv.subinventory_code )) CF_subinventory,
&nbsp; foobar_3.cf_delivery_idformula(wpgr.delivery_flag, wnd.delivery_id) CF_delivery_id ,
&nbsp; wnd.delivery_id CF_delivery ,
&nbsp; DECODE(ooha.ATTRIBUTE7,'Y','DUPLICATE',NULL) CF_DUPLICATE ,
&nbsp; foobar_3.INSERT_GT_TBL(ooha.header_id,ooha.org_id,ooha.ATTRIBUTE7) CF_INSERT_GT_TBL ,
&nbsp; foobar_3.cf_trip_stop_address1formula(wpgr.trip_stop_flag, wpgr.delivery_flag, foobar_3.cf_delivery_idformula(wpgr.delivery_flag, wnd.delivery_id), wpsv.pick_slip_number) CF_trip_stop_address,
&nbsp; foobar_3.cf_order_numberformula(wpgr.order_number_flag, wdd.source_header_number) CF_order_number ,
&nbsp; lk1.meaning so_freight_terms ,
&nbsp; DECODE(ooha.deliver_to_org_id,NULL, NVL(ooha.packing_instructions, ship_party_site.addressee
&nbsp; ||
&nbsp; (SELECT ' &nbsp;Phone '
&nbsp; &nbsp; || (DECODE(phone_country_code,NULL,NULL,'+'
&nbsp; &nbsp; || phone_country_code
&nbsp; &nbsp; || ' ')
&nbsp; &nbsp; || DECODE(phone_area_code,NULL,NULL,'('
&nbsp; &nbsp; || phone_area_code
&nbsp; &nbsp; || ')')
&nbsp; &nbsp; || phone_number)
&nbsp; FROM hz_contact_points hcp
&nbsp; WHERE owner_table_name = 'HZ_PARTY_SITES'
&nbsp; AND primary_flag &nbsp; &nbsp; &nbsp; = 'Y'
&nbsp; AND owner_table_id &nbsp; &nbsp; = ship_party_site.party_site_id
&nbsp; AND contact_point_type = 'PHONE'
&nbsp; AND PHONE_LINE_TYPE &nbsp; &nbsp;= 'GEN'
&nbsp; AND status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'A'
&nbsp; ) ) , ooha.packing_instructions) packing_instructions,
&nbsp; /* &nbsp; (SELECT MIN (request_date)
&nbsp; FROM oe_order_lines_all l
&nbsp; WHERE l.org_id = ooha.org_id
&nbsp; AND l.header_id= ooha.header_id
&nbsp; )so_request_date, */
&nbsp; TRUNC(oola.schedule_ship_date) SSD ,
&nbsp; foobar_3.cf_customer_nameformula(wpgr.customer_flag, wdd.source_header_id) CF_customer_name ,
&nbsp; foobar_3.CP_warehouse_code_p CP_warehouse_code ,
&nbsp; foobar_3.CP_warehouse_name_p CP_warehouse_name ,
&nbsp; foobar_3.st_addr1_p st_addr1 ,
&nbsp; foobar_3.ts_addr3_p ts_addr3 ,
&nbsp; foobar_3.ts_addr4_p ts_addr4 ,
&nbsp; foobar_3.ts_addr5_p ts_addr5 ,
&nbsp; foobar_3.ts_addr1_p ts_addr1 ,
&nbsp; foobar_3.ts_addr2_p ts_addr2 ,
&nbsp; foobar_3.st_addr4_p st_addr4 ,
&nbsp; foobar_3.st_addr5_p st_addr5 ,
&nbsp; foobar_3.st_addr2_p st_addr2 ,
&nbsp; foobar_3.st_addr3_p st_addr3 ,
&nbsp; foobar_3.f_to_locationformula(wpsv.to_locator_id, wdd.organization_id) F_TO_LOCATION ,
&nbsp; foobar_3.cf_customerformula(wpgr.customer_flag, wdd.source_header_id) CF_customer ,
&nbsp; foobar_3.cf_trip_idformula(wnd.delivery_id, wnd.initial_pickup_location_id) CF_trip_id ,
&nbsp; foobar_3.f_item_descriptionformula(msitl.description, wdd.inventory_item_id, wdd.organization_id, msitl.description) F_ITEM_DESCRIPTION ,
&nbsp; foobar_3.f_requested_quantityformula(wdd.source_header_id, wdd.source_line_id, wpsv.move_order_line_id) F_REQUESTED_QUANTITY ,
&nbsp; foobar_3.f_shipped_quantityformula() F_SHIPPED_QUANTITY ,
&nbsp; foobar_3.cf_trip_chrformula(foobar_3.cf_trip_idformula(wnd.delivery_id, wnd.initial_pickup_location_id)) CF_TRIP_CHR ,
&nbsp; foobar_3.CP_trip_name_p CP_trip_name ,
&nbsp; foobar_3.f_from_locationformula(DECODE ( msik.reservable_type , 2 , wdd.locator_id , wpsv.from_locator_id ), wdd.organization_id) F_FROM_LOCATION,
&nbsp; foobar_3.cf_freight_terms_nameformula(wdd.freight_terms_code, wdd.source_code) CF_FREIGHT_TERMS_NAME ,
&nbsp; foobar_3.cf_revisionformula(NVL ( wpsv.transaction_id , - 99 )) CF_REVISION ,
&nbsp; foobar_3.B_task_idFt(wdd.organization_id) B_task_idFt
FROM
&nbsp; (SELECT mmt.subinventory_code subinventory_code ,
&nbsp; &nbsp; mmt.locator_id from_locator_id ,
&nbsp; &nbsp; mmt.transfer_subinventory to_subinventory,
&nbsp; &nbsp; mmt.transfer_locator_id to_locator_id ,
&nbsp; &nbsp; ABS(mmt.primary_quantity) primary_qty ,
&nbsp; &nbsp; mmt.pick_slip_number ,
&nbsp; &nbsp; mmt.transaction_date detailing_date ,
&nbsp; &nbsp; mmt.move_order_line_id ,
&nbsp; &nbsp; 'PICKED' line_status ,
&nbsp; &nbsp; mmt.transaction_id ,
&nbsp; &nbsp; mmt.transaction_uom ,
&nbsp; &nbsp; mmt.secondary_transaction_quantity ,
&nbsp; &nbsp; mmt.secondary_uom_code ,
&nbsp; &nbsp; mtrl.header_id ,
&nbsp; &nbsp; mtrl.line_id ,
&nbsp; &nbsp; mtrl.line_number
&nbsp; FROM mtl_material_transactions mmt,
&nbsp; &nbsp; mtl_txn_request_lines mtrl
&nbsp; WHERE mmt.pick_slip_number &nbsp; &nbsp; &nbsp; &nbsp; IS NOT NULL
&nbsp; AND NVL(mmt.transaction_quantity,0) &lt; 0
&nbsp; AND mmt.move_order_line_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= mtrl.line_id
&nbsp; AND mtrl.organization_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= :p_organization_id
&nbsp; AND 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =1
&nbsp; AND 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =1
&nbsp; ) wpsv ,
&nbsp; wsh_delivery_details wdd ,
&nbsp; wsh_carriers wc ,
&nbsp; mtl_txn_request_headers mtrh ,
&nbsp; wsh_delivery_assignments_v wda,
&nbsp; wsh_new_deliveries wnd ,
&nbsp; oe_order_lines_all oola ,
&nbsp; oe_lookups lk1 ,
&nbsp; oe_sets os ,
&nbsp; wsh_pick_grouping_rules wpgr ,
&nbsp; mtl_system_items_b_kfv msik ,
&nbsp; mtl_system_items_tl msitl ,
&nbsp; oe_order_headers_all ooha ,
&nbsp; fnd_currencies f_currency ,
&nbsp; hz_cust_site_uses_all bill_su ,
&nbsp; hz_cust_acct_sites_all bill_acct_site,
&nbsp; hz_party_sites bill_party_site ,
&nbsp; hz_locations bill_loc ,
&nbsp; hz_parties bill_party ,
&nbsp; hz_cust_accounts bill_cust_acct ,
&nbsp; fnd_territories_tl terr1 ,
&nbsp; hz_cust_site_uses_all ship_su ,
&nbsp; hz_cust_acct_sites_all ship_acct_site,
&nbsp; hz_party_sites ship_party_site ,
&nbsp; hz_locations ship_loc ,
&nbsp; hz_parties ship_party ,
&nbsp; hz_cust_accounts ship_cust_acct
WHERE msik.inventory_item_id &nbsp; &nbsp; = msitl.inventory_item_id
AND msik.organization_id &nbsp; &nbsp; &nbsp; &nbsp; = msitl.organization_id
AND msitl.LANGUAGE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = userenv('LANG')
AND wpsv.header_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = mtrh.header_id
AND wpsv.move_order_line_id &nbsp; &nbsp; &nbsp;= wdd.move_order_line_id(+)
AND wdd.carrier_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = wc.carrier_id(+)
AND NVL(wpsv.transaction_id,-99) = DECODE(NVL(wdd.transaction_id ,-99),-99,NVL(wpsv.transaction_id,-99),wdd.transaction_id)
AND wdd.inventory_item_id &nbsp; &nbsp; &nbsp; &nbsp;= msik.inventory_item_id(+)
AND wdd.organization_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= msik.organization_id(+)
AND NVL(TRUNC(oola.SCHEDULE_SHIP_DATE),TRUNC(SYSDATE)) BETWEEN NVL(:P_SCHEDULE_SHIP_DATE_LOW,NVL(TRUNC(oola.SCHEDULE_SHIP_DATE),TRUNC(SYSDATE))) AND NVL(:P_SCHEDULE_SHIP_DATE_HIGH,NVL(TRUNC(oola.SCHEDULE_SHIP_DATE),TRUNC(SYSDATE)))
AND wdd.delivery_detail_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= wda.delivery_detail_id
AND wda.delivery_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = wnd.delivery_id(+)
AND ( wnd.delivery_type &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IS NULL
OR wnd.delivery_type &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'STANDARD' )
AND wdd.source_line_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= oola.line_id
AND wdd.source_header_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= oola.header_id
AND wdd.source_code &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'OE'
AND wdd.container_flag &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IN ('N', 'Y')
AND wdd.ship_set_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = os.set_id(+)
AND mtrh.grouping_rule_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = wpgr.pick_grouping_rule_id(+)
AND ooha.transactional_curr_code &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= f_currency.currency_code(+)
AND ooha.header_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= wdd.source_header_id
AND ooha.invoice_to_org_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= bill_su.site_use_id(+)
AND bill_su.cust_acct_site_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = bill_acct_site.cust_acct_site_id(+)
AND bill_acct_site.party_site_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= bill_party_site.party_site_id(+)
AND bill_acct_site.cust_account_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= bill_cust_acct.cust_account_id(+)
AND bill_loc.location_id(+) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = bill_party_site.location_id
AND bill_cust_acct.party_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = bill_party.party_id
AND bill_loc.country &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= terr1.territory_code(+)
AND terr1.language &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= userenv('LANG')
AND NVL(oola.deliver_to_org_id,oola.ship_to_org_id) = ship_su.site_use_id(+)
AND ship_su.cust_acct_site_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = ship_acct_site.cust_acct_site_id(+)
AND ship_acct_site.party_site_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= ship_party_site.party_site_id(+)
AND ship_acct_site.cust_account_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= ship_cust_acct.cust_account_id(+)
AND ship_loc.location_id(+) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = NVL(wdd.deliver_to_location_id,wdd.ship_to_location_id)
AND ship_cust_acct.party_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = ship_party.party_id
AND lk1.lookup_code(+) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= ooha.freight_terms_code
AND lk1.lookup_type(+) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'FREIGHT_TERMS'
AND wdd.released_status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = :p_line_status
AND EXISTS (
&nbsp; ( SELECT 1 FROM dual WHERE 1 =1 AND 'All' = :p_print
&nbsp; )
UNION
&nbsp; (SELECT 1
&nbsp; FROM DUAL
&nbsp; WHERE 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 1
&nbsp; AND 'Original' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= :p_print
&nbsp; AND NVL(OOHA.ATTRIBUTE7,'N') != 'Y'
&nbsp; )
UNION
&nbsp; (SELECT 1
&nbsp; FROM DUAL
&nbsp; WHERE 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 1
&nbsp; AND 'Duplicate' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= :p_print
&nbsp; AND NVL(OOHA.ATTRIBUTE7,'N') = 'Y'
&nbsp; ) )
AND 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 1
AND ooha.order_number &nbsp;= to_number(:p_order_num_low)
AND ooha.ORDER_TYPE_ID = to_number(:p_order_type_id)
AND 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=1
AND 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=1
UNION
SELECT DISTINCT 'B' USE_TEMPLATE ,
&nbsp; 100000000000000000000 pick_slip_number,
&nbsp; (SELECT listagg(fdst.short_text, ', ') WITHIN GROUP (
&nbsp; ORDER BY fad.seq_num)
&nbsp; FROM fnd_attached_documents fad ,
&nbsp; &nbsp; fnd_documents_vl fd ,
&nbsp; &nbsp; FND_DOCUMENTS_SHORT_TEXT fdst,
&nbsp; &nbsp; fnd_document_categories_vl fdc--, Defect 4322
&nbsp; WHERE fad.document_id = fd.document_id
&nbsp; AND fdst.media_id &nbsp; &nbsp; = fd.media_id
&nbsp; AND SYSDATE BETWEEN NVL(fd.start_date_active, SYSDATE - 1) AND NVL(fd.end_date_active, SYSDATE + 1)
&nbsp; AND fad.entity_name &nbsp;= 'OE_ORDER_LINES'
&nbsp; AND fd.category_id &nbsp; = fdc.category_id(+)
&nbsp; AND fd.datatype_name = 'Short Text'
&nbsp; AND fdc.user_name &nbsp; &nbsp;='Printed Pick Slip'
&nbsp; AND fad.pk1_value &nbsp; &nbsp;= wdd.source_line_id
&nbsp; ) PICKING_INSTRUCTION,
&nbsp; (SELECT listagg(fdst.short_text, ', ') WITHIN GROUP (
&nbsp; ORDER BY fad.seq_num)
&nbsp; FROM fnd_attached_documents fad ,
&nbsp; &nbsp; fnd_documents_vl fd ,
&nbsp; &nbsp; fnd_documents_short_text fdst,
&nbsp; &nbsp; fnd_document_categories_vl fdc
&nbsp; WHERE fad.document_id = fd.document_id
&nbsp; AND fdst.media_id &nbsp; &nbsp; = fd.media_id
&nbsp; AND SYSDATE BETWEEN NVL(fd.start_date_active, SYSDATE - 1) AND NVL(fd.end_date_active, SYSDATE + 1)
&nbsp; AND fad.entity_name &nbsp;= 'OE_ORDER_HEADERS'
&nbsp; AND fd.category_id &nbsp; = fdc.category_id(+)
&nbsp; AND fd.datatype_name = 'Short Text'
&nbsp; AND fdc.user_name &nbsp; &nbsp;='Printed Pick Slip'
&nbsp; AND fad.pk1_value &nbsp; &nbsp;= ooha.header_id
&nbsp; ) HEADER_PICK_INSTR ,
&nbsp; ooha.attribute20 ir_delivery_note,
&nbsp; (SELECT fl.meaning shipping_method
&nbsp; FROM fnd_lookup_values fl
&nbsp; WHERE ooha.shipping_method_code = fl.lookup_code(+)
&nbsp; AND fl.language &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = userenv('LANG')
&nbsp; AND fl.lookup_type &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'SHIP_METHOD'
&nbsp; AND fl.enabled_flag &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'Y'
&nbsp; AND SYSDATE BETWEEN fl.start_date_active AND NVL (fl.end_date_active, SYSDATE + 1 )
&nbsp; ) freight_code ,
&nbsp; NULL from_subinventory ,
&nbsp; NULL from_locator_id ,
&nbsp; NULL to_subinventory ,
&nbsp; NULL to_locator_id ,
&nbsp; NULL transaction_id ,
&nbsp; NULL rev_txn_id ,
&nbsp; NULL move_order_line_id ,
&nbsp; NULL detailing_date ,
&nbsp; 'PICKED' line_status ,
&nbsp; NVL(wdd.picked_quantity,wdd.requested_quantity) primary_qty,
&nbsp; (SELECT mtrh.request_number
&nbsp; FROM mtl_txn_request_headers mtrh,
&nbsp; &nbsp; mtl_txn_request_lines mtrl
&nbsp; WHERE mtrh.header_id = mtrl.header_id
&nbsp; AND mtrl.line_id &nbsp; &nbsp; = wdd.move_order_line_id
&nbsp; ) mo_number,
&nbsp; ( SELECT USER_NAME FROM fnd_user WHERE user_id = ooha.created_by
&nbsp; ) entered_by ,
&nbsp; NULL mo_line_id,
&nbsp; (SELECT mtrl.line_number
&nbsp; FROM mtl_txn_request_lines mtrl
&nbsp; WHERE mtrl.line_id = wdd.move_order_line_id
&nbsp; ) mo_line_number ,
&nbsp; wdd.delivery_detail_id delivery_detail_id1 ,
&nbsp; wdd.delivery_detail_id ser_dd_id ,
&nbsp; wdd.source_header_number ,
&nbsp; TO_CHAR(wdd.source_header_id) order_n_header_char,
&nbsp; TO_CHAR(wdd.source_line_id) order_n_line_char1 ,
&nbsp; wdd.source_header_id ,
&nbsp; wdd.source_line_id ,
&nbsp; TO_CHAR(wdd.source_header_id) source_header_chr ,
&nbsp; TO_CHAR(wdd.source_line_id) source_line_chr ,
&nbsp; wdd.shipping_instructions ,
&nbsp; wdd.ship_tolerance_above ,
&nbsp; wdd.ship_tolerance_below ,
&nbsp; wdd.inventory_item_id ,
&nbsp; wdd.inventory_item_id WDD_INV_ITEM ,
&nbsp; wdd.organization_id WDD_ORGANIZATION ,
&nbsp; wdd.requested_quantity_uom ,
&nbsp; NVL(
&nbsp; (SELECT listagg(xiab.trade_attribute13, ', ') WITHIN GROUP (
&nbsp; ORDER BY wdd.inventory_item_id)
&nbsp; FROM foobar_1 xiab
&nbsp; WHERE xiab.organization_id = wdd.organization_id
&nbsp; AND wdd.inventory_item_id &nbsp;= xiab.inventory_item_id
&nbsp; AND :P_ECCN_CTY_ORIGIN &nbsp; &nbsp; = 'Y'
&nbsp; ) ,
&nbsp; (SELECT listagg(xiab.trade_attribute13, ', ') WITHIN GROUP (
&nbsp; ORDER BY wdd.inventory_item_id)
&nbsp; FROM foobar_1 xiab
&nbsp; WHERE xiab.organization_id =
&nbsp; &nbsp; (SELECT organization_id FROM foobar_2 WHERE organization_code ='000'
&nbsp; &nbsp; )
&nbsp; AND wdd.inventory_item_id = xiab.inventory_item_id
&nbsp; AND :P_ECCN_CTY_ORIGIN &nbsp; &nbsp;= 'Y'
&nbsp; ) ) CF_ECCN,
&nbsp; NVL(
&nbsp; (SELECT listagg(xiab.trade_attribute14, ', ') WITHIN GROUP (
&nbsp; ORDER BY wdd.inventory_item_id)
&nbsp; FROM foobar_1 xiab
&nbsp; WHERE xiab.organization_id = wdd.organization_id
&nbsp; AND wdd.inventory_item_id &nbsp;= xiab.inventory_item_id
&nbsp; AND :P_ECCN_CTY_ORIGIN &nbsp; &nbsp; = 'Y'
&nbsp; ) ,
&nbsp; (SELECT listagg(xiab.trade_attribute14, ', ') WITHIN GROUP (
&nbsp; ORDER BY wdd.inventory_item_id)
&nbsp; FROM foobar_1 xiab
&nbsp; WHERE xiab.organization_id =
&nbsp; &nbsp; (SELECT organization_id FROM foobar_2 WHERE organization_code ='000'
&nbsp; &nbsp; )
&nbsp; AND wdd.inventory_item_id = xiab.inventory_item_id
&nbsp; AND :P_ECCN_CTY_ORIGIN &nbsp; &nbsp;= 'Y'
&nbsp; ) ) HTS,
&nbsp; NVL(
&nbsp; (SELECT listagg(xiab.trade_attribute18, ', ') WITHIN GROUP (
&nbsp; ORDER BY wdd.inventory_item_id)
&nbsp; FROM foobar_1 xiab
&nbsp; WHERE xiab.organization_id = wdd.organization_id
&nbsp; AND wdd.inventory_item_id &nbsp;= xiab.inventory_item_id
&nbsp; AND :P_ECCN_CTY_ORIGIN &nbsp; &nbsp; = 'Y'
&nbsp; ) ,
&nbsp; (SELECT listagg(xiab.trade_attribute18, ', ') WITHIN GROUP (
&nbsp; ORDER BY wdd.inventory_item_id)
&nbsp; FROM foobar_1 xiab
&nbsp; WHERE xiab.organization_id =
&nbsp; &nbsp; (SELECT organization_id FROM foobar_2 WHERE organization_code ='000'
&nbsp; &nbsp; )
&nbsp; AND wdd.inventory_item_id = xiab.inventory_item_id
&nbsp; AND :P_ECCN_CTY_ORIGIN &nbsp; &nbsp;= 'Y'
&nbsp; ) ) CF_CTY_ORIGIN,
&nbsp; wnd.delivery_id ,
&nbsp; TO_CHAR(wnd.delivery_id) delivery_chr ,
&nbsp; wnd.name delivery_name ,
&nbsp; wnd.initial_pickup_location_id ,
&nbsp; oola.ordered_quantity line_ordered_quantity ,
&nbsp; f_currency.symbol currency_symbol ,
&nbsp; oola.unit_selling_price ,
&nbsp; (oola.unit_selling_price * oola.ordered_quantity) line_extended_total,
&nbsp; oola.line_number sales_line_number ,
&nbsp; (SELECT DECODE(ship_loc.country,'US',xiab.attribute1, 'CA',xiab.attribute2, 'MX',xiab.attribute11, 'TT',xiab.attribute12, xiab.attribute1)
&nbsp; FROM foobar_1 xiab,
&nbsp; &nbsp; mtl_parameters mp
&nbsp; WHERE xiab.inventory_item_id = oola.inventory_item_id
&nbsp; AND xiab.organization_id &nbsp; &nbsp; = mp.master_organization_id
&nbsp; AND mp.organization_id &nbsp; &nbsp; &nbsp; = oola.ship_from_org_id
&nbsp; ) us_sds_num,
&nbsp; TO_CHAR(wdd.inventory_item_id) item_info ,
&nbsp; DECODE(:P_ITEM_DISPLAY,'F',NULL,msitl.description) item_desc ,
&nbsp; msik.revision_qty_control_code ,
&nbsp; DECODE(:P_ITEM_DISPLAY,'D',NULL,msik.segment1) segment1 ,
&nbsp; DECODE(wdd.released_status,'B', '(Backorder line)',NULL) BACKORDER,
&nbsp; os.set_name ,
&nbsp; NULL CUSTOMER_FLAG1 ,
&nbsp; NULL order_number_flag ,
&nbsp; NULL subinventory_flag ,
&nbsp; NULL customer_flag ,
&nbsp; NULL ship_to_flag ,
&nbsp; NULL carrier_flag ,
&nbsp; NULL shipment_priority_flag ,
&nbsp; NULL trip_stop_flag ,
&nbsp; NULL delivery_flag ,
&nbsp; (SELECT wpgr.NAME
&nbsp; FROM mtl_txn_request_headers mtrh,
&nbsp; &nbsp; mtl_txn_request_lines mtrl ,
&nbsp; &nbsp; wsh_pick_grouping_rules wpgr
&nbsp; WHERE mtrh.header_id &nbsp; &nbsp; &nbsp;= mtrl.header_id
&nbsp; AND mtrl.line_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= wdd.move_order_line_id
&nbsp; AND mtrh.grouping_rule_id = wpgr.pick_grouping_rule_id(+)
&nbsp; ) name ,
&nbsp; wdd.ship_method_code carrier ,
&nbsp; wdd.shipment_priority_code priority ,
&nbsp; wdd.organization_id ,
&nbsp; wdd.requested_quantity2 secondary_qty_requested ,
&nbsp; wdd.requested_quantity_uom2 secondary_qty_requested_uom,
&nbsp; wdd.shipped_quantity2 secondary_qty_shipped ,
&nbsp; wdd.requested_quantity_uom2 secondary_qty_shipped_uom ,
&nbsp; wdd.preferred_grade grade ,
&nbsp; wdd.freight_terms_code freight_terms ,
&nbsp; wdd.date_requested requested_ship_date ,
&nbsp; wdd.attribute1 wdd_attribute1 ,
&nbsp; wdd.attribute2 wdd_attribute2 ,
&nbsp; wdd.attribute3 wdd_attribute3 ,
&nbsp; wdd.attribute4 wdd_attribute4 ,
&nbsp; wdd.attribute5 wdd_attribute5 ,
&nbsp; wdd.attribute6 wdd_attribute6 ,
&nbsp; wdd.attribute7 wdd_attribute7 ,
&nbsp; wdd.attribute8 wdd_attribute8 ,
&nbsp; wdd.attribute9 wdd_attribute9 ,
&nbsp; wdd.attribute10 wdd_attribute10 ,
&nbsp; wdd.attribute11 wdd_attribute11 ,
&nbsp; wdd.attribute12 wdd_attribute12 ,
&nbsp; wdd.attribute13 wdd_attribute13 ,
&nbsp; wdd.attribute14 wdd_attribute14 ,
&nbsp; wdd.attribute15 wdd_attribute15 ,
&nbsp; wnd.attribute1 wnd_attribute1 ,
&nbsp; wnd.attribute2 wnd_attribute2 ,
&nbsp; wnd.attribute3 wnd_attribute3 ,
&nbsp; wnd.attribute4 wnd_attribute4 ,
&nbsp; wnd.attribute5 wnd_attribute5 ,
&nbsp; wnd.attribute6 wnd_attribute6 ,
&nbsp; wnd.attribute7 wnd_attribute7 ,
&nbsp; wnd.attribute8 wnd_attribute8 ,
&nbsp; wnd.attribute9 wnd_attribute9 ,
&nbsp; wnd.attribute10 wnd_attribute10 ,
&nbsp; wnd.attribute11 wnd_attribute11 ,
&nbsp; wnd.attribute12 wnd_attribute12 ,
&nbsp; wnd.attribute13 wnd_attribute13 ,
&nbsp; wnd.attribute14 wnd_attribute14 ,
&nbsp; wnd.attribute15 wnd_attribute15 ,
&nbsp; msik.concatenated_segments item_name ,
&nbsp; wdd.source_code source_code ,
&nbsp; ooha.cust_po_number cust_po_number ,
&nbsp; NVL( bill_acct_site.translated_customer_name,bill_party.party_name) bill_customer,
&nbsp; bill_su.location b_location ,
&nbsp; bill_loc.address1 b_address1 ,
&nbsp; bill_loc.address2 b_address2 ,
&nbsp; bill_loc.address3 b_address3 ,
&nbsp; bill_loc.city
&nbsp; || DECODE( bill_loc.city,NULL,NULL, DECODE(bill_loc.state,NULL,NULL,', '
&nbsp; || bill_loc.state))
&nbsp; || DECODE(bill_loc.province,NULL,NULL,', '
&nbsp; || bill_loc.province)
&nbsp; || ' '
&nbsp; || bill_loc.postal_code
&nbsp; || ', '
&nbsp; || bill_loc.country b_city_st_zip ,
&nbsp; bill_loc.country b_country ,
&nbsp; terr1.territory_short_name b_country_name ,
&nbsp; NVL( ship_acct_site.translated_customer_name,ship_party.party_name) ship_customer,
&nbsp; DECODE(ooha.deliver_to_org_id,NULL,ship_party.party_name,NULL) S_PARTY_NAME,
&nbsp; ship_su.location s_location ,
&nbsp; ship_loc.address1 s_address1 ,
&nbsp; ship_loc.address2 s_address2 ,
&nbsp; ship_loc.city
&nbsp; || DECODE( ship_loc.city,NULL,NULL, DECODE(ship_loc.state,NULL,NULL,', '
&nbsp; || ship_loc.state))
&nbsp; || DECODE(ship_loc.province,NULL,NULL,', '
&nbsp; || ship_loc.province)
&nbsp; || ' '
&nbsp; || ship_loc.postal_code
&nbsp; || ', '
&nbsp; || ship_loc.country s_city_st_zip,
&nbsp; foobar_3.cf_warehouseformula(wdd.organization_id) CF_warehouse,
&nbsp; (SELECT fl.meaning
&nbsp; FROM fnd_lookup_values fl
&nbsp; WHERE ooha.shipment_priority_code = fl.lookup_code(+)
&nbsp; AND fl.language &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = userenv('LANG')
&nbsp; AND fl.lookup_type &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'SHIPMENT_PRIORITY'
&nbsp; AND fl.enabled_flag &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'Y'
&nbsp; AND SYSDATE BETWEEN fl.start_date_active AND NVL (fl.end_date_active, SYSDATE + 1 )
&nbsp; ) CF_temp ,
&nbsp; foobar_3.cf_requisition_numberformula(wdd.source_header_id) CF_requisition_number,
&nbsp; NULL CF_ship_to_address ,
&nbsp; NULL CF_carrier ,
&nbsp; NULL CF_shipment_priority ,
&nbsp; NULL CF_subinventory ,
&nbsp; NULL CF_delivery_id ,
&nbsp; wnd.delivery_id CF_delivery ,
&nbsp; DECODE(ooha.ATTRIBUTE7,'Y','DUPLICATE',NULL) CF_DUPLICATE ,
&nbsp; foobar_3.INSERT_GT_TBL(ooha.header_id,ooha.org_id,ooha.ATTRIBUTE7) CF_INSERT_GT_TBL,
&nbsp; NULL CF_trip_stop_address ,
&nbsp; ooha.order_number CF_order_number,
&nbsp; lk1.meaning so_freight_terms ,
&nbsp; DECODE(ooha.deliver_to_org_id,NULL, NVL(ooha.packing_instructions, ship_party_site.addressee
&nbsp; ||
&nbsp; (SELECT ' &nbsp;Phone '
&nbsp; &nbsp; || (DECODE(phone_country_code,NULL,NULL,'+'
&nbsp; &nbsp; || phone_country_code
&nbsp; &nbsp; || ' ')
&nbsp; &nbsp; || DECODE(phone_area_code,NULL,NULL,'('
&nbsp; &nbsp; || phone_area_code
&nbsp; &nbsp; || ')')
&nbsp; &nbsp; || phone_number)
&nbsp; FROM hz_contact_points hcp
&nbsp; WHERE owner_table_name = 'HZ_PARTY_SITES'
&nbsp; AND primary_flag &nbsp; &nbsp; &nbsp; = 'Y'
&nbsp; AND owner_table_id &nbsp; &nbsp; = ship_party_site.party_site_id
&nbsp; AND contact_point_type = 'PHONE'
&nbsp; AND PHONE_LINE_TYPE &nbsp; &nbsp;= 'GEN'
&nbsp; AND status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'A'
&nbsp; ) ) , ooha.packing_instructions) packing_instructions,
&nbsp; /* &nbsp; (SELECT MIN (request_date)
&nbsp; FROM oe_order_lines_all l
&nbsp; WHERE l.org_id = ooha.org_id
&nbsp; AND l.header_id= ooha.header_id
&nbsp; )so_request_date, */
&nbsp; TRUNC(oola.schedule_ship_date) SSD ,
&nbsp; NULL CF_customer_name ,
&nbsp; foobar_3.CP_warehouse_code_p CP_warehouse_code ,
&nbsp; foobar_3.CP_warehouse_name_p CP_warehouse_name ,
&nbsp; foobar_3.st_addr1_p st_addr1 ,
&nbsp; foobar_3.ts_addr3_p ts_addr3 ,
&nbsp; foobar_3.ts_addr4_p ts_addr4 ,
&nbsp; foobar_3.ts_addr5_p ts_addr5 ,
&nbsp; foobar_3.ts_addr1_p ts_addr1 ,
&nbsp; foobar_3.ts_addr2_p ts_addr2 ,
&nbsp; foobar_3.st_addr4_p st_addr4 ,
&nbsp; foobar_3.st_addr5_p st_addr5 ,
&nbsp; foobar_3.st_addr2_p st_addr2 ,
&nbsp; foobar_3.st_addr3_p st_addr3 ,
&nbsp; NULL F_TO_LOCATION ,
&nbsp; NULL CF_customer ,
&nbsp; foobar_3.cf_trip_idformula(wnd.delivery_id, wnd.initial_pickup_location_id) CF_trip_id ,
&nbsp; foobar_3.f_item_descriptionformula(msitl.description, wdd.inventory_item_id, wdd.organization_id, msitl.description) F_ITEM_DESCRIPTION,
&nbsp; NULL F_REQUESTED_QUANTITY ,
&nbsp; foobar_3.f_shipped_quantityformula() F_SHIPPED_QUANTITY ,
&nbsp; foobar_3.cf_trip_chrformula(foobar_3.cf_trip_idformula(wnd.delivery_id, wnd.initial_pickup_location_id)) CF_TRIP_CHR ,
&nbsp; foobar_3.CP_trip_name_p CP_trip_name ,
&nbsp; NULL F_FROM_LOCATION ,
&nbsp; foobar_3.cf_freight_terms_nameformula(wdd.freight_terms_code, wdd.source_code) CF_FREIGHT_TERMS_NAME ,
&nbsp; NULL CF_REVISION ,
&nbsp; foobar_3.B_task_idFt(wdd.organization_id) B_task_idFt
FROM
&nbsp; /* &nbsp; &nbsp; &nbsp; &nbsp;(
&nbsp; SELECT mmt.subinventory_code subinventory_code,
&nbsp; mmt.locator_id from_locator_id,
&nbsp; mmt.transfer_subinventory to_subinventory,
&nbsp; mmt.transfer_locator_id to_locator_id,
&nbsp; abs(mmt.primary_quantity) primary_qty,
&nbsp; mmt.pick_slip_number,
&nbsp; mmt.transaction_date detailing_date,
&nbsp; mmt.move_order_line_id,
&nbsp; 'PICKED' line_status,
&nbsp; mmt.transaction_id,
&nbsp; mmt.transaction_uom,
&nbsp; mmt.secondary_transaction_quantity,
&nbsp; mmt.secondary_uom_code ,
&nbsp; mtrl.header_id,
&nbsp; mtrl.line_id,
&nbsp; mtrl.line_number
&nbsp; FROM mtl_material_transactions mmt,
&nbsp; mtl_txn_request_lines mtrl
&nbsp; WHERE &nbsp;mmt.pick_slip_number IS NOT NULL
&nbsp; AND nvl(mmt.transaction_quantity,0) &lt; 0
&nbsp; AND mmt.move_order_line_id = mtrl.line_id
&nbsp; AND mtrl.organization_id = :p_organization_id
&nbsp; AND 1=1
&nbsp; and 1=1
&nbsp; ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wpsv, */
&nbsp; wsh_delivery_details wdd,
&nbsp; wsh_carriers wc ,
&nbsp; wsh_delivery_assignments_v wda,
&nbsp; wsh_new_deliveries wnd ,
&nbsp; oe_order_lines_all oola ,
&nbsp; oe_lookups lk1 ,
&nbsp; oe_sets os ,
&nbsp; mtl_system_items_b_kfv msik,
&nbsp; mtl_system_items_tl msitl ,
&nbsp; oe_order_headers_all ooha ,
&nbsp; fnd_currencies f_currency ,
&nbsp; hz_cust_site_uses_all bill_su ,
&nbsp; hz_cust_acct_sites_all bill_acct_site,
&nbsp; hz_party_sites bill_party_site ,
&nbsp; hz_locations bill_loc ,
&nbsp; hz_parties bill_party ,
&nbsp; hz_cust_accounts bill_cust_acct ,
&nbsp; fnd_territories_tl terr1 ,
&nbsp; hz_cust_site_uses_all ship_su ,
&nbsp; hz_cust_acct_sites_all ship_acct_site,
&nbsp; hz_party_sites ship_party_site ,
&nbsp; hz_locations ship_loc ,
&nbsp; hz_parties ship_party ,
&nbsp; hz_cust_accounts ship_cust_acct
WHERE msik.inventory_item_id = msitl.inventory_item_id
AND msik.organization_id &nbsp; &nbsp; = msitl.organization_id
AND msitl.LANGUAGE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = userenv('LANG')
AND wdd.carrier_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = wc.carrier_id(+)
AND wdd.organization_id &nbsp; &nbsp; &nbsp;= :p_organization_id
AND wdd.inventory_item_id &nbsp; &nbsp;= msik.inventory_item_id(+)
AND wdd.organization_id &nbsp; &nbsp; &nbsp;= msik.organization_id(+)
AND NVL(TRUNC(oola.SCHEDULE_SHIP_DATE),TRUNC(SYSDATE)) BETWEEN NVL(:P_SCHEDULE_SHIP_DATE_LOW,NVL(TRUNC(oola.SCHEDULE_SHIP_DATE),TRUNC(SYSDATE))) AND NVL(:P_SCHEDULE_SHIP_DATE_HIGH,NVL(TRUNC(oola.SCHEDULE_SHIP_DATE),TRUNC(SYSDATE)))
AND wdd.delivery_detail_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= wda.delivery_detail_id
AND wda.delivery_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = wnd.delivery_id(+)
AND ( wnd.delivery_type &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IS NULL
OR wnd.delivery_type &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'STANDARD' )
AND wdd.source_line_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= oola.line_id
AND wdd.source_header_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= oola.header_id
AND wdd.source_code &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 'OE'
AND wdd.container_flag &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IN ('N', 'Y')
AND wdd.ship_set_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = os.set_id(+)
AND ooha.transactional_curr_code &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= f_currency.currency_code(+)
AND ooha.header_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= wdd.source_header_id
AND ooha.invoice_to_org_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= bill_su.site_use_id(+)
AND bill_su.cust_acct_site_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = bill_acct_site.cust_acct_site_id(+)
AND bill_acct_site.party_site_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= bill_party_site.party_site_id(+)
AND bill_acct_site.cust_account_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= bill_cust_acct.cust_account_id(+)
AND bill_loc.location_id(+) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = bill_party_site.location_id
AND bill_cust_acct.party_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = bill_party.party_id
AND bill_loc.country &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= terr1.territory_code(+)
AND terr1.language &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= userenv('LANG')
AND NVL(ooha.deliver_to_org_id,ooha.ship_to_org_id) = ship_su.site_use_id(+)
AND ship_su.cust_acct_site_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = ship_acct_site.cust_acct_site_id(+)
AND ship_acct_site.party_site_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= ship_party_site.party_site_id(+)
AND ship_acct_site.cust_account_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= ship_cust_acct.cust_account_id(+)
AND ship_loc.location_id(+) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = ship_party_site.location_id
AND ship_cust_acct.party_id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = ship_party.party_id
AND lk1.lookup_code(+) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= ooha.freight_terms_code
AND lk1.lookup_type(+) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 'FREIGHT_TERMS'
AND wdd.released_status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = :p_line_status
AND :P_PICK_SLIP_NUM_LOW &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IS NULL
AND :P_PICK_SLIP_NUM_HIGH &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IS NULL
AND DECODE (:P_MOVE_ORDER_HIGH,NULL,'1',
&nbsp; (SELECT TO_CHAR(mtrh.request_number)
&nbsp; FROM mtl_txn_request_headers mtrh,
&nbsp; &nbsp; mtl_txn_request_lines mtrl
&nbsp; WHERE mtrh.header_id = mtrl.header_id
&nbsp; AND mtrl.line_id &nbsp; &nbsp; = wdd.move_order_line_id
&nbsp; ) ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= NVL(TO_CHAR(:P_MOVE_ORDER_HIGH),'1')
AND EXISTS (
&nbsp; ( SELECT 1 FROM dual WHERE 1 =1 AND 'All' = :p_print
&nbsp; )
UNION
&nbsp; (SELECT 1
&nbsp; FROM DUAL
&nbsp; WHERE 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 1
&nbsp; AND 'Original' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= :p_print
&nbsp; AND NVL(OOHA.ATTRIBUTE7,'N') != 'Y'
&nbsp; )
UNION
&nbsp; (SELECT 1
&nbsp; FROM DUAL
&nbsp; WHERE 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= 1
&nbsp; AND 'Duplicate' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= :p_print
&nbsp; AND NVL(OOHA.ATTRIBUTE7,'N') = 'Y'
&nbsp; ) )
AND ooha.order_number &nbsp;= to_number(:p_order_num_low)
AND ooha.ORDER_TYPE_ID = to_number(:p_order_type_id)
AND 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=1
AND 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;=1
AND NOT EXISTS
&nbsp; (SELECT 1
&nbsp; FROM mtl_material_transactions mmt,
&nbsp; &nbsp; mtl_txn_request_lines mtrl
&nbsp; WHERE mmt.pick_slip_number IS NOT NULL
&nbsp; AND mmt.move_order_line_id &nbsp;= mtrl.line_id
&nbsp; AND WDD.MOVE_ORDER_LINE_ID &nbsp;= mtrl.line_id
&nbsp; )
ORDER BY PICK_SLIP_NUMBER,
&nbsp; CF_ORDER_NUMBER ,
&nbsp; SSD ,
&nbsp; SALES_LINE_NUMBER;