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

Relational Operator '-'.

Former Member
0 Likes
1,297

Hi

can anybody tell me if i want to subtract one thing from another(subtracting) how can I write the code?

can I use minus symbol for subtractions.

17 REPLIES 17
Read only

Former Member
0 Likes
1,257

v_var = v_data1 - v_data2.

Read only

Former Member
0 Likes
1,257

data: v_test type i value 10,

v_test1 type i value 4,

output type i .

output = v_test - v_test1 .

write:/ output.

regards,

venkat

Read only

Former Member
0 Likes
1,257

hi,

Yes you can very well use that ...



data : p_var1 type i value '10',
     P_var2 type i value '2',
     p_out type i.

p_out = p_var1 - p_var2.

write : p_out.  

Read only

Former Member
0 Likes
1,257

Hi,

data: v_num type i value 12.

v_num = v_num - 3.

write:/ v_num.

Read only

Former Member
0 Likes
1,257

Hi sandeep,

You can use the subtraction operator i.e ' - ' sign.

But while using it be careul to give spaces in between operator sign and the variables you want to subtraction i.e.

var1 = var3 - var4.

I hope this may solve ur queris.

Read only

Former Member
0 Likes
1,257

Hi,

You can go ahead with the above solutions.

Thanks,

Sriram Ponna.

Read only

0 Likes
1,257

Ya i was trying to write like

wa_output-duedate = wa_vendor-base - wa_vendor-terms.

here it is saying relational operator '-' is not supported

Read only

0 Likes
1,257

Are you doing it inside an if or other control structure?

Post your code, is probably a syntax error

Read only

0 Likes
1,257

LOOP AT lt_vendor INTO wa_vendor.

  • wa_output-name1 = wa_vendor-name1.

  • wa_output-duedate = wa_vendor-zfbdt + wa_vendor-zterm.

  • IF ( wa_output-duedate - p_audat ) LE 30.

  • wa_output-days30 = 'X'.

  • ENDIF.

endloop.

here is the piece of code

Read only

0 Likes
1,257

Yes, that's the problem, you can't do that in abap.

Just put the value of


wa_output-duedate - p_audat

in another variable and compare that variable in the if

Read only

0 Likes
1,257

hi this can be done like this also...

LOOP AT lt_vendor INTO wa_vendor.

v_diff = wa_output-duedate - p_audat .

wa_output-name1 = wa_vendor-name1.

wa_output-duedate = wa_vendor-zfbdt + wa_vendor-zterm.

IF v_diff LE 30.

wa_output-days30 = 'X'.

ENDIF.

endloop.

regards,

venkat

Read only

0 Likes
1,257

Ok. i got it thanks for the solution.

but why it wont work the other way.?

Read only

matt
Active Contributor
0 Likes
1,257

>

> Ok. i got it thanks for the solution.

>

> but why it wont work the other way.?

Because the ABAP interpreter doesn't work like that.

Interestingly, if you write a static method, say DIFFERENCE, of a class, say my_class, that finds the difference, you can write something like:

IF my_class=>difference( i_val1 = wa_out-duedata i_val2 = p_audat) LE 30.

But it would be pretty pointless!

matt

Read only

Former Member
0 Likes
1,257

hi,

do this way ..

data : lv_differ type i.

LOOP AT lt_vendor INTO wa_vendor.

wa_output-name1 = wa_vendor-name1.

wa_output-duedate = wa_vendor-zfbdt + wa_vendor-zterm.

lv_differ = wa_output-duedate - p_audat.

IF lv_differ LE 30.

wa_output-days30 = 'X'.

ENDIF.

endloop.

Read only

Former Member
0 Likes
1,257

Can I write expression like

  • IF 30 GE delay LE 60.

  • wa_output-days60 = 'X'.

  • ENDIF.

Read only

0 Likes
1,257

no, you need to join them using the operand AND.

but is way better to use


IF  delay between 30 and 60. 
wa_output-days60 = 'X'. 
ENDIF. 

Read only

0 Likes
1,257

yes.. but in this syntax


DATA: delay TYPE i.
IF delay BETWEEN 30 AND 60.
ENDIF.