http://generalledger-gl.blogspot.com/2016/10/query-for-period-closure.html
PLSQL query to find Open/Close Periods
To See Periods Status (Open/Closed & Future)
select NAME, LEDGER_ID, period_name, APPLICATION_NAME, status
from (select ff.NAME NAME,
kk.LEDGER_ID,
kk.PERIOD_NAME,
jj.APPLICATION_NAME,
DECODE(kk.CLOSING_STATUS,
'O',
'Open',
'C',
'Closed',
'F',
'Future',
'N',
'Never') STATUS
from GL_PERIOD_STATUSES_V kk, fnd_application_vl jj, gl_ledgers ff
where 1 = 1
and jj.APPLICATION_ID = kk.APPLICATION_ID
and ff.LEDGER_ID = kk.LEDGER_ID
--and kk.PERIOD_NAME = 'SEP-16'
--and kk.LEDGER_ID=2021
/* and jj.APPLICATION_NAME in ('Payables', 'General Ledger', 'Receivables')*/ -- Open for your Modules
and kk.CLOSING_STATUS != 'N'
--and kk.CLOSING_STATUS = 'O'
--order by kk.PERIOD_NAME
)
union
(SELECT /*(select sob.NAME from gl_sets_of_books sob where sob.SET_OF_BOOKS_ID = fbc.SET_OF_BOOKS_ID)*/
fbc.BOOK_TYPE_CODE NAME,
fbc.set_of_books_id LEDGER_ID,
fdp.period_name,
'Assets' APPLICATION_NAME,
DECODE(fdp.period_close_date, NULL, 'Open', 'Closed') status
FROM fa_book_controls fbc, fa_deprn_periods fdp
--WHERE fbc.set_of_books_id = NVL('&sob',set_of_books_id)
WHERE fbc.book_type_code = fdp.book_type_code
-- and fdp.period_close_date is null
and fbc.DATE_INEFFECTIVE is null
--AND UPPER (fdp.period_name) = UPPER ('&period_name')
--order by fdp.PERIOD_NAME
)
order by period_name
PLSQL query to find Open/Close Periods
To See Periods Status (Open/Closed & Future)
select NAME, LEDGER_ID, period_name, APPLICATION_NAME, status
from (select ff.NAME NAME,
kk.LEDGER_ID,
kk.PERIOD_NAME,
jj.APPLICATION_NAME,
DECODE(kk.CLOSING_STATUS,
'O',
'Open',
'C',
'Closed',
'F',
'Future',
'N',
'Never') STATUS
from GL_PERIOD_STATUSES_V kk, fnd_application_vl jj, gl_ledgers ff
where 1 = 1
and jj.APPLICATION_ID = kk.APPLICATION_ID
and ff.LEDGER_ID = kk.LEDGER_ID
--and kk.PERIOD_NAME = 'SEP-16'
--and kk.LEDGER_ID=2021
/* and jj.APPLICATION_NAME in ('Payables', 'General Ledger', 'Receivables')*/ -- Open for your Modules
and kk.CLOSING_STATUS != 'N'
--and kk.CLOSING_STATUS = 'O'
--order by kk.PERIOD_NAME
)
union
(SELECT /*(select sob.NAME from gl_sets_of_books sob where sob.SET_OF_BOOKS_ID = fbc.SET_OF_BOOKS_ID)*/
fbc.BOOK_TYPE_CODE NAME,
fbc.set_of_books_id LEDGER_ID,
fdp.period_name,
'Assets' APPLICATION_NAME,
DECODE(fdp.period_close_date, NULL, 'Open', 'Closed') status
FROM fa_book_controls fbc, fa_deprn_periods fdp
--WHERE fbc.set_of_books_id = NVL('&sob',set_of_books_id)
WHERE fbc.book_type_code = fdp.book_type_code
-- and fdp.period_close_date is null
and fbc.DATE_INEFFECTIVE is null
--AND UPPER (fdp.period_name) = UPPER ('&period_name')
--order by fdp.PERIOD_NAME
)
order by period_name
#############################################################################
To See Open Periods Only
1st Query
select NAME, LEDGER_ID, period_name, APPLICATION_NAME, status
from (select ff.NAME NAME,
kk.LEDGER_ID,
kk.PERIOD_NAME,
jj.APPLICATION_NAME,
DECODE(kk.CLOSING_STATUS,
'O',
'Open',
'C',
'Closed',
'F',
'Future',
'N',
'Never') STATUS
from GL_PERIOD_STATUSES_V kk, fnd_application_vl jj, gl_ledgers ff
where 1 = 1
and jj.APPLICATION_ID = kk.APPLICATION_ID
and ff.LEDGER_ID = kk.LEDGER_ID
--and kk.PERIOD_NAME = 'SEP-16'
--and kk.LEDGER_ID=2021
/* and jj.APPLICATION_NAME in ('Payables', 'General Ledger', 'Receivables')*/ -- Open for your Modules
and kk.CLOSING_STATUS != 'N'
and kk.CLOSING_STATUS = 'O'
--order by kk.PERIOD_NAME
)
union
(SELECT /*(select sob.NAME from gl_sets_of_books sob where sob.SET_OF_BOOKS_ID = fbc.SET_OF_BOOKS_ID)*/
fbc.BOOK_TYPE_CODE NAME,
fbc.set_of_books_id LEDGER_ID,
fdp.period_name,
'Assets' APPLICATION_NAME,
DECODE(fdp.period_close_date, NULL, 'Open', 'Closed') status
FROM fa_book_controls fbc, fa_deprn_periods fdp
--WHERE fbc.set_of_books_id = NVL('&sob',set_of_books_id)
WHERE fbc.book_type_code = fdp.book_type_code
and fdp.period_close_date is null
and fbc.DATE_INEFFECTIVE is null
--AND UPPER (fdp.period_name) = UPPER ('&period_name')
--order by fdp.PERIOD_NAME
)
order by period_name
#############################################################################
2nd Query
SELECT DISTINCT (SELECT sob.NAME
FROM gl_sets_of_books sob
WHERE sob.set_of_books_id = a.set_of_books_id) "SOB_Name",
a.period_name "Period_Name"
-- , a.period_num "Period_Num"
,
a.GL_PERIOD "GL_PERIOD"
-- , b.po_status "PO_Status"
,
c.AP_PERIOD "AP_PERIOD",
d.AR_PERIOD "AR_PERIOD",
e.FA_PERIOD "FA_PERIOD"
FROM (SELECT period_name,
period_num,
DECODE(closing_status, 'O', 'Open', null) GL_PERIOD
/*, 'C', 'Closed'
, 'F', 'Future'
, 'N', 'Never'
,*/
,
set_of_books_id
FROM gl_period_statuses
WHERE application_id = 101
-- and closing_status = 'O'
AND UPPER(period_name) =
NVL(UPPER('&period_name'), UPPER(period_name))
AND set_of_books_id = NVL('&sob', set_of_books_id)) a
/* , (SELECT period_name
, DECODE (closing_status
, 'O', 'Open',null) po_status
\* , 'C', 'Closed'
, 'F', 'Future'
, 'N', 'Never'
,*\
, set_of_books_id
FROM gl_period_statuses
WHERE application_id = 201
AND UPPER (period_name) = NVL(UPPER ('&period_name'),UPPER (period_name))
AND set_of_books_id = NVL('&sob',set_of_books_id)
) b*/
,
(SELECT period_name,
DECODE(closing_status, 'O', 'Open', null) AP_PERIOD
/*, 'C', 'Closed'
, 'F', 'Future'
, 'N', 'Never'
,*/
,
set_of_books_id
FROM gl_period_statuses
WHERE application_id = 200
-- and closing_status = 'O'
AND UPPER(period_name) =
NVL(UPPER('&period_name'), UPPER(period_name))
AND set_of_books_id = NVL('&sob', set_of_books_id)) c,
(SELECT period_name,
DECODE(closing_status, 'O', 'Open', null) AR_PERIOD
/*, 'C', 'Closed'
, 'F', 'Future'
, 'N', 'Never'
,*/
,
set_of_books_id
FROM gl_period_statuses
WHERE application_id = 222
-- and closing_status = 'O'
AND UPPER(period_name) =
NVL(UPPER('&period_name'), UPPER(period_name))
AND set_of_books_id = NVL('&sob', set_of_books_id)) d,
(SELECT fdp.period_name,
DECODE(fdp.period_close_date, NULL, 'Open', null) FA_PERIOD,
fbc.set_of_books_id
FROM fa_book_controls fbc, fa_deprn_periods fdp
WHERE fbc.set_of_books_id = NVL('&sob', fbc.set_of_books_id)
AND fbc.book_type_code = fdp.book_type_code
and fbc.DATE_INEFFECTIVE is null
--and DECODE (fdp.period_close_date, NULL, 'Open', 'Closed') = 'Open'
AND UPPER(fdp.period_name) =
NVL(UPPER('&period_name'), UPPER(fdp.period_name))) e
WHERE 1 = 1
-- AND a.period_name = b.period_name(+)
AND a.period_name = c.period_name(+)
AND a.period_name = d.period_name(+)
AND a.period_name = e.period_name(+)
-- AND a.set_of_books_id = b.set_of_books_id(+)
AND a.set_of_books_id = c.set_of_books_id(+)
AND a.set_of_books_id = d.set_of_books_id(+)
AND a.set_of_books_id = e.set_of_books_id(+)
and (GL_PERIOD = 'Open' or AR_PERIOD = 'Open' or AP_PERIOD = 'Open' or
FA_PERIOD = 'Open'
/*or PO_STATUS = 'Open'*/
)
ORDER BY 2;
To See Open Periods Only
1st Query
select NAME, LEDGER_ID, period_name, APPLICATION_NAME, status
from (select ff.NAME NAME,
kk.LEDGER_ID,
kk.PERIOD_NAME,
jj.APPLICATION_NAME,
DECODE(kk.CLOSING_STATUS,
'O',
'Open',
'C',
'Closed',
'F',
'Future',
'N',
'Never') STATUS
from GL_PERIOD_STATUSES_V kk, fnd_application_vl jj, gl_ledgers ff
where 1 = 1
and jj.APPLICATION_ID = kk.APPLICATION_ID
and ff.LEDGER_ID = kk.LEDGER_ID
--and kk.PERIOD_NAME = 'SEP-16'
--and kk.LEDGER_ID=2021
/* and jj.APPLICATION_NAME in ('Payables', 'General Ledger', 'Receivables')*/ -- Open for your Modules
and kk.CLOSING_STATUS != 'N'
and kk.CLOSING_STATUS = 'O'
--order by kk.PERIOD_NAME
)
union
(SELECT /*(select sob.NAME from gl_sets_of_books sob where sob.SET_OF_BOOKS_ID = fbc.SET_OF_BOOKS_ID)*/
fbc.BOOK_TYPE_CODE NAME,
fbc.set_of_books_id LEDGER_ID,
fdp.period_name,
'Assets' APPLICATION_NAME,
DECODE(fdp.period_close_date, NULL, 'Open', 'Closed') status
FROM fa_book_controls fbc, fa_deprn_periods fdp
--WHERE fbc.set_of_books_id = NVL('&sob',set_of_books_id)
WHERE fbc.book_type_code = fdp.book_type_code
and fdp.period_close_date is null
and fbc.DATE_INEFFECTIVE is null
--AND UPPER (fdp.period_name) = UPPER ('&period_name')
--order by fdp.PERIOD_NAME
)
order by period_name
SELECT DISTINCT (SELECT sob.NAME
FROM gl_sets_of_books sob
WHERE sob.set_of_books_id = a.set_of_books_id) "SOB_Name",
a.period_name "Period_Name"
-- , a.period_num "Period_Num"
,
a.GL_PERIOD "GL_PERIOD"
-- , b.po_status "PO_Status"
,
c.AP_PERIOD "AP_PERIOD",
d.AR_PERIOD "AR_PERIOD",
e.FA_PERIOD "FA_PERIOD"
FROM (SELECT period_name,
period_num,
DECODE(closing_status, 'O', 'Open', null) GL_PERIOD
/*, 'C', 'Closed'
, 'F', 'Future'
, 'N', 'Never'
,*/
,
set_of_books_id
FROM gl_period_statuses
WHERE application_id = 101
-- and closing_status = 'O'
AND UPPER(period_name) =
NVL(UPPER('&period_name'), UPPER(period_name))
AND set_of_books_id = NVL('&sob', set_of_books_id)) a
/* , (SELECT period_name
, DECODE (closing_status
, 'O', 'Open',null) po_status
\* , 'C', 'Closed'
, 'F', 'Future'
, 'N', 'Never'
,*\
, set_of_books_id
FROM gl_period_statuses
WHERE application_id = 201
AND UPPER (period_name) = NVL(UPPER ('&period_name'),UPPER (period_name))
AND set_of_books_id = NVL('&sob',set_of_books_id)
) b*/
,
(SELECT period_name,
DECODE(closing_status, 'O', 'Open', null) AP_PERIOD
/*, 'C', 'Closed'
, 'F', 'Future'
, 'N', 'Never'
,*/
,
set_of_books_id
FROM gl_period_statuses
WHERE application_id = 200
-- and closing_status = 'O'
AND UPPER(period_name) =
NVL(UPPER('&period_name'), UPPER(period_name))
AND set_of_books_id = NVL('&sob', set_of_books_id)) c,
(SELECT period_name,
DECODE(closing_status, 'O', 'Open', null) AR_PERIOD
/*, 'C', 'Closed'
, 'F', 'Future'
, 'N', 'Never'
,*/
,
set_of_books_id
FROM gl_period_statuses
WHERE application_id = 222
-- and closing_status = 'O'
AND UPPER(period_name) =
NVL(UPPER('&period_name'), UPPER(period_name))
AND set_of_books_id = NVL('&sob', set_of_books_id)) d,
(SELECT fdp.period_name,
DECODE(fdp.period_close_date, NULL, 'Open', null) FA_PERIOD,
fbc.set_of_books_id
FROM fa_book_controls fbc, fa_deprn_periods fdp
WHERE fbc.set_of_books_id = NVL('&sob', fbc.set_of_books_id)
AND fbc.book_type_code = fdp.book_type_code
and fbc.DATE_INEFFECTIVE is null
--and DECODE (fdp.period_close_date, NULL, 'Open', 'Closed') = 'Open'
AND UPPER(fdp.period_name) =
NVL(UPPER('&period_name'), UPPER(fdp.period_name))) e
WHERE 1 = 1
-- AND a.period_name = b.period_name(+)
AND a.period_name = c.period_name(+)
AND a.period_name = d.period_name(+)
AND a.period_name = e.period_name(+)
-- AND a.set_of_books_id = b.set_of_books_id(+)
AND a.set_of_books_id = c.set_of_books_id(+)
AND a.set_of_books_id = d.set_of_books_id(+)
AND a.set_of_books_id = e.set_of_books_id(+)
and (GL_PERIOD = 'Open' or AR_PERIOD = 'Open' or AP_PERIOD = 'Open' or
FA_PERIOD = 'Open'
/*or PO_STATUS = 'Open'*/
)
ORDER BY 2;
No comments:
Post a Comment