Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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.

6 REPLIES 6

horst_keller
Product and Topic Expert
Product and Topic Expert

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

0 Kudos

Hi Horst,

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

If so, it will be highly useful.

Thanks,

Sauptik

matt
Active Contributor

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

former_member182550
Active Contributor
0 Kudos

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

raghug
Active Contributor

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 ) ).

kiran_k8
Active Contributor
0 Kudos

Sauptik,

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

K.Kiran.