Skip to Content
avatar image
Former Member

Dynamic Where Clause in a Loop ??

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    Apr 13, 2006 at 08:56 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 13, 2006 at 08:52 AM

    take refrence from given link...

    dynamic-where-clause

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 13, 2006 at 08:57 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 13, 2006 at 09:11 AM

    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

    Add comment
    10|10000 characters needed characters exceeded