Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

dynamic

Former Member
0 Kudos

how can i call dynamically function module and subroutine

1 REPLY 1

Former Member
0 Kudos

Hi sivaranjhani,

Here is an example of how to call a function dynamically (note: comments were added to an existing example from the standard help)

REPORT ZDANY_DYN_FM_CALL.

*The constants and structures required to use the dynamic function call

*is stored in the type pool ABAP.

type-pools abap.

*This is the name of the function you want to call.

data NAME type STRING value `READ_SPFLI_INTO_TABLE`.

  • Parameter table, where you store all parameters, importing, exporting

  • and changing data PARA_TAB type ABAP_FUNC_PARMBIND_TAB. data PARA_LINE like line of PARA_TAB.

  • Exception table to handle the exception that can occur during the

  • execution of the function

data EXCP_TAB type ABAP_FUNC_EXCPBIND_TAB.

data EXCP_LINE like line of EXCP_TAB.

data CARRIER type SPFLI-CARRID.

data JTAB type SPFLI_TAB.

CARRIER = 'XYZ'.

  • Name of the first parameter

PARA_LINE-NAME = 'ID'.

  • type of the first parameter, could be :

  • abap_func_exporting value 10,

  • abap_func_importing value 20,

  • abap_func_tables value 30,

  • abap_func_changing value 40.

PARA_LINE-KIND = ABAP_FUNC_EXPORTING.

*We need the datatype of the parameter to pass

get reference of CARRIER into PARA_LINE-VALUE.

append PARA_LINE to PARA_TAB.

*Same thing for parameter 2

PARA_LINE-NAME = 'ITAB'.

PARA_LINE-KIND = ABAP_FUNC_IMPORTING.

get reference of JTAB into PARA_LINE-VALUE.

append PARA_LINE to PARA_TAB.

*Now we create the possible exceptions

EXCP_LINE-NAME = 'NOT_FOUND'.

EXCP_LINE-VALUE = 1.

insert EXCP_LINE into table EXCP_TAB.

EXCP_LINE-NAME = 'OTHERS'.

EXCP_LINE-VALUE = 4.

insert EXCP_LINE into table EXCP_TAB.

*... and we dynamically call the function with the parameter-table and

  • exception-table addition

call function NAME parameter-table PARA_TAB exception-table EXCP_TAB.

  • We check the result codecase SY-SUBRC. when 1. message id SY-MSGID type SY-MSGTY number SY-MSGNO. when 2. message E888(SABAPDOCU) with 'Error in function module'.endcase.

Reward ponits if helpful..

Regards,

Goutham.