Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

coloring the rows

Former Member
0 Likes
668

Hi every 1 ,

I am displaying the grid output with material and batch.

but for every change of batch i want to change the color for that row .

its urgent please any body help me to resolve this problem.

thanks in advance

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
642

Try this sample program. It should give you some idea.




REPORT zrich_001.

type-pools slis.

data: fieldcat type slis_t_fieldcat_alv.

data: begin of imara occurs 0,
      matnr type mara-matnr,
      mtart type mara-mtart,
      maktx type makt-maktx,
      color_line(4) type c,
      end of imara.

data: xcolor type slis_specialcol_alv.

START-OF-SELECTION.

  PERFORM get_data.
  PERFORM write_report.


************************************************************************
*  Get_Data
************************************************************************
FORM get_data.

  imara-matnr = 'ABC'.
  imara-mtart = 'ZCFG'.
  imara-maktx = 'This is description for ABC'.
  APPEND imara.

  imara-matnr = 'DEF'.
  imara-mtart = 'ZCFG'.
  imara-maktx = 'This is description for DEF'.
  APPEND imara.

  imara-matnr = 'GHI'.
  imara-mtart = 'ZCFG'.
  imara-maktx = 'This is description for GHI'.
  APPEND imara.

  imara-matnr = 'JKL'.
  imara-mtart = 'ZCFG'.
  imara-maktx = 'This is description for JKL'.
  APPEND imara.

  DATA: color_code(1) TYPE n VALUE '1'.
  data: color_line(4) type c.
  LOOP AT imara.
    AT NEW matnr.
      CONCATENATE 'C' color_code '10' INTO color_line.
      color_code = color_code + 1.
      IF color_code = '8'.
        color_code = '1'.
      ENDIF.
    ENDAT.
    imara-color_line = color_line..
    MODIFY imara.
  ENDLOOP.

ENDFORM.                    "get_data

************************************************************************
*  WRITE_REPORT
************************************************************************
FORM write_report.

  DATA: layout TYPE  slis_layout_alv.

  layout-info_fieldname = 'COLOR_LINE'.

  PERFORM build_field_catalog.

* CALL ABAP LIST VIEWER (ALV)
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      is_layout   = layout
      it_fieldcat = fieldcat
    TABLES
      t_outtab    = imara.

ENDFORM.                    "write_report

************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
FORM build_field_catalog.

  DATA: fc_tmp TYPE slis_t_fieldcat_alv WITH HEADER LINE.
  CLEAR: fieldcat. REFRESH: fieldcat.

  CLEAR: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Number'.
  fc_tmp-fieldname  = 'MATNR'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '18'.
  APPEND fc_tmp TO fieldcat.

  CLEAR: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Type'.
  fc_tmp-fieldname  = 'MTART'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '4'.
  APPEND fc_tmp TO fieldcat.

  CLEAR: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material'.
  fc_tmp-fieldname  = 'MAKTX'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '40'.
  APPEND fc_tmp TO fieldcat.

ENDFORM.                    "build_field_catalog

Regards,

Rich Heilman

Hi every 1 ,

I am displaying the grid output with material and batch.

but for every change of batch i want to change the color for that row .

its urgent please any body help me to resolve this problem.

thanks in advance

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
643

Try this sample program. It should give you some idea.




REPORT zrich_001.

type-pools slis.

data: fieldcat type slis_t_fieldcat_alv.

data: begin of imara occurs 0,
      matnr type mara-matnr,
      mtart type mara-mtart,
      maktx type makt-maktx,
      color_line(4) type c,
      end of imara.

data: xcolor type slis_specialcol_alv.

START-OF-SELECTION.

  PERFORM get_data.
  PERFORM write_report.


************************************************************************
*  Get_Data
************************************************************************
FORM get_data.

  imara-matnr = 'ABC'.
  imara-mtart = 'ZCFG'.
  imara-maktx = 'This is description for ABC'.
  APPEND imara.

  imara-matnr = 'DEF'.
  imara-mtart = 'ZCFG'.
  imara-maktx = 'This is description for DEF'.
  APPEND imara.

  imara-matnr = 'GHI'.
  imara-mtart = 'ZCFG'.
  imara-maktx = 'This is description for GHI'.
  APPEND imara.

  imara-matnr = 'JKL'.
  imara-mtart = 'ZCFG'.
  imara-maktx = 'This is description for JKL'.
  APPEND imara.

  DATA: color_code(1) TYPE n VALUE '1'.
  data: color_line(4) type c.
  LOOP AT imara.
    AT NEW matnr.
      CONCATENATE 'C' color_code '10' INTO color_line.
      color_code = color_code + 1.
      IF color_code = '8'.
        color_code = '1'.
      ENDIF.
    ENDAT.
    imara-color_line = color_line..
    MODIFY imara.
  ENDLOOP.

ENDFORM.                    "get_data

************************************************************************
*  WRITE_REPORT
************************************************************************
FORM write_report.

  DATA: layout TYPE  slis_layout_alv.

  layout-info_fieldname = 'COLOR_LINE'.

  PERFORM build_field_catalog.

* CALL ABAP LIST VIEWER (ALV)
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      is_layout   = layout
      it_fieldcat = fieldcat
    TABLES
      t_outtab    = imara.

ENDFORM.                    "write_report

************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
FORM build_field_catalog.

  DATA: fc_tmp TYPE slis_t_fieldcat_alv WITH HEADER LINE.
  CLEAR: fieldcat. REFRESH: fieldcat.

  CLEAR: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Number'.
  fc_tmp-fieldname  = 'MATNR'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '18'.
  APPEND fc_tmp TO fieldcat.

  CLEAR: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Type'.
  fc_tmp-fieldname  = 'MTART'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '4'.
  APPEND fc_tmp TO fieldcat.

  CLEAR: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material'.
  fc_tmp-fieldname  = 'MAKTX'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '40'.
  APPEND fc_tmp TO fieldcat.

ENDFORM.                    "build_field_catalog

Regards,

Rich Heilman

Read only

Former Member
0 Likes
642

madhavi,

check these below links may be useful for you

http://www.sapfans.com/forums/viewtopic.php?t=52107

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm

Coming to Colors in ALV's. Following links would help you.

we can also manipulate the color in each cell.

2.

IMPORTANT THINGS

a. Extra field in internal table

clr TYPE slis_t_specialcol_alv,

(this field will contain the colour codes)

b. assign fieldname to alv layout

alvly-coltab_fieldname = 'CLR'

c. work area for colour

DATA : clrwa TYPE slis_specialcol_alv.

d. Populating the color

Once again

Loop at ITAB.

*********logic

if itab-field < 0 "---negative

clrwa-fieldname = 'FIELDNAME'. "<--- FIELDNAME FOR COLOR

clrwa-color-col = 6. <------- COLOUR 0-9

APPEND clrwa TO itab-clr.

MODIFY ITAB.

endif.

ENDLOOP.

*----


5. just copy paste in new program

6.

REPORT abc .

*----


NECESSARY / MUST

TYPE-POOLS : slis.

DATA : alvfc TYPE slis_t_fieldcat_alv.

DATA : alvly TYPE slis_layout_alv.

*----


ITAB DECLARATION

DATA : prg TYPE sy-repid.

DATA : BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE t001.

DATA : clname(3) TYPE c,

clr TYPE slis_t_specialcol_alv,

END OF itab.

DATA : clrwa TYPE slis_specialcol_alv.

PARAMETERS : a TYPE c.

DATA : flname TYPE slis_fieldname.

*----


SELECT

START-OF-SELECTION.

SELECT * FROM t001

INTO CORRESPONDING FIELDS OF TABLE itab..

LOOP AT itab..

IF SY-TABIX <= 5.

itab-clname = 'C50'.

ELSE.

itab-clname = 'C30'.

ENDIF.

MODIFY itab.

ENDLOOP.

LOOP AT ITAB.

check itab-bukrs = '1000'

.

clrwa-fieldname = 'BUTXT'.

clrwa-color-col = 6.

APPEND clrwa TO itab-clr.

MODIFY ITAB.

clrwa-fieldname = 'LAND1'.

clrwa-color-col = 4.

APPEND clrwa TO itab-clr.

MODIFY ITAB.

ENDLOOP.

prg = sy-repid.

flname = 'CLNAME'.

  • alvly-info_fieldname = 'CLNAME'.

alvly-coltab_fieldname = 'CLR'.

LOOP AT ITAB.

if sy-tabix = 3.

clrwa-fieldname = 'BUTXT'.

clrwa-color-col = 6.

APPEND clrwa TO itab-clr.

MODIFY ITAB.

clrwa-fieldname = 'LAND1'.

clrwa-color-col = 1.

APPEND clrwa TO itab-clr.

MODIFY ITAB.

endif.

ENDLOOP

.

*

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = prg

i_internal_tabname = 'ITAB'

i_inclname = prg

CHANGING

ct_fieldcat = alvfc

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

*----


minimum

*CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

  • EXPORTING

  • it_fieldcat = alvfc

  • TABLES

  • t_outtab = itab

  • EXCEPTIONS

  • program_error = 1

  • OTHERS = 2

*.

*----


extra

sy-uname = 'XYZAB'.

prg = sy-repid.

*----


Excluding

DATA : excl TYPE slis_t_extab.

DATA : exclwa TYPE slis_extab.

exclwa = '&OUP'.

APPEND exclwa TO excl.

exclwa = '&ODN'.

APPEND exclwa TO excl.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

it_fieldcat = alvfc

i_callback_program = sy-repid

is_layout = alvly

i_callback_user_command = 'ITAB_USER_COMMAND'

it_excluding =

excl

i_save = 'A'

TABLES

t_outtab = itab

EXCEPTIONS

program_error = 1

OTHERS = 2.

&----


*& Form itab_user_command

&----


  • text

----


  • -->WHATCOMM text

  • -->WHATROW text

----


FORM itab_user_command USING whatcomm TYPE sy-ucomm whatrow TYPE

slis_selfield.

BREAK-POINT.

ENDFORM. "itab_user_command

Mark the points if u find useful

~~Guduri

Read only

Former Member
0 Likes
642

Hi Madavi,

We have one option in SLIS <b>zebra</b>.

If u mark that s 'X' then it will display in zebra color.

Hope this helps you, reply for queries, Shall post you the updates.

Regards.

Kumar. .

Read only

Former Member
0 Likes
642

Hi Madavi,

We will get by this way...

PERFORM build_layout.

form build_layout.

gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-totals_text = 'Totals'(201).

  • Set layout field for row attributes(i.e. color)

gd_layout-info_fieldname = 'LINE_COLOR'.

  • gd_layout-totals_only = 'X'.

  • gd_layout-f2code = 'DISP'. "Sets fcode for when double

  • "click(press f2)

  • gd_layout-zebra = 'X'.

  • gd_layout-group_change_edit = 'X'.

  • gd_layout-header_text = 'helllllo'.

endform. " BUILD_LAYOUT

Hope this helps you, reply for queries, Shall post you the updates.

Regards.

Kumar. .

Read only

Former Member