Monday, February 24, 2020

Using CDS Parameter view in ALV Report


Using CDS Parameter view in ALV  Report:

So let us now calling CDS in our ALV Report .
*&---------------------------------------------------------------------*
*& Report  ZSD_CDS_REPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSD_CDS_REPORT.
TABLES vbrk.
*--------------------------DATA DECLARATION----------------------------*
DATAi_test 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.

* Select data using CDS View with Parameter
PERFORM sub_get_data_from_cds.

*&---------------------------------------------------------------------*
*& END OF SELECTION.
*&---------------------------------------------------------------------*
END-OF-SELECTION.

* Display data
PERFORM sub_display_data.

*&---------------------------------------------------------------------*
*& SUB ROUTINES
*&---------------------------------------------------------------------*

FORM sub_get_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_cdsP_VBELN_LOW @p_low ,P_VBELN_HIGH @p_high )  INTO TABLE @i_test.

ENDFORM.

FORM sub_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 i_test IS NOT INITIAL.
TRY.
* Factory Method
cl_salv_table=>factoryIMPORTING r_salv_table lr_alv
CHANGING t_table i_test ).

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_allabap_true ).

lr_display lr_alv->get_display_settings).

lr_display->set_striped_patterncl_salv_display_settings=>true ).

lr_display->set_list_headertext-001 ).

* Actual Diplay
lr_alv->display).

ELSE.
MESSAGE 'No data found' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.

ENDFORM. 


Screenshots : 


if you run the report O/P will be :