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: 

"IN" in dynamic where clause

Former Member
0 Kudos

Hi all,

Consider following code.

TABLES: lfa1.

DATA : i_lfa1 TYPE STANDARD TABLE OF lfa1.

DATA : v_string TYPE string.

SELECT-OPTIONS : s_lifnr FOR lfa1-lifnr.

v_string = 'lifnr in s_lifnr'.

SELECT * FROM lfa1 INTO CORRESPONDING FIELDS OF TABLE i_lfa1 WHERE (v_string) .

*******************************************

when I execute above code it gives me a dump....

following is the analysis

-


Error analysis

An exception occurred. This exception will be dealt with in more detail

below. The exception, assigned to the class 'CX_SY_DYNAMIC_OSQL_SYNTAX', was

not caught, which

led to a runtime error. The reason for this 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.

Do help.

Regards

Dnyanesh

9 REPLIES 9

Former Member
0 Kudos

refer..

good discussion abt ur problem....

Simha_
Employee
Employee
0 Kudos

Hi,

as kishen said...

this might be useful..

<b>Guys can anyone provide some material on Dynamic where clause??</b>

Message was edited by: Narasimha Rao Bandla

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I don't think that you can use IN statement in dynamic WHERE clause.

Regards,

Rich Heilman

0 Kudos

Hi,

dynamic-where-clause is getting better with the newer releases:

Notes

Before SAP Web AS 6.10, it was only possible to specify an internal table with a flat character-type row type of a maximum of 72 characters for cond_syntax. It was also not possible before SAP Web AS 6.10 for the condition in cond_syntax to contain any named data objects (host variables) as operands dobj. Only literals could be specified. Finally, before SAP Web AS 6.10, a dynamic logical expression could only be used in the WHERE or HAVING condition of the select statement, but not in the statements DELETE and UPDATE.

It is possible since SAP Web AS 6.20 to evaluate an internal table specified after FOR ALL ENTRIES in a logical expression since.

It is possible since SAP Web AS 6.40 to check a selection table in a dynamic logical expression.

If cond_syntax is an internal table with a header line, the table body is evaluated, and not the header line.

-> a lot of conversions are needed.

Regards,

Christian

former_member188685
Active Contributor
0 Kudos

Hi,

You can do this way..,if you are on above 4.6c(i mean from 4.7).

REPORT  ZDYNAMIC_SELECT        .
TABLES: VBAK.
DATA: CONDITION TYPE STRING.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBAP-POSNR,
END OF ITAB.

SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.

CONCATENATE 'VBELN' 'IN' 'S_VBELN.'
INTO CONDITION SEPARATED BY SPACE.

SELECT VBELN POSNR FROM VBAP INTO TABLE ITAB
WHERE (CONDITION).

LOOP AT ITAB.
WRITE itab-vbeln.
ENDLOOP.

regards

vijay

Former Member
0 Kudos

hi,

Why ur using dynamaic where clause for select-option.

when the select-option itab is initial it is atomatically ingnored from the select query .

if u want it to dropped from select query u

refresh s_lifnr just before the select query

Former Member
0 Kudos

I ran your code in 4.7 and it didn't dump and did return what I expected. In 4.6C, it gave a syntax error.

Rob

0 Kudos

Hi Rob,

it's more depending on the version of the Web AS - you can run 4.7 from 610 (or 620) up to 640, so the basis release might differ for identical application releases.

That's obviously the case, Rob your system runs already on 640, Dnyanesh's SAP has an older basis release.

Regards,

Christian

sridhar_k1
Active Contributor
0 Kudos

Check fm FVD_SELECT_OPTIONS_2_WHERE is in ur system, does a good job of converting selectiotions to where condition.

Above FM uses FREE_SELECTIONS_RANGE_2_WHERE, which is older, try it.

Regards

Sridhar

Message was edited by: Sridhar K