Skip to Content
0
Former Member
Nov 15, 2004 at 03:55 PM

Dynamic Where Clause

85 Views

Hi Frineds,

I am facing some problem with regards to Dynamic Where clause in my Select Statement.

I have a few ranges table and want them to be conmsidered in the Dynamic Where Clause.

the static query will look like...

SELECT *

FROM /SAPAPO/FCST_LC1

INTO TABLE VIT_FCST_LC

WHERE (vit_where).

PAREAID = L_PLANAREA

AND MERKMAL1 IN R_MERKMAL1

AND MERKMAL2 IN R_MERKMAL2

AND MERKMAL3 IN R_MERKMAL3

AND MERKMAL4 IN R_MERKMAL4

AND MERKMAL5 IN R_MERKMAL5

AND MERKMAL6 IN R_MERKMAL6.

I want to convert it into dynamic where clause. I had declared an Internal Table with a Char72 length Field.

I keep on appending the Statements into this table as given below....

Concatenate 'AND MERKMAL1' 'IN R_MERKMAL1' into vit_where-cond separated by space.

Append vit_where.

The table has all the required condition statements. But the Problem comes while execution.

Because of the IN statement and Ranges tables...It gives me a dump saying...

The WHERE condition has an unexpected format. And The reason for the exception is:

The current ABAP/4 program attempted to execute an ABAP/4 Open SQL

statement containing a WHERE condition of the form WHERE (itab) or

WHERE ... AND (itab). The part of the WHERE condition specified at

runtime in the internal table itab contains the operator

IN (v1, ..., vn)

in incomplete form.

What I get from this is that the Ranges are not getting considered for the Dynamic where Clause and the IN statement is throwing the Error.

So How Can I include RANGES or SELECT-OPTIONS in my Dynamic Where Clause.

Thanks and Regards,

Arunava