直接代码不解释:
1 *&---------------------------------------------------------------------* 2 *& Report ZRDEMO 3 *& 4 *&---------------------------------------------------------------------* 5 *& 6 *& 7 *&---------------------------------------------------------------------* 8 9 REPORT ZRDEMO2. 10 11 TABLES:MAKT,MARC. 12 TYPE-POOLS:SLIS. 13 14 TYPES:BEGIN OF TY_ALV. 15 INCLUDE TYPE MAKT. 16 TYPES: ZCHECK TYPE C, 17 END OF TY_ALV. 18 19 *ALV 20 DATA:GT_ALV TYPE TABLE OF TY_ALV. 21 DATA:GS_ALV TYPE TY_ALV. 22 DATA:GT_FIELDCAT TYPE LVC_T_FCAT. 23 DATA:GS_FIELDCAT TYPE LVC_S_FCAT. 24 DATA:GS_LAYOUT TYPE LVC_S_LAYO. 25 26 27 *---------------------------------------------------------------------* 28 *选择屏幕 29 *---------------------------------------------------------------------* 30 SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001. 31 SELECT-OPTIONS:S_MATNR FOR MAKT-MATNR. 32 33 SELECTION-SCREEN END OF BLOCK B1. 34 35 36 SELECTION-SCREEN COMMENT /3(40) COMM1. 37 SELECTION-SCREEN COMMENT /3(40) COMM2. 38 SELECTION-SCREEN COMMENT /3(40) COMM3. 39 40 INITIALIZATION. 41 COMM1 = '备注1'. 42 COMM2 = '备注2'. 43 COMM3 = '备注3'. 44 45 46 47 *---------------------------------------------------------------------* 48 *START-OF-SELECTION. 49 *---------------------------------------------------------------------* 50 START-OF-SELECTION. 51 PERFORM FRM_GET_DATA. 52 PERFORM FRM_DISPLAY_ALV. 53 54 55 56 57 *&---------------------------------------------------------------------* 58 *& Form FRM_GET_DATA 59 *&---------------------------------------------------------------------* 60 * text 61 *----------------------------------------------------------------------* 62 FORM FRM_GET_DATA . 63 64 SELECT MANDT 65 MATNR 66 SPRAS 67 MAKTX 68 MAKTG 69 INTO TABLE GT_ALV 70 FROM MAKT 71 WHERE MATNR IN S_MATNR 72 AND SPRAS = SY-LANGU. 73 74 75 IF GT_ALV IS INITIAL. 76 MESSAGE '没有找到数据' TYPE 'S' DISPLAY LIKE 'E'. 77 LEAVE LIST-PROCESSING. 78 ENDIF. 79 80 ENDFORM. " FRM_GET_DATA 81 82 83 *&---------------------------------------------------------------------* 84 *& Form FRM_DISPLAY_ALV 85 *&---------------------------------------------------------------------* 86 * text 87 *----------------------------------------------------------------------* 88 FORM FRM_DISPLAY_ALV . 89 PERFORM FRM_SET_FILEDCAT. 90 PERFORM FRM_SET_LAYOUT. 91 PERFORM FRM_DISPLAY. 92 ENDFORM. " FRM_DISPLAY_ALV 93 94 95 *&---------------------------------------------------------------------* 96 *& Form FRM_SET_FILEDCAT 97 *&---------------------------------------------------------------------* 98 * text 99 *----------------------------------------------------------------------* 100 FORM FRM_SET_FILEDCAT . 101 GS_FIELDCAT-FIELDNAME = 'MANDT'. 102 GS_FIELDCAT-COLTEXT = '客户端'. 103 GS_FIELDCAT-NO_ZERO = 'X'. 104 APPEND GS_FIELDCAT TO GT_FIELDCAT. 105 CLEAR GS_FIELDCAT. 106 GS_FIELDCAT-FIELDNAME = 'MATNR'. 107 GS_FIELDCAT-COLTEXT = '物料号'. 108 GS_FIELDCAT-NO_ZERO = 'X'. 109 APPEND GS_FIELDCAT TO GT_FIELDCAT. 110 CLEAR GS_FIELDCAT. 111 GS_FIELDCAT-FIELDNAME = 'SPRAS'. 112 GS_FIELDCAT-COLTEXT = '语言代码'. 113 APPEND GS_FIELDCAT TO GT_FIELDCAT. 114 CLEAR GS_FIELDCAT. 115 GS_FIELDCAT-FIELDNAME = 'MAKTX'. 116 GS_FIELDCAT-COLTEXT = '物料描述(短文本)'. 117 APPEND GS_FIELDCAT TO GT_FIELDCAT. 118 CLEAR GS_FIELDCAT. 119 GS_FIELDCAT-FIELDNAME = 'MAKTG'. 120 GS_FIELDCAT-COLTEXT = '有关匹配码的大写的物料描述'. 121 APPEND GS_FIELDCAT TO GT_FIELDCAT. 122 CLEAR GS_FIELDCAT. 123 ENDFORM. " FRM_SET_FILEDCAT 124 125 126 *&---------------------------------------------------------------------* 127 *& Form FRM_SET_LAYOUT 128 *&---------------------------------------------------------------------* 129 * text 130 *----------------------------------------------------------------------* 131 FORM FRM_SET_LAYOUT . 132 GS_LAYOUT-ZEBRA = 'X'. 133 GS_LAYOUT-SEL_MODE = 'A'. "选择模式 134 GS_LAYOUT-CWIDTH_OPT = 'X'. 135 GS_LAYOUT-BOX_FNAME = 'ZCHECK'. 136 ENDFORM. " FRM_SET_LAYOUT 137 138 139 *&---------------------------------------------------------------------* 140 *& Form FRM_DISPLAY 141 *&---------------------------------------------------------------------* 142 * text 143 *----------------------------------------------------------------------* 144 FORM FRM_DISPLAY . 145 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' 146 EXPORTING 147 * I_INTERFACE_CHECK = ' ' 148 * I_BYPASSING_BUFFER = 149 I_BUFFER_ACTIVE = 'X' 150 I_CALLBACK_PROGRAM = SY-REPID 151 I_CALLBACK_PF_STATUS_SET = 'FRM_STATUS_SET' 152 I_CALLBACK_USER_COMMAND = 'FRM_USER_COMMAND' 153 * I_CALLBACK_TOP_OF_PAGE = 'FRM_SET_HEADER' 154 * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' 155 * I_CALLBACK_HTML_END_OF_LIST = ' ' 156 * I_STRUCTURE_NAME = 157 * I_BACKGROUND_ID = G_REPID 158 * I_GRID_TITLE = 159 * I_GRID_SETTINGS = I_GRID_SETTINGS 160 IS_LAYOUT_LVC = GS_LAYOUT 161 IT_FIELDCAT_LVC = GT_FIELDCAT 162 * IT_EXCLUDING = 163 * IT_SPECIAL_GROUPS_LVC = 164 * IT_SORT_LVC = 165 * IT_FILTER_LVC = 166 * IT_HYPERLINK = 167 * IS_SEL_HIDE = 168 * I_DEFAULT = 'X' 169 I_SAVE = 'X' 170 * IS_VARIANT = 171 * IT_EVENTS = GT_EVENTS 172 * IT_EVENT_EXIT = 173 * IS_PRINT_LVC = 174 * IS_REPREP_ID_LVC = 175 * I_SCREEN_START_COLUMN = 0 176 * I_SCREEN_START_LINE = 0 177 * I_SCREEN_END_COLUMN = 0 178 * I_SCREEN_END_LINE = 0 179 * I_HTML_HEIGHT_TOP = 180 * I_HTML_HEIGHT_END = 181 * IT_ALV_GRAPHICS = 182 * IT_EXCEPT_QINFO_LVC = 183 * IR_SALV_FULLSCREEN_ADAPTER = 184 * IMPORTING 185 * E_EXIT_CAUSED_BY_CALLER = 186 * ES_EXIT_CAUSED_BY_USER = 187 TABLES 188 T_OUTTAB = GT_ALV 189 EXCEPTIONS 190 PROGRAM_ERROR = 1 191 OTHERS = 2. 192 IF SY-SUBRC <> 0. 193 ENDIF. 194 ENDFORM. " FRM_DISPLAY 195 196 197 198 *&---------------------------------------------------------------------* 199 *& Form FRM_STATUS_SET 200 *&---------------------------------------------------------------------* 201 * text 202 *----------------------------------------------------------------------* 203 * -->RT_EXTAB text 204 *----------------------------------------------------------------------* 205 FORM FRM_STATUS_SET USING RT_EXTAB TYPE SLIS_T_EXTAB. 206 SET PF-STATUS 'STANDARD' . 207 ENDFORM. "FRM_STATUS_SET 208 209 210 *&---------------------------------------------------------------------* 211 *& Form FRM_USER_COMMAND 212 *&---------------------------------------------------------------------* 213 * text 214 *----------------------------------------------------------------------* 215 * -->R_UCOMM text 216 * -->RS_SELFIELD text 217 *----------------------------------------------------------------------* 218 FORM FRM_USER_COMMAND USING 219 R_UCOMM LIKE SY-UCOMM 220 RS_SELFIELD TYPE SLIS_SELFIELD. 221 222 CASE R_UCOMM. 223 WHEN 'ZPRINT'. 224 BREAK-POINT. 225 MESSAGE 'ZPRINT' TYPE 'S'. 226 WHEN OTHERS. 227 ENDCASE. 228 229 ENDFORM. "FRM_USER_COMMAND