Friday, June 3, 2011

Changing the color of a cell in ALV

For changing the color of a column in ALV.
we need to get the column using the interface controller of the ALV used comp
and then set its cell design to the desired color or design .
as shown in the below fig.
here we are getting the column instance of column "STATUS" and set it to some
design using the method set_cell_design
Here is the code

method WDDOINIT .

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.

DATA lo_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
lo_INTERFACECONTROLLER = wd_this->wd_cpifc_alv( ).

DATA lo_value TYPE ref to cl_salv_wd_config_table.
lo_value = lo_interfacecontroller->get_model(
).

*we dont want to display the celldesign as seperate column so remove it form the ALV table
lo_value->IF_SALV_WD_COLUMN_SETTINGS~DELETE_COLUMN( 'CELLDESIGN' ).

* get the column whose cell design you want to change
data col1 type ref to cl_salv_wd_column.

col1 = lo_value->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'STATUS' ).


* change the cell design BINDING IT TO THE FIELD 'CELLDESIGN'
col1->SET_CELL_DESIGN( CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-NEGATIVE ).

endmethod.

Photobucket


then as we can see the column 'status' is coming in different color.

Photobucket

Now we will have a look at one example where we will change the color of cell based on some condition. here in this example we will change the cell color based on the content of the status
column.
For this, follow the steps as listed below.

1. go to the component controller having the node which is acting as source for the ALV table.
there add one more attribute ( name celldesign and type WDUI_TABLE_CELL_DESIGN )
Add the same attribute to view controller context also.

Photobucket

Photobucket

Photobucket

Photobucket

Photobucket

Photobucket

Photobucket

Photobucket

2. then in the wddoinit method. get the column and set its property cell design property to some field name. here we will set it to CellDesign field. then modify the data of the node to fill the
attribute CELLDESIGN according to the content of the status field.
then fill the node with new modified values.
here is the code..

method WDDOINIT .

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.

DATA lo_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
lo_INTERFACECONTROLLER = wd_this->wd_cpifc_alv( ).

DATA lo_value TYPE ref to cl_salv_wd_config_table.
lo_value = lo_interfacecontroller->get_model(
).

*we dont want to display the celldesign as seperate column so remove it form the ALV table
lo_value->IF_SALV_WD_COLUMN_SETTINGS~DELETE_COLUMN( 'CELLDESIGN' ).

* get the column whose cell design you want to change
data col1 type ref to cl_salv_wd_column.

col1 = lo_value->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'STATUS' ).


* change the cell design BINDING IT TO THE FIELD 'CELLDESIGN'
col1->SET_CELL_DESIGN_FIELDNAME( 'CELLDESIGN' ).

*now get the node's element collection into one internal table
*and fill cell design according to the required condition
DATA lo_nd_dealer TYPE REF TO if_wd_context_node.
DATA LT_dealer TYPE wd_this->elementS_dealer.
DATA LS_DEALER TYPE WD_THIS->ELEMENT_DEALER.

lo_nd_dealer = wd_context->get_child_node( name = wd_this->wdctx_dealer ).

* get all elements into internal table
lo_nd_dealer->get_static_attributes_TABLE(
IMPORTING
TABLE = LT_dealer ).
* loop at the internal table and modify the records as per the requirement
* here in this case i am giving different colors to the cell according to the content
* status 1 is red , 4 is green and rest is some other color
LOOP AT LT_DEALER INTO LS_DEALER.
IF LS_DEALER-STATUS EQ '0001'.
LS_DEALER-CELLDESIGN = CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-NEGATIVE.
ELSEIF LS_DEALER-STATUS EQ '0004'.
LS_DEALER-CELLDESIGN = CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-POSITIVE.
ELSE.
LS_DEALER-CELLDESIGN = CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-BADVALUE_MEDIUM.
ENDIF.

MODIFY LT_DEALER FROM LS_DEALER.
ENDLOOP.

*fll the node with new element collection from the modified internal table lt_dealer
lo_nd_dealer->BIND_TABLE(
LT_DEALER
).



endmethod.


Photobucket

Photobucket

3. save and activate . you will get the application like this.

Photobucket




Thanks
Gill :)

Wednesday, June 1, 2011

Making the ALV column editable


We will have a small example to make one ALV column editable.
for that first create one application with simple editable and for that you can refer to the below link



1. After that go to the main view and there we need to add the interface controller of the used comp ALV as shown below.



Photobucket

Photobucket

Photobucket

Photobucket

2. After that go to the method Wddoinit and there write the code to instantiate the interface controller and component usage. and Use the class CL_SALV_WD_CONFIG_TABLE
and use its method GET_COLUMN to get the column and SET_READ_ONLY to make ALV table editable
and use the SET_EDITOR method to change the editor of the column to INPUT_FIELD.

Here is the code used ...

method WDDOINIT .

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.

DATA lo_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
lo_INTERFACECONTROLLER = wd_this->wd_cpifc_alv( ).

DATA lo_value TYPE ref to cl_salv_wd_config_table.
lo_value = lo_interfacecontroller->get_model(
).

*declaring the input field for using it in cell editor of ALV table
data INP type ref to CL_SALV_WD_UIE_INPUT_FIELD.

create object INP
exporting
VALUE_FIELDNAME = 'NAME'. "here give the name of the field to which you want to do the binding.

* Now get the coloum whose cell editor you want to replace.
data col type ref to CL_SALV_WD_COLUMN.
col = lo_value->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'NAME' ).

*Change the cell editor for the column

col->SET_CELL_EDITOR( INP ).

* Make the ALV table editable
lo_value->IF_SALV_WD_TABLE_SETTINGS~SET_READ_ONLY( abap_false ).



endmethod.


Photobucket


Photobucket


Photobucket

Photobucket

Photobucket




Photobucket

test the application and we will get the NAME column as editable.

Photobucket


Thanks :)


Gill...

Tuesday, May 31, 2011

Using Assistance Class in web dynpro abap

Assistance Class in web dynpro Abap :- Assistance class is a way of writing a separate class and using the functionality or logic defined in its method within your web dynpro application.
It is useful where you have some piece of logic which is reusable at many places.
plus Assistance class is also used in internationalization of the WD application.
You can declare the text in the assistance class and then afterwards can use it in your WD application.
Concept is almost straight forward and easy.
You declare a class with some methods having the required functionality.
and can declare some text elements also if you want to use them.
and you have to make this class subclass of a class CL_WD_COMPONENT_ASSISTANCE.
However this is not a mandatory steps but declaring this class as superclass makes services available in web dynpro framework work.
WD_ASSIST attribute will be getting created automatically in each of the controllers in the web dynpro component.

Now lets have one step by step example of working with this feature of assistance class.

1. Go to txn se24 and create a class . give a relevant name and press on create.

Photobucket


Photobucket

and click on save.

Photobucket

2. Go to the methods tab and create methods. In the current case, I am creating a method name
'Get Name' and with one import and one export parameter.
functionality of the method is to give name of the dealer based on the ID.

Photobucket

Photobucket

Photobucket

Photobucket

Photobucket

3. Save and activate the class.


Photobucket

4. You can test the functionality of the method by using the TEST option as shown below.

Photobucket

Photobucket

Photobucket

5. ON the properties tab you can find one field called super class there give the name
CL_WD_COMPONENT_ASSISTANCE.
save and activate the class.

Photobucket

6. Go to SE80 and open the WD component where you want to use the assistance class.
give the name of the class in the assistance class field.

Photobucket

7. Automatically the attribute WD_ASSIST of type instance of class will be created in the component controller and view controller.

Photobucket

Photobucket

8. In the view we will use the assistance class method "GET_NAME". for that i have created some context attribute and then in the view layout, have designed two input fields and one button.
we will enter dealer id and then click on submit button. In the eventhandler of the button we will
call the method GET_NAME of the assistance class using the attribute WD_ASSIST and fetch the name form the database after passing ID.

Photobucket

Photobucket

Photobucket

9. Create an application and test it .

Photobucket

Photobucket




10. Now lets check out the other usage of assistance class. i.e. declaring the text elements in the class and then using it for translation according to the language chosen.
Here we will have one page with one simple text view translated according to the language chosen.

go to se24 and open the class and Goto-> Text elements.

11. declare the text elements here and after that save it and then Goto->Translation






12. Select the from and to language and then give the translated texts for each of the text elements. Save it and activate the class again.


13. Go to SE80 and open the web dynpro component and the view where you want the text.
I have used one text view which is bound to one context attribute of type string.


14. Then in wddoinit have used the
WD_ASSIST->IF_WD_COMPONENT_ASSISTANCE~GET_TEXT( KEY = ' ').
method of the interface for getting the data.
it will give the text according to the language selected in the application.


15. Test the application and we can see the text got automatically translated according to the
language selected.





Thanks :)

thanks
gill