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: 

Is it possible to use a sub-query in dynamic selects?

BaerbelWinkler
Active Contributor
0 Kudos
422

Hi Folks,

I'd like to build a select where the components are dynamic. This is what I have so far and what works for simple selects:

  "Select is enclosed in TRY...ENTRY to catch any Syntax-errors
  "related to the dynamic where-clause provided in P_WHERE
  TRY.

      SELECT *
        FROM (p_tabn)
        INTO TABLE <t_in_itab>
       WHERE (v_whereclause).

    CATCH cx_sy_dynamic_osql_syntax cx_sy_dynamic_osql_semantics
     INTO gx_root.

  ENDTRY.

If P_TABN is filled with T001 and the below where-clause is provided, the correct data is selected and put into the itab <t_in_itab>:

BUKRS EQ 'DE50' OR BUKRS EQ 'AT10' OR BUKRS EQ 'PL10'

Now, I want to do something similar with table LIPS but where the actual selection is happening on LIKP-data.

P_TABN is filled with LIPS and the where-clause looks as follows:

VBELN IN ( SELECT VBELN FROM LIKP WHERE VKORG EQ 'DE10' OR VKORG EQ 'PL10' )

When I execute this, I get the CX_SY_DYNAMIC_OSQL_SEMANTICS exception with this error-message:

Could not interpret the value 'SELECT'

If I have the coding in "plain" writing it does work:

    SELECT *
    FROM lips
    INTO table t_lips
   WHERE VBELN IN
         ( SELECT VBELN FROM LIKP WHERE VKORG EQ 'DE10'
                                     OR VKORG EQ 'PL10' ).

Is my coding wrong or is there simply a hard and fast rule which prohibits sub-selects from being used in dynamic selects? I tried to find something in SCN and elsewhere but didn't happen upon a "yes/no" type of answer.

Thanks for any insights you have!

Cheers

Baerbel

1 ACCEPTED SOLUTION

former_member193464
Contributor
0 Kudos
92

I dont think you can write dynamic subquery in Where clause ....
you can go and check for dynamic where condition documentation in SAP it might have been written there...

5 REPLIES 5

former_member193464
Contributor
0 Kudos
93

I dont think you can write dynamic subquery in Where clause ....
you can go and check for dynamic where condition documentation in SAP it might have been written there...

0 Kudos
92

Thanks, Maverick mvx

After some more searching - not even online but in the ABAP-reference book - I did find a definite statement which says that since release 6.40 all logical expressions with the exception of sub-queries can be used in a dynamic where-clause.

Does anybody know if that restriction will perhaps be gone in a later release?

0 Kudos
92

Hi Baerbel,
                see the documentation for dynamic where

If you see in the last sentence its written , with the exception of evaluation of a subquery...
About its gonna be in the later release. Honestly no ideas on it  , but if it this restriction has not been removed till now its hard to say whether its been worked upon or not....

0 Kudos
92

Thanks again!

We somehow missed that when looking more generically into the syntax for subqueries.

Cheers

Baerbel

0 Kudos
92

yes , happens sometimes....
i remembered it coz long back i too searched for a dynamic sub query and then found this documentation in F1 help...