‎2006 Dec 11 6:45 AM
Hi,
I have to validate a field for numbers. Its an Amount field. I am taking the input in a Character field and then moving it to an amount field in the code.
I have done the validation for entering characters and throwing error message in this case.
How do i do the validation if something like '1..00' is entered or '1.0.2.3.4.' is entered?
Quick answers will be rewarded.
Thanks,
Rashmi.
‎2006 Dec 11 6:49 AM
Divide the number by 1 and check if it equal to the same number and give a try..
v_var = v_amount / 1.
if v_var = v_amount.
else.
*give error message that it is not anumber
endif.
‎2006 Dec 11 6:49 AM
Divide the number by 1 and check if it equal to the same number and give a try..
v_var = v_amount / 1.
if v_var = v_amount.
else.
*give error message that it is not anumber
endif.
‎2006 Dec 11 6:54 AM
data p1(8) type c '1.2.3.4'.
data p2 type p decimal 2.
<b>
try.
p2 = p1.
catch cx_root.
mesage ' Invalid input'.
endtry.</b>
‎2006 Dec 11 6:54 AM
Hi Rashmi,
Here is one idea:
1) Take the number into temp variable l_num.
2) use FIND '.' IN l_num MATCH OFFSET off.
3) then using the offset value in 'off' take the remaining string from there oneards.
4) l_num2 = l_num+off.
5) now apply same FIND on l_num2.
6) if another '.' is found then the input was wrong like 1..0 or 1.2.
Both the condition metioned by u can be validated by this logic.
Regards,
Vivek Kute.
‎2006 Dec 11 6:55 AM
Hi Rasmi,
you can use CATCH to validate the input...
Please see the following codes:
DATA int TYPE i.
CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.
MOVE 'abc' TO int.
ENDCATCH.
IF sy-subrc = 1.
MESSAGE i398(00) WITH 'Conversion Error'.
ENDIF.
Regards,
Hendy
‎2006 Dec 11 6:55 AM
Hi,
I hope the following code will be helpful.
Please do validation in character field only and move to numeric fileds.
DATA:
c_numeric TYPE char69
VALUE '12345 .67890'. " Alphanumc Group
IF lv_amount CO c_numeric.
find '.' in lv_amount MATCH LENGTH mlen.
if mlen gT 1.
Message 'Invalid amount value'.
endif.
--- define your code here.
ELSE.
Message 'Invalid amount value'.
ENDIF.
Regards
Bhupal Reddy
Message was edited by:
Bhupal Reddy Vendidandi
‎2006 Dec 11 8:24 AM
Hi All,
Thanks a lot for your answers.
I am now catching the exception and giving the message.
Thanks,
Rashmi.