Calling CDS View in Program:
CDS View Code :
CDS View Code :
@AbapCatalog.sqlViewName: 'ZZTEST_cds'
@AbapCatalog.compiler.CompareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS'
define view ZTEST_cds
with parameters p_vbeln_low : vbeln,
p_vbeln_high: vbeln
as select from vbrk
join vbrp on vbrp.vbeln = vbrk.vbeln
{
vbrk.vbeln,
vbrp.posnr,
vbrk.vkorg,
vbrp.netwr,
vbrp.matnr
}
where vbrk.vbeln = :p_vbeln_low or vbrk.vbeln between :p_vbeln_low
and :p_vbeln_high and vkorg = '1000';
---------------------------------------------------------------------
Report Source Code : Simply copy& paste and run it in se38.
*&---------------------------------------------------------------------*
*& Report ZSD_CDS_REPORT
*& Created By : Sourav
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSD_CDS_REPORT.
TABLES : vbrk.
*--------------------------DATA DECLARATION----------------------------*
DATA: iT_CDS TYPE STANDARD TABLE OF ZTEST_cds. " CDS Entity View
*&---------------------------------------------------------------------*
*&SELECTION SCREEN
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK a01 WITH FRAME TITLE text-001.
SELECT-OPTIONS : S_VBELN FOR Vbrk-VBELN.
SELECTION-SCREEN END OF BLOCK a01.
*&---------------------------------------------------------------------*
*& START OF SELECTION.
*&---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM getting_data_from_cds.
PERFORM display_data.
*&---------------------------------------------------------------------*
*& SUB ROUTINES
*&---------------------------------------------------------------------*
FORM getting_data_from_cds.
* Fetch from CDS Entity View
data : p_low TYPE vbeln.
data : p_high TYPE vbeln.
p_low = s_vbeln-low.
p_high = s_vbeln-high.
break sap_abap2.
SELECT * FROM ZTEST_cds( P_VBELN_LOW = @p_low ,P_VBELN_HIGH = @p_high ) INTO TABLE @it_cds.
ENDFORM.
FORM display_data.
DATA:
lr_functions TYPE REF TO cl_salv_functions, " ALV Functions
lr_alv TYPE REF TO cl_salv_table, " ALV Functions
lr_display TYPE REF TO cl_salv_display_settings, " ALV Functions
lv_salv_msg TYPE REF TO cx_salv_msg. "ALV Functions.
* Display the final internal table in ALV
IF it_cds IS NOT INITIAL.
TRY.
* Factory Method
cl_salv_table=>factory( IMPORTING r_salv_table = lr_alv
CHANGING t_table = it_cds ).
CATCH cx_salv_msg INTO lv_salv_msg.
MESSAGE lv_salv_msg TYPE 'E'.
ENDTRY.
* Self explanatory
lr_functions = lr_alv->get_functions( ).
lr_functions->set_all( abap_true ).
lr_display = lr_alv->get_display_settings( ).
lr_display->set_striped_pattern( cl_salv_display_settings=>true ).
lr_display->set_list_header( text-001 ).
* Actual Diplay
lr_alv->display( ).
ELSE.
MESSAGE 'No data found' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.