Sunday 26 June 2016

Dynamic call to FM with PARAMETER-TABLE

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.
12345
The source code returns a table of records from SFLIGHT table if the selection criteria meets else sends back only a text message.67

PRORGAM
TYPE-POOLSabap.
DATAfm_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.
PARAMETERSp_carr TYPE sflightcarrid,
                             p_conn TYPE sflightconnid,
                             p_date TYPE sflightfldate.
* Build parameters
ls_paramname ‘CARRID’.
ls_paramkind abap_func_exporting.
GET REFERENCE OF p_carr INTO ls_paramvalue.
APPEND ls_param TO lt_param.
CLEAR ls_param.
ls_paramname ‘CONNID’.
ls_paramkind abap_func_exporting.
GET REFERENCE OF p_conn INTO ls_paramvalue.
APPEND ls_param TO lt_param.
CLEAR ls_param.
ls_paramname ‘FLDATE’.
ls_paramkind abap_func_exporting.
GET REFERENCE OF p_date INTO ls_paramvalue.
APPEND ls_param TO lt_param.
CLEAR ls_param.
ls_paramname ‘MSG’.
ls_paramkind abap_func_importing.
GET REFERENCE OF lv_msg INTO ls_paramvalue.
APPEND ls_param TO lt_param.
CLEAR ls_param.
ls_paramname ‘DETAILS’.
ls_paramkind abap_func_tables.
GET REFERENCE OF lt_flight INTO ls_paramvalue.
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
  PARAMETERTABLE lt_param.
READ TABLE lt_param INTO ls_param WITH KEY name ‘MSG’.
IF sysubrc IS INITIAL.
  ASSIGN ls_paramvalue->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 sysubrc IS INITIAL.
      ASSIGN ls_paramvalue->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 syrepid
            i_structure_name   ‘SFLIGHT’
          TABLES
            t_outtab           lt_flight.
      ENDIF.
    ENDIF.
  ENDIF.
ENDIF.

13.jpg
RUN & OUTPUT- For the selection criteria no data is present in SFLIGHT table.
89
RUN & OUTPUT- For the selection criteria data is present in SFLIGHT table.
1011

Needed Info defined in TYPE GROUP- ABAP
12
-------------------------------------------------------------------------------------------------------------------------------------------

No comments:

Comments system

Disqus Shortname