AT FIRST: 第一次循环时.
AT LAST: 最后一次循环时.
AT NEW f: 在一组字段的开头时. 这组字段里f和f左边的内容要完全相同.
AT END OF f: 在一组字段的结尾时. 字段同上.
*&---------------------------------------------------------------------*
*& Report ZPAB06_T_AT *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT zpab06_t_at LINE-COUNT 10.
DATA: BEGIN OF line,
col1 TYPE c,
col2 TYPE i,
col3 TYPE i,
END OF line.
DATA itab LIKE STANDARD TABLE OF line WITH HEADER LINE.
line-col1 = 'A'.
DO 3 TIMES.
line-col2 = 1.
line-col3 = sy-index ** 1.
INSERT line INTO TABLE itab.
ENDDO.
line-col1 = 'B'.
DO 3 TIMES.
line-col2 = 2 * sy-index.
line-col3 = ( 2 * sy-index ) ** 2.
INSERT line INTO TABLE itab.
ENDDO.
SORT itab BY col1 col2.
PERFORM output_last.
*&--------------------------------------------------------------------*
*& Form output_end
*&--------------------------------------------------------------------*
* at end of
*---------------------------------------------------------------------*
FORM output_end.
LOOP AT itab INTO line.
WRITE: / line-col1, 10 line-col2, 20 line-col3.
AT END OF col2.
SUM.
ULINE.
WRITE: / 'TOTAL:', 10 line-col2, 20 line-col3.
SKIP.
ENDAT.
ENDLOOP.
ENDFORM. "output_end
*&--------------------------------------------------------------------*
*& Form output_new
*&--------------------------------------------------------------------*
* at new
*---------------------------------------------------------------------*
FORM output_new.
LOOP AT itab INTO line.
WRITE: / line-col1, 10 line-col2, 20 line-col3.
AT NEW col2.
SUM.
ULINE.
WRITE: / 'TOTAL:', 10 line-col2, 20 line-col3.
SKIP.
ENDAT.
ENDLOOP.
ENDFORM. "output_new
*&--------------------------------------------------------------------*
*& Form output_last
*&--------------------------------------------------------------------*
* at last
*---------------------------------------------------------------------*
FORM output_last.
LOOP AT itab INTO line.
WRITE: / line-col1, 10 line-col2, 20 line-col3.
AT LAST.
SUM.
ULINE.
WRITE: / 'TOTAL:', 10 line-col2, 20 line-col3.
SKIP.
ENDAT.
ENDLOOP.
ENDFORM. "output_last
*&--------------------------------------------------------------------*
*& Form output_first
*&--------------------------------------------------------------------*
* at first
*---------------------------------------------------------------------*
FORM output_first.
LOOP AT itab INTO line.
WRITE: / line-col1, 10 line-col2, 20 line-col3.
AT FIRST.
SUM.
ULINE.
WRITE: / 'TOTAL:', 10 line-col2, 20 line-col3.
SKIP.
ENDAT.
ENDLOOP.
ENDFORM. "output_first
AT LAST: 最后一次循环时.
AT NEW f: 在一组字段的开头时. 这组字段里f和f左边的内容要完全相同.
AT END OF f: 在一组字段的结尾时. 字段同上.
*&---------------------------------------------------------------------*
*& Report ZPAB06_T_AT *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT zpab06_t_at LINE-COUNT 10.
DATA: BEGIN OF line,
col1 TYPE c,
col2 TYPE i,
col3 TYPE i,
END OF line.
DATA itab LIKE STANDARD TABLE OF line WITH HEADER LINE.
line-col1 = 'A'.
DO 3 TIMES.
line-col2 = 1.
line-col3 = sy-index ** 1.
INSERT line INTO TABLE itab.
ENDDO.
line-col1 = 'B'.
DO 3 TIMES.
line-col2 = 2 * sy-index.
line-col3 = ( 2 * sy-index ) ** 2.
INSERT line INTO TABLE itab.
ENDDO.
SORT itab BY col1 col2.
PERFORM output_last.
*&--------------------------------------------------------------------*
*& Form output_end
*&--------------------------------------------------------------------*
* at end of
*---------------------------------------------------------------------*
FORM output_end.
LOOP AT itab INTO line.
WRITE: / line-col1, 10 line-col2, 20 line-col3.
AT END OF col2.
SUM.
ULINE.
WRITE: / 'TOTAL:', 10 line-col2, 20 line-col3.
SKIP.
ENDAT.
ENDLOOP.
ENDFORM. "output_end
*&--------------------------------------------------------------------*
*& Form output_new
*&--------------------------------------------------------------------*
* at new
*---------------------------------------------------------------------*
FORM output_new.
LOOP AT itab INTO line.
WRITE: / line-col1, 10 line-col2, 20 line-col3.
AT NEW col2.
SUM.
ULINE.
WRITE: / 'TOTAL:', 10 line-col2, 20 line-col3.
SKIP.
ENDAT.
ENDLOOP.
ENDFORM. "output_new
*&--------------------------------------------------------------------*
*& Form output_last
*&--------------------------------------------------------------------*
* at last
*---------------------------------------------------------------------*
FORM output_last.
LOOP AT itab INTO line.
WRITE: / line-col1, 10 line-col2, 20 line-col3.
AT LAST.
SUM.
ULINE.
WRITE: / 'TOTAL:', 10 line-col2, 20 line-col3.
SKIP.
ENDAT.
ENDLOOP.
ENDFORM. "output_last
*&--------------------------------------------------------------------*
*& Form output_first
*&--------------------------------------------------------------------*
* at first
*---------------------------------------------------------------------*
FORM output_first.
LOOP AT itab INTO line.
WRITE: / line-col1, 10 line-col2, 20 line-col3.
AT FIRST.
SUM.
ULINE.
WRITE: / 'TOTAL:', 10 line-col2, 20 line-col3.
SKIP.
ENDAT.
ENDLOOP.
ENDFORM. "output_first