用到的TCODE:
SE37/SE80函数构建器
SE11 ABAP字典(包括数据库表/视图/数据类型等)
SE16 数据浏览器
RSA6 数据源目录
RSO2 维护一般数据源(事务数据/主数据属性/文本)
RSA3 提取器检验程序(数据源测试)
SE80 新建函数组,利用copy RSAX新建一个,最好一个函数组对应一个数据源
安全间隔下限:若2,则会将今天+昨天+前天的数抽一次
数据库表:ZHBSJ
数据类型:ZDS_ZHBSJ_STR
函数组:ZDS_ZHBSJ_GRP
函数:ZDS_ZHBSJ
数据源:ZDS_ZHBSJ
Step1:TCODE: SE11 创建数据库表
表名:ZHBSJ
Step2:TCODE: SE11 创建数据结构
数据结构名:ZDS_ZHBSJ_STR
Step3:TCODE: SE80 创建函数组和函数
函数组:ZDS_ZHBSJ_GRP,函数:ZDS_ZHBSJ
筛选出“函数组”,以“RSAX”作为关键字搜索我们要作为函数组模板的对象,并右击选择“复制”
函数组创建完成后,需要复制函数模块,这里我们只需要复制“RSAX_BIW_GET_DATA_SIMPLE”,并输入新函数模块名“ZDS_ZHBSJ”,然后点击“复制”。
这时候一定不要忘记右击函数组ZDS_ZHBSJ_GRP激活
Step4:TCODE: SE37 更改函数信息,修改源代码
下图中关联类型更改为我们刚创建的数据结构ZDS_ZHBSJ_STR
这时候,我们就需要修改源代码了
FUNCTION ZDS_ZHBSJ.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(I_REQUNR) TYPE SRSC_S_IF_SIMPLE-REQUNR
*" VALUE(I_DSOURCE) TYPE SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*" VALUE(I_MAXSIZE) TYPE SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
*" VALUE(I_INITFLAG) TYPE SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*" VALUE(I_READ_ONLY) TYPE SRSC_S_IF_SIMPLE-READONLY OPTIONAL
*" VALUE(I_REMOTE_CALL) TYPE SBIWA_FLAG DEFAULT SBIWA_C_FLAG_OFF
*" TABLES
*" I_T_SELECT TYPE SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL
*" I_T_FIELDS TYPE SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL
*" E_T_DATA STRUCTURE ZDS_ZHBSJ_STR OPTIONAL
*" EXCEPTIONS
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER
*"----------------------------------------------------------------------
* Example: DataSource for table SFLIGHT
TABLES: ZHBSJ."T001--公司代码
* Auxiliary Selection criteria structure
DATA: L_S_SELECT TYPE SRSC_S_SELECT.
* Maximum number of lines for DB table
STATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE,
* counter
S_COUNTER_DATAPAKID LIKE SY-TABIX,
* cursor
S_CURSOR TYPE CURSOR.
* Select ranges
RANGES: L_R_RYEAR FOR ZHBSJ-RYEAR,
L_R_POPER FOR ZHBSJ-POPER,
L_R_DOCNR FOR ZHBSJ-DOCNR,
L_R_CPUDT FOR ZHBSJ-CPUDT,
L_R_RBUKRS FOR ZHBSJ-RBUKRS.
* Initialization mode (first call by SAPI) or data transfer mode
* (following calls) ?
IF I_INITFLAG = SBIWA_C_FLAG_ON.
************************************************************************
* Initialization: check input parameters
* buffer input parameters
* prepare data selection
************************************************************************
* Check DataSource validity 数据源名字 : ZDS_ZHBSJ
CASE I_DSOURCE.
WHEN ‘ZDS_ZHBSJ‘.
WHEN OTHERS.
IF 1 = 2. MESSAGE E009(R3). ENDIF.
* this is a typical log call. Please write every error message like this
LOG_WRITE ‘E‘ "message type
‘R3‘ "message class
‘009‘ "message number
I_DSOURCE "message variable 1
‘ ‘. "message variable 2
RAISE ERROR_PASSED_TO_MESS_HANDLER.
ENDCASE.
APPEND LINES OF I_T_SELECT TO S_S_IF-T_SELECT.
* Fill parameter buffer for data extraction calls
S_S_IF-REQUNR = I_REQUNR.
S_S_IF-DSOURCE = I_DSOURCE.
S_S_IF-MAXSIZE = I_MAXSIZE.
* Fill field list table for an optimized select statement
* (in case that there is no 1:1 relation between InfoSource fields
* and database table fields this may be far from beeing trivial)
APPEND LINES OF I_T_FIELDS TO S_S_IF-T_FIELDS.
ELSE. "Initialization mode or data extraction ?
************************************************************************
* Data transfer: First Call OPEN CURSOR + FETCH
* Following Calls FETCH only
************************************************************************
* First data package -> OPEN CURSOR
IF S_COUNTER_DATAPAKID = 0.
* Fill range tables BW will only pass down simple selection criteria
* of the type SIGN = ‘I‘ and OPTION = ‘EQ‘ or OPTION = ‘BT‘.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = ‘RYEAR‘.
MOVE-CORRESPONDING L_S_SELECT TO L_R_RYEAR.
APPEND L_R_RYEAR.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = ‘POPER‘.
MOVE-CORRESPONDING L_S_SELECT TO L_R_POPER.
APPEND L_R_POPER.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = ‘DOCNR‘.
MOVE-CORRESPONDING L_S_SELECT TO L_R_DOCNR.
APPEND L_R_DOCNR.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = ‘CPUDT‘.
MOVE-CORRESPONDING L_S_SELECT TO L_R_CPUDT.
APPEND L_R_CPUDT.
ENDLOOP.
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE FIELDNM = ‘RBUKRS‘.
MOVE-CORRESPONDING L_S_SELECT TO L_R_RBUKRS.
APPEND L_R_RBUKRS.
ENDLOOP.
* Determine number of database records to be read per FETCH statement
* from input parameter I_MAXSIZE. If there is a one to one relation
* between DataSource table lines and database entries, this is trivial.
* In other cases, it may be impossible and some estimated value has to
* be determined.
OPEN CURSOR WITH HOLD S_CURSOR FOR
SELECT * FROM ZHBSJ WHERE RYEAR IN L_R_RYEAR AND
POPER IN L_R_POPER AND
DOCNR IN L_R_DOCNR AND
CPUDT IN L_R_CPUDT AND
RBUKRS IN L_R_RBUKRS.
ENDIF. "First data package ?
* Fetch records into interface table.
* named E_T_‘Name of extract structure‘.
FETCH NEXT CURSOR S_CURSOR
APPENDING CORRESPONDING FIELDS
OF TABLE e_t_data
PACKAGE SIZE S_S_IF-MAXSIZE.
IF SY-SUBRC <> 0.
CLOSE CURSOR S_CURSOR.
RAISE NO_MORE_DATA.
ENDIF.
S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.
ENDIF. "Initialization mode or data extraction ?
ENDFUNCTION.
Step5:TCODE:RSO2 创建数据源
数据源名:ZDS_ZHBSJ
这次的数据源我们以事务数据作为数据源
填写应用程序组件/简要描述/中间的说明/长文本描述信息
点击保存图标后,跳到如下界面,将有查询条件的字段在“选择”上选中,然后点击保存,这时候数据源就新增完成了
Step6:TCODE:RSA3 测试数据源
输入我们要测试的数据源名称,然后点击“提取”按钮,就可以提取到满足条件的数据记录