The below post shows how to call a FM dynamically and passing all the parameters by using PARAMETER-TABLE option.
We have the below FM with parameters in different sections such as import, export, tables.
The source code returns a table of records from SFLIGHT table if the selection criteria meets else sends back only a text message.
PRORGAM
TYPE-POOLS: abap.
DATA: fm_name TYPE rs38l_fnam VALUE ‘FLIGHT_DETAILS’,
lt_param TYPE abap_func_parmbind_tab,
ls_param TYPE abap_func_parmbind,
lv_msg TYPE string,
lt_flight TYPE TABLE OF sflight.
FIELD-SYMBOLS: <fs_msg> TYPE string,
<fs_details> TYPE ANY TABLE.
PARAMETERS: p_carr TYPE sflight–carrid,
p_conn TYPE sflight–connid,
p_date TYPE sflight–fldate.
* Build parameters
ls_param–name = ‘CARRID’.
ls_param–kind = abap_func_exporting.
GET REFERENCE OF p_carr INTO ls_param–value.
APPEND ls_param TO lt_param.
CLEAR ls_param.
ls_param–name = ‘CONNID’.
ls_param–kind = abap_func_exporting.
GET REFERENCE OF p_conn INTO ls_param–value.
APPEND ls_param TO lt_param.
CLEAR ls_param.
ls_param–name = ‘FLDATE’.
ls_param–kind = abap_func_exporting.
GET REFERENCE OF p_date INTO ls_param–value.
APPEND ls_param TO lt_param.
CLEAR ls_param.
ls_param–name = ‘MSG’.
ls_param–kind = abap_func_importing.
GET REFERENCE OF lv_msg INTO ls_param–value.
APPEND ls_param TO lt_param.
CLEAR ls_param.
ls_param–name = ‘DETAILS’.
ls_param–kind = abap_func_tables.
GET REFERENCE OF lt_flight INTO ls_param–value.
APPEND ls_param TO lt_param.
CLEAR ls_param.
* Dynamic FM call with all import,export,table parameters
* passed in the Parameter-table
CALL FUNCTION fm_name
PARAMETER–TABLE lt_param.
READ TABLE lt_param INTO ls_param WITH KEY name = ‘MSG’.
IF sy–subrc IS INITIAL.
ASSIGN ls_param–value->* TO <fs_msg>.
IF <fs_msg> IS ASSIGNED AND <fs_msg> IS NOT INITIAL.
WRITE:/ <fs_msg>.
ELSE.
READ TABLE lt_param INTO ls_param WITH KEY name = ‘DETAILS’.
IF sy–subrc IS INITIAL.
ASSIGN ls_param–value->* TO <fs_details>.
IF <fs_details> IS ASSIGNED AND <fs_details> IS NOT INITIAL .
lt_flight = <fs_details>.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
i_callback_program = sy–repid
i_structure_name = ‘SFLIGHT’
TABLES
t_outtab = lt_flight.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
RUN & OUTPUT- For the selection criteria no data is present in SFLIGHT table.
RUN & OUTPUT- For the selection criteria data is present in SFLIGHT table.
Needed Info defined in TYPE GROUP- ABAP
-------------------------------------------------------------------------------------------------------------------------------------------