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 a string into multiple internal tables

pradeep_grandhi
Active Participant
0 Likes
3,070

Hi all,

I need to split a string based internal table into multiple internal tables based on some sub strings in that string based internal table...

High priority help me out...

eg...

a | jhkhjk | kljdskj |lkjdlj |

b | kjhdkjh | kldjkj |

c | jndojkok |

d |

this data which is in the application server file is brought into a internal table as a text. Now i need to send 'a' to one internal table, 'b' to one internal table, so on... help me

<Priority downgraded>

Edited by: Suhas Saha on Oct 12, 2011 12:24 PM

8 REPLIES 8
Read only

Former Member
0 Likes
1,596

Could you be more clear on what is required.

Read only

0 Likes
1,596

The example says how the file is there in the application server.

Now i got that file read into an internal table which has only 1 field string.

So it would contain only 1 file.

Now i would like to send the line starting with 'a' (in the example) in one internal table, 'b' in another internal table, so on....

how could i send can u help me out wit some logic or code?

Read only

0 Likes
1,596

Pradeep,

Can you share your actual requirement ?

Splitting it into different internal tables is very much possible based on 1st field (before 1st pipe) but if there are 1000 rows coming, you may end up with 1000 internal tables. How you declare them ?? It will be always random, right ?

Regards,

Diwakar

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,596

There should be some better solutions for this instead of creating internal tables for each row in the file.

What is the maximum row count expected ( is it 26 )

Please let us know what are you going to do after moving each row to a internal table ?

Read only

Former Member
0 Likes
1,596

Hi,

Assign Internal table name dynamicaly.


LOOP AT IT_STR INTO WA_STR.
IF <Cond to put data in table >.
ASSIGN <table> TO <F_TAB>.                "<TABLE> here you hav to required table name
SPLIT WA_STR INTO TABLE <F_TAB>.
ENDIF.
ENDLOOP.

Thanks,

Anmol.

Edited by: anmol112 on Oct 12, 2011 3:05 AM

Read only

Former Member
0 Likes
1,596

First split the line into corresponding columns of the internal table using


loop at itab into wa_itab.

SPLIT wa_itab AT '|' into wa_itab1-column1 wa_itab1-column2 wa_itab1-column3.

append wa_itab1 into itab1.

endloop.

read the itab1 using column1 and move the rows into different internal tables.

Read only

Former Member
0 Likes
1,596

Hi pradeep,

eg...

a | jhkhjk | kljdskj |lkjdlj |

b | kjhdkjh | kldjkj |

c | jndojkok |

d |

As per your statement "Now i need to send 'a' to one internal table, 'b' to one internal table"

Do you want only a to one internal table and b to one internal table

OR

Do you want the whole row of the internal table i mean

a | jhkhjk | kljdskj |lkjdlj | to 1 internal table

Having the case of an internal table which is of type string,

1) Loop through the internal table. LOOP AT lt_tab INTO lwa_tab.

2) Ge the work area contents and get the first char wa_tab-string+0(1)

3) FIELD-SYMBOLS: <t_itab> TYPE ANY TABLE.

w_tabname = p_table.

CREATE DATA w_dref TYPE TABLE OF (w_tabname).

ASSIGN w_dref->* TO <t_itab>.

Follow the link

http://www.sap-img.com/ab030.htm

http://www.sapdev.co.uk/tips/dynamic-structure.htm

and then based on the sy-tabix values you will get that many number of internal table

<FS> = wa_tab-string+0(1)

append <FS>

OR

USE SPLIT statement at the relevant seperator

revert for further clarification

Thanks

Sri

Edited by: SRIKANTH P on Oct 12, 2011 12:36 PM

Read only

pradeep_grandhi
Active Participant
0 Likes
1,596

solved by myself...

Thanq all