场景:
大批量复制物料描述到新的物料上,多线程同时执行已提高效率
REPORT zmm316.
INCLUDE zmm316_top.
INCLUDE zmm316_f01.
*-----------------------------------------------------------------------
*-----------------------------------------------------------------------
START-OF-SELECTION.
PERFORM frm_get_data.
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.
*-----------------------------------------------------------------------
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.
&---------------------------------------------------------------------
*& 包含 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.
BINARY SEARCH.
<fs_alv>-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
----------------------------------------------------------------------
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.