Application Development and Automation 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: 
Read only

How to call a function module dynamically?

Former Member
0 Likes
3,197

Hi

I am doing a smartform development and here my scenario.

<b>Scenario:</b>

There will be a simple report which will trigger a smartform output. The report has a selection screen and and in one of the field the user will enter the layout name or the layout name will be stored in the variant so that the user need not remember the layout name.

Based on the layout selected i need to show the output.

<b>What i have coded:</b>

In my program after selecting the data i am calling the FM SSF_FUNCTION_MODULE_NAME which will return the function module name to be called.

<b>Question:</b>

How do i call the function module dynamically. I cannot do a single call to the function module using the FM name derived from the above function call. I want to make the interface calling dynamic. We dont want to hardcode the function calls coz we may have many layouts to be called so how is it possible in SAP to call the FM interface dynamically.

~Suresh

5 REPLIES 5
Read only

naimesh_patel
Active Contributor
0 Likes
1,266

Actually you can call the FM dynamically in by taking it into one variable and than use the CALL FUNCTION V_FM_NAME.

But the problem here is, you need to take care about the importing, exporting and tables parameters. They needs to be same for all FMs which you are planning to call. Otherwise system will give you a run time error.


   CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
         EXPORTING  FORMNAME           = LF_FORMNAME
*                 variant            = ' '
*                 direct_call        = ' '
         IMPORTING  FM_NAME            = LF_FM_NAME
         EXCEPTIONS NO_FORM            = 1
                    NO_FUNCTION_MODULE = 2
                    OTHERS             = 3.


      CALL FUNCTION LF_FM_NAME
           EXPORTING
                      ARCHIVE_INDEX        = TOA_DARA
                      ARCHIVE_PARAMETERS   = ARC_PARAMS
                      CONTROL_PARAMETERS   = LS_CONTROL_PARAM
*                 mail_appl_obj        =
*                     mail_recipient       = ls_recipient
                      MAIL_SENDER          = LS_SENDER

Regards,

Naimesh Patel

Read only

0 Likes
1,266

Hi Naimesh,

Thanks ....I understand the next step. Thats my problem. The chances of the interface being same is very less. We will have different FM with different smart form interface. Any idea how i can achieve this?

~Suresh

Read only

matt
Active Contributor
0 Likes
1,266

Try using static methods instead.

CALL METHOD ... PARAMETER-TABLE ptab

EXCEPTION-TABLE etab.

I <i>think</i> the same additions exist in the latest versions for function modules, so you should check your version. ( Not at a sap system at the moment, so I can't check myself ).

matt

Read only

Pawan_Kesari
Active Contributor
0 Likes
1,266

How are you handling other things which will depend on layout selected, for example gathering data?

My point is if you are already writing IF statenent for other things then why don't add the function call too in that IF block.

Read only

christian_wohlfahrt
Active Contributor
0 Likes
1,265

Hi Suresh!

When I understood your requirement correctly, you want to call several different smartforms in one report.

Still the calling program has to fill all the needed data before calling the smartforms. Here also some specific coding has to be done... or you define the largest possible interface for all smartforms and just fill the relevant fields. Then all smartform interfaces would be the same.

Regards,

Christian