Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Sy-datum

Former Member
0 Likes
5,564

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........

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,209

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........

14 REPLIES 14
Read only

VXLozano
Active Contributor
0 Likes
3,209

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)

Read only

Former Member
0 Likes
3,210

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

Read only

0 Likes
3,209

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.

Read only

Former Member
0 Likes
3,209

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

Read only

gopi_narendra
Active Contributor
0 Likes
3,209

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

Read only

hymavathi_oruganti
Active Contributor
0 Likes
3,209

sy-datum - 61 will work.

example:

data: v_date like sy-datum.

v_date = sy-datum - 61.

Read only

Former Member
0 Likes
3,209

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

Read only

varma_narayana
Active Contributor
0 Likes
3,209

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>

Read only

Former Member
0 Likes
3,209

Hi,

U can use this FM

CCM_GO_BACK_MONTHS

HR_JP_ADD_MONTH_TO_DATE

Hope this helps,

Regards,

Pritha.

Reward if helpful.

Read only

Former Member
0 Likes
3,209

.

Read only

Former Member
0 Likes
3,209

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.

Read only

Former Member
0 Likes
3,209

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

Read only

Former Member
0 Likes
3,209

<b>Reward points if helpful</b>

Read only

Former Member
0 Likes
3,209

Vicenç Lozano is begging for points in another forum.

he gave you a great answer... so, why not give him 10 points?

poor sheeps...