ABAP--SAP是如何控制REUSE_ALV_GRID_DISPLAY函数嵌套调用的返回控制

本文深入探讨了REUSE_ALV_GRID_DISPLAY函数的工作原理,重点介绍了该函数如何利用全局内表gt_grid作为堆栈来实现屏幕间的准确切换。通过具体的代码示例,展示了函数调用时的入栈与出栈操作。

最近无事对REUSE_ALV_GRID_DISPLAY函数代码又进行了一次阅读,发现该函数使用了堆栈进行嵌套调用的控制。sap使用全局内表gt_grid作为堆栈,每次调用REUSE_ALV_GRID_DISPLAY函数都会调用globals_push子过程进行入栈处理,返回时globals_pop会调用做出站处理。这样就保证了屏幕之间的切换的准确性。

代码摘抄如下,参见红色标记

function reuse_alv_grid_display. "#EC *
*"----------------------------------------------------------------------
*"*"Globale Schnittstelle:
*" IMPORTING
*" REFERENCE(I_INTERFACE_CHECK) DEFAULT SPACE
*" VALUE(I_BYPASSING_BUFFER) TYPE CHAR01 DEFAULT SPACE
*" VALUE(I_BUFFER_ACTIVE) DEFAULT SPACE
*" REFERENCE(I_CALLBACK_PROGRAM) LIKE SY-REPID DEFAULT SPACE
*" REFERENCE(I_CALLBACK_PF_STATUS_SET) TYPE SLIS_FORMNAME DEFAULT
*" SPACE
*" REFERENCE(I_CALLBACK_USER_COMMAND) TYPE SLIS_FORMNAME DEFAULT
*" SPACE
*" REFERENCE(I_CALLBACK_TOP_OF_PAGE) TYPE SLIS_FORMNAME DEFAULT
*" SPACE
*" REFERENCE(I_CALLBACK_HTML_TOP_OF_PAGE) TYPE SLIS_FORMNAME
*" DEFAULT SPACE
*" REFERENCE(I_CALLBACK_HTML_END_OF_LIST) TYPE SLIS_FORMNAME
*" DEFAULT SPACE
*" REFERENCE(I_STRUCTURE_NAME) LIKE DD02L-TABNAME OPTIONAL
*" REFERENCE(I_BACKGROUND_ID) TYPE SDYDO_KEY DEFAULT SPACE
*" REFERENCE(I_GRID_TITLE) TYPE LVC_TITLE OPTIONAL
*" REFERENCE(I_GRID_SETTINGS) TYPE LVC_S_GLAY OPTIONAL
*" REFERENCE(IS_LAYOUT) TYPE SLIS_LAYOUT_ALV OPTIONAL
*" REFERENCE(IT_FIELDCAT) TYPE SLIS_T_FIELDCAT_ALV OPTIONAL
*" REFERENCE(IT_EXCLUDING) TYPE SLIS_T_EXTAB OPTIONAL
*" REFERENCE(IT_SPECIAL_GROUPS) TYPE SLIS_T_SP_GROUP_ALV OPTIONAL
*" REFERENCE(IT_SORT) TYPE SLIS_T_SORTINFO_ALV OPTIONAL
*" REFERENCE(IT_FILTER) TYPE SLIS_T_FILTER_ALV OPTIONAL
*" REFERENCE(IS_SEL_HIDE) TYPE SLIS_SEL_HIDE_ALV OPTIONAL
*" REFERENCE(I_DEFAULT) DEFAULT 'X'
*" REFERENCE(I_SAVE) DEFAULT SPACE
*" REFERENCE(IS_VARIANT) LIKE DISVARIANT STRUCTURE DISVARIANT
*" OPTIONAL
*" REFERENCE(IT_EVENTS) TYPE SLIS_T_EVENT OPTIONAL
*" REFERENCE(IT_EVENT_EXIT) TYPE SLIS_T_EVENT_EXIT OPTIONAL
*" REFERENCE(IS_PRINT) TYPE SLIS_PRINT_ALV OPTIONAL
*" REFERENCE(IS_REPREP_ID) TYPE SLIS_REPREP_ID OPTIONAL
*" REFERENCE(I_SCREEN_START_COLUMN) DEFAULT 0
*" REFERENCE(I_SCREEN_START_LINE) DEFAULT 0
*" REFERENCE(I_SCREEN_END_COLUMN) DEFAULT 0
*" REFERENCE(I_SCREEN_END_LINE) DEFAULT 0
*" REFERENCE(IT_ALV_GRAPHICS) TYPE DTC_T_TC OPTIONAL
*" REFERENCE(IT_HYPERLINK) TYPE LVC_T_HYPE OPTIONAL
*" REFERENCE(IT_ADD_FIELDCAT) TYPE SLIS_T_ADD_FIELDCAT OPTIONAL
*" REFERENCE(IT_EXCEPT_QINFO) TYPE SLIS_T_QINFO_ALV OPTIONAL
*" REFERENCE(I_HTML_HEIGHT_TOP) TYPE I OPTIONAL
*" REFERENCE(I_HTML_HEIGHT_END) TYPE I OPTIONAL
*" EXPORTING
*" REFERENCE(E_EXIT_CAUSED_BY_CALLER)
*" REFERENCE(ES_EXIT_CAUSED_BY_USER) TYPE SLIS_EXIT_BY_USER
*" TABLES
*" T_OUTTAB
*" EXCEPTIONS
*" PROGRAM_ERROR
*"----------------------------------------------------------------------

clear e_exit_caused_by_caller.
clear es_exit_caused_by_user.

*... Trace?
if ( cl_alv_trace=>is_trace_on( ) eq 1 ).
create object mr_trace.

call method mr_trace->add_trace_item
exporting
i_trace_item = 'REUSE_ALV_GRID_DISPLAY'
is_vari_slis = is_variant
is_layo_slis = is_layout
is_prnt_slis = is_print
it_fcat_slis = it_fieldcat
it_sort_slis = it_sort
it_filt_slis = it_filter.
endif.

free memory id 'DYNDOS_FOR_ALV'.

perform globals_push.

gt_grid-flg_first_time = 'X'.

perform reprep_check.

g_repid = sy-repid.

if i_screen_start_column is initial and
i_screen_start_line is initial and
i_screen_start_column is initial and
i_screen_end_line is initial.
gt_grid-flg_popup = space.
call screen 500.
else.
gt_grid-flg_popup = 'X'.
call screen 700
starting at i_screen_start_column i_screen_start_line
ending at i_screen_end_column i_screen_end_line.
endif.

perform globals_pop.

clear g_repid.

endfunction.

*&---------------------------------------------------------------------* *& Report YTEST31 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT YTEST31. DATA: OK_CODE TYPE SY-UCOMM, SAVE_OK TYPE SY-UCOMM. TABLES SPFLI. DATA LS_SPFLI TYPE SPFLI. DATA WA_SPFLI TYPE TABLE OF SPFLI. DATA WADEL_SPFLI TYPE TABLE OF SPFLI. SELECT * INTO TABLE WA_SPFLI FROM SPFLI. DATA: WA_CONTAINER TYPE SCRFNAME VALUE 'ALVDATA', ALV_GRID TYPE REF TO CL_GUI_ALV_GRID, WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER. DATA WA_LAYOUT TYPE LVC_S_LAYO. WA_LAYOUT-EDIT = 'X'. CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED. DATA EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER. ************************************************************************ * CLASS LCL_EVENT_RECEIVER DEFINITION * * * ************************************************************************ CLASS LCL_EVENT_RECEIVER DEFINITION. PUBLIC SECTION. TYPES: DEL_ROWS TYPE STANDARD TABLE OF SPFLI. DATA: DDEL_ROWS TYPE STANDARD TABLE OF SPFLI. METHODS: HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID IMPORTING ER_DATA_CHANGED. METHODS: UPDATE_DELTA_TABLES IMPORTING PR_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL. METHODS: GET_DELETED_ROWS EXPORTING DELETED_ROWS TYPE DEL_ROWS. ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION *&-------------------------------------------------------------------------- *& CLASS LCL_EVENT_RECEIVER IMPLENTMENTATION *& *&-------------------------------------------------------------------------- CLASS LCL_EVENT_RECEIVER IMPLEMENTATION. METHOD HANDLE_DATA_CHANGED. CALL METHOD UPDATE_DELTA_TABLES( ER_DATA_CHANGED ). ENDMETHOD. "HANDLE_DATA_CHANGED METHOD UPDATE_DELTA_TABLES. "HANDLE_DATA_CHANGED DATA: L_DEL_ROW TYPE LVC_S_MOCE. LOOP AT PR_DATA_CHANGED->MT_DELETED_ROWS INTO L_DEL_ROW. READ TABLE WA_SPFLI INTO LS_SPFLI INDEX L_DEL_ROW-ROW_ID. IF SY-SUBRC NE 0. MESSAGE E208(00) WITH '?理??'. ELSE. APPEND LS_SPFLI TO DDEL_ROWS. ENDIF. ENDLOOP. ENDMETHOD. "UPDATE_DELTA_TABLES METHOD GET_DELETED_ROWS. "update_delta_tables DELETED_ROWS = ME->DDEL_ROWS. ENDMETHOD. "GET_DELETED_ROWS ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION START-OF-SELECTION. CALL SCREEN 100. WRITE / '?除的内表??'. "get_deleted_rows WRITE / '______________'. "LCL_EVENT_RECEIVER DEFINITION CALL METHOD EVENT_RECEIVER->GET_DELETED_ROWS IMPORTING DELETED_ROWS = WADEL_SPFLI. LOOP AT WADEL_SPFLI INTO SPFLI. WRITE: / SPFLI-CARRID,SPFLI-CONNID,SPFLI-CITYFROM. ENDLOOP. WRITE: / '更新后的内表??:'. WRITE: / '__________________'. LOOP AT WA_SPFLI INTO SPFLI. WRITE : / SPFLI-CARRID,SPFLI-CONNID,SPFLI-CITYFROM. ENDLOOP. *此?是更新到数据?的操作 *WHEN 'SAVE'. * MODIFY SPFLI FORM TABLE WA_SPFLI. * IF SY-SUBRC NE 0. *MESSAGE I005(YMESS) WITH '更新数据??!'. EXIT. * ELSE. * MESSAGE I005(YMESS) WITH '更新数据OK!'. * ENDIF. * DELETE SPFLI FROM TABLE DELA_SPFLI. * IF SY-SUBRC NE 0. * MESSAGE I005(YMESS) WITH '更新数据??!'. * ELSE. * MESSAGE I005(YMESS) WITH '更新数据OK!'. * ENDIF. END-OF-SELECTION. INCLUDE YTEST31_STATUS_100. INCLUDE YTEST31_USER_COMMAND_100.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值