Application Development and Automation 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: 
Read only

How do I do a data type check?

Former Member
0 Likes
1,039

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
Read only

Former Member
0 Likes
899

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
Read only

Former Member
0 Likes
899

Hi Kian,

Try this

If hash_value CA sy-abcde.

***Error.

ENDIF.

Regards,

Atish

Read only

Former Member
0 Likes
900

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

Read only

uwe_schieferstein
Active Contributor
0 Likes
899

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

Read only

Former Member
0 Likes
899

changes

Read only

Former Member
0 Likes
899

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