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

Reg. Internal table

Former Member
0 Likes
724

Dear Experts,

I want to merge three internal table values into single final internal table.

How to do that?

For e.g see this internal table field structures

Internal table 1 : F1, F2, F3, F4, F5

Internal table 2 : F1, F6, F7

Internal table 3 : F1, F8, F9, F10

I want append all these internal table values in to final internal table without changing their respective structures.

Like If I append itab 2 and 3 after itab 1 then it should be like this.

Final internal table:

F1, F2, F3, F4, F5

F1, F2, F3, F4, F5

F1, F6, F7

F1, F6, F7

F1, F6, F7

F1, F8, F9, F10

I dont want to create final internal table structure with all other fields and by using 'INTO CORRESPONDING FIELDS' to append all those values by leaving other field values empty.

The final internal table values should have their respective internal table structure in each row of values.

Kindly show some light on how to do this.

Regards,

Sakthi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
683

Hi,

Let your final internal table have 5 fields ... 1 2 3 4 5

Now ...

Loop at ITAB1.

final-1 = itab1-f1.

final-2 = itab1-f2.

final-3 = itab1-f3.

final-4 = itab1-f4.

final-5 = itab1-f5.

append final.

clear final.

endloop.

similarly

Loop at ITAB2.

final-1 = itab2-f1.

final-2 = itab2-f6.

final-3 = itab2-f7.

append final.

clear final.

endloop.

Loop at ITAB3.

final-1 = itab3-f1.

final-2 = itab3-f8.

final-3 = itab3-f9.

final-4 = itab3-f10.

append final.

clear final.

endloop.

Regards,

Srini.

5 REPLIES 5
Read only

Former Member
0 Likes
684

Hi,

Let your final internal table have 5 fields ... 1 2 3 4 5

Now ...

Loop at ITAB1.

final-1 = itab1-f1.

final-2 = itab1-f2.

final-3 = itab1-f3.

final-4 = itab1-f4.

final-5 = itab1-f5.

append final.

clear final.

endloop.

similarly

Loop at ITAB2.

final-1 = itab2-f1.

final-2 = itab2-f6.

final-3 = itab2-f7.

append final.

clear final.

endloop.

Loop at ITAB3.

final-1 = itab3-f1.

final-2 = itab3-f8.

final-3 = itab3-f9.

final-4 = itab3-f10.

append final.

clear final.

endloop.

Regards,

Srini.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
683

You can create an internal table of DATA references & append the internal tables as shown:

DATA: v_table LIKE dd02l-tabname,
      it_data TYPE STANDARD TABLE OF REF TO data,
      wa_data TYPE REF TO data.

FIELD-SYMBOLS <itab> TYPE STANDARD TABLE.

SELECT-OPTIONS: s_table FOR v_table NO INTERVALS OBLIGATORY.

LOOP AT s_table.
  CREATE DATA wa_data TYPE STANDARD TABLE OF (s_table-low).
  ASSIGN wa_data->* TO <itab>.
  CHECK sy-subrc = 0.
  TRY.
      SELECT * FROM (s_table-low) INTO TABLE <itab> UP TO 10 ROWS.
      APPEND wa_data TO it_data.
    CATCH cx_sy_sql_error.
  ENDTRY.
ENDLOOP.

LOOP AT it_data INTO wa_data.

ENDLOOP.

BR,

Suhas

Read only

Former Member
0 Likes
682

Thank Suhas.

This logic will works to create dynamic internal table. But my requirement is already three internal tables has been created with different fields.

If I want to append all the values of three internal table into one final internal table then what shall I do?

For e.g. I need an final internal table like this:

F1 F2 F3 F4 F5

F1 F2 F3 F4 F5

F1 F6 F7

F1 F6 F7

F1 F8

F1 F8

First two records are itab 1, next two records are from itab 2 and next two records are from itab 3.

I want to maintain the data structure of itab as it is as I want to download this final internal table into XML.

Regards,

Sakthi

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
682

Hello Sakthi,

The structure of your internal table is defined once during data declaration & can't be changed during runtime.

As er your requirement, your internal table should contain data reference objects. If you've the 3 internal tables defined statically you've to GET REFERENCE of them in some data object & populate your final internal table.

Check this code reference for details:

DATA: it1 TYPE STANDARD TABLE OF t000,
      it2 TYPE STANDARD TABLE OF t001,
      it3 TYPE STANDARD TABLE OF t100,
      it_final TYPE STANDARD TABLE OF REF TO data,
      wa_data TYPE REF TO data.

SELECT * FROM t000 INTO TABLE it1 UP TO 10 ROWS.
CHECK sy-subrc = 0.
GET REFERENCE OF it1 INTO wa_data.
APPEND wa_data TO it_final.CLEAR wa_data.

SELECT * FROM t001 INTO TABLE it2 UP TO 10 ROWS.
CHECK sy-subrc = 0.
GET REFERENCE OF it2 INTO wa_data.
APPEND wa_data TO it_final.CLEAR wa_data.

SELECT * FROM t100 INTO TABLE it3 UP TO 10 ROWS.
CHECK sy-subrc = 0.
GET REFERENCE OF it3 INTO wa_data.
APPEND wa_data TO it_final.CLEAR wa_data.

BR,

Suhas

Read only

Former Member
0 Likes
682

Thank you. Suhas. I got some new ideas from your reply.

I have managed to solve the issue in a different way.

Here are the steps.

1. I have declared a final internal table in a nested way which is shown below:

types : begin of ty_fin,

itab1 like it_first_itab,

itab2 like it_sec_itab,

itab3 like it_thr_itab,

end of ty_fin.

data : IT_FIN type standard table of ty_fin,

wa_fin type ty_fin.

2. Then I have moved all the values of my it_first_itab to itab1 and respectively for other two internal tables.

wa_fin-itab1 = it_first_itab[].

similarly for the other two internal table.

3. Append the wa_fin to final internal table - IT_FIN.

Here we will get all the different kinds of internal table values in single internal table and we can use the values as per our requirement further.

Thank you.

Regards,

Sakthi.

Edited by: Sakthi Saravanan C on Aug 25, 2010 6:34 PM