CONV - Conversion Operator
7.31 | 7.40 | 7.54
... CONV type( [let_exp] dobj ) ...
- A non-generic data type
dtype(with the exception of reference types).
#character as a symbol for the operand type.
- If the data type required in an operand position is unique and known completely, this type is used.
- If the constructor expression is passed to an actual parameter with a generically typed formal parameter, the operand type is derived in accordance with special rules.
- In other cases, the character
#cannot be specified.
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
type must be byte-like or character-like with the type
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. For
enumerated types, special
rules apply. If
is compatible with the data type
CONV does not need to be used and a syntax check warning is usually produced.
can be specified before the data object to define local helper fields. If a
expression is specified, a warning is produced after conversions to compatible types, since
LET can be used to construct new values using helper variables.
- The conversion operator
CONVis suitable for avoiding the declaration of helper variables only needed to (for example)
- specify type-friendly actual parameters.
- specify the calculation type of an arithmetic expression or the comparison type of a relational expression.
- The argument of
CONVcan itself be a calculation expression, which means that
CONVcan be used within a calculation expression to transform results of subcalculations to a specific type.
- No empty parentheses can be specified after
CONVto construct an initial value of the specified type. The expression VALUE #( ) can be used to do this.
- The conversion operator
CONVcloses the gap where the value operator
VALUEcannot be used to construct values for elementary data objects except for the initial value.
- If a constructor expression with the conversion operator is used as a source field of an assignment where the same conversion takes place, it can be ignored and is removed when the program is compiled.
- For reference types, the conversion operator
CONVis not necessary, since these involve only castings and no conversions. The operator
CASTis used for castings.
The method CONVERT of the interface IF_ABAP_CONV_OUT of the object created
using the class CL_ABAP_CONV_CODEPAGE expects the data type
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_conv_codepage=>create_out( )->convert( source = CONV string( text ) ).
Even though the internal table
itab in the method
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. PUBLIC SECTION. TYPES t_itab TYPE STANDARD TABLE OF i WITH EMPTY KEY. METHODS meth1. PRIVATE SECTION. METHODS meth2 IMPORTING para TYPE t_itab. ENDCLASS. CLASS class IMPLEMENTATION. METHOD meth1. DATA itab TYPE SORTED TABLE OF i WITH NON-UNIQUE DEFAULT KEY. ... meth2( CONV #( itab ) ). ... ENDMETHOD. METHOD meth2. ... ENDMETHOD. ENDCLASS.
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
CONV converts each intermediate result to the calculation type
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. ... ENDIF. IF txt = CONV abap_bool( str ). ... ENDIF.