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.

 

clip_image002

 

 

 

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

.

clip_image004

 

 

 

clip_image006

 

 

The following code will be generated as below.

 

 

clip_image008

 

 

 

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.

 

clip_image010

 

 

 

Select the interface controller of the ALV.

 

clip_image012

 

 

Choose the method get_model and press enter.

 

clip_image014

clip_image016

Following code will be generated.

clip_image018

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.

 

clip_image020

 

 

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

 

clip_image022

 

 

Following codes will be generated.

 

clip_image024

 

 

 

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,
       ls_columns
type SALV_WD_S_COLUMN_REF.

 

CALL METHOD LV_VALUE->IF_SALV_WD_COLUMN_SETTINGS~
GET_COLUMNS
  RECEIVING
   
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.

    ls_columns
-r_column->set_cell_editor( lo_bukrs ).
endcase.

endloop.

 

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.

 

clip_image028

 

clip_image030

 

 

 

clip_image032

 

 

Modify the code as shown below.

 

clip_image034

 

 

 

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.

lo_nd_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.

lo_nd_ekko
->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.
lo_cmp_usage
=   wd_this->wd_cpuse_alv( ).
if lo_cmp_usage->has_active_component( ) is initial.
  lo_cmp_usage
->create_component( ).
endif.

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

data lv_value type ref to cl_salv_wd_config_table.
lv_value
= 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,
       ls_columns
type salv_wd_s_column_ref.

call method lv_value->if_salv_wd_column_settings~get_columns
  receiving
   
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.

   ls_columns
-r_column->set_cell_editor( lo_bukrs ).
endcase.
endloop.
call method lv_value->if_salv_wd_table_settings~set_read_only
 
exporting

   
value  = abap_false.

endmethod.

Output:

 

clip_image036

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

 

About Arun

0 Comments:

Post a Comment

Powered by Blogger.