Skip to Content

Select with comparison between two fields in DB table

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    Posted on Sep 28, 2007 at 03:22 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 28, 2007 at 03:27 PM

    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.
    
    

    Add comment
    10|10000 characters needed characters exceeded