DECLARE
-- Declare variables for the script
l_vendor_id NUMBER;
l_vendor_site_id NUMBER;
l_item_id NUMBER;
l_category_id NUMBER;
l_currency_code VARCHAR2(3);
l_org_id NUMBER;
l_bpo_header_id NUMBER;
l_bpo_line_id NUMBER;
l_start_date DATE := SYSDATE;
l_end_date DATE := ADD_MONTHS(SYSDATE, 12);
BEGIN
-- Set variable values as per your requirements
l_vendor_id := <vendor_id>;
l_vendor_site_id := <vendor_site_id>;
l_item_id := <item_id>;
l_category_id := <category_id>;
l_currency_code := 'USD';
l_org_id := <org_id>;
-- Create Blanket Purchase Order Header
l_bpo_header_id := po_headers_s.nextval;
INSERT INTO po_headers_all
(po_header_id, segment1, type_lookup_code, supplier_id, supplier_site_id,
currency_code, rate_date, rate_type, agreement_id, agreement_line_id,
authorization_status, org_id, start_date, end_date, created_by, creation_date,
last_updated_by, last_update_date, last_update_login, object_version_number)
VALUES
(l_bpo_header_id, 'BPO-' || to_char(SYSDATE, 'YYYYMMDD') || '-' || l_bpo_header_id,
'BLANKET', l_vendor_id, l_vendor_site_id, l_currency_code, SYSDATE,
'Corporate', NULL, NULL, 'INCOMPLETE', l_org_id, l_start_date, l_end_date,
fnd_global.user_id, SYSDATE, fnd_global.user_id, SYSDATE,
fnd_global.login_id, 1);
-- Create Blanket Purchase Order Line
l_bpo_line_id := po_lines_s.nextval;
INSERT INTO po_lines_all
(po_header_id, po_line_id, line_num, item_id, category_id, quantity,
unit_price, unit_meas_lookup_code, need_by_date, promise_date, org_id,
created_by, creation_date, last_updated_by, last_update_date, last_update_login,
object_version_number)
VALUES
(l_bpo_header_id, l_bpo_line_id, 1, l_item_id, l_category_id, 100,
10, 'EACH', l_start_date, l_end_date, l_org_id,
fnd_global.user_id, SYSDATE, fnd_global.user_id, SYSDATE, fnd_global.login_id, 1);
-- Commit the transaction
COMMIT;
DBMS_OUTPUT.PUT_LINE('Blanket Purchase Order created successfully with Header ID ' || l_bpo_header_id || ' and Line ID ' || l_bpo_line_id);
EXCEPTION
WHEN OTHERS THEN
-- Rollback the transaction in case of any exception
ROLLBACK;
DBMS_OUTPUT.PUT_LINE('Error creating Blanket Purchase Order: ' || SQLERRM);
END;