06-10-2008 6:11 PM
I did cell colouring for dynamic ALV by the procedure given in WIKI provided by Mr A.de Smidt when I created a DDIC structure and inside it a field with type LVC_S_SCOL and all worked fine.But now I dont want to create structure and the solution provided by Mr A.de Smdt at https://www.sdn.sap.com/irj/sdn/wiki?path=/display/abap/individualcellcoloringindynamic+alv
to declare like this :
is_lvc_cat-tech = 'X'.
is_lvc_cat-fieldname = 'TCOLOR'.
is_lvc_cat-ref_field = 'SCOL'.
is_lvc_cat-ref_table = '/BEV2/ED_DETAILS_MATBEL_ALV'.
is_lvc_cat-scrtext_s = is_lvc_cat-scrtext_m =
is_lvc_cat-scrtext_l = 'kleur'.
APPEND is_lvc_cat TO it_lvc_cat.
But my program gets short dump at the class :
CALL METHOD cl_alv_table_create=>create_dynamic_table
What should I do to solve this issue?
06-11-2008 5:54 AM
06-11-2008 6:13 AM
REPORT YMS_COLOURCELLALV.
TYPE-POOLS : slis.
DATA : BEGIN OF t5 OCCURS 0.
INCLUDE STRUCTURE t005t.
DATA : color(4) TYPE c,
coltab TYPE slis_t_specialcol_alv,
target TYPE p,
END OF t5.
DATA fcat TYPE slis_t_fieldcat_alv.
DATA scol TYPE slis_specialcol_alv.
DATA cs_layo TYPE slis_layout_alv.
PARAMETER : p_row TYPE i DEFAULT 2.
START-OF-SELECTION.
SELECT * INTO CORRESPONDING FIELDS OF TABLE t5 FROM t005t
WHERE spras = sy-langu.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'T005T'
CHANGING
ct_fieldcat = fcat.
DELETE fcat WHERE fieldname NE 'LANDX'.
CLEAR cs_layo.
cs_layo-window_titlebar = 'Test ALV with color'.
cs_layo-colwidth_optimize = 'X'.
cs_layo-edit = 'X'.
cs_layo-edit_mode = space.
MOVE 'COLOR' TO cs_layo-info_fieldname.
MOVE 'COLTAB' TO cs_layo-coltab_fieldname.
READ TABLE t5 INDEX p_row.
IF sy-subrc = 0.
scol-fieldname = 'LANDX'.
scol-color-col = 6.
scol-color-int = 1.
scol-color-inv = 0.
APPEND scol TO t5-coltab.
MODIFY t5 INDEX p_row.
ENDIF.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = cs_layo
it_fieldcat = fcat
TABLES
t_outtab = t5.
06-11-2008 6:21 AM
Hi Rock
Code Sample
REPORT zcdf_dynamic_table.
Dynamic ALV Grid with Cell Coloring.
Build a field catalog dynamically and provide the ability to color the cells.
To test, copy this code to any program name and create screen 100
as described in the comments. After the screen is displayed, hit
enter to exit the screen.
DATA:
r_dyn_table TYPE REF TO data,
r_wa_dyn_table TYPE REF TO data,
r_dock_ctnr TYPE REF TO cl_gui_docking_container,
r_alv_grid TYPE REF TO cl_gui_alv_grid,
t_fieldcat1 TYPE lvc_t_fcat, "with cell color
t_fieldcat2 TYPE lvc_t_fcat, "without cell color
wa_fieldcat LIKE LINE OF t_fieldcat1,
wa_cellcolors TYPE LINE OF lvc_t_scol,
wa_is_layout TYPE lvc_s_layo.
FIELD-SYMBOLS:
<t_dyn_table> TYPE STANDARD TABLE,
<wa_dyn_table> TYPE ANY,
<t_cellcolors> TYPE lvc_t_scol,
<w_field> TYPE ANY.
START-OF-SELECTION.
Build field catalog based on your criteria.
wa_fieldcat-fieldname = 'FIELD1'.
wa_fieldcat-inttype = 'C'.
wa_fieldcat-outputlen = '10'.
wa_fieldcat-coltext = 'My Field 1'.
wa_fieldcat-seltext = wa_fieldcat-coltext.
APPEND wa_fieldcat TO t_fieldcat1.
wa_fieldcat-fieldname = 'FIELD2'.
wa_fieldcat-inttype = 'C'.
wa_fieldcat-outputlen = '10'.
wa_fieldcat-coltext = 'My Field 2'.
wa_fieldcat-seltext = wa_fieldcat-coltext.
APPEND wa_fieldcat TO t_fieldcat1.
Before adding cell color table, save fieldcatalog to pass
to ALV call. The ALV call needs a fieldcatalog without
the internal table for cell coloring.
t_fieldcat2[] = t_fieldcat1[].
Add cell color table.
CALENDAR_TYPE is a structure in the dictionary with a
field called COLTAB of type LVC_T_SCOL. You can use
any structure and field that has the type LVC_T_SCOL.
wa_fieldcat-fieldname = 'T_CELLCOLORS'.
wa_fieldcat-ref_field = 'COLTAB'.
wa_fieldcat-ref_table = 'CALENDAR_TYPE'.
APPEND wa_fieldcat TO t_fieldcat1.
Create dynamic table including the internal table
for cell coloring.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fieldcat1
IMPORTING
ep_table = r_dyn_table
EXCEPTIONS
generate_subpool_dir_full = 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.
Get access to new table using field symbol.
ASSIGN r_dyn_table->* TO <t_dyn_table>.
Create work area for new table.
CREATE DATA r_wa_dyn_table LIKE LINE OF <t_dyn_table>.
Get access to new work area using field symbol.
ASSIGN r_wa_dyn_table->* TO <wa_dyn_table>.
Get data into table from somewhere. Field names are
known at this point because field catalog is already
built. Read field names from the field catalog or use
COMPONENT <number> in a DO loop to access the fields. A
simpler hard coded approach is used here.
ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_dyn_table> TO <w_field>.
<w_field> = 'ABC'.
ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
<w_field> = 'XYZ'.
APPEND <wa_dyn_table> TO <t_dyn_table>.
ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_dyn_table> TO <w_field>.
<w_field> = 'TUV'.
ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table> TO <w_field>.
<w_field> = 'DEF'.
APPEND <wa_dyn_table> TO <t_dyn_table>.
Color cells based on your criteria. In this example, a test on
FIELD2 is used to decide on color.
LOOP AT <t_dyn_table> INTO <wa_dyn_table>.
ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_dyn_table
Regards
Reward if helpful
Lakshman
06-11-2008 4:47 PM
Thanks u all for u r replies,But IAM ASKING CELL COLOURING IN DYNAMIC ALV.I did it by creating a DDIC structure,I want to do it without creating a DDIC structure.
07-25-2008 4:19 PM
Lakshman Rao Says:
wa_fieldcat-fieldname = 'T_CELLCOLORS'.
wa_fieldcat-ref_field = 'COLTAB'.
wa_fieldcat-ref_table = 'CALENDAR_TYPE'.
APPEND wa_fieldcat TO t_fieldcat1.
Create dynamic table including the internal table
for cell coloring.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_fieldcat1
IMPORTING
ep_table = r_dyn_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
06-11-2008 7:47 AM
hi,
see the below example.
tables: vbak.
type-pools: slis.
selection-screen: begin of block b1.
select-options: cust for vbak-kunnr.
selection-screen: end of block b1.
types: begin of ty_vbak,
vbeln type vbeln_va,
erdat type erdat,
ernam type ernam,
netwr type netwr_ak,
end of ty_vbak.
types: begin of ty_vbak1,
vbeln type vbeln_va,
erdat type erdat,
ernam type ernam,
netwr type netwr_ak,
tabcolor type lvc_t_scol,
end of ty_vbak1.
data: i_vbak type table of ty_vbak,
w_vbak type ty_vbak,
i_fieldcat type lvc_t_fcat, "slis_t_fieldcat_alv,
i_vbak1 type table of ty_vbak1,
w_vbak1 type ty_vbak1.
data: ls_layout type lvc_s_layo.
select vbeln erdat ernam netwr from vbak into table i_vbak where kunnr in cust.
perform fieldcat.
perform display.
&----
*& Form fieldcat
&----
text
-
--> p1 text
<-- p2 text
-
form fieldcat .
data: w_fieldcat type line of lvc_t_fcat.
clear w_fieldcat.
w_fieldcat-fieldname = 'VBELN'.
w_fieldcat-tabname = 'I_VBAK'.
w_fieldcat-seltext = 'DOCUMENT NUMBER'.
append w_fieldcat to i_fieldcat.
clear w_fieldcat.
w_fieldcat-fieldname = 'ERDAT'.
w_fieldcat-tabname = 'I_VBAK'.
w_fieldcat-seltext = 'CREATED ON'.
append w_fieldcat to i_fieldcat.
clear w_fieldcat.
w_fieldcat-fieldname = 'ERNAM'.
w_fieldcat-tabname = 'I_VBAK'.
w_fieldcat-seltext = 'CREATED BY'.
append w_fieldcat to i_fieldcat.
clear w_fieldcat.
w_fieldcat-fieldname = 'NETWR'.
w_fieldcat-tabname = 'I_VBAK'.
w_fieldcat-seltext = 'NET PRICE'.
append w_fieldcat to i_fieldcat.
endform. " fieldcat
&----
*& Form display
&----
text
-
--> p1 text
<-- p2 text
-
form display .
data: ls_tabcolor type lvc_s_scol.
loop at i_vbak into w_vbak.
if sy-tabix <> 3.
clear ls_tabcolor.
ls_tabcolor-fname = 'VBELN'.
ls_tabcolor-color-col = 1. " Blue.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
insert ls_tabcolor into table w_vbak1-tabcolor.
clear ls_tabcolor.
ls_tabcolor-fname = 'ERDAT'.
ls_tabcolor-color-col = 2. " Blue.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
insert ls_tabcolor into table w_vbak1-tabcolor.
clear ls_tabcolor.
ls_tabcolor-fname = 'ERNAM'.
ls_tabcolor-color-col = 3. " Blue.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
insert ls_tabcolor into table w_vbak1-tabcolor.
clear ls_tabcolor.
ls_tabcolor-fname = 'NETWR'.
ls_tabcolor-color-col = 4. " Blue.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
insert ls_tabcolor into table w_vbak1-tabcolor.
move-corresponding w_vbak to w_vbak1.
append w_vbak1 to i_vbak1.
else.
clear ls_tabcolor.
ls_tabcolor-fname = 'VBELN'.
ls_tabcolor-color-col = 1. " Blue.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
insert ls_tabcolor into table w_vbak1-tabcolor.
clear ls_tabcolor.
ls_tabcolor-fname = 'ERDAT'.
ls_tabcolor-color-col = 2. " Blue.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
insert ls_tabcolor into table w_vbak1-tabcolor.
clear ls_tabcolor.
ls_tabcolor-fname = 'ERNAM'.
ls_tabcolor-color-col = 3. " Blue.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
insert ls_tabcolor into table w_vbak1-tabcolor.
clear ls_tabcolor.
ls_tabcolor-fname = 'NETWR'.
ls_tabcolor-color-col = 6. " Blue.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
insert ls_tabcolor into table w_vbak1-tabcolor.
move-corresponding w_vbak to w_vbak1.
append w_vbak1 to i_vbak1.
endif.
clear w_vbak.
clear w_vbak1.
endloop.
**
**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 = ' '
I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
IS_LAYOUT =
IT_FIELDCAT = I_FIELDCAT
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
I_HTML_HEIGHT_TOP = 0
I_HTML_HEIGHT_END = 0
IT_ALV_GRAPHICS =
IT_HYPERLINK =
IT_ADD_FIELDCAT =
IT_EXCEPT_QINFO =
IR_SALV_FULLSCREEN_ADAPTER =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = I_VBAK1
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.
ls_layout-ctab_fname = 'TABCOLOR'.
call function 'REUSE_ALV_GRID_DISPLAY_LVC'
exporting
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
i_callback_program = sy-repid
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
is_layout_lvc = ls_layout
it_fieldcat_lvc = i_fieldcat
IT_EXCLUDING =
IT_SPECIAL_GROUPS_LVC =
IT_SORT_LVC =
IT_FILTER_LVC =
IT_HYPERLINK =
IS_SEL_HIDE =
I_DEFAULT = 'X'
i_save = 'X'
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT_LVC =
IS_REPREP_ID_LVC =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
I_HTML_HEIGHT_TOP =
I_HTML_HEIGHT_END =
IT_EXCEPT_QINFO_LVC =
IR_SALV_FULLSCREEN_ADAPTER =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
tables
t_outtab = i_vbak1
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.
endform. " display
reward if useful,
thanks and regards