Thursday, March 10, 2011

ALV Object Model (OM)

Hi Guys, so far at least there are different types of approach in developing or creating an ALV depending on your needs and objective. One of them is called ALV Object Model which has been around for some time. This type of ALV can be created using a cl_salv_table class - a wrapper class of the previous ALV classes.


Below is an excerpt taken from other sources that can be a starting guide to create this type of ALV

report zrich_0001.


data:  ispfli type table of spfli.

data: salv_table type ref to cl_salv_table.
data: salv_functions type ref to cl_salv_functions_list.
data: salv_text type  ref to cl_salv_form_text.
data: salv_label type ref to cl_salv_form_label.
data: salv_grid type  ref to cl_salv_form_layout_grid.

start-of-selection.

  select * into corresponding fields of table ispfli from spfli
              up to 100 rows.

  call method cl_salv_table=>factory
    exporting
      list_display = if_salv_c_bool_sap=>false
    importing
      r_salv_table = salv_table
    changing
      t_table      = ispfli.


  salv_functions = salv_table->get_functions( ).
  salv_functions->set_all( abap_true ).


  create object salv_grid.

  salv_label = salv_grid->create_label(
               text   = '1.1 LABEL'
               row    = 1
               column = 1 ).

  salv_text = salv_grid->create_text(
              text   = '1.2 TEXT'
              row    = 1
              column = 2 ).

  salv_label->set_label_for( salv_text ).

  salv_text = salv_grid->create_text(
              text   = '2.2 TEXT'
              row    = 2
              column = 2 ).
  salv_table->set_top_of_list( salv_grid ).



* Display
  salv_table->display( ).

No comments:

Post a Comment