ABAP – Very simple ALV

It’s quite common request to show lines of an internal table in form of ALV popup – e.g. some custom log messages after a program execution.

Here’s an example of very short & easy code snippet to display any internal table in either separate window or as a popup window encapsulated in a CLASS-METHOD

CLASS lcl_helper DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      simple_alv
        IMPORTING
          iv_start_col  TYPE i         DEFAULT 25
          iv_start_line TYPE i         DEFAULT 6
          iv_end_col    TYPE i         DEFAULT 100
          iv_end_line   TYPE i         DEFAULT 10
          iv_popup      TYPE abap_bool DEFAULT abap_false
        CHANGING
          ct_table      TYPE ANY TABLE.
ENDCLASS.

CLASS lcl_helper IMPLEMENTATION.
  METHOD simple_alv.
    DATA lo_alv TYPE REF TO cl_salv_table.

    TRY.
        cl_salv_table=>factory(
          IMPORTING
            r_salv_table = lo_alv
          CHANGING
            t_table      = ct_table[] ).

      CATCH cx_salv_msg.
    ENDTRY.

    DATA: lr_functions TYPE REF TO cl_salv_functions_list.

    lr_functions = lo_alv->get_functions( ).
    lr_functions->set_all( 'X' ).

    IF lo_alv IS BOUND.
      IF iv_popup = 'X'.   "display as popup?
        lo_alv->set_screen_popup(
          start_column = iv_start_col
          end_column   = iv_end_col
          start_line   = iv_start_line
          end_line     = iv_end_line ).
      ENDIF.

      lo_alv->display( ).

    ENDIF.
  ENDMETHOD.
ENDCLASS.

Here’s the method real usage – show ALV fullscreen

START-OF-SELECTION.
  DATA:
    lt_curr TYPE TABLE OF tcurr.

  SELECT *
    FROM tcurr
    INTO TABLE lt_curr.

  lcl_helper=>simple_alv(
*  EXPORTING
*    iv_start_col  = 25
*    iv_start_line = 6
*    iv_end_col    = 100
*    iv_end_line   = 10
*    iv_popup      = ABAP_TRUE
    CHANGING
      ct_table      = lt_curr
  ).

And a simple code modification when you want to display the result as a popup

  lcl_helper=>simple_alv(
    EXPORTING
*    iv_start_col  = 25
*    iv_start_line = 6
*    iv_end_col    = 100
*    iv_end_line   = 10
      iv_popup      = abap_true
    CHANGING
      ct_table      = lt_curr
  ).

Leave a Reply