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: 

substracting number of days from date

Former Member
0 Kudos

Hi all, I need to create a user exit to get a date value based on another variable. Basically, 100 days minus the first variable.

var2 = var1 - 100

How can I write this?

Thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Just the way you coded it.

REPORT ztest MESSAGE-ID 00 LINE-SIZE 80.

DATA: var1 TYPE sy-datum,

var2 TYPE sy-datum.

var1 = sy-datum.

var2 = var1 - 100.

WRITE: /001 var1, var2.

rob

Message was edited by:

Rob Burbank

9 REPLIES 9

Former Member
0 Kudos

Just the way you coded it.

REPORT ztest MESSAGE-ID 00 LINE-SIZE 80.

DATA: var1 TYPE sy-datum,

var2 TYPE sy-datum.

var1 = sy-datum.

var2 = var1 - 100.

WRITE: /001 var1, var2.

rob

Message was edited by:

Rob Burbank

0 Kudos

That did not work. Here is my code:


LOOP AT I_T_var_range
         INTO loc_var_range WHERE
                  VNAM = 'ZENDT' or
                  VNAM = 'ZENDATE'.


      l_S_range-low = loc_var_range-low - 275.
      l_s_range-sign = 'I'.
      l_s_range-opt = 'EQ'.
      APPEND l_s_range TO E_T_range.

    ENDLOOP.

When I tried to debug, loc_var_range-low showed a value of 20070401 which is var2 value. When I run the query, it returns me an error saying value for val1 cannot be calculated.

0 Kudos

So in your code, what is var1?

Rob

0 Kudos

zendt is var1.

From this I need to get value of var2

0 Kudos

I'm afraid I don't understand what you're asking; however, date arithmetic is simple. The solution I provided does do the subtraction correctly, so your problem appears to be ain applying it to your situation. Maybe if you posted more code showing just where the problems lies, it would help.

Rob

0 Kudos

ok, here is the full code. hope it makes sense.


IF i_step = 2.


*****Loops for Quarter Variable.*****************************************
    LOOP AT I_T_var_range
         INTO loc_var_range WHERE
                  VNAM = 'ZENDT' or
                  VNAM = 'ZENDATE'.

      l_S_range-low = loc_var_range-low - 275.
        l_s_range-sign = 'I'.
      l_s_range-opt = 'EQ'.
      APPEND l_s_range TO E_T_range.

    ENDLOOP.


    EXIT.
  ENDIF.

0 Kudos

Not yet.

Rob

0 Kudos

Ok, I figured it out. I had to declare variables of type d and then assign it.


IF i_step = 2.

    data:zday type d,
          zday1 type d.
*****Loops for Variable.*****************************************
    LOOP AT I_T_var_range
         INTO loc_var_range WHERE
                  VNAM = 'ZENDT' or
                  VNAM = 'ZENDATE'.


    zday = loc_var_range-low.

    zday1 = zday - 275.

*      l_S_range-low = loc_var_range-low - 275.
      l_S_range-low = zday1.

      l_s_range-sign = 'I'.
      l_s_range-opt = 'EQ'.
      APPEND l_s_range TO E_T_range.

    ENDLOOP.


    EXIT.
  ENDIF.

0 Kudos

Yes - you can only do date arithmetic on fields declared as dates.

Rob