SELECT DISTINCT A.BUSINESS_UNIT, A.BOOK, CASE WHEN A.ACCOUNTING_PERIOD = C.NUMBER_OF_PERIODS THEN A.FISCAL_YEAR + 1 ELSE A.FISCAL_YEAR END , CASE WHEN A.ACCOUNTING_PERIOD = C.NUMBER_OF_PERIODS THEN 1 ELSE A.ACCOUNTING_PERIOD + 1 END FROM PS_BU_BOOK_CLOSE A, PS_SET_CNTRL_REC B , PS_CAL_DEFN_TBL C, PS_BU_BOOK_TBL D WHERE B.SETCNTRLVALUE = A.BUSINESS_UNIT AND B.RECNAME = 'CAL_DEFN_TBL' AND B.SETID = C.SETID AND D.CAL_DEPR_PD = C.CALENDAR_ID AND C.DEPR_CAL_SW = 'Y' AND A.BUSINESS_UNIT = D.BUSINESS_UNIT AND A.BOOK = D.BOOK AND A.FISCAL_YEAR = A.FISCAL_YEAR AND A.FISCAL_YEAR = (SELECT MAX(B.FISCAL_YEAR) FROM PS_BU_BOOK_CLOSE B WHERE A.BUSINESS_UNIT = B.BUSINESS_UNIT AND A.BOOK = B.BOOK) AND A.ACCOUNTING_PERIOD = (SELECT MAX(B.ACCOUNTING_PERIOD) FROM PS_BU_BOOK_CLOSE B WHERE A.BUSINESS_UNIT = B.BUSINESS_UNIT AND A.BOOK = B.BOOK AND A.FISCAL_YEAR = B.FISCAL_YEAR)
|