Last month, i was engaging with a small project that involved with alv grid. And usually, there are 2 ways to do the alv grid control:
1 Call FM
2 ALV grid control using OO approach. (Object Orientied)
and some of my team members are a little confused about which to choose, so i want to talk about the differences between the 2 approaches.
For the first one, call funtion module, this is something like the structured programming approach. We call a funtion module, pass some parameters to this funtion module, and it will do some specific function. and it is done. the mostly used function modules are: REUSE_ALV_LIST_DISPLAY ,EUSE_ALV_GRID_DISPLAY,REUSE_ALV_GRID_DISPLAY_LVC.
For the later one, OO approach. we are using a more flexible way. and it is different. first we need to create some objects : instance of cl_gui_alv_grid, instance of cl_gui_custom_container. then we have to create a screen to hold the container.finally, we call a method "set_table_for_first_display"
apart from that , there are some other different.
the parameter types are different .for function modules REUSE_ALV_LIST_DISPLAY ,EUSE_ALV_GRID_DISPLAY,
the parameter:is_layout is of type slis_layout_alv,
and the parameter it_fieldcat is of type slit_t_fieldcata_alv
but when you using the OO approach, the two parameters are of type lvc_s_layo and lvc_t_fcat. however, when you call function module REUSE_ALV_GRID_DISPLAY_LVC, the two parameters are the some as the OO approach. Following listed a simple sample.
Call Function Module:
Error rendering macro 'code': Invalid value specified for parameter 'lang'
DATA: LAYOUT TYPE SLIS_LAYOUT_ALV, FCAT TYPE SLIS_T_FIELDCATA_ALV, W_FCAT TYPE SLIT_FIELDCATA_ALV. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING IS_LAYOUT = LAYOUT IT_FIELDCAT = FCAT TABLES T_OUTTAB = YOUR TABLE. OO APPROACH DATA: GRID TYPE REF TO CL_GUI_ALV_GRID, CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER, LAYOUT TYPE LVC_S_LAYO, FCAT TYPE LVC_T_FCAT, W_FCAT TYPE LVC_S_FCAT. IF CONTAINER IS INITIAL. CREATE OBJECT CONTAINER EXPORTING CONTAINER_NAME = 'mycont'. CREATE OBJECT GRID EXPORTING I_PARENT = PARENT_GRID. CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_LAYOUT = LAYOUT CHANGING IT_FIELDCATALOG = FCAT IT_OUTTAB = YOUR IT.
next time i would talk about the event handling differeces between those 2 approaches.