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;
/