‎2011 Dec 15 4:21 AM
Hi,
I have two internal tables ITAB and ITAB1. I have to compare the two tables based on a Field 'MATKL'.
That is, ITAB contains a list of MATKL, and ITAB1 has MATKL and their corresponding MATNR's.
I have to keep only those records in ITAB1, which have a corresponding record in ITAB.
Please suggest.
‎2011 Dec 15 4:27 AM
you can achieve this before loading the internal table ITAB1
Just in the Select Statement for ITAB1 use for all entries.
ex:
SELECT * FROM <TABLE>
INTO CORRESPONDING FIELDS OF TABLE ITAB1
FOR ALL ENTRIES IN ITAB
WHERE MATKL = ITAB1-MATKL.
‎2011 Dec 15 4:43 AM
Hi,
Your post i dint get ,can you elaborate clearly you want to fetch from single table and placed that same value in other table.
If you want to place common matnr in internal table use for all entries in the second query.
Regards,
G.Aditya
Edited by: Aditya.G on Dec 15, 2011 10:18 AM
Edited by: Aditya.G on Dec 15, 2011 10:21 AM
‎2011 Dec 15 5:06 AM
Hi Aditya,
My query is :
I have a table ITAB populated through various select logics, it contains the field 'MATNR''.
There's another table ITAB1, which fetches data (MATNR) from MARA for specific 'MATKL' (picked from another table).
I have to keep only those records in ITAB, for which there is a corresponding record in the table ITAB1, and delete the others.
‎2011 Dec 15 5:13 AM
Hi,
From which table you retrieve the data for the first query.
‎2011 Dec 15 5:23 AM
Then You try like this,
with this logic you delete the entries which doesnt have in ITAB
LOOP AT ITAB1 INTO WA_ITAB1.
READ TABLE ITAB WITH KEY MATKL = WA_ITAB1-MATKL TRANSPORTING NO FIELDS.
IF SY-SUBRC NE 0.
DELETE ITAB1 INDEX SY-TABIX.
ENDIF.
ENDLOOP.
‎2011 Dec 15 5:25 AM
Hi Ravi,
The first Internal Table is fetched from multiple tables, and some fields are calculated and then appended.
‎2011 Dec 15 5:34 AM
Hi Bachack,
// use this query
select * from mara into corresponding fields of table itab1 for all entries in itab where matnr = itab-matnr.
// This query retrieves the data for the revelant matnr in itab .
‎2011 Dec 15 4:44 AM
Hi,
SELECT * FROM ITAB
INTO CORRESPONDING FIELDS OF ITAB1
WHERE MATKL = ITAB1-MATKL.
Warm Regards,
PavanKumar.G
Edited by: pavankumar.g on Dec 15, 2011 5:45 AM
‎2011 Dec 15 4:53 AM
Hi Pavan,
I tried this but I get an error " 'ITAB' is not defined in the ABAP dictionary as a table, projection view, or database view."
‎2011 Dec 15 5:00 AM
Hi Bach,
Try this one
SELECT * FROM MARA
INTO CORRESPONDING FIELDS OF TABLE ITAB1
FOR ALL ENTRIES IN ITAB
WHERE MATKL = ITAB1-MATkL.
Warm Regards,
PavanKumar.G
Edited by: pavankumar.g on Dec 15, 2011 6:01 AM
Edited by: pavankumar.g on Dec 15, 2011 6:11 AM
‎2011 Dec 15 5:07 AM
hi,
select statement won,t work for internal tables,it's only to fetch the data from data base table.that is the reason it is showing error.use DB table instead of internal table.
Thanks
Naresh
‎2011 Dec 15 4:57 AM
HI,
Use the following code ..
first create an internal table with required fields.
for eg:
data:begin of it_final occurs 0,
matnr type matnr,
maktl type maktl,
end of it_final.
Loop at itab.
read table itab1 into wa with key where matnr = itab-matnr.
move wa-matnr to it_final-matnr.
move wa-maktl to it_final-maktl.
append it_final.
clear it_final.
endloop.Now you have required fields into your internal table
Edited by: naresh bammidi on Dec 15, 2011 5:58 AM
‎2011 Dec 15 5:00 AM
Hi,
select * from mara into corresponding fields of table itab .
if itab is not initial.
select * from mara into corresponding fields of table itab1 for all entries in itab where maktl = itab-maktl.
endif.
‎2011 Dec 15 10:37 AM
Hi,
Try below logic.
Data : LW_TABIX TYPE SYTABIX.
LOOP AT ITAB1 INTO WA_ITAB1.
CLEAR LW_TABIX.
LW_TABIX = SY-TABIX.
READ TABLE ITAB WITH KEY MATKL = WA_ITAB1-MATKL TRANSPORTING NO FIELDS.
IF SY-SUBRC NE 0.
DELETE ITAB1 INDEX LW_TABIX.
ENDIF.
ENDLOOP.
BR,
Vijay
‎2011 Dec 15 10:47 AM
The Simplest solution for your query is :
LOOP AT ITAB1 INTO WA.
READ TABLE ITAB TRANSPORTING NO FIELD WITH KEY MATNR = WA1-MATNR AND MATKL = WA1-MATKL.
IF SY-SUBRC <> 0.
DELETE ITAB1 FROM WA.
ENDIF.
ENDLOOP.
Try it at your end.
Thanks,
Anmol.