Copyright 2024 - BV TallVision IT

The SELECT statement is kind of a big deal in ABAP programming. SAP sits on a database server and the SELECT statement serves data into ABAP. It's is the main and only channel in fetching data, so it is good to know a thing or 2 about it. In it's simplest form:

TABLES: mara. 
SELECT-OPTIONS: 
so_matnr for mara-matnr. SELECT * FROM mara WHERE matnr IN so_matnr. * Do something with the result ENDSELECT.

The above example selects all available fields (*) from table mara (The material master) for which the material number (matnr) is specified in range variabele (select-options variabele) so_matnr. Note that the actual select statement is a loop, ending with ENDSELECT.

 

The results of a selection "round" are made available in variabele mara which is effectively made available via the TABLES: mara definition. All in all this is a working setup, and even in the early versions of SAP this would have worked. But SAP Abap has come a long way since it's early versions.

Field lists should be specified, the mara workarea is needed, but in a more useful way, the loop effect is a performance killer and puts database server power out of play, thus selection results should be placed into a table. You may find that the ENDSELECT statement is not used very often any more. Nor is the TABLES statement.

TABLES: mara. "<= for select-options definition only
TYPES: begin of ty_mara, 
         matnr type mara-matnr, 
         matkl type mara-matkl, 
       end of ty_mara. 
DATA: gt_mara type standard table of ty_mara.         
SELECT-OPTIONS: so_matnr for mara-matnr.

SELECT matnr matkl FROM mara
  INTO TABLE gt_mara 
  WHERE matnr IN so_matnr. 
* Do something with the result (internal table)

Not only is the approach more efficient for a database server (the instruction executed on the database is much larger, returning all results in a single request), this is (once you're used to it) much more efficient and readable ABAP coding as well.