Open all | Close all


Add n number of working days to date


The following ABAP code adds/Subtracts n number of months from a particular date. This is a very simple
processusing the 'MONTH_PLUS_DETERMINE' function module. If this function module does not exist please
see the  more cumbersome solution using SAP FM 'CALCULATE_DATE'.

Simply add the below FORM into you ABAP code and call it using the usual PERFORM command:
	  DATA: ld_date TYPE sy-datum.
		PERFORM calculate_date 	using '-4'
					changing ld_date.

*&---------------------------------------------------------------------*
*&      Form  CALCULATE_DATE
*&---------------------------------------------------------------------*
*       Add/Subtract n number of months from a date
*----------------------------------------------------------------------*
*  -->  p_months  Number of months to add/subtract
*  <--  p_date    Start date and result date
*----------------------------------------------------------------------*

FORM calculate_date USING p_months
                    CHANGING p_date.

  DATA: ld_datestor TYPE sy-datum.

  ld_datestor = p_date.

  CALL FUNCTION 'MONTH_PLUS_DETERMINE'
    EXPORTING
      MONTHS        = p_months
      OLDDATE       = p_date
    IMPORTING
      NEWDATE       = p_date.
ENDFORM.                    " CALCULATE_DATE