‎2007 Apr 24 9:30 AM
Hi friends,
i do a loop over a a table and am writing out the field contents like this:
LOOP AT <dyn_table> INTO <dyn_wa>.
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
EXIT.
else.
* Here it gets the name of the field based on the sy-index of the component
READ TABLE l_tab_fields INTO w_tab_fields INDEX sy-index.
endif.
ENDLOOP.What now doesnt work is, that whenever i have the read statement uncommented the loop doesnt increment so i only get the first row but that n-times.
any idea where the error is ?
thank you! i am awarding points generously
‎2007 Apr 24 9:34 AM
is ur loop statement correct??
If i am not wrong shouldnt it be like this
<b>LOOP AT <dyn_table> ASSIGNING <dyn_wa>.</b>
‎2007 Apr 24 9:33 AM
Hi
for the DO
ENDDO is missing.
Write it and see
LOOP AT <dyn_table> INTO <dyn_wa>.
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
EXIT.
else.
Here it gets the name of the field based on the sy-index of the component
READ TABLE l_tab_fields INTO w_tab_fields INDEX sy-index.
endif.
ENDDO.
ENDLOOP.
reward if useful
regards,
ANJI
‎2007 Apr 24 9:34 AM
is ur loop statement correct??
If i am not wrong shouldnt it be like this
<b>LOOP AT <dyn_table> ASSIGNING <dyn_wa>.</b>
‎2007 Apr 24 9:34 AM
You have to use SY-TABIX in LOOPS...
and in DO etc you have to use SY-INDEX
That's the only problem....
Tabix as you are looping at an INTERNAL TABLE data...
‎2007 Apr 24 9:35 AM
LOOP AT <dyn_table> INTO <dyn_wa>.
<b>lv_index = sy-tabix.</b>
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
EXIT.
else.
Here it gets the name of the field based on the sy-index of the component
READ TABLE l_tab_fields INTO w_tab_fields INDEX<b> lv_index.</b>
endif.
ENDLOOP.
‎2007 Apr 24 9:39 AM
‎2007 Apr 24 9:39 AM
Hi
Your code seems to be right, if LOOP doesn't increment the index it means there's only one record (?): let's know how many and which records are in DYN_TABLE and l_tab_fields.
Anyway you should use a variable to store the index of the first table:
DATA: TABIX TYPE SY-TABIX.
LOOP AT <dyn_table> INTO <dyn_wa>.
TABIX = SY-TABIX.
DO.
assign component sy-index of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
EXIT.
else.
* Here it gets the name of the field based on the sy-index of the component
READ TABLE l_tab_fields INTO w_tab_fields INDEX sy-index.
*---> Here if sy-subrc = 0, the SY-TABIX is equal to SY-INDEX.
endif.
ENDDO.
ENDLOOP.Max
‎2007 Apr 24 9:40 AM
LOOP AT <dyn_table> INTO <dyn_wa>.
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
EXIT.
else.
Here it gets the name of the field based on the sy-index of the component
READ TABLE l_tab_fields INTO w_tab_fields INDEX sy-index.
endif.
ENDLOOP.
If i gt you rite..i would suggest this
Data: l_tabix type sy-tabix.
LOOP AT <dyn_table> INTO <dyn_wa>.
l_tabix - sy-tabix.
assign component l_tabix
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
EXIT.
else.
Here it gets the name of the field based on the sy-index of the component
READ TABLE l_tab_fields INTO w_tab_fields INDEX l_tabix.
endif.
ENDLOOP.
santhosh