OO ALV 后台运行时错误:Control Framework: Fatal error - GUI cannot be reached
这个错误的原因,是GUI容器依赖GUI的存在,因为它是在后台运行,没有GUI,因此控制错误。
可以通过做一些编码绕过这个。
* ALV Grid DATA: R_GRID TYPE REF TO CL_GUI_ALV_GRID. DATA: R_CONTROL TYPE REF TO CL_GUI_CUSTOM_CONTAINER. DATA: G_DOCK TYPE REF TO CL_GUI_DOCKING_CONTAINER. MODULE STATUS_0100 OUTPUT. SET PF-STATUS 'LISTOUT1'. SET TITLEBAR 'LIST1'. IF R_CONTROL IS INITIAL. * Check whether the program is run in batch or foreground(判断是否后台运行) IF CL_GUI_ALV_GRID=>OFFLINE( ) IS INITIAL. * Run in foreground CREATE OBJECT R_CONTROL EXPORTING CONTAINER_NAME = 'CONTAINER_1'. CREATE OBJECT R_GRID EXPORTING I_PARENT = R_CONTROL. ELSE. * Run in background CREATE OBJECT R_GRID EXPORTING I_PARENT = G_DOCK. ENDIF. * Structure ZBA_MARA1 is defined in DDIC as linetype CALL METHOD R_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING I_STRUCTURE_NAME = 'MARA' CHANGING IT_OUTTAB = ITAB. ENDIF. ENDMODULE. " STATUS_0100 OUTPUT