Skip to Content
-3

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

Dec 21, 2016 at 06:39 AM

198

avatar image
Former Member

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.

10 |10000 characters needed characters left characters exceeded

Sauptik,

For future reference you can refer to this standard demo program - DEMO_REGEX_TOY.

K.Kiran.

0
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Horst Keller
Dec 21, 2016 at 06:50 AM
2

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Horst,

Do you have a ready-made FM in your mind?

If so, it will be highly useful.

Thanks,

Sauptik

0

Why do you need a function module when there are build in string functions and regex handling?

1
Raghu Govindarajan Dec 21, 2016 at 11:12 AM
1

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 ) ).
Share
10 |10000 characters needed characters left characters exceeded
Richard Harper Dec 21, 2016 at 08:02 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded