02-18-2011 4:37 AM
Hi,
i to have select few records from a table based on conditions from two different internal tables. How can I achieve this.?
ex:
select objid from HRVPAD25 into table t_pad25
where PLVAR = 01
OTYPE = E
OBJID = itab1-sobid
sobid = itab2-pernr.
How can this be written? can i use "for all entries..." addition with 2 tables?
02-18-2011 4:44 AM
Hi Maansi
You cannot use two internal table with FOR ALL ENTRIES ADDITION. You need the merge the two internal table and use the single internal table. So in your case, you need to build your internal table such that for SOBID from ITAB1 you need to have all the records PERNR from ITAB2.
Regards
Ranganath
02-18-2011 4:47 AM
Hi Mansi,
Query you have written will not work, it is not possible to use two internal tables in where clause.
I think you have to analyse your requirement and then think how to achieve this.
May be inner join could serve your purpose.
Hope this helps.
02-19-2011 3:04 PM
Hi,
Take two internal tables has to be as internal table and set as select that tables by an for all entries in i_tab
following below code. It will works. Try below code
SELECT field FROM dbtab INTO TABLE itab PACKAGE SIZE 500 FOR ALL ENTRIES IN i_tab WHERE conditions
**Here you can process itab ( will always contain <= 500 records
ENDSELECT.
02-19-2011 7:58 PM
Hi Maansi_SAP,
you can use exactly one internal table in the FOR ALL ENTRIES clause. Consider this alternative:
data:
itab_sobid_hash like itab1 with unique key sobid,
ls_pad25 like line of t_pad25.
sort itab1.
delete adjacend duplicates from itab1 comparing sobid.
itab_sobid_hash = itab1.
select objid
into ls_pad25
from HRVPAD25
for all entries in itab2
where PLVAR = '01'
and OTYPE = E
and sobid = itab2-pernr..
read table itab_sobid_hash with table key sobid = ls_pad25-objid.
check sy-subrc = 0.
append ls_pad25 to t_pad25.
endselect.
You may decide if itab1 or itab2 is better used as hashed table. Make a performance test.
The critics will tell you that SELECT ... ENDSELECT is not performant. That was very true, back in last milleniums's 90ies
Regards,
Clemens
04-12-2011 8:26 AM
04-12-2011 8:43 AM
Hi Maansi,
Thank you for sharing the solution. This really helps.
Regards,
Clemens