REPORT z_archive_test.
DATA: taskname(10) TYPE n VALUE '1',"Task name administration
snd_jobs TYPE i VALUE 0,"Sent jobs
rcv_jobs TYPE i VALUE 0,"Received replies
wa_indx TYPE indx.
DATA: gt_log TYPE zesp1_message_tab_type_test WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK bl00 WITH FRAME TITLE text-000.
PARAMETERS: p_datum LIKE sy-datum OBLIGATORY DEFAULT sy-datum,"归档时间点
p_thrcnt LIKE sy-tabix OBLIGATORY DEFAULT 100,"每个线程处理数据记录条数
p_maxcnt LIKE sy-tabix DEFAULT 1000."总共读取数据条数
SELECTION-SCREEN END OF BLOCK bl00.
START-OF-SELECTION.
CALL FUNCTION 'SPBT_INITIALIZE'
EXPORTING
group_name = serv_group"可不填
* IMPORTING
* MAX_PBT_WPS = 最大线程数
* FREE_PBT_WPS = 空闲线程数
EXCEPTIONS
invalid_group_name = 1
internal_error = 2
pbt_env_already_initialized = 3
currently_no_resources_avail = 4
no_pbt_resources_found = 5
cant_init_different_pbt_groups = 6
OTHERS = 7
.
PERFORM frm_do_it.
*&---------------------------------------------------------------------*
*& Form frm_do_it
*&---------------------------------------------------------------------*
* 分批取数 多线程数据处理
*----------------------------------------------------------------------*
FORM frm_do_it.
DATA: ekko_cursor TYPE cursor,
lt_ekko TYPE TABLE OF ekko.
OPEN CURSOR WITH HOLD ekko_cursor FOR
SELECT *
UP TO p_maxcnt ROWS
FROM ekko
WHERE ekko~aedat <= p_datum .
DO.
FETCH NEXT CURSOR ekko_cursor
INTO TABLE lt_ekko
PACKAGE SIZE p_thrcnt."阀值
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF LINES( lt_ekko ) <> 0.
DO.
CALL FUNCTION 'ZARCHIVE_EKKO_TEST' "Make the FM as RFC enabled.
STARTING NEW TASK taskname
DESTINATION IN GROUP DEFAULT
PERFORMING frm_reveive_result ON END OF TASK
EXPORTING
taskname = taskname
TABLES
it_ekko = lt_ekko
EXCEPTIONS
resource_failure = 1
OTHERS = 2.
IF sy-subrc = 0.
snd_jobs = snd_jobs + 1.
EXIT.
ELSE.
WAIT UNTIL rcv_jobs = snd_jobs.
ENDIF.
"如果1000次尝试还没有成功,即放弃
IF sy-index > 1000.
EXIT.
ENDIF.
ENDDO.
taskname = taskname + 1.
ELSE.
MESSAGE '未找到指定选择的数据' TYPE 'S'.
STOP.
"EXIT.
ENDIF.
ENDDO.
CLOSE CURSOR ekko_cursor.
WAIT UNTIL rcv_jobs = snd_jobs."执行完成,统计结果
LOOP AT gt_log.
gt_log-lineno = sy-tabix.
MODIFY gt_log.
ENDLOOP.
CALL FUNCTION 'C14Z_MESSAGES_SHOW_AS_POPUP'
TABLES
i_message_tab = gt_log.
ENDFORM. "frm_do_it
*&---------------------------------------------------------------------*
*& Form frm_reveive_result
*&---------------------------------------------------------------------*
* 接收现成执行结果
*----------------------------------------------------------------------*
FORM frm_reveive_result USING taskname.
DATA: lt_log TYPE zesp1_message_tab_type_test.
RECEIVE RESULTS
FROM FUNCTION 'ZARCHIVE_EKKO_TEST'
IMPORTING
et_log = lt_log.
"如果接收不成功,则使程序dump掉
IF sy-subrc <> 0.
ENDIF.
rcv_jobs = rcv_jobs + 1. "Receiving data
APPEND LINES OF lt_log TO gt_log.
REFRESH lt_log.
ENDFORM. "frm_reveive_result
***********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
FUNCTION zarchive_ekko_test.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(TASKNAME) TYPE CHAR10
*" EXPORTING
*" VALUE(ET_LOG) TYPE ZESP1_MESSAGE_TAB_TYPE_TEST
*" TABLES
*" IT_EKKO STRUCTURE EKKO
*"----------------------------------------------------------------------
DATA: wa_log TYPE zesp1_message_wa_type_test.
wa_log-msgid = 'ZFI'.
wa_log-msgty = 'S'.
wa_log-msgno = '000'.
CONCATENATE taskname '任务开始' INTO wa_log-msgv1.
APPEND wa_log TO et_log.
ENDFUNCTION.