SAP Save Operations Records CDHDR and Cdpos tables

Source: Internet
Author: User

Http://blog.sina.com.cn/s/blog_7dce1fac01014yp2.html turn from
SAP field and object modifications save the old values, the data is stored in the CDHDR and Cdpos tables, and the old values can be extracted in two ways

1) Use SAP's standard functions changedocument_read_headers and Changedocument_read_positions

*   archive_handle = 0          "Sy-tabix      
    ChangeNumber =              "Cdpos-changenr  
*   Tablekey = SPACE            "Cdpos-tabkey  
*   tablename = SPACE           "Cdpos-tabname  
*   tablekey254 = SPACE         "Cdpos_uid-tabkey  
*   keyguid = SPACE             "Cdpos_uid-keyguid  
*   keyguid_str = SPACE         "Cdpos_str-keyguid  
    Header =                    "Cdhdr   
   Et_cdred_str =              "Cdred_str_tab  
*   Editpos =                  "cdshw     
Editpos_with_header =               "cdred  
No_position_found = 1       "               
wrong_access_to_archive = 2  "              

* Extract the header information of the Credit limit field modification
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.
* extract the field values modified by the credit limit field
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.

You can set interrupts in Changedocument_read_headers to get the object type.

Ex.

Extract the changed Acc. Changes
SELECT single Tabkey value_new into (Cdpos-tabkey,ikoinh)
From Cdpos
WHERE Objectclas = ' kred '
and Objectid = Itab-lifnr
and Changenr = Itab-changenr
and tabname = ' LFBK '
and fname = ' Koinh '.

Extract vendor Date of change

SELECT MAX (udate) to itab-cndate from CDHDR
WHERE Objectclas = ' kred ' and Objectid = Itab-lifnr.

--------------------------------------------------------------------------------

Grab all the changed programs

Report ztest001.
type-pools SLIs.
data:cdhdr TYPE cdhdr.
select-options:
s_objcls for Cdhdr-objectclas obligatory,
S_objtid for Cdhdr-objectid,
S_chngnr for Cdhdr-changenr,
S_usrnam for Cdhdr-username DEFAULT Sy-uname,
s_udate for Cdhdr-udate DEFAULT sy-datum,
s_time for Cdhdr-utime,
S_tcode for Cdhdr-tcode,
s_plncnr for Cdhdr-planchngnr,
S_chngno for Cdhdr-act_chngno,
s_wsplnd for Cdhdr-was_plannd,
s_chngid for Cdhdr-change_ind.

selection-screen SKIP.
PARAMETERS P_max TYPE numc3 obligatory DEFAULT ' $ '.

*---------------------------------------------------------------------*
TYPES:
BEGIN of TY_S_CDHDR.
INCLUDE STRUCTURE cdhdr.
Types:checkbox,
END of Ty_s_cdhdr,

BEGIN of Ty_s_cdpos.
INCLUDE STRUCTURE cdpos.
Types:checkbox,
END of Ty_s_cdpos.

*---------------------------------------------------------------------*
DATA:
* Layout for ALV
gs_layout TYPE Slis_layout_alv,
* Change Document Header
t_cdhdr TYPE TABLE of TY_S_CDHDR.

*---------------------------------------------------------------------*
start-of-selection.

* Read Change document Header
SELECT * into TABLE t_cdhdr
Up to P_max ROWS
From Cdhdr
WHERE Objectclas in S_objcls
and Objectid in S_objtid
and Changenr in S_chngnr
and username in S_usrnam
and udate in S_udate
and Utime in S_time
and Tcode in S_tcode
and Planchngnr in S_PLNCNR
and Act_chngno in S_chngno
and was_plannd in S_wsplnd
and Change_ind in S_chngid.

Gs_layout-zebra = ' X '.
gs_layout-colwidth_optimize = ' X '.
gs_layout-box_fieldname = ' CHECKBOX '.

* Display ALV
Call FUNCTION ' Reuse_alv_grid_display '
Exporting
I_callback_program = Sy-cprog
I_callback_user_command = ' User_command '
i_structure_name = ' CDHDR '
is_layout = Gs_layout
TABLES
t_outtab = T_cdhdr.

*---------------------------------------------------------------------*
* FORM User_command *
*---------------------------------------------------------------------*
FORM user_command USING u_ucomm TYPE syucomm
Us_selfield TYPE Slis_selfield. "#EC called

* Macro definition
DEFINE M_sort.
add 1 to Ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = ' X '.
append Ls_sort to Lt_sort.
end-of-definition.

DATA:
ls_cdhdr TYPE Ty_s_cdhdr,
ls_sort TYPE Slis_sortinfo_alv,
lt_sort TYPE Slis_t_sortinfo_alv,
* Change document Items
lt_cdpos TYPE TABLE of Ty_s_cdpos.

Case U_ucomm.
When ' &ic1 '.
PERFORM check_marked USING Us_selfield.

* Read Change document Items
LOOP at T_cdhdr into ls_cdhdr WHERE checkbox = ' X '.
SELECT * Appending TABLE lt_cdpos
From Cdpos
WHERE Objectclas = Ls_cdhdr-objectclas
and Objectid = Ls_cdhdr-objectid
and Changenr = Ls_cdhdr-changenr.
Endloop.

m_sort ' Changenr '.

* Display ALV
Call FUNCTION ' Reuse_alv_grid_display '
Exporting
i_structure_name = ' Cdpos '
is_layout = Gs_layout
It_sort = Lt_sort
TABLES
t_outtab = Lt_cdpos.

endcase.

EndForm. "User_command
*--------------------------------------------------------------------

FORM check_marked USING Us_selfield TYPE Slis_selfield.

Field-symbols:
<cdhdr> TYPE Ty_s_cdhdr.

READ TABLE T_cdhdr transporting NO fields with KEY checkbox = ' X '.
IF not SY-SUBRC is INITIAL and
Not Us_selfield-tabindex is INITIAL.
READ TABLE t_cdhdr INDEX us_selfield-tabindex assigning <cdhdr>.
<cdhdr>-checkbox = ' X '.
ENDIF.

EndForm.

SAP Save Operations Records CDHDR and Cdpos tables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.