01/10/2010

Dynamically Created Internal Tables and Display ALV


REPORT ZADN_SAMPLE.

*----------------------------------------------------------------------*
* - > CLASS cl_dynamical_alv DEFINITION
*----------------------------------------------------------------------*
CLASS cl_dynamical_alv DEFINITION.

PUBLIC SECTION.

TYPES: BEGIN OF ty_screenfields,
tab_name TYPE tabname,
tab_rows TYPE i,
END OF ty_screenfields.

METHODS : display_table_data IMPORTING p_tabname TYPE tabname
p_maxrow TYPE i.

PRIVATE SECTION.

DATA: dtabref TYPE REF TO data,
alv TYPE REF TO cl_gui_alv_grid.

ENDCLASS. "cl_dynamical_alv DEFINITION

*----------------------------------------------------------------------*
* - > CLASS cl_dynamical_alv IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS cl_dynamical_alv IMPLEMENTATION.

METHOD display_table_data.

FIELD-SYMBOLS: TYPE ANY TABLE.

CREATE DATA me->dtabref TYPE TABLE OF (p_tabname).

ASSIGN me->dtabref->* TO .

SELECT *
FROM (p_tabname) UP TO p_maxrow ROWS
INTO TABLE .

CREATE OBJECT alv
EXPORTING
i_parent = cl_gui_container=>screen0.

CALL METHOD alv->set_table_for_first_display
EXPORTING
i_structure_name = p_tabname
CHANGING
it_outtab = .

CALL SCREEN 100.

ENDMETHOD. "DISPLAY_TABLE_DATA

ENDCLASS. "cl_dynamical_alv IMPLEMENTATION

************************************************************************
************************************************************************
* *
* PROGRAM FLOW LOGIC *
* *
************************************************************************

SELECTION-SCREEN BEGIN OF BLOCK b001 WITH FRAME TITLE text-001.

PARAMETERS : p_tbname TYPE cl_dynamical_alv=>ty_screenfields-tab_name,
p_tbrows TYPE cl_dynamical_alv=>ty_screenfields-tab_rows.

SELECTION-SCREEN END OF BLOCK b001.

START-OF-SELECTION.

DATA : o_cl_dynamical_alv TYPE REF TO cl_dynamical_alv.

CREATE OBJECT o_cl_dynamical_alv.

o_cl_dynamical_alv->display_table_data( EXPORTING p_tabname = p_tbname
p_maxrow = p_tbrows ).

Nenhum comentário:

Postar um comentário