关于ALV表格颜色,感觉这种需求在项目中用到的时候不是很多,但是前一段时间面试的时候,面试官问了我关于ALV单元格颜色的问题。
以前了解过一点,回答的不是很好,后来百度了一下,大概了解了一些,今天工作不忙,所以总结一下,以后工作用到可以过来看一下。
(其实有的时候面试官就是想通过这些不常用的知识点,来了解被面试者的水平)
DEMO源代码
*&---------------------------------------------------------------------*
*& Report ZHAIM_test
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------* REPORT ZHAIM_test NO STANDARD PAGE HEADING. TABLES ZEMP_TEST. TYPES: BEGIN OF TY_ZEMP.
INCLUDE STRUCTURE ZEMP_TEST.
TYPES: CLR TYPE CHAR4,
CELLCOLOR TYPE LVC_T_SCOL, "单元格颜色
END OF TY_ZEMP. DATA: IT_ZEMP TYPE STANDARD TABLE OF TY_ZEMP,
IW_ZEMP TYPE TY_ZEMP. TYPE-POOLS : SLIS.
DATA : IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
IT_EVENT TYPE SLIS_T_EVENT, "不能有表头,否则会RUNTIME ERROR
IW_LAYOUT TYPE SLIS_LAYOUT_ALV,
IW_CELLCOLOR TYPE LVC_S_SCOL,
IT_LISTHEADER TYPE SLIS_T_LISTHEADER. PARAMETERS P_DEPT TYPE ZEMP_TEST-EDEPT. START-OF-SELECTION. PERFORM FRM_GET_EVENT.
PERFORM FRM_GET_DATA.
PERFORM FRM_ALV_COLOR.
PERFORM FRM_COMMENT_BUILD.
PERFORM FRM_LAYOUT.
PERFORM FRM_FIELDCAT.
PERFORM FRM_ALV_DISPLAY. *&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA . AUTHORITY-CHECK OBJECT 'ZEMPOBJ00'
ID 'ZEMPDEPT' FIELD P_DEPT
ID 'ACTVT' FIELD ''.
IF SY-SUBRC <> .
MESSAGE S001() WITH '您没有权限查看此数据' DISPLAY LIKE 'E'.
STOP.
ENDIF. SELECT *
FROM ZEMP_TEST
INTO CORRESPONDING FIELDS OF TABLE IT_ZEMP
WHERE EDEPT = P_DEPT.
IF SY-SUBRC <> .
MESSAGE S001() WITH '不存在符合条件的数据' DISPLAY LIKE 'E'.
STOP.
ENDIF. ENDFORM. " FRM_GET_DATA *&---------------------------------------------------------------------*
*& Form FRM_GET_EVENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_EVENT . DATA: FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'FRM_TOP_OF_PAGE'. DATA L_EVENTS TYPE SLIS_ALV_EVENT. CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE =
IMPORTING
ET_EVENTS = IT_EVENT
EXCEPTIONS
LIST_TYPE_WRONG =
OTHERS = .
IF SY-SUBRC <> .
MESSAGE ID SY-MSGID TYPE SY-MSGTY
NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* 在事件(字段名:NAME)为"TOP_OF_PAGE"的行中
*将FORM名(字段名:FORM)设为"FRM_TOP_OF_PAGE"
* 这样,系统就会自动PERFORM FRM_TOP_OF_PAGE.
CLEAR L_EVENTS.
READ TABLE IT_EVENT
WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO L_EVENTS. IF SY-SUBRC = .
MOVE FORMNAME_TOP_OF_PAGE TO L_EVENTS-FORM.
MODIFY IT_EVENT FROM L_EVENTS INDEX SY-TABIX.
ELSE.
L_EVENTS-FORM = FORMNAME_TOP_OF_PAGE.
L_EVENTS-NAME = FORMNAME_TOP_OF_PAGE.
APPEND L_EVENTS TO IT_EVENT.
ENDIF. ENDFORM. " FRM_GET_EVENT *&---------------------------------------------------------------------*
*& Form FRM_TOP_OF_PAGE
*&---------------------------------------------------------------------*
* 表头
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LISTHEADER
I_LOGO = 'ENJOYSAP_LOGO'
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
* "TCODE:OAOR,CLASS
* NAME:PICTURES,CLASS TYPE :OT,执行,可以看到所有的PICTURE ENDFORM. "FRM_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form FRM_COMMENT_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_COMMENT_BUILD .
DATA LW_LISTHEADER TYPE SLIS_LISTHEADER. CLEAR: IT_LISTHEADER, LW_LISTHEADER. LW_LISTHEADER-TYP = 'H'.
LW_LISTHEADER-INFO = 'ALV DEMO'.
APPEND LW_LISTHEADER TO IT_LISTHEADER. CLEAR LW_LISTHEADER.
LW_LISTHEADER-TYP = 'S'.
LW_LISTHEADER-KEY = '用户:'.
LW_LISTHEADER-INFO = SY-UNAME.
APPEND LW_LISTHEADER TO IT_LISTHEADER. CLEAR LW_LISTHEADER.
LW_LISTHEADER-TYP = 'S'.
LW_LISTHEADER-KEY = '日期:'.
LW_LISTHEADER-INFO = SY-DATUM.
APPEND LW_LISTHEADER TO IT_LISTHEADER. ENDFORM. " FRM_COMMENT_BUILD
*&---------------------------------------------------------------------*
*& Form FRM_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_LAYOUT . IW_LAYOUT-COLWIDTH_OPTIMIZE = 'X'."自适应字段宽度
IW_LAYOUT-ZEBRA = 'X'. "斑马线显示
"ALV单元格中列的颜色在 IT_FIELDCAT 中设置,
"行的颜色,以及单元格颜色在 IS_LAYOUT中设置。
IW_LAYOUT-INFO_FIELDNAME = 'CLR'. "行颜色代码的字段
IW_LAYOUT-COLTAB_FIELDNAME = 'CELLCOLOR'. "单元格颜色内表字段
* IW_LAYOUT-EDIT = 'X'. "可以修改所有ALV列的数据,
* 左边也会出来选择行的按钮","保存"按钮也会出来
IW_LAYOUT-F2CODE = 'PICK'."双击触发的FUNCTION CODE ENDFORM. " FRM_LAYOUT
*&---------------------------------------------------------------------*
*& Form FRM_ALV_COLOR
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_ALV_COLOR .
LOOP AT IT_ZEMP INTO IW_ZEMP. "员工编号为‘3’的行,颜色为红色
IF IW_ZEMP-EMPID = ''.
IW_ZEMP-CLR = 'C610'. MODIFY IT_ZEMP FROM IW_ZEMP.
CLEAR IW_ZEMP. ENDIF. IF IW_ZEMP-EMPID = ''.
IW_CELLCOLOR-FNAME = 'ENAME'.
"员工编号为‘2’的行的‘ENAME’字段颜色为 黄色
IW_CELLCOLOR-COLOR-COL = .
IW_CELLCOLOR-COLOR-INT = .
IW_CELLCOLOR-COLOR-INV = . APPEND IW_CELLCOLOR TO IW_ZEMP-CELLCOLOR.
MODIFY IT_ZEMP FROM IW_ZEMP.
CLEAR IW_ZEMP. ENDIF.
ENDLOOP.
* Syntax of color value in col color
*{ COL_BACKGROUND } 0 GUI-specific
*{ 1 | COL_HEADING } 1 Gray-blue
*{ 2 | COL_NORMAL } 2 Light gray
*{ 3 | COL_TOTAL } 3 Yellow
*{ 4 | COL_KEY } 4 Blue-green
*{ 5 | COL_POSITIVE } 5 Green
*{ 6 | COL_NEGATIVE } 6 Red
*{ 7 | COL_GROUP } 7 Violet ENDFORM. " FRM_ALV_COLOR
*&---------------------------------------------------------------------*
*& Form FRM_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_FIELDCAT . CLEAR IT_FIELDCAT. * 函数调用获得标准字段,构成FCAT
PERFORM FRM_GET_ALL_FIELD.
* RFE自定义字段,字段颜色,求和
PERFORM FRM_REDEFINE_FIELD. * 颜色和HOTSPOT和对齐
"PERFORM FRM_COLOR_HOTSPOT USING LW_FCAT.
* 格式调整
" PERFORM FRM_FORMAT_FIELD USING LW_FCAT. ENDFORM. " FRM_FIELDCAT
*&---------------------------------------------------------------------*
*& Form FRM_GET_ALL_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM FRM_GET_ALL_FIELD . DATA W_REPID TYPE SY-REPID.
W_REPID = SY-REPID. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = W_REPID
* I_INTERNAL_TABNAME =
I_STRUCTURE_NAME = 'ZEMP_TEST'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = IT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE =
PROGRAM_ERROR =
OTHERS = .
IF SY-SUBRC <> .
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. ENDFORM. " FRM_GET_ALL_FIELD
*&---------------------------------------------------------------------*
*& Form FRM_REDEFINE_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_REDEFINE_FIELD .
DATA LW_FCAT TYPE SLIS_FIELDCAT_ALV.
CLEAR LW_FCAT.
** DEFINE INITIAL_FIELD.
** ADD 1 TO col_pos .
** CLEAR LW_FCAT.
** LW_FCAT-COL_POS = col_pos.
** LW_FCAT-TABNAME = TABNAME.
** LW_FCAT-SELTEXT_L = &1.
** LW_FCAT-SELTEXT_M = &1.
** LW_FCAT-SELTEXT_S = &1.
** LW_FCAT-FIELDNAME = &2.
** APPEND P_LW_FCAT TO IT_FIELDCAT.
** END-OF-DEFINITION.
*
LW_FCAT-COL_POS = ''.
LW_FCAT-SELTEXT_L = 'SALARY'.
LW_FCAT-SELTEXT_M = 'SALARY'.
LW_FCAT-SELTEXT_S = 'SALARY'.
LW_FCAT-EMPHASIZE = 'C710'. "设置字段的颜色
LW_FCAT-DO_SUM = 'X'. "立即求和,只有I,F,P类型的列可以求和 MODIFY IT_FIELDCAT FROM LW_FCAT
TRANSPORTING EMPHASIZE SELTEXT_L SELTEXT_M SELTEXT_S EMPHASIZE DO_SUM
WHERE FIELDNAME = 'ESLRY'. CLEAR LW_FCAT.
LW_FCAT-HOTSPOT = 'X'.
LW_FCAT-KEY = 'X'.
MODIFY IT_FIELDCAT FROM LW_FCAT
TRANSPORTING REF_TABNAME HOTSPOT KEY
WHERE FIELDNAME = 'EMPID'. ENDFORM. " FRM_REDEFINE_FIELD
*&---------------------------------------------------------------------*
*& Form FRM_STATUS_EX
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_STATUS_EX USING EXTAB TYPE SLIS_T_EXTAB.
DATA:BEGIN OF TAB OCCURS ,
FCODE LIKE RSMPE-FUNC,
END OF TAB. TAB-FCODE = '&OL0'.APPEND TAB.
TAB-FCODE = '&OAD'.APPEND TAB.
TAB-FCODE = '&AVE'.APPEND TAB. SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'
EXCLUDING TAB IMMEDIATELY. ENDFORM. " FRM_STATUS_EX *&---------------------------------------------------------------------*
*& Form FRM_ALV_USER_COMMD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_ALV_USER_COMMD USING R_UCOMM TYPE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD. DATA LW_EMPTEST TYPE CHAR10 VALUE 'ZEMP_TEST'. CASE R_UCOMM.
WHEN 'PICK'.
* READ TABLE IT_ASSET INTO IW_ASSET INDEX RS_SELFIELD-TABINDEX.
SET PARAMETER ID: 'DTB' FIELD LW_EMPTEST. CALL TRANSACTION 'SE11' ."AND SKIP FIRST SCREEN.
ENDCASE. ENDFORM. " FRM_ALV_USER_COMMAND *&---------------------------------------------------------------------*
*& Form FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_ALV_DISPLAY .
DATA LW_REPID TYPE SY-REPID.
LW_REPID = SY-REPID. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = LW_REPID
I_CALLBACK_PF_STATUS_SET = 'FRM_STATUS_EX'
I_CALLBACK_USER_COMMAND = 'FRM_ALV_USER_COMMD'
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME = 'ZEMP_TEST'
* I_BACKGROUND_ID = ' '
I_GRID_TITLE = 'ALV DEMO'
* I_GRID_SETTINGS =
IS_LAYOUT = IW_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS = IT_EVENT
* 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 = IT_ZEMP
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> .
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. ENDFORM. " FRM_ALV_DISPLAY
- 列颜色
列的颜色很简单,在构成ALV字段的FIELDCAT内表中有一个字段是EMPHASIZE,将一个char型4位的颜色代码分配到FIELDCAT内表这个字段即可。
LW_FCAT-EMPHASIZE = 'C710'. "设置字段的颜色 MODIFY IT_FIELDCAT FROM LW_FCAT
TRANSPORTING EMPHASIZE
WHERE FIELDNAME = 'ESLRY'.
- 行颜色
1. 在构成ALV数据的内表中,添加一个char型4位的字段(CLR),用来记录颜色代码
TABLES ZEMP_TEST. TYPES: BEGIN OF TY_ZEMP.
INCLUDE STRUCTURE ZEMP_TEST.
TYPES: CLR TYPE CHAR4,"可以控制行颜色
END OF TY_ZEMP. DATA: IT_ZEMP TYPE STANDARD TABLE OF TY_ZEMP,
IW_ZEMP TYPE TY_ZEMP.
2. 循环内表,设置颜色代码
LOOP AT IT_ZEMP INTO IW_ZEMP.
"员工编号为‘3的行,颜色为红色
IF IW_ZEMP-EMPID = ''.
IW_ZEMP-CLR = 'C610'.
MODIFY IT_ZEMP FROM IW_ZEMP.
CLEAR IW_ZEMP.
ENDIF.
ENDLOOP.
3. LAYOUT结构中INFO_FIELDNAME的值指定为 CLR
IW_LAYOUT-INFO_FIELDNAME = 'CLR'. "行颜色代码的字段
- 单元格颜色
单元格颜色的设置与行颜色设计基本一致
1. 在构成ALV数据的内表中,添加一个内表 CellColor,用来记录颜色代码,需要设置颜色的字段名
TYPES: BEGIN OF TY_ZEMP.
INCLUDE STRUCTURE ZEMP_TEST.
TYPES: CLR TYPE CHAR4,
CELLCOLOR TYPE LVC_T_SCOL, "单元格颜色
END OF TY_ZEMP.
CellColor的结构:FNAME ALV 控制: 内部表字段的字段名称
COLOR ALV 控制: 颜色代码 COLOR是一个结构:COL ALV 控制: 颜色
INT ALV 控制: 强化 1/0
INV ALV 控制: 相反 1/0 设置颜色是前景,或者是背景
NOKEYCOL ALV 控制: 覆盖码颜色
2. 循环内表,设置颜色代码
3. LAYOUT结构中COLTAB_FIELDNAME的值指定为CELLCOLOR
IW_LAYOUT-COLTAB_FIELDNAME = 'CELLCOLOR'. "单元格颜色内表字段
最后在调用ALV函数时,设置layout,fieldcat参数
IS_LAYOUT = IW_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
- ALV工具栏
可以自定义工具栏,或者添加标准ALV工具栏,然后去除一些不需要的功能,这样可以保留标准工具栏的功能
DATA:BEGIN OF TAB OCCURS ,
FCODE LIKE RSMPE-FUNC,
END OF TAB. TAB-FCODE = '&OL0'.APPEND TAB.
TAB-FCODE = '&OAD'.APPEND TAB.
TAB-FCODE = '&AVE'.APPEND TAB. SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'
EXCLUDING TAB IMMEDIATELY.
- 求和
LW_FCAT-DO_SUM = 'X'. "立即求和,只有I,F,P类型的列可以求和
----------------------------------------------------------
附:ALV的颜色代码:http://blog.csdn.net/wren2004/article/details/3941551
DATA: ok_code LIKE sy-ucomm, save_ok LIKE sy-ucomm, g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1', grid1 TYPE REF TO cl_gui_alv_grid, g_custom_container TYPE REF TO cl_gui_custom_container, gs_layout TYPE lvc_s_layo, g_max TYPE i VALUE . *§1.Extend your output table for a field, e.g., CELLTAB, that holds * information about the edit status of each cell for the * corresponding row (the table type is SORTED!). DATA: BEGIN OF gt_outtab OCCURS . "with header line INCLUDE STRUCTURE sflight. DATA: celltab TYPE lvc_t_styl. DATA: END OF gt_outtab. *---------------------------------------------------------------------* * MAIN * *---------------------------------------------------------------------* CALL SCREEN . *---------------------------------------------------------------------* * MODULE PBO OUTPUT * *---------------------------------------------------------------------* MODULE pbo OUTPUT. SET PF-STATUS 'MAIN100'. SET TITLEBAR 'MAIN100'. IF g_custom_container IS INITIAL. CREATE OBJECT g_custom_container EXPORTING container_name = g_container. CREATE OBJECT grid1 EXPORTING i_parent = g_custom_container. PERFORM select_data_and_init_style. *§3.Provide the fieldname of the celltab field by using field * STYLEFNAME of the layout structure. gs_layout-stylefname = 'CELLTAB'. CALL METHOD grid1->set_table_for_first_display EXPORTING i_structure_name = 'SFLIGHT' is_layout = gs_layout CHANGING it_outtab = gt_outtab[]. ENDIF. ENDMODULE. "pbo OUTPUT *---------------------------------------------------------------------* * MODULE PAI INPUT * *---------------------------------------------------------------------* MODULE pai INPUT. save_ok = ok_code. CLEAR ok_code. CASE save_ok. WHEN 'EXIT'. PERFORM exit_program. WHEN 'SWITCH'. PERFORM switch_edit_mode. WHEN OTHERS. * do nothing ENDCASE. ENDMODULE. "pai INPUT *---------------------------------------------------------------------* * FORM EXIT_PROGRAM * *---------------------------------------------------------------------* FORM exit_program. LEAVE PROGRAM. ENDFORM. "exit_program *&---------------------------------------------------------------------* *& Form SELECT_DATA_AND_INIT_STYLE *&---------------------------------------------------------------------* FORM select_data_and_init_style. DATA: lt_sflight TYPE TABLE OF sflight WITH HEADER LINE, lt_celltab TYPE lvc_t_styl, l_index TYPE i. SELECT * FROM sflight INTO TABLE lt_sflight UP TO g_max ROWS. * move corresponding fields from lt_sflight to gt_outtab LOOP AT lt_sflight. MOVE-CORRESPONDING lt_sflight TO gt_outtab. APPEND gt_outtab. ENDLOOP. *§2.After selecting data, set edit status for each row in a loop * according to field SEATSMAX. LOOP AT gt_outtab. l_index = sy-tabix. REFRESH lt_celltab. IF gt_outtab-seatsmax GE . PERFORM fill_celltab USING 'RW' CHANGING lt_celltab. ELSE. PERFORM fill_celltab USING 'RO' CHANGING lt_celltab. ENDIF. *§2c.Copy your celltab to the celltab of the current row of gt_outtab. INSERT LINES OF lt_celltab INTO TABLE gt_outtab-celltab. MODIFY gt_outtab INDEX l_index. ENDLOOP. ENDFORM. " SELECT_DATA_AND_INIT_STYLE *&---------------------------------------------------------------------* *& Form FILL_CELLTAB *&---------------------------------------------------------------------* FORM fill_celltab USING value(p_mode) CHANGING pt_celltab TYPE lvc_t_styl. DATA: ls_celltab TYPE lvc_s_styl, l_mode TYPE raw4. * This forms sets the style of column 'PRICE' editable * according to 'p_mode' and the rest to read only either way. IF p_mode EQ 'RW'. *§2a.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_ENABLED to set a cell * to status "editable". l_mode = cl_gui_alv_grid=>mc_style_enabled. ELSE. "p_mode eq 'RO' *§2b.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_DISABLED to set a cell * to status "non-editable". l_mode = cl_gui_alv_grid=>mc_style_disabled. ENDIF. ls_celltab-fieldname = 'CARRID'. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = 'CONNID'. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = 'FLDATE'. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = 'PRICE'. ls_celltab-style = l_mode. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = 'CURRENCY'. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = 'PLANETYPE'. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = 'SEATSMAX'. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = 'SEATSOCC'. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ls_celltab-fieldname = 'PAYMENTSUM'. ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled. INSERT ls_celltab INTO TABLE pt_celltab. ENDFORM. " FILL_CELLTAB *&---------------------------------------------------------------------* *& Form SWITCH_EDIT_MODE *&---------------------------------------------------------------------* FORM switch_edit_mode. IF grid1->is_ready_for_input( ) EQ . * set edit enabled cells ready for input CALL METHOD grid1->set_ready_for_input EXPORTING i_ready_for_input = . ELSE. * lock edit enabled cells against input CALL METHOD grid1->set_ready_for_input EXPORTING i_ready_for_input = . ENDIF. ENDFORM. " SWITCH_EDIT_MODE
-------------------------------------------------
REPORT zmmr_perf_eval_vend. “Types Declaration
TYPES:BEGIN OF t_disp,
lifnr TYPE lifnr,
name1 TYPE name1_gp,
bedat TYPE bedat,
rfq TYPE I ,
quot TYPE I ,
po TYPE I ,
cont TYPE I ,
sch TYPE I ,
END OF t_disp,
BEGIN OF t_temp,
lifnr TYPE lifnr,
CNT TYPE I ,
END OF t_temp,
BEGIN OF t_lfa1,
lifnr TYPE lifnr,
name1 TYPE name1_gp,
END OF t_lfa1. “For ALV {
DATA: “it_layout TYPE lvc_s_layo,
gr_table TYPE REF TO cl_salv_table,
gr_functions TYPE REF TO cl_salv_functions,
gr_columns TYPE REF TO cl_salv_columns_table,
gr_column TYPE REF TO cl_salv_column_table,
gr_display TYPE REF TO cl_salv_display_settings,
lr_grid TYPE REF TO cl_salv_form_layout_grid,
lr_gridx TYPE REF TO cl_salv_form_layout_grid,
lr_logo TYPE REF TO cl_salv_form_layout_logo,
lr_label TYPE REF TO cl_salv_form_label,
lr_text TYPE REF TO cl_salv_form_text,
lr_footer TYPE REF TO cl_salv_form_layout_grid,
ls_color TYPE lvc_s_colo
.
” For ALV } DATA: it_disp TYPE TABLE OF t_disp,
wa_disp LIKE LINE OF it_disp,
it_temp TYPE TABLE OF t_temp,
wa_temp LIKE LINE OF it_temp,
it_lfa1 TYPE TABLE OF t_lfa1,
wa_lfa1 LIKE LINE OF it_lfa1. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT– .
SELECT-OPTIONS : s_lifnr FOR wa_disp– lifnr,
s_bedat FOR wa_disp– bedat.
SELECTION-SCREEN END OF BLOCK b1. *———————————————————————-*
* CLASS lcl_Perf_Eval DEFINITION
*———————————————————————-*
*
*———————————————————————-*
CLASS lcl_perf_eval DEFINITION .
PUBLIC SECTION.
METHODS: constructor ,
fill_disp.
METHODS build_fc.
METHODS disp_alv.
METHODS set_tol.
METHODS end_of_page. ENDCLASS. “lcl_perf_eval DEFINITION *———————————————————————-*
* CLASS lcl_perf_eval IMPLEMENTATION
*———————————————————————-*
*
*———————————————————————-*
CLASS lcl_perf_eval IMPLEMENTATION .
METHOD constructor.
TRY.
cl_salv_table=> factory( IMPORTING r_salv_table = gr_table CHANGING t_table = it_disp ). “Calling Factory Obj of Cl_ALV_TABLE
CATCH cx_salv_msg.
ENDTRY . IF gr_table IS INITIAL .
MESSAGE TEXT – TYPE ‘I’ DISPLAY LIKE ‘E’.
EXIT .
ENDIF .
ENDMETHOD. “constructor METHOD fill_disp.
“RFQ
SELECT a~lifnr COUNT( DISTINCT a~ebeln ) AS rfq FROM ekko AS a
JOIN ekpo AS b ON a~ ebeln = b ~ebeln
INTO CORRESPONDING FIELDS OF TABLE it_disp
WHERE a~lifnr IN s_lifnr AND bedat IN s_bedat
AND b~loekz NE ‘X’
AND a~bstyp = ‘A’
GROUP BY a~lifnr . “WRITE sy-dbcnt.
“Quot
SELECT lifnr COUNT( DISTINCT ebeln ) AS CNT FROM ekko
APPENDING CORRESPONDING FIELDS OF TABLE it_temp
WHERE lifnr IN s_lifnr AND bedat IN s_bedat
AND loekz EQ space
AND ( bstyp = ‘A’ AND statu = ‘A’ )
GROUP BY lifnr. LOOP AT it_temp INTO wa_temp .
wa_disp– lifnr = wa_temp –lifnr.
wa_disp– quot = wa_temp –CNT.
MODIFY it_disp FROM wa_disp TRANSPORTING lifnr quot WHERE lifnr = wa_temp–lifnr .
CLEAR : wa_disp, wa_temp.
ENDLOOP . ” PO
REFRESH it_temp.
SELECT lifnr COUNT( DISTINCT a~ ebeln ) AS CNT FROM ekko AS a JOIN ekpo AS b ON a~ ebeln = b ~ebeln
APPENDING CORRESPONDING FIELDS OF TABLE it_temp
WHERE lifnr IN s_lifnr AND bedat IN s_bedat
AND b~loekz EQ space
AND bsart NE ‘UB’
AND ( a~ bstyp = ‘F’ )
GROUP BY lifnr. LOOP AT it_temp INTO wa_temp .
wa_disp– lifnr = wa_temp –lifnr.
wa_disp– po = wa_temp –CNT.
MODIFY it_disp FROM wa_disp TRANSPORTING lifnr po WHERE lifnr = wa_temp–lifnr .
IF sy–subrc NE .
APPEND wa_disp TO it_disp .
ENDIF .
CLEAR : wa_disp, wa_temp.
ENDLOOP . “Cont. Created
REFRESH it_temp.
SELECT lifnr COUNT( DISTINCT a~ ebeln ) AS CNT FROM ekko AS a JOIN ekpo AS b ON a~ ebeln = b ~ebeln
APPENDING CORRESPONDING FIELDS OF TABLE it_temp
WHERE lifnr IN s_lifnr AND bedat IN s_bedat
AND b~loekz EQ space
AND ( a~ bstyp = ‘K’ )
GROUP BY lifnr. LOOP AT it_temp INTO wa_temp .
wa_disp– lifnr = wa_temp –lifnr.
wa_disp– cont = wa_temp –CNT.
MODIFY it_disp FROM wa_disp TRANSPORTING lifnr cont WHERE lifnr = wa_temp–lifnr .
IF sy–subrc NE .
APPEND wa_disp TO it_disp .
ENDIF .
CLEAR : wa_disp, wa_temp.
ENDLOOP . “Sch Aggre
REFRESH it_temp.
SELECT lifnr COUNT( DISTINCT a~ ebeln ) AS CNT FROM ekko AS a JOIN ekpo AS b ON a~ ebeln = b ~ebeln
APPENDING CORRESPONDING FIELDS OF TABLE it_temp
WHERE lifnr IN s_lifnr AND bedat IN s_bedat
AND b~loekz EQ space
AND ( a~ bstyp = ‘L’ )
GROUP BY lifnr. LOOP AT it_temp INTO wa_temp .
wa_disp– lifnr = wa_temp –lifnr.
wa_disp– sch = wa_temp –CNT.
MODIFY it_disp FROM wa_disp TRANSPORTING lifnr sch WHERE lifnr = wa_temp–lifnr .
IF sy–subrc NE .
APPEND wa_disp TO it_disp .
ENDIF .
CLEAR : wa_disp, wa_temp.
ENDLOOP . SELECT lifnr name1 FROM lfa1
INTO CORRESPONDING FIELDS OF TABLE it_lfa1
FOR ALL ENTRIES IN it_disp
WHERE lifnr = it_disp –lifnr. LOOP AT it_disp INTO wa_disp .
READ TABLE it_lfa1 INTO wa_lfa1 WITH KEY lifnr = wa_disp–lifnr .
IF sy–subrc EQ .
wa_disp– name1 = wa_lfa1 –name1.
MODIFY it_disp FROM wa_disp TRANSPORTING lifnr name1 WHERE lifnr = wa_disp– lifnr .
ENDIF .
ENDLOOP . SORT it_disp BY lifnr . ENDMETHOD. “fill_disp
METHOD build_fc. INCLUDE <color>.
TRY.
gr_columns = gr_table->get_columns ( ).
gr_columns-> set_optimize( abap_true ).
gr_column ?= gr_columns-> get_column( ‘LIFNR’ ).
ls_color– col = .
gr_column-> set_color( ls_color ). CATCH cx_salv_not_found.
ENDTRY . TRY.
gr_column ?= gr_columns-> get_column( ‘NAME1’ ).
gr_column-> set_long_text(‘Vendor Name’ ).
gr_column-> set_short_text( ‘V.Name’ ).
gr_column-> set_medium_text(‘Vendor Name’ ).
ls_color– col = .
gr_column-> set_color( ls_color ).
CATCH cx_salv_not_found.
ENDTRY . TRY.
gr_column ?= gr_columns-> get_column( ‘BEDAT’ ).
gr_column-> set_visible( abap_false ).
gr_column-> set_technical( VALUE = if_salv_c_bool_sap=> true ).
CATCH cx_salv_not_found.
ENDTRY . TRY.
gr_column ?= gr_columns-> get_column( ‘RFQ’ ).
gr_column-> set_short_text( ‘RFQ’ ).
gr_column-> set_medium_text( ‘RFQ Created’ ).
CATCH cx_salv_not_found.
ENDTRY . TRY.
gr_column ?= gr_columns-> get_column( ‘QUOT’ ).
gr_column-> set_short_text( ‘Quot.’ ).
gr_column-> set_medium_text( ‘Quotation Maintained’ ).
CATCH cx_salv_not_found.
ENDTRY .
TRY.
gr_column ?= gr_columns-> get_column( ‘PO’ ).
gr_column-> set_short_text( ‘PO Created’ ).
CATCH cx_salv_not_found.
ENDTRY . TRY.
gr_column ?= gr_columns-> get_column( ‘CONT’ ).
gr_column-> set_short_text( ‘Cont.’ ).
gr_column-> set_medium_text( ‘Contract Created’ ).
CATCH cx_salv_not_found.
ENDTRY .
TRY.
gr_column ?= gr_columns-> get_column( ‘SCH’ ).
gr_column-> set_short_text( ‘Sch. Crea.’ ).
gr_column-> set_medium_text( ‘Sch. Agr. Created’ ).
gr_column-> set_long_text( ‘Schedule Agreement Created’ ).
CATCH cx_salv_not_found.
ENDTRY . ENDMETHOD. “build_fc METHOD disp_alv. set_tol( ).
build_fc( ).
end_of_page( ). gr_functions = gr_table->get_functions ( ).
gr_functions-> set_all( abap_true ).
gr_table-> set_top_of_list( lr_logo ).
gr_table-> set_end_of_list( lr_footer ).
gr_display = gr_table->get_display_settings ( ).
gr_display-> set_striped_pattern( cl_salv_display_settings =>true ). gr_table-> display( ). ENDMETHOD. “disp_alv
METHOD set_tol.
DATA : lv_text( ) TYPE C ,
lv_date TYPE C LENGTH . CREATE OBJECT lr_grid. lr_grid-> create_header_information( row = column =
TEXT = ‘MM: Vendor Evaluation’
tooltip = ‘MM: Vendor Evaluation’ ). lr_gridx = lr_grid->create_grid ( row = column = ).
lr_label = lr_gridx->create_label ( row = column =
TEXT = ‘Vendor No # :’ tooltip = ‘Vendor #.’ ). IF s_lifnr IS NOT INITIAL .
lv_text = s_lifnr–low .
IF s_lifnr–high IS NOT INITIAL.
CONCATENATE lv_text ‘ to ‘ s_lifnr –high INTO lv_text SEPARATED BY space.
ENDIF .
ELSE .
lv_text = ‘Not Provided’.
ENDIF .
lr_text = lr_gridx->create_text ( row = column =
TEXT = lv_text tooltip = lv_text ).
“Vendor
lr_label = lr_gridx->create_label ( row = column =
TEXT = ‘Posting Date:’ tooltip = ‘Posting Date’ ).
IF s_bedat IS NOT INITIAL .
WRITE s_bedat–low DD/MM/YYYY TO lv_text .
IF s_bedat–high IS NOT INITIAL.
WRITE s_bedat–high DD/MM/YYYY TO lv_date.
CONCATENATE lv_text ‘ to ‘ lv_date INTO lv_text SEPARATED BY space.
ENDIF .
ELSE .
lv_text = ‘Not Provided’.
ENDIF . lr_text = lr_gridx->create_text ( row = column =
TEXT = lv_text tooltip = lv_text ). lr_label = lr_gridx->create_label ( row = column =
TEXT = ‘Run Date:’ tooltip = ‘Run Date’ ).
lr_text = lr_gridx->create_text ( row = column =
TEXT = sy– datum tooltip = sy –datum ). lr_label = lr_gridx->create_label ( row = column = ).
lr_label = lr_gridx->create_label ( row = column = ).
lr_label = lr_gridx->create_label ( row = column = ).
lr_label = lr_gridx->create_label ( row = column = ). * Create logo layout, set grid content on left and logo image on right
CREATE OBJECT lr_logo.
lr_logo-> set_left_content( lr_grid ).
lr_logo-> set_right_logo( ‘ZCHEM_N_LOGO_SMALL’ ). ” Image From OAER T.code ENDMETHOD. “set_Tol METHOD end_of_page. DATA :lf_lines TYPE sy–tfill . DATA : “lr_label TYPE REF TO cl_salv_form_label,
lf_flow TYPE REF TO cl_salv_form_layout_flow . CREATE OBJECT lr_footer.
*–get total lines in internal table
lf_lines = LINES( it_disp ).
lr_label = lr_footer->create_label ( row = column = ).
lr_label-> set_text( ‘Information:’ ).
lf_flow = lr_footer->create_flow ( row = column = ).
lf_flow-> create_text( TEXT = ‘Total Number of Entries’ ).
lf_flow = lr_footer->create_flow ( row = column = ).
lf_flow-> create_text( TEXT = lf_lines ). ENDMETHOD. “end_of_page ENDCLASS. “lcl_perf_eval IMPLEMENTATION START-OF-SELECTION.
DATA : obj_rep TYPE REF TO lcl_perf_eval. ” Declaring Object for Class CREATE OBJECT : obj_rep. ” Creating Object obj_rep->fill_disp( ). ” Calling class Methods
obj_rep->disp_alv( ).