Code: Alles auswählen.
DATA BEGIN OF ls_neu,
bukrs like skb1-burks,
saknr like skb1-saknr,
ernam like skb1-ernam,
END OF ls_neu.
Auf welchem Reales bist du unter wegs?jondahl11 hat geschrieben:Hat jemand eine Idee wie das realisieren kann? Das Problem ist eben, das in der DB Tabelle theoretisch alle Felder der sturktur skb1 stehen können, die neue struktur muss also dynamisch aufgebaut werden.
Code: Alles auswählen.
TYPE-POOLS: abap.
DATA: ls_component TYPE abap_componentdescr, "Zeile der Strukturbeschreibung
lt_component TYPE abap_component_tab, "Tabelle der Strukturbeschreibung
lr_strucdescr TYPE REF TO cl_abap_structdescr, "Referenz auf Datentyp der Struktur
lr_tabledescr TYPE REF TO cl_abap_tabledescr, "Referenz auf Datentyp der Tabelle
lr_data_struct TYPE REF TO data, "Referenz auf die erzeugte Struktur
lr_data_table TYPE REF TO data, "Referenz auf die erzeugte Tabelle
l_count TYPE i. "Anzahl Komponenten
FIELD-SYMBOLS: <fs_comp> TYPE ANY, "Um auf eine Komponente zu zugreifen
<fs_struct> TYPE ANY, "Um auf die Struktur zu zugreifen
<fs_table> TYPE ANY TABLE. "Um auf die Tabelle zu zugreifen
* (1) identify components required in your dynamic table
CLEAR ls_component.
ls_component-name = 'CARRID'.
ls_component-type ?= cl_abap_typedescr=>describe_by_name( 'SFLIGHT-CARRID' ).
INSERT ls_component INTO TABLE lt_component.
CLEAR ls_component.
ls_component-name = 'CONNID'.
ls_component-type ?= cl_abap_typedescr=>describe_by_name( 'SFLIGHT-CONNID' ).
INSERT ls_component INTO TABLE lt_component.
CLEAR ls_component.
ls_component-name = 'FLDATE'.
ls_component-type ?= cl_abap_typedescr=>describe_by_name( 'SFLIGHT-FLDATE' ).
INSERT ls_component INTO TABLE lt_component.
* (2) create structure description in accordance to componentdata:
IF lt_component IS NOT INITIAL.
lr_strucdescr = cl_abap_structdescr=>create( lt_component ).
ENDIF.
* (3) create table description for structure descriptiondata:
lr_tabledescr = cl_abap_tabledescr=>create( p_line_type = lr_strucdescr ).
* (4) create structure and assign
CREATE DATA lr_data_struct TYPE HANDLE lr_strucdescr.
ASSIGN lr_data_struct->* TO <fs_struct>.
* (5) create table and assign
CREATE DATA lr_data_table TYPE HANDLE lr_tabledescr.
ASSIGN lr_data_table->* TO <fs_table> .
* (6) fill table (from database)
SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE <fs_table>.
* (7) output
l_count = LINES( lt_component ).
LOOP AT <fs_table> INTO <fs_struct>.
DO l_count TIMES.
ASSIGN COMPONENT sy-index OF STRUCTURE <fs_struct> TO <fs_comp>.
IF sy-index = 1.
WRITE: / <fs_comp>.
ELSE.
WRITE: <fs_comp>.
ENDIF.
ENDDO.
ENDLOOP. "<fs_table> INTO <fs_struct>
jondahl11 hat geschrieben:Bin auf 6.40, aber GENERATE SUBROUTINE POOL gefällt mir ganz gut.
Ich frag mich nur, wie ich auf die dort erzeugte struktur dann in meinem aufrufenden programm zugreifen kann??
Code: Alles auswählen.
CATCH SYSTEM-EXCEPTIONS generate_subpool_dir_full = 9.
GENERATE SUBROUTINE POOL lt_source NAME l_name
MESSAGE l_message LINE l_line WORD l_word.
ENDCATCH.
CASE sy-subrc.
WHEN 0.
WHEN OTHERS.
* message x000 with l_message l_line l_word.
ENDCASE.
PERFORM table_create IN PROGRAM (l_name)
CHANGING rd_tabelle.