Skip to content

ABAP Keyword Documentation →  ABAP - Short Reference 

SELECT - Short Reference

Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


SELECT { { SINGLE [FOR UPDATE] } 
       | { [DISTINCT] { }      } }
       { *
       | { {col1|aggregate( [DISTINCT] col1 )} [AS a1]
           {col2|aggregate( [DISTINCT] col2 )} [AS a2]  ... }
       | (column_syntax) }
       FROM { { {dbtab [AS tabalias]}
              | { [(] {dbtab_left [AS tabalias_left]} | join
                      {[INNER] JOIN}|{LEFT [OUTER] JOIN}
                      {dbtab_right [AS tabalias_right] ON join_cond} [)]}
              | (dbtab_syntax) [AS tabalias] }
              [CLIENT SPECIFIED]
              [UP TO n ROWS]
              [BYPASSING BUFFER]
              [CONNECTION {con|(con_syntax)}] }
       { { INTO {[CORRESPONDING FIELDS OF] wa}|(dobj1, dobj2, ...) }
       | { INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE itab
                          [PACKAGE SIZE n] } }
       [ CREATING {  READER|LOCATOR FOR { COLUMNS col1 col2 ... }
                                 | { ALL [OTHER] [BLOB|CLOB] COLUMNS }
                    [READER|LOCATOR FOR ...] }
                | {  (crea_syntax) } ]
       [[FOR ALL ENTRIES IN itab] WHERE sql_cond]
       [GROUP BY {col1 col2 ...}|(column_syntax)]
       [HAVING sql_cond]
       [ORDER BY { {PRIMARY KEY}
                 |{{{col1|a1} [ASCENDING|DESCENDING]}
                   {{col2|a2} [ASCENDING|DESCENDING]}
                   ... }
                 | (column_syntax) }].
  ...
[ENDSELECT.].

Effect

This statement reads data from one or more database tables into data objects. If the result set is not assigned in one step, a loop is opened which is closed using ENDSELECT. This loop provides the results in the target fields.

Additions

Specification of the rows

Specification of the columns

Specification of the database table(s)

Specification of the target area

Specification of a condition

  • FOR ALL ENTRIES IN itab
    Enables you to use a logical condition for all rows in an internal table itab after WHERE.
  • WHERE sql_cond
    Restricts the result set using the condition sql_cond. The condition can consist of different logical expressions.

Specification of a grouping

  • GROUP BY { {col1 col2 ...} | (column_syntax) }
    Integrates groups of rows that have the same content in the columns col1, col2, ... into one row of the result, where you can specify the columns dynamically in column_syntax.
  • HAVING sql_cond
    Restricts rows combined in groups in the result set using a condition sql_cond.

Specification of a sorting