经常会在ALV的状态栏上加入自定义的按钮(button),有时还需要动态更改自定义按钮上的文本和图标,如下:开始是修改按钮,点击后变成显示按钮,按钮上的显示的内容可以自动切换。
下面介绍具体实现方法:
1,现在程序中定义一个全局变量,类型是 smp_dyntxt
1 |
DATA:g_text TYPE smp_dyntxt. |
2,在创建状态(status)中的按钮时选择Dynamic Text选项
然后选择1中定义的全局变量
创建完如下:
完整代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
REPORT ztest_alv_lvc_button. DATA:go_grid TYPE REF TO cl_gui_alv_grid. DATA:g_text TYPE smp_dyntxt. DATA:g_display TYPE c. TYPES:BEGIN OF gty_ekko, ebeln TYPE ekko-ebeln, verkf TYPE ekko-verkf, sel TYPE c, "用来标识行选择的字段 END OF gty_ekko. DATA:git_ekko TYPE STANDARD TABLE OF gty_ekko, gwa_ekko TYPE gty_ekko. DATA:git_fcat TYPE lvc_t_fcat, gwa_fcat LIKE LINE OF git_fcat, gwa_layout TYPE lvc_s_layo. CONSTANTS: gco_callback_user_command TYPE slis_formname VALUE 'FRM_USER_COMMAND', gco_callback_status TYPE slis_formname VALUE 'FRM_USER_STATUS'. START-OF-SELECTION. SELECT ebeln verkf INTO CORRESPONDING FIELDS OF TABLE git_ekko FROM ekko UP TO 10 ROWS. PERFORM frm_set_catalog. gwa_layout-zebra = 'X'. gwa_layout-box_fname = 'SEL'. "指定行选择字段 gwa_layout-cwidth_opt = 'X'. * 初始化状态栏中的button g_text-icon_id = icon_change . g_text-text = 'Change' . g_text-icon_text = 'Change'. g_display = 'X'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid is_layout_lvc = gwa_layout it_fieldcat_lvc = git_fcat i_callback_pf_status_set = gco_callback_status i_callback_user_command = gco_callback_user_command TABLES t_outtab = git_ekko[] EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc = 0. ENDIF. *&---------------------------------------------------------------------* *& Form FRM_SET_PF_STATUS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_user_status USING i_it_extab TYPE slis_t_extab. SET PF-STATUS 'S0001' . ENDFORM. " FRM_SET_PF_STATUS FORM frm_user_command USING i_ucomm TYPE sy-ucomm i_wa_selfield TYPE slis_selfield. CASE i_ucomm. WHEN 'CHANGE'. "click Change button in application toolbar IF g_display = 'X'. g_text-icon_id = icon_display . g_text-text = 'Display' . g_text-icon_text = 'Display'. CLEAR:g_display. ELSE. g_text-icon_id = icon_change . g_text-text = 'Change' . g_text-icon_text = 'Change'. g_display = 'X'. ENDIF. WHEN '&IC1'. "Double click * if click on PO field, jump to me23n IF i_wa_selfield-fieldname = 'EBELN'. SET PARAMETER ID 'BES' FIELD i_wa_selfield-value. CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN. ENDIF. WHEN OTHERS. ENDCASE. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_SET_CATALOG *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_set_catalog . DATA:l_pos TYPE i VALUE 1. CLEAR: l_pos. l_pos = l_pos + 1. gwa_fcat-coltext = 'PO'. gwa_fcat-scrtext_l = 'PO'. gwa_fcat-scrtext_m = 'PO'. gwa_fcat-scrtext_s = 'PO'. gwa_fcat-fieldname = 'EBELN'. gwa_fcat-col_pos = l_pos. gwa_fcat-outputlen = '10'. APPEND gwa_fcat TO git_fcat. l_pos = l_pos + 1. gwa_fcat-coltext = 'PO item'. gwa_fcat-scrtext_l = 'PO item'. gwa_fcat-scrtext_m = 'PO item'. gwa_fcat-scrtext_s = 'PO item'. gwa_fcat-fieldname = 'VERKF'. gwa_fcat-col_pos = l_pos. gwa_fcat-outputlen = '20'. APPEND gwa_fcat TO git_fcat. ENDFORM. |
以上。
发表评论