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

Select with comparison between two fields in DB table

Former Member
0 Likes
717

I need to do the following select but I am not sure of the correct syntax.

select vbeln fkart netwr into table it_table from vbrk where

fkdat NE erdat.

What I need is every record (only fields vbeln, fkart, and netwr) from vbrk where fkdat and erdat are not equal. Is there a way to do this in a single select? It is looking for erdat to be defined in the program but erdat and fkdat are both the values in the database and are not supplied by the program or the use. I hope this makes sense.

Davis

1 ACCEPTED SOLUTION
Read only

ferry_lianto
Active Contributor
0 Likes
662

Hi,

Please try this.


select vbeln fkart netwr fkdat erdat 
into (vbrk-vbeln, vbrk-fkart, vbrk-netwr, vbrk-fkdat, vbrk-erdat) 
from vbrk
where fkdat ne space.
  if vbrk-fkdat ne vbrk-erdat.
    it_table-vbeln = vbrk-vbeln.
    it_table-fkart = vbrk-fkart.
    it_table-netwr = vbrk-netwr.
    append it_table.
  endif.
endselect.

Regards,

Ferry Lianto

3 REPLIES 3
Read only

ferry_lianto
Active Contributor
0 Likes
663

Hi,

Please try this.


select vbeln fkart netwr fkdat erdat 
into (vbrk-vbeln, vbrk-fkart, vbrk-netwr, vbrk-fkdat, vbrk-erdat) 
from vbrk
where fkdat ne space.
  if vbrk-fkdat ne vbrk-erdat.
    it_table-vbeln = vbrk-vbeln.
    it_table-fkart = vbrk-fkart.
    it_table-netwr = vbrk-netwr.
    append it_table.
  endif.
endselect.

Regards,

Ferry Lianto

Read only

0 Likes
662

Ferry, thank you very much. I was unaware that you could do such a thing. I have learned a lot from you and I appreciate it very much!

Davis

Read only

former_member194669
Active Contributor
0 Likes
662

Hi,

May be this way.


tables : vbrk.
select vbeln fkart netwr from vbrk
  if vbrk-fkdat NE vbrk-erdat.
    move-corresponding vbrk to it_table.
    append it_table.
  endif.
endselect.

a®