cancel
Showing results for 
Search instead for 
Did you mean: 

How to build a generic ALV GRID DISPLAY

0 Kudos

Hello there,
I'm trying to build a generic ALV Display function that can work to any case.
This is my progress right now.

"THIS IS THE CLASS DEFINITION
CLASS lcl_utils DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF it_sel,
sel1 TYPE string,
sel2 TYPE string,
sel3 TYPE string,
sel4 TYPE string,
END OF it_sel.

TYPES: BEGIN OF it_field,
name TYPE string,
prop TYPE string,
value TYPE int8,
END OF it_sel.

CLASS-METHODS:
build_alv IMPORTING iv_table TYPE tabname "TABLE TYPE
it_select TYPE it_sel "INTERNAL TABLE WITH SELECT INSTRUCIONS
iv_cname TYPE string "IDENTIFIER OF 'CUSTOM CONTROL' FROM PAINTER
it_fieldcat TYPE it_field "OPTIONAL - INTERNAL TABLE WITH THE FIELDCAT
iv_hotspot TYPE string "OPTIONAL - FUNCIONT TO BE EXECUTED.
ENDCLASS.

------------------------

"THIS WOULD BE THE GENERIC METHOD
METHOD build_alv.
DATA: lt_fieldcat TYPE lvc_t_fcat,
lv_grid TYPE REF TO cl_gui_alv_grid.

IF iv_table IS NOT INITIAL.
DATA: lt_generic TYPE TABLE OF iv_table.
SELECT it_sel-sel1 FROM it_sel-sel2 WHERE it_sel-sel3 EQ it_sel-sel4 INTO TABLE @lt_generic.
"RECIVE SELECT
ENDIF.

IF lv_grid IS INITIAL.
lv_grid = NEW #( i_parent = NEW cl_gui_custom_container( container_name = iv_cname ) ).
"RECIVE CONTAINER NAME

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = iv_table
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

IF it_fieldcat IS NOT INITIAL.
LOOP AT it_fieldcat.
lt_fieldcat[ fieldname = it_fieldcat-name ]-it_fieldcat-prop = it_fieldcat-value.
"RECIVE NAME PROPERTY AND VALUE
ENDLOOP.
ENDIF.


me->lv_grid->set_table_for_first_display(
EXPORTING
i_structure_name = iv_table
"RECIVE TABLE NAME TYPE
CHANGING
it_fieldcatalog = lt_fieldcat
it_outtab = lt_generic
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4
).

IF iv_hotspot IS NOT INITIAL.
lv_grid->register_edit_event( i_event_id = cl_gui_alv_grid=>mc_evt_modified ).
SET HANDLER iv_hotspot FOR lv_grid.
"RECIVE FUNCION NAME
ENDIF.
ELSE.
lv_grid->refresh_table_display( ).
ENDIF.
ENDMETHOD.

The problem now is that I don't now the 'TYPE' of an ABAP instruction, of course sel1, sel2... cant be a string, but how can I say that is a instruction of code or part of the code? Can I send a SQL instructions through parameter of a function?
If anyone has done, or can see a way to fix my design I would be very much appreciated.

Accepted Solutions (0)

Answers (0)