Tuesday, May 2, 2017

Script to Submit the Request Set using API in Oracle

Using below script One can submit the request set. But to execute the below script successfully define the Concurrent program for the following script and the either submit it through SRS window or using API FND_REQUEST.SUBMIT_REQUEST.


CREATE OR REPLACE PROCEDURE apps.xx_fnd_submit(errbuf                                       OUT VARCHAR2
                                                    , retcode                                      OUT VARCHAR2)
AS
   /*+==========================================================================
   | Concurrent Processing Sample Code
   |
   | FILE:
   | fnd_submit_test.pls
   |
   | REVISION:
   | $Id$
   |
   | DESCRIPTION:
   | FND_SUBMIT test procedure and sample code
   | Creates a procedure called fnd_submit_test that can be registered
   | and run as a concurrent program.
   | This procedure will use the FND_SUBMIT API to submit a request set.
   | (Function Security Reports - This request set should be seeded, if
   | it is not available the values in the script may need to be changed.)
   | The procedure will then place itself in a Paused status until the
   | request set completes.
   |
   | INSTRUCTIONS:
   |
   | 1. Install this procedure in the APPS schema.
   |
   | 2. Register the procedure as a concurrent program
   |
   |
   +==========================================================================*/
   success                                      BOOLEAN;
   req_id                                       NUMBER;
   req_data                                     VARCHAR2(10);
   srs_failed                                   EXCEPTION;
   submitprog_failed                            EXCEPTION;
   submitset_failed                             EXCEPTION;
BEGIN
   -- Use FND_FILE to output messages at each stage
   DBMS_OUTPUT.put_line( 'Starting test...');

   -- Read fnd_conc_global.request_data, if available then we have been
   -- reawakened after the request set has completed.
   -- If so, exit.
   req_data                                                 := fnd_conc_global.request_data;
   DBMS_OUTPUT.put_line(   'req_data : '
                        || req_data);

   IF (req_data IS NOT NULL)
   THEN
      errbuf                                                   := 'Done!';
      retcode                                                  := 0;
      RETURN;
   END IF;

   -- Step 1 - call set_request_set
   DBMS_OUTPUT.put_line( 'Calling set_request_set...');

   success                                                  :=
      fnd_submit.set_request_set('XX'
                               , 'XX_CRE_CONT');

   IF (NOT success)
   THEN
      RAISE srs_failed;
   END IF;


   DBMS_OUTPUT.put_line( 'Calling submit program first time...');

   -- Step 2 - call submit program for each program in the set
   success                                                  :=
      fnd_submit.submit_program('XX'
                              , 'XX_OM_CREATE_CONTRACT'
                              , 'STAGE10');

   IF (NOT success)
   THEN
      RAISE submitprog_failed;
   END IF;


   DBMS_OUTPUT.put_line( 'Calling submit program second time...');

   success                                                  :=
      fnd_submit.submit_program('OKS'
                              , 'OKSREPROC'
                              , 'OKCCONTORD'
                              , ''
                              , '');

   IF (NOT success)
   THEN
      RAISE submitprog_failed;
   END IF;

   -- Step 3 - call submit_set
   DBMS_OUTPUT.put_line( 'Calling submit_set...');

   req_id                                                   :=
      fnd_submit.submit_set(NULL
                          , TRUE);

   IF (req_id = 0)
   THEN
      RAISE submitset_failed;
   END IF;

   DBMS_OUTPUT.put_line(   'Finished. with request_id : '
                        || req_id);


   -- Set conc_status to PAUSED, set request_data to 1 and exit
   fnd_conc_global.set_req_globals(conc_status                               => 'PAUSED'
                                 , request_data                              => '1');

   errbuf                                                   :=
         'Request set submitted. id = '
      || req_id;
   retcode                                                  := 0;
   COMMIT;
EXCEPTION
   WHEN srs_failed
   THEN
      errbuf                                                   :=
            'Call to set_request_set failed: '
         || fnd_message.get;
      retcode                                                  := 2;
      DBMS_OUTPUT.put_line( errbuf);
   WHEN submitprog_failed
   THEN
      errbuf                                                   :=
            'Call to submit_program failed: '
         || fnd_message.get;
      retcode                                                  := 2;
      DBMS_OUTPUT.put_line( errbuf);
   WHEN submitset_failed
   THEN
      errbuf                                                   :=
            'Call to submit_set failed: '
         || fnd_message.get;
      retcode                                                  := 2;
      DBMS_OUTPUT.put_line( errbuf);
   WHEN OTHERS
   THEN
      errbuf                                                   :=
            'Request set submission failed - unknown error: '
         || SQLERRM;
      retcode                                                  := 2;
      DBMS_OUTPUT.put_line( errbuf);
END;
/

Friday, April 28, 2017

How to Pass Parameters from One Program to the Next Program in a Request Set

How to Pass Parameters from One Program to the Next Program in a Request Set (Doc ID 239808.1)




APPLIES TO:

Oracle Application Object Library - Version 11.5.10.2 to 12.1.3 [Release 11.5 to 12.1]
Information in this document applies to any platform.


GOAL

 How to pass parameters from one program to the next program in a request set

SOLUTION

1. Query up your request set.
2. Select the 'Define Stages' button.
3. Select 'Requests' button for the stage.
4. Select 'Parameters' button for the report.
5. Enter a short name for the 'Shared Parameter' field.
5. Select the name for the parameter to be shared in the other reports in the request set.

For an example to see how this is done, query up the seeded report set: Function Security Reports


Thursday, November 10, 2016

Public API's Needed For Performing ISupplier Portal Actions From Concurrent Program.

REM Doc ID 2193130.1

1. As soon as the change request is submitted, row level validations are done in controller, AMImpl .
Once the validation is successful, change request records are stored in array. Then, it will be passed to PO_CHG_REQUEST_PVT.PROCESS_SUPPLIER_REQUEST.
2. The above API will have some validations and then finally saves the data in po_change_requests table by calling save_request.
3. Finally, POSCHORD workflow will be called . (Main Process).
4. Check for the change details, Notify Requester/Planner if required, then check whether change is within tolerance or not.
Based on the same and few other criteria, check whether Requester approval is required or not.
5. Later, Sends notification to buyer for approval. You can clearly find all the API details in Workflow.
6. Even after buyer accepts the change, the details can be found in workflow - PO_SUP_CHG_REQUEST_WF_GRP.PROCESS_RESPONSE.

Brief details about response flow.

-> PO_ChangeOrderWF_PVT.ProcessResponse
-> PO_CHANGE_RESPONSE_PVT.MoveChangeToPO
-> UPDATE PO_HEADERS_ALL to APPROVED.
-> PO_DOCUMENT_UPDATE_GRP.update_document
-> UPDATE po_change_requests with line_location_id for split shipment
-> PO_DOCUMENT_UPDATE_GRP.launch_po_approval_wf

How to use Change PO API group package PO_DOCUMENT_UPDATE_GRP to make multiple changes to PO at once

REM Refer to metalink Doc ID 1406047.1 for more details
REM Note:  This API supports only set of attributes at 
REM line/shipment/distribution level as listed above with 
REM Approval option.
REM Any other PO attributes  in Type PO_CHANGES_REC_TYPE then listed REM above are  reserved for Internal References/Usage and not
REM supported via this API.
REM 1. PO_CHANGES_REC_TYPE:
REM This object represents header of PO. It can be created by supplying header_id of a PO.
REM e.g.
REM l_header PO_CHANGES_REC_TYPE;
REM l_header.create_object(p_po-header_id => <po_header_id>, p_po_release_id => <release_id>);

REM In case of a PO, release_id should be supplied and release_id will be null. Release_id is used while creating object of release header.

REM Optional parameters to create object are:
REM 1. p_line_changes (PO_LINES_REC_TYPE)
REM 2. p_shipment_changes(PO_SHIPMENTS_REC_TYPE)
REM 3. p_distribution_changes (PO_DISTRIBUTIONS_REC_TYPE)

REM These parameters are the objects of line, shipment and distribution respectively.

REM 2. PO_LINES_REC_TYPE:

REM This object represents line in a PO. It can be created using line_id of a line.

REM e.g.
REM l_line PO_LINES_REC_TYPE;
REM l_line.create_object(p_po_line_id => <line_id>);

REM create_object method takes following optional parameters which represent change in line.

REM 1. Unit price
REM 2. Vendor product number
REM 3. Quantity
REM 4. Start Date
REM 5. Expiration date
REM 6. Amount
REM 7. Unit of measure
REM 8. Secondary Quantity
REM 9. Secondary UOM

REM 3. PO_SHIPMENTS_REC_TYPE:

REM This object represents shipment in a PO. It can be created using line_location_id of a line.

REM e.g.
REM l_ship PO_SHIPMENTS_REC_TYPE;
REM l_ship.create_object(p_po_line_location_id => <line_location_id>);

REM create_object method takes following optional parameters which represent change in line.

REM 1. Quantity
REM 2. promised date
REM 3. Price override
REM 4. Parent line location id -- To copy data from other existing shipment.
REM 5. Need by date
REM 6. Ship to location id
REM 7. Sales order update date
REM 8. Amount
REM 9. Unit of measure
REM 10. Secondary quantity
REM 11. Secondary UOM

REM 4. PO_DISTRIBUTIONS_REC_TYPE:

REM This object represents distribution in a PO. It can be created using distribution_id of a line.

REM e.g.
REM l_dist PO_DISTRIBUTIONS_REC_TYPE;
REM l_dist.create_object(p_po_distribution_id => <distribution_id>);

REM create_object method takes following optional parameters which represent change in line.

REM 1. Quantity ordered
REM 2. Parent distribution id
REM 3. Amount ordered

REM 4. Unit of measure

REM Simple Update 

DECLARE
   l_result                  NUMBER;
   l_progress                NUMBER;
   l_errors                  po_api_errors_rec_type;
   l_chg                     po_changes_rec_type;
   l_shipment_changes        po_shipments_rec_type;
   l_return_status           VARCHAR2(30);
BEGIN
   --to set org context in a R12 env
   mo_global.set_policy_context('S'
                              , &org_id);

   -- Create an Object for Changes
   -- po_changes_rec_type constructor takes either po_header_id OR      --- po_release_id to construct the object. In case of purchase 
   ---order pass po_release_id as NULL.

   l_chg                                                    :=
      po_changes_rec_type.create_object(
                           p_po_header_id  => &header_id
                         , p_po_release_id => &release_id);

   -- Add a Line Changes to the Change Object
   l_chg.line_changes.add_change(
                           p_po_line_id      => &po_line_id
                         , p_quantity        => &value);

   -- Add Shipment Changes to the Change Object
   l_chg.shipment_changes.add_change(
                   p_po_line_location_id => &line_location_id
                 , p_quantity         => &value);

   -- Add Distribution Level Changes
   l_chg.distribution_changes.add_change(
    p_po_distribution_id    => &po_distribution_id
  , p_quantity_ordered      => &value);

   -- Now call the change api to execute the above changes
   po_document_update_grp.update_document(
      p_api_version    => 1.0 -- pass this as 1.0
    , p_init_msg_list  => fnd_api.g_true -- pass this as TRUE
    , x_return_status  => l_return_status -- returns the result of 
 ---execution
    , p_changes        => l_chg -- changes obj. contains all changes    --- intended to be made on document
    , p_run_submission_checks  => fnd_api.g_false -- set to TRUE if --- want to perform submission check
    , p_launch_approvals_flag  => fnd_api.g_fals
-- set to TRUE if want to launch approval work flow after making the --changes
    , p_buyer_id       => NULL -- buyer id
    , p_update_source  => NULL -- name of a source who is calling     --- this API. In case of manual call can be passed as NULL
    , p_override_date  => NULL
    , x_api_errors     => l_errors -- list of errors if any occurred -- in execution
    , p_mass_update_releases   => NULL);

   IF l_errors IS NOT NULL
   THEN
      FOR i IN 1 .. l_errors.MESSAGE_TEXT.COUNT
      LOOP
         DBMS_OUTPUT.put_line(   ' Error is '
                              || l_errors.MESSAGE_TEXT( i)
                              || ' - name'
                              || l_errors.message_name( i));
      END LOOP;
   END IF;

   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line(   'error :'
                           || SQLERRM);
END;


REM Update and Approve 
DECLARE
   l_result                                     NUMBER;
   l_progress                                   NUMBER;
   l_errors              po_api_errors_rec_type;
   l_chg                 po_changes_rec_type;
   l_shipment_changes    po_shipments_rec_type;
   l_return_status       VARCHAR2(30);
BEGIN
   fnd_global.apps_initialize(user_id                                   => &user_id
                            , -- This function execution is required before launching the approval work flow.
                             resp_id                                    => &responsibility_id
                            , resp_appl_id                              => &resp_application_id);

   --to set org context in a R12 env
   mo_global.set_policy_context('S'
                              , &org_id);

   -- Create an Object for Changes
   -- po_changes_rec_type constructor takes either po_header_id OR      -- po_release_id to construct the object.
   -- In case of purchase order pass po_release_id as NULL.

   l_chg                                                    :=
      po_changes_rec_type.create_object(
    p_po_header_id            => &header_id
  , p_po_release_id           => &release_id);

   -- Add a Line Changes to the Change Object
   l_chg.line_changes.add_change(
      p_po_line_id   => &po_line_id
    , p_quantity     => &value);

   -- Add Shipment Changes to the Change Object
   l_chg.shipment_changes.add_change(
    p_po_line_location_id    => &line_location_id
  , p_quantity               => &value);

   -- Add Distribution Level Changes
   l_chg.distribution_changes.add_change(
       p_po_distribution_id    => &po_distribution_id
     , p_quantity_ordered      => &value);

   -- Now call the change api to execute the above changes
   po_document_update_grp.update_document(
  p_api_version    => 1.0 -- pass this as 1.0
p_init_msg_list  => fnd_api.g_true -- pass this as TRUE
x_return_status  => l_return_status -- returns the result of 
  --- execution
p_changes        => l_chg -- changes obj. contains all changes 
  ---intended to be made on document
p_run_submission_checks => fnd_api.g_false  -- set to TRUE if want --- to perform submission check
, p_launch_approvals_flag  => fnd_api.g_true -- set to TRUE if want   ---to launch approval work flow after making the changes
, p_buyer_id               => NULL -- buyer id
p_update_source          => NULL -- name of a source who is 
  ---calling this API. In case of manual call can be passed as NULL
, p_override_date          => NULL
, x_api_errors             => l_errors -- list of errors if any 
   --- occurred in execution
, p_mass_update_releases   => NULL);


   IF l_errors IS NOT NULL
   THEN
      FOR i IN 1 .. l_errors.MESSAGE_TEXT.COUNT
      LOOP
         DBMS_OUTPUT.put_line(   ' Error is '
                              || l_errors.MESSAGE_TEXT( i)
                              || ' - name'
                              || l_errors.message_name( i));
      END LOOP;
   END IF;

   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line(   'error :'
                           || SQLERRM);
END;

How to use Change PO API group package PO_DOCUMENT_UPDATE_GRP to make multiple changes to PO at once

REM Refer to metalink Doc ID 1406047.1 for more details
REM Note:  This API supports only set of attributes at 
REM line/shipment/distribution level as listed above with 
REM Approval option.
REM Any other PO attributes  in Type PO_CHANGES_REC_TYPE then listed REM above are  reserved for Internal References/Usage and not
REM supported via this API.
REM 1. PO_CHANGES_REC_TYPE:
REM This object represents header of PO. It can be created by supplying header_id of a PO.
REM e.g.
REM l_header PO_CHANGES_REC_TYPE;
REM l_header.create_object(p_po-header_id => <po_header_id>, p_po_release_id => <release_id>);

REM In case of a PO, release_id should be supplied and release_id will be null. Release_id is used while creating object of release header.

REM Optional parameters to create object are:
REM 1. p_line_changes (PO_LINES_REC_TYPE)
REM 2. p_shipment_changes(PO_SHIPMENTS_REC_TYPE)
REM 3. p_distribution_changes (PO_DISTRIBUTIONS_REC_TYPE)

REM These parameters are the objects of line, shipment and distribution respectively.

REM 2. PO_LINES_REC_TYPE:

REM This object represents line in a PO. It can be created using line_id of a line.

REM e.g.
REM l_line PO_LINES_REC_TYPE;
REM l_line.create_object(p_po_line_id => <line_id>);

REM create_object method takes following optional parameters which represent change in line.

REM 1. Unit price
REM 2. Vendor product number
REM 3. Quantity
REM 4. Start Date
REM 5. Expiration date
REM 6. Amount
REM 7. Unit of measure
REM 8. Secondary Quantity
REM 9. Secondary UOM

REM 3. PO_SHIPMENTS_REC_TYPE:

REM This object represents shipment in a PO. It can be created using line_location_id of a line.

REM e.g.
REM l_ship PO_SHIPMENTS_REC_TYPE;
REM l_ship.create_object(p_po_line_location_id => <line_location_id>);

REM create_object method takes following optional parameters which represent change in line.

REM 1. Quantity
REM 2. promised date
REM 3. Price override
REM 4. Parent line location id -- To copy data from other existing shipment.
REM 5. Need by date
REM 6. Ship to location id
REM 7. Sales order update date
REM 8. Amount
REM 9. Unit of measure
REM 10. Secondary quantity
REM 11. Secondary UOM

REM 4. PO_DISTRIBUTIONS_REC_TYPE:

REM This object represents distribution in a PO. It can be created using distribution_id of a line.

REM e.g.
REM l_dist PO_DISTRIBUTIONS_REC_TYPE;
REM l_dist.create_object(p_po_distribution_id => <distribution_id>);

REM create_object method takes following optional parameters which represent change in line.

REM 1. Quantity ordered
REM 2. Parent distribution id
REM 3. Amount ordered

REM 4. Unit of measure

REM Simple Update 

DECLARE
   l_result                  NUMBER;
   l_progress                NUMBER;
   l_errors                  po_api_errors_rec_type;
   l_chg                     po_changes_rec_type;
   l_shipment_changes        po_shipments_rec_type;
   l_return_status           VARCHAR2(30);
BEGIN
   --to set org context in a R12 env
   mo_global.set_policy_context('S'
                              , &org_id);

   -- Create an Object for Changes
   -- po_changes_rec_type constructor takes either po_header_id OR      --- po_release_id to construct the object. In case of purchase 
   ---order pass po_release_id as NULL.

   l_chg                                                    :=
      po_changes_rec_type.create_object(
                           p_po_header_id  => &header_id
                         , p_po_release_id => &release_id);

   -- Add a Line Changes to the Change Object
   l_chg.line_changes.add_change(
                           p_po_line_id      => &po_line_id
                         , p_quantity        => &value);

   -- Add Shipment Changes to the Change Object
   l_chg.shipment_changes.add_change(
                   p_po_line_location_id => &line_location_id
                 , p_quantity         => &value);

   -- Add Distribution Level Changes
   l_chg.distribution_changes.add_change(
    p_po_distribution_id    => &po_distribution_id
  , p_quantity_ordered      => &value);

   -- Now call the change api to execute the above changes
   po_document_update_grp.update_document(
      p_api_version    => 1.0 -- pass this as 1.0
    , p_init_msg_list  => fnd_api.g_true -- pass this as TRUE
    , x_return_status  => l_return_status -- returns the result of 
 ---execution
    , p_changes        => l_chg -- changes obj. contains all changes    --- intended to be made on document
    , p_run_submission_checks  => fnd_api.g_false -- set to TRUE if --- want to perform submission check
    , p_launch_approvals_flag  => fnd_api.g_fals
-- set to TRUE if want to launch approval work flow after making the --changes
    , p_buyer_id       => NULL -- buyer id
    , p_update_source  => NULL -- name of a source who is calling     --- this API. In case of manual call can be passed as NULL
    , p_override_date  => NULL
    , x_api_errors     => l_errors -- list of errors if any occurred -- in execution
    , p_mass_update_releases   => NULL);

   IF l_errors IS NOT NULL
   THEN
      FOR i IN 1 .. l_errors.MESSAGE_TEXT.COUNT
      LOOP
         DBMS_OUTPUT.put_line(   ' Error is '
                              || l_errors.MESSAGE_TEXT( i)
                              || ' - name'
                              || l_errors.message_name( i));
      END LOOP;
   END IF;

   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line(   'error :'
                           || SQLERRM);
END;


REM Update and Approve 
DECLARE
   l_result                                     NUMBER;
   l_progress                                   NUMBER;
   l_errors              po_api_errors_rec_type;
   l_chg                 po_changes_rec_type;
   l_shipment_changes    po_shipments_rec_type;
   l_return_status       VARCHAR2(30);
BEGIN
   fnd_global.apps_initialize(user_id                                   => &user_id
                            , -- This function execution is required before launching the approval work flow.
                             resp_id                                    => &responsibility_id
                            , resp_appl_id                              => &resp_application_id);

   --to set org context in a R12 env
   mo_global.set_policy_context('S'
                              , &org_id);

   -- Create an Object for Changes
   -- po_changes_rec_type constructor takes either po_header_id OR      -- po_release_id to construct the object.
   -- In case of purchase order pass po_release_id as NULL.

   l_chg                                                    :=
      po_changes_rec_type.create_object(
    p_po_header_id            => &header_id
  , p_po_release_id           => &release_id);

   -- Add a Line Changes to the Change Object
   l_chg.line_changes.add_change(
      p_po_line_id   => &po_line_id
    , p_quantity     => &value);

   -- Add Shipment Changes to the Change Object
   l_chg.shipment_changes.add_change(
    p_po_line_location_id    => &line_location_id
  , p_quantity               => &value);

   -- Add Distribution Level Changes
   l_chg.distribution_changes.add_change(
       p_po_distribution_id    => &po_distribution_id
     , p_quantity_ordered      => &value);

   -- Now call the change api to execute the above changes
   po_document_update_grp.update_document(
  p_api_version    => 1.0 -- pass this as 1.0
p_init_msg_list  => fnd_api.g_true -- pass this as TRUE
x_return_status  => l_return_status -- returns the result of 
  --- execution
p_changes        => l_chg -- changes obj. contains all changes 
  ---intended to be made on document
p_run_submission_checks => fnd_api.g_false  -- set to TRUE if want --- to perform submission check
, p_launch_approvals_flag  => fnd_api.g_true -- set to TRUE if want   ---to launch approval work flow after making the changes
, p_buyer_id               => NULL -- buyer id
p_update_source          => NULL -- name of a source who is 
  ---calling this API. In case of manual call can be passed as NULL
, p_override_date          => NULL
, x_api_errors             => l_errors -- list of errors if any 
   --- occurred in execution
, p_mass_update_releases   => NULL);


   IF l_errors IS NOT NULL
   THEN
      FOR i IN 1 .. l_errors.MESSAGE_TEXT.COUNT
      LOOP
         DBMS_OUTPUT.put_line(   ' Error is '
                              || l_errors.MESSAGE_TEXT( i)
                              || ' - name'
                              || l_errors.message_name( i));
      END LOOP;
   END IF;

   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line(   'error :'
                           || SQLERRM);
END;