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

Itab - field selection at runtime

Former Member
0 Likes
485

Hello,

I need to select lines from one internal table (with a large number of fields) based on different fields. E.g.

Table: zitab1

Fields: field1, field2, ..., fieldN

If I want to go through the table based on fields: field1, field2 and field3, I have to use the following code:

LOOP AT ZITAB1 WHERE FIELD1 EQ 'SEARCH_KEY'.

...

ENDLOOP.

LOOP AT ZITAB1 WHERE FIELD2 EQ 'SEARCH_KEY'.

...

ENDLOOP.

LOOP AT ZITAB1 WHERE FIELD3 EQ 'SEARCH_KEY'.

...

ENDLOOP.

Is there a way to read the itab using field selection at runtime so I can replace all these separate loop statements with a single statement, e.g.

LOOP AT ZITAB1 WHERE (FIELD) EQ 'SEARCH_KEY'.

...

ENDLOOP.

where (FIELD) can be specified to be any of the fields in the table zitab1?

Help is appreciated.

Regards

Edited by: Khan Awkhan on Nov 18, 2008 7:04 AM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
454

Hi Khan,

By using field-symbols, i think this might be possible.

First define this LOOP in a sub-routine to which you pass the field name as a parameter.

Then, you can use the syntax

ASSIGN COMPONENT OF .......

to assign the field name to a field-symbol. Pass this as the parameter to the sub-routine.

In the sub-routine, while looping, you can try using this parameter (Field-Symbol) and check against the search key (This can also be passed using a field-symbol).

Try this. I think you should be able to crack it.

Best Regards,

Ram.

2 REPLIES 2
Read only

Former Member
0 Likes
455

Hi Khan,

By using field-symbols, i think this might be possible.

First define this LOOP in a sub-routine to which you pass the field name as a parameter.

Then, you can use the syntax

ASSIGN COMPONENT OF .......

to assign the field name to a field-symbol. Pass this as the parameter to the sub-routine.

In the sub-routine, while looping, you can try using this parameter (Field-Symbol) and check against the search key (This can also be passed using a field-symbol).

Try this. I think you should be able to crack it.

Best Regards,

Ram.

Read only

Former Member
0 Likes
454

Hi:

Try to use Subroutine by passing the field name and its value.

Regards

Shashi