多线程执行后台任务,提供效率
场景:
大批量复制物料描述到新的物料上,多线程同时执行已提高效率
REPORT zmm316.
INCLUDE zmm316_top.
INCLUDE zmm316_f01.
*-----------------------------------------------------------------------
- I N I T I A L I Z A T I O N
*-----------------------------------------------------------------------
INITIALIZATION.
*-----------------------------------------------------------------------
- A T S E L E C T I O N - S C R E E N
*-----------------------------------------------------------------------
AT SELECTION-SCREEN.
START-OF-SELECTION.
- 读取文件
- IF p_sc = ‘X’.
- PERFORM read_file.
- PERFORM frm_data_check.
- ELSEIF p_cx = ‘X’.
PERFORM frm_get_data.
- ENDIF.
&---------------------------------------------------------------------
*& 包含 ZMM316_TOP
&---------------------------------------------------------------------
----------------------------------------------------------------------
TABLES: sscrfields,ztmatnr_match,a017,mara.
TYPES: BEGIN OF ty_alv,
matnr_o TYPE mseg-matnr, "旧物料号
matnr_n TYPE mseg-matnr,
zdate TYPE ztmatnr_match-zdate,
ztime TYPE ztmatnr_match-ztime,
zsel TYPE char1,
zlight TYPE char04, " 指示灯
zmsg TYPE char100,
-
zwlsl type P LENGTH 10 DECIMALS 3,
-
zdate TYPE DATS,
-
zsl TYPE i, END OF ty_alv.
TYPES: BEGIN OF ty_alv2,
matnr_n(18) TYPE c,
zsel TYPE char1,
zlight TYPE char04, " 指示灯
zmsg TYPE char100,
-
zwlsl type P LENGTH 10 DECIMALS 3,
-
zdate TYPE DATS, END OF ty_alv2.
DATA:gt_alv TYPE STANDARD TABLE OF ty_alv. "定义内表
DATA:gs_alv TYPE ty_alv. "定义工作区
FIELD-SYMBOLS: <fs_alv> TYPE ty_alv.
DATA:gt_fieldcat TYPE lvc_t_fcat, "字段目录内表
gs_fieldcat TYPE lvc_s_fcat, "字段目录工作区
gs_layout TYPE lvc_s_layo. "用于定义ALV表单的相关格式、属性
*DATA:gt_index_all TYPE STANDARD TABLE OF ty_index,
-
gs_index TYPE ty_index.
DATA: gv_messages TYPE c LENGTH 200,
bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE,
gs_option TYPE ctu_params,
messtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE.
RANGES:r_matnr_old FOR mara-bismt.
RANGES:r_werks FOR a017-werks.
*-----------------------------------------------------------------------
- P A R A M E T E R S & S E L E C T - O P T I O N S
*----------------------------------------------------------------------- - 功能选择界面
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS: s_jmatnr FOR ztmatnr_match-matnr_old, "旧物料 -
s_werks FOR a017-werks OBLIGATORY,"工厂 s_xmatnr FOR ztmatnr_match-matnr_new NO-DISPLAY. "新物料
PARAMETERS: p_sjfb TYPE char07, "数据分包
p_htrw TYPE char04. "后台任务
SELECTION-SCREEN END OF BLOCK blk1.
- 下载模版按钮
SELECTION-SCREEN FUNCTION KEY 1.
&---------------------------------------------------------------------
*& 包含 ZMM316_F01
&---------------------------------------------------------------------
FORM frm_get_data .
SELECT bismt AS matnr_n
matnr AS matnr_o
INTO CORRESPONDING FIELDS OF TABLE gt_alv
FROM mara
WHERE matnr IN s_jmatnr
AND bismt IN s_xmatnr
AND bismt <> ‘’.
SELECT matnr_new AS matnr_n,
matnr_old AS matnr_o,
zdate,
ztime
INTO TABLE @DATA(lt_match)
FROM ztmatnr_match "pa001 bseg mseg ekpo
.
SORT lt_match BY matnr_o.
.
REFRESH r_werks.
r_werks-sign = ‘I’.
r_werks-option = ‘CP’.
r_werks-low = ‘*’.
APPEND r_werks.
- LOOP AT gt_alv ASSIGNING <fs_alv>.
- READ TABLE lt_match INTO DATA(ls_match) WITH KEY matnr_o = <fs_alv>-matnr_o
-
BINARY SEARCH.
- IF sy-subrc = 0.
-
<fs_alv>-zlight = icon_green_light.
- ENDIF.
- ENDLOOP.
- DELETE gt_alv[] WHERE zlight = icon_green_light.
******后台数据处理
DATA:lv_xhhs TYPE p LENGTH 13 DECIMALS 2."每次循环数据行数
DATA:lv_num TYPE p LENGTH 13 DECIMALS 2,
lv_time TYPE int4, "
lvf_indexf TYPE int4, "
lvt_indext TYPE int4. "
lv_num = lines( gt_alv ).
lv_xhhs = ceil( lv_num / p_sjfb ). "获得包得数量
DO lv_xhhs TIMES.
lv_time = lv_time + 1.
lvf_indexf = lvt_indext + 1."计算本次包发送的数据开始索引
lvt_indext = lv_time * p_sjfb ."计算本次包发送的数据结束索引
REFRESH r_matnr_old.
LOOP AT gt_alv ASSIGNING <fs_alv> FROM lvf_indexf TO lvt_indext. "循环取到得数据
r_matnr_old-sign = 'I'.
r_matnr_old-option = 'EQ'.
r_matnr_old-low = <fs_alv>-matnr_o.
APPEND r_matnr_old.
ENDLOOP.
PERFORM frm_creat_job .
ENDDO.
ENDFORM.
&---------------------------------------------------------------------
*& Form FRM_CREAT_JOB
&---------------------------------------------------------------------
-
text
----------------------------------------------------------------------
- –> p1 text
- <-- p2 text
----------------------------------------------------------------------
FORM frm_creat_job .
DATA:lv_number TYPE tbtcjob-jobcount,
lv_name TYPE tbtcjob-jobname,
lv_print_parameters TYPE pri_params VALUE ‘LP01’.
DATA lv_rep LIKE trdir-name VALUE ‘ZMM315’.
DATA:lv_job LIKE tbtco-jobname.
DATA:lv_num TYPE p LENGTH 13 DECIMALS 2.
lv_job =‘ZMM315后台复制采购信息记录’&& ‘-’ && sy-datum && ‘-’&& sy-uzeit.
DO.
SELECT COUNT(*)
INTO @DATA(lv_count)
FROM tbtco
WHERE tbtco~jobname LIKE ‘ZMM315后台复制采购信息记录%’
AND tbtco~status IN ( ‘R’,‘Y’ ).
IF lv_count < p_htrw.
EXIT.
ENDIF.
ENDDO.
CLEAR lv_number.
"创建已计划状态的JOB
CALL FUNCTION ‘JOB_OPEN’
EXPORTING
jobname = lv_job
IMPORTING
jobcount = lv_number
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc = 0.
SUBMIT (lv_rep)
TO SAP-SPOOL "打印机参数设置
SPOOL PARAMETERS lv_print_parameters "打印机格式
WITH s_matnr IN r_matnr_old
WITH s_werks IN r_werks
WITH p_job = 'X'
WITHOUT SPOOL DYNPRO
USER syst-uname
VIA JOB lv_job
NUMBER lv_number
AND RETURN.
IF sy-subrc = 0.
"释放已计划的JOB,JOB状态为活动
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_number
jobname = lv_job
strtimmed = 'X'
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!