Раскраска строк в ALV GRID SAP ABAP Coloring a Row

Вывод всех возможных цветов

REPORT ZALVCOLOR.

TYPE-POOLS: SLIS.

DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: LAYOUT TYPE SLIS_LAYOUT_ALV.

DATA: BEGIN OF I_OUTPUT OCCURS 0,
I_TEXT(30) TYPE C,
I_COLOR(4),
END OF I_OUTPUT.

DATA: I_NUM(1) TYPE N.
DATA: I_INT(1) TYPE N.
DATA: I_4(1) TYPE N.

DO 28 TIMES.
I_4 = 0.
IF SY-INDEX = 1.
I_NUM = 1.
I_INT = 1.
ELSE.
I_NUM = I_NUM + 1.
IF I_NUM = 8.
I_NUM = 1.
I_INT = 0.
ENDIF.
ENDIF.
IF SY-INDEX > 14.
I_4 = 1.
ENDIF.
IF SY-INDEX > 21.
I_INT = 1.
ENDIF.

CONCATENATE 'C' I_NUM I_INT I_4 INTO I_OUTPUT-I_COLOR.
CONCATENATE 'COLOR ' I_OUTPUT-I_COLOR INTO I_OUTPUT-I_TEXT SEPARATED BY SPACE.
APPEND I_OUTPUT.
CLEAR I_OUTPUT.
ENDDO.

DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = 'I_TEXT'.
LS_FIELDCAT-SELTEXT_L = 'ALV COLOR VIEW'.
LS_FIELDCAT-KEY = 'X'.
LS_FIELDCAT-OUTPUTLEN = '30'.
APPEND LS_FIELDCAT TO FIELDCAT.

LAYOUT-INFO_FIELDNAME = 'I_COLOR'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = 'Z_SET_COLOR_IN_ALV_OUTPUT'
IS_LAYOUT = LAYOUT
IT_FIELDCAT = FIELDCAT[]
TABLES
T_OUTTAB = I_OUTPUT[].

 

 

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.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Добавить комментарий