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: 

ABAP 7.5 : Union in select stament

Former Member
0 Kudos

Is it possible to use UNION with FOR ALL ENTRIES ?

for e.g.

    SELECT FROM table1 AS _table1
      LEFT JOIN table2 AS _table2 ON _table1~source_doc = _table2~execution_document
        LEFT JOIN table3 AS _table3 ON _table2~instrument = _table3~instrument
       FIELDS
*-- table1 part
              _table1~pricing_key          ,
              _table1~kposn                ,
              _table1~kschl                ,
              _table1~kschl_subkey         ,


*-- table2 Part
              _table2~valid_to_tst         ,
              _table2~kbetr                ,
              _table2~document             ,
              _table2~execution_document   ,
*-- table3 Part
              _table3~instrument            ,
              _table3~pricedate_to          ,
              _table3~price
        FOR ALL ENTRIES IN @lt_sel_table1
          WHERE _table1~source_doc         =   @lt_sel_table1-source_doc AND
                _table2~cgroup_cat         =   @gc_condition AND
                _table3~pricetype          =   _table2~pricetype AND
                _table3~pricedate_to       =   @gc_max


    UNION


    SELECT FROM table1 AS _table1
      LEFT JOIN table2 AS _table2 ON _table1~pricing_key = _table2~pricing_key
        LEFT JOIN table3 AS _table3 ON _table2~instrument = _table3~instrument
        FIELDS
*-- table1 part
              _table1~pricing_key          ,
              _table1~kposn                ,
              _table1~kschl                ,
              _table1~kschl_subkey         ,
*-- table2 Part
              _table2~valid_to_tst         ,
              _table2~kbetr                ,
              _table2~document             ,
              _table2~execution_document   ,
*-- table3 Part
              _table3~instrument            ,
              _table3~pricedate_from        ,
              _table3~price
         FOR ALL ENTRIES IN @lt_sel_table1
          WHERE _table1~source_doc_type    =  'BUS2028' AND
                _table2~cgroup_cat         =  @gc_contract_condition AND
                _table3~pricedate_to       =  @gc_max


		into table @data(lt_anchored_data). 

This code gives me syntax error “UNION can not be used here . is expected”. I am not sure that it is because of FOR ALL ENTRIES or some other error.

Please suggest if the issue is known to anyone.

1 ACCEPTED SOLUTION

horst_keller
Product and Topic Expert
Product and Topic Expert

Indeed, I'm getting a little bit tired of answering please read this documentation or that documentation.

3 REPLIES 3

Former Member
0 Kudos

Thanks for the information.

horst_keller
Product and Topic Expert
Product and Topic Expert

Indeed, I'm getting a little bit tired of answering please read this documentation or that documentation.

0 Kudos
  • The addition FOR ALL ENTRIES cannot be combined with UNION.