Code for change documents in ABAP using Changedocument function module

Scenario: Need report for change documents for Purchase order for given period.

Solution: Use standard SAP function module and pass the proper object class to the function module."CHANGEDOCUMENT_READ_HEADERS" and "CHANGE_DOCUMENT_READ_POSITIONS"
For Purchase orders use class as 'EINKBELEG' for other documents the object class need to change. Check the code below.

select-optionsS_chgdt  for ekpo-aedat obligatory.             

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S32 { color: #3399FF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; } datav_fromdt like CDHDR-UDATE,
      v_todate like CDHDR-UDATE.

datait_cdhdr like standard table of cdhdr,
      wa_cdhdr like cdhdr,
      it_editpos like standard table of cdshw,
      wa_editpos like cdshw,
      it_editpos1 like standard table of cdshw,
      wa_editpos1 like cdshw.

v_fromdt s_chgdt-low.
v_todate s_chgdt-high.


CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'
  EXPORTING
*   ARCHIVE_HANDLE                   = 0
    DATE_OF_CHANGE                   v_fromdt
    objectclass                      'EINKBELEG'
*   OBJECTID                         = ' '
*   TIME_OF_CHANGE                   = '000000'
*   USERNAME                         = SY-UNAME
*   LOCAL_TIME                       = ' '
*   TIME_ZONE                        = 'UTC'
    DATE_UNTIL                       v_todate
*   TIME_UNTIL                       = '235959'
*   NOPLUS_ASWILDCARD_INOBJID        = ' '
*   READ_CHANGEDOCU                  = ' '
  tables
    i_cdhdr                          it_cdhdr
* EXCEPTIONS
*   NO_POSITION_FOUND                = 1
*   WRONG_ACCESS_TO_ARCHIVE          = 2
*   TIME_ZONE_CONVERSION_ERROR       = 3
*   OTHERS                           = 4
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

if it_cdhdr[] is not initial.

loop at it_cdhdr into wa_cdhdr.

CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'
  EXPORTING
*   ARCHIVE_HANDLE                = 0
    changenumber                  wa_cdhdr-CHANGENR
*   TABLEKEY                      = ' '
*   TABLENAME                     = ' '
*   TABLEKEY254                   = ' '
*   KEYGUID                       = ' '
*   KEYGUID_STR                   = ' '
* IMPORTING
*   HEADER                        =
*   ET_CDRED_STR                  =
  TABLES
    EDITPOS                       it_editpos
*   EDITPOS_WITH_HEADER           =
* EXCEPTIONS
*   NO_POSITION_FOUND             = 1
*   WRONG_ACCESS_TO_ARCHIVE       = 2
*   OTHERS                        = 3
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

loop at it_editpos into wa_editpos.
  append wa_editpos to it_editpos1.
  clear wa_editpos.
endloop.

clear it_editpos[].
clear wa_cdhdr.
endloop.
endif.


Write/1(30)'Table Name'31(30)'Tabble filed name'61(15)'Old Value'76(15)'New value',91(10)'Doc Num',101(10)'Litem',111(10)'Change Type' .
loop at it_editpos1 into wa_editpos1.
  write/1(30wa_editpos1-TABNAME31(30wa_editpos1-FNAME61(15wa_editpos1-F_OLD+0(15)76(15wa_editpos1-f_new+0(15),
            91(10wa_editpos1-tabkey+3(10)101(10wa_editpos1-tabkey+13(5)111(10wa_editpos1-chngind.
endloop.

Comments

Popular posts from this blog

Add additional fields in VA05 report

Totals table for ACDOCA in S/4 HANA - ACDOCT

FAGLL03 / FBL1N / FBL3N / FBL5N not showing custom fields