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: 

problems with dynamic "EXISTS" statements

Former Member
0 Kudos

Hi experts,

We are making a program to show a list. To look for all the information that our customer need,  we have to do some rather complex and  long SELECT statement. To reduce the cost of maintaining of the program,  I´m trying to introduce dynamic code in sentence "WHERE" ,  depending on the fields that users introduce via selection screen. But I have a problem with dynamic statement "  EXISTS " when I execute the program.

I obtain an error 'SAPSQL_INVALID_FIELDNAME' .  The program  identifies  EXISTS as the  name of a column.

If i write the literal sentence (no dynamic) the program is correctly executed.

I have read something about to  GENERATE SUBROUTINE POOL but at this point this would be more complex than repeat the  statement with and without EXISTS depending the selection and in diferent parts of the program. I don´t like and I know it is  an awfull solution  but it is a solution.

Has had somebody  the same problem and  has  found a solution ?

Thanks for your help

.

4 REPLIES 4

Private_Member_49934
Contributor
0 Kudos

to the best of my understanding EXISTS is used with subqueries. Subqueries are themselves select statments. And you can't have select statement fully dynamics without having the static keywords SELECT, FROM , WHERE , etc. So you must be getting this error

Former Member
0 Kudos

As Kumar writes, EXISTS would appear in a subquery within the where clause.  But, just a question, how are you using exists?   Are you writing something like 'and fieldname exists' ?    Have you reviewed the subquery construction via F1 ABAP Help, or in SE30's Tips and Tricks example?

Former Member
0 Kudos

Hi,

If the idea is to only generate dynamic where clause, just leave the EXISTS option out of it.

e.g:

SELECT *

    FROM dbtab1 AS s

    INTO TABLE itab

   WHERE (lv_where1) AND
          EXISTS ( SELECT  *

                     FROM  dbtab2

                     WHERE (lv_where2) ).

Cheers,

Manu.

Former Member
0 Kudos

Hi,

i know the last solution works properly (and also that EXISTS is a subquery) but It isn´t that I need. I need some way to "trick" the system to "swallow" the proposed code and  by this way  reduce the cost of maintenance code due to the large number of selections that I have to do If I can´t to do it by this way, in order to reduce the cost of access to database (the selection screen defined by our customer is quite ilogical and "brutal").

The database is being continuously monitored, and when it is " a little heavier" then they  protest immediately.