String Operation – Compare


 

Comparisons can be applied on strings with types C, D, N, and T.

 

<operator>

Meaning

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

CO- Contains Only

 

* contains only: true, if operand1 only contains characters from operand2.
* it is case-sensitive and trailing blanks are respected in both operands.
*IF the comparison IS  false, sy-fdpos contains the offset
* of the first character in operand1 that is not contained in operand2.
* IF the comparison IS true, sy-fdpos contains the length of operand1.

DATA res TYPE string VALUE ‘SAP ABAP PROGRAM’.

IF ‘GRA’ CO res.
WRITE :‘Success’syfdpos” Success -> sy-fdpos = strlen ( ‘GRA’ )
ELSE.
WRITE :‘Failure’syfdpos.
ENDIF.
ULINE.
IF ‘GRAPX’ CO res.
WRITE :‘Success’syfdpos.
ELSE.
WRITE :‘Failure’syfdpos” Failure-> sy-fdpos = offset position of X
ENDIF.

 

 

Output:

 
 CN Contains Not Only

 

* contains not only->
* If true, sy-fdpos contains the offset of the first
* character in operand1 that is not contained in operand2.
* If false, sy-fdpos contains the length of operand1.

DATA res TYPE string VALUE ‘SAP ABAP PROGRAM’.

IF ‘GRA’ CN res.
WRITE :‘Success’syfdpos.
ELSE.
WRITE :‘Failure’syfdpos” Failure-> sy-fdpos = strlen ( ‘GRA’ )
ENDIF.
ULINE.
IF ‘GRAPX’ CN res.
WRITE :‘Success’syfdpos” Success -> sy-fdpos = offset position of X
ELSE.
WRITE :‘Failure’syfdpos.
ENDIF.


 

Output:

 
 CA- Contains Any

 

* contains any->
* True, if operand1 contains at least one character from operand2.
* then sy-fdpos contains the offset of the first character in operand1
* that is also contained in operand2
* If the comparison is false, sy-fdpos contains the length of operand1.

DATA res TYPE string VALUE ‘SAP ABAP PROGRAM’.

IF ‘ZYGRA’ CA res.
WRITE :‘Success:’syfdpos” Success -> sy-fdpos = offset OF ‘G’
ELSE.
WRITE :‘Failure:’syfdpos.
ENDIF.
ULINE.
IF ‘YX’ CA res.
WRITE :‘Success:’syfdpos.
ELSE.
WRITE :‘Failure:’syfdpos” Failure-> sy-fdpos = strlen ( ‘GRA’ )
ENDIF.


  

NA- Contains Not Any


 

* contains not any->
* True, if operand1 does not contain any characters from operand2.
* If the comparison is false,sy-fdpos contains the offset of the first
* character in operand1 that is also contained in operand2.
* If the comparison is true, sy-fdpos contains the length of operand1.

DATA res TYPE string VALUE ‘SAP ABAP PROGRAM’.

IF ‘ZYGRA’ NA res.
WRITE :‘Success:’syfdpos.
ELSE.
WRITE :‘Failure:’syfdpos” Failure-> sy-fdpos = offset of ‘G’
ENDIF.
ULINE.
IF ‘YXZ’ NA res.
WRITE :‘Success:’syfdpos“Success -> sy-fdpos = STRLEN ( ‘YXZ’ )
ELSE.
WRITE :‘Failure:’syfdpos.
ENDIF.


 

 CS- Contains String

 

* contains String->
* True, if operand1 contains the string in operand2 and not case sensitive
* If the comparison is false,sy-fdpos contains the length of operand1
* If the comparison is true, sy-fdpos contains the  offset of the operand2 in operand1

DATA res TYPE string VALUE ‘SAP ABAP PROGRAM’.

IF RES CS ‘PrO’.
WRITE :‘Success:’syfdpos.  “Success -> sy-fdpos = Offset of ‘P’ in res
ELSE.
WRITE :‘Failure:’syfdpos.
ENDIF.
ULINE.
IF RES CS ‘YXZ’.
WRITE :‘Success:’syfdpos.
ELSE.
WRITE :‘Failure:’syfdpos” Failure-> sy-fdpos = strlen ( res )
ENDIF.


 

 

 

NS- Contains No String


 

* contains no string->
* True, If operand1 does not contains the string operand and not case sensitive
* If the comparison is TRUE,sy-fdpos contains the length of operand1
* If the comparison is FALSE, sy-fdpos contains the  offset of the operand2 in operand1

DATA res TYPE string VALUE ‘SAP ABAP PROGRAM’.

IF res NS  ‘PrO’.
WRITE :‘Success:’syfdpos.
ELSE.
WRITE :‘Failure:’syfdpos” Failure-> sy-fdpos =  offset of ‘P’ in res
ENDIF.
ULINE.
IF res NS ‘YXZ’.
WRITE :‘Success:’syfdpos.  “Success -> lengeth of ( res )
ELSE.
WRITE :‘Failure:’syfdpos.
ENDIF.

 

 

 

CP- Contains Pattern


 

* contains Pattern->
* True, If operand1 contains pattern operand2 and not case sensitive
* If the comparison is TRUE,sy-fdpos contains the offset of operand2 in operand
* If the comparison is FALSE, sy-fdpos contains the length of operand1

DATA res TYPE string VALUE ‘SAP ABAP PROGRAM’.

IF res CP  ‘*Ro*’.
WRITE :‘Success:’syfdpos“Success ->  sy-fdpos = Offset of ‘R’ in res
ELSE.
WRITE :‘Failure:’syfdpos.
ENDIF.
ULINE.
IF res CP ‘*XY*’.
WRITE :‘Success:’syfdpos.
ELSE.
WRITE :‘Failure:’syfdpos” Failure-> sy-fdpos =  length of ( res )
ENDIF.

 

 

 

NP- Contains No Pattern


 

* contains no Pattern->
* True, If operand1 does not contains pattern operand2 and not case sensitive
* If the comparison is TRUE,sy-fdpos contains the length of operand1
* If the comparison is FALSE, sy-fdpos contains the offset of operand2 in operand1

DATA res TYPE string VALUE ‘SAP ABAP PROGRAM’.

IF res NP  ‘*Ro*’.
WRITE :‘Success:’syfdpos.
ELSE.
WRITE :‘Failure:’syfdpos.  ” Failure-> sy-fdpos =   Offset of ‘R’ in res
ENDIF.
ULINE.
IF res NP ‘*XY*’.
WRITE :‘Success:’syfdpos.  “Success ->  sy-fdpos =  length of ( res )
ELSE.
WRITE :‘Failure:’syfdpos.
ENDIF.


 


 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s