‎2007 Jan 04 5:28 AM
Hi all,
My requiremtn is to validate a field to contain only numeric characters and one decimal.
Problem is if i give more than 1 decimal also, CO returns success. It sould fail on encountering more than one decimal.
If you have any inputs, please let me know.
Thanks and regards,
Ridhima
‎2007 Jan 04 6:12 AM
Hi Ridhima ,
Here is a sample code which does exacyly what you want to acheive
Data : v1(10) ,
s1(10),
s2(10).
v1 = '19.0.'.
split v1 at '.' into s1 s2 .
if s2 ca '.' .
write 'error'.
else.
write 'ok'.
endif.
Please do revert back in case of further queries.
Regards
Arun
‎2007 Jan 04 5:33 AM
just take two char variables
data : c1(10),
c2(10),
c3(10).
split <your field> at '.' into c1 c2 c3.
if c3 ne ''.
<give error >
endif.
regards
shiba dutta
Message was edited by:
SHIBA DUTTA
‎2007 Jan 04 5:47 AM
Thanks for reply.
But this logic will fail if i have value '19.3.'
‎2007 Jan 04 5:59 AM
yes ridhima it will fail for your condition sorry i dint think about that.
then you have only option to check whole string byte by byte.
i.e.
data : len type i,
c1
counter type i ,
occurnc type i.
compute len = strlen( str ).
do len times.
c1 = str+counter(1).
if c1 = '.'.
occurnc = occurnc + 1.
endif.
counter = counter + 1.
enddo.
if occurnc gt 2 show the error.
it may work
regards
shiba dutta
Message was edited by:
SHIBA DUTTA
‎2007 Jan 04 6:11 AM
Hello Ridhima
Here is a possible solution for your problem.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_CHECK_NUMERIC_AND_DEC
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_check_numeric_and_dec.
DATA:
gd_value_1 TYPE p DECIMALS 1,
gd_value TYPE p DECIMALS 10,
gd_diff TYPE p DECIMALS 10,
gd_int TYPE i.
PARAMETERS:
p_value TYPE char10,
p_digits TYPE numc01 OBLIGATORY DEFAULT '1'.
START-OF-SELECTION.
gd_value = p_value.
DO p_digits TIMES.
gd_value = gd_value * 10.
ENDDO.
gd_int = gd_value DIV 1.
gd_diff = gd_value - gd_int.
IF ( gd_diff = 0 ).
MESSAGE 'Decimals o.k.' TYPE 'S'.
ELSE.
MESSAGE 'Decimals not o.k.' TYPE 'S'.
ENDIF.
* Simple version if number of digit is fixed
gd_value = p_value.
gd_value_1 = p_value.
IF ( gd_value = gd_value_1 ).
MESSAGE 'Decimals o.k.' TYPE 'S'.
ELSE.
MESSAGE 'Decimals not o.k.' TYPE 'S'.
ENDIF.
END-OF-SELECTION.Regards
Uwe
‎2007 Jan 04 6:12 AM
Hi Ridhima ,
Here is a sample code which does exacyly what you want to acheive
Data : v1(10) ,
s1(10),
s2(10).
v1 = '19.0.'.
split v1 at '.' into s1 s2 .
if s2 ca '.' .
write 'error'.
else.
write 'ok'.
endif.
Please do revert back in case of further queries.
Regards
Arun
‎2007 Jan 04 6:28 AM
just check this with the input "a1d23.24.66
and see if this is working for your criteria.
parameters : val(30) type c.
data : final(30) type c,
cnt type i,
dotcnt type i,
v type c,
n type i.
cnt = strlen( val ).
do cnt times.
move val+n(1) to v.
if v co '.0123456789'.
move v to final+n(1).
endif.
n = n + 1.
if n = cnt .
exit.
endif.
enddo.
condense final no-gaps.
write:/ final . "get the numeric values with '.' till here
*get the occurances of '.'s
clear: cnt, n .
cnt = strlen( final ).
do cnt times.
move final+n(1) to v.
if v = '.'.
dotcnt = dotcnt + 1. "make the logic to check the count of .'s
endif.
n = n + 1.
if n = cnt .
exit.
endif.
enddo.
write:/ 'Dot counts', Dotcnt.
if dotcnt > 1.
write:/ 'more'.
else.
write:/ 'Ok'.
endif.hope this helps ,
Regards,
VIjay.
‎2007 Jan 04 8:36 AM
Hi all,
Thanks for your replies.
I did it on my own. I used the
REPLACE ALL OCCURRENCES OF '.' IN wl_hours
WITH wl_rep
REPLACEMENT COUNT wl_cnt.
if wl_cnt < 1, error.
it worked for me. anyways, thanks for ur replies.
I have awarded the points.
Ridhima
‎2007 Jan 04 8:37 AM
sorry its if wl_cnt > 1, error.
instead of if wl_cnt < 1, error.