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

append internal table

Former Member
0 Likes
1,337

Hi all,

I have 2 internal tables and i want to append it another table. data of both are like below.

1.internal table : itab.

in this field BANFN. values are like :

81000

81001

81002

81003

81004

2. internal table : itab1.

same field BANFN. values are like :

81000

81001

81002

81003

I want third internal table having combination of both and values are like:

81000

81001

81002

81003

81004

Plz help me..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,294

Hi,

Try this..

LOOP AT ITAB.

READ TABLE ITAB1 WITH KEY BANFN = ITAB-BANFN.

IF SY-SUBRC = 0.

APPEND ITAB1 TO ITAB2.

ELSE.

APPEND ITAB TO ITAB2.

ENDIF.

ENDLOOP.

12 REPLIES 12
Read only

Former Member
0 Likes
1,294

hi

1>take one more table of same type as of itab.

2> loop through 1 table and readt the second table

3> if entries found then pass it to the third table

eg

loop at itab

read table itab1 ....

if sy-subrc eq 0.

move to itab2

endif.

endloop.

Read only

JozsefSzikszai
Active Contributor
0 Likes
1,294
APPEND LINES OF itab1 TO itab3.
APPEND LINES OF itab2 TO itab3.
SORT itab3.
DELETE ADJACENT DUPLICATES FROM itab3.
Read only

Former Member
0 Likes
1,294

Hi,

Do it through Erics Method.

Amresh.

Read only

Former Member
0 Likes
1,294

HI Ankitha,

Do you have any other fields apart from these.

anyhow.

loop at itab1.

move itab1 to final.

append final.

endloop.

loop at itab2.

read table final with key banfn = itab2-banfn,

if sy-subrc is not initial.

move itab2 to final

append final.

endif.

endloop.

try this out.

Eric's approch is better one

Regards

Ramchander Rao.K

Edited by: ramchander krishnamraju on Nov 27, 2008 9:58 AM

Read only

0 Likes
1,294

Hi Ramchandar..

your logic may be right but it does not work for such internal table

output of ur logic is like .

81000

81001

81001

81003

81000

81001

81002

81003

81004

I want same column.

output like:

81000

81001

81002

81003

81004

Read only

0 Likes
1,294

Hi Ankitha,

You need to write the output after the final append into the final table from both the 2 internal tables.

even eric's method is better one , try that.

Regards

Ramchander Rao.K

Read only

0 Likes
1,294

Hi,

Erics Method is feasible. try for tht.

Take one more internal table of same type.

Append itab1 to that internal table.

Append another itab2 to same internal table.

Now delete the adjacent duplicate entries from new table .

Thanks.

Read only

Former Member
0 Likes
1,294

use select queyr with APPENDING CORRESPONDING FIELDS OF TABLE <internal table>

Read only

agnihotro_sinha2
Active Contributor
0 Likes
1,294

loop at table itab into wa1.
append to fina_tab.

read table itab1 into wa2.

if ay-subrc NE 0.

append to final_tab.

endif.

endif.

endloop.
Read only

Former Member
0 Likes
1,294

seee this example

DATA : BEGIN OF ITAB OCCURS 0,

NAME(3),

VALUE TYPE I,

END OF ITAB.

DATA : BEGIN OF ITAB1 OCCURS 0,

NAME(3),

VALUE TYPE I,

END OF ITAB1.

DATA : BEGIN OF ITAB3 OCCURS 0,

NAME(3),

VALUE TYPE I,

END OF ITAB3.

ITAB-NAME = 'abc'.

ITAB-VALUE = 100.

APPEND ITAB.

ITAB-NAME = 'abd'.

ITAB-VALUE = 100.

APPEND ITAB.

ITAB-NAME = 'abc'.

ITAB-VALUE = 100.

APPEND ITAB.

ITAB-NAME = 'abd'.

ITAB-VALUE = 300.

APPEND ITAB.

ITAB1-NAME = 'abc'.

ITAB1-VALUE = 100.

APPEND ITAB1.

ITAB1-NAME = 'abd'.

ITAB1-VALUE = 100.

APPEND ITAB1.

ITAB1-NAME = 'abc'.

ITAB1-VALUE = 100.

APPEND ITAB1.

break developer.

loop at itab.

move itab to itab3.

append itab3.

endloop.

loop at itab1.

read table itab3 with key name = itab1-name.

if sy-subrc <> 0.

move itab1 to itab3.

append itab3.

endif.

endloop.

Read only

Former Member
0 Likes
1,294

loop at itab into wa_itab

append itab_final from wa_itab.

loop at itab1 into wa_itab1

append itab_final from wa_itab1.

then use delete adjacent command and sort command to get desired result.

Read only

Former Member
0 Likes
1,295

Hi,

Try this..

LOOP AT ITAB.

READ TABLE ITAB1 WITH KEY BANFN = ITAB-BANFN.

IF SY-SUBRC = 0.

APPEND ITAB1 TO ITAB2.

ELSE.

APPEND ITAB TO ITAB2.

ENDIF.

ENDLOOP.