在SAP与外部系统的整合开发中,SAP开发人员需要将RFC的输入输出参数信息提供给外部系统开发人员。为了提高效率,老板要求开发一个RFC,外部系统调用此RFC,只需要输入相关RFC名称,即可获得其详细的参数信息,例如table类型的参数具体有哪些栏位,各个栏位的data type, length, description等等。通过此程序,外部系统开发人员可直接获取某个RFC的参数的详细信息,而不必登录SAP或者要求SAP开发人员提供某个RFC的参数的具体信息。
源代码如下:
function y_rfc_get_fm_parameter.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(FMNAME) LIKE FUPARAREF-FUNCNAME
*" EXPORTING
*" VALUE(NUM) TYPE I
*" TABLES
*" PARA_TAB STRUCTURE FUPARAREF
*" PARA_INFO_TAB STRUCTURE YZBS003
*"----------------------------------------------------------------------
data: x030l_wa like x030l,dfies_wa type dfies,
x031l_tab like x031l occurs 0 with header line.
data: tbname type ddobjname,all_types type ddbool_d,
lfname type dfies-lfieldname,gp_name type ddbool_d,
fdname like x031l_tab-fieldname.
data: indi type i.
select * into corresponding fields of table para_tab from fupararef
where funcname = fmname.
describe table para_tab lines num.
do num times.
clear indi.clear fdname.
read table para_tab index sy-index.
if para_tab-structure cs '-'.
indi = 2.
tbname = para_tab-structure(sy-fdpos).
add 1 to sy-fdpos.
fdname = para_tab-structure+sy-fdpos.
else.
indi = 1.
tbname = para_tab-structure.
fdname = para_tab-structure.
endif.
lfname = para_tab-structure.
all_types = 'X'.
call function 'DDIF_NAMETAB_GET'
exporting
tabname = tbname "para_tab-structure
all_types = all_types
lfieldname = lfname
* GROUP_NAMES = ' '
* UCLEN =
importing
x030l_wa = x030l_wa
* DTELINFO_WA = DTELINFO_WA
* TTYPINFO_WA =
* DDOBJTYPE =
* DFIES_WA = dfies_wa
* LINES_DESCR =
tables
x031l_tab = x031l_tab
* DFIES_TAB = DFIES_TAB
exceptions
not_found = 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.
if indi = 1.
loop at x031l_tab.
para_info_tab-zparameter = para_tab-parameter.
move-corresponding x031l_tab to para_info_tab.
para_info_tab-zposition = x031l_tab-position.
para_info_tab-zoffset = x031l_tab-offset.
append para_info_tab.clear para_info_tab.
endloop.
elseif indi = 2.
loop at x031l_tab where fieldname = fdname.
para_info_tab-zparameter = para_tab-parameter.
move-corresponding x031l_tab to para_info_tab.
para_info_tab-tabname = para_tab-structure.
para_info_tab-zposition = x031l_tab-position.
para_info_tab-zoffset = x031l_tab-offset.
append para_info_tab.clear para_info_tab.
endloop.
endif.
enddo.
endfunction.