SAP Idocs. Creating and Configuring Change Pointers for Idoc from Scratch
SAP Idocs. Creating and Configuring Change Pointers for Idoc from Scratch
Having broken down the components of setting up and developing a custom Idoc, it makes sense to do the same for the process of configuring and developing change pointers in connection with a newly created Idoc. That’s exactly the goal of this post, as it seems a logical continuation of my previously published material.
Background
See article: SAP Idocs. Creating and Configuring a Custom Idoc from Scratch
Task
Enable the creation of change pointers for a custom message type. A change pointer should be generated upon modification of a Personnel Administration infotype. Based on the generated change pointer, an Idoc should be created and sent to another SAP system.
Theory
See: Change Pointer (Master Data Distribution)
See: Distributing Master Data with the SMD Tool
Step 1. Activate Change Pointer Creation (Transaction BD61)
Activate the change pointer creation capability in the system by executing transaction BD61.

Step 2. Implement the Change Pointer Generation Mechanism
According to the task, a change pointer should be created when editing a Personnel Administration infotype record. Tracking of infotype changes will be handled by an implementation of BAdI HRPAD00INFTY (which is currently not implemented). The actual creation of the change pointer will be performed by calling the function module CHANGE_POINTERS_CREATE_DIRECT inside the new BAdI implementation.
See article: How to Define Additional Logic for a PA Infotype?
You can create a new BAdI implementation using transaction SE18.

Note: The ABAP code shown below is meant for demonstration purposes only. It must be adapted before use in any real project.
Also note: by default, SAP does not manage indicators (Insert, Update, Delete) for newly created change pointers. Depending on the business requirement, the logic for setting and assigning these indicators will have to be developed by the consultant and developer.
Step 3. Verify Change Pointer Creation for the Message Type
The following video clip shows the sequence of actions in which a PA infotype record is created/edited/deleted, followed by a check for the corresponding change pointer entry in table BDCP2.
Step 4. Configure the Distribution Model
Using transaction BD64, assign the message type to the partner system to which the Idoc generated from the change pointer should be sent.
See: Model Distribution

Step 5. FM to Create Idoc from Change Pointer (Transaction SE37)
Based on the change pointer stored in table BDCP2, create an Idoc with the relevant content. This cannot be done without ABAP. Fortunately, this task becomes manageable knowing that you can look at the source code of existing function modules under the pattern MASTERIDOC_CREATE_SMD_* in transaction SE37.
The following ABAP snippet demonstrates this:
DATA: distrimodel LIKE bdi_model OCCURS 0 WITH HEADER LINE,
change_pointers LIKE STANDARD TABLE OF bdcp,
change_pointer LIKE bdcp,
lt_cp TYPE TABLE OF bdicpident,
lv_subty TYPE p0021-subty,
lt_0021 TYPE TABLE OF p0021,
it_data TYPE TABLE OF edidd,
it_data1 TYPE TABLE OF edidd,
ls_idoc_body TYPE z1i0021,
ls_data TYPE edidd,
lt_comm_idoc LIKE edidc OCCURS 0 WITH HEADER LINE,
s_ctrl_rec LIKE edidc.
CONSTANTS: lc_message_type TYPE bdcps-mestype VALUE 'ZFAMILY'.
CALL FUNCTION 'CHANGE_POINTERS_READ'
EXPORTING
message_type = lc_message_type
read_not_processed_pointers = 'X'
TABLES
change_pointers = change_pointers
EXCEPTIONS
error_in_date_interval = 1
error_in_time_interval = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT change_pointers INTO change_pointer.
IF change_pointer-cretime+0(8) <= sy-datum.
DATA(lv_pernr) = change_pointer-tabkey+1(8).
DATA(lv_infty) = change_pointer-tabkey+9(4).
DATA(lv_strlen) = strlen( change_pointer-tabkey ).
IF lv_strlen = 30.
lv_subty = change_pointer-tabkey+13(1).
DATA(lv_begda) = change_pointer-tabkey+14(8).
DATA(lv_endda) = change_pointer-tabkey+22(8).
ELSE.
lv_subty = change_pointer-tabkey+13(2).
lv_begda = change_pointer-tabkey+15(8).
lv_endda = change_pointer-tabkey+23(8).
ENDIF.
ls_data-segnam = 'Z1I0021'.
ls_data-mandt = sy-mandt.
CALL FUNCTION 'HR_READ_INFOTYPE'
EXPORTING
tclas = 'A'
pernr = CONV prelp-pernr( lv_pernr )
infty = CONV prelp-infty( lv_infty )
begda = CONV prelp-begda( lv_begda )
endda = CONV prelp-endda( lv_endda )
TABLES
infty_tab = lt_0021.
IF lt_0021 IS NOT INITIAL.
READ TABLE lt_0021 ASSIGNING FIELD-SYMBOL() WITH KEY subty = lv_subty.
IF IS ASSIGNED.
ls_idoc_body-pernr = -pernr.
ls_idoc_body-begda = -begda.
ls_idoc_body-endda = -endda.
ls_idoc_body-rel_type = -subty.
ls_idoc_body-dob = -fgbdt.
ls_idoc_body-first_name = -favor.
ls_idoc_body-last_name = -fanam.
ls_idoc_body-gender_key = -fasex.
ls_data-docnum = change_pointer-cpident.
ls_data-sdata = ls_idoc_body.
APPEND ls_data TO it_data.
ELSE.
IF change_pointer-cdchgid EQ 'D'.
ls_idoc_body-pernr = -pernr.
ls_idoc_body-begda = -begda.
ls_idoc_body-endda = -endda.
ls_idoc_body-rel_type = -subty.
ls_data-sdata = ls_idoc_body.
ls_data-docnum = change_pointer-cpident.
APPEND ls_data TO it_data.
ENDIF.
ENDIF.
ELSE.
ls_idoc_body-pernr = lv_pernr.
ls_idoc_body-begda = lv_begda.
ls_idoc_body-endda = lv_endda.
ls_idoc_body-rel_type = lv_subty.
ls_data-sdata = ls_idoc_body.
ls_data-docnum = change_pointer-cpident.
APPEND ls_data TO it_data.
ENDIF.
ELSE.
ls_idoc_body-pernr = lv_pernr.
ls_idoc_body-begda = lv_begda.
ls_idoc_body-endda = lv_endda.
ls_idoc_body-rel_type = lv_subty.
ls_data-sdata = ls_idoc_body.
ls_data-docnum = change_pointer-cpident.
APPEND ls_data TO it_data.
ENDIF.
CALL FUNCTION 'ALE_MODEL_INFO_GET'
EXPORTING
message_type = lc_message_type
TABLES
model_data = distrimodel
EXCEPTIONS
OTHERS = 0.
IF distrimodel IS NOT INITIAL.
s_ctrl_rec-mestyp = 'ZFAMILY' . "Message type
s_ctrl_rec-idoctp = 'ZHR_IT0021'. "Basic IDOC type
s_ctrl_rec-rcvprt = 'LS'. "Partner type of receiver
s_ctrl_rec-rcvprn = 'IDECLNT810'. "Part
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
master_idoc_control = s_ctrl_rec "rec_control " Control record of master IDoc
TABLES
communication_idoc_control = lt_comm_idoc "it_control " Control records of created comm. IDocs
master_idoc_data = it_data " Data records of master IDoc
EXCEPTIONS
error_in_idoc_control = 1
error_writing_idoc_status = 2
error_in_idoc_data = 3
sending_logical_system_unknown = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
CLEAR lt_cp.
APPEND VALUE #( cpident = change_pointer-cpident ) TO lt_cp.
CALL FUNCTION 'CHANGE_POINTERS_STATUS_WRITE'
EXPORTING
message_type = 'ZFAMILY'
TABLES
change_pointers_idents = lt_cp.
ENDIF.
ENDIF.
ENDLOOP.
After a change pointer is successfully processed, a corresponding status flag should be set in table BDCP2 (BDCP2-PROCESS = 'X'
). In ABAP, this is done by calling CHANGE_POINTERS_STATUS_WRITE.
Step 6. Assign the FM for Idoc Creation to the Message Type (Transaction BD60)
Assign the newly created FM to the appropriate message type using transaction BD60.

Step 7. Activate Change Pointer for the Message Type (Transaction BD50)
Activate change pointer creation for the desired message type using transaction BD50.

Step 8. Test the Idoc Creation Process from the Change Pointer
As described in a previous post on Idoc generation from change pointers, once the pointer entry is written to BDCP2, the program RBDMIDOC must complete the process by handling the specified message types.
See article: SAP IDocs. Change Pointers
The next video shows the sequence in which change pointers are created and program RBDMIDOC is run. The result is then reviewed by verifying the transmission of the generated Idoc to the receiving system. In this example, the Idoc is sent from client #800 to client #810 within the same system. In the "neighbor" client, the Idoc’s status and its impact on the employee’s master data are verified.
How to Quickly Disable Change Pointer Creation for a Specific Message Type?
Deactivate the relevant message type in transaction BD50. See Step #7 — Activate Change Pointer for the Message Type.
The final video clip shows the process of changing employee master data with change pointer creation enabled, followed by the same actions with change pointer creation disabled.