I have a few field names in LT_FIELDS
. I am trying to concatenate the data in that internal table in a specific format and append it to LT_WHERE
for a dynamic select query.
Below is the snippet I wrote:
TYPES: BEGIN OF ty_whr,
fieldname TYPE string,
END OF ty_whr.
DATA(lt_fields) = VALUE rsds_frange_t( ).
DATA(lt_where) = REDUCE ty_whr(
INIT whereclause = VALUE ty_whr( )
FOR <fields> IN lt_fields
NEXT whereclause =
COND #( WHEN whereclause IS NOT INITIAL
THEN <fields>-fieldname && | IN | && |@| && <fields>-fieldname && | AND |
ELSE <fields>-fieldname && | IN | && |@| && <fields>-fieldname
) ).
I am getting this error on concatenation part:
String calculation not permitted here
Is the syntax wrong here?
CodePudding user response:
The syntax messages are a little bit strange with Constructor Expressions.
In fact the issue is due to the target (whereclause
) which is a structure, you can't assign a Text Literal to a structure, instead you should assign it to its text component whereclause-fieldname
(right after NEXT
):
TYPES: BEGIN OF ty_whr,
fieldname TYPE string,
END OF ty_whr.
DATA(lt_fields) = VALUE rsds_frange_t( ).
DATA(lt_where) = REDUCE ty_whr(
INIT whereclause = VALUE ty_whr( )
FOR <fields> IN lt_fields
NEXT whereclause-fieldname =
COND #( WHEN whereclause IS NOT INITIAL
THEN <fields>-fieldname && | IN | && |@| && <fields>-fieldname && | AND |
ELSE <fields>-fieldname && | IN | && |@| && <fields>-fieldname
) ).