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 internal table

former_member602116
Participant
0 Likes
1,369

Hi Experts,

I have a requirement where I have a select-options for plant input that can handle ranges.

With plant input, I need to select from multiple tables.

From these tables, I have created internal tables e.g gt_ekpo, gt_eban, gt_marc.

My question is how do I print the output in such a way that it is separated by plant? For example, my input in selection screen is 1110 and 1112.

I want to print it like the below:

Plant 1110

Details from gt_ekpo

Details from gt_eban

Details from gt_marc.

Plant 1112

Details from gt_ekpo

Details from gt_eban

Details from gt_marc.

Thank you.

Regards,

Kath

5 REPLIES 5
Read only

YorRombaut
Participant
0 Likes
1,259

Hi Katherine,

For this you probably best use the LOOP AT ... GROUP BY statement

Kind regards

Yor

Read only

former_member1716
Active Contributor
1,259

kdarunday,

Suggest you to do following steps:

1) Try fetching the entire data from respective tables with unique SELECTs.

2) Later you can use GROUP BY functionalities. You can refer below blogs for better understanding!

BLOG1

BLOG2

Regards!

Read only

Abinathsiva
Active Contributor
0 Likes
1,259

Hi,

Along with satishkumarbalasubramanian's answer which is right way approach, try by sort based on Plant and loop at .. AT NEW append to tab1 also can help.

Read only

michael_piesche
Active Contributor
0 Likes
1,259

Since you already collected all the data in your three tables, gt_ekpo, gt_eban and gt_marc, you could do the following in a loop for your plants, to print out the information:

LOOP AT gt_plants ASSIGNING <plant>. " e.g. select from T001W based on input
  
  WRITE: / <plant>-werks, ' ', <plant>-name1.

  LOOP AT gt_ekpo ASSIGNING <ekpo> WHERE werks = <plant>-werks.
    " Write details from gt_ekpo
  ENDLOOP.

  LOOP AT gt_eban ASSIGNING <eban> WHERE werks = <plant>-werks.
    " Write details from gt_eban
  ENDLOOP.

  LOOP AT gt_marc ASSIGNING <marc> WHERE werks = <plant>-werks.
    " Write details from gt_ekpo
  ENDLOOP.
ENDLOOP.

Depending on the amount of selected data, it could be useful to define primary or secondary sorted keys for gt_ekpo, gt_eban and gt_marc, in order to improve the performance when accessing those tables.

If you want to rewrite your select, you could also fetch all the data at once using several joins to combine data from T001W, EKPO, EBAN and MARC, and use the GROUP BY function on the resulting internal table.

LOOP AT it_table INTO DATA(wa).
                  GROUP BY wa-werks
                  INTO DATA(key).
   
  LOOP AT GROUP key ASSIGNING FIELD-SYMBOL(<members>).
    " collect data based on plant
  ENDLOOP.

  WRITE: / <members>-werks, ' ', <members>-name1.
  " write data collected for plant
ENDLOOP.<br>
Read only

0 Likes
1,259

kdarunday, do you continue to have issues or were you able to solve your problem?

Please add comments to your question that further describe your problem or add an answer that describes how you solved your problem.
If your problem is solved, accept an answer if it helped you and please close the question.