Copyright 2024 - BV TallVision IT

The ALV concept can also be applied several times on a single screen, for which a DYNPRO needs to be created. This example shows how that can be done for a simple screen with 2 custom containers. 

ALV reports don't have a lot of disadvantages in comparison to classic reports. But I found one. The classic report can handle different line types in a single report. The solution can be quite simple: use 2 ALV overviews in a single screen. Stacked on top or side by side, the first report shows high level information and the second (right or bottom) reports details linked to a selected line from the main report.

The report source coding:


class lcl_event_manager definition deferred.
data: gt_data type table of mara,
      gw_data type mara,
      gt_data2 type table of marc,
      gv_okcode type syucomm,
* A custom container needs to be set up in a custom screen. This
* example has 2: top and bottom.
      go_container_top type ref to cl_gui_custom_container,
      go_container_bottom type ref to cl_gui_custom_container,
* 2 ALV references (again for the top and bottom)
      go_alv_top type ref to lcl_easy_alv,                "Define
      go_salv_top type ref to cl_salv_table,
      go_alv_bottom type ref to lcl_easy_alv,             "Define
      go_salv_bottom type ref to cl_salv_table,
      go_event_man type ref to lcl_event_manager.

* CLASS lcl_event_manager DEFINITION
* An example subclass for processing events
class lcl_event_manager definition.
  public section.
    methods: constructor importing r_object type ref to cl_salv_table,
             on_link_click for event link_click of cl_salv_events_table
               importing row column.
  private section.
    data: go_salv type ref to cl_salv_table.
endclass.                    "lcl_example_alv DEFINITION
* CLASS lcl_event_manager IMPLEMENTATION
* Allow response for double clicks and user commands (menu actions)
class lcl_event_manager implementation.
  method constructor.
    data: lo_events type ref to cl_salv_events_table.

    go_salv = r_object.
    lo_events = go_salv->get_event( ).
    set handler on_link_click for lo_events.
  endmethod.                    "preperation_control
  method on_link_click.
    read table gt_data index row into gw_data.
* Fetch fresh data
    select * from marc up to 15 rows
      into table gt_data2
      where matnr = gw_data-matnr.
    go_alv_bottom->display( refresh = abap_true ).
  endmethod.                    "on_link_click
endclass.                    "lcl_example_alv IMPLEMENTATION

* Module  STATUS_0900  OUTPUT
module status_0900 output.

  set pf-status 'MAIN'. "<=your own menu, no ALV functionality here

  if go_container_top is initial.
    create object go_container_top
        container_name = 'TOP_HALF'.
      exporting container = go_container_top
      changing  content = gt_data
                salv_table = go_salv_top ).
    create object go_event_man
        r_object = go_salv_top.
    go_alv_top->set_field( fieldname = 'MATNR'
      is_hotspot = abap_true ).
    go_alv_top->display( ).

  if go_container_bottom is initial.
    create object go_container_bottom
        container_name = 'BOTTOM_HALF'.

      exporting container = go_container_bottom
                title = 'Plants for the material'(001)
                SKIP_VARIANT_SUPPORT = abap_true
      changing  content = gt_data2
                salv_table = go_salv_bottom ).

    go_alv_bottom->set_no_buttons( ).
    go_alv_bottom->set_field( fieldname = 'MATNR'
      is_key = abap_false is_hidden = abap_true ).
    go_alv_bottom->display( ).

endmodule.                 " STATUS_0900  OUTPUT
*  Module  USER_COMMAND_0900  INPUT
module user_command_0900 input.

  case gv_okcode.
    when 'BACK'.
      leave to screen 0.

endmodule.                 " USER_COMMAND_0900  INPUT


* Compose simple set of test data:
  select * from mara
    up to 20 rows into table gt_data
    where mtart = 'DIEN'.
  read table gt_data index 1 into gw_data.
  select * from marc up to 15 rows
    into table gt_data2
    where matnr = gw_data-matnr.

  create object go_alv_top.            "Create
  create object go_alv_bottom.         "Create

* Call the main screen, from which the ALV lists are controlled:
  call screen 900.

The main screen for this example

Most of the demo's in the EASY ALV suite run by simply implementing a bit of coding, for this example however, an actual DYNPRO is required. Double click on the CALL SCREEN 900. line (on the "900") to create it.

Screen 900 is a simple screen with a very basic flow logic. The STATUS_0900 will prepare all the work and the USER_COMMAND_0900 module will provide a way out of the report.

process before output.

  module status_0900.

process after input.

  module user_command_0900.

and also a very basic layout, custom control TOP_HALF and custom control BOTTOM_HALF. Custom controls can be created via the "Layout of screen" (screen painter), select Edit / Create element / Custom control. Select a star point and end point and make sure you use the names as described above.

The menu (pf-status)

Last but not least, there is a menu to be incorporated in the setup. Find the line SET PF-STATUS 'MAIN". and double click on it to create. Make sure you add a "way out" for your end user. In this demo, the BACK function is the only available function.