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

Dynamically calling a function module..

Former Member
0 Likes
393

Hi Friends,

I have to call different function modules dynamically depending on the field name.

Suppose..if field name is MASSN i have to call "HRWPC_RFC_MASSN_TEXT_GET" or if it is MASSG , then I have to call "HRWPC_RFC_MASSG_TEXT_GET". Its just for an example.Like this, I may get number of fields I have to call them dynamically.

For this.. I am retreiving the import and export parameters..from FUPARAREF table. And i am passing the values to PARA_TAB as follows.

LOOP AT it_import_fields INTO wa_import_fields.

READ TABLE lt_fields WITH KEY fname = wa_import_fields-fname.

IF sy-subrc EQ 0.

IF lt_fields-newdt IS NOT INITIAL.

wa_import_fields-value = lt_fields-newdt.

ELSE.

wa_import_fields-value = lt_fields-olddt.

ENDIF.

ENDIF.

MODIFY it_import_fields FROM wa_import_fields.

CLEAR wa_import_fields.

ENDLOOP.

LOOP AT it_export_fields INTO wa_export_fields.

READ TABLE lt_fields WITH KEY fname = wa_export_fields-fname.

IF sy-subrc EQ 0.

IF lt_fields-newdt IS NOT INITIAL.

wa_export_fields-value = lt_fields-newdt.

ELSE.

wa_export_fields-value = lt_fields-olddt.

ENDIF.

ENDIF.

MODIFY it_export_fields FROM wa_export_fields.

CLEAR wa_export_fields.

ENDLOOP.

LOOP AT it_import_fields INTO wa_import_fields.

wa_para_line-name = wa_import_fields-fname.

wa_para_line-kind = abap_func_exporting.

GET REFERENCE OF wa_import_fields-value INTO wa_para_line-value.

APPEND wa_para_line TO lt_para_tab.

ENDLOOP.

LOOP AT it_export_fields INTO wa_export_fields.

wa_para_line-name = wa_export_fields-fname.

wa_para_line-kind = abap_func_importing.

GET REFERENCE OF wa_export_fields-value INTO wa_para_line-value.

APPEND wa_para_line TO lt_para_tab.

ENDLOOP.

CALL FUNCTION lv_func_name

PARAMETER-TABLE

lt_para_tab.

ENDIF.

I am getting Dump at call function line saying.. Type declaration mis matched..

Please help me..

Thanks in advance.

Cheers.

Phani.

1 ACCEPTED SOLUTION
Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
359

Check the content and definitions in lt_para_tab.

From my personal experience CALL FUNCTION seems to be very finicky about the field type. Even the types that one would think should be compatible might cause a short dump. I always try to define the fields that I pass as the parameters with exactly the same type that is used in the FM definition.

1 REPLY 1
Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
360

Check the content and definitions in lt_para_tab.

From my personal experience CALL FUNCTION seems to be very finicky about the field type. Even the types that one would think should be compatible might cause a short dump. I always try to define the fields that I pass as the parameters with exactly the same type that is used in the FM definition.