Sie sind auf Seite 1von 4

D:\clear_unordered_under_ISOIOT.

sql Wednesday, February 20, 2019 9:00 AM

/*
* Generic script to delete unordered receipt data existing for ISO or IOT shipments.
* Please refer to bug 8706731.
*
* Inputs for the script :-
* 1. shipment number (for l_shipment_num variable) and
* 2. receiving org id (for l_receiving_org_id variable)
*
* Important Note :
* Please ensure the scripts are ran on TEST instance first and tested for data
* correctness thoroughly. After the scripts are ran, please check the data and
* only the correct records are updated before committing.
* If all goes well, the script can be promoted to the PRODUCTION instance.
*
*/

DECLARE
x_progress number;
l_shipment_num rcv_shipment_headers.shipment_num%type := '&l_shipment_num';
--shipment number
l_receiving_org_id rcv_transactions.organization_id%type := &l_receiving_org_id ;
--Receiving Org Id
l_status rcv_shipment_lines.shipment_line_status_code%type;
l_quantity_received rcv_shipment_lines.quantity_received%type;
l_rt_quantity rcv_transactions.quantity%type;
l_shipment_line_id rcv_shipment_lines.shipment_line_id%type;
l_uom_rt rcv_transactions.unit_of_measure%type;
l_uom_rsl rcv_shipment_lines.unit_of_measure%type;
l_uom_con_rate number;
l_item_id rcv_shipment_lines.item_id%type;
l_exists_mtl number;
l_qty_precision number := 6;

CURSOR c_rt_unordered IS
SELECT rt.quantity as rt_quantity,
rt.unit_of_measure as rt_uom,
rt.shipment_line_id,
rsl.item_id,
rsl.unit_of_measure as rsl_uom
FROM rcv_transactions RT ,
rcv_shipment_headers rsh,
rcv_shipment_lines rsl
WHERE rt.transaction_type ='UNORDERED'
AND rsl.source_document_code in ('INVENTORY','REQ')
AND rsh.shipment_header_id = rsl.shipment_header_id
AND rsl.shipment_line_id = rt.shipment_line_id
AND rsh.shipment_num = l_shipment_num
AND rsh.ship_to_org_id = rsl.to_organization_id
AND rsh.organization_id = rsl.from_organization_id
AND rsh.ship_to_org_id = l_receiving_org_id
AND EXISTS (SELECT '1'
FROM mtl_supply ms
WHERE ms.supply_type_code = 'SHIPMENT'

-1-
D:\clear_unordered_under_ISOIOT.sql Wednesday, February 20, 2019 9:00 AM

AND ms.supply_source_id =
rsl.shipment_line_id
AND ms.po_line_location_id IS null)
order BY rt.shipment_line_id;

rt_record c_rt_unordered%ROWTYPE;
BEGIN
x_progress := 10;
OPEN c_rt_unordered;
x_progress := 20;
LOOP
x_progress := 30;
FETCH c_rt_unordered
INTO rt_record;

x_progress := 40;
EXIT WHEN c_rt_unordered%NOTFOUND;

l_rt_quantity := rt_record.rt_quantity;
l_shipment_line_id := rt_record.shipment_line_id;
l_uom_rt := rt_record.rt_uom;
l_uom_rsl := rt_record.rsl_uom;
l_item_id := rt_record.item_id;

x_progress := 41;

select quantity_received
into l_quantity_received
from rcv_shipment_lines
where shipment_line_id = l_shipment_line_id;
x_progress := 42;

if l_uom_rt <> l_uom_rsl then


x_progress := 43;
l_rt_quantity := l_rt_quantity *
po_uom_s.po_uom_convert(l_uom_rt, l_uom_rsl, l_item_id);
end if;
x_progress := 44;

IF round(l_quantity_received - l_rt_quantity, l_qty_precision) >


0 THEN
l_status := 'PARTIALLY RECEIVED';
x_progress := 45;
ELSIF round(l_quantity_received - l_rt_quantity,
l_qty_precision) <= 0 THEN
l_status := 'EXPECTED';
x_progress := 46;
END IF;

UPDATE apps.rcv_shipment_lines rsl


SET rsl.quantity_received =
round(rsl.quantity_received - l_rt_quantity, l_qty_precision),
rsl.shipment_line_status_code = l_status

-2-
D:\clear_unordered_under_ISOIOT.sql Wednesday, February 20, 2019 9:00 AM

WHERE rsl.shipment_line_id = l_shipment_line_id;


x_progress := 47;

select count(1)
into l_exists_mtl
from rcv_shipment_lines rsl,mtl_supply ms
where rsl.shipment_line_id = ms.shipment_line_id
and rsl.shipment_line_id = l_shipment_line_id
and ms.supply_type_Code = 'SHIPMENT'
and round(ms.quantity - (rsl.QUANTITY_SHIPPED -
rsl.QUANTITY_RECEIVED), l_qty_precision) >= 0;
x_progress := 48;

if l_exists_mtl = 0 then
x_progress := 49;
raise NO_DATA_FOUND;
end if;
x_progress := 50;
END LOOP;
x_progress := 60;
CLOSE c_rt_unordered;

x_progress := 70;

--delete rcv_supply records


DELETE rcv_supply
WHERE supply_source_id IN
( SELECT rt.transaction_id
FROM rcv_transactions rt ,
rcv_shipment_headers rsh,
rcv_shipment_lines rsl
WHERE rt.transaction_type ='UNORDERED'
AND rsl.source_document_code in ('INVENTORY','REQ')
AND rsh.shipment_header_id = rsl.shipment_header_id
AND rsl.shipment_line_id = rt.shipment_line_id
AND rsh.shipment_num = l_shipment_num
AND rsh.ship_to_org_id = rsl.to_organization_id
AND rsh.organization_id = rsl.from_organization_id
AND rsh.ship_to_org_id = l_receiving_org_id
AND EXISTS (SELECT '1'
FROM mtl_supply ms
WHERE ms.supply_type_code = 'SHIPMENT'
AND ms.supply_source_id =
rsl.shipment_line_id
AND ms.po_line_location_id IS null)
);

x_progress := 80;

--delete rt records
DELETE rcv_transactions
WHERE transaction_id IN
( SELECT rt.transaction_id

-3-
D:\clear_unordered_under_ISOIOT.sql Wednesday, February 20, 2019 9:00 AM

FROM rcv_transactions rt ,
rcv_shipment_headers rsh,
rcv_shipment_lines rsl
WHERE rt.transaction_type ='UNORDERED'
AND rsl.source_document_code in ('INVENTORY','REQ')
AND rsh.shipment_header_id = rsl.shipment_header_id
AND rsl.shipment_line_id = rt.shipment_line_id
AND rsh.shipment_num = l_shipment_num
AND rsh.ship_to_org_id = rsl.to_organization_id
AND rsh.organization_id = rsl.from_organization_id
AND rsh.ship_to_org_id = l_receiving_org_id
AND EXISTS (SELECT '1'
FROM mtl_supply ms
WHERE ms.supply_type_code = 'SHIPMENT'
AND ms.supply_source_id =
rsl.shipment_line_id
AND ms.po_line_location_id IS null)
);
dbms_output.put_line('Script execution completed...' );

EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('x_progress := '|| x_progress);
ROLLBACK;
IF ( c_rt_unordered%ISOPEN) THEN
CLOSE c_rt_unordered;
END IF;
RAISE;
END;

-4-