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

alphabet checking

Former Member
0 Likes
1,081

I took a variable of type c

and another variable type i.

Now my question is :

I want to check the content in variable type c

either it is consisting of alphabets or numeric.

If it is numeric then i want to move it into type i variable.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,046

Hi

use the FM C14W_CHAR_NUMBER_CONVERSION ,

if sy-subrc = 0 then it contains character field

Reward points if useful..

Regards

Nilesh

8 REPLIES 8
Read only

Former Member
0 Likes
1,046

Hi.

You can say:

if var_c CO '0123456789'.

var_i = var_c.

endif.

Hope this helps.

Read only

Former Member
0 Likes
1,046

Hi Srujan,

You can make use of 'CO'

Check help on 'log_exp - Comparison operators for character-type operands '

For 'CO'

Contains Only: True, if operand1 only contains characters from operand2. Upper/lower case and trailing blanks are taken into account for both operands. If operand2 is of type string and is initial, then the logical expression is false, unless operand1 is also of type string and is initial, in which case the logical expression is always true. If the result of the comparison is negative, sy-fdpos contains the offset of the first character in operand1, that is not contained in operand2. If the result of the comparison is positive, sy-fdpos contains the length of operand1.

Regards,

Suruchi

Read only

Former Member
0 Likes
1,046

Hi again.

I forgot to include the comma (,) and the period (.)

There could be cases when these are also in the value of var_c.

Br!

Read only

Former Member
0 Likes
1,047

Hi

use the FM C14W_CHAR_NUMBER_CONVERSION ,

if sy-subrc = 0 then it contains character field

Reward points if useful..

Regards

Nilesh

Read only

Former Member
0 Likes
1,046

Hi Srujan ,

You can use the FM <b>CATS_NUMERIC_INPUT_CHECK</b> , this FM checks if the input is numeric or not , if not it raises an execption.

You can also use the FM <b>NUMERIC_CHECK</b>, this check the input and return the data type CHAR or Numeric .

Hope this helps.

Regards

Arun

Read only

Former Member
0 Likes
1,046

if not var CA sy-abcde.

move var to Ivar.

endif.

Read only

Former Member
0 Likes
1,046

data : text(10) type c value 'abc153f4a',

pos type i,

len type i,

v_text,

v_char(10),

v_chari(10),

v_int type i.

len = strlen( text ).

do len times.

v_text = text+pos(1).

if v_text ca sy-abcde.

concatenate v_cahr v_text into v_char.

condense v_char no-gap.

else.

concatenate v_cahri v_text into v_chari.

condense v_chari no-gap.

endif.

pos = pos + 1.

enddo.

v_int = v_chari.

write : / v_char, v_int.

regards

shiba dutta

Read only

dev_parbutteea
Active Contributor
0 Likes
1,046

Use the following , it will help u!

data : varc(5) type c VALUE '456re',

answer(5) type c ,

HTYPE LIKE DD01V-DATATYPE.

CALL FUNCTION 'NUMERIC_CHECK'

EXPORTING

string_in = varc

IMPORTING

STRING_OUT = answer

HTYPE = HTYPE "--> returns numc in case of numeric else returns char

.

Regerds ,

Sooness