标签:
? ?
sap标准:RSSCD100,RSSCD200
? ?
来自 <http://blog.csdn.net/sap_jack/article/details/1366572>
? ?
sap的字段和对象的修改都会保存旧值,数据保存在CDHDR和CDPOS表中,对于提取旧值你可以采用两种方法
?1)使用sap的标准函数CHANGEDOCUMENT_READ_HEADERS?和CHANGEDOCUMENT_READ_POSITIONS
2)使用select语句直接从表中读取。
直接使用SELECT语句读取数据的示例:
*提取信用额度字段修改的抬头信息
????? select? cdhdr~changenr cdhdr~udate cdhdr~utime
??????? into? corresponding fields of table p_cdhdr
??????? from cdhdr
??????? where cdhdr~objectclas = ‘KLIM‘ and
????????? cdhdr~objectid = wa_customerinfo-kunnr.
????? if sy-subrc = 0.
*提取信用额度字段修改的字段值
??????? select cdpos~changenr cdpos~value_old cdpos~value_new
????????? into corresponding fields of table? p_cdpos
????????? from cdpos
??????????? for all entries in p_cdhdr
????????? where cdpos~objectclas = ‘KLIM‘ and
??????????? cdpos~objectid = wa_customerinfo-kunnr and
??????????? cdpos~changenr = p_cdhdr-changenr and
??????????? cdpos~tabname = ‘KNKK‘ and
??????????? cdpos~fname = ‘KLIMK‘.
??????? if sy-subrc = 0.
?????? endif.
endif.
可以在CHANGEDOCUMENT_READ_HEADERS?中设置中断获得对象类型。
参考连接:http://blog.csdn.net/CompassButton/archive/2006/11/04/1366572.aspx
? ?
来自 <http://blog.csdn.net/sap_jack/article/details/1119340>
? ?
SCDO
2015年1月9日
12:39
? ?
项目中遇到了一个需求:对自建表的数据进行操作的时候,需要对更改信息进行记录,到字段级别~
使用到了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
? ?
来自 <http://blog.csdn.net/zeewjj/article/details/8753295#comments>
? ?
Table 日志
2015年1月9日
12:44
? ?
?现在项目上自开发的dialog程序越来越多,有很多敏感数据需要像SAP标准的业务一样,能看到所有的修改日志,要想实现日志的功能,有以下几个办法:
办法一、建一个日志表,在原有表的基础上,加上日期和时间两个关键字,这样每次修改的记录都会存到日志表里,然后在日志报表里把日志表的数据取出来做比较。
办法二、表级别的日志记录。在自建表的SE11技术设置里把Log data changes勾选中,这样,每次这个表的修改都会自动记录到标准表:DBTABLOG和DBTABPRT中。查看日志的标准TCODE是:SCU3。如果表里有数,但是无法用标准TCODE查看的话,可以给自建表维护一个表维护再试试看。
办法三、字段级别的日志记录。
1、对自建表中想要记录日志的字段,进入到这个字段额data element里面的Further?characteristics视图,勾选中:更改文档。一些标准的data element如果已经勾选中,则不需要再勾。想记录哪个字段就勾选哪个字段的。
2、TCODE: SCDO,创建文档对象
3、创建好以后会自动生成函数,再你的程序里面调用此函数,将原始值和修改后的值传入,系统会自动记录日志,效果和标准的ME23N之类的相同
4、SAP提供了一个标准的报表查看修改记录: RSSCD100 。
? ?
来自 <http://blog.163.com/arhao_h/blog/static/125169020123911254671/>
? ?
? ?
Application Log
2015年2月28日
9:54
? ?
Create and view LOG using SLG0 and SLG1 transaction
created by?akankshi prasad?on Apr 18, 2012 2:25 PM, last modified by?akankshi prasad?on Apr 18, 2012 2:35 PM
Version 1
inShare11
Create and view LOG using SLG0 and SLG1 transaction
? ?
Application LOG
When we need to display all messages together then this set of messages is a log. Logs usually also contain general header information (log type, creator, creation time, etc.). Several logs can be created in a transaction. The Application Log provides a comprehensive infrastructure for collecting messages, saving them in the database and displaying them as logs. It has also traffic icons for the messages based on the message type.
? ?
Important Transactions
The important transactions codes used for application log are as following:
·??????SLG0?– Create a new Log Object and sub object
·??????SLG1?– Display Application Log
·??????SLG2?– Delete the Application Log
Creation of object and sub object:
For generating a custom application log we need to create a new log object and sub object. For this we use transaction SLG0.
Go to transaction SLG0 and click on new entries. Then give the name of object and save. For any of the object we can create the sub object as well.?Sub objects are simply further classifications of the application log.
? ?
To collect messages and display them in LOG in program:
Function modules to be used:
BAL_LOG_CREATE Create log with header data
BAL_LOG_MSG_ADD Add a message to a log
BAL_DB_SAVE Save the messages
BAL_DSP_LOG_DISPLAY Display message in memory
? ?
Open Log
The FM BAL_LOG_CREATE is used to open application log. This FM returns log handle. This log handle is a unique identifier for a particular log. We use this log handle later for accessing the log like for example adding messages to the log etc.
? ?
Add message to LOG
Using the log handle we can add as many messages we want to the LOG through the FM BAL_LOG_MSG_ADD to the importing parameter I_S_MSG?(structure BAL_S_MSG). This data is very much similar to the T100 data that is message type, message number and the four message variables.
? ?
Save messages
Logs there in the memory can be saved to database using the FM BAL_DB_SAVE by passing the importing parameter I_SAVE_ALL = ‘X‘.The function module BAL_DB_SAVE returns a table (Exporting parameter E_NEW_LOGNUMBERS), which relates LOG_HANDLE, external number EXTNUMBER, temporary LOGNUMBER and permanent LOGNUMBER, so you can find out which number was assigned to a log after saving.
? ?
Display messages
FM BAL_DSP_LOG_DISPLAY is used to display collected messages.
? ?
Below is one sample code using the above mentioned FMs:
? ?
ls_log-object = lc_object.????????? "Object name
? ls_log-aluser = sy-uname.??????? "Username
? ls_log-alprog = sy-repid.????????? "Report name
? ?
***Open Log
? CALL FUNCTION ‘BAL_LOG_CREATE‘
??? EXPORTING
????? i_s_log???????????????? = ls_log
??? IMPORTING
????? e_log_handle??????????? = ls_log_handle
??? EXCEPTIONS
????? log_header_inconsistent = 1
????? OTHERS????????????????? = 2.
? IF sy-subrc EQ 0.
? ?
***Create message
??? ls_msg-msgty = lc_type.?????????????? "Message type
??? ls_msg-msgid = lc_msgid.??????????? "Message id
??? ls_msg-msgno = lc_msgno.????????? "Message number
??? ls_msg-msgv1 = lv_message1.????? "Text that you want to pass as message
??? ls_msg-msgv2 = lv_message2.
??? ls_msg-msgv3 = lv_message3.
??? ls_msg-msgv4 = lv_message4.
??? ls_msg-probclass = 2.
? ?
??? CALL FUNCTION ‘BAL_LOG_MSG_ADD‘
????? EXPORTING
?????? i_log_handle????????????? = ls_log_handle
??????? i_s_msg?????????????????? = ls_msg
* IMPORTING
*?? E_S_MSG_HANDLE??????????? =
*?? E_MSG_WAS_LOGGED????????? =
*?? E_MSG_WAS_DISPLAYED?????? =
???? EXCEPTIONS
?????? log_not_found???????????? = 1
?????? msg_inconsistent????????? = 2
?????? log_is_full?????????????? = 3
?????? OTHERS??????????????????? = 4.
??? IF sy-subrc NE 0.
????? "Do nothing
??? ENDIF.
??? INSERT ls_log_handle INTO TABLE li_log_handle.
? ?
***Save message
??? CALL FUNCTION ‘BAL_DB_SAVE‘
???? EXPORTING
?????? i_client?????????????? = sy-mandt
*?? I_IN_UPDATE_TASK?????? = ‘ ‘
?????? i_save_all???????????? = lc_set
?????? i_t_log_handle???????? = li_log_handle
* IMPORTING
*?? E_NEW_LOGNUMBERS?????? =
???? EXCEPTIONS
?????? log_not_found????????? = 1
?????? save_not_allowed?????? = 2
?????? numbering_error??????? = 3
?????? OTHERS???????????????? = 4.
??? IF sy-subrc EQ 0.
????? REFRESH: li_log_handle.
??? ENDIF.
? ?
Usage of Application LOG
We can use application log in the below scenarios:
·??????When we want to save the List/Log for the long time: Generally, we have the spool retention period of 8 days. So, the list or log will be deleted automatically.
·??????When we want more information compared to Log generated with WRITE: Application Log has more information like User, date of creation, Severity of the message.
·??????In ALE / EDI Processing: When we do the cross client processing (IDoc Processing), we can generate the Application log to keep track of the generated errors or the messages.
Summary of the steps to Create and View logs:
1)???? 1)??Create object and sub object in SLG0 transaction.
2)???? 2)?The program where you want to create the LOG call the FMs:
?????????????BAL_LOG_CREATE
BAL_LOG_MSG_ADD
BAL_DB_SAVE
3)???? 3)??For viewing the logs go to SLG1 transaction and give the object name, sub object name (if any) and other related information like the Username and date etc.
4)??????Then click on Execute. You will be able to see the logs. Double click on any one of them to see the detailed error message.
????????4) One can even view the logs through the program itself by using the FM?BAL_DSP_LOG_DISPLAY.
? ?
? ?
来自 <http://scn.sap.com/docs/DOC-27066>
标签:
原文地址:http://www.cnblogs.com/rootbin/p/4463319.html