Search code examples
abapinternal-tablesstring-function

Delete internal table lines where field contains the "+"?


I want to delete entries from an internal table, which has not a "+" in one column. Now, if I want to delete it like this:

DELETE internal_table where field1 <> '+'.

it doesn't work. This means, it takes the "+" as a regex and just selects any character with length 1.

Now I've tried several things:

DELETE internal_table where field1 <> '\+'.
DELETE internal_table where field1 <> |\+|.
DELETE internal_table where field1 <> `\+`.

Nothing of this works. With the String template |\+| I get the error "Unmasked symbol '\' in string template.

Field 1 is a character field with length 1. How can I escape the "+" that only the lines, which have a "+" in field1?


Solution

  • You can do it without regex:

    DELETE internal_table 
           WHERE field CA '+'.
    

    CA stands for contains any and it will delete all lines where the field contains a '+' character (independent of the lenght of the field or what other characters are in). You can add more characters if you wish, for example CA '+-' which means the string contains a '+' or a '-' etc.

    If you want to delete a line, which does NOT contain a '+' you can use:

    DELETE internal_table
           WHERE field NA '+'.
    

    Here is a link to the direct SAPHelp: https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abenlogexp_op.htm