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

Split Statement

Former Member
0 Likes
1,804

hi all:

i try to split the string 'asd #bve#fdsf # sfdsdf#' into an internal table,does it have any ways to respect the Blank Spaces in the internal table?

Ex:split str at '#' into table i_tab

result;i_tab[1] = 'asd '

i_tab[2] = 'bve'

i_tab[3] = 'dsf '

i_tab[4] = ' sfdsd'

it would be grateful for any king answer.

BTW:i can't use the method which to replace the spaces with a "filler" and then split them up.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,754

hi all

i think i gave a bad sample to all of you,my questions was "how can i keep the blank space in the each table lines ".

15 REPLIES 15
Read only

Former Member
0 Likes
1,754

play around with

split str at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB into i_tab

Read only

Former Member
0 Likes
1,754

hi Sam,

do this way

split str at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB into i_tab. 
result;i_tab[1] = 'asd '
i_tab[2] = 'bve'
i_tab[3] = 'dsf '
i_tab[4] = ' sfdsd'

Regards,

Santosh

Read only

Former Member
0 Likes
1,754

Hi,

i am giving the sample code here, like wise do it.

DATA: STRING(60),

P1(20) VALUE '++++++++++++++++++++',

P2(20) VALUE '++++++++++++++++++++',

P3(20) VALUE '++++++++++++++++++++',

P4(20) VALUE '++++++++++++++++++++',

DEL(3) VALUE '***'.

STRING = ' Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5'.

WRITE STRING.

SPLIT STRING AT DEL INTO P1 P2 P3 P4.

WRITE / P1.

WRITE / P2.

WRITE / P3.

WRITE / P4.

The output appears as follows:

Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5

Part 1

Part 2

Part 3

Part 4 *** Part 5

Regards,

Bhaskar

Read only

Former Member
0 Likes
1,755

hi all

i think i gave a bad sample to all of you,my questions was "how can i keep the blank space in the each table lines ".

Read only

0 Likes
1,754

Just replace the blank space with an "exotic" character before split, and then replace ther other way in the table.

Define you "exotic" char via a constant of type X with a value in hexa or use a character never used.

REPLACE ALL OCCURRENCES OF ' ' IN i<your field> WITH char_x. 

Then split, ad loop at result tab and reverse the REPLACE.

Regards

Read only

0 Likes
1,754

Hi Raymond

because i do not know which "exotic" will not be used in the string,the any data would be used in the string which i want to split,so i can't use the ways you suggest althought it was a good way to work around it.any ideas?

Message was edited by:

sam feng

Read only

0 Likes
1,754

I fear that you have to manually split the string

REFRESH itab. CLEAR itab. CLEAR pos.
DO.
if string(1) eq '#'.
  append itab to itab.
  clear: itab, pos.
ELSE.
  itab+pos(1) = string(1).
  add 1 to pos.
ENDIF.
SHIFT string.
IF string is intial. 
  if pos > 0. " save last text
    append itab to itab.
  endif.
  exit.
 endif.
ENDDO. 

Regards

Read only

0 Likes
1,754

Hi Raymond:

thanks you so much,i have solved this issue according your suggest.points has been award to you.

Read only

Former Member
0 Likes
1,754

Trailing spaces in a record will not be retained. Can you please let us know the reason why you need those trailing spaces?

Read only

0 Likes
1,754

Hi Adavi:

in actually,this string was imported by the other function,and i have no any idea to change the format of data,my function must keep anything from it and exported it as an internal table.do you have any ideas?

Read only

Former Member
0 Likes
1,754

any one can do me a favour?appreciate in advance

Read only

p291102
Active Contributor
0 Likes
1,754

Hi,

This is the functionality and use of split statement in abap.

I know of an abap statement SPLIT but no SPLIT ROW.

SPLIT will split a string at a specified location.

split str at ',' into v_str v_str2.

do u want to split a row

DATA: str1 TYPE string,

str2 TYPE string,

str3 TYPE string,

itab TYPE TABLE OF string,

text TYPE string.

text = `What a drag it is getting old`.

SPLIT text AT space INTO: str1 str2 str3,

TABLE itab.

data: x(35) value 'Gangadharayya,Hiremath',

y(15),z(15).

split x at ',' into y z.

write: y,/ z.

output: Gangadharayya

Hiremath

Thanks,

Sankar M

Read only

Former Member
0 Likes
1,754

Hi,Sankar

thanks for your answer,but it can't solve my issues.

Read only

Former Member
0 Likes
1,754

hi,all

is there any ideas to solve it?points will reward to the helpful answer.

Read only

Former Member
0 Likes
1,754

thanks to the solution which submitted by Raymond