Simply display internal table into ALV grid

Simply display internal table into ALV grid

To display content of internal table into ALV grid, use this method :


  DATA : lo_table     TYPE REF TO cl_salv_table.

* Create ALV
  TRY.
      cl_salv_table=>factory(
        IMPORTING
          r_salv_table = lo_table
        CHANGING
          t_table      = gi_data_to_display ).
    CATCH cx_salv_msg.
  ENDTRY.

* Display ALV grid
  lo_table->display( ).

Example of use in SAP demo program : SALV_DEMO_TABLE_REAL_SIMPLE.

Add a toolbar in the ALV :


 DATA : lo_table     TYPE REF TO cl_salv_table,
         lr_functions TYPE REF TO cl_salv_functions_list,
         lr_columns   TYPE REF TO cl_salv_columns_table,
         lr_column    TYPE REF TO cl_salv_column_table.

* Create ALV
  IF lo_table IS NOT BOUND. "si l'objet alv n'a pas encore été crée
    TRY.
        cl_salv_table=>factory(
          IMPORTING
            r_salv_table = lo_table
          CHANGING
            t_table      = gt_alv ).
      CATCH cx_salv_msg.
    ENDTRY.
    TRY.
        CALL METHOD lo_table->set_screen_status
          EXPORTING
            report        = sy-cprog
            pfstatus      = 'ZSTANDARD'
            set_functions = lo_table->c_functions_all.
      CATCH cx_salv_msg.
    ENDTRY.

    "Mise en forme de l'ALV

    lr_functions = lo_table->get_functions( ).
    lr_functions->set_all( 'X' ).
    lr_columns = lo_table->get_columns( ).
    lr_columns->set_optimize( abap_true ).

* Display ALV grid
    lo_table->display( ).

  ENDIF.

About the author

fjourneau administrator

Hi, I'm Florian Journeau, SAP ABAP R3 Freelance, based in Toulouse, France. You want to know more about me, have a look on my CV : cv.fjourneau.net.

3 Comments so far

f.s.Posted on11:51 am - Aug 5, 2020

Exactly what I needed!
Cheers!
f.s.

ClemclemPosted on4:30 pm - Nov 18, 2024

Mieux que ChatGPT, je recommande.

Leave a Reply