Wie bekommst du denn die Angaben wieviele Felder von welchem Typ du in der Tabelle haben willst?schwar01 hat geschrieben:Es liegt nicht am ALV sondern beim Anlegen der variablen Struktur.
Code: Alles auswählen.
REPORT LINE-SIZE 200.
FIELD-SYMBOLS: <tab> TYPE table,
<line> type any.
DATA: g_subrc TYPE sysubrc.
END-OF-SELECTION.
DO 5 TIMES.
PERFORM create_var_struct USING sy-index
CHANGING g_subrc.
IF g_subrc = 0.
WRITE:/ 'Struktur erzeugt'.
append initial line to <tab>.
loop at <tab> assigning <line>.
clear <line> with 'X'.
write:/ <line>.
endloop.
ENDIF.
ENDDO.
*---------------------------------------------------------------------*
* FORM create_var_struct *
*---------------------------------------------------------------------*
FORM create_var_struct USING value(i_anzahl) TYPE syindex
CHANGING e_subrc TYPE sysubrc.
CONSTANTS: formname TYPE syrepid VALUE 'CREATE_VAR_STRUCT_FROM'.
DATA: t_source TYPE STANDARD TABLE OF abapsource
WITH NON-UNIQUE DEFAULT KEY,
wa_source LIKE LINE OF t_source,
progname TYPE syrepid.
DATA: err_line TYPE sytabix,
err_message TYPE text120,
n4(4) TYPE n.
* worst case assumption
e_subrc = 4.
FORMAT COLOR OFF INTENSIFIED ON.
WRITE:/ 'Erzeuge Struktur mit Länge',i_anzahl.
* Aufbau des Subroutinepools.
DEFINE as.
wa_source = &1.
append wa_source to t_source.
END-OF-DEFINITION.
as 'REPORT.'.
as 'TYPES: BEGIN OF TY,'.
* Variabler Anteil
DO i_anzahl TIMES.
n4 = sy-index.
CONCATENATE 'FELD' n4 INTO wa_source.
CONCATENATE wa_source 'TYPE TEXT20,'
INTO wa_source SEPARATED BY space.
APPEND wa_source TO t_source.
ENDDO.
as ' END OF TY.'.
* Tabelle mit variabler Struktur
as 'DATA tab TYPE STANDARD TABLE OF ty WITH NON-UNIQUE DEFAULT KEY.'.
as space.
as space.
CONCATENATE 'FORM' formname 'USING VALUE(i_anzahl) TYPE syindex.'
INTO wa_source SEPARATED BY space.
APPEND wa_source TO t_source.
* Callback mit variable Struktur
as 'PERFORM receive_structure in program (sy-cprog) using tab.'.
as 'ENDFORM.'.
* Erzeugen des Subroutinepools ( evtl. Fehler abfangen )
GENERATE SUBROUTINE POOL t_source NAME progname
MESSAGE err_message
LINE err_line.
IF progname IS INITIAL.
FORMAT COLOR 6 INTENSIFIED OFF.
WRITE: 'Zeile',err_line,
': Message',err_message.
EXIT.
ELSE.
FORMAT COLOR 5 INTENSIFIED OFF.
WRITE: 'Name',progname.
ENDIF.
* holen der Struktur
PERFORM (formname) IN PROGRAM (progname) USING i_anzahl.
* Alles zurückgeben
CLEAR e_subrc.
ENDFORM.
*---------------------------------------------------------------------*
* FORM receive_structure *
*---------------------------------------------------------------------*
* Wird aus Subroutinepool gerufen um Tabelle assignen zu können *
*---------------------------------------------------------------------*
FORM receive_structure USING tab TYPE table.
ASSIGN tab TO <tab>.
ENDFORM.