04-23-2007 9:29 PM
Hi,
I am interested in catching past 6 months values in a cutom report( example : 200611,200612,200701,200702 ,200703,200704 & future 12 months 200705,200706...etc....200804)
based on current date everytime values will be changing..how can we capture this?
For current SY-DATUM+0(6) is giving me 200704
how can we get remaing values?
Rgds
Praveen
04-23-2007 9:36 PM
Hi,
Please try this.
DATA: BEGIN OF ITAB OCCURS 0,
SPMON TYPE SPMON,
END OF ITAB.
PARAMETERS PSPMON TYPE SPMON.
INITIALIZATION.
MOVE SY-DATUM TO PSPMON.
START-OF-SELECTION.
ITAB-SPMON = PSPMON.
DO 12 TIMES.
IF ITAB-SPMON+4(2) = '00'.
ITAB-SPMON+4(2) = '012'.
ITAB-SPMON(4) = ITAB-SPMON(4) - 1.
ENDIF.
APPEND ITAB .
IF ITAB-SPMON+4(2) = '12'.
ITAB-SPMON+4(2) = '00'.
ITAB-SPMON(4) = ITAB-SPMON(4) + 1.
ENDIF.
ITAB-SPMON = ITAB-SPMON + 1.
ENDDO.
LOOP AT ITAB.
WRITE: / ITAB-SPMON.
ENDLOOP.
Regards,
Ferry Lianto
04-23-2007 9:32 PM
Hi,
Please check this FM RP_CALC_DATE_IN_INTERVAL.
Regards,
Ferry Lianto
04-23-2007 9:36 PM
Hi,
Please try this.
DATA: BEGIN OF ITAB OCCURS 0,
SPMON TYPE SPMON,
END OF ITAB.
PARAMETERS PSPMON TYPE SPMON.
INITIALIZATION.
MOVE SY-DATUM TO PSPMON.
START-OF-SELECTION.
ITAB-SPMON = PSPMON.
DO 12 TIMES.
IF ITAB-SPMON+4(2) = '00'.
ITAB-SPMON+4(2) = '012'.
ITAB-SPMON(4) = ITAB-SPMON(4) - 1.
ENDIF.
APPEND ITAB .
IF ITAB-SPMON+4(2) = '12'.
ITAB-SPMON+4(2) = '00'.
ITAB-SPMON(4) = ITAB-SPMON(4) + 1.
ENDIF.
ITAB-SPMON = ITAB-SPMON + 1.
ENDDO.
LOOP AT ITAB.
WRITE: / ITAB-SPMON.
ENDLOOP.
Regards,
Ferry Lianto
04-23-2007 9:40 PM
04-23-2007 9:42 PM
Hi,
Check this sample code..
DATA: v_date TYPE sydatum.
DATA: t_mon_year(6) TYPE n OCCURS 0 WITH HEADER LINE.
Input
v_date = sy-datum.
<b>* Calculate previous six months.</b>
DO 6 TIMES.
v_date+6(2) = '01'.
Get the previous month
CALL FUNCTION 'RE_ADD_MONTH_TO_DATE'
EXPORTING
months = '-1'
olddate = v_date
IMPORTING
newdate = v_date.
t_mon_year = v_date(6).
APPEND t_mon_year.
ENDDO.
Reset the date.
v_date = sy-datum.
Get the current month also.
t_mon_year = v_date(6).
APPEND t_mon_year.
<b>* Calculate NEXT 12 months.</b>
DO 12 TIMES.
v_date+6(2) = '01'.
Get the next month.
CALL FUNCTION 'RE_ADD_MONTH_TO_DATE'
EXPORTING
months = '1'
olddate = v_date
IMPORTING
newdate = v_date.
*
t_mon_year = v_date(6).
APPEND t_mon_year.
ENDDO.
Display.
LOOP AT t_mon_year.
WRITE: / t_mon_year.
ENDLOOP.
Thanks,
Naren
04-23-2007 9:50 PM