|
ABAP Tutorials -
Dynamic Programming
|
|
Written by mastram
|
|
Tuesday, 12 August 2008 09:29 |
|
I always wondered if we can code some dynamic method calls in ABAP. So I tried and to my surprise, it was possible !! Well its kinda simple only but sometimes it can be tricky also. The method name can be taken into a variable and called by placing it in brackets. But how to handle the prametes ! This is tricky.. The below code snippet shows how to do this..
TYPE-POOLS abap.
DATA : lv_control TYPE seoclsname VALUE 'CL_GUI_ALV_GRID', lt_par_tab TYPE abap_parmbind_tab, ls_param LIKE LINE OF lt_par_tab, lv_data TYPE REF TO data.
** Prepare the Parameters table.. ** Here I am passing a object as an exporting parameter
ls_param-name = 'I_PARENT'. ls_param-kind = 'E'. GET REFERENCE OF lref_cont INTO lv_data. ls_param-value = lv_data. INSERT ls_param INTO TABLE lt_par_tab.
** Now create ALV Control. CREATE OBJECT lref_alv_ctrl TYPE (lv_control) PARAMETER-TABLE lt_par_tab. Similarly you can pass many parameters and call methods also. An complete example code is provided in the Example codes section.
|