Application Development and Automation 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: 
Read only

Problem in dynamic where clause

Former Member
0 Likes
1,056

Hi All,

I am using a dynamic internal, populating the same in program itself and the trying to pass the same in the select clause

following 2 lines are populated in the internal table i_where.

DATA i_where TYPE STANDARD TABLE OF char100.

these lines are populated in i_where.

  • A~LIFNR IN <L_TABLE1>

  • AND A~LIFNR = vendor_tab-LIFNR.

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

SELECT a~lifnr FROM lfa1 as a

inner join lfm1 as m

on alifnr = mlifnr

INTO TABLE i_vendor

FOR ALL ENTRIES IN vendor_tab

WHERE (i_where).

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

but the query doesnt execute......

if I write the same query as

SELECT a~lifnr FROM lfa1 as a

inner join lfm1 as m

on alifnr = mlifnr

INTO TABLE i_vendor

FOR ALL ENTRIES IN vendor_tab

WHERE A~LIFNR IN <L_TABLE1>

AND A~LIFNR = vendor_tab-LIFNR.

I am getting the desired result....

Can anyone guide me why is this happening?

Thanks & Regards

Dnyanesh

Hi All,

I am using a dynamic internal, populating the same in program itself and the trying to pass the same in the select clause

following 2 lines are populated in the internal table i_where.

DATA i_where TYPE STANDARD TABLE OF char100.

these lines are populated in i_where.

  • A~LIFNR IN <L_TABLE1>

  • AND A~LIFNR = vendor_tab-LIFNR.

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

SELECT a~lifnr FROM lfa1 as a

inner join lfm1 as m

on alifnr = mlifnr

INTO TABLE i_vendor

FOR ALL ENTRIES IN vendor_tab

WHERE (i_where).

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

but the query doesnt execute......

if I write the same query as

SELECT a~lifnr FROM lfa1 as a

inner join lfm1 as m

on alifnr = mlifnr

INTO TABLE i_vendor

FOR ALL ENTRIES IN vendor_tab

WHERE A~LIFNR IN <L_TABLE1>

AND A~LIFNR = vendor_tab-LIFNR.

I am getting the desired result....

Can anyone guide me why is this happening?

Thanks & Regards

Dnyanesh

8 REPLIES 8
Read only

Former Member
0 Likes
1,009

Hai

Check the following Code

REPORT ZDYNAMIC_WHERE .

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 'hello'.

ENDLOOP.

Thanks & regards

Sreenivasulu P

Read only

amit_khare
Active Contributor
0 Likes
1,009

Hi,

Instead of declaring i_where type table declare it of type char or string and then use it.

Amit

Read only

Former Member
0 Likes
1,009

To specify a condition dynamically, use:

SELECT ... WHERE (<itab>) ...

<i>where <itab> is an internal table with line type C and maximum length 72 characters. All of the conditions listed above except for selection tables, can be written into the lines of <itab>. However, you may only use literals, and not the names of data objects. The internal table can also be left empty.</i>

so try reducing the size of ur internal table to 70 or so...

Reward points if it helps

Regards

Gunjan

Message was edited by: Gunjan Kumar

Read only

Former Member
0 Likes
1,009

See this exapmle:

Example

Creating a dynamic comparison from user input. In the case of incorrect syntax or incorrect semantics, exceptions are generated, which are handled using the common superclass.

PARAMETERS: column(8) TYPE c,

value(30) TYPE c.

DATA spfli_wa TYPE spfli.

DATA cond_syntax TYPE string.

CONCATENATE column '= value'

INTO cond_syntax SEPARATED BY space.

TRY.

SELECT SINGLE *

FROM spfli

INTO spfli_wa

WHERE (cond_syntax).

CATCH cx_sy_dynamic_osql_error.

MESSAGE `Wrong WHERE condition!` TYPE 'I'.

ENDTRY.

I think the only mistake you have done is the declaration of the i_where as an internal table instead of a string.

Regards,

ravi

Read only

Former Member
0 Likes
1,009

Hi,

Cross check with ST05 ; u will come know how exactly the select query getting generated.

1) put break point before select query and start debugging

2) open another session for transaction ST05

3) click activate trace

4) come back to the debugging screen press F5 to execute the select query.

5) go back to ST05 and click deactivate trace ; u will

find select query ; which being executed.

Hope it helps.

Mark Helpfull Answers

Read only

andreas_mann3
Active Contributor
0 Likes
1,009

hi,

i think you can <b>not</b> use variable like <L_TABLE1>

in where clause - only constants

Andreas

Read only

Former Member
0 Likes
1,009

We should use 'into corresponding fields of table'

in the select clause .......then it is working.

thanks for the suggestions.....

Read only

Former Member
0 Likes
1,009

we cannot use 'in' in dynamic where clause