【转】普通数据源实现DELTA

最近在做PI和BW的一个接口,从其他数据源发送数据到BW的“直接更新”类型的CUBE,确切的说应该是BCS单户数据。当中,遇到了2个问题: 1. DSO的最多只能设置16个主键,而我们的模型需要设置超过16个主键? 2. 上载数据如何实现增量上载? 解决方法: 1. 自定义一个字段,作为主键,其他字段都作为数据字段。在开始例程中判断数据是否已经存在,存在,取原数据的主键;不存在,取时间戳和数据包上载记录的顺序号做为DSO的主键。 2. 利用DSO的增量机制,KEY FIGURE的Aggregation属性设置为OVERWRITE,上载数据默认为后镜像数据,每次上载的数据覆盖以前的数据,这样,对于修改和新增的数据都可以实现增量。对于数据包中删除的数据,将数据为0的记录写入到数据包。这样做,可以将删除的数据清为0。但要注意的是,在判断数据是否删除之前,必须要指定一个范围,即指定在哪个范围的数据内操作,否则程序会将除上载数据外的所有数据都置为0。 如:我们的例子中规定,每次上载一个合并单位下的某个期间的数据,在第二次上载的时候,我就要考虑数据是否在这个范围(合并单位+年度+期间)内存在,如果不存在,才将key figure为0的数据记录写入。 关于DELTA机制,请参考: http://community.kingdee.com/pages/chunguangz/blog/archive/2010/03/21/401977.aspx

METHOD start_routine. *=== Segments ===

FIELD-SYMBOLS: <SOURCE_FIELDS> TYPE _ty_s_SC_1.

DATA: MONITOR_REC TYPE rstmonitor.

*$*$ begin of routine - insert your code only below this line *-* ... "insert your code here *-- fill table "MONITOR" with values of structure "MONITOR_REC" *- to make monitor entries ... "to cancel the update process * raise exception type CX_RSROUT_ABORT.

DATA: lt_dso type TABLE OF /BIC/AZTBCSD0100, ls_dso type /BIC/AZTBCSD0100.

data: lv_index type i, lv_index_str(6) type c.

data: lv_stamp1(14) type c, lv_stamp2(14) type c.

data: sf_fields type _ty_s_SC_1.

types: BEGIN OF ts_id , FISCPER3 type /BIC/AZTBCSD0100-FISCPER3, FISCYEAR type /BIC/AZTBCSD0100-FISCYEAR, CS_UNIT type /BIC/AZTBCSD0100-CS_UNIT, END OF ts_id.

data: lt_id type TABLE OF ts_id, ls_id type ts_id.

select * from /BIC/AZTBCSD0100 into table lt_dso.

concatenate sy-datum sy-uzeit into lv_stamp1. move lv_stamp1 to lv_stamp2.

* 设置DSO主键 loop at SOURCE_PACKAGE ASSIGNING <source_fields>. * 如果时间过1秒,事件重新从1开始累计 concatenate sy-datum sy-uzeit into lv_stamp2. if lv_stamp1 <> lv_stamp2. clear lv_index. move lv_stamp2 to lv_stamp1. endif. lv_index = lv_index + 1.

* 查询数据是否已存在,本例中,所有字段都是主键 read table lt_dso with key CS_VERSION = <source_fields>-CS_VERSION CS_CHART = <source_fields>-CS_CHART CS_ITEM = <source_fields>-CS_ITEM COUNTRY = <source_fields>-COUNTRY MOVE_TYPE = <source_fields>-MOVE_TYPE ACQ_YEAR = <source_fields>-ACQ_YEAR ACQ_PER = <source_fields>-ACQ_PER BLINE_DATE = <source_fields>-BLINE_DATE CS_PARTNER = <source_fields>-CS_PARTNER FUNC_AREA = <source_fields>-FUNC_AREA /BIC/Z03BCS_01 = <source_fields>-/BIC/Z03BCS_01 /BIC/Z03BCS_02 = <source_fields>-/BIC/Z03BCS_02 /BIC/Z03BCS_03 = <source_fields>-/BIC/Z03BCS_03 /BIC/Z03BCS_04 = <source_fields>-/BIC/Z03BCS_04 /BIC/Z03BCS_05 = <source_fields>-/BIC/Z03BCS_05 /BIC/Z03BCS_06 = <source_fields>-/BIC/Z03BCS_06 /BIC/Z03BCS_07 = <source_fields>-/BIC/Z03BCS_07 /BIC/Z03BCS_08 = <source_fields>-/BIC/Z03BCS_08 /BIC/Z03BCS_09 = <source_fields>-/BIC/Z03BCS_09 /BIC/Z03BCS_14 = <source_fields>-/BIC/Z03BCS_14 /BIC/Z03BCS_15 = <source_fields>-/BIC/Z03BCS_15 /BIC/Z03BCS_16 = <source_fields>-/BIC/Z03BCS_16 /BIC/Z03BCS_66 = <source_fields>-/BIC/Z03BCS_66 /BIC/Z03BCS_67 = <source_fields>-/BIC/Z03BCS_67 /BIC/Z03BCS_68 = <source_fields>-/BIC/Z03BCS_68 /BIC/Z03BCS_69 = <source_fields>-/BIC/Z03BCS_69 /BIC/Z03BCS_70 = <source_fields>-/BIC/Z03BCS_70 /BIC/Z03BCS_72 = <source_fields>-/BIC/Z03BCS_72 /BIC/Z03BCS_71 = <source_fields>-/BIC/Z03BCS_71 /BIC/Z03BCS_74 = <source_fields>-/BIC/Z03BCS_74 /BIC/Z03BCS_75 = <source_fields>-/BIC/Z03BCS_75 /BIC/Z03BCS_76 = <source_fields>-/BIC/Z03BCS_76 /BIC/Z03BCS_77 = <source_fields>-/BIC/Z03BCS_77 /BIC/Z03BCS_10 = <source_fields>-/BIC/Z03BCS_10 /BIC/Z03BCS_11 = <source_fields>-/BIC/Z03BCS_11 /BIC/Z03BCS_12 = <source_fields>-/BIC/Z03BCS_12 /BIC/Z03BCS_13 = <source_fields>-/BIC/Z03BCS_13 /BIC/Z03BCS_78 = <source_fields>-/BIC/Z03BCS_78 /BIC/Z03BCS_80 = <source_fields>-/BIC/Z03BCS_80 /BIC/Z03BCS_81 = <source_fields>-/BIC/Z03BCS_81 /BIC/Z03BCS_82 = <source_fields>-/BIC/Z03BCS_82 /BIC/Z03BCS_83 = <source_fields>-/BIC/Z03BCS_83 /BIC/Z03BCS_84 = <source_fields>-/BIC/Z03BCS_84 /BIC/Z03BCS_85 = <source_fields>-/BIC/Z03BCS_85 /BIC/Z03BCS_86 = <source_fields>-/BIC/Z03BCS_86 /BIC/Z03BCS_79 = <source_fields>-/BIC/Z03BCS_79 BCS_DIDIEL = <source_fields>-BCS_DIDIEL BCS_PRGRP = <source_fields>-BCS_PRGRP /BIC/Z03BCS_17 = <source_fields>-/BIC/Z03BCS_17 SEM_ACOMP = <source_fields>-SEM_ACOMP CS_INVESTO = <source_fields>-CS_INVESTO CS_PLEVEL = <source_fields>-CS_PLEVEL BCS_DOCTY = <source_fields>-BCS_DOCTY BCS_CTFLG = <source_fields>-BCS_CTFLG CS_INVESTE = <source_fields>-CS_INVESTE CURKEY_GC = <source_fields>-CURKEY_GC CURKEY_LC = <source_fields>-CURKEY_LC UNIT = <source_fields>-UNIT CURKEY_TC = <source_fields>-CURKEY_TC CS_DIMEN = <source_fields>-CS_DIMEN CS_UNIT = <source_fields>-CS_UNIT CS_GROUP = <source_fields>-CS_GROUP FISCYEAR = <source_fields>-FISCYEAR FISCVARNT = <source_fields>-FISCVARNT FISCPER3 = <source_fields>-FISCPER3 into ls_dso.

if sy-subrc eq 0. * 如果数据已存在,则使用系统中数据的ZTMSTAMP作为现有的主键 <source_fields>-/BIC/ZTMSTAMP = ls_dso-/BIC/ZTMSTAMP. else. * 如果数据不存在,则使用获得的时间戳+INDEX作为主键 MOVE LV_INDEX TO LV_INDEX_STR. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING INPUT = lv_index_str IMPORTING OUTPUT = lv_index_str.

CONCATENATE lv_stamp1 lv_index_str into <source_fields>-/BIC/ZTMSTAMP. endif. modify SOURCE_PACKAGE from <source_fields>.

* 归集不同数据包(当有多家公司上载时) MOVE-CORRESPONDING <source_fields> to ls_id. collect ls_id into lt_id .

endloop.

loop at lt_id into ls_id. * 对不同公司分别处理 loop at lt_dso into ls_dso where FISCPER3 eq ls_id-FISCPER3 and FISCYEAR eq ls_id-FISCYEAR and CS_UNIT eq ls_id-CS_UNIT .

read table SOURCE_PACKAGE with key CS_VERSION = ls_dso-CS_VERSION CS_CHART = ls_dso-CS_CHART CS_ITEM = ls_dso-CS_ITEM COUNTRY = ls_dso-COUNTRY MOVE_TYPE = ls_dso-MOVE_TYPE ACQ_YEAR = ls_dso-ACQ_YEAR ACQ_PER = ls_dso-ACQ_PER BLINE_DATE = ls_dso-BLINE_DATE CS_PARTNER = ls_dso-CS_PARTNER FUNC_AREA = ls_dso-FUNC_AREA /BIC/Z03BCS_01 = ls_dso-/BIC/Z03BCS_01 /BIC/Z03BCS_02 = ls_dso-/BIC/Z03BCS_02 /BIC/Z03BCS_03 = ls_dso-/BIC/Z03BCS_03 /BIC/Z03BCS_04 = ls_dso-/BIC/Z03BCS_04 /BIC/Z03BCS_05 = ls_dso-/BIC/Z03BCS_05 /BIC/Z03BCS_06 = ls_dso-/BIC/Z03BCS_06 /BIC/Z03BCS_07 = ls_dso-/BIC/Z03BCS_07 /BIC/Z03BCS_08 = ls_dso-/BIC/Z03BCS_08 /BIC/Z03BCS_09 = ls_dso-/BIC/Z03BCS_09 /BIC/Z03BCS_14 = ls_dso-/BIC/Z03BCS_14 /BIC/Z03BCS_15 = ls_dso-/BIC/Z03BCS_15 /BIC/Z03BCS_16 = ls_dso-/BIC/Z03BCS_16 /BIC/Z03BCS_66 = ls_dso-/BIC/Z03BCS_66 /BIC/Z03BCS_67 = ls_dso-/BIC/Z03BCS_67 /BIC/Z03BCS_68 = ls_dso-/BIC/Z03BCS_68 /BIC/Z03BCS_69 = ls_dso-/BIC/Z03BCS_69 /BIC/Z03BCS_70 = ls_dso-/BIC/Z03BCS_70 /BIC/Z03BCS_72 = ls_dso-/BIC/Z03BCS_72 /BIC/Z03BCS_71 = ls_dso-/BIC/Z03BCS_71 /BIC/Z03BCS_74 = ls_dso-/BIC/Z03BCS_74 /BIC/Z03BCS_75 = ls_dso-/BIC/Z03BCS_75 /BIC/Z03BCS_76 = ls_dso-/BIC/Z03BCS_76 /BIC/Z03BCS_77 = ls_dso-/BIC/Z03BCS_77 /BIC/Z03BCS_10 = ls_dso-/BIC/Z03BCS_10 /BIC/Z03BCS_11 = ls_dso-/BIC/Z03BCS_11 /BIC/Z03BCS_12 = ls_dso-/BIC/Z03BCS_12 /BIC/Z03BCS_13 = ls_dso-/BIC/Z03BCS_13 /BIC/Z03BCS_78 = ls_dso-/BIC/Z03BCS_78 /BIC/Z03BCS_80 = ls_dso-/BIC/Z03BCS_80 /BIC/Z03BCS_81 = ls_dso-/BIC/Z03BCS_81 /BIC/Z03BCS_82 = ls_dso-/BIC/Z03BCS_82 /BIC/Z03BCS_83 = ls_dso-/BIC/Z03BCS_83 /BIC/Z03BCS_84 = ls_dso-/BIC/Z03BCS_84 /BIC/Z03BCS_85 = ls_dso-/BIC/Z03BCS_85 /BIC/Z03BCS_86 = ls_dso-/BIC/Z03BCS_86 /BIC/Z03BCS_79 = ls_dso-/BIC/Z03BCS_79 BCS_DIDIEL = ls_dso-BCS_DIDIEL BCS_PRGRP = ls_dso-BCS_PRGRP /BIC/Z03BCS_17 = ls_dso-/BIC/Z03BCS_17 SEM_ACOMP = ls_dso-SEM_ACOMP CS_INVESTO = ls_dso-CS_INVESTO CS_PLEVEL = ls_dso-CS_PLEVEL BCS_DOCTY = ls_dso-BCS_DOCTY BCS_CTFLG = ls_dso-BCS_CTFLG CS_INVESTE = ls_dso-CS_INVESTE CURKEY_GC = ls_dso-CURKEY_GC CURKEY_LC = ls_dso-CURKEY_LC UNIT = ls_dso-UNIT CURKEY_TC = ls_dso-CURKEY_TC CS_DIMEN = ls_dso-CS_DIMEN CS_UNIT = ls_dso-CS_UNIT CS_GROUP = ls_dso-CS_GROUP FISCYEAR = ls_dso-FISCYEAR FISCVARNT = ls_dso-FISCVARNT FISCPER3 = ls_dso-FISCPER3 assigning <source_fields>.

if sy-subrc <> 0 . * 如果数据不在DSO中,将为0的项目写入数据包 clear sf_fields. ls_dso-CS_TRN_GC = 0. ls_dso-CS_TRN_LC = 0. ls_dso-CS_TRN_QTY = 0. ls_dso-CS_TRN_TC = 0. MOVE-CORRESPONDING ls_dso to sf_fields. APPEND sf_fields to SOURCE_PACKAGE. endif.

endloop. endloop.

*$*$ end of routine - insert your code only before this line *-* ENDMETHOD. "start_routine

转自:http://community.kingdee.com/pages/chunguangz/blog/archive/2010/06/02/434488.aspx

posted @ 2013-01-10 11:20  hanmos  阅读(712)  评论(0编辑  收藏  举报