Skip to Content
author's profile photo Former Member
Former Member

Date Caclculations

Hi,

I want set the first and last day of the last month as default values for the parameters on my selection screen. Do i need to do offset operations or is there any simple way to do so..

Thanks in advance,

Ram.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 08:19 AM

    Hi everybody,

    Thanks for your ans. Now i got the solution. But its not coming to my parameters as default values. I perfromed calculations under INITIALIZATION event before declaring parameters. Is that wrong. If so, where should i perform these calculations.

    Thanks,

    Ram.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 07:27 AM

    Hi,

    It is better to use OFFSET way, it is better in performance.

    To set the first and last day of the last month as default values for the parameters.

    • First day of the month.

    date1 = sy-datum.

    date1+6(2) = '01'.

    • Last day of the month.

    date2 = sy-datum.

    if date2+4(2) < 12.

    date24(2) = date24(2) + 1.

    else.

    date2+4(2) = '01'.

    date20(4) = date20(4) + 1.

    endif.

    date2 = date2 - 1.

    P_Para1 = date1.

    P_Para2 = date2.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 07:35 AM

    hiiii

    for getting first & last date of last month.. you can use following code

    DATA:
         w_fldate   TYPE sy-datum,
          w_carrid  TYPE sflight-carrid,
          w_date    TYPE sy-datum,
          w_date1   TYPE i VALUE '01',
          w_temp    TYPE sy-datum,
          w_next    TYPE i,
          w_last    TYPE sy-datum.
     SELECT-OPTIONS
       s_fldate FOR w_fldate.
      MOVE sy-datum TO s_fldate-low.
      MOVE sy-datum TO s_fldate-high.
      w_date = sy-datum.
    
    
      s_fldate-low+6(2) = w_date1.
      w_temp = s_fldate-low.
      w_next = s_fldate-low+4(2) + 1.
      w_temp+4(2) = w_next.
    
      w_last = w_temp - 1.
      s_fldate-high = w_last.
      APPEND s_fldate.

    reward if useful

    thx

    twinkal

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 07:35 AM

    You can use the below function modules too...

    • Last day of the month.

    1) SG_PS_GET_LAST_AY_OF_MONTH

    • Please consider the below code for the last day of the month or the above function module.

    date2 = sy-datum.

    if date2+4(2) < 12.

    date24(2) = date24(2) + 1.

    date2+6(2) = '01'.

    else.

    date20(4) = date20(4) + 1.

    date2+4(2) = '01'.

    date2+6(2) = '01'.

    endif.

    date2 = date2 - 1.

    Edited by: Ravi Kumar on Jun 19, 2008 9:40 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 07:36 AM

    Hi,

    In my view this ould be the best possible way.

    Data:

    w_date LIKE sy-datum. " Date Variable

    SELECT-OPTIONS:

    s_date FOR w_date.

    w_date = sy-datum.

    w_date+6(2) = 01.

    s_date-low = w_date.

    w_date = sy-datum.

    ADD 1 TO w_date+4(2).

    w_date+6(2) = 01.

    w_date = w_date - 1.

    s_date-high = w_date.

    Regards,

    Nisrin.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Ram

      Check this code

      REPORT ztest.
      
      TABLES:
        syst.
      SELECT-OPTIONS:
        s_date FOR sy-datum.
      
      INITIALIZATION.
        s_date-high = sy-datum.
        s_date-high+6(2) = '01'.
        s_date-high = s_date-high - 1.
      
        s_date-low = s_date-high.
        s_date-low+6(2) = '01'.
      
        APPEND s_date.
      

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 07:52 AM

    Hi.

    Are giving select option on selection screen then use the following code it is working.

    select-options:

    s_date for sy-datum.

    data:

    w_firstdate type sy-datum,

    w_lastdate type sy-datum.

    initialization.

    CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'

    EXPORTING

    iv_date = sy-datum

    IMPORTING

    EV_MONTH_BEGIN_DATE = w_firstdate

    EV_MONTH_END_DATE = w_lastdate.

    s_date-low = w_firstdate.

    s_date-high = w_lastdate.

    append s_date.

    If not r u using parameters only, Use the same function module to get first and last date of a month and then write initialization event as given below.

    INITIALIZATION.

    p_firstdate = w_firstdate.

    p_lastdate = w_lastdate.

    PLZ reward points both will definately work.

    Regards.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 19, 2008 at 07:53 AM

    Hi.

    Are giving select option on selection screen then use the following code it is working.

    select-options:

    s_date for sy-datum.

    data:

    w_firstdate type sy-datum,

    w_lastdate type sy-datum.

    initialization.

    CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'

    EXPORTING

    iv_date = sy-datum

    IMPORTING

    EV_MONTH_BEGIN_DATE = w_firstdate

    EV_MONTH_END_DATE = w_lastdate.

    s_date-low = w_firstdate.

    s_date-high = w_lastdate.

    append s_date.

    If not r u using parameters only, Use the same function module to get first and last date of a month and then write initialization event as given below.

    INITIALIZATION.

    p_firstdate = w_firstdate.

    p_lastdate = w_lastdate.

    PLZ reward points both will definately work.

    Regards.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.