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.
1.注意:
在HANA STUDIO创建ABAP 程序时,有两个可选的创建 “ABAP Program”,不能选择错了图中,必须要选择Source Code Library 下的 ABAP Program ,才是正确的,而选择Others下的 ABAP Program ,是错误的,选择错误时,会发现创建的程序在SE38中找不到。也就修改不了源代码,具体这个错误的内容是做什么用不不太了解。

1.1.1.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.
在开发ABAP程序时,可以使用 Eclipse ,也可以使用HANA STUDIO,我在操作时,使用的是HANA STUDIO,据说, Eclipse 的SAP扩展插件,以后SAP公司不要进行升级更新了,所以建议大家还是使用HANA STUDIO,进行例子中的CDS,及ABAP程序开发。
例子中需要使用到,前面创建的CDS,如你不知如何创建CDS,请参看:
1.1.2.Step-by-Step Procedure
1. Create an ABAP program/report.

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

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.

4. 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.
1.1.2.1.1.Syntax: SELECT * FROM <cds_view_name>.
1 2 3 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
*&---------------------------------------------------------------------* *& Report zdemo_cds_report *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zdemo_cds_report. ************************************************ * OPEN SQL statement to access the CDS View * ************************************************ *SELECT * FROM ztest02 INTO TABLE @DATA(lt_data). ************************************************ * CDS View in ABAP ALV Report * ************************************************ TRY . DATA IV_CDS_VIEW_NAME TYPE DBTABL. DATA IO_GUI_CONTAINER TYPE REF TO CL_GUI_CONTAINER. DATA IO_CALC_FIELD_HANDLER TYPE REF TO IF_SALV_IDA_CALC_FIELD_HANDLER. DATA RO_ALV_GUI_TABLE_IDA TYPE REF TO IF_SALV_GUI_TABLE_IDA. IV_CDS_VIEW_NAME = 'ZTEST01'. ro_alv_gui_table_ida = cl_salv_gui_table_ida=>create_for_cds_view( iv_cds_view_name = iv_cds_view_name io_gui_container = io_gui_container io_calc_field_handler = io_calc_field_handler ). * * CATCH CX_SALV_DB_CONNECTION INTO DATA(LO_SALV_DB_CONNECTION). " * CATCH CX_SALV_DB_TABLE_NOT_SUPPORTED INTO DATA(LO_SALV_DB_TABLE_NOT_SUPPORTED). " * CATCH CX_SALV_IDA_CONTRACT_VIOLATION INTO DATA(LO_SALV_IDA_CONTRACT_VIOLATION). * CATCH CX_SALV_FUNCTION_NOT_SUPPORTED INTO DATA(LO_SALV_FUNTION_NOT_SUPPORTED). * * CLEANUP. * IF LO_SALV_DB_CONNECTION IS BOUND. * CLEAR:LO_SALV_DB_CONNECTION. * ENDIF. * * IF LO_SALV_DB_TABLE_NOT_SUPPORTED IS BOUND. * CLEAR:LO_SALV_DB_TABLE_NOT_SUPPORTED. * ENDIF. * * IF LO_SALV_IDA_CONTRACT_VIOLATION IS BOUND. * CLEAR:LO_SALV_IDA_CONTRACT_VIOLATION. * ENDIF. * * IF LO_SALV_FUNTION_NOT_SUPPORTED IS BOUND . * CLEAR:LO_SALV_FUNTION_NOT_SUPPORTED. * ENDIF. ENDTRY. IF ro_alv_gui_table_ida IS NOT INITIAL . ro_alv_gui_table_ida->fullscreen( )->display( ). ENDIF. |
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.
6. Execute the ABAP report and you should see the ALV output like below

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.
在这个程序中,是最简单的直接以CDS的内容为数据源,直接ALV显示出来,
事实上也是可以对CDS数据源进行WHERE查询的,并对ALV输入的格式做处理,细节后面文章再做研究。