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

Internal Tables

Former Member
0 Likes
686

Hi Friends,

My query is, assume that have two internal tables as itab1 and itab2 ?

I need to pass the unique records to third internal table....

Let me know pls completely.....

Hope, early reply from your end.

Thanks & Regards,

Rahul Khan

5 REPLIES 5
Read only

matt
Active Contributor
0 Likes
646
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
646

HI Rahul,

Unique as in i consider you have one field commomn in both tables which should be unique let the field be 'KEY'...


DELETE ADJACENT DUPLICATES FROM itab1 COMPARING key.

itab_final[] = itab1[].

LOOP AT itab2.
  READ TABLE itab_final WITH KEY key = itab2-key.
  IF sy-subrc NE 0.
    itab_final = itab2.
    APPEND itab_final.
  ENDIF.
ENDLOOP>

Read only

Former Member
0 Likes
646

Hi Rahul,

Try it this way:

Data:
  w_lines  type i,
  w_index type i value 1.

Describe table itab1 lines w_lines.

While w_index LE w_lines.
Read table itab1 into wa1 index w_index.
  
   Read table itab2 into wa2 with key field1 = wa1-field1.
   If sy-subrc eq 0.
      wa3-field1 = wa1-field1.
      wa3-field2 = wa1-field2.
      wa3-field3 = wa2-field2.
      wa3-field4 = wa2-field3.
      Append wa3 to itab3.
   Endif.
w_index = w_index + 1.
Endwhile

With luck,

Pritam.

Read only

Former Member
0 Likes
646

Hi Rahul,

If Itab1, Itab2 & itab3 are identical

( Append Itab1 to itab3.

Append itab2 to itab3.

Sort Itab3.

Delete adjacent duplicates of itab3. ) is the better way to proceed.

Regards

Sravan

Read only

Former Member
0 Likes
646

Hi Rahul,

This transfers only unique entries from tab1 to tab3.

describe table itab1 lines w_lines.

loop at itab1.

w_idx = sy-tabix + 1.

do w_lines times.

read table itab1 index w_idx comparing all fields transporting no fields.

if sy-subrc eq 0.

fl_flag = 1.

exit.

endif.

add 1 to w_idx.

if w_idx gt w_lines.

exit.

endif.

enddo.

if fl_flag ne 1.

append itab1 to itab3.

fl_flag = 0.

endif.

endloop.

Regards,

Mdi.Deeba