需求场景
用户提出:有部分遗留的采购申请,没人处理,一直挂在系统中。(主要是最近要考核他们的PR转PO及时率等KPI指标)
一、需求分析及预置功能
一个合格的系统工程师或实施者,应该对用户的需求具有清晰的认知,并想到用户将来可能提出的相关需求。
首先,要实现基本需求:批量删除采购申请PR(BAPI:BAPI_REQUISITION_DELETE 删除采购申请)。
然后,实现过程中,做成可控制删除范围的程序。
为防止频繁找工程师处理,做成定时任务运行。
二、实现步骤
1.筛选屏幕
尽量多的筛选条件,以备不时之需。
2.代码实现
代码如下:
REPORT zmmr026.
TABLES:eban,marc.
DATA:zdays TYPE vtbbewe-atage.
DATA: gt_item TYPE TABLE OF bapieband,
zreturn TYPE TABLE OF bapireturn.
DATA:gs_item LIKE LINE OF gt_item.
DATA:zcount TYPE i..
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:s_banfn FOR eban-banfn. "PR
SELECT-OPTIONS:s_beskz FOR marc-beskz DEFAULT 'F'."采购类型
SELECT-OPTIONS:s_ekgrp FOR eban-ekgrp."采购组
SELECT-OPTIONS:s_date FOR eban-creationdate."创建天数取值范围
SELECT-OPTIONS:s_indate FOR eban-creationdate NO-DISPLAY."
PARAMETERS: p_day TYPE i."向前取值天数
PARAMETERS: p_time TYPE i DEFAULT 3 OBLIGATORY."自动删除时长
PARAMETERS:p_xz AS CHECKBOX DEFAULT 'X'."是否限制备件物料
SELECTION-SCREEN END OF BLOCK b1.
INITIALIZATION .
IF s_ekgrp[] IS INITIAL.
s_ekgrp-sign = 'I'.
s_ekgrp-option = 'BT'.
s_ekgrp-low = '006'.
s_ekgrp-high = '009'.
APPEND s_ekgrp.
CLEAR s_ekgrp.
s_ekgrp-sign = 'I'.
s_ekgrp-option = 'EQ'.
s_ekgrp-low = '011'.
APPEND s_ekgrp.
ENDIF.
START-OF-SELECTION .
IF s_date[] IS INITIAL AND p_day IS INITIAL.
DATA(msg) = '创建日期取值范围和向前取值天数不能同时为空!'.
ENDIF.
IF s_date[] IS NOT INITIAL AND p_day IS NOT INITIAL.
msg = '创建日期取值范围和向前取值天数只选一个填写!'.
ENDIF.
IF msg IS NOT INITIAL.
MESSAGE msg TYPE 'S' DISPLAY LIKE 'E'.
ELSE.
IF s_date[] IS INITIAL.
s_indate-sign = 'I'.
s_indate-option = 'BT'.
s_indate-low = sy-datum - p_day.
s_indate-high = sy-datum.
APPEND s_indate.
ELSE.
MOVE-CORRESPONDING s_date[] TO s_indate[].
ENDIF.
PERFORM:pro_data.
ENDIF.
FORM pro_data.
CLEAR msg.
IF p_xz EQ 'X'.
SELECT banfn,bnfpo,bsart,loekz,frgkz,"采购申请,采购申请项目,凭证类型,删除标识,审批状态
creationdate,eban~matnr,beskz
INTO TABLE @DATA(dt_eban)
FROM eban
LEFT JOIN marc ON marc~matnr = eban~matnr AND marc~werks = '8000'
WHERE bsart <> 'Z004'
AND ( eban~matnr LIKE '9%' OR eban~matnr LIKE 'A%' )
AND ( frgkz = 'J' OR frgkz = '' ) "只取审批中或为空 状态的
AND eban~ekgrp IN @s_ekgrp
AND creationdate IN @s_indate"创建日期
AND loekz = ''."未删除的
ELSE.
SELECT banfn,bnfpo,bsart,loekz,frgkz,"采购申请,采购申请项目,凭证类型,删除标识,审批状态
creationdate,eban~matnr,beskz
INTO TABLE @dt_eban
FROM eban
LEFT JOIN marc ON marc~matnr = eban~matnr AND marc~werks = '8000'
WHERE bsart <> 'Z004'
AND ( frgkz = 'J' OR frgkz = '' )
AND eban~ekgrp IN @s_ekgrp
AND creationdate IN @s_indate"创建日期
AND loekz = ''."未删除的
ENDIF.
SORT dt_eban BY banfn bnfpo.
LOOP AT dt_eban INTO DATA(ds_eban) WHERE beskz IN s_beskz.
gs_item-preq_item = ds_eban-bnfpo.
gs_item-delete_ind = 'X'.
gs_item-closed = 'X'.
APPEND gs_item TO gt_item.
* AT END OF banfn.
CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
EXPORTING
i_date_from = ds_eban-creationdate
i_date_to = sy-datum
IMPORTING
e_days = zdays.
IF zdays > p_time.
CALL FUNCTION 'BAPI_REQUISITION_DELETE'
EXPORTING
number = ds_eban-banfn
TABLES
requisition_items_to_delete = gt_item
return = zreturn
EXCEPTIONS
error_message = 1
OTHERS = 2.
READ TABLE zreturn INTO DATA(ds_return) WITH KEY type = 'E'.
IF sy-subrc <> 0.
zcount = zcount + 1.
ELSE.
msg = msg + ds_return-message.
ENDIF.
ENDIF.
* ENDAT.
CLEAR: gs_item,gt_item,zreturn,zdays,ds_eban.
ENDLOOP.
IF zcount > 0.
msg = '已处理' && zcount && '条'.
MESSAGE msg TYPE 'S'.
ELSE.
IF msg IS INITIAL.
msg = '无符合条件的PR'.
ENDIF.
MESSAGE msg TYPE 'S'.
ENDIF.
ENDFORM.
3.定时任务设置
事务代码SM36,设置定时任务
公众号
关注公众号:AI云书,参与现金红包抽奖活动!