Skip to Content

Overview

     This document provide step-by-step instructions to manipulate the column settings of ALV grid created using SALV_WD_TABLE component.  Column settings which can be controlled by standard ALV settings are not covered here.  Following column settings can be controlled by end-user by the Editable field catalog provided to the user.

  • Column Heading
  • Column Tooltip
  • Column Width
  • Toggling between TextView(Read only) & Input field (Editable)

Scenario

     User inputs, Order date (Select-options), Sales Organization (Parameter), Document category (parameter) has been received using the re-usable Web Dynpro component WDR_SELECT_OPTIONS. Sales order data is extracted through assistance class and output table data displayed as ALV grid using re-usable Web Dynpro component SALV_WD_TABLE.

     Field catalog of ALV grid is displayed in an editable table control, where end user can change the column properties mentioned above.  Updated properties will be reflected in the ALV grid.

Steps

  • Component & used components assignments

    image1.JPG

    image1.JPG


  • Component controller Contexts
    • Node : Range_Date – Select options for Order date
    • Node : Input – Parameters for Sales organization (VKORG) and Document Category (VBTYP)
    • Node : Sotab – Table for ALV output
    • Node : ALV – Field catalog for ALV output With following attributes
      • ID – String
      • COL_HEAD – String
      • TOOLTIP – String
      • EDITABLE – Wdy_boolean
      • WIDTH – String

image1.JPG

image1.JPG

  • Component controller Methods
    • WDDOINIT – Controller Initialization Method
    • METHOD wddoinit .
      DATA : lo_cmp_usage TYPE REF TO if_wd_component_usage,
                lo_interfacecontroller TYPE REF TO iwci_wdr_select_options,
                lv_r_helper_class TYPE REF TO if_wd_select_options.
      DATA : lt_range_table TYPE REF TO data,
                lv_block       TYPE string VALUE 'B1',
                lr_vkorg       TYPE REF TO data,
                lr_vbtyp       TYPE REF TO data.
      FIELD-SYMBOLS : <fs_vkorg> TYPE vkorg,
                         <fs_vbtyp> TYPE vbtyp.
      CREATE DATA : lr_vkorg TYPE vkorg,
                       lr_vbtyp TYPE vbtyp.
      ASSIGN lr_vkorg->* TO <fs_vkorg>.
         <fs_vkorg> = '1000'.
      ASSIGN lr_vbtyp->* TO <fs_vbtyp>.
         lo_cmp_usage =   wd_this->wd_cpuse_select_options( ).
      IF lo_cmp_usage->has_active_component( ) IS INITIAL.
           lo_cmp_usage->create_component( ).
         ENDIF.
         lo_interfacecontroller =   wd_this->wd_cpifc_select_options( ).
         lv_r_helper_class = lo_interfacecontroller->init_selection_screen( ).
      ** Select options for Range_date **
         lt_range_table = lv_r_helper_class->create_range_table(
             i_typename     = 'AUDAT' ).
         lv_r_helper_class->add_block(
             i_id                     = lv_block
             i_title                  = 'Selection Screen'
             i_width                  = '50%' ).
         lv_r_helper_class->add_selection_field(
           i_id                         = wd_this->wdctx_range_date
           i_within_block               = lv_block
           it_result                    = lt_range_table ).
      ** Parameters for VKORG and VBTYP **
         lv_r_helper_class->add_parameter_field(
             i_id                         = 'VKORG'
             i_within_block               = lv_block
             i_value                      = lr_vkorg ).
         lv_r_helper_class->add_parameter_field(
             i_id                         = 'VBTYP'
             i_within_block               = lv_block
             i_value                      = lr_vbtyp ).
      ** Field catalog & ALV settings **
      DATA : lt_column_ref TYPE salv_wd_t_column_ref,
                ls_column_ref TYPE salv_wd_s_column_ref.
      DATA : lv_value                TYPE REF TO cl_salv_wd_config_table,
                lo_interfacecontroller1 TYPE REF TO iwci_salv_wd_table,
                lo_ui                   TYPE REF TO cl_salv_wd_uie,
                lo_col_header           TYPE REF TO cl_salv_wd_column_header,
                lo_input                TYPE REF TO cl_salv_wd_uie_input_field,
                lo_textview             TYPE REF TO cl_salv_wd_uie_text_view.
      DATA : lo_alv TYPE REF TO if_wd_context_node.
      DATA : lt_alv TYPE wd_this->elements_alv,
                ls_alv TYPE wd_this->element_alv.
      CLEAR : lo_cmp_usage.
         lo_cmp_usage =   wd_this->wd_cpuse_alv( ).
      IF lo_cmp_usage->has_active_component( ) IS INITIAL.
           lo_cmp_usage->create_component( ).
         ENDIF.
         lo_interfacecontroller1 =   wd_this->wd_cpifc_alv( ).
         lv_value = lo_interfacecontroller1->get_model( ).
      ** Set number of lines **
         lv_value->if_salv_wd_table_settings~set_visible_row_count( 7 ).
      ** Get column properties **
         lt_column_ref = lv_value->if_salv_wd_column_settings~get_columns( ).
      LOOP AT lt_column_ref INTO ls_column_ref.
      ** Column Name **
           ls_alv-id       = ls_column_ref-id.
      ** Column Header text & Tooltip **
           lo_col_header   = ls_column_ref-r_column->get_header( ).
           ls_alv-col_head = lo_col_header->get_text( ).
           ls_alv-tooltip  = lo_col_header->get_tooltip( ).
      ** Column Width **
           ls_alv-width    = ls_column_ref-r_column->get_width( ).
           lo_ui = ls_column_ref-r_column->get_cell_editor( ).
      IF lo_ui->editor EQ if_salv_wd_c_column_settings=>cell_editor_text_view.
             ls_alv-editable = abap_false.
      ELSEIF lo_ui->editor EQ if_salv_wd_c_column_settings=>cell_editor_input_field.
             ls_alv-editable = abap_true.
           ENDIF.
      APPEND ls_alv TO lt_alv.
         ENDLOOP.
         lo_alv = wd_context->get_child_node( wd_this->wdctx_alv ).
         lo_alv->bind_elements( lt_alv ).
       ENDMETHOD.
    • GET_REPORT – Get ALV data

      METHOD get_report .
      DATA : lo_cmp_usage TYPE REF TO if_wd_component_usage,
                lo_interfacecontroller TYPE REF TO iwci_wdr_select_options,
                lv_r_helper_class TYPE REF TO if_wd_select_options,
                lo_sotab     TYPE REF TO if_wd_context_node.
      DATA : lt_fields TYPE if_wd_select_options=>tt_selection_screen_item,
                lt_sotab  TYPE wd_this->elements_sotab.
      FIELD-SYMBOLS : <fs_fields> TYPE LINE OF if_wd_select_options=>tt_selection_screen_item,
                         <fs_range_date> TYPE wd_this->elements_range_date,
                         <fs_vkorg> TYPE vkorg,
                         <fs_vbtyp> TYPE vbtyp.
         lo_cmp_usage =   wd_this->wd_cpuse_select_options( ).
      IF lo_cmp_usage->has_active_component( ) IS INITIAL.
           lo_cmp_usage->create_component( ).
         ENDIF.
         lo_interfacecontroller =   wd_this->wd_cpifc_select_options( ).
         lv_r_helper_class = lo_interfacecontroller->init_selection_screen( ).
         lv_r_helper_class->check_selection_screen( ).
         lv_r_helper_class->get_selection_fields(
      IMPORTING
             et_fields = lt_fields ).
      LOOP AT lt_fields ASSIGNING <fs_fields>.
      IF <fs_fields>-m_id = wd_this->wdctx_range_date.
      ASSIGN <fs_fields>-mt_range_table->* TO <fs_range_date>.
           ENDIF.
         ENDLOOP.
         lv_r_helper_class->get_parameter_fields(
      IMPORTING
             et_fields = lt_fields ).
      LOOP AT lt_fields ASSIGNING <fs_fields>.
      CASE <fs_fields>-m_id.
      WHEN 'VKORG'.
      ASSIGN <fs_fields>-m_value->* TO <fs_vkorg>.
      WHEN 'VBTYP'.
      ASSIGN <fs_fields>-m_value->* TO <fs_vbtyp>.
           ENDCASE.
         ENDLOOP.
         lt_sotab = wd_assist->get_so_details_vkorg(
             date_range = <fs_range_date>
             vkorg      = <fs_vkorg>
             vbtyp      = <fs_vbtyp> ).
         lo_sotab = wd_context->get_child_node( wd_this->wdctx_sotab ).
         lo_sotab->bind_elements( lt_sotab ).
         no_records = LINES( lt_sotab ).
       ENDMETHOD.
    • REFRESH_ALV_SETTINGS – Apply column settings to ALV Grid display
    • METHOD refresh_alv_settings .
      DATA : lo_alv    TYPE REF TO if_wd_context_node,
                lo_alv_el TYPE REF TO if_wd_context_element.
      DATA : lt_alv TYPE wd_this->elements_alv,
                ls_alv TYPE wd_this->element_alv,
                lt_set TYPE wdr_context_element_set.
         lo_alv = wd_context->get_child_node( wd_this->wdctx_alv ).
         lt_set = lo_alv->get_elements( ).
      LOOP AT lt_set INTO lo_alv_el.
           lo_alv_el->get_static_attributes(
      IMPORTING
               static_attributes = ls_alv ).
      APPEND ls_alv TO lt_alv.
         ENDLOOP.
      ** Refresh ALV Settings **
      DATA : lo_cmp_usage           TYPE REF TO if_wd_component_usage,
                lo_interfacecontroller TYPE REF TO iwci_salv_wd_table,
                lo_value               TYPE REF TO cl_salv_wd_config_table,
                lo_column              TYPE REF TO cl_salv_wd_column,
                lo_header              TYPE REF TO cl_salv_wd_column_header,
                lo_input               TYPE REF TO cl_salv_wd_uie_input_field,
                lo_textview            TYPE REF TO cl_salv_wd_uie_text_view,
                lo_alv_uie             TYPE REF TO if_salv_wd_table_cell_editor.
      DATA : ls_bind                TYPE cl_salv_wd_a_header=>s_type_ddic_binding.
         lo_cmp_usage =   wd_this->wd_cpuse_alv( ).
      IF lo_cmp_usage->has_active_component( ) IS INITIAL.
           lo_cmp_usage->create_component( ).
         ENDIF.
         lo_interfacecontroller =   wd_this->wd_cpifc_alv( ).
         lo_value = lo_interfacecontroller->get_model( ).
         lo_value->if_salv_wd_table_settings~set_edit_mode( ).
         lo_value->if_salv_wd_table_settings~set_read_only( abap_false ).
         lo_value->if_salv_wd_table_settings~set_fixed_table_layout( abap_false ).
      LOOP AT lt_alv INTO ls_alv.
           lo_column = lo_value->if_salv_wd_column_settings~get_column(
      id     = ls_alv-id ).
      IF ls_alv-width GT 0.
             lo_column->set_resizable( abap_true ).
             lo_column->set_width( ls_alv-width ).
           ENDIF.
           lo_header = lo_column->get_header( ).
           lo_header->set_prop_ddic_binding_field(
      EXPORTING
      property = if_salv_wd_c_ddic_binding=>bind_prop_text
      value    = if_salv_wd_c_ddic_binding=>ddic_bind_none ).
           lo_header->set_text( ls_alv-col_head ).
           lo_header->set_tooltip( ls_alv-tooltip ).
      ** Set Input field/Text view **
      IF ls_alv-editable = abap_true.
      CREATE OBJECT lo_input
      EXPORTING
                 value_fieldname = ls_alv-id.
             lo_input->set_read_only( abap_false ).
             lo_alv_uie = lo_input.
             lo_column->set_cell_editor( lo_alv_uie ).
           ELSE.
      CREATE OBJECT lo_textview.
             lo_textview->set_text_fieldname( ls_alv-id ).
             lo_alv_uie = lo_textview.
             lo_column->set_cell_editor( lo_alv_uie ).
           ENDIF.
       ENDLOOP.
      ENDMETHOD.
  • Views – V_MAIN
    • Layout

image1.JPG

    • onAction Event of “Report” Button – GET_DATA
    • METHOD onactionget_data .
      DATA : lv_rec TYPE int2.
         lv_rec = wd_comp_controller->get_report( ).
       ENDMETHOD.
  • Views – V_ALV
    • Layout
    • image1.JPG
    • onAction Event of “Report” Button – REFRESH_ALV
    • METHOD onactionrefresh_alv .
         wd_comp_controller->refresh_alv_settings( ).
       ENDMETHOD.
  • Windows – W_MAIN

    image1.JPG

Output

image1.JPG

Exclusions

  • Further activities for input fields in ALV ( data check etc., ) not mentioned in the document
  • Dynamic display of ALV buttons (check/append/insert/delete) not mentioned in the document
To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply