How to call ABAP CDS Views in ABAP report on HANA

1
17413

How to call ABAP CDS Views in ABAP report on HANA :-

[adsenseyu2]

Hello everyone, In this ABAP on HANA/ABAP In Eclipse tutorial we will learn how to call ABAP CDS Views in ABAP report on HANA. The abbreviation for CDS is Core Data Services.To know about ABAP CDS click here.

Prerequisites

  • You have installed Eclipse IDE( Kepler/Juno version )on your local machine.
  • You have installed ABAP Development Tools in Eclipse IDE.
  • You have access to ABAP Netweaver 7.4 on HANA.
  • You have created ABAP Project in eclipse to connect to ABAP Netweaver 7.4 system.Click here to know how to create ABAP Project.
  • You have already created ABAP CDS View.

Step-by-Step Procedure

1. Create an ABAP program/report.

New ABAP Program

2. In the New ABAP Program window, enter Name and Description and hit Next.

Create an ABAP Program

3. In the Selection of Transport Request window, choose the transport request. As we are saving the program in $TMP package in our case no transport request is required.Click on Finish.

Selection of Transport Requestt4. To call an ABAP CDS view you can use Open SQL statements to get the data.Sample ABAP code snippet to call a CDS will look like below.

Syntax: SELECT * FROM <cds_view_name>.
SELECT * FROM ZCDS_DEMO_EXAMPLE1 
         INTO TABLE @DATA(lt_data).

 

But in this demo example we will use the CDS View to create an ABAP ALV report.Copy and paste the below code in the ABAP program.

************************************************
*  OPEN SQL statement to access the CDS View   *
************************************************
SELECT * FROM ZCDS_DEMO_EXAMPLE1 INTO TABLE @DATA(lt_data).

************************************************
*       CDS View in ABAP ALV Report            *
************************************************
DATA: lo_alv TYPE REF TO if_salv_gui_table_ida.

cl_salv_gui_table_ida=>create(
  EXPORTING
    iv_table_name         = 'ZV_DEMO_01'    "Name of CDS View name
  RECEIVING
    ro_alv_gui_table_ida  =  lo_alv  
).
*  CATCH cx_salv_db_connection.    "
*  CATCH cx_salv_db_table_not_supported.    "
*  CATCH cx_salv_ida_contract_violation.    "

* Display ALV
lo_alv->FULLSCREEN( )->display( )

 

5. Lets look at the code, we have used CDS view name created in our previous tutorial to the ALV with IDA class CL_SALV_GUI_TABLE_IDA as a data source to the ALV. Save and activate the ABAP program.

[adsenseyu1]

6. Execute the ABAP report and you should see the ALV output like below.

ALV Output

You successfully learned how to call ABAP CDS Views in ABAP report on HANA. Please stay tuned to us for ABAP on HANA/ABAP in Eclipse tutorials.Please feel free to comment and let us know your feedback. You feedback will keep us alive.

Thank you.