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

Loop on table based on a dynamic variable pattern

Former Member
0 Likes
1,113

Hi,

i need to find all values that are present in an internal table that matches the pattern(value) of a given variable.

for eg:

VAR(3) type c value 'B10'.

internal table consists of the following records

___itab-field1_______

B10AAAAA

B10BBBBB

B10CCCCC

B20CCCCC

B20ddddddd

if i have to loop on this internal table to get

B10AAAAA

B10BBBBB

B10CCCCC

what would be the where condition below

loop at itab into...where ????VAR?????

endloop.

your help will be rewarded

Thanks,

gopal.

3 REPLIES 3
Read only

Former Member
0 Likes
736

Hi gopal,

you may try this:


loop at itab where field1 like 'B10_____'.   "five underscores
  ...
endloop.

Each underscore stands for any single character.

Or also:


data: l_pattern(8) type c.
concatenate var '_____' into l_pattern.
loop at itab where field1 like l_pattern.
  ...
endloop.

I hope this helps. Best regards,

Alvaro

Read only

Former Member
0 Likes
736

hi,

i write the code below. this may help.

DATA : BEGIN OF lt_table OCCURS 0,

f1(20) ,

END OF lt_table .

DATA : lv_var(3) .

lv_var = 'AAA' .

lt_table-f1 = 'AAA1'.

APPEND lt_table .

lt_table-f1 = 'AAA2'.

APPEND lt_table .

lt_table-f1 = 'BBB1'.

APPEND lt_table .

LOOP AT lt_table where f1+0(3) = lv_var.

write lt_table-f1 .

ENDLOOP.

Read only

Former Member
0 Likes
736

loop at itab where value+0(3) = var