Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to dispaly dynamic internal table in ALV format

Former Member
0 Kudos
1,757

How to dispaly dynamic internal table in ALV format

hey i have created the internal tabel dynamically

and have stored in the value

i want to display the output of the table in ALV format

With Regards

Rohan

1 ACCEPTED SOLUTION

Former Member
0 Kudos
254

Pl. see this sample code..

REPORT z_alv_dynamic_data.

TABLES:

dd02l, " SAP tables

dd03l. " Table Fields

TYPE-POOLS: slis. " ALV Global Types

SELECTION-SCREEN :

BEGIN OF LINE, COMMENT 1(35) v_1 FOR FIELD p_table. "#EC NEEDED

PARAMETERS p_table LIKE dd03l-tabname OBLIGATORY MEMORY ID dtb.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN :

BEGIN OF LINE, COMMENT 1(35) v_2 FOR FIELD p_max. "#EC NEEDED

PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.

SELECTION-SCREEN END OF LINE.

----


AT SELECTION-SCREEN.

SELECT SINGLE * FROM dd02l WHERE tabname = p_table

AND as4local = 'A'

AND as4vers = '0000'.

IF sy-subrc NE 0.

  • Table & is not active in the Dictionary

MESSAGE e402(mo) WITH p_table.

ELSEIF dd02l-tabclass = 'INTTAB'.

  • & is a structure, not a table

MESSAGE e403(mo) WITH p_table.

ENDIF.

----


INITIALIZATION.

v_1 = 'Table'.

v_2 = 'Maximum of records'.

----


START-OF-SELECTION.

PERFORM f_display_data.

----


  • Form F_DISPLAY_DATA

----


FORM f_display_data.

  • Macro definition

DEFINE m_sort.

add 1 to ls_sort-spos.

ls_sort-fieldname = &1.

ls_sort-up = 'X'.

append ls_sort to lt_sort.

END-OF-DEFINITION.

DATA:

l_long TYPE i,

lp_struct TYPE REF TO data,

lp_table TYPE REF TO data, " Pointer to dynamic table

of_sdescr TYPE REF TO cl_abap_structdescr,

ls_lvc_cat TYPE lvc_s_fcat,

lt_lvc_cat TYPE lvc_t_fcat, " Field catalog

ls_fieldcat TYPE slis_fieldcat_alv,

lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog

ls_layout TYPE slis_layout_alv,

lt_sort TYPE slis_t_sortinfo_alv, " Sort table

ls_sort TYPE slis_sortinfo_alv.

FIELD-SYMBOLS :

<fieldcat> TYPE slis_fieldcat_alv,

<lt_data> TYPE table, " Data to display

<fs> TYPE ANY,

<components> TYPE abap_compdescr.

  • Dynamic creation of a structure

CREATE DATA lp_struct TYPE (p_table).

ASSIGN lp_struct->* TO <fs>.

  • Fields Structure

of_sdescr ?= cl_abap_typedescr=>describe_by_data( <fs> ).

LOOP AT of_sdescr->components ASSIGNING <components>.

  • Field MANDT not displayed

IF sy-tabix = 1 AND <components>-name = 'MANDT'.

CONTINUE. " Next loop

ENDIF.

  • Build Fieldcatalog

ls_lvc_cat-fieldname = <components>-name.

ls_lvc_cat-ref_table = p_table.

APPEND ls_lvc_cat TO lt_lvc_cat.

  • Build Fieldcatalog

ls_fieldcat-fieldname = <components>-name.

ls_fieldcat-ref_tabname = p_table.

APPEND ls_fieldcat TO lt_fieldcat.

ENDLOOP.

  • Create internal table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING it_fieldcatalog = lt_lvc_cat

IMPORTING ep_table = lp_table.

ASSIGN lp_table->* TO <lt_data>.

  • Read data

SELECT * FROM (p_table) UP TO p_max ROWS

INTO CORRESPONDING FIELDS OF TABLE <lt_data>

ORDER BY PRIMARY KEY.

IF <lt_data>[] IS INITIAL.

  • No table entries found for specified key

MESSAGE i429(mo).

EXIT.

ENDIF.

  • Read key field to Build Sort Table

SELECT * FROM dd03l WHERE tabname = p_table

AND fieldname <> '.INCLUDE'

AND as4vers = '0000'

AND as4local = 'A'

ORDER BY position.

READ TABLE lt_fieldcat ASSIGNING <fieldcat>

WITH KEY fieldname = dd03l-fieldname.

CHECK sy-subrc EQ 0.

ADD dd03l-leng TO l_long.

IF dd03l-keyflag = 'X'.

  • Build Sort Table

m_sort dd03l-fieldname.

<fieldcat>-key = 'X'.

ELSEIF l_long > 150.

<fieldcat>-tech = 'X'.

ENDIF.

ENDSELECT.

ls_layout-zebra = 'X'.

ls_layout-colwidth_optimize = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

is_layout = ls_layout

it_fieldcat = lt_fieldcat

it_sort = lt_sort

TABLES

t_outtab = <lt_data>.

ENDFORM. " F_DISPLAY_DATA

Regards,

Joy.

4 REPLIES 4

Former Member
0 Kudos
255

Pl. see this sample code..

REPORT z_alv_dynamic_data.

TABLES:

dd02l, " SAP tables

dd03l. " Table Fields

TYPE-POOLS: slis. " ALV Global Types

SELECTION-SCREEN :

BEGIN OF LINE, COMMENT 1(35) v_1 FOR FIELD p_table. "#EC NEEDED

PARAMETERS p_table LIKE dd03l-tabname OBLIGATORY MEMORY ID dtb.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN :

BEGIN OF LINE, COMMENT 1(35) v_2 FOR FIELD p_max. "#EC NEEDED

PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.

SELECTION-SCREEN END OF LINE.

----


AT SELECTION-SCREEN.

SELECT SINGLE * FROM dd02l WHERE tabname = p_table

AND as4local = 'A'

AND as4vers = '0000'.

IF sy-subrc NE 0.

  • Table & is not active in the Dictionary

MESSAGE e402(mo) WITH p_table.

ELSEIF dd02l-tabclass = 'INTTAB'.

  • & is a structure, not a table

MESSAGE e403(mo) WITH p_table.

ENDIF.

----


INITIALIZATION.

v_1 = 'Table'.

v_2 = 'Maximum of records'.

----


START-OF-SELECTION.

PERFORM f_display_data.

----


  • Form F_DISPLAY_DATA

----


FORM f_display_data.

  • Macro definition

DEFINE m_sort.

add 1 to ls_sort-spos.

ls_sort-fieldname = &1.

ls_sort-up = 'X'.

append ls_sort to lt_sort.

END-OF-DEFINITION.

DATA:

l_long TYPE i,

lp_struct TYPE REF TO data,

lp_table TYPE REF TO data, " Pointer to dynamic table

of_sdescr TYPE REF TO cl_abap_structdescr,

ls_lvc_cat TYPE lvc_s_fcat,

lt_lvc_cat TYPE lvc_t_fcat, " Field catalog

ls_fieldcat TYPE slis_fieldcat_alv,

lt_fieldcat TYPE slis_t_fieldcat_alv, " Field catalog

ls_layout TYPE slis_layout_alv,

lt_sort TYPE slis_t_sortinfo_alv, " Sort table

ls_sort TYPE slis_sortinfo_alv.

FIELD-SYMBOLS :

<fieldcat> TYPE slis_fieldcat_alv,

<lt_data> TYPE table, " Data to display

<fs> TYPE ANY,

<components> TYPE abap_compdescr.

  • Dynamic creation of a structure

CREATE DATA lp_struct TYPE (p_table).

ASSIGN lp_struct->* TO <fs>.

  • Fields Structure

of_sdescr ?= cl_abap_typedescr=>describe_by_data( <fs> ).

LOOP AT of_sdescr->components ASSIGNING <components>.

  • Field MANDT not displayed

IF sy-tabix = 1 AND <components>-name = 'MANDT'.

CONTINUE. " Next loop

ENDIF.

  • Build Fieldcatalog

ls_lvc_cat-fieldname = <components>-name.

ls_lvc_cat-ref_table = p_table.

APPEND ls_lvc_cat TO lt_lvc_cat.

  • Build Fieldcatalog

ls_fieldcat-fieldname = <components>-name.

ls_fieldcat-ref_tabname = p_table.

APPEND ls_fieldcat TO lt_fieldcat.

ENDLOOP.

  • Create internal table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING it_fieldcatalog = lt_lvc_cat

IMPORTING ep_table = lp_table.

ASSIGN lp_table->* TO <lt_data>.

  • Read data

SELECT * FROM (p_table) UP TO p_max ROWS

INTO CORRESPONDING FIELDS OF TABLE <lt_data>

ORDER BY PRIMARY KEY.

IF <lt_data>[] IS INITIAL.

  • No table entries found for specified key

MESSAGE i429(mo).

EXIT.

ENDIF.

  • Read key field to Build Sort Table

SELECT * FROM dd03l WHERE tabname = p_table

AND fieldname <> '.INCLUDE'

AND as4vers = '0000'

AND as4local = 'A'

ORDER BY position.

READ TABLE lt_fieldcat ASSIGNING <fieldcat>

WITH KEY fieldname = dd03l-fieldname.

CHECK sy-subrc EQ 0.

ADD dd03l-leng TO l_long.

IF dd03l-keyflag = 'X'.

  • Build Sort Table

m_sort dd03l-fieldname.

<fieldcat>-key = 'X'.

ELSEIF l_long > 150.

<fieldcat>-tech = 'X'.

ENDIF.

ENDSELECT.

ls_layout-zebra = 'X'.

ls_layout-colwidth_optimize = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

is_layout = ls_layout

it_fieldcat = lt_fieldcat

it_sort = lt_sort

TABLES

t_outtab = <lt_data>.

ENDFORM. " F_DISPLAY_DATA

Regards,

Joy.

Clemenss
Active Contributor
0 Kudos
254

Hi Rohan,

it depends on how you create the dynamic internal table: If you use the METHOD cl_alv_table_create=>create_dynamic_table you have used a field catalog for this - pass the field catalog to the ALV display function or method.

If you create using a dictionary structure, you may pass this structure to the ALV function/method as parameter.

If you used some other way, you may use my generic form routine that creates a fieldcatalog from any kind of internal table or data structure:


*&---------------------------------------------------------------------*
*&      Form  ALV_FIELDCAT_FOR_ITAB
*&---------------------------------------------------------------------*
*       Feldkatalog from (arbitrary) internal Table (c) Clemens Li
*       * build field catalog from        type description
*----------------------------------------------------------------------*
FORM alv_fieldcat_for_itab                                  "#EC *
  TABLES   pt_outtab                      TYPE table        "#EC *
  CHANGING pt_alv_fieldcat                TYPE slis_t_fieldcat_alv."#EC *
  DATA:
    lv_desc                               TYPE sydes_desc,
    ls_alv_fieldcat                       TYPE slis_fieldcat_alv,
    lv_longfield                          TYPE text80."CRM<=R/3 fname.
  FIELD-SYMBOLS:
    <typeinfo>                            TYPE sydes_typeinfo,
    <nameinfo>                            TYPE sydes_nameinfo.
  DESCRIBE FIELD pt_outtab INTO lv_desc.                    "#EC *

  LOOP AT lv_desc-types
      ASSIGNING <typeinfo>
      WHERE NOT idx_name IS INITIAL
        AND table_kind IS INITIAL "no entries for deep table like color
        AND back                          = 1. "top-level-entries only.
    READ TABLE lv_desc-names INDEX <typeinfo>-idx_name
      ASSIGNING <nameinfo>.
    CHECK <nameinfo>-name                 <> 'INCLUDE'.
    ls_alv_fieldcat-fieldname             = <nameinfo>-name.
    WHILE NOT <nameinfo>-continue IS INITIAL.
      ADD 1 TO <typeinfo>-idx_name.
      READ TABLE lv_desc-names INDEX <typeinfo>-idx_name
        ASSIGNING <nameinfo>.
      CONCATENATE
        ls_alv_fieldcat-fieldname
        <nameinfo>-name
        INTO ls_alv_fieldcat-fieldname.
    ENDWHILE." not <nameinfo>-continue IS INITIAL.
    READ TABLE lv_desc-names INDEX <typeinfo>-idx_help_id
      ASSIGNING <nameinfo>.
    IF sy-subrc                           = 0.

* Caution: Help-ID may be Tablename-Fieldname and thus longer
* than 30 Chars; ls_alv_fieldcat-rollname is 30 Chars only
      ls_alv_fieldcat-rollname            = <nameinfo>-name.
      lv_longfield                        = <nameinfo>-name.
      WHILE NOT <nameinfo>-continue IS INITIAL.
        ADD 1 TO <typeinfo>-idx_help_id.
        READ TABLE lv_desc-names INDEX <typeinfo>-idx_help_id
          ASSIGNING <nameinfo>.
        CONCATENATE
          lv_longfield
          <nameinfo>-name
          INTO lv_longfield.
      ENDWHILE." not lv_desc-continue is initial.

* help id may be data element or <table>-<field>
      IF lv_longfield CA '-'.

* get data                                type for table field
        PERFORM get_rollname_4_tabfield
          USING lv_longfield CHANGING ls_alv_fieldcat.
      ENDIF." lv_longfield ca '-'.
    ELSE.

* No Help-ID: Use Fieldname as text
      ls_alv_fieldcat-seltext_s           =
      ls_alv_fieldcat-seltext_m           =
      ls_alv_fieldcat-seltext_l           =
      ls_alv_fieldcat-reptext_ddic        =
      <nameinfo>-name.
    ENDIF." sy-subrc                      = 0.

* Starting 4.7: get edit mask
    IF NOT <typeinfo>-idx_edit_mask IS INITIAL.
      READ TABLE lv_desc-names INDEX <typeinfo>-idx_edit_mask
        ASSIGNING <nameinfo>.
      ls_alv_fieldcat-edit_mask           = <nameinfo>-name.
      IF NOT <nameinfo>-continue IS INITIAL.
        ADD 1 TO <typeinfo>-idx_edit_mask.
        READ TABLE lv_desc-names INDEX <typeinfo>-idx_edit_mask
          ASSIGNING <nameinfo>.
        CONCATENATE
          ls_alv_fieldcat-edit_mask
          <nameinfo>-name
          INTO ls_alv_fieldcat-edit_mask.
      ENDIF." not <nameinfo>-continue IS INITIAL.
    ENDIF." not <typeinfo>-IDX_EDIT_MASK is initial.

* assign length, output length and decimals
    ls_alv_fieldcat-intlen                = <typeinfo>-length.
    ls_alv_fieldcat-outputlen             = <typeinfo>-output_length.
    ls_alv_fieldcat-decimals_out          = <typeinfo>-decimals.
    ls_alv_fieldcat-inttype               = <typeinfo>-type.
    APPEND ls_alv_fieldcat TO pt_alv_fieldcat.
    CLEAR:  "prevent anything 2 B  taken for subsequent fields
      ls_alv_fieldcat.
  ENDLOOP." at lv_desc-types where not IDX_NAME is in initial.
ENDFORM.                    " ALV_FIELDCAT_FOR_ITAB


*&---------------------------------------------------------------------
*&      Form  get_rollname_4_tabfield
*&---------------------------------------------------------------------
*       Get Data                          type for Table field
*----------------------------------------------------------------------
FORM get_rollname_4_tabfield
  USING    p_fname                        TYPE text80 ""CRM<=R/3 fname
  CHANGING p_alv_fieldcat                 TYPE slis_fieldcat_alv.
  FIELD-SYMBOLS:
    <dfies>                               TYPE dfies.
  DATA:
    lv_tabname                            TYPE tabname,
     lt_dfies                             TYPE TABLE OF dfies,
    lv_fieldname                          TYPE fieldname.
  SPLIT p_fname AT '-'
    INTO lv_tabname lv_fieldname.
  CLEAR p_alv_fieldcat-rollname.
  CALL FUNCTION 'DDIF_FIELDINFO_GET'
    EXPORTING
      tabname                             = lv_tabname
      fieldname                           = lv_fieldname
*   LANGU                                 = SY-LANGU
*   LFIELDNAME                            = ' '
*   ALL_TYPES                             = ' '
* IMPORTING
*   X030L_WA                              =
*   DDOBJTYPE                             =
*   DFIES_WA                              =
*   LINES_DESCR                           =
   TABLES
     dfies_tab                            =  lt_dfies
*   FIXED_VALUES                          =
   EXCEPTIONS
     not_found                            = 1
     internal_error                       = 2
     OTHERS                               = 3
            .
  IF sy-subrc                             <> 0.
    MESSAGE ID sy-msgid                   TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    READ TABLE   lt_dfies ASSIGNING <dfies> INDEX 1.
    p_alv_fieldcat-rollname               = <dfies>-rollname.
* Und wenn keinerlei Twexte gepflegt sind?
    IF <dfies>-reptext IS INITIAL AND
       <dfies>-scrtext_s IS INITIAL AND
       <dfies>-scrtext_m IS INITIAL AND
       <dfies>-scrtext_l IS INITIAL.
* No Text: Use Fieldname as text
      p_alv_fieldcat-seltext_s            =
      p_alv_fieldcat-seltext_m            =
      p_alv_fieldcat-seltext_l            =
      p_alv_fieldcat-reptext_ddic         =
      p_alv_fieldcat-fieldname.
    ENDIF." <dfies>-reptext IS INITIAL AND
  ENDIF.
ENDFORM.                    " get_rollname_4_tabfield

This iis used primarily for ALVs based on the functional (slis) type. If you use the LVC (OO) type, you can convert the field catalog with a function module:


 CALL FUNCTION 'LVC_TRANSFER_FROM_SLIS'
    EXPORTING
      it_fieldcat_alv                     = lt_fcat  " TYPE slis_t_fieldcat_alv.
    IMPORTING
      et_fieldcat_lvc                     = pt_alv_fieldcat "TYPE lvc_t_fcat.
    TABLES
      it_data                             = pt_outtab
    EXCEPTIONS
      it_data_missing                     = 1
      OTHERS                              = 2

.

Regards,

Clemens

former_member212653
Active Contributor
0 Kudos
254

Hope this helps:


*&---------------------------------------------------------------------*
*& Report  ZDYNAMIC_ALV
*&
*&---------------------------------------------------------------------*

REPORT  ZDYNAMIC_ALV.

TYPE-POOLS: abap, slis.

DATA: tab TYPE REF TO cl_abap_structdescr,
      wa_tab TYPE REF TO cl_abap_structdescr,
      comp_tab   TYPE cl_abap_structdescr=>component_table,
      comp LIKE LINE OF comp_tab,
      i_tab TYPE REF TO cl_abap_tabledescr,
      i_table TYPE REF TO data.

DATA:
l_program_name   TYPE syrepid VALUE sy-repid,
l_structure_name TYPE tabname,
l_i_ct_fieldcat  TYPE slis_t_fieldcat_alv.


FIELD-SYMBOLS:
<f_tab1> TYPE STANDARD TABLE.

PARAMETERS:
p_tname TYPE tabname16 OBLIGATORY, " DEFAULT 'MARA' ,
p_rows(5) TYPE c DEFAULT '200'.

tab ?= cl_abap_typedescr=>describe_by_name( p_tname ).
comp_tab = tab->get_components( ).
wa_tab  = cl_abap_structdescr=>create( comp_tab ).
i_tab   = cl_abap_tabledescr=>create( wa_tab ).
CREATE DATA i_table TYPE HANDLE i_tab.
*create data wa_table type handle wa_tab.
ASSIGN i_table->* TO <f_tab1>.
*assign wa_table->* to <f1>.

IF p_rows IS INITIAL.
  p_rows = '50000'.
ENDIF.

AT SELECTION-SCREEN.

  SELECT COUNT( * )
    FROM dd02l
    WHERE tabname  = p_tname
    AND   as4local = 'A'
    AND   tabclass = 'TRANSP'.
  IF sy-subrc <> 0.
    MESSAGE e001(00) WITH
    p_tname ' is not a Transparant Table'.
  ENDIF.




START-OF-SELECTION.
*Get data
  SELECT * FROM (p_tname)
  INTO TABLE <f_tab1>
  UP TO p_rows ROWS.

  IF sy-subrc <> 0.
    MESSAGE i000(z_zzz_ca_messages) WITH 'No data found'.
    LEAVE LIST-PROCESSING.
  ENDIF.

END-OF-SELECTION.

  SET TITLEBAR sy-title
  OF PROGRAM sy-cprog
  WITH 'Display table:'   p_tname.

  l_structure_name = p_tname.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name               = l_program_name
      i_internal_tabname           = 'I_TABLE'
      i_structure_name             = l_structure_name
      i_client_never_display       = 'X'
*   I_INCLNAME                   =
*   I_BYPASSING_BUFFER           =
*   I_BUFFER_ACTIVE              =
    CHANGING
      ct_fieldcat                  = l_i_ct_fieldcat
   EXCEPTIONS
     inconsistent_interface       = 1
     program_error                = 2
     OTHERS                       = 3
            .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program = l_program_name
        it_fieldcat        = l_i_ct_fieldcat
      TABLES
        t_outtab           = <f_tab1>
      EXCEPTIONS
        program_error      = 1
        OTHERS             = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDIF.

former_member212653
Active Contributor
0 Kudos
254

Another shorter one...


*&---------------------------------------------------------------------*
*& Report  ZDYNAMIC_ALV
*&
*&---------------------------------------------------------------------*

REPORT  ZDYNAMIC_ALV.

TYPE-POOLS: abap, slis.

DATA: tab TYPE REF TO cl_abap_structdescr,
      wa_tab TYPE REF TO cl_abap_structdescr,
      comp_tab   TYPE cl_abap_structdescr=>component_table,
      comp LIKE LINE OF comp_tab,
      i_tab TYPE REF TO cl_abap_tabledescr,
      i_table TYPE REF TO data.

DATA:
l_program_name   TYPE syrepid VALUE sy-repid.

FIELD-SYMBOLS:
<f_tab1> TYPE STANDARD TABLE.

PARAMETERS:
p_tname TYPE tabname16 OBLIGATORY DEFAULT 'SBOOK' ,
p_rows(5) TYPE c DEFAULT '200'.

tab ?= cl_abap_typedescr=>describe_by_name( p_tname ).
comp_tab = tab->get_components( ).
wa_tab  = cl_abap_structdescr=>create( comp_tab ).
i_tab   = cl_abap_tabledescr=>create( wa_tab ).
CREATE DATA i_table TYPE HANDLE i_tab.
*create data wa_table type handle wa_tab.
ASSIGN i_table->* TO <f_tab1>.
*assign wa_table->* to <f1>.

IF p_rows IS INITIAL.
  p_rows = '50000'.
ENDIF.

AT SELECTION-SCREEN.

  SELECT COUNT( * )
    FROM dd02l
    WHERE tabname  = p_tname
    AND   as4local = 'A'
    AND   tabclass = 'TRANSP'.
  IF sy-subrc <> 0.
    MESSAGE e001(00) WITH
    p_tname ' is not a Transparant Table'.
  ENDIF.

START-OF-SELECTION.
*Get data
  SELECT * FROM (p_tname)
  INTO TABLE <f_tab1>
  UP TO p_rows ROWS.

  IF sy-subrc <> 0.
    MESSAGE i000(z_zzz_ca_messages) WITH 'No data found'.
    LEAVE LIST-PROCESSING.
  ENDIF.

END-OF-SELECTION.

  SET TITLEBAR sy-title
  OF PROGRAM sy-cprog
  WITH 'Display table:'   p_tname.

  DATA: l_gr_alv TYPE REF TO cl_salv_table.
  data: l_gr_functions type ref to cl_salv_functions.
  TRY.
      CALL METHOD cl_salv_table=>factory
        IMPORTING
          r_salv_table   = l_gr_alv
        changing
          t_table        = <f_tab1>
          .
    CATCH cx_salv_msg .
  ENDTRY.
  l_gr_functions = l_gr_alv->get_functions( ).
  l_gr_functions->set_all( abap_true ).
  l_gr_alv->display( ).