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: 

REGEX find 'SELECT FROM Z'

Former Member
0 Kudos

Hi

I'm running SAP program RS_ABAP_SOURCE_SCAN and enter string to search for as ^(?:SELECT)|(?:SELECT+\s)$ and select checkbox 'String is regular expression'.

This works okay, but it includes non-Z tables. I'd like to only get the SELECT statements from Z tables. But I'm not experienced enough and the examples I get are not clear. If you can adjust the REGEX above to extract SELECT statements only from Z tables, that would be great thanks.

Why is it required to have a similar expression split by a | character in REGEX? What is the purpose of the expression to the left and the one to the right?

Please assist.

Thanks,

Adrian

1 ACCEPTED SOLUTION

jrg_wulf
Active Contributor
0 Kudos

Hi Adrian,

try this regexp

\<(?:select\b).+(?:from z).+

the | character combines the left and right patterns with OR so either match is valid.

My above example translates as follows:

Find where select is separate word (\< and \b define word start and word end), is followed by one to many characters of no description and then is followed by 'from z" wich indicates a Z-Table. Again 1 to many characters may follow.

Try it out.

Best regards - Jörg

4 REPLIES 4

jrg_wulf
Active Contributor
0 Kudos

Hi Adrian,

try this regexp

\<(?:select\b).+(?:from z).+

the | character combines the left and right patterns with OR so either match is valid.

My above example translates as follows:

Find where select is separate word (\< and \b define word start and word end), is followed by one to many characters of no description and then is followed by 'from z" wich indicates a Z-Table. Again 1 to many characters may follow.

Try it out.

Best regards - Jörg

Former Member
0 Kudos

Brilliant! Thanks! Adrian

Former Member
0 Kudos

Most select queries are written multi-line. If FROM clause is not in same line as SELECT, regex will not give you a match.

0 Kudos

Hi Manish

In our case most of the SELECT FROM [TAB] is in the same line and the purpose of my analyses is a high level management report. So the exceptions to the data found will be dealt with when the developers get to the task level. We'll build in some fat.

Thank you and best regards,

Adrian