Mittwoch, 16. Februar 2011

Create Generic Datasource using Function Module and Timestamps

You can create a generic datasource using a function module.

For delta functionality you need a delta field. Some tables like VBAK (Sales Document: Header Data) don't have a timestamp field for creation/change that we can use as a unique delta field but have separate fields for creation date (ERDAT), creation time (ERZET) and change date (AEDAT). To get the data of the VBAK table by using delta functionality we will create a generic datasource using a custom function module which implements the necessary logic.

We will create an extraction structure that has a timestamp field and we will use this field to implement the delta functionality. In this blog I will explain this concept.

There are two template function modules that one can copy and use:

- RSAX_BIW_GET_DATA_SIMPLE: A function module with simple interface for Full Load with no support of delta loads.

- RSAX_BIW_GET_DATA: : A function module with complete interface that supports Delta Load. We will use this FM.

Step 1: Create an Extract Structure

- Go to transaction SE11 and create a new structure ZZVBAK.





- Insert the table VBAK as an include into the structure.






- Add a field ZTMSTMP (Data element: TZNTSTMPS, it is of datatype DEC with Length 15). This field will hold the timestamp and allow us to use the extraction for delta purposes.



- Save and activate the structure. This structure will be our extract structure for the datasource.

Step 2: Create the function module:

- Go to transaction code se80 and copy the function group RSAX to the new function group Z_RSAX and copy the function module RSAX_BIW_GET_DATA to Z_RSAX_BIW_GET_DATA_VBAK . Be sure to copy and activate all the related objects (interfaces, datatypes etc.).





- Go to SE37 and Open your FM Z_RSAX_BIW_GET_DATA_VBAK to edit. In TABLES tab set the parameter E_T_DATA to associated type ZZVBAK.



- Click Here to find the ABAP code and copy and paste it into the source code pane.

- Save and activate the function module.

Step 3: Create the Datasource:

- Go to transaction RSO2 and create a new datasource for transaction data and name it to ZDSVBAK.



- Set the Application component and the description texts.



- Click on Extraction by FM. Enter the name of the function module Z_RSAX_BIW_GET_DATA_VBAK and the extract structure ZZVBAK.



- Click on Generic Delta. Select the timestamp Field ZTMSTMP and set the option Timestamp.



- Optionally set the Safety Interval Lower Limit. For more Information refer to
SAP HELP.

- Click Save and click Save again. In the following screen you can set the selection fields. The timestamp field is disabled because it will be automatically populated as part of the delta process.



- Now go to transaction RSA2 to see the details of our datasource ZDSVBAK. The Extraction Method is set to F2 (Simple Interface). To change it to F1 (Complete Interface) execute the following ABAP code. (You can go to SE38 and create new report with this ABAP code). Unfortunately this is not possible in the GUI. I don't know why.

REPORT ZABAPDEMO.
UPDATE roosource
SET delta = 'E'
exmethod = 'F1'
WHERE oltpsource = 'ZDSVBAK'.


- Go to RSA2 and check the status of the datasource ZDSVBAK (just to confirm, that it is set to F1).



- This is an optional step: To test the function module go to SE37 and call it two times in succession - one call for Initialization and the second to read data. This is actually not necessary but it's a good way to check, if the function module is basically working well.




- This was the initialization Call. Now the second call to get the data:





- Be sure that the table E_T_DATA contains the data.

Step 4: Go to transaction RSA3 to test the datasource.





- Now the datasource is created and you can use the Xtract DeltaQ component to read it. Be sure to activate it via the activate button.

- The datasource supports the Full and Update Delta mode. To use the Update Delta mode the first call must have the update type C (Delta Initialization). All following calls must have the update type D (Delta Update). The delta process of the datasource can be monitored and maintained in RSA7 (Delta queue).



References:

- SAP Help about Maintaining generic datasources.

- SAP BI Generic Extraction Using a Function Module

- How to Create Generic Delta

- SAP BI Generic Extraction Using a Function Module

7 Kommentare:

  1. Hi Khoder,

    very nice Blog, THX ;) One thing I didn't get is how timestamp is beeing filled. Further I have always error in Extractor checker RSA3... In SE37 everything is fine.

    Cheers, Alex

    AntwortenLöschen
  2. Hi Alex,

    the timestamp will be automatically filled by the sap system.
    If you have an error in RSA3 try to debug the call.

    AntwortenLöschen
  3. Hi Khoder,

    Here in the VBAK table created time does not gets changed when the sales document is changed.
    Now suppose a doument is created
    Documnet no:-D001
    Created date: 2/10/2011
    Ceated time: 10:12:11
    Changed on:

    Now this documnet is changed.
    Documnet no:-D001
    Created date: 2/10/2011
    Ceated time: 10:12:11
    Changed on:6/10/2011

    here as we can see the change time remains same,
    and the ABAP code brings delta based on created time also, hence it will bring delta for only particular date, not based on time.

    How will the timestamp work?

    AntwortenLöschen
  4. Hi.

    I want inform you that your SQL contraint is not correct. If you initialize the delta one minute after midnight you will have any rows, that are created sometimes between midnights and 1 minute after minute for every day. You have to do it like this, to get the whole data between dates.

    ( vbrp~erdat = startdate AND vbrp~erzet >= starttime )
    OR ( vbrp~erdat = enddate AND vbrp~erzet <= endtime )
    OR ( vbrp~erdat > startdate AND vbrp~erdat < enddate )
    OR ( vbrp~aedat >= startdate AND vbrp~aedat <= enddate )

    AntwortenLöschen
  5. Thank-you for illustrating the steps. I find myself creating a generic delta extractor every few years and your blog helps to refresh my memory. :)

    AntwortenLöschen
  6. Thank you Nils for the comment

    AntwortenLöschen
  7. Hi Khoder
    thanks for your explanations.
    However, it is possible to use RSAX_BIW_GET_DATA_SIMPLE for delta uploads.
    Just create your selection in open cursor statement appropriate; select only deltas with timestamp.

    See also:
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/30f1a423-02ae-2e10-bd85-bde64e61fe7b?overridelayout=true

    AntwortenLöschen