Skip to Content
0
Jul 07, 2010 at 06:55 AM

How to create a ALV Grid Display for a dynamic Table?

1099 Views

Dear ABAP-Specialists,

i acutally try to create a ALV Output from dynamic Tables, but i do not know, how to perform the output, due to the Function Call does not accept <TABLE> and requires a "Standard Table".

Here a part of the Coding:

.......

cl_abap_typedescr=>describe_by_name(

EXPORTING

p_name = lv_tabname

RECEIVING

p_descr_ref = lo_type

).

lo_struc ?= lo_type.

lt_components = lo_struc->get_components( ).

lo_struc = cl_abap_structdescr=>create(

p_components = lt_components

).

lo_table = cl_abap_tabledescr=>create(

p_line_type = lo_struc

).

  • Create Data for Tables

CREATE DATA lt_table_ref TYPE HANDLE lo_table.

ASSIGN lt_table_ref->* TO <table>.

<table>[] = lt_entries[].

  • Assignment from String to Structur

LOOP AT lt_entries INTO ls_entries.

ASSIGN ls_entries TO <fs> CASTING TYPE (lv_tabname).

LOOP AT lt_components INTO ls_component.

ASSIGN COMPONENT sy-tabix OF STRUCTURE <fs> TO <comp>.

WRITE: <comp>, sy-vline. " Sollte durch eine ALV-Ausgabe ersetzt werden

ENDLOOP.

SKIP.

ENDLOOP.

  • Build Fieldcatalog

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = SY-REPID

i_structure_name = p_tab

CHANGING

ct_fieldcat = gt_fieldcat.

  • ALV-Output:

DATA: lv_output TYPE dd02l-tabname.

gv_repid = sy-repid.

lv_tabname = 'Testausgabe Variable Strukturen'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = gv_repid

it_fieldcat = gt_fieldcat

i_grid_title = 'Table Entries' "#EC NOTEXT

TABLES

t_outtab = <table>.

IF sy-subrc <> 0.

ENDIF.

Thanks a lot in advance

Best regards

Carsten Klatt