2010 Jan 12 8:57 AM
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
2010 Jan 12 9:02 AM
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.
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.
2010 Jan 12 8:59 AM
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
2010 Jan 12 9:24 AM
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
2010 Jan 12 9:29 AM
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
2010 Jan 12 9:48 AM
Hi,
You can use
it_tab3 = it_tab2.
delete it_tab1 from it_tab3.
2010 Jan 12 9:02 AM
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.
2010 Jan 12 9:03 AM
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.
2010 Jan 12 9:10 AM
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.
2010 Jan 12 9:28 AM
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_3Regards,
Sumit Nene
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |