Selecting Multiple Rows Directly into an Internal Table

To select multiple rows directly into the body of an internal table, use the into table addition of the select statement. It takes the selected rows and places them into the body of an internal table in a single operation known as an array fetch operation. No work areas are used or needed.

An array operation is any statement that performs an operation on multiple rows of an internal table, instead of a single row at a time. Array operations are always more efficient than single row operations.

1ST METHOD:

SELECT LIFNR LAND1 FROM LFA1 INTO TABLE ITAB_LFA1

WHERE LAND1 = ‘DE’

2ND METHOD:

SELECT * FROM LFA1 INTO CORRESPONDING FIELDS OF TABLE ITAB_LFA1

WHERE LAND1=’DE’

Don't use an endselect with select into table. A syntax error will occur.

CONTROL BREAK PROCESSING

Use at first for:

·  Loop initialization processing

·  Writing totals at the top of a report

·  Writing headings

Use at last for:

·  Loop termination processing

·  Writing totals at the bottom of a report

·  Writing footings

Listing 9.7 Using at first to Write Headings and at last to Underline the Last Line

1 report z##0907.

2 tables lfc3.

3 data itab like lfc3 occurs 25 with header line.

4 select * from lfc3 into table itab where shbkz = 'Z'.

5 loop at itab.

6 at first.

7 write: / 'Vendor',

8 12 'Cpny',

9 17 'Year',

10 22 'Bal C/F'.

11 uline.

12 endat.

13 write: / itab-lifnr,

14 12 itab-bukrs,

15 17 itab-gjahr,

16 22 itab-saldv.

17 at last.

18 write: / '------',

19 12 '----',

20 17 '----',

21 22 '------'.

22 endat.

23 endloop.

24 free itab.

A control level is the component named on a control break statement; it regulates the control break. For example, in the following code snippet, f2 is a control level because it appears on the at new statement.

loop at itab.

at new f2.

"(some code here)

endat.

endloop.

It is said that a control break is triggered if the control level changes. This means that when the contents of the control level change, the code between the at and endat is executed.

A control break is also triggered if any of the fields prior to the control level in the structure change. Therefore, you should define the internal table structure to begin with the fields that form your control levels. You must also sort by all fields prior to and including c.