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

merging internal tables

Former Member
0 Likes
2,254

Hi Experts ,

I got 4 internal tables in my report . I have retrieved the data .

I should display the report in alv . How can i merge all the internal tables into single output table.

thanks

Raj

10 REPLIES 10
Read only

Former Member
0 Likes
1,268

You will need to declare one more table - the final table and move the contents into it from all the four tables one by one.

Thanks.

Read only

Former Member
0 Likes
1,268

Hi,

Define final internal table contains all the fields.

Use MOVE statement to insert the data into final internal table.

Ex:- MOVE it_kna1-kunnr TO it_final-kunnr.

Reward points,if it is useful.

Thanks,

Chandu.

Read only

Former Member
0 Likes
1,268

Hi,

Define final internal table contains all the fields.

by passing data from one internal table to another by

itab[] = itab2 .

itab2[] = itab3.

and define all the fields in final internal table .

or

Use MOVE statement to insert the data into final internal table.

Read only

Former Member
0 Likes
1,268

hi,

Define a final internal table with all the fields which u need to display in the report.

use MOVE statement to move the data from internal tabe to the final internal table.

Read only

Former Member
0 Likes
1,268

Hi Raj,

Create another table that will contain all the fields that you want to display in the ALV output. Move the data from the four internal tables into corresponding fields of the fourth table.

Example:

Itab_dat1, Itab_dat2, Itab_dat3, itab_dat4.

Itab_Report.

Move-Corresponding Itab_dat1 to Itab_Report.

Read only

Former Member
0 Likes
1,268

Hi declare one final internal table with all the fields, check the relation between ur internal tables which u hav the data, based on conditions u move that data into ur final internal table by using MOVE-CORRESPONDING statement.... bcaz ur internal table and ur final internal table are diffrent structures u hav to use MOVE-CORRESPONDING statement.

like...........

LOOP AT itab1 INTO wa1.

MOVE-CORRESPONDING wa1 TO ifinal.

ENDLOOP.

Read only

Former Member
0 Likes
1,268

Hi,

Declare an internal table that contains all the fields of the four internal table.

Loop the first internal table.

Move the fields using move statement.

Endloop.

Do the same procedure for the rest of the tables.

You can also give condition based on the requirement in loop.

Read only

anversha_s
Active Contributor
0 Likes
1,268

k

edited by anvar

Read only

Former Member
0 Likes
1,268

Hi Raj,

I assume that you have four internal tables with a common key field.

Please note that merging internal table is not merely moving contents of one table to another. You need to ensure that you are moving the records (rows) of one itab that corresponds to the records in another table.

Hence assume that we have two internal table with the following fields.

itab1 with field1 field2 field3

and itab2 with field1 field4 field5.

now if you want to merge the above two tables either you need to have a third internal table itab3 with field1 field2 field3 field4 and field5.

once this is available just judge which is the larger table in terms of number of records (itab1 or itab2). Assume that itab1 is larger and contains at least 1 record corresponding to an entry in itab2 and itab2 does not contain duplicate records for the key.

Now follow the below algorithm:

sort itab2 by field1.

loop at itab1.

read itab2 where field1 = field2 binary search.

(you can include code to read itab4 and itab5 also here if they have the same common field)

move-correspond itab1 to itab3.

move itab2-field4 to itab4-field4.

move itab2-field5 to itab4-field5.

(include the code to move fields from itab4 and itab5 here )

append itab3.

clear: itab2, itab3 (itab4 and itab5).

endloop.

now itab3 will have the all the fields of itab1 and itab2.

Hope the above addresses your problem.

Regards,

Girish

Edited by: girish kumar on Mar 17, 2008 10:51 AM

Read only

Former Member
0 Likes
1,268

Build an internal table with all the fields u find in all the tables.

check any commmon fields are there in between those tables

Use

LOOP AT

READ

Assignments

commands to do that. U will find syntaxes for these in ABAP documentation