Skip to Content
avatar image
Former Member

system date calculation

i want to manipulate the system date..

fetch the data the date which is enter on selection screen - previous 6 month data.

how i will manipulate the month of system date.

is there any function module for that??

thanks in advance.

Manish

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Apr 16, 2006 at 01:35 PM

    Hi Manish,

    Welcome to SDN.

    You can use this FM <b>RP_CALC_DATE_IN_INTERVAL</b>.

    data: wa_date like sy-datum.
     
    call function 'RP_CALC_DATE_IN_INTERVAL'
             exporting
                  date      = sy-datum
                  days      = 0
                  months    = 6
                  signum    = '-'
                  years     = 0
             importing
                  calc_date = wa_date.
    
    *This will give you the month 
    write: / wa_date+4(2). 
    

    Hope this will help.

    Regards,

    Ferry Lianto

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 16, 2006 at 02:49 PM

    Manish,

    Make use of the FM CCM_GO_BACK_MONTHS.You can obtain the exact date as of 6 months back or any number of months for that matter from the date that is entered on the selection-screen.Use the date returned from the FM to obtain the date range.Then use these dates to extract the data that you need.

    Cheers

    Nishanth

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Nishanth

      Thanks for your reply,

      now i can use both as you and ferry suggested both looks okay for my requirement...

      regards

      Manish

  • avatar image
    Former Member
    Apr 16, 2006 at 12:00 PM

    Hi Manish,

    You can directly seperate the date to go back to 6 month date. No need of a Function module. You can directly subtract the system date by the 180 days which will give you a 6 month back date.

    Incase you want to modify the 2 character month value then you may use the string modifiers like sy-datum+4(2) to get the month as the date is stored in YYYYMMDD.

    Hope this helps. If you need anyspecific logic feel free to let me know.

    Cheers

    VJ

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 16, 2006 at 12:51 PM

    Hello manish,

    Use the function module BKK_ADD_MONTH_TO_DATE to add certain number of months to a date.

    Subtracting 180 days would be a crude way as 6 months is not equal 180 days in most of cases.

    Modifying the month's digits directly would lead to numerous errors like having 31 in months that actually have 30 days or less,... etc.

    Best bet would be use sap provide FM, which would take care of all exceptions..

    Hope this helps..

    Regards,

    Nagaraju Chidurupalli

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 16, 2006 at 01:29 PM

    Hi,

    Yes i agree with Nagraju. FM is a better ways at times but not all the time. If the date calculation is carried out in a loop then it doesnt make sense to use a FM and slow down the performance of the program.

    Again it all depends on whats the actual requirment. If its a general report where you need to give a window period of 6 months to restrict huge data selection then going 180 days back would makes sense. If the requirement is to find the exact 6 month period for financial calculations then a FM is a better bet.

    So i leave it you to descide the best approach. Cheers

    VJ

    Message was edited by: Vijayendra Rao

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      VJ - you have to be careful when working with dates. Six months back isn't necessarily 180 days. If you subtract 180 days from 2006/04/16, you end up with 2005/10/18. If you subtract 6 months using the function module you get 2005/10/16.

      I think the users would expect the latter in this case.

      Having said that, I agree that there is overhead when calling a function module and here, it would be simple enough to do in the same program code:

      DATA: year(4)  TYPE n,
            month(2) TYPE n,
            day(2)   TYPE n,
            then     LIKE sy-datum.
      
      IF sy-datum+4(2) > 6.
        year  = sy-datum(4).
        month = sy-datum+4(2) - 6.
      ELSE.
        year  = sy-datum(4) - 1.
        month = sy-datum+4(2) + 6.
      ENDIF.
      day = sy-datum+6(2).
      CONCATENATE year month day INTO then.
      

      Rob