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

Method Display_data – but don’t dump!

I am am using my display_data-method quite often.

And every now and then, I stumbled over a dump, e.g. wenn the table provided was “deep” -> included other components that where themselves tables.

I often thought: If we could just drop those columns but display all the others – would’t that be nice?!
But I never created the thing.
Until now.

So here it is:

(Edit: it was improved a little here: https://blogs.sap.com/2023/09/13/method-display_data-but-dont-dump-version-2/ )

METHODS display_data_deep_enabled IMPORTING it_data TYPE ANY TABLE.
  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 might fail if it's a single-coloum-Table.

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

    "find and remove the components that would hurt us (that is: dump)
    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.
    ENDLOOP.

    " New Structure + Table.
    lo_struct_descr = cl_abap_structdescr=>create( p_components = 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 ).

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

    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( ).
  ENDMETHOD.

Bonus:

– This made me use / (again) learn about the ABAP RTTS (RTTI + RTTC)
– It always bothered me a bit, that that parameter to display_data had to be a CHANGING one. Now it’s IMPORTING. Feels way better.

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Yash Singh
      Yash Singh

      Definitely a nice workaround. But can't we just make those columns technical? 🤔

      Author's profile photo Joachim Rees
      Joachim Rees
      Blog Post Author

      Thanks for the feedback an the idea! That might well be another solution, yes. (Feel free to try it out and share, if you like!?)