Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Date issue -how can we get this value dynamically -200705

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

ferry_lianto
Active Contributor
0 Kudos

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

5 REPLIES 5

ferry_lianto
Active Contributor
0 Kudos

Hi,

Please check this FM RP_CALC_DATE_IN_INTERVAL.

Regards,

Ferry Lianto

ferry_lianto
Active Contributor
0 Kudos

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

0 Kudos

Thank you.

Former Member
0 Kudos

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

0 Kudos

Excellent Naren,

Thank you.