SAP对于BAPI测试或调用可以记录测试数据,但是自己开发的函数不会生成测试记录,所以参考标准功能可以实现自开发的RFC也能生成测试记录,这样在接口遇到问题需要调试时,可以用测试记录直接调试,节约在RFC填入的数据的时间
FBGENDAT
- SE38运行程序FBGENDAT,输入要记录测试数据的BAPI,模式选B
- SU01 添加 FBGENDAT 为 X
- 自开发的函数通过写代码是可以生成测试数据的,跟踪源代码可以发现,其实测试记录是写在EUFUNC这张表里面,发现源代码里面一段宏就是用来记录测试数据的,只而且在函数开始调用宏就可以,代码如下
*&---------------------------------------------------------------------*
*& 包含 LZPI_TESTFRM
*&---------------------------------------------------------------------*
DEFINE fbgenmac.
types: begin of ltyp_datadir_gd,
dataid like eufunc-nummer,
stepid(3),
seqid like eufunc-seqid,
datum like sy-datum,
uzeit like sy-uzeit,
title(40),
end of ltyp_datadir_gd,
ltyp_datadir_gd_tab type table of ltyp_datadir_gd,
begin of ltyp_gendat, "Type of Cluster Table
fname type rs38l_fnam, "Name of Function Module
mode type c, "Mode
end of ltyp_gendat.
data: lv_para_gd type xuvalue,
lv_mode_gd(1) type c,
ls_gendat type ltyp_gendat,
lt_gendat type standard table of ltyp_gendat,
lv_pname_gd type tfdir-pname,
ls_header_gd type header_fb,
lt_tables_gd type rsfb_para,
lt_import_gd type rsfb_para,
lt_export_gd type rsfb_para,
lt_change_gd type rsfb_para,
lv_progname_gd type trdir-name,
lv_paraname_gd(100),
ls_datadir_gd type ltyp_datadir_gd,
lv_dataid_gd type eufunc-nummer,
lv_exit_gd type xfeld.
field-symbols: <ls_para> type rsfbpara,
<lv_parafld> type any,
<lv_paraval> type any,
<lt_parafld> type any table,
<lt_paraval> type any table,
<lt_datadir> type ltyp_datadir_gd_tab.
* user Parameter set ?
get parameter id 'FBGENDAT' field lv_para_gd.
if not lv_para_gd is initial.
* read the configuration table from DB
import gendat = lt_gendat from database indx(sd)
id 'GENDAT'.
* continue if the configuration table exists
if sy-subrc = 0.
* get name of calling function module
ls_header_gd-name = &1.
* read the configuration table
read table lt_gendat into ls_gendat
with key fname = ls_header_gd-name.
if sy-subrc = 0.
move ls_gendat-mode to lv_mode_gd.
endif.
case lv_mode_gd.
* 'A': create test data record and terminate
* 'B': create test data record and continue
* 'C': run into endless loop
* 'D': prepare test data record and continue
when 'A' or 'B' or 'D'.
* read function-pool
select single pname
from tfdir
into lv_pname_gd
where funcname = ls_header_gd-name.
call function 'FUNCTION_INCLUDE_SPLIT'
exporting
program = lv_pname_gd
importing
group = ls_header_gd-area
namespace = ls_header_gd-namespace.
* insert namespace (e.g. /AFS/)
concatenate ls_header_gd-namespace ls_header_gd-area
into ls_header_gd-area.
* read parameter of function module
call method cl_fb_parameter_db=>read
importing
tables = lt_tables_gd[]
import = lt_import_gd[]
export = lt_export_gd[]
change = lt_change_gd[]
changing
header = ls_header_gd.
* generate and load test data program
perform check_report_generate(saplseuj) using
ls_header_gd-name.
lv_progname_gd = ls_header_gd-name.
translate lv_progname_gd using ' ='.
lv_progname_gd+30 = 'FT'.
perform (space) in program (lv_progname_gd) if found.
* assign parameter to test frame
loop at lt_import_gd assigning <ls_para>.
concatenate '(' lv_progname_gd ')%_I' <ls_para>-parameter
into lv_paraname_gd.
assign (lv_paraname_gd) to <lv_parafld>.
check sy-subrc = 0.
assign (<ls_para>-parameter) to <lv_paraval>.
check sy-subrc = 0.
<lv_parafld> = <lv_paraval>.
endloop.
loop at lt_change_gd assigning <ls_para>.
concatenate '(' lv_progname_gd ')%_I' <ls_para>-parameter
into lv_paraname_gd.
assign (lv_paraname_gd) to <lv_parafld>.
check sy-subrc = 0.
assign (<ls_para>-parameter) to <lv_paraval>.
check sy-subrc = 0.
<lv_parafld> = <lv_paraval>.
endloop.
loop at lt_tables_gd assigning <ls_para>.
concatenate '(' lv_progname_gd ')%_I'
<ls_para>-parameter '[]'
into lv_paraname_gd.
assign (lv_paraname_gd) to <lt_parafld>.
check sy-subrc = 0.
concatenate <ls_para>-parameter '[]' into lv_paraname_gd.
assign (lv_paraname_gd) to <lt_paraval>.
check sy-subrc = 0.
<lt_parafld>[] = <lt_paraval>[].
endloop.
* If program will be terminated after creating test data
* it is required to commit work before, to save the test data.
* To avoid inconsistencies in business data, possible db changes
* have to be rolled back at this point.
*
if lv_mode_gd = 'A'.
rollback work.
endif.
* extend test data directory
perform db_import_datadir(saplseuj) using ls_header_gd-area
ls_header_gd-name
'999'
'X'.
assign ('(SAPLSEUJ)TE_DATADIR[]') to <lt_datadir>.
describe table <lt_datadir> lines lv_dataid_gd.
add 1 to lv_dataid_gd.
ls_datadir_gd-dataid = lv_dataid_gd.
concatenate 'GENERATED BY:' sy-uname into ls_datadir_gd-title.
ls_datadir_gd-datum = sy-datum.
ls_datadir_gd-uzeit = sy-uzeit.
ls_datadir_gd-stepid = 'PBO'.
append ls_datadir_gd to <lt_datadir>.
if lv_mode_gd ne 'D'.
call function 'SFCS_FA_PARAMETER_WRITE'
exporting
function = ls_header_gd-name
dataset = lv_dataid_gd.
perform db_export_datadir(saplseuj) using ls_header_gd-area
ls_header_gd-name
'999'.
else.
export ls_header_gd-area
ls_header_gd-name
lv_dataid_gd
to memory id 'fbgendat'.
endif.
if lv_mode_gd = 'A'.
commit work.
message x436(v2) with lv_dataid_gd ls_header_gd-name.
endif.
when 'C'.
while lv_exit_gd = space.
endwhile.
endcase.
endif.
endif.
END-OF-DEFINITION.