Skip to Content

8.0pt;font-family:Verdana’> 

8.0pt;font-family:Verdana’>Following is the remaining content of the first part of the weblog series ‘Custom fields in standard extractors…’. It lists a quick and dirty code of the user-exit to realize the extract structure extension with custom fields, and  provide delta functionality for the same.

8.0pt;font-family:Verdana’> 

8.0pt;font-family:Verdana’>Remaining parts of this series will cover other options for including custom fields with standard extractors.

8.0pt;font-family:Verdana’> 

8.0pt;font-family:Verdana’>Exit: EXIT_SAPLRSAP_001

8.0pt;font-family:Verdana’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>*———————————————————————-*

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>*   INCLUDE ZXRSAU01                                                   *

lang=ES-TRAD 8.0pt;font-family:”Arial monospaced for SAP”;color:black; ES-TRAD’>*———————————————————————-*

lang=ES-TRAD 8.0pt;font-family:”Arial monospaced for SAP”;color:black; ES-TRAD’>tables: knvv, mara.

lang=ES-TRAD 8.0pt;font-family:”Arial monospaced for SAP”;color:black; ES-TRAD’>*** T A B L E S    D E C L A R A T I O N ***

lang=ES-TRAD 8.0pt;font-family:”Arial monospaced for SAP”;color:black; ES-TRAD’> 

lang=ES-TRAD 8.0pt;font-family:”Arial monospaced for SAP”;color:black; ES-TRAD’>tables : ekpo, ztimestamp, mc02m_0itm, cdhdr, cdpos.

lang=ES-TRAD 8.0pt;font-family:”Arial monospaced for SAP”;color:black; ES-TRAD’> 

lang=ES-TRAD 8.0pt;font-family:”Arial monospaced for SAP”;color:black; ES-TRAD’>*** D A T A   D E C LA R A T I O N ***

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>types: begin of str_cdpos.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        include structure cdpos.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>types: udate like sy-datum,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>       utime like sy-uzeit,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>       end of str_cdpos.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>data   : num_lines     like sy-dbcnt,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>         zkopprctr     like ekpo-kopprctr,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>         zkocapvalue   like ekpo-kocapvalue,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>         l_s_icctrcst1 like mc02m_0itm,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>         it_timestamp  type table of ztimestamp with header line,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>         it_cdpos      type table of str_cdpos  with header line,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>         it_cdhdr      type table of cdhdr      with header line,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>         ldate         like sy-datum,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>         ltime         like sy-uzeit,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>         tabkey        like cdpos-tabkey,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>         logic_flag    type n value ‘0’. “Indicator whether

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>” Logic for finding old value of custom field is

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>” needed

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>data: l_s_icctrcst like s001biws,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      l_counter,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      l_s_icctract like icctract,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      l_s_icctrsta like icctrsta,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      l_tabix      like sy-tabix,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      w_value      like ekpo-kopprctr.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>data : begin of itab occurs 1,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>       ebeln like ekpo-ebeln,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>       ebelp like ekpo-ebelp,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>       end of itab.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>case i_datasource.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>  when ‘2LIS_02_ITM’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>************************************************************************

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>**** logic for delta transfer

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>************************************************************************

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>************************************************************************

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* To create the initial entry in the Z timestamp table if it is not a

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* delta extraction run.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>************************************************************************

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>    if i_updmode eq ‘C’ or i_updmode eq ‘I’ or i_updmode eq ‘F’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      it_timestamp-ztime       = sy-uzeit.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      it_timestamp-zdate       = sy-datum.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      it_timestamp-zdatasource = ‘2LIS_02_ITM’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      append it_timestamp.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      insert ztimestamp from table it_timestamp.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>    endif.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>************************************************************************

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>**** IF UPDATE MODE IS DELTA****

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>************************************************************************

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>    if i_updmode eq ‘D’ .

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* Get the timestamp value of last extraction run

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      SELECT * FROM ZTIMESTAMP INTO TABLE IT_TIMESTAMP

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>         WHERE ZDATASOURCE = ‘2LIS_02_ITM’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      sort it_timestamp by zdate ztime.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      read table it_timestamp index sy-dbcnt.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      refresh it_timestamp.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>**** GET THE EXTRACTED RECORDS ****

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      loop at c_t_data into l_s_icctrcst1.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        logic_flag = ‘0’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        w_value = ”.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        l_tabix = sy-tabix.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        sort itab.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* Insert ‘before image’ value only if this is the first occurance of the

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* PO-ITEM, and it is a cancellation record. For all other records,

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* original logic (same as historical data setup) will be followed for

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* both ‘before’ and ‘after’ image records.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        read table itab with key ebeln = l_s_icctrcst1-ebeln

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                                 ebelp = l_s_icctrcst1-ebelp.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        if sy-subrc ne 0 and l_s_icctrcst1-rocancel = ‘X’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>**** SELECT FROM THE CDHDR TABLE FOR THE DELTA RECORD****

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>          refresh it_cdhdr. clear it_cdhdr.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>          select * from cdhdr into table it_cdhdr

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                   where

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                     objectid = l_s_icctrcst1-ebeln

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                     and objectclas = ‘EINKBELEG’

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                     AND ( udate > it_timestamp-zdate or

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                         (  udate = it_timestamp-zdate

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                         and utime > it_timestamp-ztime ) ).

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>**** IF NO CHANGE RECORDS ARE FOUND , THE ORIGINAL LOGIC IS FOLLOWED FOR

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* THE CUSTOM FIELD.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>          if sy-subrc = 0.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>*** CHECK FOR THE LINE ITEM RECORD CHANGES IN THE CDPOS TABLE ****

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* ‘800’ is the client value hardcoded below.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>         concatenate ‘800’ l_s_icctrcst1-ebeln l_s_icctrcst1-ebelp into

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                                  tabkey.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>**** GET ALL THE RECORDS FROM THE CDPOS TABLE ****

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            refresh it_cdpos. clear it_cdpos.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            loop at it_cdhdr.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>              select * from cdpos into it_cdpos where

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                     changenr = it_cdhdr-changenr and tabkey = tabkey.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                it_cdpos-utime = it_cdhdr-utime.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                it_cdpos-udate = it_cdhdr-udate.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                append it_cdpos.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>              endselect.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            endloop.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            describe table it_cdpos lines sy-tfill.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>****IF NO RECORDS ARE PRESENT FOR THAT LINE ITEM WE SET TIME MARKER TO

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>****EARLIEST TIME (OR INITIAL). This time marker is to be used as the

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* starting point since when we are going to look for changes in the

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* change document tables for the custom field KOPPRCTR.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            ltime = ‘000000’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            ldate = ‘10000101’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            if sy-tfill <> 0.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>              sort it_cdpos by udate utime.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>              loop at it_cdpos where fname <> ‘KOPPRCTR’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                ltime = it_cdpos-utime.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                ldate = it_cdpos-udate.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>              endloop.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            endif.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* Find the extraction run timestamp when this po-item was extracted last

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            select * from ztimestamp into table it_timestamp

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                     where zdatasource = ‘2LIS_02_ITM’ and

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                          (  zdate > ldate or

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                            ( zdate = ldate and ztime > ltime ) ).

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            sort it_timestamp descending by zdate ztime.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            read table it_timestamp index 1.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* Find the first change to KOPPRCTR field since last time it was

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>* extracted by BW.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            loop at it_cdpos where ( udate > it_timestamp-zdate

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                                  or ( udate = it_timestamp-zdate and

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                                       utime > it_timestamp-ztime ) ).

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>              if it_cdpos-fname = ‘KOPPRCTR’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                logic_flag = ‘1’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                w_value = it_cdpos-value_old.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                exit.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>              endif.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>            endloop.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>          endif.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        endif.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>**** THE ORIGINAL LOGIC TO UPDATE THE C_T_DATA INTERNAL TABLE ****

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        select single * from ekpo where ebeln = l_s_icctrcst1-ebeln

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>                                    and ebelp = l_s_icctrcst1-ebelp.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        if logic_flag = ‘0’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>          l_s_icctrcst1-zkopprctr   = ekpo-kopprctr.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        else.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>          l_s_icctrcst1-zkopprctr   = w_value.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>          move l_s_icctrcst1-ebeln to itab-ebeln.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>          move l_s_icctrcst1-ebelp to itab-ebelp.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>          append itab.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        endif.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        l_s_icctrcst1-zkocapvalue = ekpo-kocapvalue.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        modify c_t_data from l_s_icctrcst1.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      endloop.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>     append l_s_icctrcst1 to c_t_data.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>*************************************************************

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      get time.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      clear it_timestamp.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      refresh it_timestamp.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      it_timestamp-ztime       = sy-uzeit.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      it_timestamp-zdate       = sy-datum.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      it_timestamp-zdatasource = ‘2LIS_02_ITM’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      append it_timestamp.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      if sy-tcode <> ‘RSA3’.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>        insert ztimestamp from table it_timestamp.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>      endif.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>    endif.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’>Endcase.

8.0pt; font-family:”Arial monospaced for SAP”;color:black’> 

1.7.0pt’>        Whenever the delta of new record is present for the line item record , the customized field is updated with the new record.

 

2.7.0pt’>        When any cancellation record is updated in the delta queue, for that line item record, the before image has the earliest value after the last delta extraction. The entire intermediate deltas for the customized field are lost. The latest value is reflected in the updated delta record.

 

3.7.0pt’>        If the delta occurs only in the customized field of the line item, the delta for that line item would not be captured until the time , there is a change in the standard line item record. In that case the earliest value will be captured for the cancellation record and the latest for the update record.

 

 

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. GVC Babu
    Custom Fields in standard extractors – making a mixed marriage work – part 1_1 & 1_2.

    Realy good One.
    It is having screen shots then look more detailed.

    (0) 

Leave a Reply