Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[ABAP] Replace unusual characters with ordinary characters in a String

DATA(unusual) = 'á Ă é Ä Ö Ü ä ö ü ß'.
DATA(pretty) = VALUE string( ).

CALL FUNCTION 'SCP_REPLACE_STRANGE_CHARS'
  EXPORTING
    intext  = unusual
  IMPORTING
    outtext = pretty.

WRITE / unusual.
WRITE / pretty. "a A e Ae Oe Ue ae oe ue ss

2 Comments

  1. Luis

    This method itself has some “unusual” characteristics, e.g. it converts uppercase text to lowercase and replaces spaces with dashes (-).

    May I suggests that you use, instead, the FM SCP_REPLACE_STRANGE_CHARS? It has a more “standard” substitution method (for example, it respects the string’s case).

    Check SAP program RSCP0155 for this function’s behavior.

    Regards,
    Luis

    1. nocin

      Hi Luis,

      thanks for your feedback! Seems like in my case, where I just had a single word without spaces, I did not notice this misbehavior.
      Just tested the function module and the result looks indeed much better. Thanks for your suggestion.
      The only letter which is not correct replaced per default is “ā”.

      á Ă ā é Ä Ö Ü ä ö ü ß
      a-a-e-ae-oe-ue-ae-oe-ue-ss

      á Ă ā é Ä Ö Ü ä ö ü ß
      a A . e Ae Oe Ue ae oe ue ss

      best regards
      Nico

Leave a Reply

Your email address will not be published. Required fields are marked *