I'm working on a routine which moves the lines of a string table (in this case fui_elements
) into a structure of unknown type (fcwa_struct
).
DATA(li_temp) = ... "fill assignment table here
LOOP AT fui_elements ASSIGNING FIELD-SYMBOL(<lfs_element>).
ASSIGN COMPONENT li_temp[ sy-tabix ] OF STRUCTURE fcwa_struct
TO FIELD-SYMBOL(<lfs_field>).
IF sy-subrc <> 0.
"somethings wrong with the fui_elements data
ENDIF.
<lfs_field> = <lfs_element>.
ENDLOOP.
If the table i_field_customizing
(STANDARD TABLE OF string
) is not initial, I want to use its values.
Otherwise I want to generate an integer table (so that the loop runs equally often regardless of the table's values). Here lw_max
is the amount of fields the imported structure has:
DATA(li_temp) = COND #( WHEN i_field_customizing[] IS INITIAL
THEN VALUE t_integer_tt( FOR X = 1
THEN X + 1
WHILE X <= lw_max
( X ) )
ELSE i_field_customizing ).
But when I run the report with i_field_customizing
like that:
DATA(i_field_customizing) = VALUE t_string_tt( ( `KUNNR` ) ( `NAME1` ) ).
I get this exception on the line where I try to construct li_temp
:
CX_SY_CONVERSION_NO_NUMBER (KUNNR cannot be interpreted as a number)
My current guess is that COND
gets its type statically. Does anybody know how I can get around this?
What you are trying to achieve will not be possible because the type of an inline definition of a variable using
COND
is decided at compilation time and not at runtime.Please see my question here. The type that will be taken is always the type of the variable that stands directly after
THEN
. You can decide what type will be chosen at compilation time by fiddling with negating the condition and switching places of variables afterTHEN
atELSE
but it will be always either or and from what I understand you want to be able to do it dynamically so yourASSIGN COMPONENT
statement works as expected with integers.Even by specifically casting the variable after
ELSE
one gets the same short dump as you do.Alternatively you could cast to
REF TO DATA
but then you have to dereference it to a field symbol of typeSTANDARD TABLE
.