3
votes

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?

1
I'm not familiar with this dialect of regex, but maybe you can do it dirty by making a set of just + like this [+] - tst
Didn't know that you cold use regex in DELETE statements. Anyway, have you tried the cs (contains string) command? WHERE field1 cs '+' - koks der drache
As a backslash is an escape character also for the string literal, double it: '\\+' - trincot
Can you explain why field1 <> '+' doesn't work if "Field 1 is a character field with length 1"? Can you please post a Minimal, Reproducible Example? - Sandra Rossi
It would help to create an example so that we can reproduce and help you and future visitors. It's not a regular expression. With this example, you can see that it works: TYPES: begin of ty, field1(1) type c, end of ty. DATA internal_table type standard table of ty. internal_table = value #( ( field1 = 'A' ) ( field1 = '+' ) ). DELETE internal_table WHERE field1 <> '+'. The line containing A is deleted as expected. - Sandra Rossi

1 Answers

5
votes

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