Skip to Content
avatar image
Former Member

Date Issues

I want to get Last month start date and end date from current date

suppose for example if i run report todate on 18.10.2008,

the sate value will be from 01.09.2008 to 30.09.2008.

if i run report on 01.11.2008 my value should be 01.10.2008 to 31.10.2008.

How to get.

In my selection screen i have only one field that is sy-datum.

Thanks

kumar

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Oct 18, 2008 at 06:37 AM

    Find current months 1st day. using this if you subtract one day you get last month last day. if you subtract one month you get last months first day.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 18, 2008 at 06:37 AM

    *INITIALIZATION.

    • s_date-sign = 'I'.

    • s_date-option = 'BT'.

    • s_date-low = sy-datum.

    • s_date-low+6(2) = '01'.

    *

    • CALL FUNCTION 'LAST_DAY_OF_MONTHS'

    • EXPORTING

    • DAY_IN = SY-DATUM

    • IMPORTING

    • LAST_DAY_OF_MONTH = S_DATE-HIGH

    • EXCEPTIONS

    • DAY_IN_NO_DATE = 1

    • OTHERS = 2.

    • APPEND S_DATE.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 18, 2008 at 07:09 AM

    Hi,

    Use the code below;

    DATA :lv_date TYPE sy-datum,
          lv_lastdate TYPE sy-datum,
          lv_firstdate TYPE sy-datum.
    
    lv_date = '20080101'.
    
    CALL FUNCTION 'OIL_LAST_DAY_OF_PREVIOUS_MONTH'
      EXPORTING
        i_date_old = lv_date
      IMPORTING
        e_date_new = lv_lastdate.
    lv_firstdate = lv_lastdate.
    lv_firstdate+6(2) = '01'.

    lv_lastday will give last day of the previous month and lv_firstday will give the first day of the previous month.

    Regards

    Karthik D

    Add comment
    10|10000 characters needed characters exceeded