Showing posts with label Queries. Show all posts
Showing posts with label Queries. Show all posts

Wednesday, 2 September 2020

One Sample to write Standardized and awesome Code for oracle Apps EBS


We all write packages with different structures and formats based on the different guidelines provided by the organizations or projects.


I have tried to formalize one way of writing, which can be edited for your standard. 

Hope this helps you to give you a little booster to start your code


CREATE OR REPLACE PACKAGE XXCUST_AP_PKG IS
------------------------------------------------------------------------------------
-- * PL/SQL PACKAGE    :  XXCUST_AP_PKG                                              
-- * DATE              :  01-Jan-2020                                                
-- * PURPOSE           :  <Program Information - Project Request Reference>          
--*  XXAPCUSTPROG      :  <Concurrent Programs  Information 
------------------------------------------------------------------------------------
-- * VERSION     DD-MON-YYYY     PERSON             CHANGES MADE                  
-- * ----------  -------------   -------------      --------------------------------
-- * 1.0         01-Jan-2020     Developer          Initiated                       
-- ---------------------------------------------------------------------------------


    ---------------------------------------------------------------------------------
    --XXAPCUSTPROG--<Program Name>
    --PROCEDURE main Parameters
    --p_inv_create_dt_from varchar2 --FND_DATE_STANDARD -- Invoice Creation Date From
    --p_inv_create_dt_to   varchar2 --FND_DATE_STANDARD -- Invoice Creation Date To
    --p_org_id             number   --XX_ORG_ID_VS      -- Organization Name
    --p_vendor_ID          varchar2 --XXAP_VENDOR_NAME  -- Vendor Name
    --p_vendoe_site_code   varchar2 --XXAP_AP_VENDOR_SITE  -- Vendor Site Code
    --p_invoice_num        varchar2 --XXAP Invoice Numbers -- Invoice Number
    --p_print_log          varchar2 DEFAULT 'Y'
    ---------------------------------------------------------------------------------
    PROCEDURE main ( p_err_buff       out varchar2
                   , p_err_code       out varchar2
                   , p_inv_create_dt_from varchar2
                   , p_inv_create_dt_to   varchar2
                   , p_org_id             number  
                   , p_vendor_ID          varchar2
                   , p_vendoe_site_code   varchar2
                   , p_invoice_num        varchar2
                   , p_print_log          varchar2 DEFAULT 'Y'
                   );

END XXCUST_AP_PKG;




CREATE OR REPLACE PACKAGE BODY XXCUST_AP_PKG IS
------------------------------------------------------------------------------------
-- * PL/SQL PACKAGE    :  XXCUST_AP_PKG                                              
-- * DATE              :  01-Jan-2020                                                
-- * PURPOSE           :  <Program Information - Project Request Reference>          
--*  XXAPCUSTPROG      :  <Concurrent Programs  Information 
------------------------------------------------------------------------------------
-- * VERSION     DD-MON-YYYY     PERSON             CHANGES MADE                  
-- * ----------  -------------   -------------      --------------------------------
-- * 1.0         01-Jan-2020     Developer          Initiated                       
-- ---------------------------------------------------------------------------------
 gp_print_log     VARCHAR2(10) := 'Y';
 gp_delimiter     CHAR(1)      := '~';
 ------------------------------------
 procedure write_log(p_str varchar2) IS
 BEGIN
    IF gp_print_log = 'Y'  THEN
       fnd_file.put_line(fnd_file.log,to_char(sysdate,'HH24:MI:SS')||':'||p_str);
       dbms_output.put_line(to_char(sysdate,'HH24:MI:SS')||':'||p_str);
    END IF;   
 end write_log;     

 procedure write_msg(p_str varchar2) IS
 BEGIN
    fnd_file.put_line(fnd_file.log,to_char(sysdate,'HH24:MI:SS')||':'||p_str);
 end write_msg;    

 procedure write_out(p_str varchar2) IS
 BEGIN
    fnd_file.put_line(fnd_file.output,p_str);
 end write_out;   
------------------------------------------------------------------------------------
--XXAPCUSTPROG--<Program Name>
--Parameters
--p_inv_create_dt_from varchar2 --FND_DATE_STANDARD    -- Invoice Creation Date From
--p_inv_create_dt_to   varchar2 --FND_DATE_STANDARD    -- Invoice Creation Date To
--p_org_id             number   --XX_ORG_ID_VS         -- Organization Name
--p_vendor_ID          varchar2 --XXAP_VENDOR_NAME     -- Vendor Name
--p_vendoe_site_code   varchar2 --XXAP_AP_VENDOR_SITE  -- Vendor Site Code
--p_invoice_num        varchar2 --XXAP Invoice Numbers -- Invoice Number
--p_print_log          varchar2 DEFAULT 'Y'
------------------------------------------------------------------------------------
 PROCEDURE main ( p_err_buff       out varchar2
                , p_err_code       out varchar2
                , p_inv_create_dt_from varchar2 
                , p_inv_create_dt_to   varchar2 
                , p_org_id             number   
                , p_vendor_ID          varchar2 
                , p_vendoe_site_code   varchar2 
                , p_invoice_num        varchar2 
                , p_print_log          varchar2 DEFAULT 'Y'
                ) IS
  CURSOR cur_inv is 
  SELECT '1' invoice_num from DUAL;
  --
  l_inv_rec_count     NUMBER := 0;
  l_inv_rec_psd_count NUMBER := 0;
  l_inv_rec_err_count NUMBER := 0;
  l_interface_line_id NUMBER;
  l_line_status       BOOLEAN;
  l_err_msg           VARCHAR2(4000);
 BEGIN
    write_msg('Program Starts');
    gp_print_log := p_print_log;

    FOR rec_inv in cur_inv LOOP
    BEGIN
      l_inv_rec_count := l_inv_rec_count + 1;
      write_out( l_inv_rec_count || '::' || rec_inv.invoice_num);
      l_interface_line_id:=XXAP_CUST_TBL_S.nextval;
  --
      insert into XXAP_CUST_TBL(interface_line_id,status) 
  values (l_interface_line_id, 'NEW');
      l_inv_rec_psd_count := l_inv_rec_psd_count + 1;          
      --
    EXCEPTION WHEN OTHERS THEN
      l_inv_rec_err_count := l_inv_rec_err_count + 1;
      write_out( l_inv_rec_count || '::' || rec_inv.invoice_num || ' :: Error');
    END;
    END LOOP;
    write_out('Invoice Total Count ::'||l_inv_rec_count);
    write_out('Invoice Processed Count ::'||l_inv_rec_psd_count);
    write_out('Invoice Error Count ::'||l_inv_rec_err_count);
    write_msg('Program Ends');  
 EXCEPTION WHEN OTHERS THEN
    write_out('Error ::'||SQLERRM);
    write_out('Invoice Total Count <when error occured>::'||l_inv_rec_count);
    write_out('Invoice Processed Count <when error occured>::'||l_inv_rec_psd_count);
    write_out('Invoice Error Count <when error occured>::'||l_inv_rec_err_count);
write_msg('Error ::'||SQLERRM);
    write_msg('Program Ends with Error');  
 END main;

END XXCUST_AP_PKG;

Thursday, 20 June 2019

1) How to extract 1-10 counting using Oracle SQL - 2) How to select data for more than 1000 using in clause

with dummy(id) as ( select 50 from dual union all select id + 1 from dummy where id < 60)  
select id from dummy
/

SELECT
   * 
FROM
   fnd_user 
WHERE
   (user_id,0) IN ((83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0),(83196,0)


DB2

with dummy(id) as ( select 55 from SYSIBM.SYSDUMMY1 union all select id + 1 from dummy where id < 60)  
select id from dummy

Thursday, 14 March 2013

Query : Concurrent Program Request Status - For Specific Time Duration


  SELECT main_prog.description Module
       , fcr.hold_flag hold
       , fcr.phase_code phase
       , fcr.status_code status
       , fcr.request_id
       , fcr.parent_request_id parent_req_id
       , TRUNC( ( NVL( fcr.actual_completion_date, SYSDATE ) - fcr.actual_start_date ) * 24 * 60, 2 ) time_in_mins
       , fu.user_name
       , fcpl.user_concurrent_program_name conc_program_name
       , frl.responsibility_name
       , fcr.requested_start_date req_start_date
       , TO_CHAR( fcr.actual_start_date, 'DD-MON-YYYY HH:MI AM' ) start_date
       , TO_CHAR( fcr.actual_completion_date, 'DD-MON-YYYY HH:MI AM' ) completion_date
       , TRUNC( fcr.actual_start_date - fcr.requested_start_date, 2 ) kick_off_time
       , fcrs.completion_text
       , fcr.argument_text
       , fcr.printer
       , fcp.concurrent_program_id||'-'||fcp.concurrent_program_name conc_prog_id_code
       , fcp.executable_id ||'-' ||fe.execution_method_code||'-'||fe.executable_name ID_CODE_NAME
       , fe.execution_file_name
       , fl.meaning execution_type
       , fe.execution_file_path
       , fcr.has_sub_request
       , fcr.resubmitted
       , fcr.resubmit_interval
       , fu.description user_full_name      
       , fcr.outfile_name
       , fcr.logfile_name
    FROM apps.fnd_executables fe
       , apps.fnd_concurrent_programs fcp
       , apps.fnd_concurrent_programs_tl fcpl
       , apps.fnd_concurrent_requests fcr
       , apps.fnd_lookups fl
       , apps.fnd_responsibility_tl frl
       , apps.fnd_user fu
       , apps.fnd_conc_req_summary_v fcrs
       , apps.fnd_lookups main_prog
   WHERE     fe.executable_id = fcp.executable_id
         AND fcp.execution_method_code = fe.execution_method_code
         AND fcr.responsibility_application_id = frl.application_id
         AND fcp.concurrent_program_id = fcr.concurrent_program_id
         AND fcpl.concurrent_program_id = fcp.concurrent_program_id                                                          
         AND frl.responsibility_id = fcr.responsibility_id
         AND fu.user_id = fcr.requested_by
         AND fl.lookup_code = fe.execution_method_code
         AND fcrs.concurrent_program_id = fcr.concurrent_program_id
         AND fcrs.request_id = fcr.request_id
         AND fl.lookup_type = 'CP_EXECUTION_METHOD_CODE'
         AND frl.language = 'US'
         AND fcpl.language = 'US'
         AND fcp.concurrent_program_name = main_prog.meaning(+)        
         AND main_prog.lookup_type(+) like 'REPORTERR'                
         --and fu.user_name = 'USER-IF-REQUIRED'        
         --and fcr.argument_text like '%Argument Content%'
         --AND fcpl.user_concurrent_program_name like '%Any Program Name if Any%'
and fcr.actual_start_date <= to_date('08-Mar-2013 09:40:00','DD-MON-YYYY HH24:MI:SS')--To Time
and nvl(fcr.actual_completion_date,sysdate) >= to_date('08-Mar-2013 09:30:00','DD-MON-YYYY HH24:MI:SS') --From Time
ORDER BY fcr.actual_start_date desc,request_id desc

Tuesday, 1 January 2013

Query : GL, AP, AR, FA and PO Period Statuses

--*************************************************************************
--Query for getting GL, AP, AR, FA and PO Period Statuses
 --Pass Period or Ledger ID for selected data; otherwise all statuses will appear as per setup.
--*************************************************************************
  SELECT ( SELECT sob.name
             FROM apps.gl_sets_of_books sob
            WHERE sob.set_of_books_id = a.set_of_books_id )
            "SOB_Name"
       , a.set_of_books_id ledger_id
       , a.period_name "Period_Name"
       , a.period_num "Period_Num"
       , a.gl_status "GL_Status"
       , b.po_status "PO_Status"
       , c.ap_status "AP_Status"
       , d.ar_status "AR_Status"
       , e.fa_status "FA_Status"
       --, f.inv_status "INV_Status"
    FROM (SELECT period_name
               , period_num
               , DECODE( closing_status,  'O', 'Open',  'C', 'Closed',  'F', 'Future',  'N', 'Never',  closing_status ) gl_status
               , set_of_books_id
            FROM gl.gl_period_statuses
           WHERE application_id = 101)a-- AND UPPER( period_name ) = UPPER( :period_name ) )a
       , (SELECT period_name
               , DECODE( closing_status,  'O', 'Open',  'C', 'Closed',  'F', 'Future',  'N', 'Never',  closing_status ) po_status
               , set_of_books_id
            FROM gl.gl_period_statuses
           WHERE application_id = 201)b-- AND UPPER( period_name ) = UPPER( :period_name ))b
       , (SELECT period_name
               , DECODE( closing_status,  'O', 'Open',  'C', 'Closed',  'F', 'Future',  'N', 'Never',  closing_status ) ap_status
               , set_of_books_id
            FROM gl.gl_period_statuses
           WHERE application_id = 200)c-- AND UPPER( period_name ) = UPPER( :period_name ))c
       , (SELECT period_name
               , DECODE( closing_status,  'O', 'Open',  'C', 'Closed',  'F', 'Future',  'N', 'Never',  closing_status ) ar_status
               , set_of_books_id
            FROM gl.gl_period_statuses
           WHERE application_id = 222)d-- AND UPPER( period_name ) = UPPER(:period_name ) )d
       , (SELECT fdp.period_name, DECODE( fdp.period_close_date, NULL, 'Open', 'Closed' ) fa_status, fbc.set_of_books_id
            FROM fa.fa_book_controls fbc, fa.fa_deprn_periods fdp
           WHERE     fbc.book_type_code = fdp.book_type_code
                 --AND UPPER( fdp.period_name ) = UPPER( nvl(:period_name,fdp.period_name) )
                 ) e
       , (SELECT period_name
               , DECODE( closing_status,  'O', 'Open',  'C', 'Closed',  'F', 'Future',  'N', 'Never',  closing_status ) inv_status
               , set_of_books_id
            FROM gl.gl_period_statuses
           WHERE application_id = 401)f-- AND UPPER( period_name ) = UPPER(:period_name ) )d
   WHERE     a.period_name = b.period_name(+)
         AND a.period_name = c.period_name(+)
         AND a.period_name = d.period_name(+)
         AND a.period_name = e.period_name(+)
         AND a.period_name = f.period_name(+)
         AND a.set_of_books_id = b.set_of_books_id(+)
         AND a.set_of_books_id = c.set_of_books_id(+)
         AND a.set_of_books_id = d.set_of_books_id(+)
         AND a.set_of_books_id = e.set_of_books_id(+)
         AND a.set_of_books_id = f.set_of_books_id(+)
         AND a.set_of_books_id = nvl(:p_ledger_id,a.set_of_books_id)
         AND a.period_name = upper(nvl(:period_name,a.period_name))
         AND substr(a.period_name,1,1)||substr(a.period_name,5,2)||substr(a.period_name,2,2) >= 'P01-12'
ORDER BY 1,2, substr(a.period_name,1,1)||substr(a.period_name,5,2)||substr(a.period_name,2,2)

Thursday, 8 November 2012

Query : Profile Options Value at all Levels

SELECT pot.user_profile_option_name "Profile",pot.profile_option_name,
       DECODE (a.profile_option_value, '1', '1 (may be "Yes")',
                                       '2', '2 (may be "No")', a.profile_option_value) "Value",
       DECODE (a.level_id, 10001, 'Site',
                           10002, 'Appl',
                           10003, 'Resp',
                           10004, 'User',
                           10006, 'Org', '????') "Level",
       DECODE (a.level_id, 10002, e.application_name,
                           10003, c.responsibility_name,
                           10004, d.user_name,
                           10006, a.level_value, '-') "Location",a.*
FROM applsys.fnd_application_tl e,
     applsys.fnd_user d,
     applsys.fnd_responsibility_tl c,
     applsys.fnd_profile_option_values a,
     applsys.fnd_profile_options b,
     applsys.fnd_profile_options_tl pot
WHERE    b.profile_option_name like 'XX%D%B%LINK%'
      AND pot.profile_option_name = b.profile_option_name
      AND b.application_id = a.application_id(+)
      AND b.profile_option_id = a.profile_option_id(+)
      AND a.level_value = c.responsibility_id(+)
      AND a.level_value = d.user_id(+)
      AND a.level_value = e.application_id(+)
      AND c.language (+)= 'US'
      AND e.language (+)= 'US'
      AND pot.language (+)= 'US'           
ORDER BY "Profile", "Level", "Location", "Value",5

Query : Value Set Values with Qualifier Details (GL Account)

SELECT fv.flex_value_set_id
     , fv.flex_value_id
     , fv.flex_value
     , fv.compiled_value_attributes
     , SUBSTR( fv.compiled_value_attributes, 1, 1 ) allow_budgeting
     , SUBSTR( fv.compiled_value_attributes, 3, 1 ) allow_posting
     , SUBSTR( fv.compiled_value_attributes, 5, 1 ) account_type
     , SUBSTR( fv.compiled_value_attributes, 7, 1 ) third_party_ac_type
     , SUBSTR( fv.compiled_value_attributes, 9, 1 ) reconcile
  FROM fnd_flex_value_sets fvs, fnd_flex_values fv, fnd_flex_validation_qualifiers ffvq
 WHERE     fv.flex_value_set_id = fvs.flex_value_set_id
       AND ffvq.flex_value_set_id = fv.flex_value_set_id
       AND flex_value_set_name = 'XXGL_GBL_ACCOUNT'
       AND flex_value = '030099'
       AND fv.enabled_flag = 'Y';

Query : To extract Concurrent Program Execution Information

  SELECT fcr.request_id
       , fcr.parent_request_id parent_req_id
       , fcr.hold_flag
       , fcr.phase_code phase
       , fcr.status_code status
       , TRUNC( ( NVL( fcr.actual_completion_date, SYSDATE ) - fcr.actual_start_date ) * 24 * 60, 2 ) time_in_mins
       , TRUNC( fcr.actual_start_date - fcr.requested_start_date, 2 ) kick_off_time
       , fcr.requested_start_date req_start_date
       , TO_CHAR( fcr.actual_start_date, 'DD-MON-YYYY HH:MI AM' ) start_date
       , TO_CHAR( fcr.actual_completion_date, 'DD-MON-YYYY HH:MI AM' ) completion_date
       , fcrs.completion_text
       , fu.user_name
       , fcpl.user_concurrent_program_name conc_program_name
       , frl.responsibility_name
       , fcp.concurrent_program_name conc_short_name
       , fcp.executable_id
       , fe.execution_method_code
       , fe.execution_file_path
       , fe.executable_name
       , fe.execution_file_name
       , fl.meaning execution_type
       , fcr.argument_text
       , fcr.printer
       , fcp.concurrent_program_id
       , fcr.outfile_name
       , fcr.logfile_name
       , fcr.has_sub_request
       , fcr.resubmitted
       , fcr.resubmit_interval
       , fu.description
    FROM apps.fnd_executables fe
       , apps.fnd_concurrent_programs fcp
       , apps.fnd_concurrent_programs_tl fcpl
       , apps.fnd_concurrent_requests fcr
       , apps.fnd_lookups fl
       , apps.fnd_responsibility_tl frl
       , apps.fnd_user fu
       , apps.fnd_conc_req_summary_v fcrs
   WHERE     fe.executable_id = fcp.executable_id
         AND fcp.execution_method_code = fe.execution_method_code
         AND fcr.responsibility_application_id = frl.application_id
         AND fcp.concurrent_program_id = fcr.concurrent_program_id
         AND fcpl.concurrent_program_id = fcp.concurrent_program_id                                                             ----
         AND frl.responsibility_id = fcr.responsibility_id
         AND fu.user_id = fcr.requested_by
         AND fl.lookup_code = fe.execution_method_code
         AND fcrs.concurrent_program_id = fcr.concurrent_program_id
         AND fcrs.request_id = fcr.request_id
         AND fl.lookup_type = 'CP_EXECUTION_METHOD_CODE'
         AND fcpl.user_concurrent_program_name IN ('AR Reconciliation Report')
         AND frl.language = 'US'
         AND fcpl.language = 'US'
ORDER BY fcr.requested_start_date DESC, fcr.request_id DESC