Using Internal Tables in SELECT Statements

 

SELECT fields FROM database table INTO TABLE t_tab (an internal table)

This does not enhance performance if the table is already buffered (SE11->technical settings) as are most configuration tables).Nor does it enhance performance unless it is executed repeated times within a program.

But it is always good practice because it makes debugging much easier and it avoids database timeouts even if the select is done only once in the program session.

Read SAMS Teach Yourself ABAP/4 in 21 Days chapter 13, "Advanced Internal Tables, Part 2 ", for an excellent guide on the use of Internal Tables. This code is the most efficient way to select data into an internal table. It populates an internal table an entire row at a time instead of populating each row one field at a time. But the initial fields in the internal table must be an exact match in the same order as the fields in the select statement. There can be additional trailing fields in the internal table that do not appear in the select statement (up, budget, actual, etc.).

If the keyword table is left out of the select statement the row goes into the header line of t_kna1 not the body. The rows would then have to be appended.. When the keyword table is used, the contents of the table are completely replaced by the result set. This is not always desirable, which is why you might like to drop the keyword, add an endselect and append the header to the table. But this is less efficient than using "for all entries in" (see special features/pitfalls) .

If it is not possible to match the select statement with the fields in the internal table, then use corresponding fields, which is only slightly less efficient than the above.

If you are modifying an existing program and you want to enhance performance with the fewest changes as possible, check out the "improving existing programs" page.