Consider a scenario where you want to add days, months and years to the date field. You can either write custom code to achieve the desired result or use a standard function module provided by SAP. It is always a best practice to use a standard function module as it save time and effort. Also the standard function modules have already been tested by SAP and they give you the desired result. The resulting code is easier to maintain.
The following function module can be used to achieve the desired result.
RP_CALC_DATE_IN_INTERVAL
Please see the code given belowREPORT ZEX_ADDDAYSMONTHSYEARS .
Parameters: p_date like P0001-BEGDA,
p_days like T5A4A-DLYDY,
p_mons like T5A4A-DLYMO,
p_yrs like T5A4A-DLYYR,
p_date1 like P0001-BEGDA.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
DATE = p_date
DAYS = p_days
MONTHS = p_mons
SIGNUM = '+'
YEARS = p_yrs
IMPORTING
CALC_DATE = p_date1 .
Write:/ p_date1.
If you enter the following parameters p_days like T5A4A-DLYDY,
p_mons like T5A4A-DLYMO,
p_yrs like T5A4A-DLYYR,
p_date1 like P0001-BEGDA.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
DATE = p_date
DAYS = p_days
MONTHS = p_mons
SIGNUM = '+'
YEARS = p_yrs
IMPORTING
CALC_DATE = p_date1 .
Write:/ p_date1.
Date = 5/5/2000
Days = 10
Months = 5
Years = 1
Days = 10
Months = 5
Years = 1
Then the OutPut would be as follows.
Add Days Months and Years to a Date
10/15/2001
10/15/2001
No comments:
Post a Comment