Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

How to Easy... Insert Standard Change Log

$
0
0

Sometimes we need to insert a change log when updating standard tables.

Here I'll show how to easy insert this change log.

 

In this example, we will insert a log for VBKD table, from VAXX transactions.

In sales order, VERKBELEG object is the one used.

 

  " Local Vars

  DATA: lc_objectid TYPE cdhdr-objectid, " Change Log Object

        ls_vbkd_old TYPE vbkd,           " Workarea before update

        ls_vbkd_new TYPE vbkd.           " Workarea after update

 

  " Load current values

  SELECT *

    FROM vbkd

    INTO ls_vbkd_old

    UP TO 1 ROWS.


  ls_vbkd_new = ls_vbkd_old.

 

  " Change ls_vbkd_new fields here

 

  " Set object id to update VERKBELEG object

  lc_objectid = ls_vbkd_old-vbeln.

 

  " Call update functions

  CALL FUNCTION 'CHANGEDOCUMENT_OPEN'

    EXPORTING

      objectclass      = 'VERKBELEG'

      objectid         = lc_objectid

    EXCEPTIONS

      sequence_invalid = 1

      OTHERS           = 2.

 

 

  CALL FUNCTION 'CHANGEDOCUMENT_SINGLE_CASE'

    EXPORTING

      tablename              = 'VBKD'      " Table to update, could be anyone in VERKBELEG object

      workarea_new           = ls_vbkd_new " New values

      workarea_old           = ls_vbkd_old " Old values

    EXCEPTIONS

      nametab_error          = 1

      open_missing           = 2

      position_insert_failed = 3

      OTHERS                 = 4.

 

 

  CALL FUNCTION 'CHANGEDOCUMENT_CLOSE'

    EXPORTING

      date_of_change         = sy-datum

      objectclass            = 'VERKBELEG'

      objectid               = lc_objectid

      tcode                  = 'ZTRANSACTION'  " Set your own transaction

      time_of_change         = sy-uzeit

      username               = sy-uname

    EXCEPTIONS

      header_insert_failed   = 1

      no_position_inserted   = 2

      object_invalid         = 3

      open_missing           = 4

      position_insert_failed = 5

      OTHERS                 = 6.

 

 

It's Done.


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>