You are on page 1of 5

PURCHASE ORDER INTERFACE

Interface Tables :-
----------------------
po_headers_interface
po_lines_interface

Import Concurrent Program:- Import Standard Purchase Orders

Staging Table :-
------------------
CREATE TABLE XXX_PURCHASE_ORDER_STG
(
LEGACY_PONUM NUMBER(20),
CURRENCY_CODE VARCHAR2(15 BYTE),
VENDOR_NAME VARCHAR2(240 BYTE),
VENDOR_SITE_CODE VARCHAR2(15 BYTE),
BILL_TO VARCHAR2(60 BYTE),
SHIP_TO VARCHAR2(60 BYTE),
STATUS VARCHAR2(40 BYTE),
AGENT_NAME VARCHAR2(100 BYTE),
ITEM VARCHAR2(100 BYTE),
LINE_NUM NUMBER(3),
UNIT_PRICE NUMBER(10,2),
QUANTITY NUMBER(10),
NEED_BY_DATE DATE,
H_VERIFY_FLAG CHAR(1 BYTE),
L_VERIFY_FLAG CHAR(1 BYTE),
H_ERROR_MESSAGE VARCHAR2(2500 BYTE),
L_ERROR_MESSAGE VARCHAR2(2500 BYTE)
)

PL/SQL Script to upload data from staging table to interface table:


-----------------------------------------------------------------------------------

CREATE OR REPLACE PROCEDURE xxx_po_api


AS
---To Import data from Interface to Base Tables - Import Standard Purchase Orders
-- please do the following: to see the errors
-- Run the program - Purchasing Interface Errors Report
-- choose parameter : PO_DOCS_OPEN_INTERFACE
-- po_interface_errors
l_currency_code fnd_currencies_vl.currency_code%type;
l_verify_flag CHAR(1);
l_error_message VARCHAR2(5000);
l_vendor_id po_vendors.vendor_id%type;
l_vendor_site_id po_vendor_sites_all.vendor_site_id%type;
l_ship_to hr_locations.location_id%type;
l_bill_to hr_locations.location_id%type;
l_inventory_item_id mtl_system_items_b.inventory_item_id%type;
l_legacy_ponum NUMBER(20):=0;
l_batch_id NUMBER(3);
CURSOR C_PO_HEADER
IS
SELECT DISTINCT legacy_ponum,
currency_code,
vendor_name,
vendor_site_code,
ship_to,
bill_to,
status
FROM xxx_purchase_order_stg;
CURSOR C_PO_LINES(l_legacy_ponum NUMBER)
IS
SELECT *
FROM xxx_purchase_order_stg
WHERE trim(legacy_ponum) = trim(l_legacy_ponum);
BEGIN
FOR H1 IN C_PO_HEADER
LOOP
l_verify_flag := 'Y' ;
l_error_message := NULL;
BEGIN
SELECT currency_code
INTO l_currency_code
FROM fnd_currencies_vl
WHERE enabled_flag = 'Y'
AND currency_flag = 'Y'
AND upper(currency_code) = upper(trim(H1.currency_code));
EXCEPTION
WHEN OTHERS THEN
l_verify_flag := 'N' ;
l_error_message := l_error_message||'Currency Code is not Valid...';
END;
BEGIN
SELECT vendor_id
INTO l_vendor_id
FROM po_vendors
WHERE upper(vendor_name) = upper(trim(H1.vendor_name)) ;
EXCEPTION
WHEN OTHERS THEN
l_verify_flag := 'N' ;
l_error_message := l_error_message||'Vendor is not Existing...';
END;
BEGIN
SELECT vendor_site_id
INTO l_vendor_site_id
FROM po_vendor_sites_all
WHERE vendor_id = l_vendor_id
AND vendor_site_code = upper(trim(H1.vendor_site_code)) ;
EXCEPTION
WHEN OTHERS THEN
l_verify_flag := 'N' ;
l_error_message := l_error_message||'Vendor Site is not Existing...';
END;
BEGIN
SELECT location_id
INTO l_ship_to
FROM hr_locations
WHERE location_code = upper(trim(H1.ship_to));
EXCEPTION
WHEN OTHERS THEN
l_verify_flag := 'N' ;
l_error_message := l_error_message||'Ship To Location is not Existing...';
END;
BEGIN
SELECT location_id
INTO l_bill_to
FROM hr_locations
WHERE location_code = upper(trim(H1.bill_to));
EXCEPTION
WHEN OTHERS THEN
l_verify_flag := 'N' ;
l_error_message := l_error_message||'Bill To Location is not Existing...';
END;
IF H1.status = 'Approved' THEN
l_batch_id := 100 ;
elsif H1.status = 'Incomplete' THEN
l_batch_id := 101 ;
ELSE
l_verify_flag := 'N' ;
l_error_message := l_error_message||'Status is not valid...';
END IF;
l_legacy_ponum := trim(H1.legacy_ponum) ;
IF l_verify_flag <> 'N' THEN
INSERT
INTO po_headers_interface
(
interface_header_id,
batch_id,
action,
document_type_code,
currency_code,
agent_id,
vendor_id,
vendor_site_id,
ship_to_location_id,
bill_to_location_id
)
VALUES
(
po_headers_interface_s.nextval,
l_batch_id,
'ORIGINAL',
'STANDARD',
l_currency_code,
5479,
l_vendor_id,
l_vendor_site_id,
l_ship_to,
l_bill_to
);
UPDATE xxx_purchase_order_stg
SET h_verify_flag = 'Y'
WHERE legacy_ponum = l_legacy_ponum;
COMMIT;
FOR L1 IN C_PO_LINES(l_legacy_ponum)
LOOP
BEGIN
SELECT inventory_item_id
INTO l_inventory_item_id
FROM mtl_system_items_b
WHERE segment1
||'.'
||segment2
||'.'
||segment3
||'.'
||segment4 =L1.item
AND organization_id =
(SELECT inventory_organization_id
FROM hr_locations
WHERE location_id = l_ship_to
);
EXCEPTION
WHEN OTHERS THEN
l_verify_flag := 'N' ;
l_error_message := l_error_message ||'Inventory Item is not Existing...';
END;
IF L1.unit_price IS NULL THEN
l_verify_flag := 'N' ;
l_error_message := l_error_message ||'Unit Price is not Existing...';
ELSIF L1.quantity IS NULL THEN
l_verify_flag := 'N' ;
l_error_message := l_error_message ||'Quantity is not Existing...';
ELSIF L1.need_by_date IS NULL THEN
l_verify_flag := 'N' ;
l_error_message := l_error_message ||'Need By Date is not Existing...';
END IF;
IF l_verify_flag <> 'N' THEN
INSERT
INTO po_lines_interface
(
interface_line_id,
interface_header_id,
action,
line_num,
item_id,
unit_price,
quantity,
Need_By_Date
)
VALUES
(
po_lines_interface_s.nextval,
po_headers_interface_s.currval,
'ORIGINAL',
L1.line_num,
l_inventory_item_id,
L1.unit_price,
L1.quantity,
L1.need_by_date
);
UPDATE xxx_purchase_order_stg
SET l_verify_flag = 'Y'
WHERE legacy_ponum = L1.legacy_ponum
AND line_num = L1.line_num;
ELSE
UPDATE xxx_purchase_order_stg
SET l_error_message = l_error_message,
l_verify_flag = 'N'
WHERE legacy_ponum = L1.legacy_ponum
AND line_num = L1.line_num;
END IF;
COMMIT;
END LOOP;
ELSE
UPDATE xxx_purchase_order_stg
SET h_error_message = l_error_message,
h_verify_flag = 'N'
WHERE legacy_ponum = H1.legacy_ponum;
END IF;
COMMIT;
END LOOP;
END xxx_po_api;
/

You might also like