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

Dynamic Where Clause in a Loop ??

Former Member
0 Likes
3,333

I need a dynamich where-clause in a Loop-Statement, like this:

LOOP AT gt_outtab INTO gs_outtab

WHERE ( delta IS INITIAL AND <f_per> IS INITIAL ).

gs_outtab-delta = gs_outtab-per01.

MODIFY gt_outtab FROM gs_outtab.

ENDLOOP.

First I tried this:

LOOP AT gt_outtab INTO gs_outtab

WHERE ( delta IS INITIAL AND (ls_per) IS INITIAL ).

gs_outtab-delta = gs_outtab-per01.

MODIFY gt_outtab FROM gs_outtab.

ENDLOOP.

but with both I get a syntax error.

Do you have an idea, how can I use the component I need dynamically?

thanks.

Samir

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
1,168

Hello Samir,

We can not specify the dynamic where clause in Loop.

IF you want to achieve for you logic,

LOOP AT gt_outtab INTO gs_outtab

WHERE delta IS INITIAL.

<b> assign f_per to <f_per>.

if f_per is initial.</b>

gs_outtab-delta = gs_outtab-per01.

MODIFY gt_outtab FROM gs_outtab.

<b>endif.</b>

ENDLOOP.

4 REPLIES 4
Read only

Former Member
0 Likes
1,168

take refrence from given link...

Read only

naimesh_patel
Active Contributor
0 Likes
1,169

Hello Samir,

We can not specify the dynamic where clause in Loop.

IF you want to achieve for you logic,

LOOP AT gt_outtab INTO gs_outtab

WHERE delta IS INITIAL.

<b> assign f_per to <f_per>.

if f_per is initial.</b>

gs_outtab-delta = gs_outtab-per01.

MODIFY gt_outtab FROM gs_outtab.

<b>endif.</b>

ENDLOOP.

Read only

Former Member
0 Likes
1,168

HI

GOOD

Dynamic Conditions

To specify a condition dynamically, use:

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

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.

If you only want to specify a part of the condition dynamically, use:

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

You cannot link a static and a dynamic condition using OR.

You may only use dynamic conditions in the WHERE clause of the SELECT statement.

===============================

DATA: TAB_SPFLI TYPE TABLE OF SPFLI,

TAB_SFLIGHT TYPE SORTED TABLE OF SFLIGHT

WITH UNIQUE KEY TABLE LINE,

WA LIKE LINE OF TAB_SFLIGHT.

SELECT CARRID CONNID

INTO CORRESPONDING FIELDS OF TABLE TAB_SPFLI

FROM SPFLI

WHERE CITYFROM = 'NEW YORK'.

SELECT CARRID CONNID FLDATE

INTO CORRESPONDING FIELDS OF TABLE TAB_SFLIGHT

FROM SFLIGHT

FOR ALL ENTRIES IN TAB_SPFLI

WHERE CARRID = TAB_SPFLI-CARRID AND

CONNID = TAB_SPFLI-CONNID.

LOOP AT TAB_SFLIGHT INTO WA.

AT NEW CONNID.

WRITE: / WA-CARRID, WA-CONNID.

ENDAT.

WRITE: / WA-FLDATE.

ENDLOOP.

THANKS

MRUTYUN

Read only

Former Member
0 Likes
1,168

thanks for the answers yet.

but I think only the answer of Naimesh Patel could be useful, i'm just checking, because there seems to be a difference between an dynamic where-clause in a select and a loop statement.

Samir