‎2007 Sep 25 5:54 AM
Hi all,
case 1 parameters : a(2) type C value 14.
case 2 parameters : a(2) type C value 'gh'.
I have to see whether the value entered by the user is<b> numeric or character.</b>
Pleas assist me..
<b>& have ur points.</b>
Regards,
‎2007 Sep 25 5:57 AM
Hi,
Try using CS '0123456789', in IF statement
Regards,
Prabhu Rajesh
‎2007 Sep 25 5:59 AM
‎2007 Sep 25 6:04 AM
if a+0(1) BETWEEN 1 AND 9.
write: 'a is a number'.
elseif a+0(1) BETWEEN 'A' AND 'Z'.
write: 'a is a character'.
endif.
U can also use CA(Contains Any)/NA(Contains Not Any) in the IF condition.
IF A CA '123456789'.
write: 'a is a number'.
IF A NA '123456789'.
write: 'a is a character'.
ENDIF.
Message was edited by:
Karthik
‎2007 Sep 25 6:05 AM
Declare another variable like,
data : b(2) type N.
if a = 0.
u have entered integer.
else.
b = a.
if b = 0.
u have entered character.
else.
integer.
This is a logic that Numeric never accepts charcter.
Please reward if useful.
Thanks.
‎2007 Sep 25 6:06 AM
Hi,
simply use if stmt with operator ca(contains any).
Like this for ur eg :
if a ca '0123456789' .
write : 'it is character'.
else.
write :'numeric'.
Reward if useful.
Thanks.
‎2007 Sep 25 6:08 AM
SY-ABCDE determines if the p_c is alphabet or not.
PARAMETERS : p_c(10) TYPE c.
START-OF-SELECTION.
IF p_c CA sy-abcde.
WRITE : 'alpha'.
ELSE.
WRITE : 'numeric'.
ENDIF.Regards
Gopi
‎2007 Sep 25 6:16 AM
Hi,
Use the below code.
data: v_length type i,
v_count type i,
v_digit_count type i,
v_char_count type i.
parameters : a(2) type c default 14.
if not a is initial.
v_length = strlen( a ).
v_count = 0.
v_length = v_length - 1.
while v_count le v_length.
case a+v_count(1).
when '0' or '1' or '2' or '3' or '4' or '5' or '6' or '7' or '8' or '9'.
v_digit_count = v_digit_count + 1.
when others.
v_char_count = v_char_count + 1.
endcase.
v_count = v_count + 1.
endwhile.
if not v_char_count is initial and
not v_digit_count is initial.
write:/ 'parameter Contains digit and chars'.
elseif v_char_count is initial.
write:/ 'parameter Contains only digits'.
elseif v_digit_count is initial.
write:/ 'parameter Contains only chars'.
endif.
endif.
Message was edited by:
Velangini Showry Maria Kumar Bandanadham
‎2007 Sep 25 8:16 AM
Check the code below, it tells whether the given characters are numeric or not..
parameter : a(2) type C.
if a0(1) ca '0123456789 ' and a1(1) ca '0123456789 '.
write:/ a,'NUMERIC'.
else.
write:/ a,'CHARACTER'.
endif.
Reward points if useful, get back in case of query...
Cheers!!!
‎2007 Sep 25 12:37 PM
Pradeep,
If you want the user to enter numeric values only - then declare like this -
<b> parameters : a(2) type N value 14.</b>
i.e accepting numeric entries only
and otherwise you can write - In case of character inputs -
parameters : a(2) type C value 'gh'.
Or you can go in the conventional way of String checking etc using CA ( contains string NA ( does not contain string) etc.