‎2006 Jun 22 8:40 PM
Hi
i have a select option for a date i want to fill the low value as a one month back date (suppose today is 22nd 06 and i want 22 nd 05).
‎2006 Jun 22 8:46 PM
Do you want one month back same date or do you want to always subtract a particular number of days(say 30)? For the first you can do like this.
data: v_date like sy-datum,
v_month(2) type n,
v_year(4) type n.
v_date = sy-datum.
v_month = v_date+4(2).
v_year = v_date+0(4).
if v_month > 1.
v_month = v_month - 1.
else.
v_month = 12.
v_year = v_year - 1.
endif.
v_date+0(4) = v_year.
v_date+4(2) = v_month. <-- now v_date has previous month same date
s_date-low = v_date.You can have this code in INITIALIZATION.
If you want the second, simply subtract 30 from sy-datum.
Took care of January
Message was edited by: Srinivas Adavi
‎2006 Jun 22 8:43 PM
hi kiran,
<b>select-options: s_date for sy-datum.
initialization.
s_date-low = sy-datum - 30.
s_date-high = sy-datum.
append s_date.</b>
hope this helps,
do reward if it helps,
priya.
Message was edited by: Priya
‎2006 Jun 22 8:43 PM
hi kiran,
use soption_low = sydatum - 30.Do this is in initialization.
then sap will take care of the date
hope this helps.
regards,
keerthi.
‎2006 Jun 22 8:46 PM
Do you want one month back same date or do you want to always subtract a particular number of days(say 30)? For the first you can do like this.
data: v_date like sy-datum,
v_month(2) type n,
v_year(4) type n.
v_date = sy-datum.
v_month = v_date+4(2).
v_year = v_date+0(4).
if v_month > 1.
v_month = v_month - 1.
else.
v_month = 12.
v_year = v_year - 1.
endif.
v_date+0(4) = v_year.
v_date+4(2) = v_month. <-- now v_date has previous month same date
s_date-low = v_date.You can have this code in INITIALIZATION.
If you want the second, simply subtract 30 from sy-datum.
Took care of January
Message was edited by: Srinivas Adavi
‎2006 Jun 22 8:47 PM
Hi Kiran,
check this
Example of a date calculation:
DATA: ULTIMO TYPE D.
ULTIMO = SY-DATUM.
ULTIMO+6(2) = '01'. " = first day of this month
ULTIMO = ULTIMO - 1. " = last day of last month
Here, the last day of the previous month is assigned to the date field ULTIMO.
1. ULTIMO is filled with the present date.
2. Using an offset specification, the day is changed to the first day of the current month.
3. 1 is subtracted from ULTIMO. Its contents are changed to the last day of the previous month. Before performing the subtraction, the system converts ULTIMO to the number of days since 01.01.0001 and converts the result back to a date.
regards,
laxmi.
‎2006 Jun 22 8:48 PM
‎2006 Jun 22 9:07 PM
The FM showed by Ferry handles awkward dates like the one I mentioned. Dates look like numbers, but they really aren't. Using them in arithmetic expressions can be problematic.
Rob
‎2006 Jun 22 9:10 PM
You are correct Rob. That is why I asked the question if he always wants the same date of the previous month. I used the same function module Ferry mentioned in some of my code.
‎2006 Jun 22 9:35 PM
The function module doesn't even work consistently. Try:
REPORT ztest MESSAGE-ID 00.
DATA: w_date LIKE sy-datum.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = '20080330'
days = 0
months = 1
signum = '-'
years = 0
IMPORTING
calc_date = w_date.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = w_date
days = 2
months = 0
signum = '-'
years = 0
IMPORTING
calc_date = w_date.
WRITE: /001 '20080330 -1 month -2 days =', w_date.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = '20080330'
days = 2
months = 0
signum = '-'
years = 0
IMPORTING
calc_date = w_date.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = w_date
days = 0
months = 1
signum = '-'
years = 0
IMPORTING
calc_date = w_date.
WRITE: /001 '20080330 -2 days -1 month =', w_date.Rob
‎2006 Jun 22 8:50 PM
Hi Kiran,
You can use this FM <b>RP_CALC_DATE_IN_INTERVAL</b> at initialization.
call function 'RP_CALC_DATE_IN_INTERVAL'
exporting
date = sy-datum
days = 30
months = 0
signum = '-'
years = 0
importing
calc_date = wa_date.Hope this will help.
Regards,
Ferry Lianto