Saturday, March 31, 2012
The ALV output is read-only by default. To allow users to change or enter new data then you have to make
some changes to the standard settings.
Procedure
  • The write-protection for the ALV output must be deactivated before these actions can be executed.
  • lv_value->IF_SALV_WD_TABLE_SETTINGS~SET_READ_ONLY( ABAP_FALSE ).
    
  • The ALV output uses TextView as the cell editor for displaying data by default. To make it possible for users to enter or change existing data, replace this interface element with an interactive interface element, such as InputField.
  •   LOOP AT lt_column INTO ls_column.
        CASE ls_column-id.
          WHEN 'STRAS'.
            CREATE OBJECT lr_input_field
              EXPORTING
                value_fieldname = ls_column-id.
            ls_column-r_column->set_cell_editor( lr_input_field ).
        ENDCASE.
    
  • The user can add rows at a specific position, attach them to the end of the ALV output, and delete them.
  • It is also possible to attach a whole page of empty rows, not only individual rows, to make it possible to enter mass data.
  • You must also define the time at which the system checks whether changed data is correct.
  • If the user changes or creates new data then it might be necessary to refresh the data manually or you might only want to refresh that data and not the whole ALV output.
Program with steps
  • Create Web Dynpro Component with Window and View(Automatically View is embedded into Window). 
  • Define Component Use ALV for the Used component SALV_WD_TABLE under Used Components tab of Web Dynpro Component.
  • Go to Component Controller COMPONENTCONTROLLER
    • Properties tab->Define or Include Used Controllers/ Components of ALV.
 
    • Context tab->Create PA0006 node with cardinality 0..n.
    • Methods tab->Write the code in WDDOINIT to populate data in ALV.
    • WDDOINIT method code
    • METHOD wddoinit .
        "Get data
        wd_this->get_data(  ).
      ENDMETHOD.
      
    • GET_DATA method code.
    • method get_data .
      
          data lo_nd_pa0006 type ref to if_wd_context_node.
          data lt_pa0006    type wd_this->elements_pa0006.
          "Navigate from <CONTEXT> to <PA0006> via lead selection
          lo_nd_pa0006 = wd_context->get_child_node( name = wd_this->wdctx_pa0006 ).
          "Get data
          select *
            from pa0006
            into corresponding fields of table lt_pa0006
            up to 10 rows
            where stras ne space.
      
          lo_nd_pa0006->bind_table( new_items = lt_pa0006 set_initial_elements = abap_true ).
      
      endmethod.
      
    • CHANGE_ALV_CONFIG method to change ALV configuration and make ALV table cell editable. This method would be called from view CELL_EDIT_V hook method WDDOINIT.
    • METHOD change_alv_config .
        "Create an instance of ALV component
        DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.
        lo_cmp_usage =   wd_this->wd_cpuse_alv( ).
        "If not initialized, then initialize
        IF lo_cmp_usage->has_active_component( ) IS INITIAL.
          lo_cmp_usage->create_component( ).
        ENDIF.
        "Create an instance of ALV Interface Controller
        DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .
        lo_interfacecontroller =   wd_this->wd_cpifc_alv( ).
        "Configuration of the ALV Output
        DATA lv_value TYPE REF TO cl_salv_wd_config_table.
        lv_value = lo_interfacecontroller->get_model( ).
      
        DATA:
              lr_column_settings TYPE REF TO if_salv_wd_column_settings,
              lr_input_field     TYPE REF TO cl_salv_wd_uie_input_field.
        DATA:
             lt_column           TYPE salv_wd_t_column_ref,
             ls_column           TYPE salv_wd_s_column_ref.
      
        "Casting
        lr_column_settings ?= lv_value.
        "Get columns
        lt_column       = lr_column_settings->get_columns( ).
        LOOP AT lt_column INTO ls_column.
          CASE ls_column-id.
            WHEN 'STRAS'.
              CREATE OBJECT lr_input_field
                EXPORTING
                  value_fieldname = ls_column-id.
              ls_column-r_column->set_cell_editor( lr_input_field ).
          ENDCASE.
        ENDLOOP.
        "Set read only mode to false (and display edit toolbar)
        DATA: lr_table_settings TYPE REF TO if_salv_wd_table_settings.
        lr_table_settings ?= lv_value.
        lr_table_settings->set_read_only( abap_false ).
      
      ENDMETHOD.
      
  • Go to view CELL_EDIT_V
    • -Layout tab->Create View Container UI element to display ALV output. 
    • Methods tab->WDDOINIT method.
    • method WDDOINIT .
        DATA:
              lo_componentcontroller TYPE REF TO ig_componentcontroller .
        lo_componentcontroller =   wd_this->get_componentcontroller_ctr( ).
        lo_componentcontroller->change_alv_config(  ).
      
      endmethod.
      
  • Go to INTERFACECONTROLLER_USAGE of ALV->Map Context node PA0006 of component controller to DATA of ALV Interface Controller. 
  • Go to window CELL_EDIT_W->Embed TABLE view of SALV_WD_TABLE component in window as shown in the screen.
  • Activate Web Dynpro component.
  • Create Web Dynpro Application and Save it as local object. 
  • Run web dynpro application. 

1 comment:

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.