ABAP Generate Change Pointer in Code

Create Change Document for Custom Table e1442419531234

ABAP Generate Change Pointer can be done directly by ABAP code. The following post will explains how to customize a change pointer and present a Sample ABAP Code to generate a Change Pointer in ABAP.

For more information about SAP change Pointer, check this post?SAP Change Pointer Overview

ABAP Generate Change Pointer Customizing

For customizing, check this post about?Creating SAP Change Documents for Custom Table/Fields.
It explains how to enable Change Document for none SAP standard tables and fields. The most common case is to trigger change on customized field on SAP Material or Customer Master Data.

If you want to know more SAP Change pointer / Document customizing and how to?Trigger IDOC immediately Purchase Order changed, the previous link will give the whole picture how to set up the customizing needed.

To sum up, First Check the SAP Change Pointer SCDO for?Display Change Document Objects if you want to adjust or create a change object for a custom field or table.

Then Add the the new Change Document objects for the Message in the SAP Tcode BD52.

Generate Change Pointer BAPI / Function

In order to generate Change pointer direclty from ABAP Code, you can use the standard function module?CHANGE_POINTERS_CREATE.?

You have to pass the following information to CHANGE_POINTERS_CREATE BAPI,

  • The Change document header: CHANGE_DOCUMENT_HEADER?( Type?CDHDR )
  • The Change document Items: CHANGE_DOCUMENT_POSITION ( Type Table of CDPOS )

Change Document Header

The Structure CHANGE_DOCUMENT_HEADER contains the header data for the change pointer.
The main fields to be filled in the change pointer header are:

  • OBJECTCLAS: Object class … ex. ‘MATERIAL’
  • OBJECTID: Object value … ex. MATNR or KUNNR
  • USERNAME: User name of the person responsible in change document
  • UDATE Creation date of the change document
  • UTIME Time changed
  • TCODE Transaction in which a change was made
  • CHANGE_IND Application object change type (U, I, E, D)
  • LANGU Language Key of the change

Change Document Items

The Change doucment Items contains the details of the change. It stores the old and the new value on the field level.
When generating Change pointer in ABAP Code, the following fields on the CDPOS structure must be filled

  • OBJECTCLAS: Object class … ex. ‘MATERIAL’
  • OBJECTID: ? ? ? Object value … ex. MATNR or KUNNR
  • TABNAME: ? ? ? Table Name
  • TABKEY: ? ? ? ?? Changed table record key
  • FNAME:? ? ? ? ? ? Field Name
  • CHNGIND: ? ? ? ?Change type (U, I, E, D)
  • TEXT_CASE:?? ?Flag: X=Text change
  • VALUE_NEW: ??New contents of changed field
  • VALUE_OLD: ?? Old contents of changed field

Generate Change Pointer Sample ABAP Code

In the following ABAP Sample code, a SAP change Pointer is created if a the value of MARC Customized field ZZFIELD is updated.

The TABKEY should be MANDT+MATNR+WERKS for SAP Material Plant Level Data.

For Customer Sales Data, the TABKET will be MANDT+KUNNR+VKORG+VTWEG for example

  DATA: ls_cdhdr TYPE cdhdr.
  DATA: lt_cdpos TYPE TABLE OF cdpos.
  FIELD-SYMBOLS: <fs_cdpos> LIKE LINE OF lt_cdpos.

  ls_cdhdr-mandant = sy-mandt.
  ls_cdhdr-objectclas = 'ZMATERIAL'.
  ls_cdhdr-objectid  = p_matnr.
  ls_cdhdr-username = sy-uname.
  ls_cdhdr-udate = sy-datum.
  ls_cdhdr-utime = sy-uzeit.
  ls_cdhdr-tcode = sy-tcode.
  ls_cdhdr-change_ind = 'U' .
  ls_cdhdr-langu = sy-langu.
  ls_cdhdr-version = '000'.
  " Change Pointer Triggered when a value of ZZFIELD on  
  " SAP Material Plant Data (extension ZZFIELD )
  <fs_cdpos>-mandant = sy-mandt.
  <fs_cdpos>-objectclas = 'ZMATERIAL'.
  <fs_cdpos>-objectid = p_matnr.
  <fs_cdpos>-tabname = 'MARC'.
  " tabkey : MANDT + MATNR + WERKS 
  CONCATENATE sy-mandt p_matnr p_werks INTO
   <fs_cdpos>-tabkey .
  <fs_cdpos>-fname =  'ZZFIELD'.
  <fs_cdpos>-chngind = 'U' . " Update Modification 
  <fs_cdpos>-text_case = 1 . 
  <fs_cdpos>-value_new = p_new_stock. " New Value 
  <fs_cdpos>-value_old = p_old_stock. " Old Value 

  " SAP Generate Change Pointer BAPI in ABAP 
      change_document_header   = ls_cdhdr
      change_document_position = lt_cdpos
      duplicate_pointer_id     = 1
      OTHERS                   = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.


If you want to dive deeper into the change pointer, check this link?Change Pointer (Master Data Distribution)?