cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Why a sentence ABAP 7.4 work in WHERE at LOOP and doesn't works in dynamically in the same LOOP?

ltirado
Discoverer
2,287

Hello,

This sentence works very well:

LOOP AT lt_t005 ASSIGNING FIELD-SYMBOL(<ls_t005>) WHERE spras in gt_rangestack[ rangename = 'SPRAS' ]-r_range.
ENDLOOP.

But on the other hand the following dynamic sentence generates a dump (exception 'CX_SY_ITAB_DYN_LOOP'):

lv_where = 'spras in gt_rangestack[ rangename = ''SPRAS'' ]-r_range'.
LOOP AT lt_t005 ASSIGNING FIELD-SYMBOL(<ls_t005>) WHERE (lv_where).
ENDLOOP.  

Accepted Solutions (0)

Answers (3)

Answers (3)

Sandra_Rossi
Active Contributor

Dynamic clauses have always been more restrictive than static clauses, that's life.

ABAP documentation of LOOP AT ... WHERE (cond_syntax):

  • The following are not supported in a dynamic WHERE condition:
  • String expressions and bit expressions
  • String functions and bit functions
  • Constructor expressions
  • Table expressions

It does a short dump in 7.52 SP01:

DYN_WHERE_PARSE_ERROR
Error while the parsing the dynamic WHERE condition.
While parsing the logical expression, the system could not interpret
token "RANGES[" in row 0, column 11.

Minimal reproducible code:

FIELD-SYMBOLS <scarr> TYPE scarr.

SELECT * FROM scarr INTO TABLE @DATA(scarr_s).
DATA(ranges) = VALUE rsds_frange_t( ( fieldname = 'CARRID' selopt_t = VALUE #( ( sign = 'I' option = 'EQ' low = 'LH' ) ) ) ).

DATA(count_static) = 0.
LOOP AT scarr_s ASSIGNING <scarr>
    WHERE carrid IN ranges[ fieldname = 'CARRID' ]-selopt_t.
  ADD 1 TO count_static.
ENDLOOP.

DATA(lv_where) = |carrid in ranges[ fieldname = 'CARRID' ]-selopt_t|.
DATA(count_dynamic) = 0.
LOOP AT scarr_s ASSIGNING <scarr> 
    WHERE (lv_where).                      " <=== SHORT DUMP DYN_WHERE_PARSE_ERROR
  ADD 1 TO count_dynamic.
ENDLOOP.

ASSERT count_dynamic = count_static.
Gourab_Dey
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Luis,

Try with below code. It may work.

lv_where = |SPRAS in GT_RANGESTACK[ RANGENAME = 'SPRAS' ]-R_RANGE|.
LOOP AT lt_t005 ASSIGNING FIELD-SYMBOL(<ls_t005>) WHERE (lv_where).
ENDLOOP

Thanks,

Gourab

GK817
Active Contributor
0 Likes

Hi Luis,

Dynamic where clause is very strict in it comes to spaces and overall formatting. This should help you:

https://answers.sap.com/questions/10083506/unable-to-loop-across-a-dynamic-table.html

Regards

GK