02-07-2011 10:19 AM
i have 40 char text. in given text will appier like below
1) Text = 'trea 123 bett $ 2 222* 333122218888 abc"
2) Text = 'trea 123 bett $ 2 222* 3331 2221 8888 abc"
3) Text = 'trea 123 123t $ 2 222* 3331- 2221-8888 abc"
4) Text = 'trea 123 be32t $ 2 222* 3331 2221 88889 abc"
now i want to Hide this 12 or 13 digit text number with '*' this 12 or 13 digit may come with space or without space or some time may be ' - ' sign. so i want output like below.
1) Text = 'trea 123 bett $ 2 222* ************ abc"
2) Text = 'trea 123 bett $ 2 222* **** **** **** abc"
3) Text = 'trea 123 123t $ 2 222* ****- ***-*** abc"
4) Text = 'trea 123 be32t $ 2 222* **** **** ***** abc"
should not change other digit in give Text.
02-07-2011 1:54 PM
Hi anmol
There is no similarity in text this is 40 char text and user will enter credit card number any where in the that text
only hint is that its lenght will be 12 or 13 digit with space or '-' sign.
my requirment to replace only that credit card number not other digit.
1) Text = 'trea 123 bett $ 2 222 @ 333122218888 abc" O/P-> "trea 123 bett $ 2 222 @ ************ abc"
2) Text = ' 3331 2221 8888 & 123 bett $ 2 abc" O/P-> " **** **** **** & 123 bett $ 2 abc"
3) Text = ' sss 123t $ 2 222 W 3331- 2221-8888 abc" o/p-> "sss 123t $ 2 222 W ****- ***-*** abc"
4) Text = ' be32t $ 2 222 Pqr 3331 2221 88889 abc" o/p-> "be32t $ 2 222 Pqr **** **** ***** abc"
02-07-2011 11:11 AM
Hi,
you can try this:
FIND FIRST OCCURRENCE OF '*' IN str1 MATCH OFFSET POS.
POS = POS + 1.
REPLACE ALL OCCURRENCES OF '0' in str1+pos WITH '*'.
REPLACE ALL OCCURRENCES OF '1' in str1+pos WITH '*'.
REPLACE ALL OCCURRENCES OF '2' in str1+pos WITH '*'.
REPLACE ALL OCCURRENCES OF '3' in str1+pos WITH '*'.
REPLACE ALL OCCURRENCES OF '4' in str1+pos WITH '*'.
REPLACE ALL OCCURRENCES OF '5' in str1+pos WITH '*'.
REPLACE ALL OCCURRENCES OF '6' in str1+pos WITH '*'.
REPLACE ALL OCCURRENCES OF '7' in str1+pos WITH '*'.
REPLACE ALL OCCURRENCES OF '8' in str1+pos WITH '*'.
REPLACE ALL OCCURRENCES OF '9' in str1+pos WITH '*'.
regards, Dieter
02-07-2011 11:13 AM
Hi Jim,
Your question is not so clear.
As per my understanding,you can follow these steps.
1.First split the text into
V1 = trea
V2 = 123
V3 = bett
v4 = $ 2 222
V5 = 333122218888
2.than replace the V5 variable 12 or 13 with *
02-07-2011 11:41 AM
hi,
I have sample code for one string. For other use loop or perform statement
Please try following code.
Data:W_var1(40) type C,
W_var2(40) type C,
i VALUE 0.
Data:Test type string VALUE 'trea 123 bett $ 2 222 3331-2221-8888 abc'."For example
SPLIT test at '*' into w_var1 W_var2.
do 10 TIMES.
REPLACE all OCCURRENCES OF i in w_var2 with '*'.
i = i + 1.
ENDDO.
thanks
Arun
02-07-2011 11:51 AM
Hi
data: text type char50.
text = 'trea 123 bett $ 2 222* 333122218888 abc'.
text+13(1) = '*'. <----------- You can use this to replace specif letter
write text.
02-07-2011 12:51 PM
Thanks to all for your valueable reply
but this text is not fix, 12 or 13 digit may appeair any where in string like
1) Text = 'trea 123 bett $ 2 222 @ 333122218888 abc"
2) Text = ' 3331 2221 8888 & 123 bett $ 2 abc"
3) Text = ' sss 123t $ 2 222* 3331- 2221-8888 abc"
4) Text = ' be32t $ 2 222 Pqr 3331 2221 88889 abc"
so this became very difficult to find and replace. only hint is that digit having length is 12 or 13 char i.e 3331 2221 88889 .
its also dynamic number , it will change 4444 2221 77889
02-07-2011 1:32 PM
Hi Jim,
Is there any possibility of similarity so that it can be replaced.
is it will be always XXXX XXXX XXXXX kind of or it will be 12-13 continues digits like tht
Thanks,
Anmol.
02-07-2011 3:18 PM
DATA:var TYPE char63.
DATA:len TYPE i,
start TYPE i,
count TYPE i,
l_offset TYPE i,
r_offset TYPE i.
var = 'Text = trea 123 bett $ 2 222* 333122218888 abc'.
len = STRLEN( var ).
start = 1.
DO len TIMES.
sy-index = sy-index - 1.
IF var+sy-index(1) CO '1234567890'.
count = count + 1.
ELSE.
IF count = 12.
r_offset = count.
l_offset = sy-index.
EXIT.
ENDIF.
start = sy-index.
count = 0.
ENDIF.
ENDDO.
WRITE l_offset.
SKIP 1.
WRITE r_offset.
replace * from l_offset to r_offset.
02-07-2011 1:54 PM
Hi anmol
There is no similarity in text this is 40 char text and user will enter credit card number any where in the that text
only hint is that its lenght will be 12 or 13 digit with space or '-' sign.
my requirment to replace only that credit card number not other digit.
1) Text = 'trea 123 bett $ 2 222 @ 333122218888 abc" O/P-> "trea 123 bett $ 2 222 @ ************ abc"
2) Text = ' 3331 2221 8888 & 123 bett $ 2 abc" O/P-> " **** **** **** & 123 bett $ 2 abc"
3) Text = ' sss 123t $ 2 222 W 3331- 2221-8888 abc" o/p-> "sss 123t $ 2 222 W ****- ***-*** abc"
4) Text = ' be32t $ 2 222 Pqr 3331 2221 88889 abc" o/p-> "be32t $ 2 222 Pqr **** **** ***** abc"
02-07-2011 2:49 PM
Hi Jim,
wrote a test code for you, little lengthy but may helps you,
you can make small changes and use it.
PARAMETERS : CDETAILS(40) TYPE C.
DATA : STR(40) TYPE C.
DATA : BEGIN OF IT_RESULT OCCURS 0,
SUBSTR(40) TYPE C,
END OF IT_RESULT.
DATA : BEGIN OF IT_STR OCCURS 0,
IND,
END OF IT_STR.
DATA : NUM TYPE I,
OREF TYPE REF TO CX_ROOT,
TEXT TYPE STRING.
DATA : N VALUE 1,
M VALUE 4,
NUM_N,
NUM_M.
DATA : MASK_STRING(19),
MASK(19) VALUE '**** **** **** ****'.
DATA : FLAG_DONE.
DATA : FIRST VALUE 'X'.
MOVE CDETAILS TO STR.
SPLIT STR AT SPACE INTO TABLE IT_RESULT.
DELETE IT_RESULT WHERE SUBSTR IS INITIAL .
LOOP AT IT_RESULT.
TRY.
NUM = IT_RESULT-SUBSTR.
CATCH CX_SY_CONVERSION_NO_NUMBER INTO OREF .
TEXT = OREF->GET_TEXT( ).
ENDTRY.
IF TEXT IS INITIAL.
IT_STR-IND = SY-TABIX.
APPEND IT_STR.
ENDIF.
CLEAR : IT_STR, TEXT, NUM.
ENDLOOP.
DO.
LOOP AT IT_STR WHERE IND BETWEEN N AND M.
IF SY-TABIX = 4.
NUM_N = N.
NUM_M = M.
FLAG_DONE = 'X'.
EXIT.
ENDIF.
ENDLOOP.
ADD 1 TO M.
ADD 1 TO N.
IF FLAG_DONE = 'X'.
EXIT.
ENDIF.
ENDDO.
LOOP AT IT_RESULT FROM NUM_N TO NUM_M.
IF FIRST = 'X'.
MASK_STRING = IT_RESULT-SUBSTR.
CLEAR FIRST.
ELSE.
CONCATENATE MASK_STRING IT_RESULT-SUBSTR INTO MASK_STRING SEPARATED BY SPACE.
ENDIF.
ENDLOOP.
REPLACE MASK_STRING WITH MASK INTO STR.
WRITE : STR.
Thanks,
Anmol
02-07-2011 5:37 PM
Hi Jim,
I have developed following code and it works perfectly to display the 12 or 13 character of credit card number as per your requirement. Only catch here is you need to add logic for including space ' ' in the character. Other wise it is perfect now.
Please let me know if you are not able to find logic for taking space into consideration.
REPORT ZSTRING_MANU .
data: text type string,
c2(11) type c value '0123456789-',
lv_data(13) type c,
lv_len type i,
lv_index1 type i.
text = 'trea 123 bett $ 2 222* 33312-118888 abc'.
data lv_index type i.
field-symbols <fs> type any.
assign text to <fs>.
lv_len = strlen( text ).
do lv_len times.
if strlen( lv_data ) >= 12.
exit.
endif.
if lv_index > lv_index1.
lv_index1 = lv_index.
endif.
if sy-index ne 1.
lv_index1 = lv_index1 + 1.
endif.
if <fs>+lv_index1(1) CA c2.
clear lv_data.
lv_index = lv_index1.
do 13 times.
if sy-index ne 1.
lv_index = lv_index + 1.
endif.
if <fs>+lv_index(1) CA c2.
concatenate lv_data <fs>+lv_index(1) into lv_data.
else.
exit.
endif.
enddo.
else.
continue.
endif.
enddo.
write lv_data.
Regards
Ram
02-10-2011 11:35 AM
02-10-2011 11:37 AM