Thursday, March 8, 2012

Update PO Line Price -- Oracle Apps

po_change_api1_s API/Package to update PO Line Price. Noticed that Price gets changed when launch_approvals_flag is set to 'Y'
----------------------------
CREATE OR REPLACE
PACKAGE xx_po_price_update
AS
PROCEDURE price_update (
errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_po_num IN VARCHAR2,
p_line_num IN VARCHAR2,
p_new_price IN VARCHAR2
);

END xx_po_price_update;
/
SHOW ERRORS PACKAGE xx_po_price_update;

CREATE OR REPLACE
PACKAGE BODY xx_po_price_update
AS

/******************************************************************************
Procedure: put_log()
Description: Writes a line to the log file.
+- Required/Optional
| Name Description
- ----------------------------- -----------------------------------------------
R p_string String to write to the log file
******************************************************************************/
PROCEDURE put_log (p_string IN VARCHAR2)
IS
BEGIN
fnd_file.put_line (fnd_file.LOG, p_string);
END put_log;

/******************************************************************************
Procedure: price_update()
Description: Procedure to update PO Line Price.
+- Required/Optional
| Name Description
- ----------------------------------------------------------------------------
R p_po_num PO Number
R p_line_num PO Line Number
R p_new_price New PO Line Price
******************************************************************************/
PROCEDURE price_update (
errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_po_num IN VARCHAR2,
p_line_num IN VARCHAR2,
p_new_price IN VARCHAR2
)
IS


e_abort EXCEPTION;
e_skip EXCEPTION;
l_po_num po_headers_all.segment1%TYPE;
l_api_errors po_api_errors_rec_type;
l_revision_num NUMBER;
l_result NUMBER;
l_price po_lines_all.unit_price%TYPE;
l_org_id NUMBER := fnd_profile.value ('ORG_ID');

BEGIN

l_po_num := NULL;
l_revision_num := NULL;
l_result := NULL;

BEGIN
SELECT segment1, revision_num
INTO l_po_num, l_revision_num
FROM po_headers_all
WHERE org_id = l_org_id
AND segment1 = p_po_num;
EXCEPTION
WHEN NO_DATA_FOUND THEN
put_log ('No matching PO Number found for the value entered '||SQLERRM);
RAISE e_abort;
WHEN OTHERS THEN
put_log ('Error While fetching PO Number '||SQLERRM);
RAISE e_abort;
END;

put_log ('PO Number: ' || p_po_num);
put_log ('PO Line Number : '|| p_line_num);
put_log ('New Price: ' || p_new_price);

l_result :=
po_change_api1_s.update_po
(x_po_number => p_po_num, --Enter the PO Number
x_release_number => NULL, --Enter the Release Num
x_revision_number => l_revision_num, --Enter the Revision Number
x_line_number => TO_NUMBER(p_line_num), --Enter the Line Number
x_shipment_number => NULL, --Enter the Shipment Number
new_quantity => NULL, --Enter the new quantity
new_price => TO_NUMBER(p_new_price), --Enter the new price,
new_promised_date => NULL, --Enter the new promised date,
new_need_by_date => NULL, --Enter the new need by date,
launch_approvals_flag => 'Y',
update_source => NULL,
version => '1.0',
x_override_date => NULL,
x_api_errors => l_api_errors,
p_buyer_name => NULL,
p_secondary_quantity => NULL,
p_preferred_grade => NULL,
p_org_id => l_org_id);

IF (l_result = 1) THEN
put_log('Successfully updated the PO => ' || p_po_num);
END IF;

IF (l_result <> 1) THEN
put_log ('Failed to update the PO Due to Following Reasons');

-- Display the errors
FOR i IN 1 .. l_api_errors.message_text.COUNT
LOOP
put_log (l_api_errors.message_text (i));
END LOOP;
retcode := 2;
END IF;
EXCEPTION
WHEN e_abort THEN
put_log ('Unexpected Error Occured in price_update(). Aborting the Program');
retcode := 2;
WHEN OTHERS THEN
put_log ('Error in price_update(): ' || SQLERRM);
errbuf := SQLERRM;
retcode := 2;
END price_update;
END xx_po_price_update;
/
SHOW ERRORS PACKAGE BODY xx_po_price_update;

No comments:

Cellular Phones

Online Store