Create a Simple ABAP CDS View in ADT

   www.simplilearnings.com

 

Create Simple ABAP CDS View in ADT and call in ABAP Program

          Create a CDS view to select data from customer open item Table i.e BSID, with code push down concept, if debit/credit indicator = ‘H’ , then display the amount with –ve sign.


      Normal ABAP Program

     select BUKRS KUNNR UMSKS UMSKZ AUGDT AUGBL ZUONR GJAHR BELNR BUZEI SHKZG DMBTR

    from BSID into table @Data(gt_bsid) where xxxxxx

    loop at gt_bsid into data(gs_bsid) where SHKZG = ‘H’.

                 gs_bsid-dmbtr = gs_bsid-dmbtr * ( -1 ).

                 modify gt_bsid from gs_bsid transporting dmbtr.

    clear : gs_bsid.

    endloop.

                  display output

Issue with normal abap program : As after selecting data from database , to make the value of field DMBTR as -ve if debit/credit indicator is 'H' , we need to make a loop, for small data set upto 500 records it is ok, but with large data set like more than 100000, due to loop, report output will be slow, to improve performance we can make use of CDS view with code push down concept and we can call the CDS view in ABAP program, or any class or smartforms or to create the ODATA service based on our requirement.

Create CDS view in ADT






Enter the SQL View name, max. 26 length, after activation of CDS view , we can search this view in SAP SE11 Transaction code, in the data source name enter the table name, from where we want to select the data.


After adding the code logic, save, check and activate.


@AbapCatalog.sqlViewName: 'ZSL_SQL_FI_CDS1'
@AbapCatalog.compiler.CompareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS View for FI BSID Table'
define view ZSL_FI_CDS1 as select from bsid {

bukrs,
kunnr,
umsks,
umskz,
augdt,
augbl,
zuonr,
gjahr,
belnr,
buzei,
shkzg,
case shkzg
when 'H' then  ( dmbtr * -1 )
else dmbtr
end as dmbtr1
  
}

Check the new generated view in SE11







We can see the record with debit/credit indicator 'H 'with value dmbtr as -ve,   
next we can directly use this view in ABAP program, avoiding use of loop..

REPORT ZFI_SQL_BSID.

tables BSID.

SELECTION-SCREEN begin of block b1 WITH FRAME TITLE text-001.
  
select-OPTIONS s_kunnr for bsid-kunnr.
SELECTION-SCREEN end of BLOCK b1.

START-OF-SELECTION.


   
select from ZSL_SQL_FI_CDS1 into TABLE @data(gt_listWHERE kunnr in @s_kunnr.


   cl_demo_output
=>displaygt_list ).

end-of-SELECTION. 




We can  see the output as required.

        Advantage of using CDS view for this requirement

·        Code push down loop removed

·        We can re-use the CDS view based on requirement at multiple places like, any other program, FM Class, somatoforms etc.

·        We can directly create the Odata service through CDS view annotations, to 







Post a Comment

2 Comments

  1. Excellent presentation..its very easy to understand

    ReplyDelete
  2. How come the view name in SE11 is ZSL_SQL_FI_CDS1 when the view is created in CDS as ZSL_FI_CDS1 ?

    ReplyDelete

Total Pageviews