04-10-2006 4:47 PM
Hi,
I have a issue related to <b>Logic for comparing 3 internal tables data</b>.
I had decalred 3 internal Tables & Final Internal Tables as follows.
<b>DATA: BEGIN OF i_pdata1 OCCURS 0,
zzexgen LIKE zexport_class-zzexgen,
zzalnum LIKE zexport_class-zzalnum,
zzembgr LIKE zexport_class-zzembgr,
zzsecgk LIKE zexport_class-zzsecgk,
END OF i_pdata1.
DATA: BEGIN OF i_pdata2 OCCURS 0,
zzexgen LIKE zexport_customer-zzexgen,
zzkunnr LIKE zexport_customer-zzkunnr,
END OF i_pdata2.
DATA: BEGIN OF i_pdata3 OCCURS 0,
zzexgen LIKE zexport_country-zzexgen,
zzgenla LIKE zexport_country-zzgenla,
END OF i_pdata3.</b>
And Final Internal Table as:
<b>DATA: BEGIN OF i_pdata OCCURS 0,
zzexgen LIKE zexport_header-zzexgen,
END OF i_pdata.</b>
Now what i have to do is to populate all the first 3 internal tables.
And then findout common Entries for [ZZEXGEN] field in all the 3 fields and push them to i_pdata.
And make use those ZZEXGEN field values.
I had written following select statements to REtrieve and fill all the first 3 internal tables.
<b> SELECT zzexgen
zzalnum
zzembgr
zzsecgk
FROM zexport_class
INTO TABLE i_pdata1
WHERE zzalnum = i_data-alnum AND
zzembgr = i_data-embgr AND
zzsecgk = i_data-secgk.
IF sy-subrc EQ 0.
ENDIF.
SELECT zzexgen
zzkunnr
FROM zexport_customer
INTO TABLE i_pdata2
WHERE zzkunnr = i_data-kunnr.
IF sy-subrc EQ 0.
ENDIF.
SELECT zzexgen
zzgenla
FROM zexport_country
INTO TABLE i_pdata3
WHERE zzgenla = i_data-land1.
IF sy-subrc EQ 0.
ENDIF.</b>
Now i need to write a logic to find out Common entries for ZZEXGEN field in all 3 internal tables and push them to final internal table I_PDATA.
Can anybody tell me the easiest logic to do so.
<b>Ex for reference :
Internal Table I_PDATA1 would have Ext_1 and Ext_2.
Internal Table I_PDATA2 would have Ext_1 and Ext_2.
Internal Table I_PDATA3 would have Ext_1, Ext_2 & Ext_3.
Now final internal table[I_PDATA] values should be
Ext_1 and Ext_2.</b>
Can anybody tell me the logic.
Thanks in advance.
Thanks & Regards,
Rayeez.
04-10-2006 4:56 PM
Hi,
You can loop at the first table and use the READ statement for the next two tables.
loop at i_pdata1.
read table i_pdata2 with key ????
if ys-subrc = 0.
read table i_pdata3 with key ???
if sy-subrc = .
move record into i_pdata.
append i_pdata.
endif.
endif.
endloop.
For performance improvement, you can declare i_pdata2 and i_pdata3 as SORTED tables, with KEY as the columns with which you are going to READ the tables and add the BINARY SEARCH option to the READ statement.
However, I was wondering, why can't write you one SELECT joining 3 tables and dumping the data directly into i_pdata.
Regards,
Ravi
Note : Please mark the helpful answers