logical expressions

Upload: lvaldeir

Post on 04-Jun-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Logical Expressions

    1/3

    Logical Expressions - Comparison Operators forCharacter-Type Fields

    In some cases, the syntax rules that apply to Unicode programsare different than those for non-Unicodeprograms. SeeProcessing Strings in Unicode Programs.

    In the condition "c1 op c2", the comparison operator opbetween the fields c1and c2may be any of the

    operations listed below, but c1and c2must be character- type fields (C, STRING,N, D, T.

    1. CO(!ontains nly#

    c1contains onlycharacters from the string c2.

    If c1or c2is of type C, the comparison ta$es into account the full length of the field, including blan$s at

    the end.comparison.If c1is of type STRINGand empty, the result of the comparison is always positi%e.

    If c2is of type STRINGand empty, the result of the comparison is always negati%e, unless c1is also an

    empty string.If the result of the comparison is negati%e, the field SY-FDPOScontains the offset of the first character in

    c1which is not also included in c2.

    If the result of the comparison is positi%e, the system field SY-FDPOScontains the length of c1.

    &he comparison is case-sensiti%e.

    'xamples#

    'ABCDE' CO 'XYZ'is false SY-FDPOS) *.

    'ABCDE' CO 'AB'is false SY-FDPOS) +.

    'ABCDE' CO 'ABCDE'is true SY-FDPOS) .

    2. CN(!ontains ot only#

    "c1 CN c2" is eui%alent to "NOT ( c1 CO c2 )".

    c1contains not onlycharacters from c2.

    If the result of the comparison is positi%e, the system field SY-FDPOScontains the offset of the first

    character in c1which is not also in c2.

    If the result of the comparison is negati%e, the system field SY-FDPOScontains the length of c1.

    3. CA(!ontains /ny#

    c1contains at least onecharacter from the string c2.

    If c1or c2is of type C, the comparison ta$es into account the full length of the field, including blan$s atthe end.If c1or c2is of type STRINGand empty, the result of the comparison is always negati%e.

    If the result of the comparison is positi%e, the system field SY-FDPOScontains the offset of the first

    character in c1which is also in c2.

    If the result of the comparison is negati%e, the system field SY-FDPOScontains the length of c1.

    &he comparison is case-sensiti%e.

    'xamples#

  • 8/13/2019 Logical Expressions

    2/3

    'ABCDE' CA 'CY'is true SY-FDPOS) +.

    'ABCDE' CA 'XY'is false SY-FDPOS) .

    4. NA(contains ot /ny#

    "c1 NA c2" is eui%alent to "NOT ( c1 CA c2 )".c1contains nocharacters from c2.

    SY-FDPOSis set accordingly.

    5. CS(!ontains String#

    c1contains the character string c2.

    &railing blan$s in c1and c2are ignored if the respecti%e field is of type C.

    /n empty string c2(i.e., only blan$s with type C, or empty string with type STRING is included in any

    string c1, including the empty string itself. n the other hand, there is no non-empty string c2included in

    an empty string c1.

    If the result of the comparison is positi%e, the system field SY-FDPOScontains the offset of the first

    character of c2in c1.If the result of the comparison is negati%e, the system field SY-FDPOScontains the length of c1.

    &he comparison is not case-sensiti%e.

    'xamples#

    'ABCDE' CS 'CD'is true SY-FDPOS) +.

    'ABCDE' CS 'XY'is false SY-FDPOS) .

    'ABAAA' CS 'AB 'is true SY-FDPOS) *.

    ' ABC' CS ' AB'is true SY-FDPOS) 0.

    'ABC DEF' CS ' 'is true but:SY-FDPOS) *,

    since ' 'is interpreted as a trailing blan$ and is thus

    ignored.

    6. NS(contains o String#

    "c1 NS c2" is eui%alent to "NOT ( c1 CS c2 )".

    c1does notcontain c2.

    SY-FDPOSis set accordingly.

    7. CP(!ontains Pattern#

    &he complete string c1matches the pattern c2(c1"matches" c2.

    &he pattern c2can contain ordinary characters and wildcards.

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

    If the result of the comparison is positi%e, the system field SY-FDPOScontains the offset of the first

    character of c2in c1. &he wildcard character '*'at the beginning of the pattern c2is ignored when

    determining the %alue of SY-FDPOS.

    If the result of the comparison is negati%e, the system field SY-FDPOScontains the length of c1.

    'xamples#

    'ABCDE' CP '*CD*'is true SY-FDPOS) +.

    'ABCDE' CP '*CD'is false SY-FDPOS) .

    'ABCDE' CP '++CD+'is true SY-FDPOS) *.

  • 8/13/2019 Logical Expressions

    3/3

    'ABCDE' CP '+CD*'is false SY-FDPOS) .

    'ABCDE' CP '*B*D*'is true SY-FDPOS) 0.

    &he character '#'has a special meaning. It ser%es as an escape symbol and indicates that the %ery next

    character should be compared "exactly".&his allows you to search for#

    - characters in upper or lower casee.g.# c1 CP '*#A#b*'

    - the wildcard characters '*', '+'themsel%es

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

    - the escape symbol itselfe.g.# c1 CP '*##*'

    - blan$s at the end of c0e.g.# c1 CP '*# '

    If c2does not contain the wildcard character '*', the shorter field is padded with "soft blan$s" to bring it

    up to the length of the longer field.

    'xamples#

    'ABC' CP 'ABC 'is true,

    'ABC ' CP 'ABC'is true,

    but

    'ABC' CP 'ABC+'is false,

    'ABC' CP 'ABC# 'is false,

    because a "soft blan$" is neither any character ('+' nor a "real" blan$ ('# '.

    &he escape symbol does not affect the length of 2('A#!#B'still has the length 1.

    &he comparison is not case-sensiti%e.

    8. NP(contains o Pattern#

    "c1 NP c2" is eui%alent to "NOT ( c1 CP c2 )"

    c1does notmatch c2.