

具备自动刷新功能的 SAP ABAP ALV 报表
source link: https://segmentfault.com/a/1190000040048922
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

具备自动刷新功能的 SAP ABAP ALV 报表
该报表主要结构如下,完整代码见文末。
- f_call_rfc_wait: 发起异步调用,等待 1 秒钟,来模拟每隔 1 秒刷新屏幕的效果。
- f_display_data: ALV 常规操作,调用函数 REUSE_ALV_LIST_DISPLAY 显示 ALV 数据。
- f_read_data: 调用函数 THUSRINFO,返回的结果作为 ALV 的数据源。该函数返回当前系统登录的用户名列表:
完整代码:
REPORT ZALV_AUTO_REFRESH.
DATA :
gt_user LIKE uinfo OCCURS 0 WITH HEADER LINE. " User info in SM04
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_display_data.
*---------------------------------------------------------------------*
* Form F_LIRE_DATA
*---------------------------------------------------------------------*
FORM f_read_data.
REFRESH gt_user.
* Get User's info
CALL FUNCTION 'THUSRINFO'
TABLES
usr_tabl = gt_user.
* Wait in a task
PERFORM f_call_rfc_wait.
ENDFORM. " F_READ_DATA
*---------------------------------------------------------------------*
* Form F_DISPLAY_DATA
*---------------------------------------------------------------------*
FORM f_display_data.
DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
append ls_sort to lt_sort.
END-OF-DEFINITION.
DEFINE m_event_exit.
clear ls_event_exit.
ls_event_exit-ucomm = &1.
ls_event_exit-after = 'X'.
append ls_event_exit to lt_event_exit.
END-OF-DEFINITION.
DATA :
ls_layout TYPE slis_layout_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
lt_event_exit TYPE slis_t_event_exit,
ls_event_exit TYPE slis_event_exit.
* Build Sort Table
m_sort 'ZEIT'.
* Build Event Exit Table
m_event_exit '&NTE'. " Refresh
ls_layout-zebra = 'X'.
ls_layout-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND'
is_layout = ls_layout
i_structure_name = 'UINFO'
it_sort = lt_sort
it_event_exit = lt_event_exit
TABLES
t_outtab = gt_user.
ENDFORM. " F_DISPLAY_DATA
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM user_command USING i_ucomm TYPE syucomm
is_selfield TYPE slis_selfield. "#EC CALLED
CASE i_ucomm.
WHEN '&NTE'.
PERFORM f_read_data.
is_selfield-refresh = 'X'.
SET USER-COMMAND '&OPT'. " Optimize columns width
ENDCASE.
ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------*
* Form F_CALL_RFC_WAIT
*---------------------------------------------------------------------*
FORM f_call_rfc_wait.
DATA lv_mssg(80). "#EC NEEDED
* Wait in a task
CALL FUNCTION 'RFC_PING_AND_WAIT' STARTING NEW TASK '001'
PERFORMING f_task_end ON END OF TASK
EXPORTING
seconds = 1 " Refresh time
busy_waiting = space
EXCEPTIONS
RESOURCE_FAILURE = 1
communication_failure = 2 MESSAGE lv_mssg
system_failure = 3 MESSAGE lv_mssg
OTHERS = 4.
ENDFORM. " F_CALL_RFC_WAIT
*---------------------------------------------------------------------*
* Form F_TASK_END
*---------------------------------------------------------------------*
FORM f_task_end USING u_taskname.
DATA lv_mssg(80). "#EC NEEDED
* Receiving task results
RECEIVE RESULTS FROM FUNCTION 'RFC_PING_AND_WAIT'
EXCEPTIONS
RESOURCE_FAILURE = 1
communication_failure = 2 MESSAGE lv_mssg
system_failure = 3 MESSAGE lv_mssg
OTHERS = 4.
CHECK sy-subrc EQ 0.
SET USER-COMMAND '&NTE'. " Refresh
ENDFORM. " F_TASK_END
*************** END OF PROGRAM Z_ALV_AUTO_REFRESH *********************
更多Jerry的原创文章,尽在:"汪子熙":
Recommend
-
14
自动出报表,零代码做驾驶舱,我到了Excel的顶级替代李启方数据分析不是个事儿大家有没...
-
1
报表设计器是什么?报表自动生成器有哪些? ...
-
13
How to print footer in ALV report Hello Everyone, I have seen so many questions were raised on how to print footer in ALV. I checked all answers and did code but still it is not working. Hence I raised t...
-
8
Display logo in ALV Report. I am happy to share my very first blog post on SAP ABAP Programming using ALV. In this blog post you will learn how to display logo in your ALV Report. How to Create a Logo
-
5
Interactable split-screen ALV (using CL_SALV_TABLE) One ALV with headers and a second with details of selected row – quite a common use-case. And won’t it be practical to have all this in one screen, so users can check det...
-
4
Uncle Editable ALV Grid 0 2 117 Did you know that CL_SALV_TABLE is not officially editable? An...
-
5
Chen Feng February 7, 2023
-
101
select multiple rows in alv of cl_salv_table Skip to Content ...
-
8
Adnan Khan August 22, 2023 2 minute read
-
2
How to refresh ALV Data in SALV on Click Event.
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK