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: 

Variations of string search

Former Member
0 Kudos

Hi SDN,

Re: IF Var1 CP 'HELLO'

Can someone direct me to a source to find out variations of CP (Contains Pattern)?

Also, how would you check if a string contains four numbers following a letter?

Thanks for your help.

Saf.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

CP (Contains Pattern):

The complete string c1 matches the pattern c2 (c1 "matches" c2).

The pattern c2 can contain ordinary characters and wildcards.

'*' stands for any character string and '+' denotes any character.

If the result of the comparison is positive, the system field SY-FDPOS contains the offset of the first character of c2 in c1. The wildcard character '*' at the beginning of the pattern c2 is ignored when determining the value of SY-FDPOS.

If the result of the comparison is negative, the system field SY-FDPOS contains the length of c1.

Examples:

'ABCDE' CP 'CD' is true; SY-FDPOS = 2.

'ABCDE' CP '*CD' is false; SY-FDPOS = 5.

'ABCDE' CP '+CD' is true; SY-FDPOS = 0.

'ABCDE' CP '+CD*' is false; SY-FDPOS = 5.

'ABCDE' CP 'BD*' is true; SY-FDPOS = 1.

The character '#' has a special meaning. It serves as an escape symbol and indicates that the very next character should be compared "exactly".

This allows you to search for:

- characters in upper or lower case

e.g.: c1 CP '#A#b'

- the wildcard characters '*', '+' themselves

e.g.: c1 CP '#' or c1 CP '#+*'

- the escape symbol itself

e.g.: c1 CP '##'

- blanks at the end of c1

e.g.: c1 CP '*# '

If c2 does not contain the wildcard character '*', the shorter field is padded with "soft blanks" to bring it up to the length of the longer field.

Examples:

'ABC' CP 'ABC ' is true,

'ABC ' CP 'ABC' is true,

but

'ABC' CP 'ABC+' is false,

'ABC' CP 'ABC# ' is false,

because a "soft blank" is neither any character ('+') nor a "real" blank ('# ').

The escape symbol does not affect the length of f2 ('A#a#B' still has the length 3).

The comparison is not case-sensitive.

4 REPLIES 4

Former Member
0 Kudos

CP (Contains Pattern):

The complete string c1 matches the pattern c2 (c1 "matches" c2).

The pattern c2 can contain ordinary characters and wildcards.

'*' stands for any character string and '+' denotes any character.

If the result of the comparison is positive, the system field SY-FDPOS contains the offset of the first character of c2 in c1. The wildcard character '*' at the beginning of the pattern c2 is ignored when determining the value of SY-FDPOS.

If the result of the comparison is negative, the system field SY-FDPOS contains the length of c1.

Examples:

'ABCDE' CP 'CD' is true; SY-FDPOS = 2.

'ABCDE' CP '*CD' is false; SY-FDPOS = 5.

'ABCDE' CP '+CD' is true; SY-FDPOS = 0.

'ABCDE' CP '+CD*' is false; SY-FDPOS = 5.

'ABCDE' CP 'BD*' is true; SY-FDPOS = 1.

The character '#' has a special meaning. It serves as an escape symbol and indicates that the very next character should be compared "exactly".

This allows you to search for:

- characters in upper or lower case

e.g.: c1 CP '#A#b'

- the wildcard characters '*', '+' themselves

e.g.: c1 CP '#' or c1 CP '#+*'

- the escape symbol itself

e.g.: c1 CP '##'

- blanks at the end of c1

e.g.: c1 CP '*# '

If c2 does not contain the wildcard character '*', the shorter field is padded with "soft blanks" to bring it up to the length of the longer field.

Examples:

'ABC' CP 'ABC ' is true,

'ABC ' CP 'ABC' is true,

but

'ABC' CP 'ABC+' is false,

'ABC' CP 'ABC# ' is false,

because a "soft blank" is neither any character ('+') nor a "real" blank ('# ').

The escape symbol does not affect the length of f2 ('A#a#B' still has the length 3).

The comparison is not case-sensitive.

0 Kudos

Sudhir,

Thanks for the help. I actually was looking for other constrcts like CP and not more examples of CP.

Thanks.

Saf.

Former Member
0 Kudos

CO (Contains Only)

CN (Contains Not only)

CA (Contains Any)

NA (contains Not Any)

CS (Contains String)

NS (contains No String)

CP (Contains Pattern)

NP (contains No Pattern)

0 Kudos

Here is the <a href="http://help.sap.com/saphelp_46c/helpdata/en/fc/eb3516358411d1829f0000e829fbfe/frameset.htm">link</a>.