Sunday, May 7, 2017

Display table content in a popup window via SALV

If you have a list of various db tables with different structure (selected by specific field name) you may want add a preview of each ones content via popup window. But field name could be a variable of unknown type. Below coding shows a way how to reach this functionality, it uses dynamic data creation, dynamic Open SQL and SALV class.

Note: Sorry for the ugly subroutine surrounding ;-) I placed this functionality into an old program, where is the subroutine triggered by event  AT LINE-SELECTION working  together with variables provided by HIDE command. The popup window nicely works with selection screen.



TYPES tyv_sql_line TYPE LENGTH 72.

*&---------------------------------------------------------------------*
*&      Form  show_table_content
*&---------------------------------------------------------------------*
*       Show table content in a popup window by specific field
*----------------------------------------------------------------------*
FORM show_table_content USING p_tablename p_fieldname p_fieldvalue.

  DATAlt_sql_where   TYPE STANDARD TABLE OF tyv_sql_line,
              lv_sql_where   LIKE LINE OF lt_sql_where,
              rv_dref        TYPE REF TO data,
              rcl_alv        TYPE REF TO cl_salv_table,
              lx_msg         TYPE REF TO cx_salv_msg.

  FIELD-SYMBOLS<itab> TYPE ANY TABLE.

  CLEAR lv_sql_where.
  CLEAR lt_sql_where.

  CONCATENATE p_fieldname ' = ' '`' p_fieldvalue '`' INTO lv_sql_where RESPECTING BLANKS.
  APPEND lv_sql_where TO lt_sql_where.

  CREATE DATA rv_dref TYPE TABLE OF (p_tablename).
  ASSIGN rv_dref->TO <itab>.

  SELECT FROM (p_tablename)
  INTO TABLE <itab>
  WHERE (lt_sql_where).

  IF <itab> IS ASSIGNED.

    TRY.
        cl_salv_table=>factory(
        IMPORTING
          r_salv_table rcl_alv
        CHANGING
          t_table      <itab> ).
      CATCH cx_salv_msg INTO lx_msg.
    ENDTRY.

    rcl_alv->set_screen_popup(
      start_column 25
      end_column   150
      start_line   15
      end_line     22
    ).

    rcl_alv->display).

  ENDIF.

ENDFORM.                    "show_table_content



The popup looks like e.g.



Valuable source for ALV popup 


No comments:

Post a Comment