Setting ALV row color based on condition in ABAP WebDynpro

...Previous

14. Go again to methods tab and in WDDOINIT method on MAIN view using code wizard instantiate and Create an instance of ALV Interface Controller.

Complete source code of wddoinit

method WDDOINIT .
*----------Alv column settings declarations---------*
  
DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings,
        lt_columns         
TYPE salv_wd_t_column_ref,
        ls_columns         
LIKE LINE OF lt_columns,
        l_column   
TYPE REF TO cl_salv_wd_column.    
    
    
DATA LO_ND_TABLE TYPE REF TO IF_WD_CONTEXT_NODE.
    
DATA LT_TABLE TYPE WD_THIS->ELEMENTS_TABLE.
    
data ls_table like LINE OF LT_TABLE.
SELECT *
from vbap
into CORRESPONDING FIELDS OF TABLE LT_TABLE
UP TO 20 rows.

LOOP AT LT_TABLE into ls_table.
if sy-tabix = 2.
ls_table-celldesign = 
'01'.
MODIFY LT_TABLE from ls_table.
endif.
ENDLOOP.

*   navigate from <CONTEXT> to <TABLE> via lead selection
    LO_ND_TABLE = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_TABLE ).

*
    LO_ND_TABLE->BIND_TABLE( NEW_ITEMS = LT_TABLE SET_INITIAL_ELEMENTS = ABAP_TRUE ).

"instantiate
DATA LO_CMP_USAGE TYPE REF TO IF_WD_COMPONENT_USAGE.

LO_CMP_USAGE =   WD_THIS->WD_CPUSE_VBAP_ALV( ).
IF LO_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) IS INITIAL.
  LO_CMP_USAGE->CREATE_COMPONENT( ).
ENDIF.
"get model
DATA LO_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
LO_INTERFACECONTROLLER =   WD_THIS->WD_CPIFC_VBAP_ALV( ).

  
DATA LV_VALUE TYPE REF TO CL_SALV_WD_CONFIG_TABLE.
  LV_VALUE = LO_INTERFACECONTROLLER->GET_MODEL(
  ).
*----------Alv column setting to change the row color---------*
  lr_column_settings ?= lv_value.
  lt_columns = lr_column_settings->get_columns( ).
  
LOOP AT lt_columns INTO ls_columns.
    ls_columns-r_column->set_cell_design_fieldname( 
value = 'CELLDESIGN' ).
    lv_value->if_salv_wd_column_settings~delete_column( 
id = 'CELLDESIGN' ).
  
ENDLOOP.
endmethod.

15. Go to windows and right click VIEW and click on embed

Embed the table view of the ALV

16. Create an application for the webdynpro component

Output:

The second row is filled with red color because we had set CELLDESIGN for SY-TABIX =2 earlier so based on different condition the row color can be set

SAP Virtual/Onsite Trainings

Document Categories:

What's New?

Contribute?

Sample Specs

What's Hot?

Web Dynpro for ABAP Tutorials 


Join the Mailing List
Enter name and email address below:
Name:
Email:
Subscribe  Unsubscribe 

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image