3

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?

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Sasku
  • 517
  • 7
  • 23
  • 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 Dec 12 '19 at 08:59
  • Didn't know that you cold use regex in DELETE statements. Anyway, have you tried the `cs` (**c**ontains **s**tring) command? `WHERE field1 cs '+'` – koks der drache Dec 12 '19 at 09:04
  • As a backslash is an escape character also for the string literal, double it: `'\\+'` – trincot Dec 12 '19 at 09:05
  • 1
    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](https://stackoverflow.com/help/minimal-reproducible-example)? – Sandra Rossi Dec 12 '19 at 12:06
  • @SandraRossi I can't explain - If I could I wouldn't need to post the question... I think that it takes the + as a regular expression. a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) wouldn't help here. But if you want one ```DELETE internal_table where field1 <> 'X'.``` - but this doesn't solve my problem.... – Sasku Dec 12 '19 at 12:45
  • 1
    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 Dec 12 '19 at 19:32
  • Then the question is, why mine doesn't work. Field1 is really simple only a char01 field, but it ignores completely this deletion... – Sasku Dec 12 '19 at 21:58
  • The difference between our two programs is that mine is reproducible and yours is not. StackOverflow principle: post a reproducible code or don't post (in StackOverflow). There are other forums for discussions, like SAP Community. – Sandra Rossi Dec 14 '19 at 09:33

1 Answers1

5

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

József Szikszai
  • 4,791
  • 3
  • 14
  • 24
  • you are totally right. BUT I made a small mistake in my question. I want to delete any entry which does not have a ```+``` in thier column. Now I only need to negate this CA ( somehow ... ) and then it should work. – Sasku Dec 12 '19 at 09:09