Application Development 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: 

How to split the string

Former Member
0 Kudos

Folks,

I have a requirement where i want to split the string and place into the internal table which has the format (row,col,value).

example:

Table1

abc#def#ghi#

jkl#mno#pqr#

(In table1 )

I want above table to be splitted to below format

Table2

row col value

1 1 abc

1 2 def

1 3 ghi

2 1 jkl

2 2 mno

2 3 pqr

Please help me out in solving this.

4 REPLIES 4

GauthamV
Active Contributor
0 Kudos

hi,

check this example from sap.

DATA: NAMES(30) TYPE C VALUE 'Charly, John , Peter',

NAMES2 TYPE STRING,

ONE(10) TYPE C,

TWO(10) TYPE C,

THREE TYPE STRING,

FOUR(4) TYPE C VALUE 'FOUR',

DELIMITER(2) VALUE ','.

SPLIT NAMES AT DELIMITER INTO ONE TWO.

  • ONE contains 'Charly' and TWO contains 'John , Pet'.

  • SY-SUBRC is 4, because TWO was not large enough to

  • accommodate the whole of the remaining string

SPLIT NAMES AT ',' INTO ONE TWO THREE.

  • ONE contains 'Charly', TWO contains ' John',

  • THREE contains ' Peter'.

SPLIT NAMES AT ', ' INTO ONE THREE TWO.

  • ONE contains 'Charly', THREE contains 'John',

  • TWO contains 'Peter'.

CONCATENATE NAMES '' INTO NAMES2 SEPARATED BY SPACE.

SPLIT NAMES2 AT DELIMITER INTO ONE TWO THREE FOUR.

  • ONE contains 'Charly', TWO contains 'John',

  • THREE contains 'Peter ', FOUR is empty.

SPLIT NAMES2 AT DELIMITER INTO ONE FOUR THREE.

  • ONE contains 'Charly', FOUR contains 'John',

  • THREE contains 'Peter', SY-SUBRC is 4, since

  • FOUR was not large enough (spaces are significant

  • characters!)

Former Member
0 Kudos

But the number of fields in table1 are not constant.

Former Member
0 Kudos

Using below syntax it solved my problem.

SPLIT itab2-b AT '#' INTO TABLE ITAB.

kesavadas_thekkillath
Active Contributor
0 Kudos

just check this code outline..

this is just a outline and i guess its not bug free.


	data:len type i.
	data:i type i.
	data:j type i.
	data:k type i.



	loop at table1.
		i = 1.
		j = 0.
		k = 0.
		table2-row = sy-tabix.
		len = strlen( table1-field ).
		len = len - 1.
		while i <= len.
			if table1-field+j(i) <> '#'.
				table2-value = table1-field+j(i).
			else.
				k = k + 1.
				table2-col = k.
				append table2.
			endif.
			i = i + 1.
		endwhile.
	endloop.