‎2010 Jul 17 7:10 AM
Hi,
I need to call few function modules dynamically.The exporting and importing parameters are also known only at run time.
Can somebody help me out in this regard,
Thanks and regards,
Archna
‎2010 Jul 17 9:32 AM
check the standard include LV69AF21, how the fm's PRICING_SUBSCREEN_PBO and PRICING_SUBSCREEN_PAI gets called.
link:[http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/840ad679-0601-0010-cd8e-9989fd650822#q-29]
‎2010 Jul 17 11:54 AM
hi ,
Create Function module according to your requirment and call the same
such as
Create functi0n module where you are passing PLant runtime and get data related to Plant
write code in function according to requirment .
FUNCTION zrfc_test.
*"----
""Local interface:
*" IMPORTING
*" VALUE(ZWERKS) TYPE MARC-WERKS OPTIONAL
*" EXPORTING
*" VALUE(RETURN) LIKE BAPIRET2 STRUCTURE BAPIRET2
*" TABLES
*" ZIT_DATA STRUCTURE MARC
*"----
IF zwerks IS NOT INITIAL.
SELECT *
FROM marc
INTO CORRESPONDING FIELDS OF TABLE zit_data
WHERE werks = zwerks .
ELSE.
SELECT *
FROM marc
INTO CORRESPONDING FIELDS OF TABLE zit_data.
ENDIF.
IF sy-subrc = 0 .
MESSAGE ' Selected ' TYPE 'I' .
ENDIF.
ENDFUNCTION.
Suppose at runtime you get Plant 7100
types : begin of w_marc .
include structure marc .
types : end of w_marc .
data : it_data type standard table of w_marc with header line .
p_plant = 7100 .
Call to function module
CALL FUNCTION 'ZRFC_TEST'
EXPORTING
ZWERKS = 'p_plant
IMPORTING
RETURN =
TABLES
zit_data = it_data .
.
You will get result in it_data .
Note : if you don't know how to create Function Module then search on SDN you will get lots of Forum .
Regards
Deepak.
‎2010 Jul 17 2:10 PM
Hello friend,
Please refer to following example:
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.