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 a long text.

Former Member
0 Kudos

Hi,

I have a long text like (0001001352, 0001001683, 0001001457, 0001236530, ............... continues). I don’t how long will be the string length either it may contain 1 or more than one numbers.

So my requirement is to split at each comma and store in a range.

If I use split then I don't know how many local fields I need to be declare to hold those split values.

I want to know is their any function module or class, which splits the string at comma and stores in internal table? So that I can store those into my range table.

Regards,

Kumar

4 REPLIES 4

former_member195698
Active Contributor
0 Kudos

try this...

do.

split wf_text at ',' into wf_first wf_rest.

if wf_rest is initial.

append wf_first to tb_table.

exit.

endif.

append wf_first to tb_table.

wf_text = wf_rest.

enddo.

Message was edited by: Abhishek Jolly

Message was edited by: Abhishek Jolly

Former Member
0 Kudos

Hi,

check this..

data: itab type table of string with header line.

data: lv_string type string.

SPLIT LV_STRING AT ',' into table itab.

Thanks,

Naren

Thanks,

Naren

Former Member
0 Kudos

Hi Kumar,

The sample code is follows.

DATA: str TYPE string VALUE 'A,B,C,D,E,F,G,H,I,J,K,L',

itab TYPE string OCCURS 0 WITH HEADER LINE.

SPLIT str AT ',' INTO TABLE itab.

LOOP AT itab.

WRITE:/ itab.

ENDLOOP.

Nothing to worry about the length of string or number of words.

Regards,

Prasanth

Former Member
0 Kudos
Hi Kumar,

  check this code



REPORT ZRICH_0001.

DATA : BEGIN OF IT_RANGE OCCURS 0,
        SIGN(1),
        OPTION(2),
        LOW TYPE STRING,
        HIGH TYPE STRING,
       END OF IT_RANGE.

DATA : BEGIN OF ITAB OCCURS 0,
          VAR(5000),
       END OF ITAB.

DATA : V_STR TYPE STRING VALUE '0000123,123456,345677'.

CLEAR ITAB.
REFRESH ITAB.

SPLIT V_STR AT ',' INTO TABLE ITAB.

CLEAR ITAB.
REFRESH IT_RANGE.

LOOP AT ITAB.
  IT_RANGE-SIGN = 'I'.
  IT_RANGE-OPTION = 'BT'.
  IT_RANGE-LOW = ITAB-VAR.
  IT_RANGE-HIGH = ''.
  APPEND IT_RANGE.
  CLEAR IT_RANGE.
ENDLOOP.

LOOP AT IT_RANGE.
  WRITE : / IT_RANGE-LOW.
ENDLOOP.