2007 Oct 03 7:35 AM
Hello Experts,
In my program i have to mention 2 dates .one is current date and other is currendate - 2 months.I have done like this:
Sy-datum - '0000020000'.
But it is not working.can suggest me any solution??
u will have points........
2007 Oct 03 7:39 AM
hi madan.,
sy-datum length is only 8.
and it takes the date as YYYYMMDD format.
if you want to decrease the date by 2 months use this stmt
sy-datum+4(2) - 2.
or use FM CCM_GO_BACK_MONTHS
<b><i>Reward points if useful</i></b>
Chandra
Message was edited by:
Chandra
Hello Experts,
In my program i have to mention 2 dates .one is current date and other is currendate - 2 months.I have done like this:
Sy-datum - '0000020000'.
But it is not working.can suggest me any solution??
u will have points........
2007 Oct 03 7:38 AM
Function Module CCM_GO_BACK_MONTHS
(by the way, I think you have two spare zeroes in your subtract sentence... '0000020000' would be '00000200', although I believe it would not work anyways)
2007 Oct 03 7:39 AM
hi madan.,
sy-datum length is only 8.
and it takes the date as YYYYMMDD format.
if you want to decrease the date by 2 months use this stmt
sy-datum+4(2) - 2.
or use FM CCM_GO_BACK_MONTHS
<b><i>Reward points if useful</i></b>
Chandra
Message was edited by:
Chandra
2007 Oct 03 7:43 AM
sy-datum+4(2) - 2 would NOT work, let's suppose you are working with february...
sy-datum+4(2) - 2 will return you yyyy00dd
Edition:
PLEASE, do NOT work with sy-datum - XX days
if you are talking about months!! The occidental calendar has months with 28, 29, 30 and/or 31 days, and if you must be sure about your work, you will have to take care of all possible cases (including years with february with 29 days). It's a useless piece of code. Use sy-datum - XX if you need to work with DAYS (or years) only.Message was edited by:
Vicenç Lozano
Edited again: Now I doubt if sy-datum - '0000xx00' would work. Although it's not the appropiate way to do it, we can suppose the SAP guys will take care about date substractions... it's something you would need to check by yourselves. But I would NOT recommend it anyways.
2007 Oct 03 7:40 AM
you can do like this
data : newdate like sy-datum.
newdate = sy-datum - 60.
or use fm
CALL FUNCTION 'MONTH_PLUS_DETERMINE'
EXPORTING
MONTHS = -2
OLDDATE = sy-datum
IMPORTING
NEWDATE = newdate
.
regards
shiba dutta
2007 Oct 03 7:40 AM
Check this ABAP Code
DATA : l_date TYPE sy-datum.
CALL FUNCTION 'BKK_ADD_MONTH_TO_DATE'
EXPORTING
months = -2
olddate = sy-datum
IMPORTING
newdate = l_date.Regards
Gopi
2007 Oct 03 7:42 AM
sy-datum - 61 will work.
example:
data: v_date like sy-datum.
v_date = sy-datum - 61.
2007 Oct 03 7:43 AM
Hi Madan,
You can get more information about the system values if you go to SE11 and put SYST in the structures field.
The SYST structure has a lot of useful information related with the server, the environment and the application running, check it
SY-DATUM : It is the system variable that holds the value of current date at runtime
write SY-DATUM4(2) to datechar0(2).
write '/' datechar+2(1).
write SY-DATUM6(2) to datechar3(2).
write '/' TO datechar+5(1).
write SY-DATUM0(4) to datechar6(4).
Value of SY-DATUM 20010616
Here's how the field changes with the execution of each line.
06________
06/_______
06/16_____
06/16/____
06/16/2001
****************************************************************************************************
(or)
****************************************************************************************************
DATA: DATEDIFF TYPE P.
CALL FUNCTION 'SD_DATETIME_DIFFERENCE'
EXPORTING
date1 = '20071122'
time1 = '000001'
date2 = '20070905'
time2 = '000001'
IMPORTING
DATEDIFF = DATEDIFF
EXCEPTIONS
INVALID_DATETIME = 1
OTHERS = 2.
Hope this will solve your problem.
Reward if helpful.
Regards,
Harini.S
2007 Oct 03 7:43 AM
Hi Madan..
To Add / Subtract months from a date use the FM
data : newdate like sy-datum.
CALL FUNCTION 'MONTH_PLUS_DETERMINE'
EXPORTING
MONTHS = -2 "for Subtracting 2 months
OLDDATE = sy-datum
IMPORTING
NEWDATE = newdate
.
WRITE:/ NEWDATE.
<b>reward if Helpful.</b>
2007 Oct 03 7:46 AM
Hi,
U can use this FM
CCM_GO_BACK_MONTHS
HR_JP_ADD_MONTH_TO_DATE
Hope this helps,
Regards,
Pritha.
Reward if helpful.
2007 Oct 03 8:18 AM
2007 Oct 03 8:22 AM
Hi,
Use the below code.
select-options: s_date for sy-datum.
initialization.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = sy-datum
days = 0
months = '02'
SIGNUM = '-'
years = 0
IMPORTING
CALC_DATE = s_date-low.
s_date-high = sy-datum.
s_date-sign = 'I'.
s_date-option = 'BT'.
append s_date.
2007 Oct 03 8:36 AM
Here only the no of months needs to be specified ...
CALL FUNCTION 'RE_ADD_MONTH_TO_DATE'
EXPORTING
months = -2 ( to reduce 2 months )
olddate = sy-datum ( Curent Date )
IMPORTING
NEWDATE = ws_date. ( current date - 2)
Regards,
Chitra
Message was edited by:
Chitra Parameswaran
2007 Oct 03 11:11 AM
2007 Oct 03 5:23 PM
Vicenç Lozano is begging for points in another forum.
he gave you a great answer... so, why not give him 10 points?
poor sheeps...
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |