2009 Sep 18 2:26 PM
Hi everybody!
I've a very quick question.
I have the infoobject 0CALMONTH and i need to reduce month offset of 2 units.
For example from 01.2009 I need to obtain 11.2008.
I have tried doing 0CALMONTH - 2 saving it in 0CALMONTH type variable but with input 01.2009 (for system is 200901) I have obtained 99.2008 (because 200901-2=200899).
My code is:
SELECT SINGLE zmonthyear INTO v_calmonth
FROM zlogmese.
v_calmonth = v_calmonth - 2.
Why 0CALMONTH doesn't work in month ranges but as a normal number?
How can I obtain my specific needs?
Thanks in advance to everybody,
Beppe
Edited by: MasQueNada on Sep 18, 2009 4:23 PM
2009 Sep 18 4:54 PM
Hi,
you can not do operations on dates in the way that you described, you must use an appropriate function module for
example:
RP_CALC_DATE_IN_INTERVAL
Regards,
Rocco
2009 Sep 22 6:00 AM
Hi,
You should use only function modules in date/month calculations. If u r using calculations, u may get answer for 1 or 2 inputs but in some cases u may get error. So always prefer Function modules..
call function 'RP_CALC_DATE_IN_INTERVAL'
exporting
date = 01.01.2009 "example.
days = 0
months = 2 "as per ur need of months
signum = '-' "add or subtract from input.
years = 0
importing
calc_date = 0CALMONTH "field in which u hv to store.
u can use the same FM for calculating with respect to date,month or year.
Regards,
Surya
2009 Sep 22 11:16 AM
check the month from v_calmonth first and then subtract.
make 2 variable month and year
get the values of month and year.
if month > 2.
subtract 2 from month.
get month and year valeu in v_calmonth.
else.
subtract 1 from year.
add 10 in month.
get month and year valeu in v_calmonth.
endif.
2009 Sep 22 11:54 AM
Hi Beppe,
0CALMONTH is a month range infoobject in BI not in ABAP. There isn't a data type of month in ABAP.
Thats the reason why v_calmonth - 2 will not yield your desired result.
As mentioned by others, you have to use FMs for date manipulations.
But you have to 1st convert month to a date type variable as under:
DATA:
v_caldate TYPE SY-DATUM.
MOVE: v_calmonth TO v_caldate+0(6).
MOVE: '01' TO v_caldate+6(2).
* Here you can make use of v_calmonth in any FM to get results
* Once date manipulation is complete...
MOVE: v_caldate+0(6) TO v_calmonth.
* Now you have desired result in month range format
2009 Sep 22 12:29 PM
Hi,
You can use FM : RP_CALC_DATE_IN_INTERVAL
Note: In place of PLUS SIGN , use MINUS sign.
Example:
Import parameters Value
DATE 22.01.2009
DAYS 00
MONTHS 02
SIGNUM -
YEARS 00
Export parameters Value
CALC_DATE 22.11.2008
Regds,
Anil