Skip to content

ABAP Keyword Documentation →  ABAP - Quick Reference 

SELECT - Quick reference

Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


SELECT [SINGLE [FOR UPDATE]] 
       { [DISTINCT] { *
                    | { ..., data_source~, ..., sql_exp} [AS alias], ... }
                    | (column_syntax)
         FROM { { {data_source [WITH PRIVILEGED ACCESS] [AS tabalias]}
                | { [(] {data_source [WITH PRIVILEGED ACCESS] [AS tabalias]}|join
                      {[INNER] JOIN}|{LEFT|RIGHT [OUTER [MANY TO ONE]] JOIN}|{CROSS JOIN}
                         {data_source [WITH PRIVILEGED ACCESS] [AS tabalias]}|join [ON join_cond]  [)] }
                | (source_syntax) [WITH PRIVILEGED ACCESS] [AS tabalias] }
                [ {USING CLIENT clnt}
                | {USING CLIENTS IN @client_range_tab}
                | {USING CLIENTS IN T000}
                | {USING ALL CLIENTS}
                | {CLIENT SPECIFIED [entity1~clnt] [, entity2~clnt] ...} ] } }
     | { FROM { { {data_source [WITH PRIVILEGED ACCESS] [AS tabalias]}
                | { [(] {data_source [WITH PRIVILEGED ACCESS] [AS tabalias]}|join
                      {[INNER] JOIN}|{LEFT|RIGHT [OUTER [MANY TO ONE]] JOIN}|{CROSS JOIN}
                         {data_source [WITH PRIVILEGED ACCESS] [AS tabalias]}|join [ON join_cond]  [)] }
                | (source_syntax) [AS tabalias] }
                [ {USING CLIENT clnt}
                | {CLIENT SPECIFIED [entity1~clnt] [, entity2~clnt] ...} ] }
         FIELDS [DISTINCT]
                { *
                | { ..., data_source~
, ..., sql_exp} [AS alias], ... }
                | (column_syntax) }
       [[FOR ALL ENTRIES IN itab] WHERE sql_cond]
       [GROUP BY { sql_exp1| grouping_sets1, sql_exp2| grouping_sets2, ...}|(column_syntax)]
       [HAVING sql_cond]
       [UNION ALL|DISTINCT SELECT ...]
       [ORDER BY { {PRIMARY KEY}
                 |{{{col1|alias1} [ASCENDING|DESCENDING],}
                   {{col2|alias2} [ASCENDING|DESCENDING],}
                   ... }
                 | (column_syntax) }].
       { { INTO ([NEW] @dobj1|@DATA(dobj1), [NEW] @dobj2|@DATA(dobj2), ...) }
       | { INTO [CORRESPONDING FIELDS OF] [NEW] @wa [INDICATORS {[NOT] NULL STRUCTURE null_ind}
                                                        | (indicator_syntax)] }
       | { INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE [NEW] @itab
                          [INDICATORS {[NOT] NULL STRUCTURE null_ind}
                                    | (indicator_syntax)]
                          [PACKAGE SIZE n] }
       | { INTO [NEW] @DATA(wa) [INDICATORS {[NOT] NULL STRUCTURE null_ind}
                                    | (indicator_syntax)]}
       | { INTO TABLE [NEW] @DATA(itab) [INDICATORS {[NOT] NULL STRUCTURE null_ind}
                                            | (indicator_syntax)]
                                  [PACKAGE SIZE n] } }
       [ EXTENDED RESULT @oref ]
       [ CREATING {  READER|LOCATOR FOR { COLUMNS col1 col2 ... }
                                 | { ALL [OTHER] [BLOB|CLOB] COLUMNS }
                    [READER|LOCATOR FOR ...] }
                | {  (crea_syntax) } ]
       [UP TO n ROWS]
       [OFFSET o]
       [BYPASSING BUFFER]
       [CONNECTION con|(con_syntax)]
  ...
[ENDSELECT.]

Effect

ABAP SQL statement. This statement reads data from one or more data sources into data objects. If the results 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

Specifying the Rows

  • SINGLE - Defines a single row results set. The results set is multirow by default.
  • FOR UPDATE - Sets an exclusive lock on a single row in the database.

Structure of the Results Set

  • FIELDS - Required if the FROM clause was specified first.
  • DISTINCT - Removes duplicate rows from the results set.
  • * - Reads all columns of all data sources.
  • data_source~* - Reads all columns of the specified data source.
  • sql_exp [AS alias] - Reads the result of an SQL expression and assigns an alias name alias (optional).
  • (column_syntax) - Specifies the columns as the content of column_syntax.

Specifying the Database Table(s)

Specifying a Condition

  • FOR ALL ENTRIES IN itab
    Enables a condition to be used after WHERE on all rows in an internal table itab.
  • WHERE sql_cond
    Restricts the results set using the condition sql_cond. The condition can consist of different relational expressions.

Specifying a Grouping

Specifying a Union

Specifying a Sort

Specifying the Target Area

Specifying Additions