[SAP ABAP] - Convert String to Number


*&---------------------------------------------------------------------*
*&      Form  fm_string_to_number
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FU_INPUT   text
*      -->FU_XFACTOR text
*      -->FC_OUTPUT  text
*----------------------------------------------------------------------*
FORM fm_string_to_number USING fu_input fu_xfactor CHANGING fc_output.
  DATA lw_usr01_exp LIKE usr01,
         lv_input(17).

  lv_input fu_input.

  CHECK NOT lv_input ' ' OR lv_input space ).
*  "Get User Profile
  CALL FUNCTION 'CETA_USR01_READ'
    EXPORTING
      bname     sy-uname
    IMPORTING
      usr01_exp lw_usr01_exp.

  "Convert String to Number
*  CALL FUNCTION 'ZHR_RU_STRING_TO_NUMBER'
*    EXPORTING
*      dcpfm  = lw_usr01_exp-dcpfm
*    IMPORTING
*      string = fc_output.

  IF lw_usr01_exp-dcpfm NE 'X'.
    REPLACE ALL OCCURRENCES OF '.' IN lv_input WITH ''.
    REPLACE ',' WITH '.' INTO lv_input.
  ELSE.
    REPLACE ALL OCCURRENCES OF ',' IN lv_input WITH ''.
  ENDIF.
  CONDENSE lv_input NO-GAPS.

  fc_output fu_xfactor * lv_input.


ENDFORM.                    "fm_string_to_number

Comments