Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

carsten_klatt
Explorer
0 Kudos

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

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos

Why don't you use the SALV concept ? You don't have to pass the field-catalogue to display the ALV

BR,

Suhas

2 REPLIES 2

Former Member
0 Kudos

REPORT ztest.**** Data declarations DATA:

dtab TYPE REF TO data,

newstr2 TYPE REF TO cl_abap_typedescr,

tab_type1 TYPE REF TO cl_abap_tabledescr,

lref_ditab TYPE REF TO data,

lref_new_line TYPE REF TO data.**** Field-Symbols declarations

FIELD-SYMBOLS:

<fs_dyn_tab1> TYPE ANY TABLE,

<fs_dyn_tab2> TYPE ANY TABLE,

<fs_dyn_wa> TYPE ANY.**** Field Catalog declarations

DATA:

ls_fcat TYPE lvc_s_fcat,

lt_fcat TYPE lvc_t_fcat.**** Data declarations for ALV Display ***** Object variable for ALV grid

DATA:

obj_my_alv_grid TYPE REF TO cl_gui_alv_grid.**** Object variable for ALV Container

DATA:

obj_r_container TYPE REF TO cl_gui_custom_container.----


  • START O F S E L E C T I O N *

----


START-OF-SELECTION.* Create Field Catalog

PERFORM create_field_catalog.* Create Dynamic Table

PERFORM create_dynamic_table.* Fill the dynamic tables with data

PERFORM fill_dynamic_table.* Call the screen no.100

PERFORM call_screen.&----


*& Form CREATE_FIELD_CATALOG

&----


FORM create_field_catalog .* Append fields to field catalog table

ls_fcat-fieldname = 'VBELN'.

ls_fcat-ref_field = 'VBELN'.

ls_fcat-ref_table = 'VBAK'.

APPEND ls_fcat TO lt_fcat.

CLEAR ls_fcat. ls_fcat-fieldname = 'AUART'.

ls_fcat-ref_field = 'AUART'.

ls_fcat-ref_table = 'VBAK'.

APPEND ls_fcat TO lt_fcat.

CLEAR ls_fcat. ls_fcat-fieldname = 'ERNAM'.

ls_fcat-ref_field = 'ERNAM'.

ls_fcat-ref_table = 'VBAK'.

APPEND ls_fcat TO lt_fcat.

CLEAR ls_fcat. ls_fcat-fieldname = 'ERDAT'.

ls_fcat-ref_field = 'ERDAT'.

ls_fcat-ref_table = 'VBAK'.

APPEND ls_fcat TO lt_fcat.

CLEAR ls_fcat. ls_fcat-fieldname = 'ERZET'.

ls_fcat-ref_field = 'ERZET'.

ls_fcat-ref_table = 'VBAK'.

APPEND ls_fcat TO lt_fcat.

CLEAR ls_fcat.

ENDFORM. " CREATE_FIELD_CATALOG&----


*& Form CREATE_DYNAMIC_TABLE

&----


FORM create_dynamic_table .

    • Create dynamic table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = lt_fcat

IMPORTING

ep_table = lref_ditab

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2. IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.** Assign the dynamic table reference to a field-symbol

ASSIGN lref_ditab->* TO <fs_dyn_tab1>.**Create another dynamic table with the same structure

newstr2 ?= cl_abap_structdescr=>describe_by_data_ref( lref_ditab ).

tab_type1 ?= newstr2.

CREATE DATA dtab TYPE HANDLE tab_type1.

ASSIGN dtab->* TO <fs_dyn_tab2>.** Create a structure similar to the dynamic table created

CREATE DATA lref_new_line LIKE LINE OF <fs_dyn_tab1>.

ASSIGN lref_new_line->* TO <fs_dyn_wa>.

ENDFORM. " CREATE_DYNAMIC_TABLE&----


*& Form FILL_DYNAMIC_TABLE

&----


FORM fill_dynamic_table.

    • Fill the dynamic table <fs_dyn_tab1>

SELECT vbeln auart ernam erdat erzet

FROM vbak INTO TABLE <fs_dyn_tab1>

WHERE auart = 'ROR'

AND erdat LT sy-datum.** Fill the dynamic table <fs_dyn_tab2>

SELECT vbeln auart ernam erdat erzet

FROM vbak INTO TABLE <fs_dyn_tab2>

WHERE auart = 'ZSOR'

AND erdat LT sy-datum.

ENDFORM. " FILL_DYNAMIC_TABLE&----


*& Form CALL_SCREEN

&----


FORM call_screen .

CALL SCREEN 100.

ENDFORM. " CALL_SCREEN&----


*& Module STATUS_0100 OUTPUT

&----


  • PBO Module- Display both the tables in alv

----


MODULE status_0100 OUTPUT.

SET PF-STATUS 'MENUBAR'.

SET TITLEBAR 'ALV REPORT'.

&----


  • ALV Display-1st table

----


  • Object for container

CREATE OBJECT obj_r_container

EXPORTING

container_name = 'CUSTOM1'

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

OTHERS = 6.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.* Object for Alv grid

CREATE OBJECT obj_my_alv_grid

EXPORTING

i_parent = obj_r_container

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.* Calling method for displaying the data

CALL METHOD obj_my_alv_grid->set_table_for_first_display

CHANGING

it_outtab = <fs_dyn_tab1>

it_fieldcatalog = lt_fcat

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.&----


  • ALV Display-2nd table

----


  • Object for conatainer

CREATE OBJECT obj_r_container

EXPORTING

container_name = 'CUSTOM2'

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

OTHERS = 6.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.* Object for Alv grid

CREATE OBJECT obj_my_alv_grid

EXPORTING

i_parent = obj_r_container

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.* Calling method for displaying the data

CALL METHOD obj_my_alv_grid->set_table_for_first_display

CHANGING

it_outtab = <fs_dyn_tab2>

it_fieldcatalog = lt_fcat

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • PAI Module

----


MODULE user_command_0100 INPUT.

CASE sy-ucomm.

WHEN 'BACK' OR 'EXIT'.

LEAVE TO SCREEN 0.

WHEN 'CANCEL'.

LEAVE PROGRAM.

ENDCASE. " CASE SY-UCOMM

ENDMODULE. " USER_COMMAND_0100 INPUT

SuhaSaha
Advisor
Advisor
0 Kudos

Why don't you use the SALV concept ? You don't have to pass the field-catalogue to display the ALV

BR,

Suhas