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

Loop Statement

Anindya
Explorer
0 Likes
736

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
695

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

5 REPLIES 5
Read only

Former Member
0 Likes
696

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

Read only

Former Member
0 Likes
695

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

Read only

0 Likes
695

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.

Read only

0 Likes
695

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

Read only

0 Likes
695

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.