Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Summary

This document presents a way to extract delta loads from RESB table.  Since this table has been known for only working with full generic datasources, this article can come in handy for those who need this data in BW.

Introduction

MM RESB table has been known for accepting full data load only.  Many have wondered and looked for a way to create a delta datasource for this table.  I spent quite some time looking at many forum discussions and searching for a solution to this problem.  And it was only when I stopped to look at BTE events available in ECC that I finally encountered a way to create this delta load.  For those who are still searching for a way to solve this issue, I hope this document comes in handy.

Step by Step Solution

1. Creating Your Datasource. 

First of all it is necessary to create a datasource.  Since we only want data from RESB table, we can create one based on a view of the table, and select only the fields of interest to us.  If you already have a datasource like this that you are using to extract your full load, you can use it for the delta load.  All you will have to do is alter it so that it will start to use a delta queue.

2. Modifying Delta Process Type of Your Datasource.

For this we use an utility program created (Z_CHANGE_DELTA_PROCESS), which can be found in the appendix.  If this program does not already exist in your system, it will need to be installed.  To do this, navigate to tcode SE38 and type in the program name.  Hit the create button, then copy and paste the code in the appendix and activate it.  To modify the delta process type of your datasource, run this program.  You will see two parameters that need to be filled before running the program: the datasource name and the delta process type.  Fill in the name of your datasource and for our solution we will choose AIM as our process type.  Once the parameters have been filled, run the program.  This will update the datasource appropriately.

3. Writing Data to the Delta Queue.

You will need a function module to write the data captured by the BTE events to our delta queue.  For this go to tcode SE37 and create a new function module and give it the name Z_WRITE_TO_QUEUE.  Copy and paste the code in the appendix and activate the function module.

4. Choosing Your BTE Events. 

Now we are ready to start using the BTE events that we need.  In tcode FINF select attribute Z and execute.

From the list that is shown the last 4 events are related to reservations.

5. Creating your Function Modules. 

Now you will have to copy each one of them.  Put the cursor over the first event and click on “sample function module”.  You will be transferred to tcode SE37 where you can copy the function module by clicking on the icon as shown on the picture.

Give it a new description, chose a function group and then press copy.

At this point your function module has been created and you can choose it and click on “change” to modify the code.  All the necessary codes can be found at the end of this document, on the appendix.

Important:  since the structure of your datasource might not be exactly the same as the tables used in the function modules, it is necessary to transfer the data to a structure just like yours before writing it to the delta queue.

In our code the structure used (ZOXRD00062) is exactly the one found in our datasource.  You can find the one used by your datasource by looking up your datasource in tcode RSO2.

Now you will need to repeat the steps above three more times.  All together you will create one function module for event 01000501, one for event 01000504, one for event 01000505 and one for event 01000506.  All codes for each created function module are found in the appendix of this document.

6. Linking your FMs and the BTE Events. 

After creating all function modules needed, go to tcode FIBF.  There you will have to find the path to “Products” “of a customer”, as shown below.

Create one new entry, give it a name and description and flag the active box.

Now a link needs to be created between the chosen BTE events, the product just created, and the function modules.  For that go back to tcode FIBF and find “P/S Modules” “of a customer”, as shown below.

Create four new entries, associating event, product and function module as shown below.

After completing this last step your delta hook is finished.  Now every change made on RESB table can be captured by one of the events.  So now you can go to the BW side, create your init infopackage and test your changes.  Remember to check tcode RSA7 on the ECC side to see if your delta queue was created, and follow the changes recorded in it as you create, modify or delete a reservation.

7. Appendix

i. Report: Z_CHANGE_DELTA_PROCESS

*&---------------------------------------------------------------------*
*& Report  Z_CHANGE_DELTA_PROCESS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT  z_change_delta_process.

PARAMETERS: p_datas TYPE roosource-oltpsource,
            p_deltap TYPE roosource-delta.
TABLES:
  roosource.
DATA: ls_roosource TYPE roosource.

IF p_datas(1) NE 'Z'.
  MESSAGE 'The DataSource needs to begin with ''Z_''.' TYPE 'E'.
ENDIF.
SELECT SINGLE *
  FROM roosource
    INTO ls_roosource
WHERE oltpsource = p_datas
  AND objvers = 'A'.

IF sy-subrc EQ 0.
  ls_roosource-delta = p_deltap.
  UPDATE roosource FROM ls_roosource.
  MESSAGE 'The DataSource has been updated successfully.' TYPE 'I'.
ELSE.
  MESSAGE 'The DataSource entered is not valid, try again.' TYPE 'E'.
ENDIF.


ii. Function module: Z_WRITE_TO_QUEUE

FUNCTION z_write_to_queue.
*"----------------------------------------------------------------------
*"*"Interface local:
*"  IMPORTING
*"     REFERENCE(I_DATASOURCE) TYPE  ROOSOURCE-OLTPSOURCE
*"  TABLES
*"      I_T_DATA OPTIONAL
*"----------------------------------------------------------------------

  TYPE-POOLS:
  sbiwa.
  DATA:   l_exstruct TYPE roosource-exstruct,
          l_initflag TYPE roosprmsc-initstate,
          l_subrc TYPE sy-subrc,
          lr_is_data TYPE REF TO data,
          lr_es_data TYPE REF TO data,
          lr_et_data TYPE REF TO data,
          l_t_fields TYPE sbiwa_t_fields,
          l_t_select TYPE sbiwa_t_select.

  FIELD-SYMBOLS:
  <i_s_data> TYPE ANY,
  <e_s_data> TYPE ANY,
  <e_t_data> TYPE STANDARD TABLE.

* Check to see if Delta initialization has been performed.
  SELECT SINGLE initstate
    FROM roosprmsc
      INTO l_initflag
  WHERE oltpsource = i_datasource
    AND rlogsys NE space
    AND slogsys NE space
    AND initrnr NE space.
* If initialization has taken place continue
  IF sy-subrc EQ 0 AND l_initflag EQ 'X'.
* grab the extraction structure from roosource based on the
* datasource parameter input.
    SELECT SINGLE exstruct
      FROM roosource
        INTO l_exstruct
    WHERE oltpsource = i_datasource
      AND objvers = 'A'.

    CHECK sy-subrc = 0.

    CREATE DATA lr_is_data LIKE LINE OF i_t_data.
    ASSIGN lr_is_data->* TO <i_s_data>.

    CREATE DATA lr_es_data TYPE (l_exstruct).
    ASSIGN lr_es_data->* TO <e_s_data>.

    CREATE DATA lr_et_data TYPE STANDARD TABLE OF (l_exstruct).
    ASSIGN lr_et_data->* TO <e_t_data>.

    LOOP AT i_t_data ASSIGNING <i_s_data>.
      CLEAR <e_s_data>.
      MOVE-CORRESPONDING <i_s_data> TO <e_s_data>.
      INSERT <e_s_data> INTO TABLE <e_t_data>.
    ENDLOOP.

    CALL FUNCTION 'EXIT_SAPLRSAP_001'
      EXPORTING
        i_datasource             = i_datasource
        i_isource                = ''
        i_updmode                = ''
      TABLES
        i_t_select               = l_t_select
        i_t_fields               = l_t_fields
        c_t_data                 = <e_t_data>
      EXCEPTIONS
        rsap_customer_exit_error = 1
        OTHERS                   = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

    CALL FUNCTION 'RSC1_TRFC_QUEUE_WRITE'
      EXPORTING
        i_isource     = i_datasource
        i_no_flush    = 'X'
      IMPORTING
        e_subrc       = l_subrc
      TABLES
        i_t_data      = <e_t_data>
      EXCEPTIONS
        name_too_long = 1
        OTHERS        = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDIF.
ENDFUNCTION.


*---------------------------------------------------------------------*
* FORM abs_type_to_rel_type *
*---------------------------------------------------------------------*
* The purpose of this subroutine is to convert an absolute type *
* name into a relative type name. *
* *
*---------------------------------------------------------------------*
* --> TYPE_NAME *
*---------------------------------------------------------------------*

form abs_type_to_rel_type changing type_name.
data junk(100) type c.

split type_name at '\TYPE=' into junk type_name.

endform. 


iii. Function module: ZBW_BTE_DELTA_CAPTURE_01000501

FUNCTION zbw_bte_delta_capture_01000501.
*"----------------------------------------------------------------------
*"*"Interface local:
*"  IMPORTING
*"     VALUE(CHANGE_RESB) LIKE  T063F-XAENP
*"     VALUE(NEW_RESB) LIKE  T063F-XNEUP
*"  TABLES
*"      XRESB STRUCTURE  RESB
*"      XRESBN STRUCTURE  RESBN
*"----------------------------------------------------------------------
  DATA:
      l_datasource TYPE roosource-oltpsource,
      wa_xresb LIKE LINE OF  xresb,
      wa_xresbn LIKE LINE OF  xresbn,
      vresb TYPE TABLE OF zoxrd00062,
      wa_vresb TYPE zoxrd00062,
      it_resb TYPE TABLE OF resb,
      wa_resb LIKE LINE OF it_resb.

  l_datasource = 'ZF1_RESERVA'.
  IF LINES( xresb[] ) GT 0.
    LOOP AT xresb INTO wa_xresb.
      MOVE-CORRESPONDING  wa_xresb  TO wa_vresb.
      APPEND wa_vresb TO vresb.
    ENDLOOP.
  ENDIF.
  IF LINES( xresbn[] ) GT 0.
    SORT: xresbn BY rsnum rspos.
    SELECT * FROM resb INTO TABLE it_resb
    FOR ALL ENTRIES IN xresbn
    WHERE rsnum = xresbn-rsnum AND
          rspos = xresbn-rspos.
    LOOP AT xresbn INTO wa_xresbn.
      READ TABLE it_resb INTO wa_resb
      WITH KEY  rsnum = wa_xresbn-rsnum
                rspos = wa_xresbn-rspos.
      IF wa_resb IS NOT INITIAL.
        MOVE-CORRESPONDING  wa_resb TO wa_vresb.
        APPEND wa_vresb TO vresb.
      ENDIF.
    ENDLOOP.
  ENDIF.
  CALL FUNCTION 'Z_WRITE_TO_QUEUE'
    EXPORTING
      i_datasource = l_datasource
    TABLES
      i_t_data     = vresb.

ENDFUNCTION. 


iv. Function module: ZBW_BTE_DELTA_CAPTURE_01000504

FUNCTION zbw_bte_delta_capture_01000504.
*"--------------------------------------------------------------------
*"*"Interface local:
*"  TABLES
*"      XRESB STRUCTURE  RESB
*"      XREUL STRUCTURE  REUL
*"--------------------------------------------------------------------
  DATA:
      l_datasource TYPE roosource-oltpsource,
      wa_xresb LIKE LINE OF  xresb,
      wa_xreul LIKE LINE OF  xreul,
      vresb TYPE TABLE OF zoxrd00062,
      wa_vresb TYPE zoxrd00062,
      it_resb TYPE TABLE OF resb,
      wa_resb LIKE LINE OF it_resb.

  l_datasource = 'ZF1_RESERVA'.
  IF LINES( xresb[] ) GT 0.
    LOOP AT xresb INTO wa_xresb.
      MOVE-CORRESPONDING  wa_xresb  TO wa_vresb.
      APPEND wa_vresb TO vresb.
    ENDLOOP.
  ENDIF.
  IF LINES( xreul[] ) GT 0.
    SORT: xreul BY rsnum rspos.
    SELECT * FROM resb INTO TABLE it_resb
    FOR ALL ENTRIES IN xreul
    WHERE rsnum = xreul-rsnum AND
          rspos = xreul-rspos.
    LOOP AT xreul INTO wa_xreul.
      READ TABLE it_resb INTO wa_resb
      WITH KEY  rsnum = wa_xreul-rsnum
                rspos = wa_xreul-rspos.
      IF wa_resb IS NOT INITIAL.
        MOVE-CORRESPONDING  wa_resb TO wa_vresb.
        APPEND wa_vresb TO vresb.
      ENDIF.
    ENDLOOP.
  ENDIF.

  CALL FUNCTION 'Z_WRITE_TO_QUEUE'
    EXPORTING
      i_datasource = l_datasource
    TABLES
      i_t_data     = vresb.

ENDFUNCTION. 


v. Function module: ZBW_BTE_DELTA_CAPTURE_01000505

FUNCTION zbw_bte_delta_capture_01000505.
*"----------------------------------------------------------------------
*"*"Interface local:
*"  TABLES
*"      XREUL STRUCTURE  REUL
*"      X_RESB STRUCTURE  RESB
*"----------------------------------------------------------------------
DATA:
    l_datasource TYPE roosource-oltpsource,
    wa_x_resb LIKE LINE OF  x_resb,
    wa_xreul LIKE LINE OF  xreul,
    vresb TYPE TABLE OF zoxrd00062,
    wa_vresb TYPE zoxrd00062,
    it_resb TYPE TABLE OF resb,
    wa_resb LIKE LINE OF it_resb.

  l_datasource = 'ZF1_RESERVA'.
  IF LINES( x_resb[] ) GT 0.
    LOOP AT x_resb INTO wa_x_resb.
      MOVE-CORRESPONDING  wa_x_resb  TO wa_vresb.
      APPEND wa_vresb TO vresb.
    ENDLOOP.
  ENDIF.
  IF LINES( xreul[] ) GT 0.
    SORT: xreul BY rsnum rspos.
    SELECT * FROM resb INTO TABLE it_resb
    FOR ALL ENTRIES IN xreul
    WHERE rsnum = xreul-rsnum AND
          rspos = xreul-rspos.
    LOOP AT xreul INTO wa_xreul.
      READ TABLE it_resb INTO wa_resb
      WITH KEY  rsnum = wa_xreul-rsnum
                rspos = wa_xreul-rspos.
      IF wa_resb IS NOT INITIAL.
        MOVE-CORRESPONDING  wa_resb TO wa_vresb.
        APPEND wa_vresb TO vresb.
      ENDIF.
    ENDLOOP.
  ENDIF.
  CALL FUNCTION 'Z_WRITE_TO_QUEUE'
    EXPORTING
      i_datasource = l_datasource
    TABLES
      i_t_data     = vresb.
ENDFUNCTION. 


vi. Function module: ZBW_BTE_DELTA_CAPTURE_01000506

FUNCTION ZBW_BTE_DELTA_CAPTURE_01000506.
*"--------------------------------------------------------------------
*"*"Interface local:
*"  TABLES
*"      XMRES STRUCTURE  SMRES
*"--------------------------------------------------------------------
  DATA:
      l_datasource TYPE roosource-oltpsource,
      wa_xmres LIKE LINE OF  xmres,
      vresb TYPE TABLE OF zoxrd00062,
      wa_vresb TYPE zoxrd00062,
      it_resb TYPE TABLE OF resb,
      wa_resb LIKE LINE OF it_resb.

  l_datasource = 'ZF1_RESERVA'.
  IF LINES( xmres[] ) GT 0.
    SORT: xmres BY rsnum rspos.
    SELECT * FROM resb INTO TABLE it_resb
    FOR ALL ENTRIES IN xmres
    WHERE rsnum = xmres-rsnum AND
          rspos = xmres-rspos.
    LOOP AT xmres INTO wa_xmres.
      READ TABLE it_resb INTO wa_resb
      WITH KEY  rsnum = wa_xmres-rsnum
                rspos = wa_xmres-rspos.
      IF wa_resb IS NOT INITIAL.
      MOVE-CORRESPONDING  wa_resb  TO wa_vresb.
      APPEND wa_vresb TO vresb.
      ENDIF.
    ENDLOOP.
    CALL FUNCTION 'Z_WRITE_TO_QUEUE'
      EXPORTING
        i_datasource = l_datasource
      TABLES
        i_t_data     = vresb.
  ENDIF.
ENDFUNCTION.

8. Related Content

Generic Data Sources which use the Delta Queue (How to).pdf
Usage of Business Transaction Events (How to).pdf
Creation of Events via Business Transaction Events

3 Comments
Labels in this area