on 11-15-2004 3:55 PM
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
Hi Arunava,
As already said, before release 6.4 this is not possible.
However a solution is quite simple.
If you look at the ranges (or select-options) they are themselves internal tables with a line by line selection condition.
Simply transfer those selection conditions to your "WHERE" table with the operator AND connecting them line by line.
Suppose your R_MERKMAL1 contains
1.R_MERKMAL1-OPTION = 'BT'
R_MERKMAL1-SIGN = 'I'
R_MERKMAL1-LOW = 'A'
R_MERKMAL1-HIGH = 'Z'
2.R_MERKMAL1-OPTION = 'EQ'
R_MERKMAL1-SIGN = 'I'
R_MERKMAL1-LOW = '1'
R_MERKMAL1-HIGH = ''
you would add this to your "WHERE" table like this:
DATA: FIELD(72) TYPE C.
LOOP AT R_MERKMAL1.
IF R_MERKMAL1-OPTION EQ 'BT'
CONCATENATE 'AND MERKMAL1 BETWEEN'
R_MERKMAL1-LOW
'AND'
R_MERKMAL1-HIGH
INTO FIELD
SEPARATED BY SPACE.
ELSEIF R R_MERKMAL1-OPTION EQ 'NB'.
CONCATENATE 'AND MERKMAL1 NOT BETWEEN'
R_MERKMAL1-LOW
'AND'
R_MERKMAL1-HIGH
INTO FIELD
SEPARATED BY SPACE.
ELSE.
CONCATENATE 'AND MERKMAL1'
R_MERKMAL1-OPTION
R_MERKMAL1-LOW
INTO FIELD
SEPARATED BY SPACE.
ENDIF.
APPEND FIELD TO VIT_WHERE.
ENDLOOP.
Hope this gives you a clue.
Regards,
Rob.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is possible since SAP Web AS 6.40 to check a selection table in a dynamic logical expression. It is not possible before Release 6.40.
Sorry.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.