Application Development 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: 

ALV Row Color?????????

rahul_srivastava3
Participant
0 Kudos

Hi Freinds,

<b>Can any plz. tell me the code to color any particular row in ALV at any given condition.</b>

Plz. reply soon. Its Urgent!!!!!

Thanks in Advance.

Regards,

Rahul Srivastava

4 REPLIES 4

Former Member
0 Kudos

Hi Rahul,

The following link will help you...

http://www.sap-img.com/abap/line-color-in-alv-example.htm

**Reward if helpful

regards,

Naveenan.

Former Member
0 Kudos

Hi Rahul,

Please refer to the following.... simpler ones...

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

regards,

Naveenan.

Former Member
0 Kudos

<b>Example 1</b>

REPORT ZBHALV_GRID_DISPLAY.

TABLES:LFA1.

SELECT-OPTIONS:LIFNR FOR LFA1-LIFNR.

DATA:BEGIN OF ITAB OCCURS 0,

LIFNR LIKE LFA1-LIFNR,

NAME1 LIKE LFA1-NAME1,

LAND1 LIKE LFA1-LAND1,

ORT01 LIKE LFA1-ORT01,

REGIO LIKE LFA1-REGIO,

SORTL LIKE LFA1-SORTL,

CFIELD(4) TYPE C,

END OF ITAB.

SELECT * FROM LFA1 INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE LIFNR

IN LIFNR.

LOOP AT ITAB.

ITAB-CFIELD = 'C410'.

MODIFY ITAB.

ENDLOOP.

TYPE-POOLS:SLIS.

DATA:FCAT TYPE SLIS_T_FIELDCAT_ALV.

DATA:LAYOUT TYPE SLIS_LAYOUT_ALV.

DATA:HEAD TYPE SLIS_T_LISTHEADER WITH HEADER LINE.

DATA:SORT TYPE slis_t_sortinfo_alv WITH HEADER LINE.

DATA:EVE TYPE SLIS_T_EVENT WITH HEADER LINE.

LAYOUT-ZEBRA = 'X'.

LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

LAYOUT-WINDOW_TITLEBAR = 'VENDORS DETAILS SCREEN'.

LAYOUT-EDIT = 'X'.

LAYOUT-info_fieldname = 'CFIELD'.

SORT-UP = 'X'.

SORT-SPOS = 1.

SORT-FIELDNAME = 'LAND1'.

SORT-tabname = 'LFA1'.

APPEND SORT.

SORT-SPOS = 2.

SORT-FIELDNAME = 'NAME1'.

SORT-tabname = 'LFA1'.

APPEND SORT.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = EVE[]

EXCEPTIONS

LIST_TYPE_WRONG = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

READ TABLE EVE WITH KEY NAME = 'END_OF_LIST'.

EVE-FORM = 'ENDOFLIST'.

MODIFY EVE TRANSPORTING FORM WHERE NAME = 'END_OF_LIST'.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = SY-REPID

I_INTERNAL_TABNAME = 'ITAB'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

I_INCLNAME = SY-REPID

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

CHANGING

CT_FIELDCAT = FCAT

  • EXCEPTIONS

  • INCONSISTENT_INTERFACE = 1

  • PROGRAM_ERROR = 2

  • OTHERS = 3

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = SY-REPID

  • I_CALLBACK_PF_STATUS_SET = 'STATUS'

  • I_CALLBACK_USER_COMMAND = 'UCOMM'

I_CALLBACK_TOP_OF_PAGE = 'TOPOFPAGE'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

I_GRID_TITLE = 'VENDOR DETAILS'

  • I_GRID_SETTINGS =

IS_LAYOUT = LAYOUT

IT_FIELDCAT = FCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = SORT[]

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = EVE[]

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 5

  • I_SCREEN_START_LINE = 5

  • I_SCREEN_END_COLUMN = 120

  • I_SCREEN_END_LINE = 25

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = ITAB

  • EXCEPTIONS

  • PROGRAM_ERROR = 1

  • OTHERS = 2

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

FORM TOPOFPAGE.

REFRESH HEAD.

HEAD-TYP = 'H'.

HEAD-INFO = 'VENDORS DETAILS TOP OF PAGE'.

APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEAD[]

  • I_END_OF_LIST_GRID = ' '

.

ENDFORM.

FORM ENDOFLIST.

REFRESH HEAD.

HEAD-TYP = 'H'.

HEAD-INFO = 'VENDORS DETAILS END OF LIST'.

APPEND HEAD.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = HEAD[]

I_END_OF_LIST_GRID = 'END OF GRID'

.

ENDFORM.

<b>Example 2</b>

&----


*& Report /BMC_TST_SHOWLOG

*&

&----


*&

*&

&----


REPORT /BMC_TST_SHOWLOG.

TYPES: BEGIN OF log_table.

TYPES: log_level TYPE /bmc_log_message,

cr_date TYPE /bmc_cr_date,

message TYPE /bmc_log_message,

linecolor(4) TYPE c.

TYPES: END OF log_table.

DATA: lt_log TYPE TABLE OF log_table with HEADER LINE,

lt_log2 TYPE TABLE OF log_table with HEADER LINE,

lt_log_list TYPE TABLE OF log_table,

lt_line LIKE LINE OF lt_log_list,

container_r TYPE REF TO cl_gui_custom_container,

grid_r TYPE REF TO cl_gui_alv_grid,

gc_custom_control_name TYPE scrfname VALUE 'CONTAINER_LOG',

fieldcat_r TYPE lvc_t_fcat,

layout_r TYPE lvc_s_layo,

logA TYPE /bmc_log_level,

logB TYPE /bmc_log_level,

logC TYPE /bmc_log_level,

logD TYPE /bmc_log_level,

logE TYPE /bmc_log_level,

ls_ct TYPE lvc_s_scol,

ok_code LIKE sy-ucomm.

*DATA BEGIN OF ls_log_list OCCURS 0.

*DATA: log_level TYPE /bmc_log_message,

  • cr_date TYPE /bmc_cr_date,

  • message TYPE /bmc_log_message,

  • rowcolor(4) TYPE c.

*DATA END OF ls_log_list.

*

*DATA: lt_log_list TYPE TABLE OF log_table.

PARAMETERS: loglevlA TYPE c AS CHECKBOX,

loglevlB TYPE c as CHECKBOX,

loglevlC TYPE c As CHECKBOX,

loglevlD TYPE c aS CHECKBOX,

loglevlE TYPE c AS CHECKBOX,

dateA TYPE /bmc_cr_date OBLIGATORY,

dateB TYPE /bmc_cr_date.

CALL SCREEN 0200.

MODULE user_command_0200 INPUT.

CASE ok_code.

WHEN 'BACK'.

SET SCREEN 0.

MESSAGE ID 'BC400' TYPE 'S' NUMBER '057'.

WHEN OTHERS.

ENDCASE.

ENDMODULE.

MODULE clear_ok_code OUTPUT.

CLEAR ok_code.

ENDMODULE.

MODULE status_0200 OUTPUT.

SET PF-STATUS 'DYNPRO200'.

SET TITLEBAR 'D0200'.

ENDMODULE.

MODULE display_alv OUTPUT.

PERFORM display_alv.

ENDMODULE.

FORM display_alv.

IF grid_r IS INITIAL.

*----Creating custom container instance

CREATE OBJECT container_r

EXPORTING

container_name = gc_custom_control_name

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

others = 6.

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

*----Creating ALV Grid instance

CREATE OBJECT grid_r

EXPORTING

i_parent = container_r

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

others = 5.

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

PERFORM get_log_data.

*----Preparing field catalog.

PERFORM prepare_field_catalog CHANGING fieldcat_r.

*----Preparing layout structure

PERFORM prepare_layout CHANGING layout_r.

*----Here will be additional preparations

*--e.g. initial sorting criteria, initial filtering criteria, excluding

*--functions

CALL METHOD grid_r->set_table_for_first_display

EXPORTING

is_layout = layout_r

CHANGING

it_outtab = lt_log2[]

it_fieldcatalog = fieldcat_r

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

ELSE.

CALL METHOD grid_r->refresh_table_display

EXCEPTIONS

finished = 1

OTHERS = 2.

IF sy-subrc <> 0.

*--Exception handling

ENDIF.

ENDIF.

CALL METHOD grid_r->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_enter.

CALL METHOD grid_r->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_modified.

ENDFORM.

FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.

DATA ls_fcat TYPE lvc_s_fcat.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = '/BMC_LOG'

CHANGING

ct_fieldcat = pt_fieldcat[]

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

IF sy-subrc ne 0.

*--Exception handling

ENDIF.

LOOP AT pt_fieldcat INTO ls_fcat.

CASE ls_fcat-fieldname.

WHEN 'UUID'.

ls_fcat-no_out = 'X'.

MODIFY pt_fieldcat FROM ls_fcat.

WHEN 'LOG_LEVEL'.

ls_fcat-coltext = 'Meldungsart'.

ls_fcat-outputlen = '25'.

MODIFY pt_fieldcat FROM ls_fcat.

WHEN 'CR_DATE'.

ls_fcat-coltext = 'Erstellungsdatum'.

ls_fcat-outputlen = '20'.

MODIFY pt_fieldcat FROM ls_fcat.

WHEN 'CR_TIME'.

ls_fcat-no_out = 'X'.

MODIFY pt_fieldcat FROM ls_fcat.

WHEN 'MESSAGE'.

ls_fcat-coltext = 'Nachricht'.

ls_fcat-outputlen = '50'.

MODIFY pt_fieldcat FROM ls_fcat.

ENDCASE.

  • CASE ls_fcat-value.

  • WHEN '1'.

  • ls_fcat-line_color = 'c100'.

  • ENDCASE.

ENDLOOP.

ENDFORM.

FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.

ps_layout-zebra = 'X'.

ps_layout-grid_title = 'Log'.

ps_layout-smalltitle = 'X'.

ps_layout-info_fname = 'LINECOLOR'.

ENDFORM.

FORM get_log_data.

if loglevlA = 'X'.

logA = '1'.

ENDIF.

if loglevlB = 'X'.

logB = '2'.

ENDIF.

if loglevlC = 'X'.

logC = '3'.

ENDIF.

if loglevlD = 'X'.

logD = '4'.

ENDIF.

if loglevlE = 'X'.

logE = '5'.

ENDIF.

IF dateB ne 0.

SELECT log_level cr_date message FROM /bmc_log INTO CORRESPONDING FIELDS OF TABLE lt_log_list WHERE log_level = logA

OR log_level = logB OR log_level = logC OR log_level = logD OR log_level = logE and cr_date >= dateA and cr_date <= dateB.

ELSE.

SELECT log_level cr_date message FROM /bmc_log INTO CORRESPONDING FIELDS OF TABLE lt_log_list WHERE log_level = logA

OR log_level = logB OR log_level = logC OR log_level = logD OR log_level = logE and cr_date >= dateA.

ENDIF.

  • and cr_date >= dateA.

SORT lt_log_list ASCENDING.

LOOP AT lt_log_list INTO lt_line.

IF lt_line-log_level = '1'.

lt_line-log_level = 'Info'.

lt_line-linecolor = 'C100'.

ENDIF.

IF lt_line-log_level = '2'.

lt_line-log_level = 'Warning'.

lt_line-linecolor = 'C200'.

ENDIF.

IF lt_line-log_level = '3'.

lt_line-log_level = 'Error'.

lt_line-linecolor = 'C300'.

ENDIF.

IF lt_line-log_level = '4'.

lt_line-log_level = 'Debug'.

lt_line-linecolor = 'C400'.

ENDIF.

IF lt_line-log_level = '5'.

lt_line-log_level = 'Trace'.

lt_line-linecolor = 'C500'.

ENDIF.

APPEND lt_line TO lt_log2.

ENDLOOP.

ENDFORM.

SELECTION-SCREEN BEGIN OF SCREEN 0100 TITLE text-001 AS WINDOW.

SELECTION-SCREEN END OF SCREEN 0100.

Regards,

Pavan.

Former Member