Logical expressions for string fields in ABAP
A logical expression compares the value in one field with the value in another field. Although the most common logical expressions compare the contents of two numeric fields, string fields can also be compared. It is important to understand (and remember) the different types of logical expression for strings as they can make it much easier to work within the string processing model.
A logical expression would be:
if logical expression.
code goes here
There are 8 relational operators for strings
- CO - contains
- Use this to test if field a contains field b. For example:
CUSNM = 'Mrs. Johnson'
TEST = 'Mrs.'
CUSNM CO TEST returns a true value.
Note:Test that CUSNM contains a value. If the field is blank ABAP returns a false true.
if ( p_matnr co ' 0123456789' ).
shift p_matnr right deleting trailing ' '.
overlay p_matnr with '00000000000000000'.
shift p_matnr left deleting leading ' '.
- CN - does not contain
- Inverse of contains
- CA - contains any
- NA - contains none
- Inverse of contains any
- CS - contains string
- NS - does not contain string
- Inverse of contains string
- CP - contains pattern
- Allow you do do some rudimentary pattern matching. Use "*" to match any string and "+" to match a single character. "#" is used as the escape character, allowing you to match "*","+" or "#" itself. The comparison is not case-sensitive.
- CN - does not contain pattern
- Inverse of contains pattern
Return to ABAP help