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
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.
take refrence from given link...
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 a comment