Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to check if a word in a string field?

0 Kudos

I have an internal table named AA which has a field named status. This field is a string field may has word such like 'DLV' or 'TECO' etc.

I want to delete all fields in this internal table that status field has word 'DLV' or 'TECO'.

How can I do this?

1 ACCEPTED SOLUTION

ssimsekler
Active Contributor
0 Kudos

Hi Mark

Try:

DELETE aa WHERE status CS ' DLV ' OR
                status CS ' TECO ' .

Be careful that CS is case insensitive.

Or you may use CP to handle with patterns like 'DLV' .

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

7 REPLIES 7

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

delete AA where status = 'DLV' or status = 'TECO'.

ssimsekler
Active Contributor
0 Kudos

Hi Mark

Try:

DELETE aa WHERE status CS ' DLV ' OR
                status CS ' TECO ' .

Be careful that CS is case insensitive.

Or you may use CP to handle with patterns like 'DLV' .

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

If you want to delete the record if the field contains the DLV or TECO,you can use cp to achieve this.

delete aa where status cp 'DLV' or status cp 'dlv'

or status cp 'TECO' or status cp 'teco'.

For more information about CP , just have a look on this.

The logical expression

<f1> CP <f2>

is true if <f1> matches the pattern <f2>. If <f2> is of type C, you can use the following wildcards in <f2>:

• for any character string: *

• for any single character: +

Trailing spaces are ignored and the comparison is not case-sensitive. If the comparison is true, the system field SY-FDPOS contains the offset of <f2> in <f1> . If it is false, SY-FDPOS contains the length of <f1>.

If you want to perform a comparison on a particular character in <f2>, place the escape character # in front of it. You can use the escape character # to specify

• characters in upper and lower case

• the wildcard character "" (enter:#)

• the wildcard character "" (enter: # )

• the escape symbol itself (enter: ## )

• blanks at the end of a string (enter: #___ )

0 Kudos

There is a problem:

The status string such like "EDOD DLC PDLV VOAD".

Though this string contains "DLV", but it should not be deleted.

If I use status CS 'DLV', the above status will be deleted.

How can I solve this problem?

Thanks!

0 Kudos

then you should use contain only option (CO).

Contains Only: True, if operand1 only contains characters from operand2. Upper/lower case and trailing blanks are taken into account for both operands. If operand2 is of type string and is initial, then the logical expression is false, unless operand1 is also of type string and is initial, in which case the logical expression is always true. If the result of the comparison is negative, sy-fdpos contains the offset of the first character in operand1, that is not contained in operand2. If the result of the comparison is positive, sy-fdpos contains the length of operand1.

Regards

Raja

0 Kudos

Because of my compared string is "EDOD DLV PDLV VOAD". I found if use c1 CO 'DLV', it returns false. I want to check if the string has 'DLV' not the 'PDLV'.

Thanks!

andreas_mann3
Active Contributor
0 Kudos

Hi Mark,

...or use select-options / ranges

SELECT-OPTIONS status FOR tj02t-txt04.

INITIALIZATION.
  status-low = 'DLV' .
  status-sign = 'I'.
  status-option = 'EQ'.
  APPEND status.
  status-low = 'TECO' .
  APPEND status.
  ...
  DELETE itab WHERE status IN status.

regards