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

a question on string manipulation

Former Member
0 Likes
1,143

hi guys,

one question on string manipulation need your help here.

source in SAP

-


doc part location

1 A u1

2 B u1,u2

3 C u1,u2,c1-c3

desire report output

-


doc part location

1 A u1

2 B u1

2 B u2

3 C u1

3 C u2

3 C c1

3 C c2

3 C c3

thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,116

Hi,

try this

loop at itab.

split itab-location into loc1, loc2,loc3 seperated by ',' .

In loc1, loc 2, loc3,

search for '-'

if found get the sy-fdpos.

from sy-fdpos-1 u will get C1

from sy-fdpos+-1 u will get C3

then u can populate as u required.

endloop.

Reward if useful.

Regards,

Bindu.

10 REPLIES 10
Read only

Former Member
0 Likes
1,116

hi boon,

a = 1 A u1

b = 2 B u1,u2

c = 3 C u1,u2,c1-c3

d = ' '.

2 B u1 -


> b+0(4).

2 B u2 -


> REplace u1 in b with d. condense b no-gaps.

3 C u1 -


> c+0(4)

3 C u2 -


> c0(2), c4(2). concatenate both.

3 C c1 -


> c0(2), c6(2). concatenate both.

Please reward if helpful.

Thanks.

Read only

0 Likes
1,116

hi Shori,

i should have explain it more clearly.

the source file are stored in a internal table with 3 columns (doc,part,location). how are we going to decide when come across the ',' and '-' and split it into new rows?

thanks.

Read only

Former Member
0 Likes
1,116

hi,

there is an option in abap as <b>search</b>.

Just use it for search <b>, and -.</b>

U have to search only the location field.

by using <b>If statement</b> u can finish the scenario.

<b>

Please reward if helpful.</b>

Read only

Former Member
0 Likes
1,117

Hi,

try this

loop at itab.

split itab-location into loc1, loc2,loc3 seperated by ',' .

In loc1, loc 2, loc3,

search for '-'

if found get the sy-fdpos.

from sy-fdpos-1 u will get C1

from sy-fdpos+-1 u will get C3

then u can populate as u required.

endloop.

Reward if useful.

Regards,

Bindu.

Read only

0 Likes
1,116

hi,

sorry for late reply...

two question here need your advice.

1.from sy-fdpos-1, how i get the content (c1)?

2.in this case we have c1 and c3, other cases may be c1 and c5. how would the program know the range (c2, or c2~c4) to be populated here?

thanks.

Read only

0 Likes
1,116

Did u see my previous post, it itself handles the string irrespective of the range(dynamic), hope it is what u r looking for.

Reward points if useful, get back in case of query...

Cheers!!!

Read only

0 Likes
1,116

yes, i tried out your code and it's working find when the location is separate by ','.

only thing is how about the case d1-d5 in the internal table?

how are we going to know how many number to fill in between d1~d5 at runtime, it can be any number here.

attach a sample code here:

&----


*& Report ZTEST20071009 *

*& *

&----


*& *

*& *

&----


REPORT ZTEST20071009 .

types: begin of itab,

doc(1),

part(1),

location(255),

end of itab.

types: begin of iloc,

location(255),

end of iloc.

data: i_itab type table of itab,

w_itab type itab,

i_loc type table of iloc,

w_loc type iloc,

i_itab2 type table of itab,

w_itab2 type itab.

w_itab-doc = '1'.

w_itab-part = 'A'.

w_itab-location = 'u1'.

append w_itab to i_itab.

w_itab-doc = '2'.

w_itab-part = 'B'.

w_itab-location = 'u1,u2'.

append w_itab to i_itab.

w_itab-doc = '3'.

w_itab-part = 'C'.

w_itab-location = 'u1,u2,c1,c2,c3,d1-d5'.

append w_itab to i_itab.

loop at i_itab into w_itab.

  • itab2 = itab.

w_itab2-doc = w_itab-doc.

w_itab2-part = w_itab-part.

split w_itab-location at ',' into table i_loc.

search w_itab-location for '-'.

if sy-subrc EQ 0.

w_loc = sy-fdpos - 1.

append w_loc to i_loc.

w_loc = sy-fdpos + 1.

append w_loc to i_loc.

endif.

  • split itab-location at ',' into table loc.

loop at i_loc into w_loc.

w_itab2-location = w_loc-location.

append w_itab2 to i_itab2.

write:/ w_itab2-doc,w_itab2-part,w_itab2-location.

endloop.

  • loop at loc.

  • itab2-location = loc-location.

  • append itab2.

  • write:/ itab2.

  • endloop.

endloop.

Read only

0 Likes
1,116

Run the code below for range...

REPORT ZTRIP_TEST.

data:

begin of itab occurs 0,

doc,

part,

location(255),

end of itab,

begin of loc occurs 0,

location like itab-location,

end of loc,

range_start like itab-location,

range_end like itab-location,

itab2 like table of itab with header line.

itab-doc = '1'.

itab-part = 'A'.

itab-location = 'u1'.

append itab.

itab-doc = '2'.

itab-part = 'B'.

itab-location = 'u1,u2,d1-d5'.

append itab.

itab-doc = '3'.

itab-part = 'C'.

itab-location = 'u1,u2,c1,c2,c3'.

append itab.

loop at itab.

itab2 = itab.

split itab-location at ',' into table loc.

loop at loc.

search loc-location for '-'.

if sy-subrc eq 0.

split loc-location at '-' into range_start range_end.

itab2-location = range_start.

append itab2.

write:/ itab2.

while itab2-location ne range_end.

itab2-location1(1) = itab2-location1(1) + 1.

append itab2.

write:/ itab2.

endwhile.

else.

itab2-location = loc-location.

append itab2.

write:/ itab2.

endif.

endloop.

endloop.

Reward points if useful, get back in case of query...

Cheers!!!

Read only

0 Likes
1,116

you're great!

Read only

Former Member
0 Likes
1,116

Check the code below, i hope it serves your pupose

data:

begin of itab occurs 0,

doc,

part,

location(255),

end of itab,

begin of loc occurs 0,

location(255),

end of loc,

itab2 like table of itab with header line.

itab-doc = '1'.

itab-part = 'A'.

itab-location = 'u1'.

append itab.

itab-doc = '2'.

itab-part = 'B'.

itab-location = 'u1,u2'.

append itab.

itab-doc = '3'.

itab-part = 'C'.

itab-location = 'u1,u2,c1,c2,c3'.

append itab.

loop at itab.

itab2 = itab.

split itab-location at ',' into table loc.

loop at loc.

itab2-location = loc-location.

append itab2.

write:/ itab2.

endloop.

endloop.

Reward points if useful, get back in case of query...

Cheers!!!