Skip to Content
avatar image
-3
Former Member

Is there any FM in SAP ABAP that can mask a set of characters in a String?

Hi Experts,

I am looking for a FM that can mask or hide a set of characters in a particular String. Let me give you an example.

  • Input:- 1234567890

Output:- ******7890

  • Input:- SAUPTIK

Output:- ***PTIK

Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Dec 21, 2016 at 06:50 AM

    That can be easily done with built-in string functions and regular expressions (if necessary).

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 21, 2016 at 11:12 AM

    Based on your example, it looks like you want the first few characters masked - not necessarily a particular set of characters masked. If that is the case you don't need regex and definitely not a function module. What you need is just good old string functions - see Processing Functions for Character-Like Arguments - ABAP Keyword Documentation. You can also use the older string manipulation statements - Statements for Character String Processing - I would suggest REPLACE SECTION.

    Here is how simple this is...

    DATA(my_var) = 'ABCDEFGHIJ'.
    DATA(mask_length) = strlen( my_var ) - 4.
    my_var = replace( val = my_var
                      off = 0
                      len = mask_length
                      with = repeat( val = '*' occ = mask_length ) ).
    Add comment
    10|10000 characters needed characters exceeded

  • Dec 21, 2016 at 08:02 AM

    As horst said - Replace with a regex - it's something I use all the time. Once you start using regexes and get used to them you'll find how powerful they are.

    Rich

    Add comment
    10|10000 characters needed characters exceeded