SELECT ABAP. ABAP SELECT to database SAP

Let’s look at the SELECT ABAP construct and where to start studying it. Options for reading data from ABAP dictionary tables. I will also show queries in the new and old syntax in comparison.

SELECT SINGLE. Reading one row from an ABAP table.

Often there is a need to read only one row from a SAP database table. The SELECT SINGLE ABAP construct is mainly used for this purpose. Let’s look in detail at each of the operators that make up an ABAP query.

SELECT SINGLE ABAP.

SELECT SINGLE. After this statement, we specify the fields that we want to extract from the ABAP table. There are several options for specifying fields to select from the database:

  • SELECT SINGLE * – Read all fields. Important! In this case, the client field is also considered if it is in the table. You should not abuse this method.
  • SELECT SINGLE price currency planetype – Enumerating fields
  • SELECT SINGLE price, currency, planetype – Enumerate fields in the new syntax since ABAP 7.40.

INTO IN SELECT ABAP

INTO. After this operator we indicate where to place the read data. In this case, there are also several options for specifying:

  • lNTO ls_sflight – place the data in a variable with a structure type.
  • INTO lv_price – place the data in a variable with a simple type.
  • INTO ( lv_price, lv_currency, lv_planetype ) – place each individual field in a separate variable.

ABAP SELECT in a SAP program. Simple example:

SELECT INTO TABLE AB. Reading multiple rows from an SAP table at the same time.

The situation when it is necessary to read more than one row from a table is more common in real work. Therefore, I will also give an example of a database query with reading several records:

SELECT … ENDSELECT. Line-by-line reading of records with processing in a loop.

Line-by-line reading of records with processing in the ABAP loop is already an obsolete design, since it negatively affects performance. But it is worth mentioning it to fully cover the work with the SELECT ABAP:

Write your examples in the comments, it will be useful to me and other users!

Leave a Reply