Code: Alles auswählen.
FUNCTION ZMIG_COPY_TABLE.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(I_TABNAME_FROM) TYPE TABNAME
*" REFERENCE(I_TABNAME_TO) TYPE TABNAME
*" TABLES
*" I_SELCON STRUCTURE ZS_SELCON
*" I_KOMP_TRANS STRUCTURE ZKOMP_TRANS OPTIONAL
*" EXCEPTIONS
*" NOT_FOUND
*" OTHERS
*"----------------------------------------------------------------------
*
* zeilenweiser Aufbau Tabelle I_SELCON z.B.:
* bukrs = 3011
* AND
* bstyp = 'F'
*
* I_KOMP_TRANS
* dient zur Uebersetzung von alt/neu, z.B. bei LIFNR
* der angegebene Funktionsbaustein wird genutzt,
* um den neuen Wert der übergebenen Komponente zu ermitteln
* Angabe z.B.:
* LIFNR
DATA: dref TYPE REF TO data,
dref_to TYPE REF TO data,
i_alv_cat TYPE TABLE OF lvc_s_fcat,
ls_alv_cat LIKE LINE OF i_alv_cat,
i_alv_cat_to TYPE TABLE OF lvc_s_fcat,
ls_alv_cat_to LIKE LINE OF i_alv_cat.
DATA: BEGIN OF itab OCCURS 0.
* INCLUDE STRUCTURE dntab.
INCLUDE structure DFIES.
DATA: END OF itab.
DATA: BEGIN OF itab_to OCCURS 0.
* INCLUDE STRUCTURE dntab.
INCLUDE structure DFIES.
DATA: END OF itab_to.
FIELD-SYMBOLS: <table_from> TYPE ANY TABLE.
FIELD-SYMBOLS: <table_to> TYPE ANY TABLE.
FIELD-SYMBOLS: <wa_to> TYPE ANY.
FIELD-SYMBOLS: <l_komp> TYPE ANY.
Data: l_alt type ELIFN.
Data: l_neu type ELIFN.
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
TABNAME = i_tabname_from
TABLES
DFIES_TAB = itab
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 1.
raise not_found.
elseif sy-subrc = 2.
raise others.
ENDIF.
LOOP AT itab .
ls_alv_cat-fieldname = itab-fieldname.
ls_alv_cat-ref_table = i_tabname_from.
ls_alv_cat-ref_field = itab-fieldname.
APPEND ls_alv_cat TO i_alv_cat.
ENDLOOP.
* build internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat
IMPORTING
ep_table = dref.
ASSIGN dref->* TO <table_from>.
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
TABNAME = i_tabname_to
TABLES
DFIES_TAB = itab_to
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 1.
raise not_found.
elseif sy-subrc = 2.
raise others.
ENDIF.
LOOP AT itab_to.
ls_alv_cat_to-fieldname = itab_to-fieldname.
ls_alv_cat_to-ref_table = i_tabname_to.
ls_alv_cat_to-ref_field = itab_to-fieldname.
APPEND ls_alv_cat_to TO i_alv_cat_to.
ENDLOOP.
break-point.
* build internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat_to
IMPORTING
ep_table = dref_to.
ASSIGN dref_to->* TO <table_to>.
*Select Ursprungstabelle mit Selektionsbedingungen
SELECT * FROM (i_tabname_from) up to 10 rows
INTO CORRESPONDING FIELDS OF TABLE <table_from>
where (i_selcon).
break-point.
*Aufbau interne Tabelle mit eventuell geänderten Feldern
if not I_KOMP_TRANS is initial.
loop at <table_from> assigning <wa_to>.
assign component I_KOMP_TRANS-KOMP
of structure <wa_to> to <l_komp>.
CALL FUNCTION 'Z_MIG_TRANS_LIFNR'
EXPORTING
I_KOMP = I_KOMP_TRANS-KOMP
I_ALT = <l_komp>
IMPORTING
E_NEU = <l_komp>.
append <wa_to> to <table_to>.
endloop.
break-point.
*Speichern der ausgelesenen Daten in Zieltabelle
* MODIFY (i_tabname_to) FROM TABLE <table_to>.
else.
*Speichern der ausgelesenen Daten in Zieltabelle
* MODIFY (i_tabname_to) FROM TABLE <table_from>.
endif.
*commit work.
break-point.
ENDFUNCTION.
Code: Alles auswählen.
append <wa_to> to <table_to>.
Wer weiss Rat?Auf Tabellen vom Typ "HASHED TABLE" bzw. "ANY TABLE" sind weder explizite noch implizite Indexoperationen erlaubt.
"<TABLE_TO>" ist aber vom Typ "ANY TABLE".
Code: Alles auswählen.
<l_sysid> = sy-sysid.
Code: Alles auswählen.
assign <table_to> to <wa_to>.
Code: Alles auswählen.
assign <table_to> to <wa_to>.
if not I_KOMP_TRANS is initial.
loop at <table_from> assigning <wa_from>.
assign component I_KOMP_TRANS-KOMP
of structure <wa_from> to <l_komp>.
CALL FUNCTION I_KOMP_TRANS-FUBA
EXPORTING
I_KOMP = I_KOMP_TRANS-KOMP
I_ALT = <l_komp>
IMPORTING
E_NEU = <l_komp>.
break-point.
assign component 'SYSID' of structure <wa_to> to <l_sysid>.
<l_sysid> = sy-sysid.
* move-corresponding <wa_from> to <wa_to>.
append <wa_to> to <table_to>.
endloop.
Danke für die Hinweise. Habe es jetzt so gelöst:ewx hat geschrieben:Hi!
Entweder machst du einen LOOP AT <TABLE_TO> ASSIGNING <WA_TO> oder du packst bei jedem Durchlauf von LOOP AT <TABLE_FROM> eine neue Zeile an die TO-Tabelle
APPEND INITIAL LINE TO <TABLE_TO> ASSIGNING <WA_TO>. Je nachdem ob du die TO-Tabelle schon hast, oder nicht. Wenn du die Tabelle schon hast, musst du natürlich mit READ ... ASSIGNING auf den richtigen Tabelleneintrag positionieren.
dann kannst du dein SYSID zuweisen und dein MOVE-CORRESPONDING funktioniert auch.
Code: Alles auswählen.
* Create the target work area..
DATA: new_line TYPE REF TO data.
CREATE DATA new_line LIKE LINE OF <table_to>.
ASSIGN new_line->* TO <wa_to>.
Code: Alles auswählen.
assign component 'SYSID' of structure <wa_to> to <l_sysid>.
<l_sysid> = sy-sysid.
LOOP AT itab .
ASSIGN COMPONENT itab-fieldname of structure <WA_FROM> TO <FS>.
CHECK SY-SUBRC = 0.
ASSIGN COMPONENT itab-fieldname of structure <WA_TO> TO <FS1>.
CHECK SY-SUBRC = 0.
* Move from source to target.
<FS1> = <FS>.
ENDLOOP.
append <wa_to> to <table_to>.
endloop.