Determine Last Day of the Previous Month

During developing a report  I came across this situation:

I've select option in which I want first date of the current month in LOW of select option and Last date of current month in HIGH of select month.  Which FUNCTION MODULES are used for this?

There's one way to do this, though it's not a straight idea.

There's a function module 'OIL_LAST_DAY_OF_PREVIOUS_MONTH' that is used to determine the last day of the previous month. from this you can derive the first date of the current month.

Sample:

parameters : date1 like sy-datum.
CALL FUNCTION 'OIL_LAST_DAY_OF_PREVIOUS_MONTH'
     EXPORTING
          I_DATE_OLD = date1
    IMPORTING
         E_DATE_NEW = date1
          .
data date2 like sy-datum.
date2 = date1 + 1.

write date2.

If you put 27.12.2005 as the input date,   date2 you will get as 01.12.2005.

Or else you can use the following code:

v_startdate = sy-datum.
v_startdate+6(2) = '01'.

v_enddate = v_startdate.
if v_enddate+4(2) >= '01' AND v_enddate >= '11'.
   v_endate+4(2) = v_enddate+4(2) + 1.
elseif v_enddate = '12'.
  v_enddate+4(2) = '01'.
  v_enddate+(4) = v_enddate+(4) + 1.
endif.
v_enddate = v_enddate - 1.

ABAP Tips by : Dileep, Nitin Gupta

Fast Links:
FM to get the Week for a Single Date
How to use function  DATE_GET_WEEK

Get help for your ABAP problems
Do you have a ABAP Question?

SAP Books
SAP Certification, Functional, Basis Administration and ABAP Programming Reference Books

More ABAP Tips

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.