Home > Software design >  How to transform "Umlaute" (ü) to "ue" in the string?
How to transform "Umlaute" (ü) to "ue" in the string?

Time:07-21

I have a string which is looking like this for example Lübeck Nürnberg Österreich with "Umlaute".

Now I want to split it and add the new "words" on the string like this Lübeck Nürnberg Österreich Luebeck Nuernberg Oesterreich.

So ä should be ae, ö should be oe and ü should be ue.

But I have no clue how to achieve this, thank you!

DATA: lt_split TYPE TABLE OF char40.

SPLIT string AT space INTO TABLE lt_split.

CodePudding user response:

You can use REPLACE to replace a string with another string inside a string:

REPLACE ALL OCCURENCES OF: 'ä'
        IN string
        WITH 'ae',
        'ü'
        IN string 
        WITH 'ue'.

There is another variation of this statement, it can be used with an internal table:

REPLACE 'ä'
        IN TABLE lt_split
        WITH 'ae'.

https://help.sap.com/doc/abapdocu_751_index_htm/7.51/de-DE/abapreplace_in_pattern.htm

Please note, the new string will be longer (if at least one replacement happened), this can be a problem, if the string was character type with fixed length and the new string would be longer, than allowed.

CodePudding user response:

You can use the function module SCP_REPLACE_STRANGE_CHARS, but you have less control than replace on what is changed.

Example:

  DATA name TYPE string.

  name = 'Lübeck Österreich Haßberge Eichstätt'.

  CALL FUNCTION 'SCP_REPLACE_STRANGE_CHARS'
    EXPORTING
      intext            = name
    IMPORTING
      outtext           = name
    EXCEPTIONS
      invalid_codepage  = 1
      codepage_mismatch = 2
      internal_error    = 3
      cannot_convert    = 4
      fields_not_type_c = 5
      OTHERS            = 6.

  ASSERT name = 'Luebeck Oesterreich Hassberge Eichstaett'.

Be careful, the function module affects lots of characters with accent and lots of special characters, for instance, depending on the values of parameters, we may have these replacements:

  • á ==> AE
  • ā ==> A (Acircumflex)
  • Ă ==> Ae (Adieresis)
  • £ ==> L (sterling)
  • ß ==> ss (eszett)
  • ¼ ==> 1/4

You may use the program RSCP0007 to test the function module.

  • Related