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 String Question

muhammad_sohail
Participant
0 Likes
902

Dear All,

I have a string like below:

'000000009,15.04.2009,08:52:18,P10#000000009,15.04.2009,16:57:00,P20#003,02.05.2009,18:14:43,P10#003,02.05.2009,18:14:50,P20#003,02.05.2009,18:14:57,P10#003,02.05.2009,18:15:03,P20#003,02.05.2009,18:15:09,P10#'

I want to split this string. # is a record separator and , used for filed separator. This string is in xml data format, i want to convert it into itab. How i can i do that. keep in mind data can be upto 10MB. pls. give me syntax exmaple.

Thanks and Regards,

Muhammad Sohail

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
867

Kindly chk for the following code , it works as per requirrement..

A string can contain any number of alphanumeric characters

http://help.sap.com/saphelp_47x200/helpdata/EN/fc/eb2fd9358411d1829f0000e829fbfe/content.htm


types:
     begin of type_s_str,
      str1 TYPE string,
      str2 TYPE string,
      str3 TYPE string,
      str4 type string,
     end of type_s_str.

data: itab TYPE TABLE OF string with header line,
      itab2 TYPE TABLE OF type_s_str with header line,
      text TYPE string.

text = '000000009,15.04.2009,08:52:18,P10#000000009,15.04.2009,16:57:00,P20#003,02.05.2009,18:14:43,P10#003,02.05.2009,18:14:50,P20#003,02.05.2009,18:14:57,P10#003,02.05.2009,18:15:03,P20#003,02.05.2009,18:15:09,P10#'.

SPLIT text AT '#' INTO TABLE itab.

loop at itab.
  split itab at ',' into itab2-str1 itab2-str2 itab2-str3 itab2-str4.
  append itab2.
  endloop.

  loop at itab2.
    write:/ itab2-str1,itab2-str2,itab2-str3,itab2-str4.
  endloop.

Regards,

Mdi.Deeba

6 REPLIES 6
Read only

rainer_hbenthal
Active Contributor
0 Likes
867

JUst spilt it twice, first at # into a table and then every line in that table at ,.

But your example does not really look like XML...

Read only

Former Member
0 Likes
867

Hi

I would suggest you to make use of offset to split the string into parts.

Regards

Gaurav.

Read only

Former Member
0 Likes
867

Hi,

You can split the string as follows:-

DATA : itab1 TYPE STANDARD TABLE OF string.

DATA : string1 TYPE string.

string1 = 'ABC#345#678#wef'.

SPLIT string1 AT '#' INTO TABLE itab1.

Regards,

Ankur Parab

Read only

Former Member
0 Likes
867

Hi,

HIT F1 on SPLIT.

I Suggest you to use SPLIT with INTO TABLE itab addition.

But i am not sure if its possible to hold such a large data in a string/character string variable. So you may get some complications.

Regards

Karthik D

Read only

0 Likes
867

>

> But i am not sure if its possible to hold such a large data in a string/character string variable. So you may get some complications.

> Regards

> Karthik D

The largest (x)string i ever had was round about 65 MBytes. (xml generated from an internal table). Of course this depends on how much memory is occupied by all other processes, so it might fail. But in principle, huge strings are not a problem.

Read only

Former Member
0 Likes
868

Kindly chk for the following code , it works as per requirrement..

A string can contain any number of alphanumeric characters

http://help.sap.com/saphelp_47x200/helpdata/EN/fc/eb2fd9358411d1829f0000e829fbfe/content.htm


types:
     begin of type_s_str,
      str1 TYPE string,
      str2 TYPE string,
      str3 TYPE string,
      str4 type string,
     end of type_s_str.

data: itab TYPE TABLE OF string with header line,
      itab2 TYPE TABLE OF type_s_str with header line,
      text TYPE string.

text = '000000009,15.04.2009,08:52:18,P10#000000009,15.04.2009,16:57:00,P20#003,02.05.2009,18:14:43,P10#003,02.05.2009,18:14:50,P20#003,02.05.2009,18:14:57,P10#003,02.05.2009,18:15:03,P20#003,02.05.2009,18:15:09,P10#'.

SPLIT text AT '#' INTO TABLE itab.

loop at itab.
  split itab at ',' into itab2-str1 itab2-str2 itab2-str3 itab2-str4.
  append itab2.
  endloop.

  loop at itab2.
    write:/ itab2-str1,itab2-str2,itab2-str3,itab2-str4.
  endloop.

Regards,

Mdi.Deeba