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: 

How can I "x-out" all but the last 4 digits of a value?

former_member210148
Participant
0 Kudos

Good day, everyone!

I searched on this topic this morning, came up with nothing, and decided to try to tackle it myself. After 5 1/2 hours, I'm throwing in the towel and need some help.

I'm writing out a simple report, and part of the output is an Account Number. I have it stored in a character field with length 10. The Account Number may be 7characters in length, while at other times it may be 9. It varies because the Account Number is coming from various bank sources, so each one has its own "standard."

For security reasons, I would like to "x-out" all but the last 4 digits of each Account Number. For example:

If the Account Number is 1234567, the report should show it as XXX4567. If the Account Number is 987654321, the report should show it as XXXXX4321. The end user viewing the report can tell the account by the last 4 digits being displayed.

I've tried all sorts of ways to get this to work, but I'm having trouble. A lot of it is getting hung up on the length of the field. I keep getting a length of 10, which I understand because the field is defined as character length 10. But I'm trying to figure out the "true" length of the field.

Does anyone have a quick, simple little ABAP routine that will handle this?

Thanks so much, and points will be awarded for all helpful answers!

Dave

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

How about this?



report zrich_0001.

data: account(10) type c value '12345678'.

data: len type i.

len = strlen( account ).
len = len - 4.

account+0(len) = 'XXXXXXXXXX'.

write:/ account.

Regards,.

Rich Heilman

4 REPLIES 4

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

How about this?



report zrich_0001.

data: account(10) type c value '12345678'.

data: len type i.

len = strlen( account ).
len = len - 4.

account+0(len) = 'XXXXXXXXXX'.

write:/ account.

Regards,.

Rich Heilman

former_member583013
Active Contributor
0 Kudos

Take a look at this -;)


REPORT ZDUMMY_ATG.

DATA: ACCOUNT(10) TYPE C,
      LONG TYPE I.

ACCOUNT = '1234567'.
LONG = STRLEN( ACCOUNT ).

LONG = LONG - 4.

WRITE:/ ACCOUNT+LONG(4).

ACCOUNT = '987654321'.
LONG = STRLEN( ACCOUNT ).

LONG = LONG - 4.

WRITE:/ ACCOUNT+LONG(4).

For the first account you get <b>4567</b> and for the second <b>4321</b>

Greetings,

Blag.

former_member210148
Participant
0 Kudos

Ah, STRLEN was what I needed! I see you both used that command, and just looking at your code, I can see I was so close.

Thanks to both of you -- points awarded!

Dave

Former Member
0 Kudos

Try this. Works for all combinations.

PARAMETERS: p_accnt(10) DEFAULT '1234567'.

DATA: v_length TYPE i,
      v_startpos TYPE i.

v_length = STRLEN( p_accnt ) - 4.
WRITE:/ p_accnt.
DO v_length TIMES.
  v_startpos = sy-index - 1.
  p_accnt+v_startpos(1) = 'X'.
ENDDO.
WRITE:/ p_accnt.

Bit late in my response I guess..)

Message was edited by:

Srinivas Adavi