Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

system date calculation

Former Member
0 Likes
2,217

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

1 ACCEPTED SOLUTION
Read only

ferry_lianto
Active Contributor
0 Likes
1,753

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

8 REPLIES 8
Read only

Former Member
0 Likes
1,753

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

Read only

Former Member
0 Likes
1,753

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

Read only

Former Member
0 Likes
1,753

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

Read only

0 Likes
1,753

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

Read only

ferry_lianto
Active Contributor
0 Likes
1,754

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

Read only

0 Likes
1,753

Hi Ferry Lianto ,

Thanks for your immediate reply,

this F.M. might help for me...

regards

Manish

Read only

nishanthbhandar
Contributor
0 Likes
1,753

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

Read only

0 Likes
1,753

Hi Nishanth

Thanks for your reply,

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

regards

Manish