cancel
Showing results for 
Search instead for 
Did you mean: 

Colour In ALV WEBDYNPRO

harish2
Explorer
0 Kudos

  Hi Friends,

  I am using the below code in wdmodify method  to show the report .

  i have not created any nodes in my component just used the below code and used standard component salv_wd_table

  so my question is how to apply colours to cells in ALV based on condition for the dynamic internal table

Accepted Solutions (0)

Answers (3)

Answers (3)

harsha_jalakam
Active Contributor
0 Kudos

Hi Harish,

Once the data is mapped to the ALV table, you can use below code, to color the cells in the ALV, regardless considering the node.

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_COL_NAM TYPE REF TO CL_SALV_WD_COLUMN.

CALL METHOD LV_VALUE->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN

EXPORTING

ID    = ‘COLUMN’

RECEIVING

VALUE = LO_COL_NAM.

CALL METHOD LO_COL_NAM->SET_CELL_DESIGN

EXPORTING

VALUE  = CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-POSITIVE.

CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-badvalue_medium.

CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-standard

Please send the code you have used, it has been missed.

Regards,

Harsha

harish2
Explorer
0 Kudos

Hi Harsha,

Thanks for quick reply,

please check the below code which i have return in wdmodify method i have not created any node at all the code is working preftly correct but i want colour in the below code.

  

    IF first_time EQ abap_true.

"add the fields to be used as ALV columns
    DATA : li_comp TYPE cl_abap_structdescr=>component_table.
    BREAK-POINT.
*    ********************************************************************** "this is the portion of the code where we can add or remove fields
    "to or from the ALV
    wd_this->fill_comp( EXPORTING fv_name = 'FILENAME'
     fv_data_element = 'ZPPAP_FILENAME' " data element
     IMPORTING fi_comp = li_comp " cl_abap_structdescr=>component_table ).
       ).
    DATA : LT_CODE TYPE STANDARD TABLE OF ZPPAP_MASTERDATA,
           LS_CODE LIKE LINE OF LT_CODE .
    SELECT * FROM ZPPAP_MASTERDATA INTO TABLE LT_CODE WHERE CATEGORY = 'SUBM'.
      LOOP AT LT_CODE INTO LS_CODE .

         wd_this->fill_comp( EXPORTING fv_name = LS_CODE-CODE
         " this would be the name of the attribute under the node 'ALV'
         fv_data_element = 'STRING' " data element
         IMPORTING fi_comp = li_comp " cl_abap_structdescr=>component_table ).
           ).
      CLEAR : LS_CODE.
      ENDLOOP.


           DATA: lo_root_info TYPE REF TO if_wd_context_node_info,
                 lo_node_info TYPE REF TO if_wd_context_node_info,
                 lo_structdescr TYPE REF TO cl_abap_structdescr.
           CALL METHOD cl_abap_structdescr=>create
           EXPORTING p_components = li_comp
           RECEIVING p_result = lo_structdescr.

* Get context node info
           lo_root_info = wd_context->get_node_info( ).
*           * Generate new node 'ALV' with the dynamic structure
           CALL METHOD lo_root_info->add_new_child_node
           EXPORTING name = 'ALV'
                     is_initialize_lead_selection = abap_false
                     static_element_rtti = lo_structdescr
                     is_static = abap_false
                     RECEIVING
                     child_node_info = lo_node_info.
*  * get instance of new node
  DATA : lo_dyn_node TYPE REF TO if_wd_context_node.
     lo_dyn_node = wd_context->get_child_node( name = 'ALV' ).


     data : lt_dyn_table type ref to data,
            lw_dyn_table type ref to data,
            lt_fieldcat type lvc_t_fcat,
            lw_fieldcat like line of lt_fieldcat.
  field-symbols : <fs_table> type standard table,
                  <fs_wa> type any,
                  <fs_variable> type any.
clear lt_fieldcat.

TYPES : BEGIN OF gfirst_typ,
FILENAME TYPE ZPPAP_FILENAME,
SUBMISSION_LEVEL TYPE ZPPAP_SUBMISSION_LEVEL,
FILE_PERMISSION TYPE ZPPAP_FILE_PERMISSION.
TYPES : END OF gfirst_typ.

DATA : it_zdemo TYPE TABLE OF gfirst_typ.
DATA : wa_zdemo LIKE LINE OF it_zdemo,
wa_zdemo1 LIKE LINE OF it_zdemo.

DATA : gv_pos TYPE i.
DATA : fname TYPE string.

* Dynamic Table Declarations


DATA : gt_dyn_table  TYPE REF TO data,
gw_line       TYPE REF TO data,
gw_line1       TYPE REF TO data,
gw_dyn_fcat         TYPE lvc_s_fcat,
gt_dyn_fcat         TYPE lvc_t_fcat.

* Field Symbols Declarations


FIELD-SYMBOLS: <gfs_dyn_table> TYPE STANDARD TABLE  ,
               <gfs_line> type ANY   ,<gfs_line1> type any,

<fs1> type any.

* Populate the initial input table. Usually this input table contents will be populated at run time, which raises the requirement of dynamic table. The table contents are filled here for illustration purpose.
select filename SUBMISSION_LEVEL FILE_PERMISSION from ZPPAP_LEVEL_M INTO TABLE  it_zdemo.

SORT IT_ZDEMO BY FILENAME.



*

* This would create structure Vendor Jan13 Feb13 Mar13 etc ....


gv_pos = gv_pos + 1.
gw_dyn_fcat-fieldname = 'FILENAME'.
gw_dyn_fcat-outputlen = 5.
gw_dyn_fcat-tabname   = 'IT_DEMO'.
gw_dyn_fcat-coltext   = 'FILENAME'.
gw_dyn_fcat-col_pos   = gv_pos.
gw_dyn_fcat-key = 'X'.
gw_dyn_fcat-key_sel = 'X'.
APPEND gw_dyn_fcat TO gt_dyn_fcat.

clear gw_dyn_fcat.


* Loop through the internal table creating a column for every distinct month in the internal table

LOOP AT it_zdemo INTO wa_zdemo.
gv_pos = gv_pos + 1.
    fname = wa_zdemo-SUBMISSION_LEVEL .
read table gt_dyn_fcat into gw_dyn_fcat with key fieldname = wa_zdemo-SUBMISSION_LEVEL.
if sy-subrc NE 0.
gw_dyn_fcat-fieldname = wa_zdemo-SUBMISSION_LEVEL.
gw_dyn_fcat-tabname   = 'IT_DEMO'.
gw_dyn_fcat-coltext   = fname.
gw_dyn_fcat-outputlen = 10.
gw_dyn_fcat-col_pos   = gv_pos.
APPEND gw_dyn_fcat TO gt_dyn_fcat.
endif.
clear gw_dyn_fcat.
ENDLOOP.



** Create a dynamic internal table with this structure.

CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
i_style_table             = 'X'
it_fieldcatalog           = gt_dyn_fcat
IMPORTING
ep_table                  = gt_dyn_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS                    = 2.

IF sy-subrc EQ 0.
* Assign the new table to field symbol
ASSIGN gt_dyn_table->* TO <gfs_dyn_table>.
* Create dynamic work area for the dynamic table
CREATE DATA gw_line LIKE LINE OF <gfs_dyn_table>.
CREATE DATA gw_line1 LIKE LINE OF <gfs_dyn_table>.
ASSIGN gw_line->* TO <gfs_line>.
ASSIGN gw_line1->* TO <gfs_line1>.
ENDIF.




* Populate the dynamic table

LOOP AT it_zdemo INTO wa_zdemo.


* Avoid duplicate entries for key field PART.
READ TABLE <gfs_dyn_table> INTO <gfs_line1> WITH KEY ('FILENAME') = wa_zdemo-FILENAME.
IF sy-subrc = 0.
CONTINUE.
ENDIF.


ASSIGN COMPONENT 'FILENAME' OF STRUCTURE <gfs_line> TO <fs1>.
<fs1> = wa_zdemo-FILENAME.
UNASSIGN <fs1>.


LOOP AT gt_dyn_fcat INTO gw_dyn_fcat.
IF gw_dyn_fcat-fieldname = 'FILENAME'.
CONTINUE.
ENDIF.
READ TABLE it_zdemo WITH KEY FILENAME = wa_zdemo-FILENAME SUBMISSION_LEVEL = gw_dyn_fcat-fieldname INTO wa_zdemo1.
IF sy-subrc = 0.
ASSIGN COMPONENT gw_dyn_fcat-fieldname OF STRUCTURE <gfs_line> TO <fs1>.
<fs1> = wa_zdemo1-FILE_PERMISSION.
UNASSIGN <fs1>.
ENDIF.
clear : wa_zdemo1.
ENDLOOP.
APPEND <gfs_line> TO <gfs_dyn_table>.
CLEAR: <gfs_line>.
clear: wa_zdemo, wa_zdemo1.
ENDLOOP.



*      .
       lo_dyn_node->bind_table( <gfs_dyn_table> ).

*       *Get reference to model
        DATA : lo_interfacecontroller TYPE REF TO iwci_salv_wd_table.
       lo_interfacecontroller = wd_this->wd_cpifc_alv( ).
       lo_interfacecontroller->set_data( lo_dyn_node ).
       ENDIF.

harish2
Explorer
0 Kudos

Hi Harsha,

In the baove screen shot i have attcahed the screen shot of out put it is perfect and working and i need to apply colours in the above screen shot as level1 level2 ...are dynamic i have used the ynamic internal table but my concerns is how to apply colour for the cells which is having data as SHARE..

harsha_jalakam
Active Contributor
0 Kudos

Hi Harish,

Please check with the following code.

IF first_time EQ abap_true.

"add the fields to be used as ALV columns
    DATA : li_comp TYPE cl_abap_structdescr=>component_table.
    BREAK-POINT.
*    ********************************************************************** "this is the portion of the code where we can add or remove fields
    "to or from the ALV
    wd_this->fill_comp( EXPORTING fv_name = 'FILENAME'
     fv_data_element = 'ZPPAP_FILENAME' " data element
     IMPORTING fi_comp = li_comp " cl_abap_structdescr=>component_table ).
       ).
    DATA : LT_CODE TYPE STANDARD TABLE OF ZPPAP_MASTERDATA,
           LS_CODE LIKE LINE OF LT_CODE .
    SELECT * FROM ZPPAP_MASTERDATA INTO TABLE LT_CODE WHERE CATEGORY = 'SUBM'.
      LOOP AT LT_CODE INTO LS_CODE .

         wd_this->fill_comp( EXPORTING fv_name = LS_CODE-CODE
         " this would be the name of the attribute under the node 'ALV'
         fv_data_element = 'STRING' " data element
         IMPORTING fi_comp = li_comp " cl_abap_structdescr=>component_table ).
           ).
      CLEAR : LS_CODE.
      ENDLOOP.


           DATA: lo_root_info TYPE REF TO if_wd_context_node_info,
                 lo_node_info TYPE REF TO if_wd_context_node_info,
                 lo_structdescr TYPE REF TO cl_abap_structdescr.
           CALL METHOD cl_abap_structdescr=>create
           EXPORTING p_components = li_comp
           RECEIVING p_result = lo_structdescr.

* Get context node info
           lo_root_info = wd_context->get_node_info( ).
*           * Generate new node 'ALV' with the dynamic structure
           CALL METHOD lo_root_info->add_new_child_node
           EXPORTING name = 'ALV'
                     is_initialize_lead_selection = abap_false
                     static_element_rtti = lo_structdescr
                     is_static = abap_false
                     RECEIVING
                     child_node_info = lo_node_info.
*  * get instance of new node
  DATA : lo_dyn_node TYPE REF TO if_wd_context_node.
     lo_dyn_node = wd_context->get_child_node( name = 'ALV' ).


     data : lt_dyn_table type ref to data,
            lw_dyn_table type ref to data,
            lt_fieldcat type lvc_t_fcat,
            lw_fieldcat like line of lt_fieldcat.
  field-symbols : <fs_table> type standard table,
                  <fs_wa> type any,
                  <fs_variable> type any.
clear lt_fieldcat.

TYPES : BEGIN OF gfirst_typ,
FILENAME TYPE ZPPAP_FILENAME,
SUBMISSION_LEVEL TYPE ZPPAP_SUBMISSION_LEVEL,
FILE_PERMISSION TYPE ZPPAP_FILE_PERMISSION.
TYPES : END OF gfirst_typ.

DATA : it_zdemo TYPE TABLE OF gfirst_typ.
DATA : wa_zdemo LIKE LINE OF it_zdemo,
wa_zdemo1 LIKE LINE OF it_zdemo.

DATA : gv_pos TYPE i.
DATA : fname TYPE string.

* Dynamic Table Declarations


DATA : gt_dyn_table  TYPE REF TO data,
gw_line       TYPE REF TO data,
gw_line1       TYPE REF TO data,
gw_dyn_fcat         TYPE lvc_s_fcat,
gt_dyn_fcat         TYPE lvc_t_fcat.

* Field Symbols Declarations


FIELD-SYMBOLS: <gfs_dyn_table> TYPE STANDARD TABLE  ,
               <gfs_line> type ANY   ,<gfs_line1> type any,

<fs1> type any.

* Populate the initial input table. Usually this input table contents will be populated at run time, which raises the requirement of dynamic table. The table contents are filled here for illustration purpose.
select filename SUBMISSION_LEVEL FILE_PERMISSION from ZPPAP_LEVEL_M INTO TABLE  it_zdemo.

SORT IT_ZDEMO BY FILENAME.



*

* This would create structure Vendor Jan13 Feb13 Mar13 etc ....


gv_pos = gv_pos + 1.
gw_dyn_fcat-fieldname = 'FILENAME'.
gw_dyn_fcat-outputlen = 5.
gw_dyn_fcat-tabname   = 'IT_DEMO'.
gw_dyn_fcat-coltext   = 'FILENAME'.
gw_dyn_fcat-col_pos   = gv_pos.
gw_dyn_fcat-key = 'X'.
gw_dyn_fcat-key_sel = 'X'.
APPEND gw_dyn_fcat TO gt_dyn_fcat.

clear gw_dyn_fcat.


* Loop through the internal table creating a column for every distinct month in the internal table

LOOP AT it_zdemo INTO wa_zdemo.
gv_pos = gv_pos + 1.
    fname = wa_zdemo-SUBMISSION_LEVEL .
read table gt_dyn_fcat into gw_dyn_fcat with key fieldname = wa_zdemo-SUBMISSION_LEVEL.
if sy-subrc NE 0.
gw_dyn_fcat-fieldname = wa_zdemo-SUBMISSION_LEVEL.
gw_dyn_fcat-tabname   = 'IT_DEMO'.
gw_dyn_fcat-coltext   = fname.
gw_dyn_fcat-outputlen = 10.
gw_dyn_fcat-col_pos   = gv_pos.
APPEND gw_dyn_fcat TO gt_dyn_fcat.
endif.
clear gw_dyn_fcat.
ENDLOOP.



** Create a dynamic internal table with this structure.

CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
i_style_table             = 'X'
it_fieldcatalog           = gt_dyn_fcat
IMPORTING
ep_table                  = gt_dyn_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS                    = 2.

IF sy-subrc EQ 0.
* Assign the new table to field symbol
ASSIGN gt_dyn_table->* TO <gfs_dyn_table>.
* Create dynamic work area for the dynamic table
CREATE DATA gw_line LIKE LINE OF <gfs_dyn_table>.
CREATE DATA gw_line1 LIKE LINE OF <gfs_dyn_table>.
ASSIGN gw_line->* TO <gfs_line>.
ASSIGN gw_line1->* TO <gfs_line1>.
ENDIF.




* Populate the dynamic table

LOOP AT it_zdemo INTO wa_zdemo.


* Avoid duplicate entries for key field PART.
READ TABLE <gfs_dyn_table> INTO <gfs_line1> WITH KEY ('FILENAME') = wa_zdemo-FILENAME.
IF sy-subrc = 0.
CONTINUE.
ENDIF.


ASSIGN COMPONENT 'FILENAME' OF STRUCTURE <gfs_line> TO <fs1>.
<fs1> = wa_zdemo-FILENAME.
UNASSIGN <fs1>.


LOOP AT gt_dyn_fcat INTO gw_dyn_fcat.
IF gw_dyn_fcat-fieldname = 'FILENAME'.
CONTINUE.
ENDIF.
READ TABLE it_zdemo WITH KEY FILENAME = wa_zdemo-FILENAME SUBMISSION_LEVEL = gw_dyn_fcat-fieldname INTO wa_zdemo1.
IF sy-subrc = 0.
ASSIGN COMPONENT gw_dyn_fcat-fieldname OF STRUCTURE <gfs_line> TO <fs1>.
<fs1> = wa_zdemo1-FILE_PERMISSION.
UNASSIGN <fs1>.
ENDIF.
clear : wa_zdemo1.
ENDLOOP.
APPEND <gfs_line> TO <gfs_dyn_table>.
CLEAR: <gfs_line>.
clear: wa_zdemo, wa_zdemo1.
ENDLOOP.



*      .
       lo_dyn_node->bind_table( <gfs_dyn_table> ).

*       *Get reference to model
        DATA : lo_interfacecontroller TYPE REF TO iwci_salv_wd_table.
       lo_interfacecontroller = wd_this->wd_cpifc_alv( ).
       lo_interfacecontroller->set_data( lo_dyn_node ).

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_COL_NAM TYPE REF TO CL_SALV_WD_COLUMN.

CALL METHOD LV_VALUE->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN

EXPORTING

ID    = ‘COLUMN’ " name of the column

RECEIVING

VALUE = LO_COL_NAM.

CALL METHOD LO_COL_NAM->SET_CELL_DESIGN

EXPORTING

VALUE  = CL_WD_TABLE_COLUMN=>E_CELL_DESIGN-POSITIVE.

ENDIF.


Regards,

Harsha

0 Kudos

Scn.sap.com/docs/DOC-36117

Scn.sap.com/docs/DOC-34563

former_member184578
Active Contributor
0 Kudos

Hi,

In your dynamic internal table, take an extra field say celldesign and the set the color to that field. You can check this document for reference: Color ALV cells in WDA

hope this helps,

Regards,

Kiran