Sometimes there is a requirement where we need to make some changes in delivery header through custom program but we need to update the change log of delivery for those changes.
Like here we are discussing a case where we need to update the LIKP table of delivery header through ABAP code like deleting or changing some header field’s value. LIKP is a standard Sales and Distribution table available within R/3 SAP systems depending on the version and release level.
As changes done directly in delivery header get reflected in Changes option of Environment tab of header. Our requirement is to achieve similar thing when changes are done through program code not in the delivery directly.
How updation of change log is done in SAP:
The change log of delivery header is updated through CDHDR and CDPOS tables.
- e.g.Let’s take an outbound delivery 82342514 and make changes in it’s header.
Go to header in change mode.
Currently, the shipment reason maintained is ‘Complete Delevery Bl’.
Let’s remove it.
And save the delivery.
After saving the delivery, shipment reason (TRSPG) gets removed in LIKP.
Also, the updation in LIKP is followed by CDHDR and CDPOS tables updation.
Following entries appear in tables CDHDR and CDPOS.
As we can see from above tables, all the data regarding the change we did is recorded in CDHDR table along with a ‘change number’ which is used for searching in CDPOS table for that particular change .The new value and old value are also specified in the CDPOS table.
Since, these tables got updated , changes are also reflected in Change log of delivery.
Go to Environment -> Changes in delivery’s header.
This thing we need to remember regarding changes done in master data that they get recorded in these two tables and can be used in custom reports or functionalities based on transactional change and master data change.
As in this case, we have made change direct in delivery , so it’s getting reflected in these tables but in case we update it through custom code we need to update CDHDR and CDPOS tables also through our code.
STEPS for updating CDHDR and CDPOS tables through custom program.
1. Before updating LIKP table in custom code, extract the old values of LIKP in a work area.
2. After updating LIKP, take the new values of LIKP for that particular vbeln in a work area.
3. Call Function module ‘CHANGEDOCUMENT_OPEN’ passing vbeln as object id, object class as ‘LIEFERUNG’. Please note that proper object class needs to be specified. In this case it is ‘LIEFERUNG’ , since the object being discussed is delivery data.
4. Call function module ‘CHANGEDOCUMENT_SINGLE_CASE‘ passing tablename as LIKP, workarea_new as new values work area and workarea_old as old LIKP values work area.
5. Call function module ‘CHANGEDOCUMENT_CLOSE’ passing the values given below .This FM will provide a change number LIKE CDHDR–CHANGENR. This indicates that CDHDR and CDPOS tables are getting updated through these function modules along with change number.
Summary: As we have updated these tables, we are able to update the change log of delivery through this.Reference code can be found in attached document.