Monday, April 3, 2017

Script for scheduling a concurrent program from backend

 DECLARE
l_responsibility_id       NUMBER;
l_application_id           NUMBER;
l_user_id                     NUMBER;
l_request_id                NUMBER;
l_boolean                    BOOLEAN;
l_temp_name              xdo_templates_tl.template_name%type;
l_temp_app                 xdo_templates_b.application_short_name%type;
l_temp_code               xdo_templates_b.template_code%type;
l_temp_lang                xdo_templates_b.default_language%type;
l_temp_terr                 xdo_templates_b.default_territory%type;
l_out_form                  xdo_templates_b.template_type_code%type;
l_start_date                DATE;
l_end_date                 DATE;
l_repeat_interval        NUMBER;
l_repeat_unit              VARCHAR2(15);
l_repeat_start_time    DATE;
l_repeat_end_time     DATE;
l_repeat_type             VARCHAR2(6);
l_rel_application         VARCHAR2(10);
l_class_name              fnd_conc_release_classes.release_class_name%type;
l_release_class_id      fnd_conc_release_classes.release_class_id%type;
BEGIN
  --
  SELECT fr.responsibility_id,
         frx.application_id
     INTO l_responsibility_id ,l_application_id
     FROM fnd_responsibility frx,
          fnd_responsibility_tl fr
    WHERE fr.responsibility_id = frx.responsibility_id
  AND frx.responsibility_id = &responsibility_id;
  --
   SELECT user_id
   INTO l_user_id
   FROM fnd_user WHERE user_name = 'VINAYAKIREDDY';

  --To set environment context.
  apps.fnd_global.apps_initialize (l_user_id,l_responsibility_id,l_application_id);

  dbms_output.put_line ('fnd_global.apps_initialize  ' || l_user_id||','||l_responsibility_id||','||l_application_id );

  -- Calling RTF
  select  application_short_name
            ,template_code
            ,default_language
            ,default_territory
            ,default_output_type
            ,template_name
       into
          l_temp_app
          ,l_temp_code
          ,l_temp_lang
          ,l_temp_terr
          ,l_out_form
          ,l_temp_name
    from  xdo_templates_vl
    where template_code = 'XXTEST';
  
        
 -- Get the start and end date for scheduling concurrent programs
      begin
        dbms_session.set_nls('nls_date_format', '''DD-MON-YY hh24:mi:ss''');
    
        select to_char(p_repeat_start_time, 'DD-MON-YY hh24:mi:ss') start_date,
               to_char(p_repeat_end_time, 'DD-MON-YY hh24:mi:ss') end_date
        into l_start_date, l_end_date
        from dual;
      end;

  --Calling BI report layout
  l_boolean := fnd_request.add_layout ( template_appl_name  => l_temp_app
                                        ,template_code      => l_temp_code
                                        ,template_language  => l_temp_lang
                                        ,template_territory => l_temp_terr
                                        ,output_format      => l_out_form
                                       );
                                                                         
 --Periodically submitting concurrent programs
 if l_repeat_start_time is not null then
 l_boolean :=fnd_submit.set_repeat_options (
                                    --repeat_time     => '14:10:00'--to_char(sysdate,'hh24:mi:ss'),
                                    repeat_interval   => 2 
                                    ,repeat_unit      => 'MINUTES'
                                    ,repeat_type      => 'END'
                                    ,repeat_end_time  => l_repeat_end_time --'01-APR-17 12:55:00'
                                        );
  end if;

  --Specific day concurrent program submission
  if l_release_class_id is not null then                
   l_boolean :=fnd_submit.set_rel_class_options (
                                    application       => l_rel_application
                                    ,class_name       => l_class_name
                                        );
  end if;

  --Submitting Concurrent Request
  l_request_id := fnd_request.submit_request (
                                              application   => 'XXGGL',
                                              program       => 'XXTEST',
                                              description   => null,
                                              start_time    => l_repeat_start_time, 
                                              sub_request   => FALSE,
                                              Argument1     => 'pass your parameters'
                                              );
  --
  COMMIT;
  --
  IF l_request_id = 0
  THEN
     dbms_output.put_line ('Concurrent request failed to submit');
  ELSE
     dbms_output.put_line('Successfully Submitted the Concurrent Request');
  END IF;
  --
EXCEPTION
WHEN OTHERS THEN
  dbms_output.put_line('Error While Submitting Concurrent Request '||TO_CHAR(SQLCODE)||'-'||sqlerrm);
END;
/

--Scheduling Request set

DECLARE
l_responsibility_id       NUMBER;
l_application_id           NUMBER;
l_user_id                     NUMBER;
l_request_id                NUMBER;
l_boolean                    BOOLEAN;
l_temp_name              xdo_templates_tl.template_name%type;
l_temp_app                 xdo_templates_b.application_short_name%type;
l_temp_code               xdo_templates_b.template_code%type;
l_temp_lang                xdo_templates_b.default_language%type;
l_temp_terr                 xdo_templates_b.default_territory%type;
l_out_form                  xdo_templates_b.template_type_code%type;
l_start_date                DATE;
l_end_date                 DATE;
l_repeat_interval        NUMBER;
l_repeat_unit              VARCHAR2(15);
l_repeat_start_time    DATE;
l_repeat_end_time     DATE;
l_repeat_type             VARCHAR2(6);
l_rel_application         VARCHAR2(10);
l_class_name              fnd_conc_release_classes.release_class_name%type;
l_release_class_id      fnd_conc_release_classes.release_class_id%type;
BEGIN
  --
  SELECT fr.responsibility_id,
         frx.application_id
     INTO l_responsibility_id ,l_application_id
     FROM fnd_responsibility frx,
          fnd_responsibility_tl fr
    WHERE fr.responsibility_id = frx.responsibility_id
  AND frx.responsibility_id = &responsibility_id;
  --
   SELECT user_id
   INTO l_user_id
   FROM fnd_user WHERE user_name = 'VINAYAKIREDDY';
 
  --To set environment context.
  apps.fnd_global.apps_initialize (l_user_id,l_responsibility_id,l_application_id);
 
  dbms_output.put_line ('fnd_global.apps_initialize  ' || l_user_id||','||l_responsibility_id||','||l_application_id );
 
 
   -- Get the start and end date for scheduling concurrent programs
      begin
        dbms_session.set_nls('nls_date_format', '''DD-MON-YY hh24:mi:ss''');
     
        select to_char(p_repeat_start_time, 'DD-MON-YY hh24:mi:ss') start_date,
               to_char(p_repeat_end_time, 'DD-MON-YY hh24:mi:ss') end_date
        into l_start_date, l_end_date
        from dual;
      end;
     
     
    --Periodically concurrent program submission
      if l_start_date is not null then
        v_result :=  fnd_submit.set_repeat_options (
                                    --repeat_time     => '14:10:00'--to_char(sysdate,'hh24:mi:ss'),
                                    repeat_interval   => p_repeat_interval   
                                    ,repeat_unit      => p_repeat_unit
                                    ,repeat_type      => p_repeat_type
                                    ,repeat_end_time  => l_end_date
                                        );
      end if;
      
      --Specific day concurrent program submission            
      if p_verify_steps.release_class_id is not null then                 
        v_result :=fnd_submit.set_rel_class_options (
                                    application       => p_rel_application
                                    ,class_name       => p_class_name
                                        );
      end if;

    -- Submit Request Set
    v_result := fnd_submit.set_request_set(l_resp_app, p_concurrent_program_name);
   
    if (v_result != true) then
      v_tf := 'False';
    else
      v_tf := 'True';
    end if;

 -- Calling RTF
  select  application_short_name
            ,template_code
            ,default_language
            ,default_territory
            ,default_output_type
            ,template_name
       into
          l_temp_app
          ,l_temp_code
          ,l_temp_lang
          ,l_temp_terr
          ,l_out_form
          ,l_temp_name
    from  xdo_templates_vl
    where template_code = 'XXTEST';
   
 -- reset variables
  l_temp_app := null;
  l_temp_code := null;
  l_temp_lang := null;
  l_temp_terr := null;
  l_out_form := null;
  l_temp_name := null;
 
    BEGIN
    -- Get template details;
    SELECT  application_short_name
            ,template_code
            ,default_language
            ,default_territory
            ,Default_Output_Type
            ,template_name
       INTO
          l_temp_app
          ,l_temp_code
          ,l_temp_lang
          ,l_temp_terr
          ,l_out_form
          ,l_temp_name
    FROM  xdo_templates_vl
    WHERE template_code = p_program_name;
    EXCEPTION
       WHEN no_data_found THEN
          sqlerr := substr(sqlerrm, 1, 900);
          write_log (gcv_package || '.' || 'Missing Tempalte info' || l_funct, sqlerr, p_instance_name, p_exec_batch_id);
        WHEN others THEN
           sqlerr := substr(sqlerrm, 1, 900);
           write_log (gcv_package || '.' || 'Layout' || l_funct, sqlerr, p_instance_name, p_exec_batch_id);
    END;

        write_log ( gcv_package || '.' || l_funct
               ,p_verify_steps.verification_application_name || ': ' || 'Template_code = ' || l_temp_code
               ,p_instance_name
               ,p_exec_batch_id);
 
 --Assign layout for RTF reports to print the output

 
  --Submitting Concurrent Request
  v_result := fnd_submit.submit_program ( l_resp_app
                                           ,'XXTEST'
                                           ,p_.stage_name
                                           ,'pass your parameters'
                                              );
  --
  COMMIT;
  --
  IF l_request_id = 0
  THEN
     dbms_output.put_line ('Concurrent request failed to submit');
  ELSE
     dbms_output.put_line('Successfully Submitted the Concurrent Request');
  END IF;
  --
EXCEPTION
WHEN OTHERS THEN
  dbms_output.put_line('Error While Submitting Concurrent Request '||TO_CHAR(SQLCODE)||'-'||sqlerrm);
END;
/

1 comment:

  1. what are the values of fnd_submit.set_rel_class_options derived from, how are the pulled?

    ReplyDelete