Show TOC

ALV Output DisplayLocate this document in the navigation structure

Use

To display the ALV output on the screen, it is sufficient to use two methods of the ALV object model:

  • FACTORY You instantiate the main ALV class:

    • You define the internal data table that provides the structure and content of the ALV output, as needed.

    • You define which display type you want to use for the ALV output.

  • DISPLAY To display the ALV output on the screen, call up the method DISPLAY afterwards.

Example

Example of a Simple, Two-Dimensional Table

The following example shows the simplest call of a table of type SFLIGHT. Table gt_outtab is the table with your application data and gr_table is the reference to the ALV main class to be used.

data: gt_outtab type table of SFLIGHT.
data: gr_table type ref to cl_salv_table.

*... Select Data
  select * from SFLIGHT into corresponding fields of table gt_outtab.

*... Create Instance
  call method cl_salv_table=>factory
   IMPORTING
    R_SALV_TABLE = gr_table
   changing
    t_table = gt_outtab.

*... Display Table
  gr_table->display( ).


            

Example of a Hierarchical-Sequential List

The following example shows the simples call of a hierarchical-sequential list.

  • The header level comes from the SCARR table, while the item level comes from the SFLIGHT table. Their columns are transferred to the tables for your application data: gt_ parent or gt_ child .

  • Both tables contain the CARRID column, upon which the foreign key relationship is built.

  • gr_table is the reference to the ALV output class that is to be used.

data: gt_parent type table of SCARR.
data: gt_child type table of SFLIGHT.
data: gr_table  type ref to cl_salv_hierseq_table.
data: lt_binding type salv_t_hierseq_binding.
data: ls_binding type salv_s_hierseq_binding.

*... Select Data
  select * from SCARR into corresponding fields of table gt_parent.
  select * from SFLIGHT into corresponding fields of table gt_child. 

*... Bind Parent and Child Table
  ls_binding-master = 'CARRID'.
  ls_binding-slave  = 'CARRID'.
  append ls_binding to lt_binding.

*... Create Instance
  call method cl_salv_hierseq_table=>factory
   exporting
    t_binding_level1_level2 = lt_binding
   importing
    r_hierseq = gr_table
   changing
    t_table_level1 = gt_parent
    t_table_level2 = gt_child.

*... Display Table
  gr_table->display( ).

            

Example of a Tree Structure

The following example shows the simplest call of a tree structure of the SFLIGHT type. The gt_outtab2 table is an empty table that only provides the structure of the tree. The table gt_outtab1 is the table that includes the desired data records..

gr_tree reference to the ALV output class that is to be used.

data: gt_outtab1 type table of sflight,
      gt_outtab2 type table of sflight.
data: ls_outtab type sflight.
data: gr_tree  type ref to cl_salv_tree.
data: nodes type ref to cl_salv_nodes,
      node type ref to cl_salv_node.

*... Select Data
  select * from sflight into corresponding fields of table gt_outtab1 up to 5 rows. 

*... Create Instance with an Empty Table
  call method cl_salv_tree=>factory
   IMPORTING
    R_SALV_TREE = gr_tree
   changing
    t_table      = gt_outtab2.

*... Add the Nodes to the Tree
  nodes = gr_tree->get_nodes( ).
  loop at gt_outtab1 into ls_outtab.
   try.
    node = nodes->add_node( related_node = key
                            relationship = cl_gui_column_tree=>relat_first_child ).
    node->set_data_row( ls_outtab ).
    catch cx_salv_msg.
   endtry.
  endloop.

*... Display Table
  gr_tree->display( ).