Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  ABAP SQL →  ABAP SQL - Reads →  SELECT clauses →  SELECT - INTO, APPENDING 

SELECT - Assignment Rules

The following assignment rules apply to assignments of the result fields of the results set of a standalone SELECT, WITH, or FETCH statement to the target fields defined in the INTO clause.

Other versions: 7.31 | 7.40 | 7.54

Prerequisites

The following table shows the prerequisites for assigning individual columns of the results set to individual data objects - that is, for all forms of the SELECT statement, except when all columns in a work area wa are read with * and CORRESPONDING FIELDS is not specified at the same time. The table shows which data types of the result set can be assigned to which ABAP data types.

Data Type of Column in Result Set ABAP Data Type
CHAR, CLNT, CUKY, LANG, SSTRING, STRING, UNIT c, string
ACCP, NUMC c, n
LCHR c
RAW, RAWSTRING, GEOM_EWKB x, xstring
LRAW x
DF16_DEC decfloat16, decfloat34
DECFLOAT16, DF16_RAW, DF16_SCL (obsolete) decfloat16
DECFLOAT34, DF34_DEC, DF34_RAW, DF34_SCL (obsolete) decfloat34
CURR, DEC, INT1, INT2, INT4, INT8, PREC, QUAN (b, s), i, int8, p, f
FLTP f
DATN, DATS d
TIMN, TIMS t
UTCLONG utclong


Notes

  • Fields of the types STRING and RAWSTRING (LOBs) from the results set can be assigned to reference variables for LOB handles as well as to strings. The static type of these reference variables must be one of the system classes or one of the system interfaces that support streaming and locators for ABAP SQL.

Rules

The following rules apply to the assignment procedure:

  • If the target field is of data type c or x, the content of the result field is inserted left-justified into the target field. If the target field is too short, the result is truncated to the right. If the target field is too long, spaces or hexadecimal 0 are filled to the right.
  • If the target field is of data type string or xstring, the content of the result field is inserted left-justified into the target field. In result fields of the type STRING, the trailing blanks are added. The target field has the same length as the result field.
  • If the target field is of data type n, the content of the result field is inserted right-justified into the target field. If necessary, it is padded with zeros on the left. If the target field is too short, the result is truncated to the left.
  • If the target field has a numeric data type, the value of the result field is converted to this data type and the value range of the target field must be large enough. Here, any surplus decimal places in result fields of the type CURR, DEC, or QUAN (numbers in the BCD format) are cut off.
  • If the result field contains a null value, a type-dependent initial value is assigned to the target field.

For assignments of LOBs to reference variables, see LOB Handles.


Example

The variable result1 is given the value 1. Any surplus decimal places are cut off. The built-in SQL function ROUND can be used to perform roundings like in conversions in ABAP. result2 is given the value 2.

DELETE FROM demo_expressions. 
INSERT demo_expressions FROM @( VALUE #( id   = 'X' 
                                        dec2 = '1.9999999999' ) ). 

DATA result1 TYPE i. 
SELECT SINGLE 
       FROM demo_expressions 
       FIELDS dec2 
       WHERE id = 'X' 
       INTO (@result1). 

DATA result2 TYPE i. 
SELECT SINGLE 
       FROM demo_expressions 
       FIELDS ROUND( dec2,0 ) AS dec2 
       WHERE id = 'X' 
       INTO (@result2).