Application Development 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: 

Subtracting from a date

Former Member
0 Kudos

Hello

I am writing a start routine in BI in which i dont want any records which are older than 2 days.

So what i am doing is this

DATA lv_date type d.

loop at SOURCE_PACKAGE assigning <source_fields>.

lv_date = <source_fields>-CHANGED_AT - 2.

if <source_fields>-CREATED_AT <> lv_date.

delete SOURCE_PACKAGE.

endif.

endloop.

Now i have checked that the format of the <source_fields>-CHANGED_AT is dd.mm.yyyy. this doesnt seem to work. Please can someone suggest me something

4 REPLIES 4

Former Member
0 Kudos

use this Function module.

RP_CALC_DATE_IN_INTERVAL

pass the date and you can add - subtract days months years from a given date.

for subtracting pass '-' in SIGNUM and '+' to add.

A

Edited by: Amandeep Bal on Sep 10, 2008 11:21 AM

JozsefSzikszai
Active Contributor
0 Kudos

.

matt
Active Contributor
0 Kudos

Dates are stored internally as yyyymmdd. Are you sure your changed_at field is also in this format? SAP uses conversion exits, so what you see in, e.g. LISTCUBE, if you have conversions switched on, isn't what is actually in the database.

Your code should work if the fields are in the correct format - but I think you missed the comparator. btw - lv_date is not a good name for a variable. How about lv_two_days_before, or something more meaningful.

DATA lv_date type d.

loop at SOURCE_PACKAGE assigning <source_fields>.
  lv_date = <source_fields>-CHANGED_AT - 2.
  if <source_fields>-CREATED_AT GT lv_date.
    delete SOURCE_PACKAGE.
  endif.
endloop.

Run through the startroutine in debug, and see what the actual values you're getting in lv_date, CHANGED_AT and CREATED_AT

If the dates really are stored in dd.mm.yyyy format, you'll have to convert them to dates, using slicing as Eric suggested, before doing calculations.

matt

Former Member
0 Kudos

Hi,

Your calculation is correct. Please check the if condition.

Also, after subtracting 2 from field type SY-DATUM, you will get the result in the format of SY-DATUM only i.e. YYYYMMDD.

Convert it using:

data: v_date type char10.

WRITE SY-DATUM TO V_DATE.

See if it helps.

- Hemant