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

Group an internal table based on sender then split the internal table

Former Member
0 Likes
417

hi all,

I have an internal table (field - sender, receiver, amt, qty). there can be multiple sender entries in the internal table

my requirement is

1. Group the internal table based on the sender

(say S1 Re 100 2

S1 Ce 200 3

S1 De 300 4

S2 Fe 200 2

S2 Fe 100 1

S3 Re 100 6)

2. Split the internal table based on grouping so in our case 3 internal table is generated say 1st internal contains S1, 2nd S2, 3rd S3 etc...

code can be like this

 

sort itab by sender.

loop at itab into wa_itab.
 at new sender.
      counter = 0.
      lv_sender = itab-sender.
 endat.

if itab-sender = lv_sender.
  counter = counter + 1.
endif.

at end of sender.
  if coutner GT 1.
     <<<<<< move into an internal table dynamically >>>>>>>>>> as there can be 3 or 4 internal table generated
    <<<<<<< generate excel file for each internal table>
 endif.
endat.

endloop.


I dont know how to move into differnet internal table dynamically and also to generate different excel file based on sender..

hope I am clear.....your suggestions are highly appreciated.

thanks

1 ACCEPTED SOLUTION
Read only

aabhas_wilmar
Contributor
0 Likes
378

You just need two internal tables:

1. Main internal table - itab - which will contain all your data

2. Temporary internal table itab_temp

Sort itab by sender.

loop at itab.
move itab to itab_temp.
append itab_temp.
at end of itab-sender.
"filename = filename+1.
"generate excel using itab_temp
"refresh itab_temp
endat.
endloop.

hi all,

I have an internal table (field - sender, receiver, amt, qty). there can be multiple sender entries in the internal table

my requirement is

1. Group the internal table based on the sender

(say S1 Re 100 2

S1 Ce 200 3

S1 De 300 4

S2 Fe 200 2

S2 Fe 100 1

S3 Re 100 6)

2. Split the internal table based on grouping so in our case 3 internal table is generated say 1st internal contains S1, 2nd S2, 3rd S3 etc...

code can be like this

 

sort itab by sender.

loop at itab into wa_itab.
 at new sender.
      counter = 0.
      lv_sender = itab-sender.
 endat.

if itab-sender = lv_sender.
  counter = counter + 1.
endif.

at end of sender.
  if coutner GT 1.
     <<<<<< move into an internal table dynamically >>>>>>>>>> as there can be 3 or 4 internal table generated
    <<<<<<< generate excel file for each internal table>
 endif.
endat.

endloop.


I dont know how to move into differnet internal table dynamically and also to generate different excel file based on sender..

hope I am clear.....your suggestions are highly appreciated.

thanks

1 REPLY 1
Read only

aabhas_wilmar
Contributor
0 Likes
379

You just need two internal tables:

1. Main internal table - itab - which will contain all your data

2. Temporary internal table itab_temp

Sort itab by sender.

loop at itab.
move itab to itab_temp.
append itab_temp.
at end of itab-sender.
"filename = filename+1.
"generate excel using itab_temp
"refresh itab_temp
endat.
endloop.