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

Dynamic LOOP in Internal Table Error

Former Member
0 Likes
436

Hi,

I have Dynamic Internal Table : <LT_TX>



<LT_TX>

Col A        Time           Number
A1              01.2011        10
A2              02.2011         10
A1              03. 2011         10

How do I do LOOP AT on <LT_TX> with KEY COLA = A1 and hence ONLY LOOP AT 'A1' in THIS DYNAMIC INTERNAL TABLE.



if I do like this, below i get an error, how to only LOOP AT A1 ones ?

data: firstcol type string value 'ColA'.

LOOP AT <LT_TX> ASSIGNING <LS_TX> WHERE (firstcol) = 'A1'.

ERROR:  in LOOP ... WHERE the line type of the table must be statically defined.

Advice please

1 ACCEPTED SOLUTION
Read only

former_member209703
Active Contributor
0 Likes
399

You can't have a dynamic where in this case.



FIELD-SYMBOS: <FIELD_1> TYPE ANY.

LOOP AT <LT_TX> ASSIGNING <LS_TX>.    "WHERE (firstcol) = 'A1'.

ASSIGN COMPONENT 1 OF STRUCTURE <LS_TX> TO <FIELD_1>.
IF <FIELD_1> EQ 'A1'.


ENDIF.

....
ENDLOOP.

2 REPLIES 2
Read only

Former Member
0 Likes
399

Hi

You can't do a dynamic where condition in the LOOP, yo can use something like that with READ statament, but that means it can read one record only

If you need to use the LOOP, you can only use the CHECK statament:

LOOP AT <LT_TX> ASSIGNING <LS_TX>.
  ASSIGN COMPONENT (FIRSTCOL) OF STRUCTURE <LS_TX> TO <FS_TX>.
  CHECK <FS_TX> = 'A1'.

Max

Read only

former_member209703
Active Contributor
0 Likes
400

You can't have a dynamic where in this case.



FIELD-SYMBOS: <FIELD_1> TYPE ANY.

LOOP AT <LT_TX> ASSIGNING <LS_TX>.    "WHERE (firstcol) = 'A1'.

ASSIGN COMPONENT 1 OF STRUCTURE <LS_TX> TO <FIELD_1>.
IF <FIELD_1> EQ 'A1'.


ENDIF.

....
ENDLOOP.