I have a key-value internal table and want to fill an existing structure with it.
Example: 1st I get a key-value table that I create by reading data from two existing tables.
SELECT vals~attr_value, names~attr_name
FROM atst_attr AS vals
INNER JOIN tc_attr AS names
ON vals~tc_attr_id = names~tc_attr_id
WHERE vals~atst_id = @lv_atst_id
INTO TABLE @DATA(itab)
.
Now my itab looks like this:
itab:
name value
1. "field_a" "value_a"
2. "field_c" "value_c"
And my local structure (or workingarea as it is often called) is empty:
l_struc:
field_a: ""
field_b: ""
field_c: ""
Now I want to fill the structure, which is where I need help - I want the result to be:
l_struc: field_a: "value_a" field_b: "" field_c: "value_c"
How can I automatically make the mapping from the name property to the name of the structure component happen and setting its value?
something like:
FIELD-SYMBOLS lv_field TYPE ANY.
LOOP AT itab
ASSIGNING FIELD-SYMBOL(<ls_itab>).
ASSIGN COMPONENT <ls_itab>-name
OF STRUCTURE l_struc
TO <lv_field>.
IF sy-subrc EQ 0.
<lv_field> = <ls_itab>-value.
ENDIF.
ENDLOOP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With