10-10-2008 10:18 AM
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. !!
10-10-2008 10:20 AM
10-10-2008 10:21 AM
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
10-10-2008 10:21 AM
>
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.
10-10-2008 10:22 AM
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
10-10-2008 10:22 AM
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.
10-10-2008 10:24 AM
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
10-10-2008 10:26 AM
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.
10-10-2008 10:32 AM
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.
10-10-2008 10:35 AM
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)
10-10-2008 10:38 AM
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 !!
10-10-2008 10:40 AM
>
> 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.
10-10-2008 10:42 AM
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.
10-10-2008 10:49 AM
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
10-10-2008 10:50 AM
10-10-2008 11:57 AM
Thanks a lot to everybody for your valuable inputs...
I think i will go with merging the tables !:-)