PTD Balance from GL Journal Totals in Oracle R12

Period-to-date (PTD) activity for a GL account can be calculated directly from journal lines instead of GL_BALANCES: sum ACCOUNTED_DR - ACCOUNTED_CR from GL_JE_LINES for the ledger, period and account. The query below does that grouped by entered currency, period and account combination, and shows the ledger (accounted) currency, which is useful to check a balance or to break it down by currency.

SQL: PTD from journal lines

--balances by journal totals
SELECT 
  gjh.currency_code entered_currency, 
  gjh.period_name, 
  gcc.concatenated_segments, 
  sum(
    nvl(gjl.accounted_dr, 0) - nvl(gjl.accounted_cr, 0)
  ) ptd, 
  (
    SELECT 
      gl.currency_code 
    FROM 
      apps.gl_ledgers gl 
    WHERE 
      gl.ledger_id = gjh.ledger_id
  ) accounted_cuurency 
FROM 
  apps.gl_je_headers gjh, 
  apps.gl_je_lines gjl, 
  apps.gl_code_combinations_kfv gcc, 
  apps.gl_je_sources_tl gjst 
WHERE 
  1 = 1 -- AND gjh.default_effective_date BETWEEN '01-OCT-2022' AND '06-MAR-2023'
  AND gjh.je_source = gjst.je_source_name --AND gjst.user_je_source_name IN ( 'manual', 'spreadsheet' )
  AND gjst.language = 'US' 
  AND gjh.je_header_id = gjl.je_header_id 
  AND gjl.code_combination_id = gcc.code_combination_id 
  AND gcc.segment1 = '001' 
  AND gcc.segment3 = '120120' 
  AND gjh.ledger_id = 1000
  and gjh.period_name = 'DEC-22' 
group by 
  gjh.currency_code, 
  gjh.period_name, 
  gjh.ledger_id, 
  gcc.concatenated_segments 
ORDER BY 
  1, 
  2;

Notes

  • Change ledger_id, the segment values and period_name.
  • Accounted amounts are always in the ledger currency, so totals across entered currencies can be added up.
  • Add AND gjh.status = 'P' to include only posted journals, and AND gjh.actual_flag = 'A' to exclude budget and encumbrance journals.
  • To compare with GL_BALANCES, see the reconciliation query below.

How do I calculate PTD from GL journals?

Sum NVL(ACCOUNTED_DR,0) – NVL(ACCOUNTED_CR,0) from GL_JE_LINES joined to GL_JE_HEADERS for the period, ledger and account, using posted actual journals only.

Related queries

Related posts: Upload your own post and refer it anywhere anytime:

Leave a Comment