Dialog transaction with ALV IDA

In new ABAP version you can find very usefull technology called ALV IDA.
The difference between old ALV is that IDA works directly at DB layer so we cannot feed it with internal tables. Also it will be useless for reports running in background. You might say – in most cases it won’t be usefull and you might be right, but on the other hand it seems to be very powerfull buliding fast monitoring and reporting transactions.
In the example underneath you can find an approach how to easily create own dialog transaction based on ALV IDA technology. Using this template you can enhance your development with new screens in a couple of minutes.

Let’s start. What is the idea?
alv_ida_idea
We’d like to build simple transaction with selection screen on start, result screen with table, detailed screen with another table and some drill-down action to standard transactions. It seems to be a typical usage.
As a source I’ll use CDS views with data combined from Sales Orders.

@AbapCatalog.sqlViewName: ‘ZSO_HDR_SEL’

@AbapCatalog.compiler.CompareFilter: true

@AccessControl.authorizationCheck: #CHECK

@EndUserText.label: ‘Sales Order Header select view’

define view
Zso_Sel_Hdr_View
as select

    key vb.vbeln,

    vb.erdat,

    vb.erzet,

    vb.ernam,

    vb.auart,

    vb.netwr,

    vb.waerk,

        @EndUserText.label: ‘Items’

        @EndUserText.quickInfo: ‘Items count’

    count( distinct vp.posnr ) as itms_cnt

    from vbak as vb

    inner join vbap as vp

    on vb.vbeln = vp.vbeln

    group by vb.vbeln, vb.erdat, vb.erzet, vb.ernam,

             vb.auart, vb.netwr, vb.waerk

CDS View with SO header

@AbapCatalog.sqlViewName: ‘ZSO_ITM_SEL2’

@AbapCatalog.compiler.CompareFilter: true

@AccessControl.authorizationCheck: #CHECK

@EndUserText.label: ‘Sales Order items’

define view
Zso_Sel_Itm_View2

    as select from vbap

    left outer join makt

    on vbap.matnr = makt.matnr

    and makt.spras = ‘E’ //only english descr

                     {

    key vbap.vbeln,

    key vbap.posnr,

    vbap.matnr,

    makt.maktx,

    vbap.kwmeng

}

CDS View with SO items

Of course you can use other DDIC objects like tables or other Views created in SE11.

In our approach we need to define table type for our configuration where we can assign container and table for each screen with ALV IDA.

TYPES:

* — ALV output structure type — *

  BEGIN OF s_alv,

    screen type sydynnr,

    container_name type SCRFNAME,

    tabname type DBTABL,

    alv_display TYPE REF TO if_salv_gui_table_ida,

    container TYPE REF TO cl_gui_custom_container,

  end of s_alv.

 

 types: t_alv type table
of
s_alv with key screen.

Screen field is dedicated for screen number.
Container_name should be filled with custom control name, which is created at screen.
Tabname contains table or view name, which will be used for ALV IDA control.

Underneath you’ll find a configuration created for our example.

 DATA(gt_alv) = VALUE t_alv(

    ( screen = ‘0100’ container_name = ‘CONT_0100’ tabname = ‘zso_sel_hdr_view’ )

    ( screen = ‘0110’ container_name = ‘CONT_0110’ tabname = ‘zso_sel_itm_view2’ ) ).

We’ve got 2 screens referring to our CDS views.

Let’s take a look at example screen delivered for our report.
alv_ida_screen_layout
Screen has only custom control at whole are.
alv_ida_screen_elem
There is only “ok code” field and our control.
alv_ida_screen_flow
Flow is the same for each screen. Easilly adding next screen you just copy first one.

MODULE pbo OUTPUT.

 

  go_report->load_alv( ).

 

ENDMODULE.

In PBO we call our method for initializing and loading data.

  METHOD load_alv.

 

    if line_exists( gt_alv[ screen = sydynnr ] )."just
in case…

        if gt_alv[ screen = sydynnr ]-container IS NOT
BOUND.

 

        "create container
and ALV

          gt_alv[ screen = sydynnr ]-container = NEW #( gt_alv[ screen = sydynnr ]-container_name ).

 

          data(tab_descr) = cl_abap_typedescr=>describe_by_name( gt_alv[ screen = sydynnr ]-tabname ).

          data(tab_type) = tab_descr->get_ddic_header( )-tabtype.

          case tab_type.

              when ‘T’. "standard
table

                gt_alv[ screen = sydynnr ]-alv_display = cl_salv_gui_table_ida=>create(

                                          iv_table_name = gt_alv[ screen = sydynnr ]-tabname

                                          io_gui_container = gt_alv[ screen = sydynnr ]-container ).

              when ‘B’. "CDS
View

                gt_alv[ screen = sydynnr ]-alv_display = cl_salv_gui_table_ida=>create_for_cds_view(

                                          iv_cds_view_name = gt_alv[ screen = sydynnr ]-tabname

                                          io_gui_container = gt_alv[ screen = sydynnr ]-container ).

          endcase."tab_type

 

        endif.

 

 

      try.

 

       DATA(meth_name) = ‘ADD_ALV_’ &&
sydynnr.

 

          call method (meth_name)

            changing

              co_alv = gt_alv[ screen = sydynnr ]-alv_display.

 

        catch cx_sy_dyn_call_illegal_method into DATA(exc).

      endtry.

 

    endif."gt_alv[] for
sy-dynnr

 

  ENDMETHOD.

As you can find – there’s a case for standard and CDS view.
Also in code you may find a place for additional processing at each screen. All you need to do is to write your own method with name add_alv_screen_number.
Underneath is example for our 0100 screen.

  METHOD add_alv_0100.

 

"## TODO: fill ranges ##

    data(lo_collector) = NEW cl_salv_range_tab_collector( ).

    lo_collector->add_ranges_for_name( iv_name = ‘ERDAT’ it_ranges = s_date[] ).

    lo_collector->get_collected_ranges( IMPORTING
et_named_ranges = data(lt_name_range_pairs) ).

    co_alv->set_select_options( it_ranges = lt_name_range_pairs ).

 

 

*   enable double-click event and handling

    co_alv->display_options( )->enable_double_click( ).

    SET HANDLER double_click_0100 FOR co_alv->display_options( ).

 

  ENDMETHOD.

Finally let’s check how it’s working.
alv_ida_sel_screen
Selection screen
alv_ida_1st_screen
1st result screen
alv_ida_2nd_screen
2nd – details screen.

Underneath is a copy paste full example. Enjoy it!

Published by

Captain SAP

Captain SAP is a technical consultant with over 15 yeras of expierience in integrated systems implementation.

Leave a Reply

Your email address will not be published. Required fields are marked *