Saturday, December 18, 2010
To get color for row
Program output
- Define color variable with length 3 type char in the final internal
which is displayed. - build layout structure type slis_layout_alv by specifying
info_fieldname = 'COLOR' and pass layout structure thru FM REUSE*ALV* - Poplate Final internal with color values for the field COLOR.
REPORT ztest_alv_color_row. *&---------------------------------------------------------------------* " Declaration *----------------------------------------------------------------------* "types TYPES: BEGIN OF t_pa0001, color(3) TYPE c, "1.Declare this pernr TYPE pa0001-pernr, ename TYPE pa0001-ename, END OF t_pa0001. "Work area DATA: w_pa0001 TYPE t_pa0001. "Internal tables DATA: i_pa0001 TYPE STANDARD TABLE OF t_pa0001. *&---------------------------------------------------------------------* * ALV Declarations *----------------------------------------------------------------------* * Types Pools TYPE-POOLS: slis. * Types TYPES: t_fieldcat TYPE slis_fieldcat_alv, t_events TYPE slis_alv_event, t_layout TYPE slis_layout_alv. * Workareas DATA: w_fieldcat TYPE t_fieldcat, w_events TYPE t_events, w_layout TYPE t_layout. * Internal Tables DATA: i_fieldcat TYPE STANDARD TABLE OF t_fieldcat, i_events TYPE STANDARD TABLE OF t_events. *&---------------------------------------------------------------------* *&START-OF-SELECTION *&---------------------------------------------------------------------* START-OF-SELECTION . PERFORM get_data. PERFORM color_the_row. "Populate Color like this based on ur conditions *&---------------------------------------------------------------------* *&END-OF-SELECTION *&---------------------------------------------------------------------* END-OF-SELECTION. PERFORM fieldcat. PERFORM layout_build. PERFORM dispaly . *&---------------------------------------------------------------------* " Form fieldcat *&---------------------------------------------------------------------* FORM fieldcat . CLEAR : w_fieldcat,i_fieldcat[]. w_fieldcat-col_pos = 1. w_fieldcat-row_pos = 1. w_fieldcat-fieldname = 'PERNR'. w_fieldcat-tabname = 'I_PA0001'. w_fieldcat-seltext_m = 'Employee No'. w_fieldcat-no_zero = 'PERNR'. APPEND w_fieldcat TO i_fieldcat. CLEAR w_fieldcat. w_fieldcat-col_pos = 2. w_fieldcat-row_pos = 1. w_fieldcat-outputlen = '200'. w_fieldcat-fieldname = 'ENAME'. w_fieldcat-tabname = 'I_PA0001'. w_fieldcat-seltext_l = 'ENAME'. APPEND w_fieldcat TO i_fieldcat. CLEAR w_fieldcat. ENDFORM. " fieldcat *&---------------------------------------------------------------------* *& Form dispaly *&---------------------------------------------------------------------* FORM dispaly . DATA :l_program TYPE sy-repid. l_program = sy-repid. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = l_program is_layout = w_layout it_events = i_events it_fieldcat = i_fieldcat TABLES t_outtab = i_pa0001. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDFORM. " dispaly *&---------------------------------------------------------------------* *& Form get_data *&---------------------------------------------------------------------* FORM get_data . DO 20 TIMES. SELECT pernr ename FROM pa0001 APPENDING CORRESPONDING FIELDS OF TABLE i_pa0001 UP TO 10 ROWS. ENDDO. ENDFORM. " get_data *&---------------------------------------------------------------------* *& Form layout_build *&---------------------------------------------------------------------* FORM layout_build . w_layout-colwidth_optimize = 'X'. w_layout-zebra = 'X'. w_layout-info_fieldname = 'COLOR'. ENDFORM. " layout_build *&---------------------------------------------------------------------* *& Form color_the_row *&---------------------------------------------------------------------* FORM color_the_row . LOOP AT i_pa0001 INTO w_pa0001. IF sy-tabix > 3. w_pa0001-color = 'C31'. MODIFY i_pa0001 FROM w_pa0001 INDEX sy-tabix. ENDIF. ENDLOOP. ENDFORM. " color_the_row
Program output
Followers
Popular Posts
- ABAP - ALV Report example with steps
- ABAP - Step by step tutorial on Smart Forms - Template Node
- ABAP - Sending email with pdf attachment
- SAP Adobe Form - Steps to create simple ADOBE Form and calling it from ABAP Program
- SAP ABAP - CL_ABAP_CHAR_UTILITIES class usage
- ABAP - Multiple value selection from F4 help for SELECT-OPTIONS
- Execute ABAP Report using SUBMIT statement
- ABAP - Select all or Deselect all in ALV or Check box handling in ALV
- Web Dynpro ABAP ALV - ON_CLICK event
- ABAP - Dynamic WHERE clause
0 comments:
Post a Comment
Your useful comments, suggestions are appreciated.Your comments are moderated.