SAP NetWeaver AS ABAP Release 750, ©Copyright 2016 SAP AG. All rights reserved.ABAP - Keyword Documentation → ABAP - Reference → Processing Internal Data → Assignments →
CONV - Conversion Operator
... CONV type( [let_exp] dobj ) ...
A constructor expression with the conversion operator CONV converts the argument dobj to the data type specified using type and creates an appropriate result. The following can be specified for type:
The parentheses must contain precisely one unnamed argument dobj that can be converted to the data type type, with the following restriction: If dobj is specified as a bit expression, type must be byte-like or character-like with the type c or string. dobj is a general expression position.
The content of the result is determined by an assignment of the argument in accordance with the associated conversion rule. If dobj is compatible with the data type type, CONV does not need to be used and a syntax check warning is usually produced.
Optionally, a LET expression let_exp can be specified before the data object to define local auxiliary fields. If a LET expression is specified, a warning is produced after conversions to compatible types, since LET can be used to construct new values using utility variables.
The method CONVERT_TO of the class CL_ABAP_CODEPAGE expects the data type string for the input parameter SOURCE. CONV is used to convert a text field to this data type, directly in the operand position.
DATA text TYPE c LENGTH 255.
DATA(xstr) = cl_abap_codepage=>convert_to(
source = CONV string( text )
codepage = `UTF-8` ).
Even though the internal table itab in the method meth1 has the same row type as the table type of the parameter para of the method meth2, it cannot be passed directly due to its different table category and key. CONV is used to convert itab to the required table type.
CLASS class DEFINITION.
TYPES t_itab TYPE STANDARD TABLE OF i
WITH EMPTY KEY.
METHODS meth2 IMPORTING para TYPE t_itab.
CLASS class IMPLEMENTATION.
DATA itab TYPE SORTED TABLE OF i
WITH NON-UNIQUE DEFAULT KEY.
meth2( CONV #( itab ) ).
The two calculations produce different results. In the first case, the calculation type is f and the end result is converted to i. In the second case, CONV converts each intermediate result to the calculation type i.
DATA int TYPE i.
int = sqrt( 5 ) + sqrt( 6 ).
int = CONV i( sqrt( 5 ) ) + CONV i( sqrt( 6 ) ).
The first logical expression is false, as specified in the comparison rules for character-like data types. CONV is used to alter the comparison type of the second comparison so that the comparison is true.
DATA txt TYPE abap_bool.
DATA str TYPE string.
txt = ' ' .
str = ` `.
IF txt = str.
IF txt = CONV abap_bool( str ).