在做类的ALV显示时,我们会设置ALV的LAYOUT参数,使用CWIDTH_OPT = ‘X’.来实现ALV显示时的自动宽度,但发现在多个屏幕跳转后,ALV刷新后,再次显示ALV时,此参数不起作用,ALV不能自动宽度来显示,
1.解决办法
在再次显示ALV时,刷新前重新设置一下自动宽度的参数 ,并重设置一下就行了,OO ALV完整显示代码如下:
代码中使用GET_FRONTEND_LAYOUT得到当前的LAYOUT参数,并重设置CWIDTH_OPT = ‘X’,最后调用SET_FRONTEND_LAYOUT设置一下参数 ,结果就对了。
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 |
MODULE INIT_ALV_0200 OUTPUT. CLEAR:LS_LAYOUT. IF GO_ALV_200 IS INITIAL. PERFORM FRM_EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE. PERFORM FRM_SET_FIELDCAT USING '2'. CREATE OBJECT GO_CUSTOMER_200 EXPORTING CONTAINER_NAME = 'CONTAINER_200'. CREATE OBJECT GO_ALV_200 EXPORTING I_PARENT = GO_CUSTOMER_200. LS_LAYOUT-CWIDTH_OPT = 'X'. LS_LAYOUT-SEL_MODE = 'A'. LS_VARIANT-REPORT = SY-REPID. CALL METHOD GO_ALV_200->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_LAYOUT = LS_LAYOUT IT_TOOLBAR_EXCLUDING = LT_EXCLUDE I_SAVE = 'U' IS_VARIANT = LS_VARIANT CHANGING IT_FIELDCATALOG = GT_FCAT_200 IT_OUTTAB = GT_OUT_200. CREATE OBJECT GO_EVENT_200. SET HANDLER GO_EVENT_200->HAND_DOUBLE_CLICK FOR GO_ALV_200. SET HANDLER GO_EVENT_200->HANDLE_DATA_CHANGED FOR GO_ALV_200. CALL METHOD GO_ALV_200->SET_TOOLBAR_INTERACTIVE. CALL METHOD GO_ALV_200->REGISTER_EDIT_EVENT EXPORTING I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED. CALL METHOD GO_ALV_200->REGISTER_EDIT_EVENT EXPORTING I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER. ELSE. GO_ALV_200->GET_FRONTEND_LAYOUT( IMPORTING ES_LAYOUT = LS_LAYOUT ). LS_LAYOUT-CWIDTH_OPT = 'X'. GO_ALV_200->SET_FRONTEND_LAYOUT( IS_LAYOUT = LS_LAYOUT ). CALL METHOD GO_ALV_200->REFRESH_TABLE_DISPLAY EXCEPTIONS FINISHED = 1 OTHERS = 2. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO INTO MSGTEXT WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDIF. ENDMODULE. |