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: 

Dynamic SQL and Sub Query

Former Member
0 Kudos

I want need to use dynamic SQL, and include a subquery in the where clause. However, I am getting a syntax error.

I have code that looks like this.


    SELECT (p_v_sqlobj_select)
        INTO CORRESPONDING FIELDS OF TABLE <matrix>
      FROM (p_v_sqlobj_from)
      WHERE (p_v_sqlobj_where).

and I pass it the following bold-faced SQL where clause (please ignore whether the statement makes sense and is the best way to do it - this is just to illustrate). However, it returns an error.

select tcode from tstc where tcode in <b>( select min( tcode ) as min from tstc )</b>

Am I correct in concluding that I cannot pass complex statements, or have I just missed something?

Thanks for any help.

3 REPLIES 3

Former Member
0 Kudos

Hi

TABLES: EKKO.

DATA L_WHERECOND TYPE TEXT50 OCCURS 0 WITH HEADER LINE.

CONCATENATE 'EBELN' 'EQ' '4500016938'

INTO L_WHERECOND SEPARATED BY SPACE.

APPEND L_WHERECOND.

SELECT SINGLE * FROM EKKO

WHERE (L_WHERECOND).

WRITE: SY-SUBRC.

WRITE: EKKO-EBELN, ekko-ebeln.

thanks

Mahesh

former_member194669
Active Contributor
0 Kudos

Hi,

Please try with order by clause in select statement and also use descending


      select * from (p_table)
               into corresponding fields of table <ptab>
              up to p_rows rows
              order by <fieldname> descending.

aRs

Former Member
0 Kudos

Hello Jerry,

I guess

SELECT

(p_v_sqlobj_select) "<-------this is not possible.

INTO CORRESPONDING FIELDS OF TABLE <matrix>

FROM (p_v_sqlobj_from) <-----this is possible

WHERE (p_v_sqlobj_where). <-----this is possible internal table of field 72 char .

Regards,

A.Singh