2007 Jul 13 6:09 AM
hello,
hi i need to find out the intial & final date for a given quarter of a year.
can i know which function module i need to call for it..
thanks
sujatha
2007 Jul 13 6:12 AM
hi,
Just execute this code.
parameters: p_date type sydatum.
start-of-selection.
data: v_month type numc2.
data: v_year type numc4.
data: v_from type sydatum,
v_to type sydatum.
* Get month
v_month = p_date+4(2).
* get year
v_year = p_date+(4).
* Check if the month is in the first quarter.
if v_month >= '01' and v_month <='03'.
v_year = v_year - 1.
v_from+(4) = v_year.
v_from+4(2) = '09'.
v_from+6(2) = '01'.
v_to+(4) = v_year.
v_to+4(2) = '12'.
v_to+6(2) = '31'.
elseif v_month >= '04' and v_month <='06'.
v_from+(4) = v_year.
v_from+4(2) = '01'.
v_from+6(2) = '01'.
v_to+(4) = v_year.
v_to+4(2) = '03'.
v_to+6(2) = '31'.
elseif v_month >= '07' and v_month <='09'.
v_from+(4) = v_year.
v_from+4(2) = '04'.
v_from+6(2) = '01'.
v_to+(4) = v_year.
v_to+4(2) = '06'.
v_to+6(2) = '30'.
elseif v_month >= '10' and v_month <='12'.
v_from+(4) = v_year.
v_from+4(2) = '07'.
v_from+6(2) = '01'.
v_to+(4) = v_year.
v_to+4(2) = '09'.
v_to+6(2) = '30'.
endif.
write: / 'From', v_from.
write: / 'To', v_to.
Regards
Reshma
2007 Jul 13 6:12 AM
REPORT ZEXAMPLE.
TABLES T009.
DATA: V_GJAHR LIKE T009B-BDATJ, "FISCAL YEAR
V_POPER LIKE T009B-POPER, "POSTING PERIOD
F_DAY LIKE SY-DATUM,
L_DAY LIKE SY-DATUM,
C_PERIO LIKE CEST1-PERIO, "CURRENT PERIOD
N_PERIO LIKE CEST1-PERIO. "NEXT PERIOD
WRITE:/ 'PERIOD INFORMATION'.
ULINE.
WRITE:/ 'PERIOD', 10 'DATE', 30 'FIRST DAY', 50 'LAST DAY', 70 'NEXT PERIOD'.
ULINE.
SELECT * FROM T009.
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
I_DATE = SY-DATUM
I_PERIV = T009-PERIV
IMPORTING
E_BUPER = V_POPER
E_GJAHR = V_GJAHR
EXCEPTIONS
INPUT_FALSE = 1
T009_NOTFOUND = 2
T009B_NOTFOUND = 3
OTHERS = 4.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
EXPORTING
I_GJAHR = V_GJAHR
I_PERIV = T009-PERIV
I_POPER = V_POPER
IMPORTING
E_DATE = F_DAY
EXCEPTIONS
INPUT_FALSE = 1
T009_NOTFOUND = 2
T009B_NOTFOUND = 3
OTHERS = 4.
IF SY-SUBRC EQ 0.
CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
EXPORTING
I_GJAHR = V_GJAHR
I_PERIV = T009-PERIV
I_POPER = V_POPER
IMPORTING
E_DATE = L_DAY
EXCEPTIONS
INPUT_FALSE = 1
T009_NOTFOUND = 2
T009B_NOTFOUND = 3
OTHERS = 4.
IF SY-SUBRC EQ 0.
CONCATENATE V_GJAHR V_POPER INTO C_PERIO.
CALL FUNCTION 'RKE_ADD_TO_PERIOD'
EXPORTING
DELTA = T009-ANZBP
PERIO = C_PERIO
PERIV = T009-PERIV
IMPORTING
PERIO = N_PERIO
EXCEPTIONS
I_ERROR = 1
I_PERFLAG_INVALID = 2
I_PERIV_NOTFOUND = 3
OTHERS = 4.
CLEAR C_PERIO.
IF SY-SUBRC EQ 0.
WRITE:/ T009-PERIV, 10 SY-DATUM, 30 F_DAY, 50 L_DAY, 70 N_PERIO.
ELSE.
WRITE:/ T009-PERIV, 10 SY-DATUM, 30 F_DAY, 50 L_DAY,
70 'NEXT PERIOD COULD NOT BE CALCULATED'.
ENDIF.
ELSE.
WRITE:/ T009-PERIV, 10 SY-DATUM, 30 F_DAY, 50 'LAST DAY COULD NOT BE CALCULATED'.
ENDIF.
ELSE.
WRITE:/ T009-PERIV, 10 SY-DATUM, 30 'FIRST DAY COULD NOT BE CALCULATED'.
ENDIF.
ELSE.
WRITE:/ T009-PERIV, 10 'COULD NOT CONVERT TO DATE'.
ENDIF.
ENDSELECT.
Dont forget to reward.
2007 Jul 13 6:15 AM
HI,
Here are the Function modules which you can use
HR_JP_MONTH_BEGIN_END_DATE
'LAST_DAY_IN_PERIOD_GET'
'SG_PS_GET_LAST_DAY_OF_MONTH'
Regards
Sudheer
2007 Jul 13 6:18 AM
hi
good
try this functionmodule
SD_DATETIME_DIFFERENCE Give the difference in Days and Time for 2 dates
thanks
mrutyun^
2007 Jul 13 7:48 AM
2007 Jul 13 8:12 AM