Monday, 26 January 2015

How To Use the PO Change API To Update Existing Purchase Orders



Goal : What are the steps required in order to use the Change PO API to update a Standard Purchase Order ?

Approach:

Login to the application using the seeded user/password Operations/welcome then Navigate to the Purchasing Responsibility : Purchasing Vision Operations (USA)

Navigate to the Purchase Order form and create a PO with a single line with quantity = 10, price = 1 and promised date = 31-MAR-2010 (use any date in the future as long as it is in an open period). The Purchase Order screen will look like the following screenshot :




Querying the same PO through the PO Summary form, all the relevant line data can be seen :




Clicking on the Shipments button shows the relevant Shipment information :



The first run of the API will demonstrate updating the Quantity of Line 1 of the PO to 25. Submit the change API using sqlplus as follows :


set serveroutput ON;
DECLARE
l_result NUMBER;
l_api_errors PO_API_ERRORS_REC_TYPE;
BEGIN
-- This needs to be changed according to your environment setup.
FND_GLOBAL.apps_initialize ( user_id => 1318,
resp_id => 50578,
resp_appl_id => 201 );
mo_global.init('PO'); -- need for R12
l_result := PO_CHANGE_API1_S.update_po (
X_PO_NUMBER => &po_num,
X_RELEASE_NUMBER => Null,
X_REVISION_NUMBER => &rev_num,
X_LINE_NUMBER => &line_num,
X_SHIPMENT_NUMBER => &shipment_num,
NEW_QUANTITY => 25,
NEW_PRICE => Null,
NEW_PROMISED_DATE => Null,
NEW_NEED_BY_DATE => Null,
LAUNCH_APPROVALS_FLAG => 'N',
UPDATE_SOURCE => 'API',
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 => &org_id
);
dbms_output.put_line ('l_result' || l_result);
IF (l_result <> 1) THEN
-- Display the errors
FOR i IN 1..l_api_errors.message_text.COUNT LOOP
dbms_output.put_line ( l_api_errors.message_text(i) );
END LOOP;
END IF;
END;

commit;


Querying the PO line again in the PO Summary form shows :


The second run of the API will demonstrate updating the Price of Line 1 of the PO to 0.9. Submit the change API using sqlplus as follows :

set serveroutput ON;
DECLARE
l_result NUMBER;
l_api_errors PO_API_ERRORS_REC_TYPE;
BEGIN
-- This needs to be changed according to your environment setup.
FND_GLOBAL.apps_initialize ( user_id => 1318,
resp_id => 50578,
resp_appl_id => 201 );
mo_global.init('PO'); -- need for R12
l_result := PO_CHANGE_API1_S.update_po (
X_PO_NUMBER => &po_num,
X_RELEASE_NUMBER => Null,
X_REVISION_NUMBER => &rev_num,
X_LINE_NUMBER => &line_num,
X_SHIPMENT_NUMBER => &shipment_num,
NEW_QUANTITY => Null,
NEW_PRICE => 0.9,
NEW_PROMISED_DATE => Null,
NEW_NEED_BY_DATE => Null,
LAUNCH_APPROVALS_FLAG => 'N',
UPDATE_SOURCE => 'API',
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 => &org_id
);
dbms_output.put_line ('l_result' || l_result);
IF (l_result <> 1) THEN
-- Display the errors
FOR i IN 1..l_api_errors.message_text.COUNT LOOP
dbms_output.put_line ( l_api_errors.message_text(i) );
END LOOP;
END IF;
END;

commit;


Requerying the PO line shows that the price has been changed as expected :




The third run of the API will demonstrate updating the Promised Date of Shipment 1 (of Line 1) of the PO to 30-Mar-2010. Submit the change API using sqlplus as follows :



set serveroutput ON;
DECLARE
l_result NUMBER;
l_api_errors PO_API_ERRORS_REC_TYPE;
BEGIN
-- This needs to be changed according to your environment setup.
FND_GLOBAL.apps_initialize ( user_id => 1318,
resp_id => 50578,
resp_appl_id => 201 );
mo_global.init('PO'); -- need for R12
l_result := PO_CHANGE_API1_S.update_po (
X_PO_NUMBER => &po_num,
X_RELEASE_NUMBER => Null,
X_REVISION_NUMBER => &rev_num,
X_LINE_NUMBER => &line_num,
X_SHIPMENT_NUMBER => &shipment_num,
NEW_QUANTITY => Null,
NEW_PRICE => Null,
NEW_PROMISED_DATE => TO_DATE(TO_CHAR('30-Mar-2010'),'DD-MON-YYYY'),
NEW_NEED_BY_DATE => Null,
LAUNCH_APPROVALS_FLAG => 'N',
UPDATE_SOURCE => 'API',
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 => &org_id
);
dbms_output.put_line ('l_result' || l_result);
IF (l_result <> 1) THEN
-- Display the errors
FOR i IN 1..l_api_errors.message_text.COUNT LOOP
dbms_output.put_line ( l_api_errors.message_text(i) );
END LOOP;
END IF;
END;

commit;


Querying the PO Shipment from the PO Summary form shows that the update was successful :



The following information from Page 131 of the Oracle Manufacturing APIs and Open Interfaces Manual explains setting the org context :

Setting Context
Prior to calling the API you should set your global context to reflect the application, user and responsibility used to perform the change action. If you do not set this context, the API will not be able to identify or update your data. If you are calling the API from an environment that already has the context set you do not need to set it again.
The call that may be used to set the global context is: fnd_global.apps_initialize(user_id, resp_id, resp_application_id); user_id is an FND_USER who would be allowed to perform the change action. Resp_id is the id of the responsibility that is being used to modify the document. This id will also set the context for the operating unit for the document being updated.

2 comments:

  1. Please let me know the API to update PO distributions.

    ReplyDelete
  2. All these changes will make the PO status as REQUIRE REAPPROVAL. How to alter the PO with changing its status?

    ReplyDelete