Skip to Content
Personal Insights
Author's profile photo Prem Shanker

BAdI Implementation in ABAP on HANA for BW Extractors


BAdI Enhancement for BW Extractors in S/4 HANA system.

The Logic for the enhancement of BW datasource is traditionally written in ABAP Function Module Exit or ABAP BAdI. But, now with S/4 HANA, BAdI is the default place to write the logic for Enhancement (Function Module Exit is still available but might not be going forward).

With S/4 HANA we have a flexibility to write logic in HANA Optimized ABAP code using new coding techniques (New Open SQL syntax).

The new HANA approach is to push our code to the database layer where all the data resides, do the calculations at database layer and bring only the relevant records to presentation layer.

This blog gives approach from a BW Consultant Perspective on BAdI development for BW extractor in ABAP on HANA



In our Project we had requirement to enhance the 0FI_ACDOCA_10 extractors in S/4 HANA (Central Finance) System.

We were not be using the traditional ABAP as we can leverage more power from ABAP on HANA.



To start the development we have to know the fields which are going to be enhanced and the base table for that fields. In our example we have taken NETDT (Net Due Date) field from ACDOCA table itself. (This field is not present in extractor itself and hence we are doing Append in Structure)

Step1: Append the Structure of Datasource 0FI_ACDOCA_10

Go to the Eclipse ABAP Perspective and find extract structure for the datasource 0FI_ACDOCA_10.

Then create an Append structure and provide the field details.

The Structure ZAFINS_ACDOCA_BW is created for single field ZZNETDT.


When the structure is created first, the Line number 2 will say: #NOT_EXTENSIBLE, change this to :#EXTENSIBLE_CHARACTER_NUMERIC then only it will allow to extend the structure

Once the Structure is enhanced, a small icon will appear in the left of define structure, that Icon is enhancement indicator/append indicator to see if we have any extension to this structure.

The Structure can be seen by scrolling on the icon.

If required, we can also switch back to SAP GUI familiar screen by right clicking in the blank space and navigate to SAP GUI.

Now the Extract structure of the datasource is enhanced, next Step is create a Class Implementation.

Step 2: Create a Class and Method in SE18/19 – GUI


Step 3: Write the logic to populate the data in the Appended field in ABAP Perspective..

The logic is written in new HANA Optimized ABAP code, this code will do the calculation in the database layer result in performance improvement.


BAdI Implementation Code:

Below is the Code for BAdI written in Eclipse:-


  Case i_datasource.
        WHEN '0FI_ACDOCA_10'.

     LOOP AT C_T_DATA ASSIGNING <l_s_data>.
       select from ACDOCA AS a
       FIELDS a~netdt
        WHERE a~rldnr  = @<l_s_data>-rldnr
         and  a~rbukrs = @<l_s_data>-rbukrs
         and  a~gjahr  = @<l_s_data>-gjahr
         and  a~belnr  = @<l_s_data>-belnr
         and  a~docln  = @<l_s_data>-docln
        INTO ( @<l_s_data>-zznetdt ).

Explanation of Code:-

In this new approach of coding, the variables have a prefix @, this a new annotation based coding which can also be seen in ABAP CDS view.

This is a simple level of code where select statement in written under loop. In normal ABAP it will be an expensive statement, but with ABAP on HANA this will work pretty fast.

But if you are dealing with a more than 100 millions or billions of records, then this logic can also start giving performance impact.

How can we optimize this:-

In normal ABAP we use to select the relevant records from required table with respect of all the entries present in our C_T_DATA, and then we loop the C_T_DATA and read the internal table to populate the newly enhance field .

“For All Entries” statement is nothing but an inner-join between the two tables.

Hence, please find the optimized code below:-

types: begin of ls_acdoca,

         rldnr type fins_ledger,
         rbukrs type bukrs,
         gjahr type gjahr,
         belnr type belnr_d,
         docln type docln6,
         netdt type netdt,

       end of ls_acdoca.

  DATA: it_acdoca TYPE STANDARD TABLE OF ls_acdoca,
         wa_data TYPE FINS_ACDOCA_BW.
  FIELD-SYMBOLS: <fs_acdoca> type ls_acdoca,
                 <l_s_data> TYPE FINS_ACDOCA_BW.

sort SOURCE_DATA BY rldnr rbukrs gjahr belnr docln.

  Case i_datasource.
        WHEN '0FI_ACDOCA_10'.

IF C_T_DATA is not initial.

      select a~rldnr, a~rbukrs, a~gjahr, a~belnr, a~docln, a~netdt
      from acdoca as a
      ON  a~rldnr  = b~rldnr
      AND a~rbukrs = b~rbukrs
      AND a~gjahr  = b~gjahr
      AND a~belnr  = b~belnr
      AND a~docln  = b~docln
      into TABLE @it_acdoca.

SORT it_acdoca BY rldnr rbukrs gjahr belnr docln.

     READ TABLE it_acdoca
     ASSIGNING <fs_acdoca>
     with key rldnr  = <l_s_data>-rldnr
              rbukrs = <l_s_data>-rbukrs
              gjahr  = <l_s_data>-gjahr
              belnr  = <l_s_data>-belnr
              docln  = <l_s_data>-docln.
        if sy-subrc = 0.
             <l_s_data>-zznetdt = <fs_acdoca>-netdt.

    clear SOURCE_DATA.



Explanation of Code:

Required fields are selected from the table ACDOCA with all entries in the C_T_DATA on Key Fields of the table.

As discussed above “For All Entries” statement is nothing but an inner-join between the two tables.

Hence you can see inner join between table ACDOCA and SOURCE_DATA (Copied from C_T_DATA) in the code. It will select only required records from ACDOCA table and stores in internal table. The internal table will read when looping the C_T_DATA to populate the field ZZNETDT.

This blogs gives the basics of coding done in ABAP on HANA approach from a BW Consultant Perspective.

Result of the Extractor

The field ZZNETDT is populated as shown in the screenshot



Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Hitesh Jena
      Hitesh Jena

      Hi Prem,


      What impact will it have on the real time streaming capability of the Data source?