‎2004 Aug 25 12:31 PM
Hi all,
We need to pick up a row from an internal Table but the Where Condition is dynamic.
I tried to use the
LOOP AT LT_T_CACHE INTO LS_CACHE WHERE ( LS_CLAUSE ) .
But is not generating the code. How can we use a dynamic where clause in a Loop/Endloop.
How can we check the
Thanks and Regards,
Arunava
‎2004 Aug 25 1:06 PM
Hallo Arunava,
this type of selection is not possible. You can use "WHERE (LS_CLAUSE)" with a SELECT but not with LOOP. One way around this would be to use a transient routine i.e. you generate code for a routine with all your selection criterien and then call the routine.
There's a Web-Log that describes this. If you look in the Web-Logs and look for "transient" you'll find it. Also, there was a message on this theme in this forum. I took part in it so you could either search for my name or for the word "transient".
I hope this helps.
All the best,
Gerard.
‎2004 Aug 25 1:24 PM
Use an IF sentence...
LOOP AT....
IF <--LS_CLAUSE.
...
ENDIF.
ENDLOOP.
‎2004 Aug 25 3:42 PM
Hi
If it is really required, you can generate subroutine pools dynamically at ABAP. Look for the statement <b>"GENERATE SUBROUTINE-POOL FROM..."</b> at SAPHelp.
*--Serdar
‎2004 Aug 26 3:05 AM
Hi,
For the Usage of Dynamic Where Clause in a program,Its better to use the Transient programs,A Transient program is a program written inside a program and ur requirement is met in that program,the syntax used for that program is:
Generate subroutine pool <Internal table name>
Program_Name.
To Get the dynamically generated
Program Name
With the following additions :
Message Contains Error Message
Include Name of the include program
Line Line Number in Transient program
Word Incorrect word that caused the error
Offset Position of the incorrect word
Trace-file. Trace output
‎2004 Aug 26 3:31 PM
Hi All,
Thanks for the suggestions. I have been able to solve the problem.
Arunava
‎2004 Sep 06 4:58 PM
A small example program in case it is needed:
TABLES : sflight.
DATA: lt_sflight TYPE TABLE OF sflight,
ls_sflight TYPE sflight,
lv_line TYPE string,
lt_code TYPE STANDARD TABLE OF string,
lv_prg TYPE char8,
lv_msg TYPE string.
PARAMETERS: pa_carid TYPE sflight-carrid.
SELECT * FROM sflight
INTO TABLE lt_sflight.
lv_line = 'REPORT DYN_LOOP.'.
APPEND lv_line TO lt_code.
lv_line = 'FORM DYN_LH.'.
APPEND lv_line TO lt_code.
lv_line = 'data : ls_sflight type sflight.'.
APPEND lv_line TO lt_code.
lv_line = 'data : lt_sflight type table of sflight.'.
APPEND lv_line TO lt_code.
lv_line = 'select * from sflight into table lt_sflight.'.
APPEND lv_line TO lt_code.
lv_line = 'loop at lt_sflight'.
APPEND lv_line TO lt_code.
lv_line = 'into ls_sflight'.
APPEND lv_line TO lt_code.
IF pa_carid EQ 'LH'.
lv_line = `where carrid eq 'LH'.`.
ELSEIF pa_carid EQ 'AA'.
lv_line = `where carrid eq 'AA'.`.
ENDIF.
APPEND lv_line TO lt_code.
lv_line = 'write:/ ls_sflight-carrid,ls_sflight-connid, ls_sflight-fldate.'.
APPEND lv_line TO lt_code.
APPEND lv_line TO lt_code.
lv_line = 'endloop.'.
APPEND lv_line TO lt_code.
lv_line = 'ENDFORM.'.
APPEND lv_line TO lt_code.
GENERATE SUBROUTINE POOL lt_code
NAME lv_prg
MESSAGE lv_msg.
IF sy-subrc EQ 0.
WRITE 😕 'Program', lv_prg, 'is generated'.
PERFORM dyn_lh IN PROGRAM (lv_prg).
ELSE.
WRITE / 'error occured'.
WRITE lv_msg.
ENDIF.
Regards,
Sükrü