ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Assignments → Lossless Assignments → Lossless Assignments - Rules → Checking Elementary Data Objects
Lossless Assignment
This example demonstrates how the operator EXACT
is used to make lossless assignments.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA: text TYPE string VALUE `4 Apples + 3 Oranges`,
num_text TYPE n LENGTH 8.
DATA(out) = cl_demo_output=>new(
)->begin_section( text
)->begin_section( `Not really exact:` ).
num_text = text.
out->write_data( num_text
)->next_section( `Try to be exact:` ).
TRY.
num_text = EXACT #( text ).
out->write_data( num_text ).
CATCH cx_sy_conversion_error INTO DATA(exc).
out->write_text( exc->get_text( ) ).
ENDTRY.
out->display( ).
Description
Without the operator EXACT
, text
is assigned to num_text
without the validity of the assigned value being checked against the associated
conversion rules. This produces a value that is not very intuitive, "00000043".
Using the operator EXACT
, the value that is passed is checked and an exception is raised in the case in question.