ME21N创建采购订单点击保存或者检查按钮时进入增强(首先根据EKKO-LIFNR、EKPO-MATNR、 EKPO-WERKS LINK自建表1中的供应商、物料和工厂取对应自建表1中“是否管控”字段值是否为N, 如果为N则不进入增强,否则进入增强,并进行以下判断: |
1、根据EKKO-LIFNR和EKPO-MATNR、EKPO-WERKS LINK自建表1中的供应商+物料+工厂取出报告 到期日(如果取到多条数据,则只取报告到期日最早的那条数据做下面的校验),然后用报告到期日减去 采购订单的凭证日期(EKKO-BEDAT): 字段值,并且对应的自建表1中“是否提醒PO”字段不为N,则弹出警告消息:第XXXX行物料XXXX的 子材料XXXX报告编码XXXX还有多少天到期,回车可跳过消息并允许保存订单; 值,并且对应的自建表1中“是否控制PO”字段不为N,则弹出错误消息:第XXXX行物料XXXX的子材料 XXXX报告编码XXXX已超期XXXX天,不允许订单保存。 |
SE19 输入相应的增强BADI 创建相应的增强
IF sy-tcode = 'ME21N' .
DATA: lv_data(6) TYPE c.
DATA: gt_ztmm035 TYPE TABLE OF ztmm035,
gs_ztmm035 type ztmm035.
REFRESH: items.
CLEAR header.
CLEAR lv_num.
header = im_header->get_data( ).
items = im_header->get_items( ).
* SELECT WERKS,MATNR,LIFNR,SFGK,JSRQ,TXPOZQ,TXPO,ZCLMC,KZPOZQ,KZPO
* INTO TABLE @DATA(gt_ztmm035)
* FROM ztmm035
* FOR ALL ENTRIES IN @items
* WHERE WERKS = @items-waers
* and matnr = @items-matnr
* and lifnr = @items-lifnr
* and SFGK <> 'N'.
* SORT gt_ztmm035 by WERKS matnr lifnr JSRQ.
* DATA:gs_ztmm035 TYPE LINE OF gt_ztmm035.
LOOP AT items INTO line_item.
lv_num = lv_num + 1.
CLEAR: po_line.
po_line = line_item-item->get_data( ).
SELECT WERKS MATNR LIFNR SFGK JSRQ TXPOZQ TXPO ZCLMC KZPOZQ KZPO
INTO CORRESPONDING FIELDS OF TABLE gt_ztmm035
FROM ztmm035
WHERE WERKS = po_line-WERKS
and matnr = po_line-matnr
and lifnr = header-lifnr
and SFGK <> 'N'.
SORT gt_ztmm035 by WERKS matnr lifnr JSRQ.
* DATA:gs_ztmm035 TYPE LINE OF gt_ztmm035.
CLEAR lv_data.
READ TABLE gt_ztmm035 INTO gs_ztmm035 WITH KEY WERKS = po_line-WERKS matnr = po_line-matnr lifnr = header-lifnr BINARY SEARCH.
if sy-subrc = 0.
CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
EXPORTING
I_DATE_FROM = header-bedat
I_DATE_TO = gs_ztmm035-JSRQ
I_FLG_SEPARATE = ' ' "是否单独计算 若有标识,则返回两日期相差的天数
IMPORTING
E_DAYS = lv_data. "返回天数:638
if lv_data <= gs_ztmm035-TXPOZQ AND gs_ztmm035-TXPO <> 'N'.
MESSAGE '第' && lv_num && '行' && gs_ztmm035-matnr && '物料的子材料' && gs_ztmm035-ZCLMC && '还有' && lv_data && '天到期,回车可跳过消息并允许保存订单'
TYPE 'I' DISPLAY LIKE 'W'.
ENDIF.
if lv_data > gs_ztmm035-KZPOZQ AND gs_ztmm035-KZPO <> 'N'.
MESSAGE '第' && lv_num && '行' && gs_ztmm035-matnr && '物料的子材料' && gs_ztmm035-ZCLMC && '已超期' && lv_data && '天,不允许订单保存'
TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
ENDIF.
CLEAR gs_ztmm035.
ENDLOOP.
ENDIF.