SAP SELECT LIST ABAP Statements
Get Example source ABAP code based on a different SAP table
• , SELECT - select_list
SELECT>, select_list> Short Reference >
ABAP_SYNTAX
... *>
$| ${..., data_source>~*, ..., col_spec> $[AS alias$], ...$}>
$| (column_syntax) ...>
ABAP_ALTERNATIVES:
1 ... *>
2 ..., data_source~*, ..., col_spec $[AS alias$], ...>
3 ... (column_syntax)>
What does it do?
SELECT> list of the SELECT> clause> of a query>. The specifications determine which columns are used to construct the result set of the SELECT> statement and how their values are obtained. There are two static variants and one dynamic variant.
The SELECT> list actually passed to the database is determined by the addition INTO CORRESPONDING>>. If one or more names match, all the columns for which there are no name matches are removed from the SELECT> list implicitly and therefore from the result set as well. If there are no name matches, none of the columns are removed from the result set.
• * SELECT - select_list
ABAP Alternative 1 ... *>
What does it do?
Defines all columns of the result set using *>. The result set is constructed from all columns in the data sources> specified after FROM>>, in the order specified there. The columns of the result set inherit their names and data types from the data sources. Only a single data object can be specified after INTO>> and lists of data objects cannot be specified.
Latest notes:
If multiple DDIC database tables are specified after FROM>, it is not possible to prevent multiple columns from inheriting the same name when *> is specified.
For performance reasons, only those columns that are actually needed should be specified. *> should only be specified if the content of all columns is actually needed.
If the addition INTO CORRESPONDING>> is used, *> can be transformed implicitly to a list of columns for which there is a name match.
When an internal table @itab>> with elementary row type is accessed in the FROM> > clause of a common table expression> after WITH>>, *> cannot be specified as a SELECT> list.
NON_V5_HINTS
If UNION>>, INTERSECT>>, or EXCEPT>> is used, *> cannot be specified as a SELECT> list.
ABAP_HINT_END
ABAP_EXAMPLE_VX5
Reading of all columns with multiple rows.
ABEXA 00631
ABAP_EXAMPLE_END
ABAP Alternative 2 ..., data_source~*, ..., col_spec $[AS alias$], ...>
ABAP_VARIANTS:
1 ... data_source~* ...>
2 ... col_spec $[AS alias$] ...>
What does it do?
Comma-separated list with
data_source~*> specifying all columns of a data source data_source>> or
the definition of individual columns col_spec>> of the result set.
The individual specifications can be combined in any way, with the exception that data_source~*> cannot be used together with aggregate expressions>.
Latest notes:
NON_V5_HINTS
Specifying individual blank-separated columns is obsolete>.
When a comma-separated list is used, the syntax check is performed in a ABAP_STRICT_740_SP05 strict mode / , which handles the statement more strictly than the regular syntax check.
ABAP_HINT_END
• ~* SELECT - select_list
ABAP_VARIANT_1 ... data_source~* ...>
What does it do?
Defines multiple columns of the result set using data_source~*>, where data_source> stands for an individual DDIC database table dbtab>>,
BEGIN_SECTION VERSION 5 OUT a DDIC view view>>,
END_SECTION VERSION 5 OUT a non-abstract CDS entity cds_entity> >, or an internal table>. The result set contains all columns of the specified data source data_source> at the relevant positions and in the order of the columns. The names of the database sources or their alias names can be specified for data_source> that are also specified as data_source>> after FROM>>. A data source can also be specified more than once. If data_source~*> is used, only a structure can be specified after INTO>>, no elementary data objects or lists of data objects.
The following special conditions should be noted:
If specified, data_source~*> cannot be specified together with aggregate expressions>. It can, however, be combined with window expressions>.
When an internal table @itab>> with elementary row type is accessed in the FROM> > clause of a common table expression> after WITH>>, data_source~*> cannot be specified in the SELECT> list.
Latest notes:
For performance reasons, only those columns that are actually needed should be specified. data_source~*> should, therefore, only be specified if the content of all columns is actually needed.
The definition of the result set can also be produced by specifying a single data source data_source~*>. This defines the same result set as specifying *> but can be different if information is specified after INTO>> and the resulting behavior.
NON_V5_HINTS
If UNION>>, INTERSECT>>, or EXCEPT>> is used, data_source~*> cannot be specified in the SELECT> list.
When data_source~*> is used, the syntax check is performed in a ABAP_STRICT_740_SP08 strict mode / , which handles the statement more strictly than the regular syntax check.
ABAP_HINT_END
ABAP_EXAMPLE_VX5
Reading of the columns of two DDIC database tables in a join > into an internal table. Two columns are read from SCARR> and all columns are read from SPFLI>.
ABEXA 00632
ABAP_EXAMPLE_END
ABAP_VARIANT_2 ... col_spec $[AS alias$] ...>
ABAP Addition
... AS alias>
What does it do?
Definition of individual columns of the result set via specified columns col_spec>>, which can be defined using any SQL expressions>. The order in which the columns are specified is arbitrary and defines the order of the columns in the result set. Only if a column of the type LCHR> or LRAW > is specified explicitly as col>> must the corresponding length field also be listed directly in front of it. Different specifications can be made after INTO>>, the interaction of which is described by the column specified there.
Latest notes:
NON_V5_HINTS
The obsolete short form> without an explicitly specified target area cannot be used when specifying individual columns. The only exception here is when the aggregation function count( * )> is used to statically specify nothing, if no alias name and no GROUP BY> are specified.
Instead of using commas, blanks can be used to separate columns specified in an obsolete form>. Commas must be specified, however, in the strict modes> of the syntax check from ABAP_RELEASE ABAP_740_SP05 .
ABAP_HINT_END
ABAP_EXAMPLE_VX5
Reading of two columns from a cell in the DDIC database table SCARR >.
ABEXA 00633
ABAP_EXAMPLE_END
• AS SELECT - select_list
ABAP Addition
What does it do?
The addition AS> can be used to define an alias name alias> with a maximum of thirty characters in the result set for every specified column col_spec>. The alias name alias> must follow the naming conventions> for internal program names and the name table_line> cannot be used.
BEGIN_SECTION VERSION 5 OUT This is checked in ABAP_STRICT_777 strict mode of the syntax check from ABAP_RELEASE ABAP_777 / .
END_SECTION VERSION 5 OUT
An alias name cannot be assigned more than once and should not be the name of a column that does not have any alias names assigned to it. The alias name is used implicitly in the addition INTO$|APPENDING CORRESPONDING FIELDS OF>>. An alias name can only be specified after ORDER BY>>. A non-unique column name used after ORDER BY> causes a syntax error or an exception.
Latest notes:
If multiple DDIC database tables are specified after FROM>, alternative names can be used when specifying single columns to avoid having multiple columns with the same name.
In particular, an alias name cannot be used as the operand of an SQL expression>.
If an alias name is to be named exactly like an addition of the SELECT> statement, it may be necessary to prefix it with the escape character !> >.
NON_V5_HINTS
Outside of the ABAP_STRICT_777 strict syntax check mode from ABAP_RELEASE ABAP_777 / , it is also possible for an alias name to contain the minus sign (->), which allows assignments to be made to components of substructures with the addition CORRESPONDING FIELDS OF > in the INTO>> clause.
ABAP_HINT_END
ABAP_EXAMPLE_VX5
Display of the flight date and average fare of all customers on Lufthansa flights with flight number 0400. The alternative name avg > of the aggregate expression is required for the ORDER BY>> clause and the inline declaration using @DATA(...)>> in the INTO>> clauses.
ABEXA 00634
ABAP_EXAMPLE_END
ABAP Alternative 3 ... (column_syntax)>
What does it do?
Instead of the previous two static specifications, a data object column_syntax> in parentheses can be specified. When the statement is executed, this data object either contains the syntax shown in static cases with the exception of host expressions> or is initial.
The data object column_syntax> can be a character-like data object or a standard table> with a character-like row type. The syntax in column_syntax> is not case-sensitive, as in the static syntax. When an internal table is specified, the syntax can be distributed across multiple rows.
If column_syntax> is initial when the statement is executed, select_list> is set implicitly to *> and all columns are read.
If columns are specified dynamically without the addition SINGLE>, the result set is always regarded as having multiple rows.
Invalid syntax raises a catchable exception from the class CX_SY_DYNAMIC_OSQL_ERROR>.