Oracle EBS GL_BALANCES Query with Code Combinations and Segment Descriptions
This generator writes the General Ledger queries Oracle E-Business Suite R12 developers keep rewriting: a trial balance from GL_BALANCES for one ledger and period, account descriptions from the FND value sets, and a PL/SQL lookup that turns a concatenated account string into a CODE_COMBINATION_ID.
Fill in
Ledger currency for normal reporting.
A actual, B budget (also filter budget_version_id), E encumbrance (also filter encumbrance_type_id).
IS NULL for ledger currency totals; Y for translated balances. Check with the diagnostic query.
Query 1: trial balance for one period
SELECT cc.concatenated_segments,
cc.SEGMENT3 AS account,
cc.account_type,
SUM(NVL(b.begin_balance_dr, 0) - NVL(b.begin_balance_cr, 0)) AS begin_balance,
SUM(NVL(b.period_net_dr, 0) - NVL(b.period_net_cr, 0)) AS period_activity,
SUM(NVL(b.begin_balance_dr, 0) - NVL(b.begin_balance_cr, 0)
+ NVL(b.period_net_dr, 0) - NVL(b.period_net_cr, 0)) AS ending_balance
FROM gl_balances b
JOIN gl_ledgers l
ON l.ledger_id = b.ledger_id
JOIN gl_code_combinations_kfv cc
ON cc.code_combination_id = b.code_combination_id
WHERE l.name = 'Vision Operations (USA)'
AND b.period_name = 'SEP-26'
AND b.currency_code = 'USD'
AND b.actual_flag = 'A'
AND b.translated_flag IS NULL
AND b.template_id IS NULL -- exclude summary account balances
AND cc.SEGMENT3 BETWEEN '1000' AND '9999'
-- For actual_flag B add: AND b.budget_version_id = <GL_BUDGET_VERSIONS.BUDGET_VERSION_ID>
-- For actual_flag E add: AND b.encumbrance_type_id = <encumbrance type id>
GROUP BY cc.concatenated_segments, cc.SEGMENT3, cc.account_type
ORDER BY cc.concatenated_segments;
-- Diagnostic: which currency / translated_flag combinations exist for this ledger and period
SELECT b.currency_code, b.translated_flag, b.actual_flag, COUNT(*) AS row_count
FROM gl_balances b
JOIN gl_ledgers l ON l.ledger_id = b.ledger_id
WHERE l.name = 'Vision Operations (USA)'
AND b.period_name = 'SEP-26'
GROUP BY b.currency_code, b.translated_flag, b.actual_flag
ORDER BY 1, 2, 3;Query 2: account segment descriptions
-- Join method: works for independent value sets
SELECT cc.code_combination_id,
cc.concatenated_segments,
cc.SEGMENT3 AS account,
fv.description AS account_description
FROM gl_code_combinations_kfv cc
JOIN gl_ledgers l
ON l.chart_of_accounts_id = cc.chart_of_accounts_id
JOIN fnd_id_flex_segments s
ON s.application_id = 101
AND s.id_flex_code = 'GL#'
AND s.id_flex_num = cc.chart_of_accounts_id
AND s.application_column_name = 'SEGMENT3'
JOIN fnd_flex_values_vl fv
ON fv.flex_value_set_id = s.flex_value_set_id
AND fv.flex_value = cc.SEGMENT3
WHERE l.name = 'Vision Operations (USA)'
AND cc.SEGMENT3 BETWEEN '1000' AND '9999'
AND cc.summary_flag = 'N'
ORDER BY cc.concatenated_segments;
-- Function method (verify the segment numbering on your chart of accounts):
-- SELECT cc.concatenated_segments,
-- GL_FLEXFIELDS_PKG.GET_DESCRIPTION_SQL(cc.chart_of_accounts_id, 3, cc.SEGMENT3) AS account_description
-- FROM gl_code_combinations_kfv cc ...Block 3: find or create a CCID from a concatenated string
SET SERVEROUTPUT ON
DECLARE
l_coa_id NUMBER;
l_ccid NUMBER;
BEGIN
SELECT chart_of_accounts_id INTO l_coa_id
FROM gl_ledgers
WHERE name = 'Vision Operations (USA)';
-- Creates the combination if it does not exist and Dynamic Inserts is allowed
l_ccid := FND_FLEX_EXT.GET_CCID('SQLGL', 'GL#', l_coa_id,
TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS'),
'01-000-1110-0000-000');
IF l_ccid = 0 THEN
DBMS_OUTPUT.PUT_LINE('Invalid combination: ' || FND_FLEX_EXT.GET_MESSAGE);
ELSE
DBMS_OUTPUT.PUT_LINE('CCID: ' || l_ccid);
END IF;
END;
/
-- Look up only, never create:
SELECT cc.code_combination_id, cc.enabled_flag, cc.start_date_active, cc.end_date_active
FROM gl_code_combinations_kfv cc
JOIN gl_ledgers l ON l.chart_of_accounts_id = cc.chart_of_accounts_id
WHERE l.name = 'Vision Operations (USA)'
AND cc.concatenated_segments = '01-000-1110-0000-000';Verify: the TRANSLATED_FLAG values present for your ledger with the diagnostic query, the account segment column in FND_ID_FLEX_SEGMENTS, the segment delimiter used in the concatenated string, and that GL_FLEXFIELDS_PKG.GET_DESCRIPTION_SQL exists on your release before uncommenting it. Dependent value sets need the parent value in the description join.
Get your GL reporting queries checked
Send your chart of accounts structure and ledger setup; we check the balance queries against your segments and currencies.
Optional. The tool and every export work without this. No spam.
How to use it
Enter the ledger name as it appears in GL_LEDGERS.NAME, the period name (for example SEP-26), the currency and the balance type. Pick the translated flag filter: ledger currency totals use translated_flag IS NULL; run the diagnostic query first if your ledger has foreign currency or translated balances. Enter the column that holds the natural account in your chart (find it in FND_ID_FLEX_SEGMENTS for id_flex_code GL#) and an account range. Query 1 gives begin, activity and ending balance per combination; Query 2 adds descriptions; Block 3 resolves a string to a CCID.
- Ledger name: SELECT name, ledger_id, currency_code FROM gl_ledgers
- Account column: FND_ID_FLEX_SEGMENTS.APPLICATION_COLUMN_NAME
- Period names: GL_PERIOD_STATUSES for application 101 and your ledger
How GL_BALANCES stores balances
GL_BALANCES has one row per ledger, code combination, currency, period, balance type and, for budgets and encumbrances, budget version or encumbrance type. BEGIN_BALANCE_DR and BEGIN_BALANCE_CR are the opening balance for the period, PERIOD_NET_DR and PERIOD_NET_CR the posted activity in the period. Ending balance is begin plus net. Balances are updated only by posting, so unposted journals are not here. Income and expense accounts reset their begin balance at the first period of a new year after the year-end roll, which is why year-to-date P&L is begin plus activity in any period of the year. TEMPLATE_ID is populated on summary account balances, so excluding it avoids double counting.
Worked example
For Vision Operations (USA), SEP-26, USD actuals with translated_flag IS NULL and accounts 1000 to 9999, Query 1 returns one row per combination with begin, activity and ending balance. Summing ending_balance across all accounts should give zero for a balanced ledger; a non-zero total points to a missing filter, usually including both entered and translated rows or a summary template. Query 2 adds the account description from FND_FLEX_VALUES_VL, joined through the value set attached to the account segment of your chart. Block 3 with 01-000-1110-0000-000 prints the CCID, or the flexfield error if the combination is invalid or cross-validation rules reject it.
Gotchas
The segment column is chart specific: SEGMENT3 is common but not universal. Period names follow the accounting calendar, so check GL_PERIODS rather than guessing the format. FND_FLEX_EXT.GET_CCID creates a combination when Dynamic Inserts is enabled, which is a write to GL_CODE_COMBINATIONS; use the lookup-only query when you only need to check. Budget balances need BUDGET_VERSION_ID or you add every budget together. For multiple ledgers sharing a chart, always filter by ledger, not just chart_of_accounts_id.
Frequently Asked Questions
How do I join GL_BALANCES and GL_LEDGERS in R12?
Join on GL_BALANCES.LEDGER_ID = GL_LEDGERS.LEDGER_ID (in 11i the column was SET_OF_BOOKS_ID against GL_SETS_OF_BOOKS). Filter by ledger name, period name, currency code, actual_flag and the translated flag, then join GL_CODE_COMBINATIONS_KFV on CODE_COMBINATION_ID for the account string.
How do I get the GL account with its description?
Find the value set of the account segment in FND_ID_FLEX_SEGMENTS (application_id 101, id_flex_code GL#, id_flex_num = chart_of_accounts_id, application_column_name = your segment), then join FND_FLEX_VALUES_VL on flex_value_set_id and flex_value = the segment value. Query 2 does exactly this.
What is GL_CODE_COMBINATIONS_KFV?
A view over GL_CODE_COMBINATIONS that adds CONCATENATED_SEGMENTS, the full account string with your chart's delimiter, built from SEGMENT1 to SEGMENT30. Use it when you need the readable account; use the base table with individual segment columns when filtering performance matters.
Why does my trial balance not net to zero?
Typical causes: summary account balances included (filter template_id IS NULL), translated and entered rows mixed (filter translated_flag), more than one ledger, budget rows without a version filter, or an account range that cuts off part of the ledger. Run the diagnostic query to see which combinations exist.
If you want finance staff to ask for a trial balance or an account movement in plain English and get the GL answer from your own EBS instance on your servers, we can set that up.
Related Tools
Oracle EBS GL Open Journals and Period Status SQL Generator
Enter a ledger and period and get queries to see period status, unposted journals, stuck import rows and subledger entries not yet in the GL.
OracleOracle EBS GL Journal Import Worksheet
Prepare journal lines in the shape of GL_INTERFACE, check debits against credits per row set, and export to Excel or CSV before loading.
OracleOracle EBS Finance Tables Reference (GL, AP, AR, FA)
Lookup of the base tables behind General Ledger, Payables, Receivables, Fixed Assets, Subledger Accounting and Purchasing, with the columns you join on.
OracleOracle EBS AR Aging Buckets SQL Generator
Generates a 7-bucket receivables aging query by customer account and an open-item detail query from AR_PAYMENT_SCHEDULES_ALL, with your bucket boundaries and as-of date.
More Oracle tools
See all- Oracle EBS Inventory Tables Reference
- Oracle EBS WIP Tables Reference
- Oracle EBS Cycle Count Workload Calculator
- Oracle EBS Discrete Manufacturing Go-Live Checklist
- Oracle EBS Inventory Accuracy Readiness Assessment
- Oracle EBS Concurrent Request Phase and Status Reference
- Oracle EBS Responsibility Design Worksheet
- Oracle EBS GL Period Close Checklist
- Oracle EBS AP Invoice Interface Template
Keep exploring
Free tools
- Oracle EBS GL Open Journals and Period Status SQL GeneratorEnter a ledger and period and get queries to see period status, unposted journals, stuck import rows and subledger entries not yet in the GL.
- Oracle EBS GL Period Close ChecklistA month-end close sequence for Oracle General Ledger and the subledgers that feed it, with critical steps marked.
- Oracle EBS GL_INTERFACE Journal Import Error Codes ReferenceDecode every common Journal Import Execution Report error code, see which GL_INTERFACE columns cause it and how to fix it, for EBS R12.
ERP fixes and how-tos
- Oracle EBS Month-End Close Checklist: GL, AP, ARStep-by-step Oracle EBS month-end close order: finish sub-ledger transactions, close AP and AR periods, transfer to GL, reconcile, then close GL. Menu paths included.
- Data Conversion in Oracle EBS: Interface Tables, Open Interfaces and ReconciliationHow data conversion works in Oracle EBS: extract, stage, validate, load through interface tables and APIs, then reconcile. Practical steps and common failures.
- GL period will not close: unposted or unaccounted journal batchesFix Oracle EBS General Ledger period close failures caused by unposted or unaccounted journal batches - run the Unposted Journals report and the Account Analysis with Payables/Receivables drill-down first.
Runs with your ERP
- Esker Order Management and Oracle E-Business SuiteHow Esker captures customer POs from email, fax and PDF and creates sales orders in Oracle EBS: integration, data flows, setup, pitfalls and a private AI layer.
- Cloud Inventory (DSI) with Oracle E-Business Suite: Mobile Barcode InventoryCloud Inventory, formerly DSI, adds offline mobile barcode inventory to Oracle E-Business Suite and JD Edwards. Data flows, setup steps, pitfalls and AI notes.
- BarTender and Oracle E-Business Suite: Label Printing from OracleHow BarTender prints labels from Oracle EBS using Oracle XML print requests and Integration Builder: methods, data flows, setup steps, pitfalls and AI help.
AI on your ERP
- AI for Oracle E-Business Suite, Without Leaving On-PremHosting Oracle EBS 12.2 on-prem or in a private cloud? Add a private LLM over concurrent programs, interface tables and AP/PO data without moving to Fusion.
- AI for Oracle EBS in Industrial Manufacturing: WIP, MRP, and BOM Questions Answered DirectlyAI for Oracle E-Business Suite in industrial manufacturing: WIP jobs, BOMs, MRP, inventory and purchasing answered in plain English, private and read-only.
Integrations
- How to use ChatGPT with Oracle E-Business SuiteUsing ChatGPT with Oracle E-Business Suite: export vs live access, custom GPT actions over ISG REST, enterprise data controls and when to keep data on-prem.
- How to connect Claude to Oracle E-Business SuiteConnect Claude to Oracle E-Business Suite via MCP, the Anthropic API, AWS Bedrock or Vertex, and know when an on-prem open-weight model is the better fit.