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: 

call FM dynamic

Former Member
0 Kudos

HI All ,

I want to use the dynamic call for FM like the following example but i dont khow how to call

assuming i have several FM's that i always want to call the with different parameters

how can i do that in dynamic way?

CALL FUNCTION func
  PARAMETER-TABLE
  ptab
  EXCEPTION-TABLE
  etab.

Regards

Joy

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Yes it is possible,

you can call function modules dynamically

but the only consideration is that all function modules called must have to have the same Exporting/Importing/Changing/Tables/Exceptions parameters.

Explanation.

You can create a variable "lv_fname" of type rs38l_fnam.

And we have to keep the function module names in a table.

You can read your ztable function module name into the variable lv_fname:

Select single <Function module Name>

Into lv_fname

From <table name>

Where <Condition>

Then simply call the function module:

CALL FUNCTION lv_fmname

EXPORTING

<Exporting Parameters>

Note: passing/returning parameters have to be exactly

the same for all of the different function modules you will be calling.

Hope this helps.

9 REPLIES 9

Former Member
0 Kudos

Create a transparent table with Key = FM-Name. Each data field should contain the name of each FM parameter required. Read the entry for the FM as required and assign the correct values to each of the parameters for the FM. Fill PARAMETER-TABLE with both parameter and value accordingly and call FM.

0 Kudos

HI David,

Ok ,do you have some example ?

Regards

Joy

Former Member
0 Kudos

Yes it is possible,

you can call function modules dynamically

but the only consideration is that all function modules called must have to have the same Exporting/Importing/Changing/Tables/Exceptions parameters.

Explanation.

You can create a variable "lv_fname" of type rs38l_fnam.

And we have to keep the function module names in a table.

You can read your ztable function module name into the variable lv_fname:

Select single <Function module Name>

Into lv_fname

From <table name>

Where <Condition>

Then simply call the function module:

CALL FUNCTION lv_fmname

EXPORTING

<Exporting Parameters>

Note: passing/returning parameters have to be exactly

the same for all of the different function modules you will be calling.

Hope this helps.

0 Kudos

HI Pradeep,

Thanks ,assuming i have the the FM in remote system that have ERP with all the available Fm's ,(the source system doesn't have all the FM).what i was doing is to use the following Fm to get the FM interface and its works ,but the issue here assuming i need to move table like export parameter how do i fill the data in the table before i call the the FM.

CALL FUNCTION 'FUNCTION_IMPORT_INTERFACE'
  EXPORTING
    funcname           = fm
  TABLES
    exception_list     = lt_exception
    export_parameter   = lt_export_parameter
    import_parameter   = lt_import_parameter
    changing_parameter = lt_changing_parameter
    tables_parameter   = lt_tables_parameter
  EXCEPTIONS
    error_message      = 1
    function_not_found = 2
    invalid_name       = 3
    OTHERS             = 4.

Maybe i sharpen my question ,assuming i have table as input (i don't remember such of BAPI )and from the above FM i get the table structure

how can i add the values to the input table ,there is a way to do that?

Regards

Joy

Edited by: Joy Stpr on Jun 22, 2011 5:31 PM

0 Kudos

Hello Joy,

We cannot know the table parameter definition in the runtime unless we need to find/investigate is there a logic by which we will come to know dynamically what are the tables , import , export & Exception parameters for a FM that you want to call dynamically.

This will make the logic more complex.

Hope this answers your question.

Thanks,

Greetson

0 Kudos

Hi greet soon

But the FM that I mentioned above retrieve the the Bapi interface ,which table and the data type of it, it's impoosibe?

regards

joy

0 Kudos

Hello Joy,

You need to replicate the SE37 transaction functioanlity to achieve this.

This logic may be complecated , But if you check the logic in SE37 you can copy the same logic and get all the data dynamically once if you know the FM name that you wnat to call.

Hope your question is answered.

Thanks,

Greetson

0 Kudos

HI Greetson,

Thanks,

Are you sure its that complected , since what i want is trivial for calling FM dynamically,

I want to fill the structure and table of the input of the FM with data like key etc..and call to the FM every time i can have diff FM ,there is no simple way to do that ?

I assume that when this functionality was implemented ,this question is raised since otherwise the solution is not

complete ...

Regards

Joy

Edited by: Joy Stpr on Jun 23, 2011 8:48 AM

0 Kudos

Joy,

Yes , this is a complicated logic. You need to do the same logic that SE37 is doing.

I don't have the logic ready on my end. We need to go through the SE37 Program.

I gave you the solution as SE37 approach. I will try to let you know the FM's that SE37 is using when I find time.

Looks like they are calling the FM "RS_FUNCTION_DISPLAY". This has the changing parameter that eturns all the import , export , tables etc.. parameter details. You need to explore how to use this FM.

Best of luck.

Thanks,

Greetson

Edited by: Greetson Shunmugasundaram on Jun 23, 2011 4:47 PM