How to get GL Balance R12
General Ledger balances can be arrived for accounting segments based on code combination identifier.
Opening, closing, period debits and credits can be obtained based on accounting periods.
Code Snippet
FUNCTION gl_balances( p_type IN VARCHAR2
, p_gl_from_period IN VARCHAR2
, p_gl_to_period IN VARCHAR2
, p_cc_id IN NUMBER ) RETURN NUMBER;
FUNCTION gl_balances( p_type IN VARCHAR2
, p_gl_from_period IN VARCHAR2
, p_gl_to_period IN VARCHAR2 --3.0
, p_cc_id IN NUMBER) RETURN NUMBER IS
l_balance NUMBER;
TYPE balance_rec_type IS RECORD
( begin_balance_dr NUMBER
, begin_balance_cr NUMBER
, begin_balances NUMBER
, period_net_dr NUMBER
, period_net_cr NUMBER
, period_balances NUMBER
, closing_balances NUMBER );
l_balance_rec_type balance_rec_type;
BEGIN
SELECT SUM(begin_balance_dr) begin_balance_dr
,SUM(begin_balance_cr) begin_balance_cr
, SUM(begin_balances) begin_balances
, SUM(period_net_dr) period_net_dr
, SUM(period_net_cr) period_net_cr
, SUM(period_balances) period_balances
,SUM (closing_balances) closing_balances
INTO l_balance_rec_type
FROM (
SELECT begin_balance_dr
, begin_balance_cr
, begin_balance_dr - begin_balance_cr begin_balances
, period_net_dr
, period_net_cr
, period_net_dr - period_net_cr period_balances
, ( begin_balance_dr-begin_balance_cr) + (period_net_dr-period_net_cr) closing_balances
FROM gl_balances
WHERE to_date('01-'||period_name) BETWEEN to_date('01-'||p_gl_from_period) AND to_date('30-'||p_gl_to_period)
AND code_combination_id = p_cc_id
AND actual_flag = 'A'
AND currency_code = 'XXX'
AND period_name NOT LIKE 'Adj%'
AND LENGTH(period_name) = 6);
SELECT NVL (
( (SELECT begin_balance_dr FROM gl_balances WHERE period_name = p_gl_from_period AND code_combination_id = p_cc_id AND actual_flag = 'A' and currency_code ='XXX')
-
(SELECT begin_balance_cr FROM gl_balances WHERE period_name = p_gl_from_period AND code_combination_id = p_cc_id AND actual_flag = 'A' and currency_code ='XXX') ), 0) begin_balances
INTO l_balance_rec_type.begin_balances
FROM DUAL;
SELECT l_balance_rec_type.begin_balances + (l_balance_rec_type.period_net_dr - l_balance_rec_type.period_net_cr)
INTO l_balance_rec_type.closing_balances
FROM DUAL;
IF p_type = 'OB' THEN
RETURN l_balance_rec_type.begin_balances;
ELSIF p_type = 'PDR' THEN
RETURN l_balance_rec_type.period_net_dr;
ELSIF p_type = 'PCR' THEN
RETURN l_balance_rec_type.period_net_cr;
ELSIF p_type = 'CB' THEN
RETURN l_balance_rec_type.closing_balances;
END IF;
EXCEPTION
WHEN OTHERS THEN
RETURN 0;
END gl_balances;
Comments
Post a Comment