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: 

Select query with multiple table fileds in where condition

skakamari2194
Explorer
0 Kudos

Hi,

Case : in one select query where condition it don't allow to pass multiple for all entries.

In that's case : I used to write like select single in loop i can pass as required fields( From different wa ) in where condtion fields. .

For that any other shortcut or other than multiple query .

Kindly post ur using methods in that case.

7 REPLIES 7

Abinathsiva
Active Contributor

Hi,

Select all required table with all conditions and store it on relevant Internal table.

loop the main table and read all other values with Read statement instead of select single...

0 Kudos

Hi,

Thank you for response.
Yes, As you said i feel its works if it contains less data.

Hi, In that case try joins

0 Kudos

Hi,


Yes i can use joins but there also i can use one for all entries, In my case i have two different internal table one is having material number,

another one sales order number i cant merge also.

Sandra_Rossi
Active Contributor
0 Kudos

You say "don't allow to pass multiple for all entries".

I think it's not even needed: why wouldn't you convert those "multiple for all entries" into one "for all entries", by joining the internal tables into one?

skakamari2194
Explorer
0 Kudos

Hi Sandra,
I am not joining multiple table into one, if join also it won't achieve my requirement.
for my required field i need to pass Different table field in where condition.

raymond_giuseppi
Active Contributor

How many records do you expect in internal tables used for selection, can you consider converting some into range (select-options)

How are your selection internal tables built, could you consider join (or subquery) between the final table(s) and the table used to build those internal tables.

* Replace
SELECT * FROM mara INTO t_mara WHERE...
SELECT * FROM mseg INTO t_final FOR ALL ENTRIES IN t_mara... WHERE ... 
* with
SELECT * FROM mseg INTO t_final WHERE ... EXISTS( SELECT * FROM mara WHERE ...

Is it possible to combine internal tables into a single table or do you get a much too big internal table (e.g. thousands x thousands records)

LOOP AT itab1 ASSIGNING <fs1>.
  LOOP AT itab2 ASSIGNING <fs2>.
    APPEND INITIAL LINE TO itall ASSIGNING <fs>.
    <fs>-field1 = <fs1>. " or <fs1>-field1.
    <fs>-field2 = <fs2>. " or <fs2>-field2.
  ENDLOOP.
ENDLOOP.
SELECT ( fiedlist ) FROM ...
  FOR ALL ENTRIES IN itaball  
  WHERE file1~field1 EQ itabll-field1 AND file2~field2 EQ itaball-field2 ...

in this last case consider breaking one (or more) of the criteria into smaller packages suitable for a range (select-option) within SQL tolerance (SQL statement size)

LOOP AT itab ASSIGNING <fs>.
  l_tabix = sy-tabix.  
  APPEND INITIAL LINE To wrange ASSIGNING <so>.
  <so>-sign = 'I'.
  <so>-option = 'EQ'.
  <so>-low = <fs>. " or <fs>-somefield
  IF lines( wrange ) EQ 200 OR l_tabix EQ lines( itab ).
     SELECT ( fiedlist ) APPENDING finaltable 
       FROM ... 
       FOR ALL ENTRIES IN anotheritab
       WHERE somefieeld IN wrange 
         AND antoherfield EQ anotheritab-anotherfield...
     REFRESH wrange.
  ENDIF.
ENDLOOP.