‎2007 Dec 07 8:49 AM
Hi All,
LOOP AT idoc_data FROM tab_index.
Here idoc_data is a structure and not a table and tab_index holds a numeric value.
How does this statement work?
Thanks in advance
Anindya
Message was edited by:
anindya mukhopadhyay
‎2007 Dec 07 8:55 AM
Hi
It means the system'll start to loop the table from record number <b>tab_index</b>.
For example the table ITAB has 100 records, but I need to read the data only from 75th record:
LOOP AT ITAB FROM 75
These code is similar to this:
TAB_INDEX = 75.
DO.
READ TABLE ITAB INDEX TAB_INDEX.
IF SY-SUBRC <> 0. EXIT. ENDIF.
TAB_INDEX = TABX_INDEX + 1.
ENDDO.If I wants to read the record from 75th to 90th
LOOP AT ITAB FROM 75
TO 90.These code is similar to this:
AB_INDEX = 75.
DO.
READ TABLE ITAB INDEX TAB_INDEX.
IF SY-SUBRC <> 0. EXIT. ENDIF.
TAB_INDEX = TABX_INDEX + 1.
if TAB_INDEX > 90. EXIT. ENDIF.
ENDDO.So you should check how the index TAB_INDEX is calculated.
Max
‎2007 Dec 07 8:55 AM
Hi
It means the system'll start to loop the table from record number <b>tab_index</b>.
For example the table ITAB has 100 records, but I need to read the data only from 75th record:
LOOP AT ITAB FROM 75
These code is similar to this:
TAB_INDEX = 75.
DO.
READ TABLE ITAB INDEX TAB_INDEX.
IF SY-SUBRC <> 0. EXIT. ENDIF.
TAB_INDEX = TABX_INDEX + 1.
ENDDO.If I wants to read the record from 75th to 90th
LOOP AT ITAB FROM 75
TO 90.These code is similar to this:
AB_INDEX = 75.
DO.
READ TABLE ITAB INDEX TAB_INDEX.
IF SY-SUBRC <> 0. EXIT. ENDIF.
TAB_INDEX = TABX_INDEX + 1.
if TAB_INDEX > 90. EXIT. ENDIF.
ENDDO.So you should check how the index TAB_INDEX is calculated.
Max
‎2007 Dec 07 9:00 AM
Loop at itab from index l_index.
endloop.
this will start from the i_index th record and process further u can also use TO option to limit the looping.
But this will have no effect on a structure . it s used only along with itab
‎2007 Dec 07 10:02 AM
Hi,
I got some valuable insights from the answers that has been posted and Thanks to you guys for your answers.
But the fundamantal Question remains why a strusture has been used here.
‎2007 Dec 07 10:43 AM
Hi
The data IDOC_DATA has to be an internal table otherwise the stament <b>LOOP AT idoc_data FROM tab_index</b> wouldn't make a sense and the system'd generate a syntax error.
We can't know how the data IDOC_DATA is defined and why it's used: you should past the code.
I can only suppose it needs to read the data of idoc segments.
Max
‎2007 Dec 07 10:48 AM
If structure IDOC_DATA your are talking about it's the same that it's defined in DDIC, then this is a table type with a line type of structure EDIDD.
So the LOOP statement makes sense here.
Otherwise, the only structure where you can put a LOOP on is the special structure SCREEN, and that's not this case.
If I declare this:
DATA struc TYPE idoc_data.
Then struc become a table and not a structured field.
Hope this helps,
Roby.