Friday, 27 October 2017

How fast is ABAP Core Data Service(CDS)?

How fast is ABAP Core Data Service (CDS)?  This is one of the frequent question raised by technical consultants after any ABAP CDS sessions. We can demonstrate speed of ABAP CDS through below simple approach, I have written same requirement in two different methodologies. Business requirement is to obtain the material number from MARA table and material description from MAKT table. Material number in final result should be without preceding zero’s.

We will approach above requirement through two methods. Traditional ABAP Code and through ABAP Core Data Services (CDS).

Approach 1: Traditional ABAP Code approach

In Traditional ABAP Code approach we are joining above 2 tables and bringing the data to application layer. Then we will loop through above obtained result table and remove the preceding zero’s using standard function module.

report ytest_mara_cds.
tables: mara, makt.
types : begin of ty_mara,
          matnr type matnr,
          maktx type makt-maktx,
        end of ty_mara.
data : it_mara type table of ty_mara,
       wa_mara type ty_mara.
select mr~matnr
       mk~maktx from mara as mr
       inner join makt as mk
                 on mr~matnr = mk~matnr
       into table it_mara
       where mk~spras = 'E'.
loop at it_mara into wa_mara.
  call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
    exporting
      input         = wa_mara-matnr
   IMPORTING
     OUTPUT        = wa_mara-matnr
            .
  modify it_mara from wa_mara.
  clear wa_mara.
endloop.

Now run the transaction SAT to check the runtime analysis.

SAP ABAP Core Data Service, SAP Development, SAP Guides, SAP ABAP Materials

From above analysis , it took 174047 micro seconds which is equal to 0.17 sec.

Approach 2: Code the same requirement using ABAP Core Data Services(CDS).

@AbapCatalog.sqlViewName: 'ZXSHIMAT'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Material View'
define view ZXSH_I_MATERIAL
as select from mara
association [0..1] to makt as _makt
    on mara.matnr = _makt.matnr {
key   LTRIM( matnr, '0') as Material_Code,
    mtart as Material_Type
}
where
_makt.spras = 'E'

Call this CDS view in ABAP.

report ytest_mara_cds.

tables: mara, makt.

types : begin of ty_mara,
          matnr type matnr,
          maktx type makt-maktx,
        end of ty_mara.
data : it_mara type table of ty_mara,
       wa_mara type ty_mara.

select * from ZXSHIMAT INTO TABLE @it_mara.

Now run the transaction SAT to check the runtime analysis.

SAP ABAP Core Data Service, SAP Development, SAP Guides, SAP ABAP Materials

From above analysis , it took 87895 micro seconds which is equal to 0.088 sec.

Conclusion: ABAP CDS approach took only half of the traditional approach execution time.

SAP ABAP Core Data Service, SAP Development, SAP Guides, SAP ABAP Materials

1 comment:

  1. Nice blog..! I really loved reading through this article... Thanks for sharing such an amazing post with us and keep blogging...
    sap consulting services in usa

    ReplyDelete