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

a problem about string split

Former Member
0 Likes
691

hi experts

i have a string like str_a = 'abc##123'

i try to : split str_a at '##' into r1 r2.

i wish r1 = abc, r2 = 123,but it doesn't work.

another question is i want to translate a char into a decimal, is there any fm?

pls help and thanks a lot!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
660

Hi Ilu,

I dont find any problem with the SPLIT statement with your try. Anyways please check the below code which may helps you. If it is from file processing then use CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB instead of '#'.


Data: str_a type string value 'abc##123',
      r1 type string,
      r2 type string.

START-OF-SELECTION.
split str_a at '##' into r1 r2.

write:/ r1,r2.

Use function module MOVE_CHAR_TO_NUM to convert character to numeric.

Thanks,

Vinay

4 REPLIES 4
Read only

Former Member
0 Likes
660

This is working for me..


DATA wa_char(10) TYPE c value 'abc##123'.
DATA : wa_chr(4),
       wa_chr1(4).

SPLIT wa_char AT '##' INTO wa_chr wa_chr1.

write : wa_chr, wa_chr1.

For char to decimal you could check as below:


IF wa_char CO '0123456789'.
  wa_decimal = wa_char.
ENDIF.

Edited by: Ankesh on Jan 9, 2009 8:29 PM

Read only

Former Member
0 Likes
660

Hi Liu,

use this way.

data : abc type string value 'abc##123'.

data : r1(3) type c,

r2(3) type c.

split abc at '##' into r1 r2.

write : r1, r2.

bye...

Read only

Former Member
0 Likes
661

Hi Ilu,

I dont find any problem with the SPLIT statement with your try. Anyways please check the below code which may helps you. If it is from file processing then use CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB instead of '#'.


Data: str_a type string value 'abc##123',
      r1 type string,
      r2 type string.

START-OF-SELECTION.
split str_a at '##' into r1 r2.

write:/ r1,r2.

Use function module MOVE_CHAR_TO_NUM to convert character to numeric.

Thanks,

Vinay

Read only

0 Likes
660

Hi,

Do as Vinaykumar has mentioned for the split statment.

For converting character to decimal , you can also try the PACK command.


DATA num(10) TYPE c VALUE '11000'.

DATA num_p(13) TYPE p DECIMALS 2.

PACK num TO num_p.

write : num.
write / num_p.

regards,

Advait

Edited by: Advait Gode on Jan 9, 2009 4:23 PM