Application Development 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: 

extracting from table based on conditions from two internal tables

Former Member
0 Kudos

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?

6 REPLIES 6

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

Clemenss
Active Contributor
0 Kudos

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

Former Member
0 Kudos

solved

0 Kudos

Hi Maansi,

Thank you for sharing the solution. This really helps.

Regards,

Clemens