2010 Mar 31 11:36 AM
Hi,
I want to know if there is a way call a "dynamic" function.
I explain:
I may have many object (LFA1, LFB1, LFM1, KNA1, KNB1) and I want to call the function module *_TEXT_HEADER_SELECT.
Something like this.
CASE wvg_object.
WHEN 'LFM1'.
wvg_function = 'LFM1_TEXT_HEADER_SELECT'.
WHEN 'LFA1'.
wvg_function = 'LFA1_TEXT_HEADER_SELECT'.
WHEN OTHERS.
ENDCASE.
CALL FUNCTION wvg_function.Possible to do this?
May you have some example to explain?
Thanks for your help.
David
2010 Mar 31 12:53 PM
You can't directly call the Function Module, You have to generate the particular Function Module by
Function Module FUNCTION_STUB_GENERATE - It will generete your dynamic Function Module with corresponding Import and Export Parameter.
DATA funcname TYPE rs38l-name.
DATA source TYPE rswsourcet.
funcname = wvg_function.
CALL FUNCTION 'FUNCTION_STUB_GENERATE'
EXPORTING
funcname = funcname
ic_mode = 'X'
with_enhancements = 'X'
TABLES
SOURCE = SOURCE "-> You will get generated Function Module Here
exceptions
function_not_exist = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Hi,
I want to know if there is a way call a "dynamic" function.
I explain:
I may have many object (LFA1, LFB1, LFM1, KNA1, KNB1) and I want to call the function module *_TEXT_HEADER_SELECT.
Something like this.
CASE wvg_object.
WHEN 'LFM1'.
wvg_function = 'LFM1_TEXT_HEADER_SELECT'.
WHEN 'LFA1'.
wvg_function = 'LFA1_TEXT_HEADER_SELECT'.
WHEN OTHERS.
ENDCASE.
CALL FUNCTION wvg_function.Possible to do this?
May you have some example to explain?
Thanks for your help.
David
2010 Mar 31 11:47 AM
try sth like this:
concatenate wvg_object '*_TEXT_HEADER_SELECT' into wvg_function.
call function wvg_function...
A.
2010 Mar 31 11:58 AM
Hi David,
DATA: wvg_function type rs38l_fnam. " the type is very important
CONCATENATE wvg_object 'TEXT_HEADER_SELECT' INTO wvg_function SEPARATED BY '_'.
CALL FUNCTION wvg_function
EXPORTING
...
IMPORTING
...
CHANGING
...Remember all the functions you call dynamically must have the same parameters and when calling dynamically remember to put parameters correctly.
Hope this help you!
Regards,
Khanh
2010 Mar 31 12:53 PM
You can't directly call the Function Module, You have to generate the particular Function Module by
Function Module FUNCTION_STUB_GENERATE - It will generete your dynamic Function Module with corresponding Import and Export Parameter.
DATA funcname TYPE rs38l-name.
DATA source TYPE rswsourcet.
funcname = wvg_function.
CALL FUNCTION 'FUNCTION_STUB_GENERATE'
EXPORTING
funcname = funcname
ic_mode = 'X'
with_enhancements = 'X'
TABLES
SOURCE = SOURCE "-> You will get generated Function Module Here
exceptions
function_not_exist = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
2010 Mar 31 1:19 PM
Hi and thanks for your messages.
the difficulty is that the paramaters are different for each function module.
Only the name seems to be similar.
David
Edited by: David31 on Mar 31, 2010 2:25 PM
Edited by: David31 on Mar 31, 2010 2:30 PM
2010 Mar 31 1:32 PM
You can Get Function Module Import and Export Parameter Details From
Function Module "FUNCTION_IMPORT_INTERFACE"
Kanagaraja L
2010 Mar 31 5:19 PM
How do you execute the code generate by FUNCTION_STUB_GENERATE?
I have the code in an internal table.
Must I only loop on this?
Thanks!
David
2010 Mar 31 6:17 PM
Hello David,
SAP has provided a standard way of handling this situation. Read this online documentation: [http://help.sap.com/abapdocu_70/en/ABAPCALL_FUNCTION_DYNAMIC.htm|http://help.sap.com/abapdocu_70/en/ABAPCALL_FUNCTION_DYNAMIC.htm]
You can get the interface parameters using this piece of code:
TYPE-POOLS abap.
DATA: it_excep TYPE STANDARD TABLE OF rsexc,
it_expar TYPE STANDARD TABLE OF rsexp,
it_impar TYPE STANDARD TABLE OF rsimp,
it_chpar TYPE STANDARD TABLE OF rscha,
it_table TYPE STANDARD TABLE OF rstbl,
wa_excep TYPE rsexc,
wa_expar TYPE rsexp,
wa_impar TYPE rsimp,
wa_chpar TYPE rscha,
wa_table TYPE rstbl,
ptab TYPE abap_func_parmbind_tab,
ptab_line TYPE abap_func_parmbind.
PARAMETERS p_fname LIKE tfdir-funcname.
CALL FUNCTION 'FUNCTION_IMPORT_INTERFACE'
EXPORTING
funcname = p_fname
TABLES
exception_list = it_excep
export_parameter = it_expar
import_parameter = it_impar
changing_parameter = it_chpar
tables_parameter = it_table
EXCEPTIONS
error_message = 1
function_not_found = 2
invalid_name = 3
OTHERS = 4.
IF sy-subrc = 0.
* Put your code for the dynamic function call here
ENDIF.Hope this helps.
BR,
Suhas
2010 Apr 07 8:53 AM
Hi!
Sorry beeing so late.
Your answers are very helpfull!
Thanks,
David