Search code examples
abapsap-erp

Incorrect SQL statement using FOR ALL ENTRIES and NOT EXISTS


I am trying to do a selection of the table VBRK, with the goal that it will select all of the data from VBRK, without those data where the column NETWR is 0. The code is as below:

 SELECT DISTINCT * FROM vbrk INTO TABLE gt_vbrk
      FOR ALL ENTRIES IN gt_vbfa_inv
      WHERE vbeln = gt_vbfa_inv-vbeln
        AND NOT EXISTS (SELECT DISTINCT * FROM vbrk 
                        INTO TABLE gt_vbrk
                        FOR ALL ENTRIES IN gt_vbfa_inv
                        WHERE netwr = 0). //Here I get an error

So I am getting an error that it is not grammatically correct to do the NOT EXISTS. Can someone tell me how can I fix the upper code or do a selection where the data with NETWR = 0 will not be selected?

Thank you all in advance!


Solution

  • Simply add netwr to the WHERE condition, NE is for not equal:

     SELECT DISTINCT * 
            FROM vbrk 
            INTO TABLE gt_vbrk
            FOR ALL ENTRIES IN gt_vbfa_inv
            WHERE vbeln EQ gt_vbfa_inv-vbeln
              AND netwr NE 0.