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

reg. value checking....have ur points.

Former Member
0 Likes
999

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,

9 REPLIES 9
Read only

Former Member
0 Likes
980

Hi,

Try using CS '0123456789', in IF statement

Regards,

Prabhu Rajesh

Read only

Former Member
0 Likes
980

you declared a type c so .value is c or n no prob i think

Read only

former_member189629
Active Contributor
0 Likes
980

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

Read only

Former Member
0 Likes
980

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.

Read only

Former Member
0 Likes
980

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.

Read only

gopi_narendra
Active Contributor
0 Likes
980

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

Read only

Former Member
0 Likes
980

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

Read only

Former Member
0 Likes
980

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!!!

Read only

Former Member
0 Likes
980

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.