User Tools

Site Tools


start:tips:sap:string

Methods for string manipulation

FILL_TEXT_WITH_VARS

CALL METHOD cl_reca_string_services=>fill_text_with_vars
  EXPORTING
    id_text = imp_text
    id_var1 = imp_var1
    id_var2 = imp_var2
    id_var3 = imp_var3
    id_var4 = imp_var4
    id_var5 = imp_var5
    id_var6 = imp_var6
    id_var7 = imp_var7
    id_var8 = imp_var8
    id_var9 = imp_var9
  RECEIVING
    rd_text = ret_text.

GET_CHARS_FROM_LEFT

Gets ANZAHL Characters from the Left and the Remainder

CALL METHOD cl_reca_string_services=>get_chars_from_left
  EXPORTING
    id_number_chars = imp_number_chars
  IMPORTING
    ed_text         = exp_text
  CHANGING
    cd_text         = chg_text.

GET_CHARS_FROM_RIGHT

Gets ANZAHL Characters from theRight and the Remainder

DATA: lw_imp_str    TYPE i.
DATA: WL_ret_length TYPE i.
CLEAR: lw_imp_str, WL_ret_length.
 
CALL METHOD cl_swf_exp_wfsyst_string=>length
  EXPORTING
    str    = imp_str
  RECEIVING
    length = WL_ret_length.
 
lw_imp_str = WL_ret_length - imp_offset.
 
CALL METHOD cl_swf_exp_wfsyst_string=>substring
  EXPORTING
    str       = imp_str
    offset    = lw_imp_str
    length    = imp_offset
  RECEIVING
    substring = ret_substring.

IGNORE_LEADING_BLANKS

Removal of Leading Spaces

CALL METHOD cl_reca_string_services=>ignore_leading_blanks
  CHANGING
    cd_string = chg_string.

LEFT_UPTO_SPACE

Returns MAX Characters from Left w/o Space, to Remainder

CALL METHOD cl_reca_string_services=>left_upto_space
  EXPORTING
    id_max_char = imp_max_char
  IMPORTING
    ed_text     = exp_text
  CHANGING
    cd_text     = chg_text.

LENGTH

Number of Characters

CALL METHOD cl_swf_exp_wfsyst_string=>length
  EXPORTING
    str    = imp_str
  RECEIVING
    length = ret_length.

LTRIM

Left Trim

CALL METHOD cl_rsan_ut_string_operations=>ltrim
  EXPORTING
    i_input  = imp_input
  RECEIVING
    r_output = ret_output.

Gets Number of Characters from “Right”

CALL METHOD cl_reca_string_services=>right
  EXPORTING
    id_string = imp_string
    id_length = imp_length
  RECEIVING
    rd_string = ret_string.

RTRIM

Right Trim

CALL METHOD cl_rsan_ut_string_operations=>rtrim
  EXPORTING
    i_input  = imp_input
  RECEIVING
    r_output = ret_output.

SUBSTRING

Sub-String

CALL METHOD cl_swf_exp_wfsyst_string=>substring
  EXPORTING
    str       = imp_str
    offset    = imp_offset
    length    = imp_length
  RECEIVING
    substring = ret_substring.

TEXT_IS_SENSICAL

Check if the text is sensical or not. If there are less than eight unique characters, it is probably nonsensical. Also require a space.

CONSTANTS : c_space TYPE string VALUE space.
 
TYPES : BEGIN OF ty_unique_char,
          unique_char TYPE string,
        END OF ty_unique_char.
 
DATA : t_unique_char  TYPE TABLE OF ty_unique_char,
       st_unique_char TYPE ty_unique_char,
       unique_char    TYPE string,
       i_nb_car       TYPE i,
       i_offset       TYPE i,
       t_words        TYPE TABLE OF string,
       f_has_space    TYPE flag.
 
ret_sensical = if_salv_c_bool_sap=>false.
 
IF length( imp_text ) IS NOT INITIAL.
 
  SPLIT imp_text AT space INTO TABLE t_words IN CHARACTER MODE.
  IF LINES( t_words ) >= 2.
    f_has_space = 'X'.
  ELSE.
    CLEAR f_has_space.
  ENDIF.
 
  i_nb_car = length( imp_text ).
  DO i_nb_car TIMES.
 
    i_offset = sy-index - 1.
    unique_char = me=>substring( imp_str    = imp_text
                                 imp_offset = i_offset
                                 imp_length = 1 ).
 
    IF unique_char CA ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.
      READ TABLE t_unique_char WITH KEY unique_char = unique_char TRANSPORTING NO FIELDS.
      IF sy-subrc <> 0.
        st_unique_char-unique_char = unique_char.
        APPEND st_unique_char TO t_unique_char.
      ENDIF.
    ENDIF.
  ENDDO.
 
  IF LINES( t_unique_char ) >= 8.
    IF f_has_space IS NOT INITIAL.
      ret_sensical = if_salv_c_bool_sap=>true.
    ENDIF.
  ENDIF.
 
ENDIF.

TO_LOWER

Upper Case in Lower Case

CALL METHOD cl_swf_exp_wfsyst_string=>to_lower
  EXPORTING
    str       = imp_str
  RECEIVING
    str_lower = ret_str_lower.

TO_UPPER

Lower Case in Upper Case

CALL METHOD cl_swf_exp_wfsyst_string=>to_upper
  EXPORTING
    str       = imp_str
  RECEIVING
    str_upper = ret_str_upper.

TRIM

Trim for Both Sides

CALL METHOD cl_rsan_ut_string_operations=>trim
  EXPORTING
    i_input  = imp_input
  RECEIVING
    r_output = ret_output.

WRITE_CURRENCY

Writes Currency Amount in Character-Like Field

CALL METHOD cl_reca_string_services=>write_currency
  EXPORTING
    id_value    = imp_value
    id_currency = imp_currency
  RECEIVING
    rd_string   = ret_result.

WRITE_FIELD

WRITE Field INTO String

CALL METHOD cl_reca_string_services=>write_field
  EXPORTING
    id_field  = imp_field
  RECEIVING
    rd_string = ret_string.
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
start/tips/sap/string.txt · Last modified: 2016/09/28 11:53 by stephane