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: 

function module to subtract a number of months from a date

Former Member
0 Kudos

I have a field, FISCPER, in the format YYYY/MMM(2007004) and I need to subtract 12 months off of it to get 2006004. I tried to just subtreact 12 but it gave me the actual value when you subtract the 2.

1 ACCEPTED SOLUTION

ferry_lianto
Active Contributor
0 Kudos

Hi,

I don't think any FM available for your purposes.

But you can try something like this.


DATA: BEGIN OF ITAB OCCURS 0,
        SPMON TYPE UMC_Y_VALIDFR,
      END OF ITAB.
                                                                        
PARAMETERS PSPMON TYPE UMC_Y_VALIDFR DEFAULT '2007004'.
                                                                     
START-OF-SELECTION.
                                            
  ITAB-SPMON = PSPMON.
  DO 12 TIMES.
    IF ITAB-SPMON+4(3) = '000'.
      ITAB-SPMON+4(3) = '012'.
      ITAB-SPMON(4) = ITAB-SPMON(4) - 1.
    ENDIF.
    APPEND ITAB.
                                                
    ITAB-SPMON = ITAB-SPMON - 1.
  ENDDO.

  READ TABLE ITAB INDEX 12.
  WRITE: / ITAB-SPMON.

Regards,

Ferry Lianto

5 REPLIES 5

ferry_lianto
Active Contributor
0 Kudos

Hi,

I don't think any FM available for your purposes.

But you can try something like this.


DATA: BEGIN OF ITAB OCCURS 0,
        SPMON TYPE UMC_Y_VALIDFR,
      END OF ITAB.
                                                                        
PARAMETERS PSPMON TYPE UMC_Y_VALIDFR DEFAULT '2007004'.
                                                                     
START-OF-SELECTION.
                                            
  ITAB-SPMON = PSPMON.
  DO 12 TIMES.
    IF ITAB-SPMON+4(3) = '000'.
      ITAB-SPMON+4(3) = '012'.
      ITAB-SPMON(4) = ITAB-SPMON(4) - 1.
    ENDIF.
    APPEND ITAB.
                                                
    ITAB-SPMON = ITAB-SPMON - 1.
  ENDDO.

  READ TABLE ITAB INDEX 12.
  WRITE: / ITAB-SPMON.

Regards,

Ferry Lianto

0 Kudos

sorry this doens't exist in Bw

0 Kudos

Try RELATIVE_DATE_CALCULATE.

~Suresh

Former Member
0 Kudos

Hi,

Check the following example:

FM to Get the Day for a Particular Date

FM or any other means by which we can get the DAY for a particular date?

Yes, DATE_COMPUTE_DAY

Sample code:

clear: hold_day_of_week.

CALL FUNCTION 'DATE_COMPUTE_DAY'

EXPORTING

DATE = workdate

IMPORTING

DAY = day_of_week_num

EXCEPTIONS

OTHERS = 8.

CASE day_of_week_num.

WHEN 1.

hold_day_of_week = 'Monday'.

WHEN 2.

hold_day_of_week = 'Tuesday'.

WHEN 3.

hold_day_of_week = 'Wednesday'.

WHEN 4.

hold_day_of_week = 'Thursday'.

WHEN 5.

hold_day_of_week = 'Friday'.

WHEN 6.

hold_day_of_week = 'Saturday'.

WHEN 7.

hold_day_of_week = 'Sunday'.

WHEN OTHERS.

hold_day_of_week = 'invalid'.

ENDCASE.

or

You can use DATE_COMPUTE_DAY to get the day number of the week (for example, today gives 5)

then use WEEKDAY_GET which returns an itab with seven entries (one for each day of the week.)

You enter in this itab and get the field langt to get the day name.

Former Member
0 Kudos

Hi ,

Check out these function modules which may help you out.

1. RP_CALC_DATE_IN_INTERVAL - Add/subtract years/months/days from a date

2. MONTH_PLUS_DETERMINE - Add or subtract months from a date to subtract a month, enter a negative value for the 'months' parameter.

If you think this helped you in anyway, reward me.

Regards,

Sravanthi.