https://www.cnblogs.com/sapSB/p/8532072.html
参考这个,做扩展,有些人喜欢用OO ALV有些喜欢用普通的CALL FUNC ALV。。。我只用LVC。。。
先说明一下,每个报表程序,我都会自定义工具栏,只是为了以防万一。工具栏有个一键填充的功能,可以把ALV常用的按钮都添加到工具栏,所以不需要自己去想加什么按钮。。
双击按钮进入工具栏界面,
入图,选择调整模板
普通的LIST,选择list viewer,下面那个复制程序的工具栏还不如直接从程序复制快。。。然后就可以了。
打印:https://www.cnblogs.com/sapSB/p/7735719.html
编辑:https://www.cnblogs.com/sapSB/p/5168184.html
今天新做的个测试例子:
REPORT YLY001. DATA:GT_FIELDCAT TYPE LVC_T_FCAT. DATA GS_FIELDCAT LIKE LINE OF GT_FIELDCAT. DATA LS_LAYOUT TYPE LVC_S_LAYO. DATA LT_EVENT TYPE SLIS_T_EVENT. DATA LS_EVENT LIKE LINE OF LT_EVENT. DATA LR_GRID TYPE REF TO CL_GUI_ALV_GRID. DATA:GT_T100 TYPE STANDARD TABLE OF T100, GS_T100 TYPE T100. DEFINE APPEND_FIELDCAT . CLEAR GS_FIELDCAT. GS_FIELDCAT-FIELDNAME = &1. GS_FIELDCAT-SCRTEXT_L = &2. GS_FIELDCAT-OUTPUTLEN = &3. GS_FIELDCAT-NO_ZERO = &4. GS_FIELDCAT-EDIT = &5. APPEND GS_FIELDCAT TO GT_FIELDCAT. END-OF-DEFINITION. START-OF-SELECTION. PERFORM PRM_GET_DATA. * PERFORM PRM_SET_FIELD. PERFORM PRM_SHOW. *&---------------------------------------------------------------------* *& Form PRM_GET_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM PRM_GET_DATA . SELECT * INTO TABLE GT_T100 FROM T100 UP TO 100 ROWS WHERE SPRSL = 'E' AND ARBGB = 'ZCRM_MSG'. ENDFORM. *&---------------------------------------------------------------------* *& Form PRM_SHOW *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM PRM_SHOW . REFRESH GT_FIELDCAT. LS_LAYOUT-CWIDTH_OPT = 'X'. "优化列宽选项是否设置 LS_LAYOUT-ZEBRA = 'X'. * ls_layout-box_fname = 'SEL'. APPEND_FIELDCAT:'SPRSL' '语言' 4 'X' '', 'ARBGB' '区域' 20 'X' '', 'MSGNR' '消息号' 3 'X' 'X', 'TEXT' '消息文本' 73 '' ''. DATA:LV_TITLE TYPE LVC_TITLE. DESCRIBE TABLE GT_T100 LINES LV_TITLE. CONDENSE LV_TITLE NO-GAPS. CONCATENATE '结果共' LV_TITLE '条目!' INTO LV_TITLE. REFRESH:LT_EVENT. LS_EVENT-FORM = 'DATA_CHANGED_METHOD'. LS_EVENT-NAME = 'DATA_CHANGED'. APPEND LS_EVENT TO LT_EVENT. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING I_CALLBACK_PROGRAM = SY-REPID I_CALLBACK_PF_STATUS_SET = 'PRM_SET_STATUS' I_CALLBACK_USER_COMMAND = 'PRM_USER_COMMAND' IS_LAYOUT_LVC = LS_LAYOUT IT_FIELDCAT_LVC = GT_FIELDCAT[] I_GRID_TITLE = LV_TITLE IT_EVENTS = LT_EVENT I_DEFAULT = 'X' I_SAVE = 'A' TABLES T_OUTTAB = GT_T100 EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2. IF SY-SUBRC <> 0. ENDIF. ENDFORM. FORM PRM_SET_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB. SET PF-STATUS 'ZSTAT'. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING E_GRID = LR_GRID. CALL METHOD LR_GRID->REGISTER_EDIT_EVENT EXPORTING I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED. IF SY-SUBRC <> 0. ENDIF. ENDFORM. FORM PRM_USER_COMMAND USING P_UCOMM LIKE SY-UCOMM P_SELFIELD TYPE SLIS_SELFIELD. CHECK P_UCOMM = '&IC1'. ENDFORM. FORM DATA_CHANGED_METHOD USING PA_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL . DATA: L_IT_DATA TYPE LVC_T_MODI, L_WA_DATA LIKE LINE OF L_IT_DATA. FIELD-SYMBOLS:<LV_FIELD> TYPE ANY. L_IT_DATA = PA_DATA_CHANGED->MT_MOD_CELLS. CHECK L_IT_DATA IS NOT INITIAL. LOOP AT PA_DATA_CHANGED->MT_MOD_CELLS INTO L_WA_DATA. READ TABLE GT_T100 INTO GS_T100 INDEX L_WA_DATA-ROW_ID. IF SY-SUBRC = 0. ASSIGN COMPONENT L_WA_DATA-FIELDNAME OF STRUCTURE GS_T100 TO <LV_FIELD>. IF SY-SUBRC = 0. <LV_FIELD> = L_WA_DATA-VALUE. IF L_WA_DATA-FIELDNAME = 'MSGNR'. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING INPUT = GS_T100-MSGNR IMPORTING OUTPUT = GS_T100-MSGNR. SELECT SINGLE TEXT INTO GS_T100-TEXT FROM T100 WHERE SPRSL = GS_T100-SPRSL AND ARBGB = GS_T100-ARBGB AND MSGNR = GS_T100-MSGNR. ENDIF. MODIFY GT_T100 FROM GS_T100 INDEX L_WA_DATA-ROW_ID. ENDIF. ENDIF. ENDLOOP. CALL METHOD LR_GRID->REFRESH_TABLE_DISPLAY. ENDFORM. " DATA_CHANGED_METHOD