Posted: Thu Jun 05, 2008 3:09 pm Post subject: Колорирование в ALV GRID
Задача состояла в написании отчета на ALV GRID, некоторые строки по определенному алгоритму мне надо было закрашивать в зеленый цвет. Столкнулась с такой проблемой, закрашиванию подддаются только строки недоступные к редактированию.
Можно ли это как нибудь победить и закрасить всю строку?
Age: 170 Joined: 04 Oct 2007 Posts: 1218 Location: Санкт-Петербург
Posted: Thu Jun 05, 2008 4:26 pm Post subject:
Немного измененый пример с сайта. Нужно создать пустой экран 9000
и статус ZSTATUS.
Code:
REPORT z_alv_edit_row_color.
*--- Internal table holding list data
DATA BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE mara.
DATA rowcolor(4) TYPE c .
DATA END OF itab.
DATA :
*Code Part 13 – Adding the field that will contain
*Field catalog
i_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,
wa TYPE mara,
w_variant TYPE disvariant,
w_layout TYPE lvc_s_layo,"Layout structure
*Docking Container
o_docking TYPE REF TO cl_gui_docking_container,
*GridDeclaring field symbols
o_grid TYPE REF TO cl_gui_alv_grid.
FIELD-SYMBOLS : <fs_fieldcat> TYPE lvc_s_fcat.
SELECT * FROM mara
INTO CORRESPONDING FIELDS OF TABLE itab
UP TO 10 ROWS.
CALL SCREEN 9000.
*&---------------------------------------------------------------------
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------
* text
*----------------------------------------------------------------------
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.
DATA: ld_color(1) TYPE c.
*Populate field with color attributes
LOOP AT itab.
* Populate color variable with colour properties
* Char 1 = C (This is a color property)
* Char 2 = 3 (Color codes: 1 - 7)
* Char 3 = Intensified on/off ( 1 or 0 )
* Char 4 = Inverse display on/off ( 1 or 0 )
* i.e. wa_ekko-line_color = 'C410'
ld_color = ld_color + 1.
* Only 7 colours so need to reset color value
IF ld_color = 8.
ld_color = 1.
ENDIF.
CONCATENATE 'C' ld_color '10' INTO itab-rowcolor.
* itab-rowcolor = 'C410'.
MODIFY itab TRANSPORTING rowcolor.
ENDLOOP.
w_variant-report = sy-repid.
*Modifying the fieldcatalog for coloring a column
LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>.
CASE <fs_fieldcat>-fieldname.
WHEN 'MATNR'.
<fs_fieldcat>-key = ' '.
*Make the field as non-key so that color should take effect
*Coloring a column
* <fs_fieldcat>-emphasize = 'C311'.
<fs_fieldcat>-edit = 'X'.
WHEN 'ERNAM'.
<fs_fieldcat>-edit = 'X'.
ENDCASE.
ENDLOOP. "Displaying the output
w_layout-info_fname = 'ROWCOLOR'.
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.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
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.
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 METHOD o_docking->free
EXCEPTIONS
cntl_error = 1
cntl_system_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.
ENDFORM.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.