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 Member
0 Likes
859

hi frnds,

I have one internal table with three fields.

and I want to split third field depending on no. of characters, say 75 characters, and I want to add this row next to row which is splitted. Remaining two fields should be same for the splitted row also..

How could i do this?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
840

Hi Nitin,

What i conclude from your requirement is......

filed1 | field2 | field3

a a1 XXXX

a a1 XX

b b1 YYY

c c1 ZZZZ

c c1 ZZZ

I hope this is what you are expecting. In this case try the following code.

data:

begin of fs_itab, " field string

field1(10) type c,

field2(10) type c,

field3(100) type c,

end of fs_itab.

data:

t_itab like standard table " internal table

of fs_itab

initial size 0.

data:

w_length type i, " string length

w_index type i, " record count

w_field3 like itab-field3, " field contents

w_char1(75) type c, " char string

w_char2(75) type c. " char string

constants:

c_maxl type i value 75. " max. length

Loop at t_itab into fs_itab.

clear w_length.

w_length = strlen( fs_itab-field3 ).

check w_length > c_maxl.

read itab index sy-tabix.

w_index = sy-tabix + 1.

w_length = w_length - c_maxl.

w_field3 = fs_itab-field3.

clear fs_itab-field3.

fs_itab-field3 = w_field3+0( c_maxl ).

modify t_itab from fs_itab

transferring field3 index sy-tabix.

clear fs_itab-field3.

fs_itab-field3 = w_field3+c_maxl( w_length ).

append fs_itab to t_itab

index w_index.

Endloop.

please award points if it was helpful.

6 REPLIES 6
Read only

Former Member
0 Likes
840

Hi,

DATA :v_clen TYPE i ,

v_char (150).

LOOP AT ITAB.

v_len = strlen( itab-fiels3) .

IF v_len > 75.

itab-field4 = itab-field3+75(v_len).

itab-field3 = itab-field3+0(75).

MODIFY ITAB TRANSFERING field3 field4.

ENDIF.

ENDLOOP.

Read only

0 Likes
840

I dont want to add extra field to itab, I just want to add extra row after splitting with same data of remaining two fields...

Read only

0 Likes
840

Hi,

DATA :v_clen TYPE i ,

v_char(150).

LOOP AT ITAB.

v_len = strlen( itab-fiels3) .

IF v_len > 75.

v_char = itab-field3+75(v_len).

itab-field3 = itab-field3+0(75).

MODIFY ITAB TRANSFERING field3.

itab-field3 = v_char.

MODIFY ITAB TRANSFERING field3.

ENDIF.

ENDLOOP.

Read only

Former Member
0 Likes
840

Hi,

you have 3 fields in your internal table.you want to split the third filed from 75 characters and you want to add this field to next field.But you are saying that iam having 3 fields in my internal table then how to add this to next.every got confusion here.specify your requirement clearly so that you will get quick answer.

regards,

swami.

Read only

0 Likes
840

hey its very simple

make one more internal table of same type let it be btab..

then

loop at itab.

fild 1 and 2 of btab = fld 1 and 2 of itab.

btab-fld3 = itab-fld3+75(*).

append btab.

clear btab.

itab-fild3 = itab-fild3+0(75).

modify itab.

endloop.

once loop is over .

append lines of btab to itab.

Read only

Former Member
0 Likes
841

Hi Nitin,

What i conclude from your requirement is......

filed1 | field2 | field3

a a1 XXXX

a a1 XX

b b1 YYY

c c1 ZZZZ

c c1 ZZZ

I hope this is what you are expecting. In this case try the following code.

data:

begin of fs_itab, " field string

field1(10) type c,

field2(10) type c,

field3(100) type c,

end of fs_itab.

data:

t_itab like standard table " internal table

of fs_itab

initial size 0.

data:

w_length type i, " string length

w_index type i, " record count

w_field3 like itab-field3, " field contents

w_char1(75) type c, " char string

w_char2(75) type c. " char string

constants:

c_maxl type i value 75. " max. length

Loop at t_itab into fs_itab.

clear w_length.

w_length = strlen( fs_itab-field3 ).

check w_length > c_maxl.

read itab index sy-tabix.

w_index = sy-tabix + 1.

w_length = w_length - c_maxl.

w_field3 = fs_itab-field3.

clear fs_itab-field3.

fs_itab-field3 = w_field3+0( c_maxl ).

modify t_itab from fs_itab

transferring field3 index sy-tabix.

clear fs_itab-field3.

fs_itab-field3 = w_field3+c_maxl( w_length ).

append fs_itab to t_itab

index w_index.

Endloop.

please award points if it was helpful.