[ABAP] String (Char) nach Float konvertieren

Variante 1 (CL_ABAP_CONTAINER_UTILITIES mit Float)

* String
DATA(lv_str_val) = |123.45|.
* Float
DATA: lv_float TYPE f.

* String -> Float
cl_abap_container_utilities=>read_container_c( EXPORTING
                                                 im_container = lv_str_val
                                               IMPORTING
                                                 ex_value     = lv_float ).

WRITE: / lv_float.

Variante 2 (CL_ABAP_CONTAINER_UTILITIES mit decfloat34)

* String
DATA(lv_str_val) = |123.45|.
* Float
DATA: lv_float TYPE decfloat34.

* String -> Float
cl_abap_container_utilities=>read_container_c( EXPORTING
                                                 im_container = lv_str_val
                                               IMPORTING
                                                 ex_value     = lv_float ).

WRITE: / lv_float.

Variante 3 (RS_CONV_EX_2_IN)

* Währungsbetrag wandeln
DATA: lv_value_in TYPE string VALUE '31,60'. " Eingabetyp und Wert
DATA: lv_value_out TYPE konp-kbetr.          " Ausgabetyp

DATA(lv_tabfield) = VALUE tabfield( tabname   = 'KONP'
                                    fieldname = 'KBETR' ).

CALL FUNCTION 'RS_CONV_EX_2_IN'
  EXPORTING
    input_external               = CONV char30( condense( val = lv_value_in ) )
    table_field                  = lv_tabfield
  IMPORTING
    output_internal              = lv_value_out
  EXCEPTIONS
    input_not_numerical          = 1
    too_many_decimals            = 2
    more_than_one_sign           = 3
    ill_thousand_separator_dist  = 4
    too_many_digits              = 5
    sign_for_unsigned            = 6
    too_large                    = 7
    too_small                    = 8
    invalid_date_format          = 9
    invalid_date                 = 10
    invalid_time_format          = 11
    invalid_time                 = 12
    invalid_hex_digit            = 13
    unexpected_error             = 14
    invalid_fieldname            = 15
    field_and_descr_incompatible = 16
    input_too_long               = 17
    no_decimals                  = 18
    invalid_float                = 19
    conversion_exit_error        = 20
    OTHERS                       = 21.

IF sy-subrc = 0.
  WRITE: / lv_value_out.
ENDIF.