How loop works in internal tables with example using
any SD table?
What is the effect on INTERNAL TABLE ITAB using CLEAR
ITAB, REFRESH ITAB?
Internal table is a temporary
storage location which is only available at runtime.
Now we are defining one internal table IT_KNA1 using the
database table KNA1.
DATA : BEGIN OF IT_KNA1 OCCURS 0,
CUST_NO LIKE KNA1-KUNNR,
NAME LIKE KNA1-NAME1,
CNTRY LIKE KNA1-LAND1,
END OF IT_KNA1.
With the above statement internal
table is created with body and work area.
Now we have populated the IT_KNA1 using select statement.
Select ... from KNA1 into IT_KNA1 where.....
append IT_KNA1.
Endselect.
(or)
select... from KNA1 into table IT_KNA1 where.....
The total number of records statisfying the where condition
will enter into the internal table. First one record enters work-area of
the internal table then it gets appended into the body of the internal
table, same procedure repeats for all the records.
For displaying the data which
is in the internal table.
Loop at IT_KNA1.
WRITE :/IT_KNA1-CUST_NO, IT_KNA1-NAME, IT_KNA1-CNTRY.
ENDLOOP.
Similarly as mentioned above for entering data, for displaying
also. The first record from the body of the internal table is fetched into
the work-area and then output is displayed, and procedure repeats for all
the records in the internal table.
Notes:
How to Loop from second row in
internal table?
You can use if condition in the loop endloop.
loop at it_tab1 .
if sy-tabix > 1.
write: / it_tab1-mandt,it_tab1-matnr
.
endif.
endloop.
This skips the first record and you can continue the execution
of the statements in the loop.
Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP MM SD Consultant
Contact : serkurumsal@yandex.com
Social Plugin