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: 

append Internal table

Former Member
0 Kudos
209

Hi all,

I have two internal tables say itab1 has values A,B,C and itab2 has vallues X,Y. now i need to append these values in itab3. the result should be like this.here there is no where condition also..what is the code for this

A X

B Y

C

Message was edited by:

sapient s

Message was edited by:

sapient s

8 REPLIES 8

Former Member
0 Kudos
148

Hi..

PLease check this ..

Declare itab3 table according to your requirement , u can try this..

loop at itab1 .

loop at itab2 .

concatenate itab1 itab2 into itab3 .

append itab3.

endloop .

Endloop .

But not sure..

Thanks .

Former Member
0 Kudos
148

your code should roughly look like.

pseudocode, syntax may not be exact


DESCRIBE TABLE itab1 LINES l1.
DESCRIBE TABLE itab2 LINES l2.

If l1 >= l2.
 LOOP AT ITAB1 INTO wa_itab1.
   READ TABLE itab2 INTO wa_itab2 INDEX SY-TABIX.
   MOVE wa_itab1 TO itab3-field1.
   MOVE wa_itab2 TO itab3-field2.
   APPEND itab3.
 ENDLOOP.
ELSE.
  LOOP AT ITAB2 INTO wa_itab2.
   READ TABLE itab1 INTO wa_itab1 INDEX SY-TABIX.
   MOVE wa_itab2 TO itab3-field2.
   MOVE wa_itab1 TO itab3-field1.
   APPEND Itab3.
 ENDLOOP.
ENDIF.

0 Kudos
148

Hi,

I have number of internal tables like this nearly 9 tables.... and i need to append all these values in one final internal table....how to do this...when i used modify index for final internal table, i am getting duplicates in the other columes. could any one send me the logic for this

Former Member
0 Kudos
148

HI

hope d code below works for u

thank u

vijay

DATA:BEGIN OF ITAB OCCURS 1 ,

F1(15),

F2(5),

F3(5),

F4 TYPE I,

END OF ITAB.

ITAB-F1 = 'AA'.

ITAB-F2 = 'AB'.

ITAB-F3 = 'AC'.

ITAB-F4 = 1000 .

APPEND ITAB.

APPEND ITAB.

APPEND ITAB.

ITAB-F2 = 'AB'.

APPEND ITAB.

ITAB-F2 = 'AB'.

APPEND ITAB.

ITAB-F1 = 'BB'.

ITAB-F2 = 'BA'.

ITAB-F3 = 'BC'.

ITAB-F4 = 2000.

APPEND ITAB.

APPEND ITAB.

APPEND ITAB.

LOOP AT ITAB.

AT NEW F3.

WRITE:/ ITAB-F1 , ITAB-F2 , ITAB-F4.

ENDAT.

WRITE:/ ITAB-F1 , ITAB-F2 , ITAB-F4.

AT END OF F3.

SUM.

WRITE:/ 'SUB TOTALS OF' COLOR 7,ITAB-F3,'IS',ITAB-F4 COLOR 7 .

endat.

AT LAST.

SUM.

WRITE:/ 'GRAND TOTALS OF' COLOR 6 ,ITAB-F4 COLOR 6.

ENDAT.

ENDLOOP.

Former Member
0 Kudos
148

hi, check this code may be it helps

data: begin of itab occurs 0,

a type char10,

b type char10,

c type char10,

end of itab.

data: begin of itab1 occurs 0,

d type char10,

e type char10,

end of itab1.

data: begin of itab2 occurs 0,

f type char10,

g type char10,

end of itab2.

itab-a = '1'.

itab-b = '2'.

itab-c = '3'.

append itab.

itab1-d = '4'.

itab1-e = '5'.

append itab1.

concatenate itab-a itab1-d into itab2-f.

concatenate itab-b itab1-e into itab2-g.

append itab2.

Former Member
0 Kudos
148

hi Friend,

Please use the following logic.


data lv_lines1 type i.
data lv_lines2 type i.

describe table itab1 lines lv_lines1.
describe table itab2 lines lv_lines2.

if lv_lines1 GE lv_lines 2.
   loop at itab1.
       itab3-field1 = itab1-field1.
       read table itab2 index sy-tabix.
       itab3-field2 = itab2-field1.
       append itab3.
   endloop.
else.
   loop at itab2.
       itab3-field2 = itab2-field1.
       read table itab1 index sy-tabix.
       itab3-field1 = itab1-field1.
       append itab3.
   endloop.
endif. 

Hope this helps,

Sajan Joseph.

Former Member
0 Kudos
148

u need to take a variable and with that variable, u have to append the internal table simultaniously.

int a type i.

Loop at itab1.

a = a + 1.

read table itab2 with key sy-tabix = a.

itab3-field1 = itab1-field.

itab3-field2 = itab2-field.

append itab3.

endloop.

I think this hint wil help u.

Regards,

Sujatha.

Former Member
0 Kudos
148

Hi Sapient,

You can go through the following code.

data: begin of itab3 occurs 0,

itab1,

itab2,

end of itab3.

loop at itab1.

move-corresponding itab1 to itab3.

lv_tabix = sy-tabix.

read table itab2 index lv_tabix.

move-corresponding itab2 to itab3.

append itab3.

endloop.