项目中遇到了一个需求:对自建表的数据进行操作的时候,需要对更改信息进行记录,到字段级别~
使用到了SAP 的chenge document 功能.
Tcode : SCDO
首先建立一个自己的change document object ,在对象里面填上需要记录的表的名字. 要是需要记录删除字段信息的话,把第二个checkbox选上.
然后选择生成更新程序 -> 保存.
点击生成信息的话,可以看见生成的程序还有function module信息,要是上面截图第一个checkbox被选择的话,还会生成新的structure .
到这里,change document object就建立好了~
在程序里面直接调用生成的function module把原始值和更新值传进去就可以了`
*------------------start-----------------------------------------------*
REFRESH : lt_icdtxt .
CALL FUNCTION 'ZYW8_WRITE_DOCUMENT'
EXPORTING
objectid = ls-objectid
tcode = ls-tcode
utime = ls-utime
udate = ls-udate
username = ls-username
* PLANNED_CHANGE_NUMBER = ' '
object_change_indicator = 'U'
* PLANNED_OR_REAL_CHANGES = ' '
* NO_CHANGE_POINTERS = ' '
* UPD_ICDTXT_ZYW8 = ' '
upd_zidowndata = 'U'
TABLES
icdtxt_zyw8 = lt_icdtxt
xzidowndata = lt_8_new
yzidowndata = lt_8_old .
*------------------end-------------------------------------------------*
SAP提供了一个标准的报表查看修改记录: RSSCD100 .
需要注意的一点,凡是需要记录的字段,dataelement里面的 changedocument属性必须设置~
自己实现的一个测试程序:
REPORT ZZ_TEST24.
data ls_person TYPE ztblperson.
data ls_person_old TYPE ztblperson.
data lt_person TYPE TABLE OF ztblperson.
data ls_person1 TYPE YZTBLPERSON.
data lt_person_new TYPE TABLE OF YZTBLPERSON.
data lt_person_old TYPE TABLE OF YZTBLPERSON.
ls_person-name = 'N10'.
ls_person-age = 50.
ls_person-job = 'ABAP'.
INSERT ls_person INTO TABLE lt_person.
MOVE-CORRESPONDING ls_person to ls_person1.
ls_person-name = 'N12'.
ls_person-age = 50.
ls_person-job = 'ABAP'.
INSERT ls_person INTO TABLE lt_person.
MOVE-CORRESPONDING ls_person to ls_person1.
INSERT ls_person1 INTO TABLE lt_person_old.
MODIFY ztblperson FROM TABLE lt_person. " update + insert
data lt_cdtxt TYPE TABLE OF CDTXT.
data ls_cdtxt TYPE CDTXT.
ls_cdtxt-TEILOBJID = ls_person-name.
ls_cdtxt-UPDKZ = 'I'.
INSERT ls_cdtxt INto table lt_cdtxt.
CALL FUNCTION 'ZPERSON_WRITE_DOCUMENT'
EXPORTING
OBJECTID = 'ZPERSON'
TCODE = sy-tcode
UTIME = sy-uzeit
UDATE = sy-datum
USERNAME = sy-uname
* PLANNED_CHANGE_NUMBER = ' '
OBJECT_CHANGE_INDICATOR = 'U'
* PLANNED_OR_REAL_CHANGES = ' '
* NO_CHANGE_POINTERS = ' '
UPD_ICDTXT_ZPERSON = 'U'
"N_ZTBLPERSON = ls_person
"O_ZTBLPERSON = ls_person_old
"UPD_ZTBLPERSON = ' '
TABLES
ICDTXT_ZPERSON = lt_cdtxt
XZTBLPERSON = lt_person_new
YZTBLPERSON = lt_person_old .
COMMIT WORK.
WRITE: 'OK'.
其他注意事项,可以参见下面的link~
http://help.sap.com/saphelp_erp2004/helpdata/en/2a/fa015b493111d182b70000e829fbfe/frameset.htm
The change document tables are as follows: CDHDR - Change document header table CDPOS - Change document items table