Skip to Content
0
Former Member
Feb 06, 2009 at 07:10 AM

Coloring a Particular Cell

22 Views

Hi,

Please find below the sample program in which tried to color a particular cell. But it is not applying the color. Please help me to resolve this issues.

Thanks in Advance,

Sunil Kumar

&----


*& Report ZSAPCOLV

&----


REPORT ZSAPCOLV.

TABLES:mara.

TYPES:BEGIN OF ty_mara,

matnr TYPE mara-matnr,

mtart TYPE mara-mtart,

END OF ty_mara.

DATA:it_mara TYPE STANDARD TABLE OF ty_mara,

it_color type table of lvc_s_scol,

wa_mara TYPE ty_mara,

wa_color type lvc_s_scol,

is_layout type lvc_s_layo.

DATA: t_newtable TYPE REF TO data,

t_newline TYPE REF TO data.

FIELD-SYMBOLS: <dyntab> TYPE STANDARD TABLE,

<wa_dyntab> TYPE ANY,

<gfs_wa> TYPE ANY.

TYPES: BEGIN OF ty_cmara,

matnr TYPE mara-matnr,

mtart TYPE mara-mtart,

tabcolor TYPE lvc_t_scol,

END OF ty_cmara. " Cell color

DATA:it_cmara TYPE STANDARD TABLE OF ty_cmara.

DATA:

gr_table TYPE REF TO cl_salv_table,

gr_functions TYPE REF TO cl_salv_functions,

gr_display TYPE REF TO cl_salv_display_settings.

DATA: it_fcat TYPE lvc_t_fcat,

wa_fcat TYPE lvc_s_fcat.

DATA:it_fcat1 TYPE lvc_t_fcat, "with cell color

it_fcat2 TYPE lvc_t_fcat,

wa_fieldcat LIKE LINE OF it_fcat1,

wa_cellcolors TYPE lvc_s_scol,

wa_is_layout TYPE lvc_s_layo.

FIELD-SYMBOLS:<t_cellcolors> TYPE lvc_t_scol,

<w_field> TYPE ANY.

DATA:t_line TYPE REF TO data .

*-----design selection screen for plant and material type.

selection-screen begin of block b1 with frame title text-b01.

select-options:

s_matnr for mara-matnr. "material type

selection-screen end of block b1.

START-OF-SELECTION.

PERFORM fetch_data.

PERFORM display_data.

&----


*& Form fetch_data

&----


FORM fetch_data .

DATA:wa_cmara TYPE ty_cmara.

DATA: ls_tabcolor TYPE lvc_s_scol.

SELECT

  • FROM mara

INTO CORRESPONDING FIELDS OF TABLE it_mara where matnr in s_matnr.

CHECK sy-subrc EQ 0.

PERFORM build_catalog USING '1' 'MATNR' 'Material number' 'Material Number' ' ' '18'.

PERFORM build_catalog USING '1' 'MTART' 'Material type' 'Material type' ' ' '10'.

it_fcat1[] = it_fcat[].

wa_fieldcat-fieldname = 'T_CELLCOLORS'.

wa_fieldcat-ref_field = 'COLTAB'.

wa_fieldcat-ref_table = 'CALENDAR_TYPE'.

APPEND wa_fieldcat TO it_fcat.

cl_alv_table_create=>create_dynamic_table( EXPORTING it_fieldcatalog = it_fcat

IMPORTING ep_table = t_newtable ).

ASSIGN t_newtable->* TO <dyntab>.

CREATE DATA t_line LIKE LINE OF <dyntab>.

ASSIGN t_line->* TO <gfs_wa>.

PERFORM fill_data.

ENDFORM. " fetch_data

&----


*& Form build_catalog

&----


FORM build_catalog USING p_pos TYPE lvc_colpos

p_field TYPE lvc_fname

p_reptext TYPE reptext

p_coltext type coltext

p_check TYPE lvc_checkb

p_len TYPE lvc_outlen.

wa_fcat-col_pos = p_pos.

wa_fcat-fieldname = p_field.

wa_fcat-reptext = p_reptext.

wa_fcat-checkbox = p_check.

wa_fcat-outputlen = p_len.

IF p_check = 'X'.

wa_fcat-edit = 'X'.

ENDIF.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

ENDFORM. " catalog

&----


*& Form fill_data

&----


FORM fill_data .

FIELD-SYMBOLS: <wa_tmp> TYPE ANY,

<v_fld> TYPE ANY,

<color> TYPE ANY.

DATA: v_fld(20).

DATA : lv_cnt TYPE i,

lv_cnt1 TYPE i.

DATA:wa_cmara TYPE ty_cmara.

LOOP AT it_mara INTO wa_mara.

lv_cnt1 = lv_cnt1 + 1.

LOOP AT it_fcat INTO wa_fcat.

UNASSIGN <wa_tmp>.

ASSIGN COMPONENT wa_fcat-fieldname OF STRUCTURE <gfs_wa> TO <wa_tmp>.

CONCATENATE 'WA_MARA-' wa_fcat-fieldname INTO v_fld.

ASSIGN (v_fld) TO <v_fld>.

CHECK sy-subrc EQ 0.

<wa_tmp> = <v_fld>.

lv_cnt = lv_cnt + 1.

IF lv_cnt = 1.

APPEND <gfs_wa> TO <dyntab>.

ELSE.

MODIFY <dyntab> INDEX lv_cnt1 FROM <gfs_wa>.

ENDIF.

ENDLOOP.

lv_cnt = 0.

CLEAR wa_mara.

ENDLOOP.

ENDFORM. " fill_data

&----


*& Form display_data

&----


FORM display_data .

IF <dyntab> IS NOT INITIAL.

LOOP AT <dyntab> INTO <gfs_wa>.

ASSIGN COMPONENT 'MATNR' OF STRUCTURE <gfs_wa> TO <w_field>.

ASSIGN COMPONENT 'T_CELLCOLORS' OF STRUCTURE <gfs_wa> TO <t_cellcolors> .

CLEAR wa_cellcolors.

wa_cellcolors-fname = 'MATNR'.

IF <w_field> = '000000000100000012'.

wa_cellcolors-color-col = '6'.

wa_cellcolors-color-int = '1'.

wa_cellcolors-color-inv = '1'.

ELSE.

wa_cellcolors-color-col = '5'.

ENDIF.

APPEND wa_cellcolors TO <t_cellcolors>.

MODIFY <dyntab> FROM <gfs_wa>.

ENDLOOP.

cl_salv_table=>factory( IMPORTING r_salv_table = gr_table CHANGING t_table = <dyntab> ).

gr_functions = gr_table->get_functions( ).

gr_functions->set_all( abap_true ).

gr_display = gr_table->get_display_settings( ).

gr_display->set_striped_pattern( cl_salv_display_settings=>true ).

gr_display->set_list_header( 'MARA DATA' ).

gr_table->display( ).

ENDIF.

ENDFORM. " display_data