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

Date

SG141
Active Participant
0 Likes
511

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
491

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

4 REPLIES 4
Read only

ferry_lianto
Active Contributor
0 Likes
491

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

Read only

Former Member
0 Likes
492

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

Read only

Former Member
0 Likes
491

You have to be aware of leap years. Simply subtracting 1 from the year won't necessarily work (eg. 20000229).

Rob

Read only

0 Likes
491

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