API To update Oracle Items
/* Formatted on 2018/04/23 12:05 (Formatter Plus v4.8.8) */
DECLARE
v_po_qty NUMBER;
v_so_qty NUMBER;
v_oh_qty NUMBER;
b_has_backlog BOOLEAN;
v_po_number VARCHAR2 (40);
v_po_line_num VARCHAR2 (40);
v_so_order_number VARCHAR2 (40);
v_so_ine_number VARCHAR2 (40);
v_subinventory_code VARCHAR2 (40);
x_inventory_item_id NUMBER;
x_organization_id NUMBER;
x_return_status VARCHAR2 (3000);
x_msg_count NUMBER;
x_msg_data VARCHAR2 (4000);
BEGIN
DBMS_OUTPUT.put_line ( 'Organization ID'
|| ','
|| 'Item Number'
|| ','
|| 'PO'
|| ','
|| 'SO'
|| ','
|| 'ONHAND'
|| ','
|| 'PO number'
|| ','
|| 'PO Line No'
|| ','
|| 'SO Number'
|| ','
|| 'SO Line No'
|| ','
|| 'Subinventory'
);
FOR i IN (SELECT msib.inventory_item_id, msib.segment1,
msib.organization_id,inventory_item_status_code
FROM apps.mtl_system_items_b msib
WHERE msib.inventory_item_status_code = 'Active'
and INVENTORY_ITEM_ID =6760202
AND ORGANIZATION_ID = 114)
LOOP
v_po_qty := 0;
v_so_qty := 0;
v_oh_qty := 0;
BEGIN
SELECT SUM ( NVL (poll.quantity, 0)
- NVL (poll.quantity_received, 0)
- NVL (poll.quantity_cancelled, 0)
),
pha.segment1, pol.line_num
INTO v_po_qty,
v_po_number, v_po_line_num
FROM apps.po_headers_all pha,
apps.po_line_locations_all poll,
apps.po_lines_all pol
WHERE pol.po_line_id = poll.po_line_id
AND pol.item_id = i.inventory_item_id
AND poll.ship_to_organization_id = i.organization_id
AND pol.po_header_id = poll.po_header_id
AND pol.po_header_id = pha.po_header_id
AND poll.need_by_date > '01-OCT-2000'
GROUP BY pha.segment1, pol.line_num;
EXCEPTION
WHEN OTHERS
THEN
v_po_qty := 0;
v_po_number := NULL;
v_po_line_num := NULL;
END;
BEGIN
SELECT SUM (moq.transaction_quantity), subinventory_code
INTO v_oh_qty, v_subinventory_code
FROM apps.mtl_onhand_quantities moq
WHERE moq.organization_id = i.organization_id
AND moq.inventory_item_id = i.inventory_item_id
GROUP BY subinventory_code;
EXCEPTION
WHEN OTHERS
THEN
v_oh_qty := 0;
v_subinventory_code := NULL;
END;
BEGIN
SELECT SUM ( NVL (oel.ordered_quantity, 0)
- NVL (oel.shipped_quantity, 0)
),
oeh.order_number, oel.line_number
INTO v_so_qty,
v_so_order_number, v_so_ine_number
FROM apps.oe_order_headers_all oeh, apps.oe_order_lines_all oel
WHERE oel.inventory_item_id = i.inventory_item_id
AND oeh.header_id = oel.header_id
AND oel.org_id IN (SELECT operating_unit
FROM apps.org_organization_definitions
WHERE organization_id = i.organization_id)
GROUP BY oeh.order_number, oel.line_number;
EXCEPTION
WHEN OTHERS
THEN
v_so_qty := 0;
v_so_order_number := NULL;
v_so_ine_number := NULL;
END;
b_has_backlog := FALSE;
IF NVL (v_po_qty, 0) + NVL (v_so_qty, 0) + NVL (v_oh_qty, 0) = 0
THEN
apps.ego_item_pub.process_item
(p_api_version => 1.0,
p_init_msg_list => 'T',
p_commit => 'T',
p_transaction_type => 'UPDATE',
p_inventory_item_id => i.inventory_item_id,
p_organization_id => i.organization_id,
p_segment1 => i.segment1,
p_inventory_item_status_code => 'Inactive',
x_inventory_item_id => x_inventory_item_id,
x_organization_id => x_organization_id,
x_return_status => x_return_status,
x_msg_count => x_msg_count,
x_msg_data => x_msg_data
);
ELSE
DBMS_OUTPUT.put_line ( i.organization_id
|| ','
|| i.segment1
|| ','
|| NVL (v_po_qty, 0)
|| ','
|| NVL (v_so_qty, 0)
|| ','
|| NVL (v_oh_qty, 0)
|| ','
|| v_po_number
|| ','
|| v_po_line_num
|| ','
|| v_so_order_number
|| ','
|| v_so_ine_number
|| ','
|| v_subinventory_code
);
END IF;
END LOOP;
DBMS_OUTPUT.put_line ('SUCCESS..'||x_msg_data);
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
ROLLBACK;
DBMS_OUTPUT.put_line ('FAILED: ' || SQLERRM);
END;
DECLARE
v_po_qty NUMBER;
v_so_qty NUMBER;
v_oh_qty NUMBER;
b_has_backlog BOOLEAN;
v_po_number VARCHAR2 (40);
v_po_line_num VARCHAR2 (40);
v_so_order_number VARCHAR2 (40);
v_so_ine_number VARCHAR2 (40);
v_subinventory_code VARCHAR2 (40);
x_inventory_item_id NUMBER;
x_organization_id NUMBER;
x_return_status VARCHAR2 (3000);
x_msg_count NUMBER;
x_msg_data VARCHAR2 (4000);
BEGIN
DBMS_OUTPUT.put_line ( 'Organization ID'
|| ','
|| 'Item Number'
|| ','
|| 'PO'
|| ','
|| 'SO'
|| ','
|| 'ONHAND'
|| ','
|| 'PO number'
|| ','
|| 'PO Line No'
|| ','
|| 'SO Number'
|| ','
|| 'SO Line No'
|| ','
|| 'Subinventory'
);
FOR i IN (SELECT msib.inventory_item_id, msib.segment1,
msib.organization_id,inventory_item_status_code
FROM apps.mtl_system_items_b msib
WHERE msib.inventory_item_status_code = 'Active'
and INVENTORY_ITEM_ID =6760202
AND ORGANIZATION_ID = 114)
LOOP
v_po_qty := 0;
v_so_qty := 0;
v_oh_qty := 0;
BEGIN
SELECT SUM ( NVL (poll.quantity, 0)
- NVL (poll.quantity_received, 0)
- NVL (poll.quantity_cancelled, 0)
),
pha.segment1, pol.line_num
INTO v_po_qty,
v_po_number, v_po_line_num
FROM apps.po_headers_all pha,
apps.po_line_locations_all poll,
apps.po_lines_all pol
WHERE pol.po_line_id = poll.po_line_id
AND pol.item_id = i.inventory_item_id
AND poll.ship_to_organization_id = i.organization_id
AND pol.po_header_id = poll.po_header_id
AND pol.po_header_id = pha.po_header_id
AND poll.need_by_date > '01-OCT-2000'
GROUP BY pha.segment1, pol.line_num;
EXCEPTION
WHEN OTHERS
THEN
v_po_qty := 0;
v_po_number := NULL;
v_po_line_num := NULL;
END;
BEGIN
SELECT SUM (moq.transaction_quantity), subinventory_code
INTO v_oh_qty, v_subinventory_code
FROM apps.mtl_onhand_quantities moq
WHERE moq.organization_id = i.organization_id
AND moq.inventory_item_id = i.inventory_item_id
GROUP BY subinventory_code;
EXCEPTION
WHEN OTHERS
THEN
v_oh_qty := 0;
v_subinventory_code := NULL;
END;
BEGIN
SELECT SUM ( NVL (oel.ordered_quantity, 0)
- NVL (oel.shipped_quantity, 0)
),
oeh.order_number, oel.line_number
INTO v_so_qty,
v_so_order_number, v_so_ine_number
FROM apps.oe_order_headers_all oeh, apps.oe_order_lines_all oel
WHERE oel.inventory_item_id = i.inventory_item_id
AND oeh.header_id = oel.header_id
AND oel.org_id IN (SELECT operating_unit
FROM apps.org_organization_definitions
WHERE organization_id = i.organization_id)
GROUP BY oeh.order_number, oel.line_number;
EXCEPTION
WHEN OTHERS
THEN
v_so_qty := 0;
v_so_order_number := NULL;
v_so_ine_number := NULL;
END;
b_has_backlog := FALSE;
IF NVL (v_po_qty, 0) + NVL (v_so_qty, 0) + NVL (v_oh_qty, 0) = 0
THEN
apps.ego_item_pub.process_item
(p_api_version => 1.0,
p_init_msg_list => 'T',
p_commit => 'T',
p_transaction_type => 'UPDATE',
p_inventory_item_id => i.inventory_item_id,
p_organization_id => i.organization_id,
p_segment1 => i.segment1,
p_inventory_item_status_code => 'Inactive',
x_inventory_item_id => x_inventory_item_id,
x_organization_id => x_organization_id,
x_return_status => x_return_status,
x_msg_count => x_msg_count,
x_msg_data => x_msg_data
);
ELSE
DBMS_OUTPUT.put_line ( i.organization_id
|| ','
|| i.segment1
|| ','
|| NVL (v_po_qty, 0)
|| ','
|| NVL (v_so_qty, 0)
|| ','
|| NVL (v_oh_qty, 0)
|| ','
|| v_po_number
|| ','
|| v_po_line_num
|| ','
|| v_so_order_number
|| ','
|| v_so_ine_number
|| ','
|| v_subinventory_code
);
END IF;
END LOOP;
DBMS_OUTPUT.put_line ('SUCCESS..'||x_msg_data);
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
ROLLBACK;
DBMS_OUTPUT.put_line ('FAILED: ' || SQLERRM);
END;
Comments
Post a Comment