Thursday, 11 April 2019

Query to find COGS (Cost of Goods Sold) Account from XLA in Oracle Apps R12

SELECT cogs_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 
               Cogs_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.entity_code IN ( 'MTL_ACCOUNTING_EVENTS', 'TRANSACTIONS', 
                                        'AP_INVOICES' 
                                      ) 
               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 ( 707, 222, 200 ) --200 : Payables, 222 : Receivables, 707 : Cost Management  
               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 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.segment2 = 'E110001' 
               --Cost of Goods Sold / COGS Account Code 
               --and xeh.AE_HEADER_ID = 123801886 
               AND GCC.segment1 
                   ||'.' 
                   ||GCC.segment2 
                   ||'.' 
                   ||GCC.segment3 
                   ||'.' 
                   ||GCC.segment4 
                   ||'.' 
                   ||GCC.segment5 IN ( 
                   '1111.E110001.999999.99999.999', 
                   '1151.E110001.999999.99999.999', 
                                     '1202.E110001.999999.99999.999', 
                                     '1207.E110001.999999.99999.999', 
                   '1208.E110001.999999.99999.999', 
                   '1209.E110001.999999.99999.999', 
                                     '1152.E110001.999999.99999.999', 
                                     '1153.E110001.999999.99999.999' ) 
        GROUP  BY GCC.segment1 
                  ||'.' 
                  ||GCC.segment2 
                  ||'.' 
                  ||GCC.segment3 
                  ||'.' 
                  ||GCC.segment4 
                  ||'.' 
                  ||GCC.segment5) 
GROUP  BY cogs_account; 

No comments:

Post a Comment