12-21-2016 6:39 AM
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.
Output:- ******7890
Output:- ***PTIK
Thanks in advance.
12-21-2016 6:50 AM
That can be easily done with built-in string functions and regular expressions (if necessary).
12-21-2016 7:19 AM
Hi Horst,
Do you have a ready-made FM in your mind?
If so, it will be highly useful.
Thanks,
Sauptik
12-21-2016 10:04 AM
Why do you need a function module when there are build in string functions and regex handling?
12-21-2016 8: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
12-21-2016 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 ) ).
12-21-2016 12:42 PM
Sauptik,
For future reference you can refer to this standard demo program - DEMO_REGEX_TOY.
K.Kiran.