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: 

Splitting internal table

Former Member
0 Kudos
1,126

I have an internal table which has 100 entries . I have a parameter on the selection screen which says how many entries to club.

Like if I say 5 entries on the screen to club , the program should submit 20 jobs, if 4 then 25, if 3 then 33 jobs with 3 entries and 1 job with one entry .

Any idea how this can be done easily ? Any sample code ?

Ankur Bhandari .

7 REPLIES 7

Former Member
0 Kudos
134

Ankur,

Have a counter inside the loop. Once the counter is equal to the value entered on the SELECTION screen, submit the job and reset the counter.

The loop is for the internal table that holds the data.

Regards,

Ravi

0 Kudos
134

This is exactly what I did , but this fails for odd numbers also when the total no of entries which are there in the main internal table then the job won't get submitted.

Ankur Bhandari

0 Kudos
134

if you are looking at loop at internal table to start at a particular index you can use

loop at itab FROM <counterstart> to <counterend>.

endloop .

Regards

Raja

Former Member
0 Kudos
134

Not sure but maybe this helps:

entries = 5.
i = 0.

do.
from = entries * i.
to = from + entries.
describe itab lines sy-tfill.
if sy-tfill lt to. 
  to = sy-tfill.
  stop = 'X'.
endif.
loop itab from from to to.
endloop.
if stop eq 'X'.
  exit.
else.
  add 1 to i.
endif.
enddo.

Regards

Rene

andreas_mann3
Active Contributor
0 Kudos
134

Hi Ankur,

try:

PARAMETERS club TYPE i DEFAULT 7.
DATA entries TYPE i.
DATA rest TYPE i.
DATA counter  TYPE i.

DESCRIBE TABLE itab LINES entries. "number of table entries
counter = trunc( entries / club )."number without rest
rest = entries MOD club."rest

*normal entries
DO club TIMES.
  DO counter TIMES.
*submit ...
  ENDDO.
ENDDO.

*rest - residuary
DO rest TIMES.
*submit...
ENDDO.

Andreas

Former Member
0 Kudos
134

append records to a tmp table and use sy-tabix that is the index of the appended record.

Then handle the line to the secondary table.

Then free the table.

parameters : split type i.

Data: tab1 type XXX occurs 0,
      tab2 like tab1.

loop at tab1.
append tab1 to tab2.
check sy-tabix = split.
submit ....
.
.
.
free tab2.
endloop.

0 Kudos
134

<b>Is it solved now ? don't forget the reward!</b>