Start of Content Area

Function documentation ALV Output Display  Locate the document in its SAP Library 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.

Examples

Example of a Simple, Two-Dimensional Table

The following example shows the simplest call of a table of type SFLIGHT. The  gt_outtab table is the table with your application data and the 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, the position level from the SFLIGHT table. Its columns are transferred into the table with your application data: gt_parent or gt_child.

·        Both tables contain the column CARRID that is used to form the foreign key relationship.

·        gr_table is the reference to the ALV output class 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 type SFLIGHT. The gt_outtab2table is an empty table that only provides the structure of the tree. The table gt_outtab1is the table that includes the desired data records..

gr_treeis the reference to the ALV output class 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( ).

 

 

 

End of Content Area