Sie sind auf Seite 1von 4

Coloring a Row

Step 1: Include a field called rowcolor in output internal table.

TYPES : BEGIN OF ty.


INCLUDE STRUCTURE mara.
TYPES : rowcolor(4) TYPE c,
END OF ty.
DATA : itab TYPE STANDARD TABLE OF ty,"Output Internal table
wa TYPE ty.
Step 2: Setting the layout accordingly

DATA w_layout TYPE lvc_s_layo."Layout structure


* Setting layout
w_layout-info_fname = 'ROWCOLOR'."For row coloring
Step 3: Coloring the specific row

* Colouring a row
CLEAR wa.
READ TABLE itab INTO wa INDEX 3.
IF sy-subrc EQ 0.
wa-rowcolor = 'C311'.
MODIFY itab FROM wa TRANSPORTING rowcolor WHERE matnr = wa-matnr.
ENDIF.
Step4: Pass the layout also in the method set_table_for_first_display

* Displaying the output


CALL METHOD o_grid->set_table_for_first_display
EXPORTING
is_variant
= w_variant
i_save
= 'A'
is_layout
= w_layout
CHANGING
it_outtab
= itab
it_fieldcatalog
= i_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error
= 2
too_many_lines
= 3
OTHERS
= 4.

Complete Code for Coloring a Row


Screen 9000,GUI Status ZSTATUS and GUI Title ZTITLE
should be created and in Flow logic of the screen, PBO
and PAI should be uncommented.
TYPES : BEGIN OF ty.
INCLUDE STRUCTURE mara.
TYPES : rowcolor(4) TYPE c,
END OF ty.
DATA : itab TYPE STANDARD TABLE OF ty,"Output Internal table

i_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,"Field catalog


wa TYPE ty,
w_variant TYPE disvariant,
w_layout TYPE lvc_s_layo,"Layout structure
o_docking TYPE REF TO cl_gui_docking_container,"Docking Container
o_grid TYPE REF TO cl_gui_alv_grid."Grid
SELECT * FROM mara INTO CORRESPONDING FIELDS OF TABLE itab UP TO 10 ROWS.
CALL SCREEN 9000.
*&--------------------------------------------------------------------*&
Module STATUS_9000 OUTPUT
*&--------------------------------------------------------------------MODULE status_9000 OUTPUT.
IF o_docking IS INITIAL.
SET PF-STATUS 'ZSTATUS'. "GUI Status
SET TITLEBAR 'ZTITLE'.
"TitleCreating Docking Container
CREATE OBJECT o_docking
EXPORTING
ratio = '95'.
IF sy-subrc EQ 0.
*Creating Grid
CREATE OBJECT o_grid
EXPORTING
i_parent = o_docking.
ENDIF.
*Filling the fieldcatalog table
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name
= 'MARA'
CHANGING
ct_fieldcat
= i_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error
= 2
OTHERS
= 3.
w_variant-report = sy-repid.
*Setting layout
w_layout-info_fname = 'ROWCOLOR'."For row coloring
*Colouring a row
CLEAR wa.
READ TABLE itab INTO wa INDEX 3.
IF sy-subrc EQ 0.
wa-rowcolor = 'C311'.
MODIFY itab FROM wa TRANSPORTING rowcolor WHERE matnr = wa-matnr.
ENDIF.
*Displaying the output
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
is_variant
= w_variant
i_save
= 'A'
is_layout
= w_layout
CHANGING
it_outtab
= itab
it_fieldcatalog
= i_fieldcat
EXCEPTIONS

invalid_parameter_combination = 1
program_error
= 2
too_many_lines
= 3
OTHERS
= 4.
ENDIF.
ENDMODULE.
" STATUS_9000 OUTPUT
*&--------------------------------------------------------------------*&
Module USER_COMMAND_9000 INPUT
*&--------------------------------------------------------------------*
PAI
*---------------------------------------------------------------------MODULE user_command_9000 INPUT.
DATA lv_ucomm TYPE sy-ucomm.
lv_ucomm = sy-ucomm.
CASE lv_ucomm.
WHEN 'CANCEl' OR 'EXIT'.
PERFORM free_objects.
LEAVE PROGRAM.
WHEN 'BACK'.
PERFORM free_objects.
SET SCREEN '0'.
LEAVE SCREEN.
ENDCASE.
ENDMODULE.
" USER_COMMAND_9000 INPUT
*&--------------------------------------------------------------------*&
Form free_objects
*&--------------------------------------------------------------------*
Free Objects
*---------------------------------------------------------------------FORM free_objects .
CALL METHOD o_grid->free
EXCEPTIONS
cntl_error
= 1
cntl_system_error = 2
OTHERS
= 3.
CALL METHOD o_docking->free
EXCEPTIONS
cntl_error
= 1
cntl_system_error = 2
OTHERS
= 3.
ENDFORM.

Output

" free_objects

Colorconstants
Use this Type-Pool to have "speaking constants" for your colorcodes.

TYPE-POOL zcol .

CONSTANTS:
zcol_greyblue(04)
zcol_lightgrey(04)
zcol_yellow(04)
zcol_bluegreen(04)
zcol_green(04)
zcol_red(04)
zcol_violett(04)

TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE

c
c
c
c
c
c
c

VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE

'C100',
'C200',
'C300',
'C400',
'C500',
'C600',
'C700',

zcol_greyblue_int(04)
zcol_lightgrey_int(04)
zcol_yellow_int(04)
zcol_bluegreen_int(04)
zcol_green_int(04)
zcol_red_int(04)
zcol_violett_int(04)

TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE

c
c
c
c
c
c
c

VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE

'C110',
'C210',
'C310',
'C410',
'C510',
'C610',
'C710',

zcol_greyblue_inv(04)
zcol_lightgrey_inv(04)
zcol_yellow_inv(04)
zcol_bluegreen_inv(04)
zcol_green_inv(04)
zcol_red_inv(04)
zcol_violett_inv(04)

TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE

c
c
c
c
c
c
c

VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE

'C101',
'C201',
'C301',
'C401',
'C501',
'C601',
'C701',

zcol_greyblue_int_inv(04)
zcol_lightgrey_int_inv(04)
zcol_yellow_int_inv(04)
zcol_bluegreen_int_inv(04)
zcol_green_int_inv(04)
zcol_red_int_inv(04)
zcol_violett_int_inv(04)

TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE

c
c
c
c
c
c
c

VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE

'C111',
'C211',
'C311',
'C411',
'C511',
'C611',
'C711'.

Das könnte Ihnen auch gefallen