SELECT Fields, WHERE Conditions and the Cost of SELECT *
Learn why field selection and WHERE conditions are the first rules of Open SQL performance.
Explanation
The first rule of Open SQL is simple: read only what you need. SELECT * may look convenient, but it often brings unnecessary columns into application server memory. On small tables, the difference may not be visible. On large transactional tables, it can increase network transfer, memory usage and runtime. A good Open SQL query should specify required fields and apply meaningful WHERE conditions. In real projects, many reports become slow not because ABAP is weak, but because the query reads too much data and filters later in ABAP. The database is designed to filter data efficiently, so filtering should happen as early as possible. A strong ABAP developer should always ask: Which fields are required? Which keys or filters reduce the result set? Can I avoid reading unnecessary records?
Code example
* Bad patternSELECT * FROM bkpf INTO TABLE @DATA(lt_bkpf_all). DELETE lt_bkpf_all WHERE bukrs <> @p_bukrs. * Better patternSELECT bukrs, belnr, gjahr, blart, budat FROM bkpf INTO TABLE @DATA(lt_bkpf) WHERE bukrs = @p_bukrs AND gjahr = @p_gjahr.Real project scenario
A finance extraction report reads BKPF and BSEG data for one fiscal year but initially uses SELECT * and filters company code later in ABAP. Runtime improves significantly after selecting only required fields and adding BUKRS and GJAHR in the WHERE condition.
Common mistakes
- Using SELECT * for convenience. - Filtering large result sets in ABAP instead of database. - Selecting fields that are never used later. - Forgetting key fields in WHERE conditions.
Best practices
- Select only required fields. - Use WHERE conditions with business keys. - Avoid application-side filtering for large datasets. - Measure with ST05 if query performance is doubtful.
Interview angle
A good interview answer should say that SELECT * increases data transfer and memory usage, and that WHERE conditions should reduce records at database level.