Thursday, 11 April 2019

Query to find REVENUE Account from XLA in Oracle Apps R12

SELECT revenue_account, 
       SUM(amt) 
FROM   (SELECT SUM (Nvl (xel.accounted_dr, 0) - Nvl (xel.accounted_cr, 0)) amt, 
               GCC.segment1 
               ||'.' 
               ||GCC.segment2 
               ||'.' 
               ||GCC.segment3 
               ||'.' 
               ||GCC.segment4 
               ||'.' 
               ||GCC.segment5 
                       Revenue_Account 
        FROM   apps.xla_transaction_entities_upg xte, 
               apps.xla_events xe, 
               apps.xla_ae_headers xeh, 
               apps.xla_ae_lines xel, 
               gl_code_combinations gcc 
        WHERE  1 = 1 
               AND xte.application_id = xe.application_id 
               AND xe.application_id = xeh.application_id 
               AND xeh.application_id = xel.application_id 
               AND xeh.application_id IN ( 200, 222 ) --200 : Payables, 222 : Receivables  
               AND xte.entity_code IN ( 'TRANSACTIONS', 'AP_INVOICES' ) 
               AND xel.accounting_class_code IN ( 'REVENUE', 'UNEARNED_REVENUE', 'ITEM EXPENSE') 
               AND xte.entity_id = xe.entity_id 
               AND xeh.event_id = xe.event_id 
               AND xeh.ledger_id = xte.ledger_id 
               AND xeh.ae_header_id = xel.ae_header_id 
               AND gcc.code_combination_id = xel.code_combination_id 
               --   and xeh.AE_HEADER_ID = 123809740  
               AND xte.ledger_id = Nvl(:P_SOB_ID, xte.ledger_id) 
               AND xeh.accounting_date BETWEEN To_date(:P_FACCOUNTING_DATE'RRRR/MM/DD HH24:MI:SS') AND To_date(:P_TACCOOUNTING_DATE, 'RRRR/MM/DD HH24:MI:SS') 
               AND GCC.segment1 
                   ||'.' 
                   ||GCC.segment2 
                   ||'.' 
                   ||GCC.segment3 
                   ||'.' 
                   ||GCC.segment4 
                   ||'.' 
                   ||GCC.segment5 = '1561.R111001.999999.99999.999' 
        GROUP  BY GCC.segment1 
                  ||'.' 
                  ||GCC.segment2 
                  ||'.' 
                  ||GCC.segment3 
                  ||'.' 
                  ||GCC.segment4 
                  ||'.' 
                  ||GCC.segment5 
        UNION ALL 
        SELECT SUM(Nvl(gjl.accounted_dr, 0) - Nvl(gjl.accounted_cr, 0)) AMT, 
               GCC.segment1 
               ||'.' 
               ||GCC.segment2 
               ||'.' 
               ||GCC.segment3 
               ||'.' 
               ||GCC.segment4 
               ||'.' 
               ||GCC.segment5 
               Revenue_Account 
        FROM   gl_je_headers gjh, 
               gl_je_lines gjl, 
               gl_code_combinations gcc, 
               gl.gl_periods glp 
        WHERE  gjh.je_header_id = gjl.je_header_id 
               AND gjh.ledger_id = Nvl(:P_SOB_ID, gjh.ledger_id) 
               AND gjl.code_combination_id = gcc.code_combination_id 
               AND gjh.period_name = glp.period_name 
               AND gjh.je_source = 'Manual' 
               AND gjh.je_category = 'Adjustment' 
               AND gjh.status = 'P' 
               AND gjh.period_name = 'Mar-19' 
               AND GCC.segment1 
                   ||'.' 
                   ||GCC.segment2 
                   ||'.' 
                   ||GCC.segment3 
                   ||'.' 
                   ||GCC.segment4 
                   ||'.' 
                   ||GCC.segment5 = '1561.R111001.999999.99999.999' 
        GROUP  BY GCC.segment1 
                  ||'.' 
                  ||GCC.segment2 
                  ||'.' 
                  ||GCC.segment3 
                  ||'.' 
                  ||GCC.segment4 
                  ||'.' 
                  ||GCC.segment5) 
GROUP  BY revenue_account; 

No comments:

Post a Comment