0% found this document useful (0 votes)
181 views

ORDTL SQL SR Query

This document contains SQL code that queries order header and line item details from an Oracle database based on an input order number. It retrieves information such as the order status, items, quantities, dates and more. The code handles exceptions if the order number is invalid and allows the user to specify options like the decimal precision for quantities.

Uploaded by

damodarvarde
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
181 views

ORDTL SQL SR Query

This document contains SQL code that queries order header and line item details from an Oracle database based on an input order number. It retrieves information such as the order status, items, quantities, dates and more. The code handles exceptions if the order number is invalid and allows the user to specify options like the decimal precision for quantities.

Uploaded by

damodarvarde
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

SET VERIFY OFF

WHENEVER SQLERROR CONTINUE;


REM dbdrv: none
/* $Header: ordtl.sql 115.8 2007/11/05 17:46:00 pupakare noship $ */
set pagesize 1000
set newpage 0
set linesize 500
set verify off
accept ord_num prompt 'ORDER NUMBER please: '
prompt
accept dec_prc default 5 prompt 'Please choose decimal precision (5, 10 or 40) O
R just press enter (default 5): '
set echo off
define extn = '.txt'
prompt ===================================
prompt spooling file &ord_num&extn
prompt ===================================
variable hhid number;
variable decprc number;
variable decfmt varchar2(60);
set serverout on
declare
l_header_id number;
l_order_type_id number;
l_version_no number;
l_count number := 0;
l_msg varchar2(200);
not_an_order exception;
begin
:decprc := &dec_prc;
IF :decprc = 10 THEN
:decfmt := '9999999999.9999999999';
ELSIF :decprc = 40 THEN
:decfmt := '9999999999.9999999999999999999999999999999999999999';
ELSE
:decfmt := '9999999999.99999';
END IF;
dbms_output.put_line('header id order type
version number');
dbms_output.put_line('-----------------------------------------------------
--------------------------');
FOR c_rec IN (
SELECT header_id, ooha.order_type_id, description, version_number
FROM oe_order_headers_all ooha, oe_transaction_types_tl ottt
WHERE order_number = &ord_num
AND ooha.order_type_id = ottt.transaction_type_id
AND language = userenv('lang'))
LOOP
l_msg:= rpad(c_rec.header_id, 15, ' ')||rpad(substr(c_rec.description, 1, 5
0), 50, ' ')||c_rec.version_number;
dbms_output.put_line(l_msg);
l_count := l_count + 1;
l_header_id := c_rec.header_id;
END LOOP;
IF (l_count = 0) then
:hhid := -999999; -- ERROR CONDITION!
!
raise not_an_order;
ELSIF (l_count = 1) then
:hhid := l_header_id;
END IF;
exception
when not_an_order then
dbms_output.put_line('');
dbms_output.put_line('EXCEPTION: Order '||&ord_num||' does not exist. !!!PR
ESS CTRL-C TO STOP!!!');
end;
/
set term off
col hhid new_value hhid
select :hhid hhid from ic_whse_mst where rownum < 2;
col decfmt new_value decfmt
select :decfmt decfmt from ic_whse_mst where rownum < 2;
set term on
accept hid default '&hhid' prompt 'Please choose appropriate header id from abo
ve OR just press enter if it is <&hhid>: '
prompt
accept lineid default 'all' prompt 'Please choose line_id (for a particular line
) OR just press enter for all lines (default = all): '
prompt
prompt spooling &ord_num&extn
prompt
spool &ord_num&extn
column operating_unit format a40 heading |operating|unit
column cancelled_flag format a6 heading hdr|cancel
column status format a10 heading status
column header_id format 9999999999 heading header_id
column open_flag format a6 heading open|flag
column booked_flag format a6 heading booked|flag
column ord_dt format a10 heading order|date
column inv_org format 9999999999 heading inventory|org
prompt =========== order header info for sales order number: &ord_num ==========
=====================================
prompt
select o.name operating_unit,h.header_id,h.ship_from_org_id inv_org,
h.flow_status_code status,h.open_flag,booked_flag,h.cancelled_flag,h.ord
ered_date ord_dt
from oe_order_headers_all h, hr_operating_units o
where header_id = &hid
and o.organization_id = h.org_id;
column line_num format a11 heading line|number
column line_id format 9999999999 heading line_id
column split_by format a10 heading |split_by
column split_from_line_id format 9999999999 heading |split|from|line_id
column status format a20
column item format a20 heading ordered|item
column inventory_item_id format 9999999999 heading apps|item_id
column dualum_ind format 9999 heading dual|?
column lot_ctl format 9999 heading lot|?
column loct_ctl format 9999 heading item|loct|?
column lot_indivisible format 9999 heading lot|indvsble|?
column noninv_ind format 9999 heading noninv|?
column sublot_ctl format 9999 heading sublot|?
column ont_pricing_qty_source format a10 heading pricing_by|?
column item_id format 9999999999 heading opm|item_id
column qty1 format &decfmt heading ordr|qty
column qty2 format &decfmt heading ordr|qty2
column fqty format &decfmt heading fulfil|qty
column sqty format &decfmt heading ship_qty|ord_uom
column sgqty format &decfmt heading ship_qty|pri_uom
column cqty format &decfmt heading cancel|qty
column open_flag format a4 heading open|flag
column booked_flag format a4 heading book|flag
column cancelled_flag format a4 heading cancel|flag
column ship_from_org_id format 9999999999 heading ship_from|org_id
column loct_ctl format 99999 heading loct|?
column ful_flag format a4 heading fulfil|flag
column open_flag format a4 heading open|flag
column invoice_qty format &decfmt heading invoice|qty
column inv_int_sta_code format a8 heading invoice|intface|sta_cod
e
column ship_int_flag format a7 heading ship|intface|flag
column cr_dt format a22 heading creation|date
column upd_dt format a22 heading last|update|date
column status_ctl format 999999 heading status|?
column grade_ctl format 99999 heading grade|?
column whse_code format a4 heading opm|whse
column wlc format 9999 heading whse|loct|?
column sta format 99999 heading ship|tol|above
column stb format 99999 heading ship|tol|below
column line_type format a25 heading 'line type'
column sdli format 9999999999 heading source_doc|line_id
column src_type format a10 heading source|type;
prompt =========== order line details for sales order number: &ord_num and line_
id: &lineid =========================
prompt
select rtrim(l.line_number||'.'||
l.shipment_number||'.'||
l.option_number||'.'||
l.component_number||'.'||
l.service_number, '.') line_num,
l.line_id,l.split_from_line_id,l.split_by,l.flow_status_code status,
l.ordered_item item,i.item_id,l.ordered_quantity qty1,l.order_quantity_u
om um1,
l.ordered_quantity2 qty2,l.ordered_quantity_uom2 um2,l.shipped_quantity
sqty,l.shipping_quantity sgqty,
l.ship_tolerance_above sta,l.ship_tolerance_below stb,l.fulfilled_flag f
ul_flag,
l.shipping_interfaced_flag ship_int_flag,l.fulfilled_quantity fqty,l.inv
oiced_quantity invoice_qty,
l.invoice_interface_status_code inv_int_sta_code,l.open_flag,l.booked_fl
ag,l.cancelled_quantity cqty,
l.cancelled_flag,l.inventory_item_id,l.ship_from_org_id,i.lot_indivisibl
e, i.noninv_ind,i.dualum_ind,
i.lot_ctl,i.sublot_ctl,i.loct_ctl,i.grade_ctl,i.status_ctl,
decode(i.ont_pricing_qty_source,1,'Secondary','Primary') ont_pricing_qty
_source,w.whse_code,w.loct_ctl wlc,
l.source_document_line_id sdli,l.source_type_code src_type,
ott.name line_type,to_char(l.creation_date,'DD-MON-YYYY HH24:MI:SS') cr_
dt,
to_char(l.last_update_date,'DD-MON-YYYY HH24:MI:SS') upd_dt
from oe_order_lines_all l, ic_whse_mst w, mtl_system_items m, ic_item_mst_b i
, oe_transaction_types_tl ott
where l.header_id = &hid
and l.line_id like decode('&lineid','all','%','&lineid')
and l.ship_from_org_id = w.mtl_organization_id
and l.inventory_item_id = m.inventory_item_id
and l.ship_from_org_id = m.organization_id
and m.segment1 = i.item_no
and l.line_type_id = ott.transaction_type_id
and ott.language = ( select fl.language_code
from fnd_languages fl
where fl.installed_flag = 'B')
order by l.line_id;

column source_header_id format 9999999999 heading order|header_id


column source_line_number format a11 heading |order|line|num
ber
column source_line_id format 9999999999 heading order|line_id
column delivery_detail_id format 9999999999 heading delivery|detail
_id
column split_from_delivery_detail_id format 9999999999 heading split_from|deli
very|detail_id
column move_order_line_id format 9999999999 heading move_order|line
_id
column rel_sts format a16 heading release|status
column src_requested_quantity format &decfmt heading order|qty
column src_requested_quantity_uom format a4 heading uom
column src_requested_quantity2 format &decfmt heading order|qty2
column src_requested_quantity_uom2 format a4 heading uom2
column requested_quantity format &decfmt heading requested|qty
column requested_quantity_uom format a4 heading uom
column requested_quantity2 format &decfmt heading requested|qty2
column requested_quantity_uom2 format a4 heading uom2
column shipped_quantity format &decfmt heading shipped|qty
column shipped_quantity2 format &decfmt heading shipped|qty2
column cancelled_quantity format &decfmt heading cancel|qty
column cancelled_quantity2 format &decfmt heading cancel|qty2
column delivered_quantity format &decfmt heading delivered|qty
column delivered_quantity2 format &decfmt heading delivered|qty2
column picked_quantity format &decfmt heading picked|qty
column picked_quantity2 format &decfmt heading picked|qty2
column oeif format a10 heading oe|interf|flag
column invif format a10 heading inv|interf|flag
column lotno format a10 heading lot|num
column slotno format a10 heading sublot|num
column ship_set_id format 9999999999 heading shipset|id
prompt =========== delivery line details for sales order number: &ord_num and li
ne_id: &lineid ======================
prompt
select source_line_number,source_line_id,delivery_detail_id,split_from_delivery
_detail_id,move_order_line_id,
decode(released_status,'R','R-Ready for rel','S','S-Rel to whse','Y','Y-
Staged',
'C','C-Shipped','B','B-Backordered','D','D-Cancelled',released_st
atus) rel_sts,
requested_quantity,requested_quantity_uom,requested_quantity2, requested
_quantity_uom2,
picked_quantity,picked_quantity2,
shipped_quantity,shipped_quantity2,lot_number lotno,sublot_number slotno
,oe_interfaced_flag oeif,
inv_interfaced_flag invif,ship_tolerance_above sta,ship_tolerance_below
stb, ship_set_id, inventory_item_id,
src_requested_quantity,src_requested_quantity_uom,src_requested_quantity
2,src_requested_quantity_uom2,
organization_id inv_org,cancelled_quantity,cancelled_quantity2,delivered
_quantity,delivered_quantity2,
to_char(creation_date,'DD-MON-YYYY HH24:MI:SS') cr_dt,to_char(last_updat
e_date,'DD-MON-YYYY HH24:MI:SS') upd_dt
from wsh_delivery_details
where source_header_id = &hid
and source_line_id like decode('&lineid','all','%','&lineid')
order by source_line_id,delivery_detail_id;

column trans_id format 9999999999 heading trans|id


column doc_id format 9999999999 heading doc|id
column doc_type format a4 heading doc|type
column orgn_code format a4 heading orgn
column co_code format a4 heading cmpny
column whse_code format a4 heading whse|code
column lot_id format 9999999999 heading lot|id
column location format a16 heading location
column trans_qty format &decfmt heading trans|qty
column trans_qty2 format &decfmt heading trans|qty2
column trans_um format a4 heading item|um1
column trans_um2 format a4 heading item|um2
column line_id format 9999999999 heading line|id
column line_type format 99 heading line|type
column lot_status format a6 heading lot|status
column qc_grade format a5 heading grade
column completed_ind format 99 heading cmpl|?
column delete_mark format 99 heading deleted|?
column trans_date format a22 heading trans|date
column line_detail_id format 9999999999 heading line|detail_id
column staged_ind format 999999 heading staged|ind
column gl_posted_ind format 99 heading glpost|?
column pick_slip_number format 9999999999 heading pick_slip|number
column cr_dt format a22 heading creation|date
column upd_dt format a22 heading |last|update|date
column invoiced_flag format a4 heading invc|flag
prompt =========== transaction details for sales order number: &ord_num and line
_id: &lineid ========================
prompt
select itp.trans_id,itp.line_id,itp.line_detail_id,itp.item_id,itp.staged_ind,
itp.completed_ind,itp.delete_mark,itp.trans_qty,itp.trans_um,itp.trans_q
ty2,itp.trans_um2,
itp.lot_id, ilm.lot_no lotno,ilm.sublot_no slotno,
itp.whse_code, itp.location, itp.lot_status,itp.qc_grade,itp.doc_type,it
p.orgn_code,
itp.co_code,itp.line_type,itp.gl_posted_ind , itp.pick_slip_number,itp.d
oc_id,
--transfer_price,
invoiced_flag,
to_char(trans_date,'DD-MON-YYYY HH24:MI:SS') trans_date,
to_char(itp.creation_date,'DD-MON-YYYY HH24:MI:SS') cr_dt, to_char(itp.l
ast_update_date,'DD-MON-YYYY HH24:MI:SS') upd_dt
from ic_tran_pnd itp, ic_lots_mst ilm, oe_order_lines_all lines
where lines.header_id = &hid
and itp.line_id like decode('&lineid','all','%','&lineid')
and itp.doc_type = 'OMSO'
and itp.item_id = ilm.item_id
and itp.lot_id = ilm.lot_id
and itp.line_id = lines.line_id
order by line_id, line_detail_id desc, trans_id;

column delivery_assignment_id format 9999999999 heading |delivery|assignm


ent|id
column delivery_id format 9999999999 heading delivery|id
column deli_name format a10 heading delivery|name
column deli_status format a10 heading delivery|status
column delivery_leg_id format 9999999999 heading delivery|leg_id
column pick_up_stop_id format 9999999999 heading pick_up|stop_id
column drop_off_stop_id format 9999999999 heading drop_off|stop_id
column pif format a12 heading pending|interf|fl
ag
column trip_stop_status format a10 heading trip|stop|status
column actual_departure_date format a10 heading actual|dep|date
column trip_name format a10 heading trip|name
column trip_id format 9999999999 heading trip|id
column trip_status format a10 heading trip|status
column trip_stop format a50 heading trip|stop
prompt =========== trip details for sales order number: &ord_num and line_id: &l
ineid ===============================
prompt
select wdd.source_header_id, wdd.source_line_id,
assign.delivery_assignment_id, assign.delivery_id, assign.delivery_detail
_id,
deli.name deli_name, deli.status_code deli_status,
legs.delivery_leg_id,legs.pick_up_stop_id,
-- legs.drop_off_stop_id,
decode(stops.pending_interface_flag, NULL, 'Not Pending', 'Y', 'Pending',
stops.pending_interface_flag) pif,
stops.status_code trip_stop_status,stops.actual_departure_date,
trips.name trip_name, trips.trip_id,trips.status_code trip_status
from wsh_delivery_details wdd, wsh_delivery_assignments assign,
wsh_new_deliveries deli,wsh_delivery_legs legs,
wsh_trip_stops stops,wsh_trips trips
where wdd.source_header_id = &hid
and wdd.source_line_id like decode('&lineid','all','%','&lineid')
and wdd.delivery_detail_id =assign.delivery_detail_id
and assign.delivery_id = deli.delivery_id
and deli.delivery_id=legs.delivery_id
and legs.pick_up_stop_id = stops.stop_id
and stops.trip_id = trips.trip_id
order by assign.delivery_assignment_id, assign.delivery_id, assign.delivery_deta
il_id;

column ord_line_id format 9999999999 heading |order|line|id


column line_number format 999999 heading line|no
column line_status format 99999 heading line|sta
column txn_line_id format 9999999999 heading move_order|line_id
column pri_qty format &decfmt heading primary|qty
column qty format &decfmt heading quantity
column sec_qty format &decfmt heading secondry|qty
column qty_del format &decfmt heading qty|deliverd
column sec_qty_del format &decfmt heading secondary|qty|deliverd
column qty_detailed format &decfmt heading qty|detailed
column sec_qty_detailed format &decfmt heading secondary|qty|detailed
column to_subinv format a10 heading to_subinv
column to_locator_id format 9999999999 heading to_locator_id
column orgn_id format 9999999999 heading orgn_id
prompt *************************************************************************
*************************************
prompt =========== move order details for sales order number: &ord_num and line_
id: &lineid =========================
prompt
select line_id txn_line_id, txn_source_line_id ord_line_id, line_number,line_st
atus,inventory_item_id,
to_subinventory_code to_subinv, to_locator_id, quantity qty, uom_code um
,primary_quantity pri_qty,
secondary_quantity sec_qty,secondary_uom_code um2,quantity_delivered qty
_del,
secondary_quantity_delivered sec_qty_del,quantity_detailed qty_detailed,
secondary_quantity_detailed sec_qty_detailed, lot_no lotno, sublot_no sl
otno, qc_grade,
organization_id orgn_id
from ic_txn_request_lines
where txn_source_line_id in (select line_id
from oe_order_lines_all
where header_id = &hid
and line_id like decode('&lineid','all','%','&li
neid'))
order by ord_line_id, txn_line_id;

spool off
set verify on
clear columns

You might also like