Effect
Processes an internal table (DATA) in a loop which begins with LOOP and ends with ENDLOOP. Each of the internal table entries is sent to the output area in turn.
원문을 먼저 보자 )
When you use LOOP AT itab, the header line of the internal table itab is used as the output area (this is only possible for tables with a header line). When you use LOOP AT itab INTO wa, the explicitly specified work area wa is used as the output area. In both cases, the current table line is copied into the output area.
Loop at itab과 Loop at itab into wa의 차이점:
위 영문 번역 )
Loopt at itab을 쓰면 인터널 테이블의 헤더라인이 출력 영역으로 쓰이고(단, 테이블에 헤더라인이 있을때만..즉, data : itab like table occurs 0 with header line.으로 설정되어 있어야한다.) , Loop at itab into wa.를 쓰면 work area가 출력 영역으로 사용된다.
정리 )
Itab에 헤더가 없을때는 Loop at itab into wa.가 필요하다는 말. Itab이 헤더가 없는데도 Loop at itab.으로 하면 에러 뜸.
Loop at itab into wa. 로 할때는 itab의 sy-index가 하나씩 증가하면서 wa에 itab의 한 행씩 출력한다.
반면에, Loop at itab.만 할때는 itab의 sy-index가 하나씩 증가하면서 한 행씩 itab의 헤더에 올라와서 헤더에 출력된다.
다른 방법으로, itab이 헤더가 있는데도 불구하고 Loop at itab into wa.로 해도 에러는 뜨지 않는다. 하지만, itab의 헤더에 값이 올라오진 않고 wa에 출력된다.
예제)
REPORT Z0818_INTERNALTABLE .
DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
END OF line.
DATA: itab LIKE STANDARD TABLE OF line ,
jtab LIKE sorted table of line WITH NON-UNIQUE KEY col1.
DO 3 TIMES.
line-col1 = sy-index. line-col2 = sy-index ** 2.
APPEND line TO itab.
line-col1 = sy-index. line-col2 = sy-index ** 3.
APPEND line TO jtab.
ENDDO.
INSERT LINES OF itab INTO TABLE jtab.
LOOP AT jtab into line.
WRITE: / sy-tabix, line-col1, line-col2.
ENDLOOP.
위 예제에서 Loop at jtab into line을 Loop at jtab. 등으로 바꿔가며 Watch 해보면 이해하기가 쉽다.
출력)
프로그램 Z0818_INTERNALTABLE
1 1 1
2 1 1
3 2 4
4 2 8
5 3 9
6 3 27