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: 

Dynamically Replace substring in an Element ABAP CDS Masking

rowieforms
Participant
0 Kudos

Hi Experts!

Good day!

I am trying to mask a sensitive element in a view.

So for example, in the following data, the expected output is beside it.

Elon Musk -> E*** M***

Meta World Peace -> M*** W**** P****

Arnold Schwarzenegger -> A***** S*************

I was thinking of using a table function which uses substring and other string functions but the one thing i don't think will work is the fact that we dont know how many words will be in the field itself. This calls for a dynamic approach, some sort of loop which I know isnt possible in SQL (please correct me if Im wrong). Any thoughts?

Thanks and regards,

Erwin Formaran

1 ACCEPTED SOLUTION

rowieforms
Participant
0 Kudos

Hello everybody, just an update. This was resolved by using function replace_regex in table function.

3 REPLIES 3

former_member808116
Participant
0 Kudos
** This is bad code but it use helpful.
REPORT ZTEST.

DATA: TEXT      TYPE STRING VALUE 'Arnold Schwarzenegger',
      LV_LENGTH TYPE I,
      LV_ITEM   TYPE STRING,
      LV_RESULT TYPE STRING.

SPLIT TEXT AT SPACE INTO: DATA(STR1) DATA(STR2) DATA(STR3),
                          TABLE DATA(ITAB).

LOOP AT ITAB ASSIGNING FIELD-SYMBOL(<FS_ITAB>).
  LV_LENGTH = STRLEN( <FS_ITAB> ) - 1.
  DO LV_LENGTH TIMES.
    CONCATENATE LV_ITEM '*' INTO LV_ITEM.
  ENDDO.
  <FS_ITAB> = <FS_ITAB>+0(1) && LV_ITEM.

  IF LV_RESULT IS INITIAL.
    CONCATENATE LV_RESULT <FS_ITAB> INTO LV_RESULT.
  ELSE.
    CONCATENATE LV_RESULT <FS_ITAB> INTO LV_RESULT SEPARATED BY SPACE.
  ENDIF.
  CLEAR: LV_ITEM.
ENDLOOP.
BREAK QUYNHBC.

0 Kudos

Hi Quynh Bui Cong,

Decent code i would say. But I am looking for ABAP CDS/SQL Script not ABAP. How i wish we could do this in CDS.

Thanks anyway.

rowieforms
Participant
0 Kudos

Hello everybody, just an update. This was resolved by using function replace_regex in table function.