cancel
Showing results for 
Search instead for 
Did you mean: 

ALV EDITABLE IN WEBDYNPRO ABAP

Former Member
0 Kudos

Hi Experts,

I working on ALV Webdynpro abap for the first time ,I have have 5 records in a table and when i come on to screen first record should be editable and i need a button called ADD ROW when i click on the button one record should be add to the alv table in editable mode.

In this table i have 5 cloumns one is INPUT FIELD, TEXT VIEW,DROPDOWNBYKEY,& BUTTON.When i click on ADD ROW BUTTON everything should in editable mode.

Please Provided me Required information.

Waiting for the Reply.

Thanks & Regards

Krishna,

Accepted Solutions (0)

Answers (4)

Answers (4)

0 Kudos

Hello All,

I also faced similar problem, Most of the posts replies goes out of topic. Just to keep it simple, I would like to categorize it like this.

ALV always creates all the columns as TextView. So common to all, we must change the cell editor of columns to make individual column editable

There are two ways of doing it

Way1: Get object of individual column and set editor to input field

For example i want to make my client column editable in alv (MANDT)

Write below code


data : lr_inp type REF TO cl_salv_wd_uie_input_field.

   create OBJECT lr_inp

     exporting

       value_fieldname = 'MANDT'

     .

   lv_value->if_salv_wd_column_settings~get_column( 'MANDT' )->set_cell_editor( value lr_inp ).


Way2: Use standard API to make the cell editor changes to ALV

cl_wsrs_tools_wd_alv_table=>set_table_column( EXPORTING

                                                               io_column              = <Pass Object of Column>

                                                               iv_editor_type          =  cl_wsrs_tools_wd_alv_table=>co_cell_editor-<choose your editor type like inpu field etc>

                                                               iv_read_only            = abap_true/abap_false

                                                               iv_column_text          = <header text>

       ).

Now comes to making rows editable

Case 1: To keep all the rows as read only use below method of model object

lv_value->if_salv_wd_table_settings~set_read_only( ABAP_TRUE ).

Case 2: When you want all the rows editable in an ALV and user can enter data wherever they want. Use below two methods of ALV model instance

**Allows mass edit of data

lv_value->if_salv_wd_table_settings~set_edit_mode( IF_SALV_WD_C_TABLE_SETTINGS=>edit_mode_mass ).

**Makes read only mode to false

   lv_value->if_salv_wd_table_settings~set_read_only( ABAP_FALSE ).

The advantage is, you don't need to worry about adding additional rows as and when user fills. ALV will automatically adds the rows.

Case 3: When you want only the filled rows to be editable use edit mode as STANDARD

**Allows mass edit of data

lv_value->if_salv_wd_table_settings~set_edit_mode( IF_SALV_WD_C_TABLE_SETTINGS=>edit_mode_standard ).

**Makes read only mode to false

   lv_value->if_salv_wd_table_settings~set_read_only( ABAP_FALSE ).


Case 4: When you want entire ALV in disable mode with some specific CELLS only enabled, we need to use additional fields in context of table node. For every table column attribute create another attribute with some name for eg. MANDT i create one more attribute MANDT_R of type WDY_BOOLEAN.


Now set the read only field name for this cell using below API call


cl_wsrs_tools_wd_alv_table=>set_table_column( EXPORTING

                                                               io_column              = <Pass Object of Column>

                                                               iv_editor_type          =  cl_wsrs_tools_wd_alv_table=>co_cell_editor-<choose your editor type like inpu field etc>

                                                               iv_read_only            = abap_true/abap_false

                                                               iv_column_text          = <header text>

                                                                iv_readonly_fieldname   = 'MANDT_R'

       ).


Now if you want only this cell to be editable. Use context programming to change the attribute flag value in that particular row to ABAP_FALSE.

Lets say i want to make MANDT cell to be enabled in 3 rd row


data : lo_element TYPE REF TO if_wd_context_Element.


lo_element = wd_context->get_child_node( 'TABLE_NODE_NAME' )->get_element( 3 ).

lo_element->SET_ATTRIBUTE(

Exporting

     Name = 'MANDT_R'

      Value = ABAP_FALSE

).


Webdynpro ALV is the most flexible control to show and edit mass data, We just need to use the right API.

Hope this helps.


Regards,

Anurag.

soldner
Participant
0 Kudos

@Anurug.

Thanks for the great overview.  Seems I will be doing some editable WD-ALVs also.

To see if I understand correctly:

CASE 2 allows all rows and columns to be editable, including empty ones.

CASE 4 is to allow some cells editable.  Is this for all rows or only selected rows?

Thanks!!

Former Member
0 Kudos

Hi,

if u want first column is in editable mode follow these steps.

steps.

1.u have pass dummy data like star(*) or space some times in the init method .

2. instantiate wd_salv interface ,and component controller get_model.

3. take the reference of the field and then create object according to ur requirement like (Button Dropdown etc).

4. set celleditor method.

sample code

" Get the component useage instance
  LO_CMP_USAGE = WD_THIS->WD_CPUSE_ALV_REQUEST_HEADER( ).  "ALV name in the component usage
  IF LO_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) IS INITIAL.
    LO_CMP_USAGE->CREATE_COMPONENT( ).
  ENDIF.
*--------------------------------------------------------------------*
  " Get the interface controller instance
  LO_INTERFACECONTROLLER = WD_THIS->WD_CPIFC_ALV_REQUEST_HEADER( ).
  LO_CONFIG = LO_INTERFACECONTROLLER->GET_MODEL( ).

-----------------------------------------------------------------------*
    "  Set the UI elements.
    LR_COLUMN_SETTINGS ?= LO_CONFIG.

    "  Get all the columns.
    LT_COLUMNS = LR_COLUMN_SETTINGS->GET_COLUMNS( ).

    " To set the fixed columns in the ALV and
    " to set dropdown values to the fields 'REQUEST_STATUS' 'REQUEST_TYPE'  'REQUEST_ACTION'
    LOOP AT LT_COLUMNS INTO LS_COLUMNS .

      CASE LS_COLUMNS-ID .

        WHEN 'REQUEST_TYPE' .  " Request Type
          " here it locked your column at the left side of the screen
          LS_COLUMNS-R_COLUMN->SET_FIXED_POSITION( CL_WD_ABSTR_TABLE_COLUMN=>E_FIXED_POSITION-LEFT ).
          CREATE OBJECT LR_DROPDOWN
            EXPORTING
              SELECTED_KEY_FIELDNAME = 'REQUEST_TYPE'.
          "   To set the field non-editable
          LR_DROPDOWN->SET_READ_ONLY( VALUE  = ABAP_TRUE ).
          "   To set the drop down to the field REQUEST_TYPE.
          LS_COLUMNS-R_COLUMN->SET_CELL_EDITOR( LR_DROPDOWN ).

Former Member
0 Kudos

Hi Vasu,

I am working on webdynpro abap alv, in my alv table they are 15 columns and i set visible columns as 5 columns and on scrolling i will get remaining columns.But here my requirement is i should freeze my 1 st columns and on scrolling remaining columns should move.

please provided me required information

Waiting fro Reply.

Thanks & Regards

Krishna.

Former Member
0 Kudos

Hi Kiran

To freeze 1 st column. You need to get the columns name, using if_salv_wd_column_settings~get_columns( ).

after that

lr_column_left =  l_table_left->if_salv_wd_column_settings~get_column( 'the name of column').

lr_column_left->set_fixed_position( cl_wd_abstr_table_column=>e_fixed_position-left)

lr_column_left is type ref to cl_salv_wd_column and l_table_left is  type ref to cl_salv_wd_config_table

i think u already done this.....

also you need to set your alv to show just a few of your columns in order to have the scroll bar.

in the same class cl_salv_wd_config_table you can use the interface if_salv_wd_table_settings~set_scrollable_col_count( X number).

if you have 15 columns you can set up ( x to be 5) and it will display the first 5 column and a scroll bar at the bottom.

Reward Points If it Reach ur requirement.

Thanks & Regards

Vasu Yadav

Former Member
0 Kudos

Hi Kiran

To freeze 1 st column. You need to get the columns name, using if_salv_wd_column_settings~get_columns( ).

after that

lr_column_left =  l_table_left->if_salv_wd_column_settings~get_column( 'the name of column').

lr_column_left->set_fixed_position( cl_wd_abstr_table_column=>e_fixed_position-left)

lr_column_left is type ref to cl_salv_wd_column and l_table_left is  type ref to cl_salv_wd_config_table

i think u already done this.....

also you need to set your alv to show just a few of your columns in order to have the scroll bar.

in the same class cl_salv_wd_config_table you can use the interface if_salv_wd_table_settings~set_scrollable_col_count( X number).

if you have 15 columns you can set up ( x to be 5) and it will display the first 5 column and a scroll bar at the bottom.

Reward Points If it Reach ur requirement.

Thanks & Regards

Vasu Yadav

Former Member
0 Kudos

sorry it is not for kiran for Kumar i hope u people can understand....

Former Member
0 Kudos

Hi Krishna,

for making webdynpro in to editable u need to have data first make sure about that .

other u can append one null record to the node.

*************************making alv editable*************

DATA : LO_CMP_USAGE           TYPE REF TO   IF_WD_COMPONENT_USAGE.

   DATA : LO_INTERFACECONTROLLER TYPE REF TO   IWCI_SALV_WD_TABLE.

   DATA : LO_CONFIG              TYPE REF TO   CL_SALV_WD_CONFIG_TABLE.

   DATA : LO_TABLE_SETTINGS      TYPE REF TO   IF_SALV_WD_TABLE_SETTINGS.

   DATA : LR_COLUMN_SETTINGS     TYPE REF TO   IF_SALV_WD_COLUMN_SETTINGS.

   DATA : LT_COLUMNS             TYPE          SALV_WD_T_COLUMN_REF.

   DATA : LS_COLUMNS             LIKE LINE OF  LT_COLUMNS.

   DATA : LR_input               TYPE REF TO   CL_SALV_WD_UIE_INPUT_FIELD.

 

*--------------------------------------------------------------------*

   " Get the component useage instance

   lo_cmp_usage =   wd_this->wd_cpuse_alvtable( ).

   IF lo_cmp_usage->has_active_component( ) IS INITIAL.

     lo_cmp_usage->create_component( ).

   ENDIF.

*-----------------------------------------------------------------------*

* get the interface controller instance using get model.

lo_interfacecontroller =   wd_this->wd_cpifc_alvtable( ).

   LO_CONFIG = lo_interfacecontroller->get_model).

  IF LO_CONFIG IS NOT INITIAL.

     " To get the dropdowns displayed Need to set the table to editable by using below statement

     LO_CONFIG->IF_SALV_WD_TABLE_SETTINGS~SET_READ_ONLY( ABAP_FALSE ).

    

     LO_CONFIG->IF_SALV_WD_STD_FUNCTIONS~SET_EDIT_APPEND_ROW_ALLOWED( ABAP_FALSE ).

   

     LO_CONFIG->IF_SALV_WD_STD_FUNCTIONS~SET_EDIT_INSERT_ROW_ALLOWED( ABAP_FALSE ).

     LO_CONFIG->IF_SALV_WD_STD_FUNCTIONS~SET_EDIT_DELETE_ROW_ALLOWED( ABAP_FALSE ).

     LO_CONFIG->if_salv_wd_table_settings~set_read_only( abap_false ).

*******************

      "  Set the UI elements.

     LR_COLUMN_SETTINGS ?= LO_CONFIG.

     "  Get all the columns.

     LT_COLUMNS = LR_COLUMN_SETTINGS->GET_COLUMNS( ).

     LOOP AT LT_COLUMNS INTO LS_COLUMNS .

        CASE LS_COLUMNS-ID .

          WHEN 'VBELN' .

*          LS_COLUMNS-R_COLUMN->SET_FIXED_POSITION( CL_WD_ABSTR_TABLE_COLUMN=>E_FIXED_POSITION-LEFT ).

          CREATE OBJECT lr_input

            EXPORTING

              value_fieldname = LS_COLUMNS-id  .

           "   To set the drop down to the field REQUEST_TYPE.

           LS_COLUMNS-R_COLUMN->SET_CELL_EDITOR( Lr_input ).

ENDIF.

***********************************************************

after you can create a button on webdynpro alv

please look this code...

*****instantiate used components.

  DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.

  lo_cmp_usage =   wd_this->wd_cpuse_alvtable( ).

  IF lo_cmp_usage->has_active_component( ) IS INITIAL.

    lo_cmp_usage->create_component( ).

  ENDIF.

*** method used in componet

DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .

lo_interfacecontroller =   wd_this->wd_cpifc_alvtable( ).

  DATA lv_value TYPE REF TO cl_salv_wd_config_table.

  lv_value = lo_interfacecontroller->get_model(  ).

**** Set the ALV Header.

DATA : lr_table_settings TYPE REF TO if_salv_wd_table_settings,

       lr_header TYPE REF TO cl_salv_wd_header.

lr_table_settings ?= lv_value.

lr_header = lr_table_settings->get_header( ) .

lr_header->set_text( 'Sales Related List' ).

DATA : lr_button TYPE REF TO cl_salv_wd_fe_button.

CREATE OBJECT lr_button.

lr_button->set_text( 'Delete' ).

DATA : button TYPE REF TO cl_salv_wd_function.

button = lv_value->if_salv_wd_function_settings~create_function( id = 'DELETE' ).

button->set_editor( lr_button ).

endmethod.

after that u can create a event-handler method for a event on_function of the interface alv what u created.

so that you can write code for appending your null record automatically it ll be editable mode.

former_member184578
Active Contributor
0 Kudos

Hi,

Just make the ALV editable bu using set_read_only( ) method with value abap_false and use the standard toolbar which contains 'Append Row' 'Insert Row' instead of creating one more extra button.

Check this wiki:  http://wiki.sdn.sap.com/wiki/display/WDABAP/How+to+edit+conditionally+row+of+a+ALV+table+in+Web+Dynp...

Also check this ref: Drop down in ALV

Hope this helps u.,

Regards,

Kiran

Former Member
0 Kudos

Hi kiran ,

i need to upload a XLSX (EXCEL) to webdynpro abap table.

please provide me the information.

Thanks & Regards.

Krishna.

former_member184578
Active Contributor
0 Kudos