Thursday, 6 December 2018

Calling Bursting Program from Reports

FND_REQUEST.SUBMIT_REQUEST is an API used to submit a concurrent program in ORACLE Applications.

Parameters:

Application : Short name of the application associated with the concurrent request to be submitted. 
Program - Short name of the concurrent program (not the executable) for which the request should be submitted. 
Description - Description of the request that is displayed in the Concurrent Requests form (Optional.) 
Start_time - Time at which the request should start running, formatted as HH24:MI or HH24:MI:SS (Optional.) 
Sub_request - Set to TRUE if the request is submitted from another request and should be treated as a sub-request. 
Argument1...100 - Arguments for the concurrent request; up to 100 arguments are permitted. If submitted from Oracle Forms, you must specify all 100 arguments.

Example 1: Submission of XML Bursting Program

FUNCTION AfterReport RETURN BOOLEAN
IS
     v_sub_req                      NUMBER;
     v_cp_description               VARCHAR2(100);
     c_cp_request_id            CONSTANT  NUMBER         := :P_CONC_REQUEST_ID;
BEGIN
         BEGIN
               SELECT fcp.user_concurrent_program_name
                 INTO v_cp_description
                 FROM FND_CONCURRENT_REQUESTS    fcr,
                      FND_CONCURRENT_PROGRAMS_VL fcp
             WHERE  fcr.concurrent_program_id = fcp.concurrent_program_id
               AND fcr.request_id             = c_cp_request_id;
         EXCEPTION WHEN OTHERS THEN
              v_cp_description := NULL;
         END;

         BEGIN
              v_sub_req :=  fnd_request.submit_request(
                                                        application => 'XDO',             -- application
                                                        program => 'XDOBURSTREP',     -- Program
                                                        description=>  v_cp_description,  -- description
                                                        argument1=>'N' ,
                                                        argument2=> c_cp_request_id,   -- argument1
                                                        argument3=> 'Yes'                -- argument2
                                                      );
              COMMIT;
              IF v_sub_req <= 0
              THEN
                   SRW.MESSAGE('206','Failed to submit Bursting XML Publisher Request for Request ID = '|| c_cp_request_id);
              ELSE
                   SRW.MESSAGE('207','Submitted Bursting XML Publisher Request Request ID = ' || v_sub_req);
              END IF;
         EXCEPTION
            WHEN OTHERS THEN
                 RAISE SRW.PROGRAM_ABORT;
         END;

  SRW.USER_EXIT('FND SRWEXIT');
  RETURN (TRUE);

EXCEPTION
      WHEN SRW.USER_EXIT_FAILURE
      THEN
         SRW.MESSAGE (1, 'Failed in AFTER REPORT TRIGGER');
         RETURN (FALSE);
      WHEN OTHERS
      THEN
         SRW.MESSAGE (1000, 'Failed in When Others' || SQLERRM);
END;


Example 2: Submission of Standard Order Import Program

SET SERVEROUTPUT ON;
DECLARE
     v_request_id                        NUMBER           DEFAULT 0;
   
    --Order Import Parameters
    p_operating_unit                     VARCHAR2(20)    := NULL;
    p_order_source                       VARCHAR2(20)    := 'XYZ';
    p_orig_sys_document_ref              VARCHAR2(20)    := NULL;
    p_operation_code                     VARCHAR2(20)    := NULL;
    p_validate_only                      VARCHAR2(20)    := 'N';
    p_debug_level                        VARCHAR2(20)    := '1';
    p_num_instances                      VARCHAR2(20)    := '4';
    p_sold_to_org_id                     VARCHAR2(20)    := NULL;
    p_sold_to_org                        VARCHAR2(20)    := NULL;
    p_change_sequence                    VARCHAR2(20)    := NULL;
    p_perf_param                         VARCHAR2(20)    := 'Y';
    p_rtrim_data                         VARCHAR2(20)    := 'N';
    p_pro_ord_with_null_flag             VARCHAR2(20)    := 'Y';
    p_default_org_id                     VARCHAR2(20)    := '83';
    p_validate_desc_flex                 VARCHAR2(20)    := 'N';

    -- End of Parameters -----

    v_context varchar2(100);


    FUNCTION set_context( i_user_name    IN  VARCHAR2
                         ,i_resp_name    IN  VARCHAR2
                         ,i_org_id       IN  NUMBER)
    RETURN VARCHAR2
    IS
        /* Inorder to reduce the content of the post I moved the implementation part of this function to another post and it is available here */
    END set_context;


BEGIN
      -- Setting the context ----
      v_context := set_context('&V_USER_NAME','&V_RESPONSIBILITY',82);
      IF v_context = 'F'
      THEN
        DBMS_OUTPUT.PUT_LINE('Error while setting the context');      
      END IF;

      DBMS_OUTPUT.PUT_LINE('Submit Order Import Concurrent Program');

      v_request_id:=  FND_REQUEST.SUBMIT_REQUEST (
               application  =>  'ONT'
              ,program      =>  'OEOIMP'
              ,description  =>  'Order Import'
              ,start_time   =>  SYSDATE
              ,sub_request  =>  NULL
              ,argument1    =>  p_operating_unit
              ,argument2    =>  p_order_source
              ,argument3    =>  p_orig_sys_document_ref
              ,argument4    =>  p_operation_code
              ,argument5    =>  p_validate_only
              ,argument6    =>  p_debug_level
              ,argument7    =>  p_num_instances
              ,argument8    =>  p_sold_to_org_id
              ,argument9    =>  p_sold_to_org
              ,argument10   =>  p_change_sequence
              ,argument11   =>  p_perf_param
              ,argument12   =>  p_rtrim_data
              ,argument13   =>  p_pro_ord_with_null_flag
              ,argument14   =>  p_default_org_id
              ,argument15   =>  p_validate_desc_flex
             );

       COMMIT;

       DBMS_OUTPUT.PUT_LINE('Request_id: '||v_request_id);

EXCEPTION WHEN OTHERS THEN       
       DBMS_OUTPUT.PUT_LINE(SQLCODE||' Error :'||SQLERRM);


END;