Skip to Content
author's profile photo Former Member
Former Member

dynamic

how can i call dynamically function module and subroutine

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 07:57 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.