Code: Alles auswählen.
types: begin of ty_tab,
item type string,
debit type string,
credit type string,
id type string,
win type string,
end of ty_tab.
data: lt_tab type standard table of ty_tab,
ls_tab type ty_tab.
loop at itab1 into ls_itab1_line from itab2.
case ls_itab1_line-name.
when 'item'.
ls_tab-item = ls_itab1_line-wert.
when 'haben'.
ls_tab-debit = ls_itab1_line-wert.
when 'soll'.
ls_tab-credit = ls_itab1_line-wert.
when 'id'.
ls_tab-id = ls_itab1_line-wert.
when 'gewinn'.
ls_tab-win = ls_itab1_line-wert.
when others.
endcase.
if ls_tab-item NE space
and ls_tab-debit NE space
and ls_tab-credit NE space
and ls_tab-gewinn NE space.
insert ls_tab into table lt_tab.
endif.
endloop.
Code: Alles auswählen.
FIELD-SYMBOLS: <fs_dummy> TYPE any,
<fs_dummy2> TYPE any.
LOOP AT itab1.
curr_line = sy-tabix + 1.
ASSIGN COMPONENT curr_line OF STRUCTURE itab2 TO <fs_dummy>.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE itab TO <fs_dummy2>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF curr_line = 1.
<fs_dummy> = <fs_dummy2>.
APPEND itab2.
ELSE.
READ TABLE itab2 INDEX sy-index.
<fs_dummy> = <fs_dummy2>.
MODIFY itab2 INDEX sy-index.
ENDIF.
ENDDO.
ENDLOOP.
Code: Alles auswählen.
REPORT zdhe_abap.
TYPES: BEGIN OF ty_tab_ziel,
item TYPE string,
debit TYPE string,
credit TYPE string,
id TYPE string,
win TYPE string,
END OF ty_tab_ziel,
BEGIN OF ty_tab_quelle,
name TYPE string,
wert TYPE string,
END OF ty_tab_quelle.
DATA: lt_ziel TYPE STANDARD TABLE OF ty_tab_ziel,
ls_ziel TYPE ty_tab_ziel,
lt_quelle TYPE STANDARD TABLE OF ty_tab_quelle,
ls_quelle TYPE ty_tab_quelle.
FIELD-SYMBOLS: <fs_comp> TYPE ANY.
"Testdaten füllen mit Name Wert
ls_quelle-name = 'ITEM'.
ls_quelle-wert = 1.
APPEND ls_quelle TO lt_quelle.
ls_quelle-name = 'HABEN'.
ls_quelle-wert = 50.
APPEND ls_quelle TO lt_quelle.
ls_quelle-name = 'SOLL'.
ls_quelle-wert = 30.
APPEND ls_quelle TO lt_quelle.
ls_quelle-name = 'ID'.
ls_quelle-wert = 01.
APPEND ls_quelle TO lt_quelle.
ls_quelle-name = 'GEWINN'.
ls_quelle-wert = 20.
APPEND ls_quelle TO lt_quelle.
ls_quelle-name = 'ITEM'.
ls_quelle-wert = 2.
APPEND ls_quelle TO lt_quelle.
ls_quelle-name = 'HABEN'.
ls_quelle-wert = 100.
APPEND ls_quelle TO lt_quelle.
ls_quelle-name = 'SOLL'.
ls_quelle-wert = 65.
APPEND ls_quelle TO lt_quelle.
ls_quelle-name = 'ID'.
ls_quelle-wert = 02.
APPEND ls_quelle TO lt_quelle.
ls_quelle-name = 'GEWINN'.
ls_quelle-wert = 35.
APPEND ls_quelle TO lt_quelle.
"alte Version
LOOP AT lt_quelle INTO ls_quelle. "FROM ist nicht notwendig
CASE ls_quelle-name.
WHEN 'ITEM'.
ls_ziel-item = ls_quelle-wert.
WHEN 'HABEN'.
ls_ziel-debit = ls_quelle-wert.
WHEN 'SOLL'.
ls_ziel-credit = ls_quelle-wert.
WHEN 'ID'.
ls_ziel-id = ls_quelle-wert.
WHEN 'GEWINN'.
ls_ziel-win = ls_quelle-wert.
WHEN OTHERS.
ENDCASE.
IF ls_ziel-item NE space
AND ls_ziel-debit NE space
AND ls_ziel-credit NE space
AND ls_ziel-win NE space.
INSERT ls_ziel INTO TABLE lt_ziel.
CLEAR ls_ziel. "wichtig, wegen dem IF in den Zeilen obendrüber
ENDIF.
ENDLOOP.
BREAK-POINT.
Code: Alles auswählen.
"neue Version
CLEAR: lt_ziel, ls_ziel.
LOOP AT lt_quelle INTO ls_quelle.
"immer wenn Name = item beginnt eine neue Zeile
IF ls_quelle-name = 'ITEM'.
IF ls_ziel IS NOT INITIAL.
APPEND ls_ziel TO lt_ziel.
CLEAR ls_ziel.
ENDIF.
ENDIF.
"fülle die Zielstruktur
ASSIGN COMPONENT ls_quelle-name OF STRUCTURE ls_ziel TO <fs_comp>.
IF sy-subrc <> 0.
"wenn keine Spalte mit dem Namen gefunden wird, gehe zur nächsten Zeile
CONTINUE.
ENDIF.
<fs_comp> = ls_quelle-wert.
ENDLOOP.
"letzte Zeile
IF ls_ziel IS NOT INITIAL.
APPEND ls_ziel TO lt_ziel.
CLEAR ls_ziel.
ENDIF.
BREAK-POINT.