Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
Webdynpro ABAP

ALV with Input Field


In the previous blog we have seen how to display a simple ALV report, In this blog we will see how to make a column of an ALV Table as a Editable. We will proceed with the same component which we created in the previous blog.


Go to the method WDDOINIT and at the end of the business logic we have written in this method do the following.  It is assumed that you have created the ALV report.


Step 1 : Instantiate the  used component to ensure that the component usage of the ALV is active.


Go to code wizard and select the radio button instantiate the used component and provide the component using F4 help.






From the F4 help choose the component which we need to instantiate.









The following code will be generated as below.







Whenever a component has been added to the interface controller of the view, a method will be created in the interface of the view whose naming convention will be wd_cpuse_ followed by the component name which we provided. You can see the interface created for the view in the attributes tab, the name of the interface will be if_ followed by the view name. This method will return the object reference for the component usage.

Using this object reference we are checking the method has active component which will return ‘x’ in case if the component is active and space in case there are no active components. If there is no active component in that case we will create the component using create component method.



Step 2 : Call the method in the used controller.

Choose the radio button Method call in the used controller.






Select the interface controller of the ALV.





Choose the method get_model and press enter.




Following code will be generated.


Similar to that of the method which returns the component usage object reference, a method with naming convention wd_cpifc_ will be generated in the interface for the view which returns the object reference for the interface of the ALV Component.

Using the interface object reference, calling the method get model will give the object reference for the class CL_SALV_WD_CONFIG_TABLE.


CL_SALV_WD_CONFIG_TABLE : Is the class where the standard functionalites of the ALV component can be modified.


In previous step we have created object to this class name lv_value.


Using this object now we can access the method of this class and modify the functionality.


Step 3:


Now to make the column editable we need to get the columns in the ALV table.


To access the columns do the following.


Click on pattern, then choose the radio button abap object patterns and press enter.

Enter the class name CL_SALV_WD_CONFIG_TABLE.





Choose the get_columns method which belongs to an interface if_salv_wd_column_settings using the F4 help.





Following codes will be generated.






Do the following modifications in the code. Replace the object reference me with the object that was generated earlier to the configuration table class.


* replace the object reference “me” with the object “lv_value” we created for the class cl_salv_wd_config_table.


* Create a table similar to the receiving parameter of the method IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMNS. You can see this by double clicking on the method and seeing the associated type of the parameter value.


This methods return the values of type SALV_WD_T_COLUMN_REF which is a table type and SALV_WD_S_COLUMN_REF is a line type for the same.


Create an internal table of this type and receive the values using the method.


* Call the method Get_coulms of Interface if_wd_table_column_settings
* to change the property of the columns.

data : lt_columns type SALV_WD_T_COLUMN_REF,


VALUE  = lt_columns

The received parameter line type consist of two fields.


  • clip_image026



The field ID stores the value of the Column ID which is nothing but the attribute names of the context which we are binding say for Example BUKRS.


The second field R_COLUMN refers to the class CL_SALV_WD_COLUMN which actually contains the methods related to the column of alv. This class CL_SALV_WD_COLUMN contains a method call SET_CELL_EDITOR which is used to Set the  type of UI element that column should posses.  This method require an object as an Importing parameter and that object should point to a UI element class for ALV.


If you go to the Tcode SE24 and search with CL_SALV_WD_UIE* you will be able to find the list of classes available for different UI element for ALV.



Create a reference variable for the class  CL_SALV_WD_UIE_INPUT_FIELD.


data : lo_bukrs type ref to cl_salv_wd_uie_input_field.

loop at lt_columns into ls_columns.

case ls_columns-id.

when 'bukrs'.

* Creating an object for the class passing the input parameter for the constructor of the class

create object lo_bukrs exporting value_fieldname = ls_columns-id.

* Passing the object to the set cell editor method.

-r_column->set_cell_editor( lo_bukrs ).



Still we will not be able to see the column as editable because the table read only property will shade the input mode property which we have set for out column.


So we have to change the property of the ALV table using the interface IF_SALV_WD_TABLE_SETTINGS. Call the method set_read_only and set the exporting parameter value as ABAP_FALSE which would previously be ABAP_TRUE.











Modify the code as shown below.






Now save and activate the component. Test the application.



Codings In WDDOINIT Method.


method wddoinit .

data lo_nd_ekko type ref to if_wd_context_node.
data lt_ekko type wd_this->elements_ekko.

= wd_context->get_child_node( name = wd_this->wdctx_ekko ).

select * from ekko into  corresponding fields of table lt_ekko up to 5 rows.

->bind_table( new_items = lt_ekko set_initial_elements = abap_true ).

* making and column editable.

* instantiate the used component alv.

data lo_cmp_usage type ref to if_wd_component_usage.
=   wd_this->wd_cpuse_alv( ).
if lo_cmp_usage->has_active_component( ) is initial.
->create_component( ).

* call the method in the current controller
data lo_interfacecontroller type ref to iwci_salv_wd_table .
=   wd_this->wd_cpifc_alv( ).

data lv_value type ref to cl_salv_wd_config_table.
= lo_interfacecontroller->get_model(  ).

* call the method get_coulms of interface if_wd_table_column_settings
* to change the property of the columns.

data : lt_columns type salv_wd_t_column_ref,
type salv_wd_s_column_ref.

call method lv_value->if_salv_wd_column_settings~get_columns
value  = lt_columns.

data : lo_bukrs type ref to cl_salv_wd_uie_input_field.

loop at lt_columns into ls_columns.
case ls_columns-id.

when 'bukrs'.

create object lo_bukrs exporting value_fieldname = ls_columns-id.

-r_column->set_cell_editor( lo_bukrs ).
call method lv_value->if_salv_wd_table_settings~set_read_only

value  = abap_false.





In the output we can see the company code in Editable mode.


About Arun


Post a Comment

Powered by Blogger.