2013 Nov 02 6:00 AM
Hai
Is there any FM to calculate months between two days.
Ex: In selction date if we have given like 1.1.2013 to 1.4.2013
I want output like :1,2,3,4 months between dates.
Regards,
Sivajyothi
2013 Nov 02 7:20 AM
Hi-
try below code:
DATA: lv_f_cnt(2) TYPE c,
lv_t_cnt(2) TYPE c,
lv_cnt TYPE i.
PARAMETERS: f_date TYPE sy-datum,
t_date TYPE sy-datum.
lv_f_cnt = f_date+4(2).
lv_t_cnt = t_date+4(2).
IF lv_f_cnt LE lv_t_cnt.
lv_cnt = lv_t_cnt - lv_f_cnt.
DO lv_cnt TIMES.
IF lv_f_cnt+0(1) = '0'.
SHIFT lv_f_cnt LEFT DELETING LEADING '0'.
ENDIF.
WRITE: lv_f_cnt.
lv_f_cnt = lv_f_cnt + 1.
IF lv_f_cnt > 12.
lv_f_cnt = 1.
ENDIF.
ENDDO.
ENDIF.
Thanks,
Venkat
2013 Nov 02 6:04 AM
Try following FM...
MONTHS_BETWEEN_TWO_DATES
MONTHS_BETWEEN_TWO_DATES_NEW
HR_99S_MONTHS_BETWEEN_DATES
HR_MONTHS_BETWEEN_TWO_DATES
or open se37 and search by *month*.. you will get some FM. try those all..
2013 Nov 02 6:11 AM
This can be done without FM also.
data lv_start_month type i.
data lv_end_month type i.
lv_start_month = lv_start_date+4(2). 1
lv_start_year = lv_start_date+0(4). 2013
lv_end_month = lv_end_date+4(2). 4
lv_end_year = lv_end_date+0(4). 2013.
if lv_s_year eq lv_end_year.
while end_month eq start_month.
append start_month to itab.
start_month ++.
endwhile.
else.
while year become equal..
while end_month eq start_month.
append start_month to itab.
start_month ++.
endwhile.
endwhile.
then increase year.
endif.
Note: take code as algorithm.
2013 Nov 02 7:20 AM
Hi-
try below code:
DATA: lv_f_cnt(2) TYPE c,
lv_t_cnt(2) TYPE c,
lv_cnt TYPE i.
PARAMETERS: f_date TYPE sy-datum,
t_date TYPE sy-datum.
lv_f_cnt = f_date+4(2).
lv_t_cnt = t_date+4(2).
IF lv_f_cnt LE lv_t_cnt.
lv_cnt = lv_t_cnt - lv_f_cnt.
DO lv_cnt TIMES.
IF lv_f_cnt+0(1) = '0'.
SHIFT lv_f_cnt LEFT DELETING LEADING '0'.
ENDIF.
WRITE: lv_f_cnt.
lv_f_cnt = lv_f_cnt + 1.
IF lv_f_cnt > 12.
lv_f_cnt = 1.
ENDIF.
ENDDO.
ENDIF.
Thanks,
Venkat
2013 Nov 02 10:41 AM