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

date calculation formula

Former Member
0 Likes
1,030

Hi Experts,

I need to do a date calculation in one of my programs.

For eg:

data: l_date1 like mch1-fvdt1,

l_maxlz like marc-maxlz,

l_date2 like mch1-vfdat.

the l_date1 and l_date2 are in DATES Format (mmddyyyy)

and l_maxlz is in MONTHS (eg: 12, 14, 20, 24).

i have to add <b>"l_date1" + "l_maxlz"</b> and store it in <b>"l_date2".</b>

Eg: 12/31/2006 + 30 = 06/31/2009

Plz suggest me the formula for calculation.

thnx for the help.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
929

Remember that all dates in SAP are stored as YYYYMMDD regardless of external formatting. Check this sample.




report zrich_0001.

data: l_date1 like mch1-fvdt1,
      l_maxlz like marc-maxlz value '30',
      l_date2 like mch1-vfdat.

l_date1 = '20061231'.

call function 'RE_ADD_MONTH_TO_DATE'
     exporting
          months  = l_maxlz
          olddate = l_date1
     importing
          newdate = l_date2.


write:/ l_date2.

Of course, this will return the date 06/30/2009, because there is no 31st of june.

Regards,

Rich Heilman

5 REPLIES 5
Read only

abdul_hakim
Active Contributor
0 Likes
929

Hi,

Have a look at the Rich's Code...

Read only

0 Likes
929

Abdul, that will not work because you are not handling the change in year.

Regards,

Rich Heilman

Read only

0 Likes
929

Hi Rich,

You are Right..Written it wrongly..

Sam Have a look at Rich's Code..

Cheers,

Abdul Hakim

Read only

0 Likes
929

PERFECT!!!!!!!!!!

thnx a lot, Rich and Abdul

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
930

Remember that all dates in SAP are stored as YYYYMMDD regardless of external formatting. Check this sample.




report zrich_0001.

data: l_date1 like mch1-fvdt1,
      l_maxlz like marc-maxlz value '30',
      l_date2 like mch1-vfdat.

l_date1 = '20061231'.

call function 'RE_ADD_MONTH_TO_DATE'
     exporting
          months  = l_maxlz
          olddate = l_date1
     importing
          newdate = l_date2.


write:/ l_date2.

Of course, this will return the date 06/30/2009, because there is no 31st of june.

Regards,

Rich Heilman