Application Development and Automation 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: 
Read only

Issue with FIND statement

Former Member
0 Likes
1,676

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

1 ACCEPTED SOLUTION
Read only

Ruediger_Plantiko
Active Contributor
0 Likes
1,513

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

12 REPLIES 12
Read only

Ruediger_Plantiko
Active Contributor
0 Likes
1,513

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.

Read only

0 Likes
1,513

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

Read only

yogendra_bhaskar
Contributor
0 Likes
1,513

hi rajasrikanth ,

try this :

FIND ALL OCCURRENCES OF REGEX '^4\d{15}$' in TABLE lt_text RESULTS result_tab.

regards ,

Yogendra Bhaskar

Read only

0 Likes
1,513

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 

Read only

0 Likes
1,513

<Irrelevant content removed>

Message was edited by: Suhas Saha

Read only

Ruediger_Plantiko
Active Contributor
0 Likes
1,514

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

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,513

"Hello, please get all my money"

ROFL ...

Read only

0 Likes
1,513

Hi Suhas, thanks for code formatting. However, I am missing ABAP syntax highlighting and Fixed Font layout... How to do this?

Regards, Rüdiger

Read only

0 Likes
1,513

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

Read only

0 Likes
1,513

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)...

Read only

0 Likes
1,513

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.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,513

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