2012 Jul 24 5:22 PM
HI Experts,
My requirement is to replace all the real credit card numbers exist in the TEXTS present in Sales orders and Customer masters with some different numbers .
It is some what difficult to find where exactly credit card number is present in the TEXT fields as it is free flowing text .
I am using FIND keyword to get the credit card numbers .
FIND ALL OCCURRENCES OF REGEX '5+[0-9]* ' in TABLE lt_text RESULTS result_tab.
Please suggest me what regular expression i need to use to search the credit card numbers .
For example : credit card number may be VISA starts with 4 followed by 15 numbers . it may be 4346781011211234 or 4346 7810 1121 0986 .
I need to extract this number from Header TEXT and send it to other system .
Please provide your valuable suggestions .
Thanks in advance
Regards
Rajasrikanth
2012 Jul 25 11:26 AM
OK, you need "progressive matching"
Try this.
Regards, Rüdiger
*&---------------------------------------------------------------------*
*& Report ZZ_CHECK_VISA_NUMBER
*&---------------------------------------------------------------------*
report zz_check_visa_number.
start-of-selection.
perform start.
* ---
form start.
data: lv_text type string,
lt_lines type tsftext,
lv_line type i,
lv_off type i,
lv_moff type i,
lv_mlen type i,
lv_match type string.
field-symbols: <ls_line> type tline.
perform build_some_lines changing lt_lines.
loop at lt_lines assigning <ls_line>.
lv_line = sy-tabix.
lv_off = 0.
while lv_off < strlen( <ls_line>-tdline ).
find all occurrences
of regex '\b(4(\d\s*){15})\b'
in section offset lv_off of <ls_line>-tdline
submatches lv_match
match offset lv_moff
match length lv_mlen.
if sy-subrc eq 0.
lv_off = lv_moff + lv_mlen.
condense lv_match no-gaps.
skip.
write: / 'Line:', lv_line,
/ 'Offset:', lv_moff,
/ 'Match:', lv_match.
else.
exit. " while
endif.
endwhile.
endloop.
endform. "start
*----------------------------------------------------------------------*
form build_some_lines changing ct_lines type tsftext.
data: ls_line type tline.
define _add.
ls_line-tdformat = '*'.
ls_line-tdline = &1.
append ls_line to ct_lines.
end-of-definition.
clear ct_lines.
_add :
'Hello, please get all my money ',
'from CC no 4346 7810 1121 1234',
'With kind regards'.
endform. "build_some_lines<added code formatting>
Message was edited by: Suhas Saha
2012 Jul 24 6:39 PM
Hi Rajasrikanth,
For example : credit card number may be VISA starts with 4 followed by 15 numbers . it may be 4346781011211234 or 4346 7810 1121 0986 .
Suppose the text field p_input contains the string as input by the user.
Then:
data: lv_text type string.
lv_text = p_input.
condense lv_text no-gaps.
find regex '^4\d{15}$' in lv_text.
if sy-subrc eq 0.
* Valid
endif.
2012 Jul 25 9:37 AM
Hi
Thanks for the reply .
i need to search this credit card number in a free flow text(like Sales order Header text) .
the 16 digit credit card number may be entered in any ways .
case 1: in texts all the 16 numbers exist with out any spaces .ex :4346781011211234
case 2 : all the 16 numbers separated by spaces or tab delimited.
ex :4346 7810 1121 1234
I need to give
generalized Regular expression to find the credit card number in TEXTS.
Regards
Raja
2012 Jul 25 10:17 AM
hi rajasrikanth ,
try this :
FIND ALL OCCURRENCES OF REGEX '^4\d{15}$' in TABLE lt_text RESULTS result_tab.
regards ,
Yogendra Bhaskar
2012 Jul 25 10:38 AM
Hi Yogendra
I think it searches only 16 digits credit card number if they are continuous digits .
please explains what exactly it searches and the functionality of REGEX you suggested .
Regards
Rajasrikanth
2012 Jul 25 11:31 AM
<Irrelevant content removed>
Message was edited by: Suhas Saha
2012 Jul 25 11:26 AM
OK, you need "progressive matching"
Try this.
Regards, Rüdiger
*&---------------------------------------------------------------------*
*& Report ZZ_CHECK_VISA_NUMBER
*&---------------------------------------------------------------------*
report zz_check_visa_number.
start-of-selection.
perform start.
* ---
form start.
data: lv_text type string,
lt_lines type tsftext,
lv_line type i,
lv_off type i,
lv_moff type i,
lv_mlen type i,
lv_match type string.
field-symbols: <ls_line> type tline.
perform build_some_lines changing lt_lines.
loop at lt_lines assigning <ls_line>.
lv_line = sy-tabix.
lv_off = 0.
while lv_off < strlen( <ls_line>-tdline ).
find all occurrences
of regex '\b(4(\d\s*){15})\b'
in section offset lv_off of <ls_line>-tdline
submatches lv_match
match offset lv_moff
match length lv_mlen.
if sy-subrc eq 0.
lv_off = lv_moff + lv_mlen.
condense lv_match no-gaps.
skip.
write: / 'Line:', lv_line,
/ 'Offset:', lv_moff,
/ 'Match:', lv_match.
else.
exit. " while
endif.
endwhile.
endloop.
endform. "start
*----------------------------------------------------------------------*
form build_some_lines changing ct_lines type tsftext.
data: ls_line type tline.
define _add.
ls_line-tdformat = '*'.
ls_line-tdline = &1.
append ls_line to ct_lines.
end-of-definition.
clear ct_lines.
_add :
'Hello, please get all my money ',
'from CC no 4346 7810 1121 1234',
'With kind regards'.
endform. "build_some_lines<added code formatting>
Message was edited by: Suhas Saha
2012 Jul 25 11:51 AM
2012 Jul 25 12:42 PM
Hi Suhas, thanks for code formatting. However, I am missing ABAP syntax highlighting and Fixed Font layout... How to do this?
Regards, Rüdiger
2012 Jul 25 1:29 PM
Abap fomatting was much better in the past (legacy SCN, we love it) and will be introduced on new facebook-scn after all other bugs have been fixed
For the time being, make a screenshot of ABAP editor
Regards
Clemens
2012 Jul 25 1:34 PM
For the time being, make a screenshot of ABAP editor
Clemens, this statement should have a smiley, too! 🙂
With a screenshot, the text cannot be handled as text (consider text search and Copy&Paste)...
2012 Jul 25 1:37 PM
Remark: ... The "all occurrences" in report zz_check_visa_number was wrong & has to be deleted.
find all occurrences
of regex '\b(4(\d\s*){15})\b'
in section offset lv_off of <ls_line>-tdline
submatches lv_match
match offset lv_moff
match length lv_mlen.
2012 Jul 25 1:58 PM
Hello Rudiger,
When you reply to a post on the top right-hand corner you will find the "Use Advance Editor" link, click it & explore
- Completely agree with you. In the legacy SCN (and i love it too) the ABAP code formatting was much better. I'll let the "the powers that be" take a call on this, until then let's make the most of what we have at our disposal.
Cheers,
Suhas