Tuesday 18 August 2015

Query to Link Between AP and GL with XLA tables in R12

SELECT GCC.CODE_COMBINATION_ID,
            GJH.JE_HEADER_ID,
            XDL.AE_HEADER_ID,
            XDL.AE_LINE_NUM,
            XTE.SOURCE_ID_INT_1,
            XTE.APPLICATION_ID,
            XTE.ENTITY_ID,
            GJH.JE_SOURCE,
            GJH.JE_CATEGORY,
            AIA.GL_DATE,
            AP.VENDOR_NAME,
            AP.SEGMENT1 SUPPLIER_NO,
            XDL.EVENT_CLASS_CODE EVENT_CLASS,
            AIA.INVOICE_ID,
           AIDA.INVOICE_DISTRIBUTION_ID,
           AIA.INVOICE_NUM TRANSACTION_NUMBER,
           AIA.INVOICE_DATE,
           INITCAP (GJL.DESCRIPTION) DESCRIPTION,
           GJL.ACCOUNTED_DR DEBIT,
           GJL.ACCOUNTED_CR CREDIT
           --NVL (Jl.Accounted_Dr, 0) –  NVL(Jl.Accounted_Cr, 0) Net_Amount
  FROM GL_JE_HEADERS  GJH,
           GL_JE_LINES GJL,
           GL_CODE_COMBINATIONS GCC,
           GL_IMPORT_REFERENCES GIR,
           XLA.XLA_AE_LINES XAL,
           XLA.XLA_AE_HEADERS XAH,
           XLA.XLA_DISTRIBUTION_LINKS XDL,
           AP_INVOICES_ALL AIA,
           AP_INVOICE_DISTRIBUTIONS_ALL AIDA,
           AP_SUPPLIERS AP,
           XLA_EVENTS XE,
           XLA_TRANSACTION_ENTITIES XTE
WHERE 1=1
    AND GJL.JE_HEADER_ID = GJH.JE_HEADER_ID
    AND GJL.CODE_COMBINATION_ID = GCC.CODE_COMBINATION_ID
    AND GIR.JE_HEADER_ID = GJL.JE_HEADER_ID
    AND GIR.JE_LINE_NUM = GJL.JE_LINE_NUM
    AND XAL.GL_SL_LINK_ID = GIR.GL_SL_LINK_ID
    AND XAL.AE_HEADER_ID = XAH.AE_HEADER_ID
    AND XAL.APPLICATION_ID = XAH.APPLICATION_ID
    AND XAH.APPLICATION_ID = XE.APPLICATION_ID
    AND XAH.EVENT_ID = XE.EVENT_ID
    AND XE.APPLICATION_ID = XTE.APPLICATION_ID(+)
    AND XE.ENTITY_ID = XTE.ENTITY_ID(+)
    AND XDL.AE_HEADER_ID = XAL.AE_HEADER_ID
    AND XDL.AE_LINE_NUM = XAL.AE_LINE_NUM
    AND XDL.APPLIED_TO_SOURCE_ID_NUM_1 = AIA.INVOICE_ID
    AND XDL.SOURCE_DISTRIBUTION_ID_NUM_1 = AIDA.INVOICE_DISTRIBUTION_ID
    AND AIDA.INVOICE_ID = AIA.INVOICE_ID
    AND AIA.VENDOR_ID = AP.VENDOR_ID
    AND AIDA.LINE_TYPE_LOOKUP_CODE = 'ITEM'
    AND AIDA.ACCOUNTING_DATE BETWEEN :STARTDATE AND :ENDDATE
    --AND GCC.CODE_COMBINATION_ID = 6429
ORDER BY AIA.GL_DATE DESC

Query to Link Between AR and GL with XLA tables in R12

SELECT b.NAME batch_name,
              b.description batch_description,
              h.je_category,
              h.je_source,
              h.period_name je_period_name,
              h.NAME journal_name,
              h.status journal_status,
              h.description je_description,
              l.je_line_num line_number
 FROM gl_je_batches b,
             gl_je_headers h,
             gl_je_lines l,
             gl_code_combinations_kfv glcc,
             gl_import_references gir,
             xla_ae_lines xlal,
             xla_ae_headers xlah,
             xla_events xlae,
             xla.xla_transaction_entities xlate,
             ra_customer_trx_all rct
WHERE   b.je_batch_id = h.je_batch_id
     AND   h.je_header_id = l.je_header_id
     AND   xlal.code_combination_id = glcc.code_combination_id
     AND   l.je_header_id = gir.je_header_id
     AND   l.je_line_num = gir.je_line_num
     AND   gir.gl_sl_link_table = xlal.gl_sl_link_table
     AND   gir.gl_sl_link_id = xlal.gl_sl_link_id
     AND   xlal.ae_header_id = xlah.ae_header_id
     AND   xlah.event_id = xlae.event_id
     AND   xlae.entity_id = xlate.entity_id
     AND   xlae.application_id = xlate.application_id
     AND   h.je_source = 'Receivables'
     AND   rct.trx_number = xlate.transaction_number
     AND   xlate.transaction_number ='TRX_NUMBER'