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

string Operation

Former Member
0 Likes
959

Hi,

I have variable X. It holds value like 12MO..numeric with characters.

Now i want only 12 in X. i do not want 'MO'.

how do i achieve this???

1 ACCEPTED SOLUTION
Read only

former_member222860
Active Contributor
0 Likes
923

Declare the varaible as type n

data: val(2) type n.

val = '12mo'.

write:/ val.

7 REPLIES 7
Read only

Former Member
0 Likes
923

If you want only the 1st 2 characters, then use this sample code:


data : X type string value '12MO'.
 X = X+00(02).

Write : X 

Regards,

mansi.

Read only

0 Likes
923

thanks for the quick reply. but this text is dynamic. sometimes the numeric value is of 3 digit and one char at the last.

so the solution will not work.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
923

Hello,

You can try this code:

DATA: x  TYPE string VALUE '124578MO',
      x1 TYPE string,
      x2 TYPE string,
      x3 TYPE string.

x3 = x.

DO.

  x1 = x+0(1).

  IF x1 CO '0123456789'.
    CONCATENATE x2 x1 INTO x2.
    x = x+1.
  ELSE.
    EXIT.
  ENDIF.

ENDDO.

WRITE: x3, x2.

BR,

Suhas

Read only

former_member222860
Active Contributor
0 Likes
924

Declare the varaible as type n

data: val(2) type n.

val = '12mo'.

write:/ val.

Read only

Former Member
0 Likes
923

hi,

use CO

if v_var CO '0123456789'.

success

else.

error

endif.

Read only

Former Member
0 Likes
923

Steps :

1. Find the string length.

2. do string lenght times.

3. if variable x()


data : c1(10) type c value '0123456789'.

do strlength times.

n = n + 1.

x(n) co c1.
if sy-subrc <> 0.

out = x(n).
exit.

endif.

enddo.

Regards

Kumar M

Read only

Former Member
0 Likes
923

Hi,

Check this....

Data: cntr type sy-index,

temp type c,

x type char10 value '0123XTY',

reslt type char10.

cntr = 0.

do.

temp = x+cntr(1).

if temp co '0123456789'.

concatenate reslt temp into reslt.

else.

exit.

endif.

enddo.

Thanks & Regards,

Vamsi.