Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I do a data type check?

Former Member
0 Kudos

Hi.

I was trying to do a hashtotal for a table column. It is necessary that the table column only contains numeric values. Is there a way to do a data type check, before I compute the hashtotal value? Thanks.

******************************************

LOOP AT itab INTO hash_value.

IF hash_value = NUMC. " (==> Cannot)

hash_total = hash_total + hash_value.

ENDIF.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

I would do it:

IF hash_value CO '0123456789.'.  "<=== Includes decimal
  hash_total = hash_total + hash_value.
ENDIF.

This avoids problems with special characters (#$@, etc). You may want to exclude the decimal point and/or check for only one or none of them.

Rob

5 REPLIES 5

Former Member
0 Kudos

Hi Kian,

Try this

If hash_value CA sy-abcde.

***Error.

ENDIF.

Regards,

Atish

Former Member
0 Kudos

I would do it:

IF hash_value CO '0123456789.'.  "<=== Includes decimal
  hash_total = hash_total + hash_value.
ENDIF.

This avoids problems with special characters (#$@, etc). You may want to exclude the decimal point and/or check for only one or none of them.

Rob

uwe_schieferstein
Active Contributor
0 Kudos

Hello Kian

The prevous postings provided reasonable answers to your question.

If you need to check for the type of an (itab) field then there is a specific statement available (>= 6.20 release):

DATA:
  ld_type(1)     TYPE c.

DESCRIBE FIELD ld_field TYPE ld_type.
IF ( ld_type = 'N' ).  " numeric type
...
ELSE.
...
ENDIF.

For more details please refer to the ABAP keyword documentation for DESCRIBE.

Regards

Uwe

Former Member
0 Kudos

changes

Former Member
0 Kudos

you can try this


data : text(50),
       dtyp like DD01V-DATATYPE,
       bef(15),
       aft(15).
data : dtype(1).
text = '1,234.60'.

if text co '0123456789.,'.

write : / 'numeric'.
endif.

split text at '.' into bef aft.
replace all occurrences of ',' in bef with space.
condense bef.

CALL FUNCTION 'NUMERIC_CHECK'
  EXPORTING
    STRING_IN        = bef
 IMPORTING
*   STRING_OUT       =
   HTYPE            = dtyp
          .

if dtyp cs 'NUMC'.
write : / 'Befor decimal Numeric'.
else.
write : / 'Befor decimal Character'.
endif.

clear dtyp.

CALL FUNCTION 'NUMERIC_CHECK'
  EXPORTING
    STRING_IN        = aft
 IMPORTING
*   STRING_OUT       =
   HTYPE            = dtyp
          .

if dtyp cs 'NUMC'.
write : / 'After decimal Numeric'.
else.
write : / 'After decimal Character'.
endif.

regards

shiba dutta