How to Check Whether a Variable Contains a Numeric Value or Character in ABAP

Use SAP Function module NUMERIC_CHECK to check whether a variable contains numeric value or character.

DATA: g_type TYPE dd01v-datatype.
DATA: g_string(10) TYPE c.

g_string = 'Hello'.

*Check whether first character of material description is NUMERIC or CHAR
CALL FUNCTION 'NUMERIC_CHECK'
  EXPORTING
    string_in = g_string
  IMPORTING
    htype     = g_type.

WRITE:/ 'The Value ', g_string, ' is a ',g_type.

g_string = '25'.

*Check whether first character of material description is NUMERIC or CHAR
CALL FUNCTION 'NUMERIC_CHECK'
  EXPORTING
    string_in = g_string
  IMPORTING
    htype     = g_type.

WRITE:/ 'The Value ', g_string, ' is a ',g_type.

Output

abap-check-numeric-value


2 Comments

  1. IF value_entered CO ‘0123456789. ‘. (There is space after 9 and .dot and then ‘ Apostrophe and .dot)
    WRITE ‘var is numeric’.
    ELSE.
    WRITE ‘var is alphabets’.
    ENDIF.

Comments are closed.