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

Function module for Date calculation

Former Member
0 Likes
13,438

hi,

I have a requirement to check a Date exactly 12 months back from the present day when my function module is called.

Is there a SAP standard function module to do this manipulation?

Presently i have used the following code,

LV_DATUM = SY-DATUM

LV_DATUM = LV_DATUM - 365.

The problem in the above code is not knowing the Leap year dynamically, which means it would sometimes be less than 365 days.

Regards,

Raja

17 REPLIES 17
Read only

Former Member
0 Likes
6,312

Hi Raja,

Try HRWPC_BL_DATES_MONTH_INTERVAL

Read only

JozsefSzikszai
Active Contributor
0 Likes
6,312

just try the following (no FM is necessary):

lv_datum = sy-datum.
lv_datum(4) = lv_datum(4) - 1.

Read only

Former Member
0 Likes
6,312

Hi,

Try this FM "MONTH_PLUS_DETERMINE"

Add or subtract months from a date. To subtract a month, enter a negative value for the 'months' parameter.

Regards,

Chithra

Read only

former_member156446
Active Contributor
0 Likes
6,312
DATA:lv_date TYPE d.
lv_date = '20000504'.

lv_date+0(4) = lv_date+0(4) - 1.

WRITE:/ lv_date.
Read only

0 Likes
6,312

And what about if the date was '20080229' how owuld your code work in that case?

Read only

0 Likes
6,312

What would be the expected result, 20070228 or 20070301?

Read only

0 Likes
6,312

Hi MXG

check it

DATA:lv_date TYPE d.
lv_date = '20080229'.   " value you gave

lv_date+0(4) = lv_date+0(4) - 1.

WRITE:/ lv_date.

outoput: 02292007

Read only

0 Likes
6,312

yes and then what to do with the date value 02/29/2007?

Read only

0 Likes
6,312

date will always be stored in YYYYMMDD format in SAP, specially in debug mode and in DB level.. its just the output or the conversion routines which shows us the ouput as per system settings...

Read only

0 Likes
6,312

do you see 20070229 or 02/29/2007 as a valid date?

got it ?

Read only

0 Likes
6,312

>

>

outoput: 02292007

Was this date came in our life?

Read only

0 Likes
6,312

date - 1year is the concept and the logic works

logic is writen in SAP _ ABAP not in Visual basics chill..

Read only

0 Likes
6,312

I guess you still dont get it.

try putting date as 02/29/2007 on any SAP date field on any screen

Read only

0 Likes
6,312

Read only

Former Member
0 Likes
6,312

Hi

Check this fm CALCULATE_DATE

Regards

Gregory

Read only

Former Member
0 Likes
6,312

FM RP_CALC_DATE_IN_INTERVAL worked fine for me

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

date = '02/29/2008'

days = '0'

months = '0'

signum = '-'

years = '01'

IMPORTING

calc_date = p_bsdte.

i got p_bsdte = 02/28/2007.

Read only

0 Likes
6,312

Try this too:

DATA:

l_year1 TYPE i,

l_year2 TYPE p DECIMALS 2,

l_date TYPE sy-datum.

PARAMETER: datum TYPE sy-datum.

l_year1 = datum(4) / 4.

l_year2 = datum(4) / 4.

IF l_year1 EQ l_year2.

l_date = datum - 365.

ELSE.

l_date = datum - 366.

ENDIF.