alv grid 自用代码
以前自己总结的alv grid的模板,可以直接复制。后来懒也没改和完善,就先放着吧
效果图
代码部分
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
REPORT ZSTEST. *LINE-SIZE 255 NO STANDARD PAGE HEADING. *---------------------------------------------------------------* " System : " Module : DEMO " T-code : " Program : Z " Author : sutton sun " Date : 2016.2.16 " Description : 程序注释规范样例 " " *---------------------------------------------------------------* " Modified Recorder : * 2016.2.17 spec12 sutton sun 修改内容 " ----------- ------- ------------ --------------- *---------------------------------------------------------------* *---------------------------------------------------------------- * DECLARATIONS *---------------------------------------------------------------- TABLES:BKPF. TYPE-POOLS:ABAP,SLIS,ICON. *---------------------------------------------------------------- *INTERNAL TABLES *---------------------------------------------------------------- DATA: BEGIN OF I_OUT OCCURS 0, BUKRS LIKE BKPF-BUKRS, GJAHR LIKE BKPF-GJAHR,"FISCAL YEAR BELNR LIKE BKPF-BELNR,"DOCUMENT NO.会计凭证编号 MONAT LIKE BKPF-MONAT,"PERIOD 期间 WAERS LIKE BKPF-WAERS,"CURRENCY BUZEI LIKE BSEG-BUZEI,"ITEM NO 行项目号 HKONT LIKE BSEG-HKONT,"I/G ACCOUNT WRBTR LIKE BSEG-WRBTR,"AMOUNT URL(100) TYPE C, SEL(1) TYPE C, ROWCOLOR(4) TYPE C , TRAFFIC_LIGHTS TYPE ICON_D, "红绿灯 END OF I_OUT. " 输出 DATA:I_BSEG LIKE TABLE OF I_OUT WITH HEADER LINE. DATA: FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE. " *&---------------------------------------------------------------------* *& PROGRAM VARIABLES程序变量 *&---------------------------------------------------------------------* DATA: WA_LAYOUT TYPE LVC_S_LAYO, GT_EVENTS TYPE SLIS_T_EVENT, GS_EVENT LIKE LINE OF GT_EVENTS. DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID. *&---------------------------------------------------------------------* *& Definition *&---------------------------------------------------------------------* DEFINE FILL_FIELD. CLEAR FIELDCAT. FIELDCAT-FIELDNAME = &1. FIELDCAT-SCRTEXT_L = &2. FIELDCAT-CFIELDNAME = &3. FIELDCAT-OUTPUTLEN = &4. FIELDCAT-EDIT = &5. APPEND FIELDCAT. END-OF-DEFINITION. *----------------------------------------------------------------------* * Contants *----------------------------------------------------------------------* CONSTANTS: C_ICON_YELLOW_LIGHT(4) TYPE C VALUE '@09@', C_ICON_GREEN_LIGHT(4) TYPE C VALUE '@08@', C_ICON_RED_LIGHT(4) TYPE C VALUE '@0A@'. *---------------------------------------------------------------- * SELECTION-SCREEN *---------------------------------------------------------------- SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001. PARAMETERS: BUKRS TYPE BKPF-BUKRS OBLIGATORY . SELECT-OPTIONS: GJAHR FOR BKPF-GJAHR, BELNR FOR BKPF-GJAHR, MONAT FOR BKPF-MONAT DEFAULT SY-DATUM+4(2). SELECTION-SCREEN: END OF BLOCK B1. *---------------------------------------------------------------- * INITIALIZATION *---------------------------------------------------------------- INITIALIZATION. *---------------------------------------------------------------- * AT SELECTION-SCREEN *---------------------------------------------------------------- AT SELECTION-SCREEN. * PERFORM FRM_AUTHORIZATION_CHECK. *---------------------------------------------------------------- * START-OF-SELECTION *---------------------------------------------------------------- START-OF-SELECTION. PERFORM FRM_GET_DATA. PERFORM FRM_DATA_PROCESS. *---------------------------------------------------------------- *END-OF-SELECTION *---------------------------------------------------------------- END-OF-SELECTION. * IF I_OUT[] IS NOT INITIAL. PERFORM FRM_DISPLAY_DATA. * ELSE. MESSAGE 'No suitable data was selected, please check your input' TYPE 'I'. * ENDIF. *---------------------------------------------------------------- * *---------------------------------------------------------------- *&---------------------------------------------------------------------* *& Form FRM_GET_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_GET_DATA . SELECT BUKRS GJAHR BELNR MONAT WAERS INTO CORRESPONDING FIELDS OF TABLE I_OUT FROM BKPF WHERE BUKRS = BKPF-BUKRS AND GJAHR = BKPF-GJAHR. SELECT BUZEI HKONT WRBTR INTO CORRESPONDING FIELDS OF TABLE I_BSEG FROM BSEG WHERE BUZEI = I_BSEG-BUZEI AND HKONT = I_BSEG-HKONT AND WRBTR = I_BSEG-WRBTR . LOOP AT I_OUT. READ TABLE I_BSEG WITH KEY BELNR = I_OUT-BELNR GJAHR = I_OUT-GJAHR BUKRS = I_OUT-BUKRS. IF SY-SUBRC = 0. I_OUT-BUZEI = I_BSEG-BUZEI. I_OUT-HKONT = I_BSEG-HKONT. I_OUT-WRBTR = I_BSEG-WRBTR. MODIFY I_OUT . ENDIF. CLEAR I_OUT. CLEAR I_BSEG. ENDLOOP. ENDFORM. " FRM_GET_DATA *&---------------------------------------------------------------------* *& Form FRM_DATA_PROCESS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_DATA_PROCESS . * LOOP AT I_OUT . * IF I_OUT-CONNID = '17'. * I_OUT-TRAFFIC_LIGHTS = C_ICON_GREEN_LIGHT. * ELSE. * I_OUT-TRAFFIC_LIGHTS = C_ICON_RED_LIGHT. * ENDIF. * I_OUT-ROWCOLOR = 'C710'. * MODIFY I_OUT TRANSPORTING ROWCOLOR TRAFFIC_LIGHTS. " 颜色设置 * ENDLOOP. ENDFORM. " FRM_DATA_PROCESS *&---------------------------------------------------------------------* *& Form FRM_DISPLAY_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_DISPLAY_DATA . PERFORM FRM_LAYOUT. PERFORM FRM_FILL_FIELD. PERFORM FRM_BUILD_EVENT. PERFORM FRM_ALV_DISPLAY. ENDFORM. " FRM_DISPLAY_DATA *&---------------------------------------------------------------------* *& Form FRM_LAYOUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_LAYOUT . CLEAR: WA_LAYOUT."它用来定义ALV报表的整体属性 * WA_LAYOUT-ZEBRA = 'X' ."ZBbra * WA_LAYOUT-DETAILINIT = 'X' . "initial values on detail screen WA_LAYOUT-CWIDTH_OPT = 'X'."优化列宽选项是否设置 * WA_LAYOUT-DETAILTITL = 'Detail Information' ."设置弹出窗口的标题栏 WA_LAYOUT-BOX_FNAME = 'SEL'. * WA_LAYOUT-INFO_FNAME = 'ROWCOLOR'. * WA_LAYOUT-GRID_TITLE = 'Alv grid title test'. ENDFORM. " FRM_LAYOUT *&---------------------------------------------------------------------* *& Form FRM_FILL_FIELD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_FILL_FIELD . REFRESH FIELDCAT. CLEAR FIELDCAT. FIELDCAT-FIELDNAME = 'TRAFFIC_LIGHTS'. FIELDCAT-SCRTEXT_L = 'Traffic Lights'. FIELDCAT-CFIELDNAME = ''. FIELDCAT-OUTPUTLEN = '8'. APPEND FIELDCAT. FILL_FIELD 'CARRID' 'Airline Code' '' '20' ''. FILL_FIELD 'CONNID' 'Flight Connection Number' '' '20' ''. FILL_FIELD 'COUNTRYFR' 'Country from' '' '3' ''. * FILL_FIELD 'CITYFROM' 'Departure city' '' '18' ''. FILL_FIELD 'CITYFROM' TEXT-004 '' '18' ''. * CLEAR FIELDCAT. * READ TABLE FIELDCAT WITH KEY FIELDNAME = 'PASSNAME'. * IF SY-SUBRC = 0. * FIELDCAT-LOWERCASE = 'X'. * MODIFY FIELDCAT INDEX SY-TABIX TRANSPORTING LOWERCASE . * ENDIF. CLEAR FIELDCAT. FIELDCAT-FIELDNAME = 'COUNTRYTO'. FIELDCAT-SCRTEXT_L = 'Country To'. FIELDCAT-CFIELDNAME = ''. FIELDCAT-OUTPUTLEN = '18'. FIELDCAT-EDIT = 'X'. APPEND FIELDCAT. * CLEAR FIELDCAT. FIELDCAT-FIELDNAME = 'CITYTO'. FIELDCAT-SCRTEXT_L = 'City To'. FIELDCAT-CFIELDNAME = ''. FIELDCAT-OUTPUTLEN = '8'. FIELDCAT-EMPHASIZE = 'C600'. APPEND FIELDCAT. * * CLEAR FIELDCAT. * FIELDCAT-FIELDNAME = 'CITYTO'. * FIELDCAT-SCRTEXT_L = 'City To'. * FIELDCAT-CFIELDNAME = ''. * FIELDCAT-OUTPUTLEN = '8'. * APPEND FIELDCAT. * ENDFORM. " FRM_FILL_FIELD *&---------------------------------------------------------------------* *& Form FRM_BUILD_EVENT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_BUILD_EVENT . REFRESH:GT_EVENTS. * CALL FUNCTION 'REUSE_ALV_EVENTS_GET' * EXPORTING * I_LIST_TYPE = 0 * IMPORTING * ET_EVENTS = GT_EVENTS. GS_EVENT-NAME = SLIS_EV_PF_STATUS_SET. GS_EVENT-FORM = 'PF_STATUS'. APPEND GS_EVENT TO GT_EVENTS. CLEAR GS_EVENT. * PERFORM PF_STATUS USING LT_EXTAB. MOVE SLIS_EV_TOP_OF_PAGE TO GS_EVENT-NAME. MOVE 'FRM_TOP_OF_PAGE' TO GS_EVENT-FORM. APPEND GS_EVENT TO GT_EVENTS. CLEAR GS_EVENT. * PERFORM FRM_TOP_OF_PAGE. * i_events-name = slis_ev_user_command. * i_events-form = 'USER_COMMAND'. * APPEND i_events. * CLEAR i_events. * CLEAR gs_event. * gs_event-name = 'CALLER_EXIT'. * gs_event-form = 'CALLER_EXIT'. * APPEND gs_event TO gt_events. ENDFORM. " FRM_BUILD_EVENT *&---------------------------------------------------------------------* *& Form FRM_ALV_DISPLAY *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_ALV_DISPLAY . DATA: IS_VARIANT LIKE DISVARIANT, I_GRID_SETTINGS TYPE LVC_S_GLAY. * I_GRID_SETTINGS-EDT_CLL_CB = 'X'. * IS_VARIANT-VARIANT = P_VARI. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING I_CALLBACK_PROGRAM = SY-REPID * I_GRID_SETTINGS = I_GRID_SETTINGS IT_FIELDCAT_LVC = FIELDCAT[] IT_EVENTS = GT_EVENTS * IS_VARIANT = IS_VARIANT I_SAVE = 'A' * I_DEFAULT = 'X' IS_LAYOUT_LVC = WA_LAYOUT * I_GRID_TITLE = 'Alv test-FM' I_CALLBACK_USER_COMMAND = 'USER_COMMAND' TABLES T_OUTTAB = I_OUT EXCEPTIONS OTHERS = 2. ENDFORM. " FRM_ALV_DISPLAY *&---------------------------------------------------------------------* *& Form user_command *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->UCOMM text * -->RS_SELFIELD text *----------------------------------------------------------------------* FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM RS_SELFIELD TYPE SLIS_SELFIELD. "#EC CALLED DATA: L_LINE TYPE I, L_INDEX TYPE I. DATA: L_VALID TYPE CHAR01. CASE UCOMM. WHEN '&IC1'. READ TABLE I_OUT INDEX RS_SELFIELD-TABINDEX. IF SY-SUBRC = 0. L_INDEX = RS_SELFIELD-TABINDEX. IF RS_SELFIELD-FIELDNAME = 'CARRID'. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING E_GRID = G_GRID. CALL METHOD G_GRID->CHECK_CHANGED_DATA IMPORTING E_VALID = L_VALID. IF L_VALID IS INITIAL. EXIT. ENDIF. * IF I_OUT-CARRID <> '' . * CALL SCREEN '0500' STARTING AT 35 5 * ENDING AT 135 25. * ENDIF. ELSEIF RS_SELFIELD-FIELDNAME = 'CONNID'. IF I_OUT-URL IS NOT INITIAL. CALL FUNCTION 'CALL_BROWSER' EXPORTING URL = I_OUT-URL. ENDIF. ENDIF. ENDIF. WHEN 'SAVE'. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING E_GRID = G_GRID. CALL METHOD G_GRID->CHECK_CHANGED_DATA IMPORTING E_VALID = L_VALID. IF L_VALID IS INITIAL. EXIT. ENDIF. * PERFORM frm_update_data. * WHEN 'CHANGE'. * PERFORM FRM_CHANGE_DATA. WHEN 'EXCEL'. IF SY-SUBRC = 0. ENDIF. * PERFORM frm_export_to_excel. ENDCASE. RS_SELFIELD-REFRESH = 'X'. RS_SELFIELD-COL_STABLE = 'X'. RS_SELFIELD-ROW_STABLE = 'X'. ENDFORM. "user_command *&---------------------------------------------------------------------* *& Form pf_status *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->LT_EXTAB text *----------------------------------------------------------------------* FORM PF_STATUS USING LT_EXTAB. "#EC NEEDED * SET PF-STATUS 'MENU'."SAPLKKBL STANDARD SET PF-STATUS 'MENU_01'."SAPLKKBL STANDARD ENDFORM. "PF_STATUS *&---------------------------------------------------------------------* *& Form frm_authorization_check *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_AUTHORIZATION_CHECK . * DATA: I_T001W LIKE TABLE OF T001W WITH HEADER LINE. * SELECT * * INTO TABLE I_T001W * FROM T001W * WHERE WERKS IN S_WERKS. * IF SY-SUBRC = 0. * LOOP AT I_T001W. * AUTHORITY-CHECK OBJECT 'C_AFKO_AWA' * ID 'ACTVT' DUMMY * ID 'AUTYP' DUMMY * ID 'AUFART' DUMMY * ID 'WERKS' FIELD I_T001W-WERKS. * IF SY-SUBRC <> 0. * MESSAGE 'No authorization for the plant!' TYPE 'E'. * ENDIF. * ENDLOOP. * ELSE. * MESSAGE 'plant does not exist,pelease check your input of plant!' TYPE 'E'. * ENDIF. ENDFORM. " frm_authorization_check *&---------------------------------------------------------------------* *& Form FRM_TOP_OF_PAGE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_TOP_OF_PAGE . DATA: WA_HEADER TYPE SLIS_LISTHEADER, I_HEADER TYPE SLIS_T_LISTHEADER. CLEAR: WA_HEADER. REFRESH:I_HEADER. WA_HEADER-TYP = 'S'. WA_HEADER-KEY = 'Top-of-page'. WA_HEADER-INFO = 'Top-of-page-info'. APPEND WA_HEADER TO I_HEADER. CLEAR WA_HEADER. WA_HEADER-TYP = 'S'. WA_HEADER-KEY = 'Top-of-page-Second'. WA_HEADER-INFO = 'Top-of-page-info-Second'. APPEND WA_HEADER TO I_HEADER. CLEAR WA_HEADER. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING IT_LIST_COMMENTARY = I_HEADER * I_LOGO = * I_END_OF_LIST_GRID = I_ALV_FORM = 'X' . ENDFORM. " FRM_TOP_OF_PAGE |