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: 

multiple internal tables in a where clause

Former Member
0 Kudos

Hi,

I want to write a select query such that it selects data from a standard table based on the field values given in two different internal tables.

For eg.. stdtbl is name of standard table

itab1 has values for 3 of the columns and

itab2 has values for 2 of the columns

so is there any was such that i select records from stdtbl based on the entries in itab1 AND itab2.

One way I could think of is merging these internal tables in a third internal table.

pls suggest. !!

15 REPLIES 15

Former Member
0 Kudos

Only mergingof itab's is the solution .

Former Member
0 Kudos

Hi,

I think it is not possible directly to fetch from two internal tables.

Try to combine these two internal tables and use them to fetch data from standard table.

Regards,

Dhanunjaya Reddy

JozsefSzikszai
Active Contributor
0 Kudos

>

One way I could think of is merging these internal tables in a third internal table. quote}

I think that is the only way, because with FOR ALL ENTRIES you can use only one table in one SELECT.

Former Member
0 Kudos

Hi ,

You have to merge itab1 and itab2 into a single itab3 and use for all entries in itab3 and select data fro stdtb1 table.

regards,

Ramya

Former Member
0 Kudos

Hi N A,

Yes you are correct

One way is use another internal table but there is another way also...

Use Appending table systax then you can solve your problem

First select the table entries based on first internal table and after that you can select the data from same database table by using appending table syntax.

Syntax

... INTO|APPENDING [CORRESPONDING FIELDS OF] TABLE itab [PACKAGE SIZE n] 

If you want example code then i will prepare it for you.

Regards,

Mahi.

former_member598013
Active Contributor
0 Kudos

Hi,

What you need to do is just create one table consisting of all fields and pass that fields in the internal table.

This is the only solutions...

Thanks,

Chidanand

Former Member
0 Kudos

Are both internal tables linked together? Eg. both have a common field?

Then you could use:

LOOP AT itab INTO wa_itab.

   LOOP AT itab2 into wa_itab2
       where common_field = wa_itab1-common_field.
*      Do your stuff
   ENDLOOP

ENDLOOP.

or (if there's a 1:1 relation between both tables)

LOOP AT itab INTO wa_itab.

   READ TABLE itab2 INTOwa_itab2
              WITH KEY common_field = wa_itab1-common_field.
   IF sy-subrc eq 0.
*      Do your stuff
   ENDIF.

ENDLOOP.

Although with a lot of data you might experience performance issues.

0 Kudos

Thanks all for ur promt reply!!

No there is no common field in the two tables. Both have different data.

Eg the first has company codes which can be 20 - 25 values.

and other contains a field called purgrp which will have 2 to 3 values.

So i want to select the data such that the query returns values for all the company codes for these purgrps.

0 Kudos

than best is to create select options from the internal table values, something like:

DATA : gr_bukrs TYPE RANGE OF bkpf-bukrs.
DATA : gw_bukrs LIKE LINE OF gr_bukrs.

gw_bukrs-sign = 'I'.
gw_bukrs-option = 'EQ'.
LOOP AT itab ...
gw_bukrs-low = itab-bukrs.
APPEND gw_bukrs TO gr_bukrs.
ENDLOOP.

same for the other table (or you can use FOR ALL ENTRIES with that one)

0 Kudos

Correct Eric, but then its eventually creating two more internal tables.

Instead of that option i can go for merging tables wherein i will have to make only one new internal table.

So i was thinking if there is any way we could directly write a select query. !!

Thanks for ur inputs !!

0 Kudos

>

> Correct Eric, but then its eventually creating two more internal tables.

you told one of them contains 20-25 records, the other 2-3. So I believe it is not a big problem to have two internal tables more. On the other hand you can make this in a subroutine with local data creation + the SELECT, so all internal tables will disappear after the subroutine finishes.

0 Kudos

Or add BUKRS in the internal table with EKGRP. Table T024E holds the relation between both fields.

Then you can try one of my examples.

0 Kudos

T024E actually holds the relation between Company Code and Purchasing Organisation (EKORG). If my understanding was right the OP has Purchasing Group (EKGRP) here. And unfortunately there is no relation between Company Codes and Purchasing Groups

0 Kudos

Ah yes.. my mistake! Going to buy new glasses...

Former Member
0 Kudos

Thanks a lot to everybody for your valuable inputs...

I think i will go with merging the tables !:-)