Get Last Day of The Month

2009 March 31
by Tresna

Any chance that you need to get the latest date of this month or any month in particular? Easy, just use function LAST_DAY_OF_MONTHS. Here’s an example of how to do it.

DATA: start_date LIKE sy_datum,
      end_date LIKE sy_datum.

* Get first day of current month
  CONCATENATE sy-datum(6) '01' INTO start_date.

* Get last day of current month
  CALL FUNCTION 'LAST_DAY_OF_MONTHS'
       EXPORTING
            day_in            = start_date
       IMPORTING
            last_day_of_month = end_date.
  IF sy-subrc  0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
       WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

and voila! you got your last day of the month :)

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS