dynamicabapsap-data-dictionary

Move fields from table to local table based on structure


I customized the table KNVV. The append structure includes a structure where I actually defined all my custom fields. Lets call it zz_knvv_app_s.

A function pool, used to get and set the custom fields, has a function called ZSD_FOO_GET_DATA. It is exporting structure es_knvv TYPE knvv.

My current solution works, but is kind of stupid:

FUNCTION ZSD_FOO_GET_DATA.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  EXPORTING
*"     REFERENCE(ES_KNVV) TYPE  KNVV
*"----------------------------------------------------------------------
  es_knvv-zzfoo = knvv-zzfoo.
  es_knvv-zzbar = knvv-zzbar.
  es_knvv-zzbaz = knvv-zzbaz.
 " there are actually many more fields...
ENDFUNCTION.

What I am looking for is something like that:

I am kind of new to ABAP. I think about looping and field symbols, but cant get it right. How would you solve it?


Solution

  • You could try to use a named include:

    You can then address all of your fields using KNVV-ZZ_MY_FIELDS as a structure of type ZZ_MY_KNVV_FIELDS