‎2007 Oct 01 8:04 PM
For one of the variable in my program whenever it is run i want the date to be 2 years back from the sy-datum.
data: date type sy-datum.
When the program is run today.
<b>
sy-datum 20071001
date 20051001</b>
How i can do that..
‎2007 Oct 01 8:07 PM
Hi
data:year(4), year1(4), date1(8).
Date = 20071001
year = date+0(4).
year1 = year - 2.
concatenate year1 date+4(4) into date1.
use the Date1
Regards
Anji
‎2007 Oct 01 8:06 PM
Hi,
Please try this.
data: wa_date like sy-datum.
wa_date = sy-datum.
wa_date(4) = wa_date(4) - 2.
write: wa_date.
Regards,
Ferry Lianto
‎2007 Oct 01 8:07 PM
Hi
data:year(4), year1(4), date1(8).
Date = 20071001
year = date+0(4).
year1 = year - 2.
concatenate year1 date+4(4) into date1.
use the Date1
Regards
Anji
‎2007 Oct 01 8:14 PM
You have to be aware of leap years. Simply subtracting 1 from the year won't necessarily work (eg. 20000229).
Rob
‎2007 Oct 01 8:38 PM
To correctly handle leap years, you can use a FM:
REPORT ztest LINE-SIZE 80 MESSAGE-ID 00.
DATA: today TYPE sy-datum VALUE '20080229',
prior_date TYPE sy-datum.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL_SG'
EXPORTING
date = today
days = 0
months = 0
signum = '-'
years = 2
IMPORTING
calc_date = prior_date.
WRITE: /001 today, prior_date.There may be others that work better.
Rob