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

Logic required for a Internal table issue

Former Member
0 Likes
1,143

Hi Friends,

I have two internal table, 1st one called it_table1 and 2nd one called it_table2. It_table2 having it_table1 records plus we more rows of records. for example if it_table1 having 5 rows of internal table records then it_table2 having 5 rows + 4 more rows of records, so total is 9 rows of records.

My requirement is i need that 4 more records only into another internal table called it_table3.

Pls give me a logic for this.

Mohana

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,114
loop at it_table2 into is_2.
 read table it_table1 into is_1 with key is_2-keyfield1.."use the required key fields 
 if sy-subrc NE 0. "i.e record is not present in table1.
   append is_2 to it_table3.
 endif.
endloop.

Hi Friends,

I have two internal table, 1st one called it_table1 and 2nd one called it_table2. It_table2 having it_table1 records plus we more rows of records. for example if it_table1 having 5 rows of internal table records then it_table2 having 5 rows + 4 more rows of records, so total is 9 rows of records.

My requirement is i need that 4 more records only into another internal table called it_table3.

Pls give me a logic for this.

Mohana

8 REPLIES 8
Read only

Former Member
0 Likes
1,114

Hi,

1. LOOP at ITAB2.

2. Read ITab1 with key fields

3. If sy-subrc NE 0.

4. Append it to new table...

Hope this Helps,

Nag

Edited by: Naga Mohan Kummara on Jan 12, 2010 9:59 AM

Read only

0 Likes
1,114

Actually i need the 4 rows only in to another internal table, if i use read statments, maybe the key fields records will repeat. So it wont work. anyother way is there to get the extra rows to another internal table.

Mohana

Read only

0 Likes
1,114

HI Mohana,

Correct me if my understanding is wrong..

You want to copy last 4 rows (which are not there in first internal) .. and you can not check with Key as it might have same values..

1. Describe ITAb1 - rows (say x)

2. Loop at ITAB2 where index > x

and APpend it to New internal table..

If this does not solve.. Please explain your problem with an example..

Nag

Read only

0 Likes
1,114

Hi,

You can use


it_tab3 = it_tab2.
delete it_tab1 from it_tab3.

Read only

Former Member
0 Likes
1,115
loop at it_table2 into is_2.
 read table it_table1 into is_1 with key is_2-keyfield1.."use the required key fields 
 if sy-subrc NE 0. "i.e record is not present in table1.
   append is_2 to it_table3.
 endif.
endloop.
Read only

Former Member
0 Likes
1,114

LOOP AT IT_TABLE2.

READ TABLE IT_TABLE1 WITH KEY <KEY1> = <TABLE2-KEY>.

IF SY-SUBRC NE 0.

APPEND TABLE2 TO <NEW TABLE>.

ENDIF.

ENDLOOP.

Read only

Former Member
0 Likes
1,114

Hi Mohana Vijayan,

use as follows,



Loop at tab1 into wa1.

clear wa2.
read table tab2 into wa2 with key.....<wa1-...condition>

IF sy-subrc ne 0.

append wa2 to tab3.

endif.

endloop.

Read only

Former Member
0 Likes
1,114

Hi,

Off course they will be repeated if there are any.

I think your requirement has to be solved with the solution all of them have given. If you are getting duplicate reords, use

delete adjacent duplicates from itab_3

Regards,

Sumit Nene