Skip to Content
Author's profile photo Former Member

CDS ALV report with selection criteria

In continuation of previous example (see CDS ALV report in seconds with 7.5 SP 03), this ALV report development will show CDS functionality of 1) selection screen criteria and 2) maximum display size threshold.

See SAP classes CL_SALV_IDA_* and SAP programs SALV_IDA_* as of 7.5 SP03. With all this functionality provided by SAP, HANA / CDS is powerful development tool saving time and making possible the code pushdown to HANA database.

Create CDS view from ADT using folder Core Data Services, right-click to create New -> DDL Source

Create program (full source code below) which leverages standard SAP classes CL_SALV_*IDA*

From SE80, right-click program, click “Create GUI Status” called STATUS (see line 84)

See selection criteria made possible by SAP class CL_SALV_IDA_QUERY_ENGINE

See selection limitation made possible by SAP class CL_SALV_GUI_GRID_MODEL_IDA

CDS view on HANA DB quickly displays records according to selection criteria, in less than 1 second, including the custom ABAP CDS annotations.

 

REPORT  z_fi_header_cds_alv_select.
DATA:   go_alv_gui_table_ida TYPE REF TO if_salv_gui_table_ida ##NEEDED.
TABLES: bkpf.
SELECT-OPTIONS: s_belnr      FOR bkpf-belnr,
                s_bukrs      FOR bkpf-bukrs,
                s_gjahr      FOR bkpf-gjahr,
                s_budat      FOR bkpf-budat.
PARAMETERS:     p_limit      TYPE syst_tabix DEFAULT 2000000.
CLASS  lcl_salv_cds DEFINITION ##CLASS_FINAL.
  PUBLIC SECTION.
    CLASS-METHODS:
      display,
      status_function_selected
                    FOR EVENT function_selected OF if_salv_gui_fullscreen_ida
        IMPORTING ev_fcode.
  PRIVATE SECTION.
ENDCLASS.                    "lcl_salv_alv DEFINITION
CLASS lcl_salv_cds IMPLEMENTATION.
  METHOD display.
    DATA: lt_excluding_fcode    TYPE if_salv_gui_types_ida=>yt_excluding_fcode.
    DATA: lt_ranges             TYPE if_salv_service_types=>yt_named_ranges.
    FIELD-SYMBOLS: <fs_r>       LIKE LINE OF lt_ranges.
    FIELD-SYMBOLS: <fs_s>     LIKE LINE OF s_belnr,
                   <fs_bukrs> LIKE LINE OF s_bukrs,
                   <fs_gjahr> LIKE LINE OF s_gjahr,
                   <fs_budat> LIKE LINE OF s_budat.

    cl_salv_ida_services=>create_entity_and_abqi(
    EXPORTING iv_entity_id   = CONV #( 'Z_FI_HEADER2' )
              iv_entity_type = 'CDS'
    IMPORTING eo_entity      = DATA(lo_entity)
              eo_fetch       = DATA(lo_fetch) ).
    DATA(lo_ida_structdescr) = cl_salv_ida_structdescr=>create_for_sadl_entity( io_entity = lo_entity ).
    cl_salv_ida_text_search_prov=>get_search_attributes( EXPORTING io_salv_ida_structdescr = lo_ida_structdescr
                                                         IMPORTING ets_search_attribute    = DATA(lt_search_attribute) ).
    DATA(lo_sti_text_search) = cl_salv_ida_text_search_prov=>create_4_sti( lt_search_attribute ).
    DATA(lo_sadl_entity) = lo_ida_structdescr->get_sadl_entity( ).
    DATA(lo_text_search) = cl_salv_ida_text_search_prov=>create_4_ida_api( lo_ida_structdescr ).
    DATA(lo_query_engine) = NEW cl_salv_ida_query_engine( io_sadl_entity          = lo_sadl_entity
                                                          io_sadl_fetch           = lo_fetch
                                                          io_salv_ida_text_search = lo_text_search ).
    DATA(lo_idas) = cl_salv_ida_services=>create( io_structdescr_prov     = lo_ida_structdescr
                                                  io_sti_text_search_prov = lo_sti_text_search
                                                  io_query_engine         = lo_query_engine ).
*   begin Z_FI_HEADER_CDS_ALV_SELECT selection screen data to CL_SALV_IDA_QUERY_ENGINE range table
    REFRESH: lt_ranges.
    LOOP AT s_belnr ASSIGNING <fs_s>.
      APPEND INITIAL LINE TO lt_ranges ASSIGNING <fs_r>.
      MOVE-CORRESPONDING <fs_s> TO <fs_r>.       <fs_r>-name   = 'BELNR'.
    ENDLOOP.
    LOOP AT s_bukrs ASSIGNING <fs_bukrs>.
      APPEND INITIAL LINE TO lt_ranges ASSIGNING <fs_r>.
      MOVE-CORRESPONDING <fs_bukrs> TO <fs_r>.   <fs_r>-name   = 'BUKRS'.
    ENDLOOP.
    LOOP AT s_gjahr ASSIGNING <fs_gjahr>.
      APPEND INITIAL LINE TO lt_ranges ASSIGNING <fs_r>.
      MOVE-CORRESPONDING <fs_gjahr> TO <fs_r>.   <fs_r>-name   = 'GJAHR'.
    ENDLOOP.
    LOOP AT s_budat ASSIGNING <fs_budat>.
      APPEND INITIAL LINE TO lt_ranges ASSIGNING <fs_r>.
      MOVE-CORRESPONDING <fs_budat> TO <fs_r>.   <fs_r>-name   = 'BUDAT'.
    ENDLOOP.
    lo_idas->get_query_engine( )->set_selection_range_tab( it_ranges = lt_ranges ).
*   end Z_FI_HEADER_CDS_ALV_SELECT selection screen data to CL_SALV_IDA_QUERY_ENGINE range table
    DATA(lo_observer_manager)   = cl_salv_gui_observer_manager=>create_observer_manager( ).
    DATA(lo_user_action)        = NEW cl_salv_gui_user_action( ).
    DATA(lo_standard_functions) = NEW cl_salv_gui_std_functions_ida( ).
    DATA(lo_field_catalog)      = NEW cl_salv_gui_field_catalog_ida( io_structdescr_provider = lo_ida_structdescr ).
    DATA(lo_layout)             = NEW cl_salv_gui_layout_ida(        io_standard_functions   = lo_standard_functions
                                                                     io_text_search          = lo_sti_text_search
                                                                     io_field_catalog        = lo_field_catalog ).
    DATA(lo_model_ida)          = NEW cl_salv_gui_grid_model_ida(    io_idas                 = lo_idas
                                                                     io_field_catalog        = lo_field_catalog
                                                                     io_layout               = lo_layout
                                                                     io_user_action          = lo_user_action ).
*   begin set selection limitation
    lo_model_ida->if_salv_gui_table_ida~set_maximum_number_of_rows( iv_number_of_rows = p_limit ).
*   begin set selection limitation
    go_alv_gui_table_ida = cl_salv_gui_grid_controler_ida=>create_for_fullscreen(
                                                           EXPORTING io_user_action          = lo_user_action
                                                                     io_gui_grid_model       = lo_model_ida
                                                                     io_observer_manager     = lo_observer_manager ).
    go_alv_gui_table_ida->fullscreen( )->set_pf_status(
            iv_pf_status_name        = 'STATUS'
            iv_program_name          = sy-repid
            it_excluding_fcode       = lt_excluding_fcode  ).
    SET HANDLER status_function_selected FOR go_alv_gui_table_ida->fullscreen( ).
    go_alv_gui_table_ida->fullscreen( )->display( ).
  ENDMETHOD.
  METHOD status_function_selected.
    CASE ev_fcode.
      WHEN OTHERS.
        go_alv_gui_table_ida->fullscreen( )->exit( ).
    ENDCASE.
  ENDMETHOD.
ENDCLASS.                    "lcl_salv_cds IMPLEMENTATION

END-OF-SELECTION.
  CALL METHOD lcl_salv_cds=>display.

Assigned Tags

      9 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Amol Samte
      Amol Samte

      Is it available on 7.5 SP2?

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hi Amol, Integrated Data Access delivered from NW 7.4 onwards. Since this particular example using NW 7.5 SP03 some of the IDA functionality (class, methods, etc.) may not be available in NW 7.5 SP02.

      All the best,
      Todd

      Author's profile photo Former Member
      Former Member

      Hi,

      You can find another example with CDS:
      http://indevya.com/sapcorner/dialog-transaction-with-alv-ida/

      It's a full dialog transaction with usage of 2 CDS views.

      BR,

      Mikolaj
       

      Author's profile photo Former Member
      Former Member

      This is really amazing, I've done the reporting with search on table, DOKTL, right now at 72 million records on my system.  Generic search works very well.  Has anyone used fuzzy logic search using the search help for ALV IDA?

      REPORT YJC_IDA2_DOKTL.

      TABLES DOKTL.

      DATA(lo_alv_displaycl_salv_gui_table_ida=>createiv_table_name 'DOKTL' ).

      "Tell the ALV the select -options
      DATA(lo_collectorNEW cl_salv_range_tab_collector.

      SELECTION-SCREEN BEGIN OF BLOCK b1.
      SELECT-OPTIONS so_OBJEC FOR DOKTL-OBJECT,
      so_dokt for doktl-doktext.
      SELECTION-SCREEN END OF BLOCK b1.

      START-OF-SELECTION.

      lo_collector->add_ranges_for_nameiv_name 'OBJECT' it_ranges so_OBJEC[] .
      lo_collector->add_ranges_for_nameiv_name 'DOKTEXT' it_ranges so_dokt[] .
      lo_collector->get_collected_rangesIMPORTING et_named_ranges DATA(lt_name_range_pairs).
      lo_alv_display->set_select_optionsit_ranges lt_name_range_pairs .

      "Display
      lo_alv_display->fullscreen)->display.

      Author's profile photo Former Member
      Former Member

      I've made the following code changes to enable Fuzzy Search on top of ALV IDA.  Only question now is how can I make the CDS view with parameter work on ALV IDA.  Has anyone tried it?

      REPORT yjc_ida2_doktl.

      TABLES : doktl.

      DATA(lo_alv_display) = cl_salv_gui_table_ida=>create( iv_table_name = 'DOKTL' ).

      "Tell the ALV the select -options
      DATA(lo_collector) = NEW cl_salv_range_tab_collector( ) .

      SELECTION-SCREEN : BEGIN OF BLOCK b1.
      SELECT-OPTIONS : so_objec FOR doktl-object MATCHCODE OBJECT YJC_DOKTL,
      so_dokt FOR doktl-doktext MATCHCODE OBJECT YJC_DOKTL_T.
      SELECTION-SCREEN : END OF BLOCK b1.

      START-OF-SELECTION.

      lo_collector->add_ranges_for_name( iv_name = 'OBJECT' it_ranges = so_objec[] ) .
      lo_collector->add_ranges_for_name( iv_name = 'DOKTEXT' it_ranges = so_dokt[] ) .
      lo_collector->get_collected_ranges( IMPORTING et_named_ranges = DATA(lt_name_range_pairs) ).
      lo_alv_display->set_select_options( it_ranges = lt_name_range_pairs ) .

      "Display
      lo_alv_display->fullscreen( )->display( ) .

       

      Author's profile photo Venkatram Cheruku
      Venkatram Cheruku

      The standard export button on the tool bar has a limitation. When I try to export all data displayed on the report, it says 'Function not possible: more than &1 lines selected'. '&1' value is calculated as 'Total number of records/Total columns'.

      I am not sure why SAP had to put such kind of limitation when a normal ALV does not limit the number of records to export.

      Thanks,

      Venkat

      Author's profile photo Sijin Chandran
      Sijin Chandran

      Hi,

       

      io_message_manager , Parameter is Mandatory for both cl_salv_gui_layout_ida and cl_salv_gui_grid_model_ida , can you please tell how to pass them.

      I tried to create a Object of Class  cl_salv_gui_message_manager and tried to pass but its giving dump.

       

       DATA(lo_message_manager)    = NEW cl_salv_gui_message_manager( ).

       

      Can you please suggest.

       

      Thanks,

      Sijin

      Author's profile photo Kuniharu Suzuki
      Kuniharu Suzuki

      The same parameter must also be added to CL_SALV_GUI_GRID_CONTROLER_IDA=>CREATE_FOR_FULLSCREEN.

      Author's profile photo Juan Victor Uribe Martinez
      Juan Victor Uribe Martinez

      Thank you Kuniharu