Saturday, December 18, 2010
To get color for row
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_GRID_DISPLAY.
- Poplate Final internal with color values for the field COLOR.
REPORT zovh_alv_color_row_col. *&---------------------------------------------------------------------* " 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-emphasize = 'C71'. "Setting Color for Column 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 i_callback_html_top_of_page = 'TOP_OF_PAGE' 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-info_fieldname = 'COLOR'. "Pass COLOR field name like this. 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 *&---------------------------------------------------------------------* *& Form top_of_page *&---------------------------------------------------------------------* FORM top_of_page USING document TYPE REF TO cl_dd_document. DATA: l_text TYPE sdydo_text_element. l_text = 'xyz'. CALL METHOD document->add_text EXPORTING text = l_text sap_emphasis = cl_dd_document=>strong sap_style = cl_dd_document=>key. CALL METHOD document->new_line. l_text = 'lmn'. CALL METHOD document->add_text EXPORTING text = l_text sap_fontsize = cl_dd_document=>medium sap_color = cl_dd_document=>list_positive sap_style = cl_dd_document=>key. CALL METHOD document->underline. CALL METHOD document->add_gap EXPORTING width = '25'. CALL METHOD document->add_text EXPORTING text = l_text sap_fontsize = cl_dd_document=>medium sap_color = cl_dd_document=>list_positive sap_style = cl_dd_document=>key. ENDFORM. "top_of_page
Output
Followers
Popular Posts
- ABAP - ALV Report example with steps
- ABAP - Sending email with pdf attachment
- ABAP - Step by step tutorial on Smart Forms - Template Node
- 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.