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

ALV with Link to Action

 

This tutorial explains how to create a link to action in the ALV table.

 

Go to the DOINIT method of the view controller and set the properties for the ALV table. We can also do it in the DOINIT method of the component controller by adding the ALV controller usage to the properties of the component controller.

 

Let us proceed to create the first column as the link to action.

 

It is assumed that you have already created the ALV report.

 

Step 1: Instantiate the used component.

 

clip_image002

 

Coding will be generated as below.

 

clip_image004

 

This coding calls the method created for the component usage mentioned earlier in the post. It checks for th active component usage and if there is no active component usage then it creates one.

 

Step 2: Method call in the used controller.

 

 

The ALV table has an interface method called get_model which will return the ALV configuration model.

 

clip_image005

 

Call the get model method of the ALV component using the code wizard method call in used controller.

 

clip_image007

 

Codings will be generated as below.

 

clip_image009

 

The object reference for the ALV configuration table class is now contained in the variable LV_VALUE.

 

This class now contains a number of interfaces which contains method for setting the different properties of the ALV table.

clip_image011

 

In order to change the cell editor of the column, we will use the method get_column of the interface if_salv_wd_column_settings. This method will return the object reference to the column.

Using pattern call the get_column method of the interface.

clip_image013

 

Coding will be generated as below.

 

clip_image015

 

Modify the coding as below.

 

clip_image017

 

Now we have obtained the Object reference for the column using which we can set the cell editor of the column using the method set_cell_editor of the class cl_salv_wd_column.

 

 

This method requires an importing paramter with the generic type for the cell editor. We need to create a object of type of cell editor required and pass it to this method so that the corresponding type will be set as a cell editor to the column.

 

clip_image019

 

 

Every type of UI element has a class associated with it which begins with the name cl_salv_wd_uie_* .  Create an object for that class and pass it to the set cell editor method of the class.

 

clip_image021

 

Call the method set text of the class for link to action to set the text for the hyper link.

 

clip_image023

 

 

Call the set cell editor method and pass the object for link to action to that method.

 

clip_image025

 

Coding will be generated as below.

 

clip_image027

 

Pass the object to it.

 

clip_image029

 

 

Save and activate the whole component and test the application.

 

Output:

 

 

 

 clip_image031

 

 

Code:

 

* Instantiate the used component.

 
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
.

* Method call in the used 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(
  ).


* Getting the object reference of the column.


 
DATA LO_EBELN TYPE REF TO CL_SALV_WD_COLUMN.

 
CALL METHOD
LV_VALUE->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN
   
EXPORTING

     
ID    = 'EBELN'
    RECEIVING
     
VALUE = LO_EBELN.

* Creating an object of cell editor type required.


 
DATA : LO_LINK TYPE REF TO CL_SALV_WD_UIE_LINK_TO_ACTION.

 
CREATE
OBJECT LO_LINK.

* Set the text for hyperlink


CALL METHOD LO_LINK->SET_TEXT_FIELDNAME
 
EXPORTING

   
VALUE  = 'EBELN'
    .


* Setting the cell editor of the

 
CALL METHOD LO_EBELN->SET_CELL_EDITOR
   
EXPORTING

     
VALUE = LO_LINK.

 

 

 

 

To proceed with the action of what has to happen next on the click of link we need to know the where exactly or what value the user has selected. Once we get to know that we can proceed with the action we want. Be it display the item details on a separate table or whatever the requirement is.

 

Now let me throw a message on what value the user has selected.

 

Go to the methods tab of the View controller and create an event handler method.

clip_image033

 

Assign the event handler method to the ON_CLICK event of the ALV component. Because this is the event triggered by the system when the user click on the Cell in the ALV component. By registering this event to our event handler method, our event handler method will be called when the user performs the action on the cell and what has to happen next can be controlled here.

clip_image035

 

 

clip_image037

 

 

 

If you see the importing parameter of this event handler method there will be an importing parameter call r_param which is a reference variable of some ALV Interface.

 

clip_image039

 

 

The attributes of this interface will provide us with the sufficient information which we need to know like which row, particular column in the ALV table the user has performed.

 

Attributes of this interface is as below.

clip_image041

 

The attribute Value will gives us the value of the cell that the user has selected. This attribute is of type data reference variable and we can get it in a field symbol.

 

Code as below in the event handler method:

clip_image043

 

Now the field symbol will be containing the value of the selected cell.

 

 

 

 

Display the message as shown below.

 

Using code wizard generate the codes.

 

clip_image045

 

Modify the generated code as below.

 

clip_image047

 

Save and activate the whole component.

 

Output:

 

clip_image049

 

 

 

 

 

About Arun

0 Comments:

Post a Comment

Powered by Blogger.