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

former_member582701
Contributor
0 Likes
665

Hello!

I have next case:

Char1000 with the interest data.

Internal table itab with 2 fields:

paramname: char35

paramvlaue: char50

Example1:

char1000 = name, john, age,24

result itab:

name john

age 24

Example2:

char1000 = name,michael,age,35,city,barcelona,

result itab:

name michael

age 35

city barcelona

We dont know the number of parameters. How we can split it and insert into internal table?

Thx!

1 ACCEPTED SOLUTION
Read only

varma_narayana
Active Contributor
0 Likes
638

Hi ...

Plz Try the Sample code below.

Hope it helps.

<b>REPORT zdemo_split .</b>

DATA : char1(100) VALUE 'name, john, age,24'.

DATA char2(100) VALUE 'name,michael,age,35,city,barcelona'.

DATA : BEGIN OF itab OCCURS 10,

param(10),

value(20),

END OF itab.

DATA : BEGIN OF temp_tab OCCURS 10,

field(10),

END OF temp_tab.

DATA v_mod TYPE i.

<b>****Case 1</b>

REFRESH itab.

SPLIT char1 AT ',' INTO TABLE temp_tab.

CLEAR v_mod.

LOOP AT temp_tab.

v_mod = sy-tabix MOD 2.

IF v_mod = 1.

itab-param = temp_tab-field.

ELSE.

itab-value = temp_tab-field.

APPEND itab.

ENDIF.

ENDLOOP.

LOOP AT itab.

WRITE:/ itab-param,

itab-value.

ENDLOOP.

<b>****Case 2</b>

SKIP 3.

REFRESH itab.

SPLIT char2 AT ',' INTO TABLE temp_tab.

CLEAR v_mod.

LOOP AT temp_tab.

v_mod = sy-tabix MOD 2.

IF v_mod = 1.

itab-param = temp_tab-field.

ELSE.

itab-value = temp_tab-field.

APPEND itab.

ENDIF.

ENDLOOP.

LOOP AT itab.

WRITE:/ itab-param,

itab-value.

ENDLOOP.

<b>Reward if helpful.</b>

7 REPLIES 7
Read only

Former Member
0 Likes
638

Are you saying that you need to ignore the second comma separator. If so you may need to code some logic to replace the second comma with another character. Then you can use the SPLIT command.

Read only

former_member191391
Participant
0 Likes
638

Hi,

From where r u getting this data into .. char1000.

Via any excel file , tab delimited file .. or etc

With Regards,

Manmeet singh

Read only

Former Member
0 Likes
638

Hi Manel ,

You can use the command

SPLIT f AT g INTO TABLE itab.

where g will be , so each item will be stored in the internal table itab.

Now from the table itab read 2 records , the first will be the header and the second the data , move these into an internal table which has 2 columns per row.

Hope this helps.

Feel free to revert back in case of any queries.

Regards

Arun

Read only

former_member582701
Contributor
0 Likes
638

I get char1000 from a parameter of a selection screen.

I'm using SPLIT:

DATA : it_split TYPE TABLE OF STRING.

SPLIT p_params AT ',' INTO TABLE it_split.

LOOP AT it_split.

IF SY-TABIX =

it_params-paramname

it_params-paramvalue

But the problem is that it_split has one value per line.

With SPLIT p_params AT ',' INTO TABLE it_params it will work fine directly?

Read only

0 Likes
638

Hello Manel ,

Here is a sample code for the same



data : str(1000).

types : begin of ty_1 ,
          word(30) ,
        end of ty_1.

data : it_1 type table of ty_1 ,
       wa_1 type ty_1,
       ind type i.

data : begin of it_2 occurs 0 ,
        header(30),
        detail(30) ,
       end of it_2.

str = 'name,michael,age,35,city,barcelona'.

split str at ',' into table it_1.

describe table it_1 lines ind.
data : index1 type i.
index1 = 0.
 clear it_2.
do ind times.
 index1 = index1 + 1 .
 read table it_1 into wa_1  index index1.
 it_2-header = wa_1-word.
 condense it_2-header.
 index1 = index1 + 1 .
read table it_1 into wa_1 index index1.
 it_2-detail = wa_1-word.
 condense it_2-detail.
if not it_2 is initial.
 append it_2.
endif.
 clear it_2.
 clear wa_1.
enddo.

Hope this helps

Regrad's

Arun

Read only

varma_narayana
Active Contributor
0 Likes
639

Hi ...

Plz Try the Sample code below.

Hope it helps.

<b>REPORT zdemo_split .</b>

DATA : char1(100) VALUE 'name, john, age,24'.

DATA char2(100) VALUE 'name,michael,age,35,city,barcelona'.

DATA : BEGIN OF itab OCCURS 10,

param(10),

value(20),

END OF itab.

DATA : BEGIN OF temp_tab OCCURS 10,

field(10),

END OF temp_tab.

DATA v_mod TYPE i.

<b>****Case 1</b>

REFRESH itab.

SPLIT char1 AT ',' INTO TABLE temp_tab.

CLEAR v_mod.

LOOP AT temp_tab.

v_mod = sy-tabix MOD 2.

IF v_mod = 1.

itab-param = temp_tab-field.

ELSE.

itab-value = temp_tab-field.

APPEND itab.

ENDIF.

ENDLOOP.

LOOP AT itab.

WRITE:/ itab-param,

itab-value.

ENDLOOP.

<b>****Case 2</b>

SKIP 3.

REFRESH itab.

SPLIT char2 AT ',' INTO TABLE temp_tab.

CLEAR v_mod.

LOOP AT temp_tab.

v_mod = sy-tabix MOD 2.

IF v_mod = 1.

itab-param = temp_tab-field.

ELSE.

itab-value = temp_tab-field.

APPEND itab.

ENDIF.

ENDLOOP.

LOOP AT itab.

WRITE:/ itab-param,

itab-value.

ENDLOOP.

<b>Reward if helpful.</b>

Read only

Former Member
0 Likes
638

TRY THIS


DATA : BEGIN OF ITAB OCCURS 0,
       F1(50),
       F2(35),
       END OF ITAB.

DATA : TEXT(500) VALUE 'name,michael,age,35,city,barcelona,'.

DATA : V_TEMP(50),
       V_TEMP1(50),
       LEN TYPE I.

COMPUTE LEN = STRLEN( TEXT ).

DO LEN TIMES.
IF TEXT IS INITIAL.
EXIT.
ENDIF.
SPLIT TEXT AT ',' INTO ITAB-F1 ITAB-F2 V_TEMP1.
CONCATENATE ITAB-F1 ',' ITAB-F2 ',' INTO V_TEMP.
REPLACE FIRST OCCURRENCE OF V_TEMP IN TEXT WITH SPACE.
CONDENSE TEXT NO-GAPS.
APPEND ITAB.
CLEAR ITAB.
ENDDO.

LOOP AT ITAB.
ENDLOOP.

REGARDS

SHIBA DUTTA