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: 

Loop at dynamic internal tables.

Former Member
0 Kudos

Hi,

I want to Loop at a dynamic internal table based on some field restrictions (for internal table is too large to loop it for all the entries).

I have tried: -

Loop at <tab> assigning <wa1> where aufnr = wa-aufnr.

Also i tried it using replacement paths: -

Data: lws_temp type string value 'aufnr = wa-aufnr'.

Loop at <tab> assigning <wa1> where (lws_temp).

In both cases, it is giving following error: -

In Loop...where ' the line type of the table must be statically defined.

Can I do it, and if it is not possible then how do we restrict entries in such case. I cannot define a static internal table in this case.

Regards,

Shreya

4 REPLIES 4

ravi_lanjewar
Contributor
0 Kudos

Hi,

define

FIELD-SYMBOLS: <fs_table> .

FIELD-SYMBOLS: <fs_field> TYPE ANY.

ASSIGN LOCAL COPY OF INITIAL LINE OF <tab> TO <fs_table>.

Loop at <tab> assigning <fs_table>.

ASSIGN COMPONENT 'AUFNR' OF STRUCTURE fs_table. TO <fs_field>.

if <fs_field> eq wa-aufnr.

*Werite your logic here

endif.

endloop.

Try above code

Edited by: Ravishankar Lanjewar on May 25, 2010 1:40 PM

0 Kudos

Hi,

Thanks for your prompt response.

But my concern is sy-tfill for this Loop will again give the full number of entries.

I mean condition is being checked inside the loop. Can we restrict it while looping such that only relevant entries are read.

Regards,

Shreya

matt
Active Contributor
0 Kudos

You cannot use LOOP AT WHERE with dynamic tables.

You can possibly do a more efficient loop, if your table is correctly sorted and is STANDARD or SORTED (better). You can read the first entry that matches your criteria, then loop from that point. So with a STANDARD table, sorted by AUFNR.:

READ TABLE <my_table> TRANSPORTING NO FIELDS WITH TABLE KEY ('AUFNR') = wa-aufnr BINARY SEARCH.
IF sy-subrc IS INITIAL.
  l_idx = sy-tabix.
  LOOP AT <my_table> INTO <my_wa> FROM l_idx.
    IF <aufnr> NE wa-aufnr.
      EXIT.
    ENDIF.

With a SORTED table, which is the better way of doing it, you use.

READ TABLE <my_table> TRANSPORTING NO FIELDS WITH TABLE KEY ('AUFNR') = wa-aufnr.

instead of binary search.

matt

Former Member
0 Kudos

Hi Shreya ,

In your case , to improve the performance, you will have to specifically code it , because as your table is dynamically accessed , it will not allow you for where Condition to be added.

WHERE can be specified with all table-types. After WHERE, you can specify any logical expression log_exp in which the first operand of any singular comparison is a component of the internal table. For this reason, all logical expressions are possible except for IS ASSIGNED, IS REQUESTED and IS SUPPLIED. Dynamic specification of a component through bracketed character-type data objects is not possible.

Depending upon your where condition , you can either first delete unnecessary records from ur internal table and then loop or you can copy only required records in another table and loop on that table.

Regards ,

Uma

Edited by: UmaDave on May 25, 2010 1:33 PM