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

Appending values

Former Member
0 Likes
642

Hi people,

There are itab1, itab2 and itab3. Itab3 is the final table. Now if I am writing data from both itab1 and itab2 to itab3, there are some entries which exist both in itab1 and itab2 although I am trying apply an if endif condition to eliminate entries from going into itab 2. Both times i am appending values from itab1 and itab2 to itab3.

Can somebody suggest something?

Thanks,

AM

6 REPLIES 6
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
566

Hi,

If you are talking about dupilcate entries,then you can do the following.After getting records from both itab1 and itab2,use the following.

sort itab3.

delete adjacent duplicates from itab3.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
566

Hi,

If the structures of internal table are same,then you can do the following if you want to combine both the internal tables.

Append lines of itab1 to itab2.

sort itab2.

delete adjacent duplicates from itab2.

Read only

0 Likes
566

Hey people,

This did not solve my problem.

What i am doing is getting information from itab1 into ftab. Then I am manipulating itab2 to put data into itab 3 and then finally from itab3 the data goes into ftab. So there are values coming to ftab from itab1 which are also coming into ftab from itab3 which I want to keep in ftab but delete the values coming in from itab1 for the same customer. kunnr is a field in ftab. and values from itab1 are written before values from itab3 as follows:

123 itab1 values

123 itab3 values

234 itab1 values

234 itab1 values

235 itab1 values

--

--

--

342 itab3 values

and so on.

So can somebody help.

thanks,

AM

Read only

0 Likes
566

Hi,

In your internal table ftab,make use of one more field flag.

Set the flag = '' if you are populating ftab from itab1.

Set the flag = 'X' if you are populating ftab from itab3.

After you get the values in ftab,

sort ftab by kunnr flag.

delete adjacent duplicates from ftab comparing kunnr flag.

This will delete the similar kunnr which you already populated using itab1.

Read only

Former Member
0 Likes
566

Hi,

I will give u a sample code

LOOP AT itab1 into w_itab1.

READ itab2 into w_itab2 with key

fieldname = w_itab1-fieldname(common field from both the table)

if sy-subrc = 0.

MOVE-CoREESPONDING w_itab1 to w_itab3.

MOVE-CoREESPONDING w_itab2 to w_itab3.

Append w_itab3 to itab3.

endif.

clear: w_itab1, itab2, itab3.

Endloop.

Hope this helps , if u want more clarification do get back to me.

Thanks & Regards,

Judith.

Read only

0 Likes
566

Hi ,

The previous logic is correct but if we are deleting the entries in the itab1 and itab2 after appending it to itab3.Then it will be easy to append those records which are not common.

Sample code

LOOP AT itab1

READ itab2 with key

fieldname = w_itab1-fieldname(common field from both the table)

if sy-subrc = 0.

move-corresponding itab1 to itab3.

Append itab3.

delete itab1.

delete itab2.

endif.

append lines of itab1 to itab3.

append lines of itab2 to itab3.

Endloop.

I think it will help u.

With Regards,

Ranganathan.