ABAP keywords to manipulate text

ABAP keywords to manipulate text

Get length of a particular field
Find character in a text variable
Search character in a text variable

Get length of a particular field

We can use STRLEN statement :


  DATA: lw_word1(10) TYPE C VALUE 'STRING A',
        lw_word2(20) TYPE C VALUE ' My STRING B',
        lw_i TYPE I.
     
  lw_i = STRLEN( lw_word1 ) + STRLEN( lw_word2 ).
     
  WRITE: lw_i.

 
or DESCRIBE FIELD … LENGHT :


  DESCRIBE FIELD lw_field LENGTH lw_len.

 

Find character in a text variable

We can use FIND statement :


  FIND '-' IN lw_string.
  IF sy-subrc = 0.
    " if the character - (hyphen) is in lw_string, subrc will be 0.
  ENDIF


 

Search character in a text variable

We can use SEARCH statement :


  SEARCH lw_string FOR 'MyCAR'.
  IF sy-subrc = 0.
    " if text MyCAR is in lw_string, subrc will be 0.
  ENDIF

About the author

fjourneau administrator

Hi, I'm Florian Journeau, SAP ABAP R3 Freelance, based in Toulouse, France. You want to know more about me, have a look on my CV : cv.fjourneau.net.

Leave a Reply