11-12-2007 3:38 AM
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.
11-12-2007 4:17 AM
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
11-12-2007 3:40 AM
Hi Kian,
Try this
If hash_value CA sy-abcde.
***Error.
ENDIF.
Regards,
Atish
11-12-2007 4:17 AM
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
11-12-2007 4:34 AM
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
11-12-2007 8:04 AM
11-12-2007 8:07 AM
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