Skip to Content
Technical Articles
Author's profile photo Joachim Rees

Method Display_data – but don’t dump! version 2

So I have this method, that lets me display any table in an ALV.
And it it’s a “deep” table – a field of a table-line being a table itself – those fields are dropped. (They are not displayed, but all the other fields are. Way better than a dump!)

You can see it here: .

But, like most things, it’s work in progress, it can and has to be improved over time.

A need for improvement might be this code:

    TYPES: BEGIN OF  ty_hus_to_move.
             INCLUDE TYPE  /scwm/s_huitm_int AS huitm.
    TYPES: END OF ty_hus_to_move,
    tyt_hus_to_move TYPE STANDARD TABLE OF ty_hus_to_move WITH NON-UNIQUE KEY guid_parent.
    DATA lt_tt_quan_string TYPE tyt_hus_to_move.

    INSERT INITIAL LINE INTO lt_tt_quan_string INDEX 1.
    display_data_deep_enabled( lt_tt_quan_string ).

Try it out.
It will dump.

But: Changing only 2 lines will make it work again. And has improved my method.

*    DATA(lt_components_with_ref) = lo_struct_descr->get_components( ).
    DATA(lt_components_with_ref) = lo_struct_descr->get_included_view( ).

*    lo_struct_descr = cl_abap_structdescr=>create( p_components = lt_components_with_ref ).
    lo_struct_descr = cl_abap_structdescr=>create( p_components = CORRESPONDING #( lt_components_with_ref ) ).

lo_struct_descr->get_components code just gave me one line with is_include = X.
lo_struct_descr->get_included_view gives me ALL the components – it resolves the include.

The structure is a litte different:

name type string
type type ref to cl_abap_datadescr

name type string
type type ref to cl_abap_datadescr
as_include type abap_bool
suffix type string

-> The relevant fields – NAME and TYPE – a the same, so CORRESPONDING # is doing fine.

Full new code:

  METHOD display_data_deep_enabled.
    DATA lo_table_descr  TYPE REF TO cl_abap_tabledescr.
    DATA lo_struct_descr TYPE REF TO cl_abap_structdescr.

    lo_table_descr ?= cl_abap_tabledescr=>describe_by_data( it_data ).
    lo_struct_descr ?= lo_table_descr->get_table_line_type( ). " note: this will  fail if it's a single-coloum-table.

    DATA(lt_components_with_ref) = lo_struct_descr->get_included_view( ). 
    DATA(lt_components_simple_tab) = lo_struct_descr->components.

    LOOP AT lt_components_simple_tab ASSIGNING FIELD-SYMBOL(<component>)
         WHERE type_kind = cl_abap_tabledescr=>typekind_table.
      DELETE lt_components_with_ref WHERE name = <component>-name.

    " New Structure + Table.
    lo_struct_descr = cl_abap_structdescr=>create( p_components = CORRESPONDING #( lt_components_with_ref ) ).
    lo_table_descr = cl_abap_tabledescr=>create( p_line_type = lo_struct_descr ).
    DATA lt_new TYPE REF TO data.
    " Create the Data-Ref of the new Type.
    CREATE DATA lt_new TYPE HANDLE lo_table_descr.
    " Fill it with data:
    lt_new->* = CORRESPONDING #( it_data ).

        cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lref_alv)
                                CHANGING  t_table      = lt_new->*  ).
      CATCH cx_salv_msg.

    lref_alv->get_layout( )->set_key( VALUE #( report = sy-repid ) ).
    lref_alv->get_layout( )->set_default( abap_true ).
    lref_alv->get_layout( )->set_save_restriction( if_salv_c_layout=>restrict_none ).
    lref_alv->get_functions( )->set_all( abap_true ).
    lref_alv->display( ).

What do you think?


Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.