设置:采购申请检查并警告提示
增强:MEREQ001
EXIT_SAPLMEREQ_005
&---------------------------------------------------------------------
*& 包含 ZXM02U05
&---------------------------------------------------------------------
DATA:BEGIN OF ls_eine,matnr TYPE marc-matnr,lifnr TYPE a017-lifnr,ekorg TYPE a017-ekorg,esokz TYPE a017-esokz,werks TYPE a017-werks,minbm TYPE eine-minbm,END OF ls_eine.
DATA:lt_eine LIKE TABLE OF ls_eine.
DATA:lv_minbm TYPE eine-minbm.
DATA:lv_minbmc TYPE string.
DATA:lv_mengec TYPE string.
DATA:lv_mess(200).
DATA:is_mess TYPE bapiret2.
DATA: symsgv TYPE symsgv.
DATA:lv_mess2(200).
DATA:lv_kc TYPE mard-labst.
DATA:lv_frkrq TYPE sy-datum.
DATA:lv_lrkrq TYPE sy-datum.
DATA:lv_lckrq TYPE sy-datum.
DATA:lw_sl LIKE mseg-menge.
DATA: BEGIN OF it_mseg OCCURS 0,matnr TYPE mseg-matnr,werks TYPE mseg-werks,mblnr TYPE mseg-mblnr,mjahr TYPE mseg-mjahr,zeile TYPE mseg-zeile,bwart TYPE mseg-bwart,menge TYPE mseg-menge,meins TYPE mseg-meins,ebeln TYPE mseg-ebeln,ebelp TYPE mseg-ebelp,afnam TYPE ekpo-afnam,aufnr TYPE mseg-aufnr,budat TYPE mseg-budat_mkpf,END OF it_mseg.
DATA:it_mseg_h LIKE TABLE OF it_mseg WITH HEADER LINE."1 标准件
"2 取物料对应信息记录的最小订购量
"3 最小订购量为1不检查
"4 存在多个不相同的最小订购量时,不检查
IF sy-tcode = 'ME51N' OR sy-tcode = 'ME52N' OR sy-tcode = 'ME53N' .IF ( ( im_data_new-menge <> im_data_old-menge ) OR im_data_old IS INITIAL ) AND im_data_new-menge > 0 .IF im_data_new-matnr <> '' AND im_data_new-werks <> ''.SELECT COUNT(*) FROM mara WHERE matnr = im_data_new-matnr AND zdz = 'N'.IF sy-subrc = 0.CLEAR :lv_minbm,lv_minbmc,lv_mengec,lv_mess.REFRESH:lt_eine.SELECTa018~matnra018~lifnra018~ekorga018~esokzeine~minbmINTO CORRESPONDING FIELDS OF TABLE lt_eineFROM a018JOIN konp ON a018~knumh EQ konp~knumhJOIN eina ON eina~matnr EQ a018~matnrAND eina~lifnr EQ a018~lifnrAND eina~loekz EQ ''JOIN eine ON eina~infnr EQ eine~infnrAND eine~werks EQ ''AND eine~loekz EQ ''AND eine~ekorg EQ a018~ekorgWHERE a018~matnr = im_data_new-matnrAND a018~esokz = im_data_new-pstypAND a018~kappl = 'M'AND a018~kschl = 'PB00'AND a018~datbi GE sy-datumAND a018~datab LE sy-datumAND konp~kschl = 'PB00'AND konp~kbetr > 0AND konp~loevm_ko = ''.
-
AND eine~minbm > 1.SELECTa017~matnra017~lifnra017~ekorga017~esokza017~werkseine~minbmAPPENDING CORRESPONDING FIELDS OF TABLE lt_eineFROM a017JOIN konp ON a017~knumh EQ konp~knumhJOIN eina ON eina~matnr EQ a017~matnrAND eina~lifnr EQ a017~lifnrAND eina~loekz EQ ''JOIN eine ON eina~infnr EQ eine~infnrAND eine~werks EQ a017~werksAND eine~loekz EQ ''AND eine~ekorg EQ a017~ekorgWHERE a017~matnr = im_data_new-matnrAND a017~werks = im_data_new-werksAND a017~esokz = im_data_new-pstypAND a017~kappl = 'M'AND a017~kschl = 'PB00'AND a017~datbi GE sy-datumAND a017~datab LE sy-datumAND konp~kschl = 'PB00'AND konp~kbetr > 0AND konp~loevm_ko = ''.
-
AND eine~minbm > 1.IF lt_eine IS NOT INITIAL.SORT lt_eine BY lifnr DESCENDING werks DESCENDING. "工厂价格优先级高,去重排除非工厂级价格DELETE ADJACENT DUPLICATES FROM lt_eine COMPARING lifnr.DATA(lines) = lines( lt_eine[] ).IF lines > 1.READ TABLE lt_eine INTO ls_eine INDEX 1.lv_minbm = ls_eine-minbm.LOOP AT lt_eine INTO ls_eine.IF lv_minbm <> ls_eine-minbm..CLEAR lv_minbm.EXIT. "说明存在多个最小订购量,不检查ENDIF.ENDLOOP.ELSE.READ TABLE lt_eine INTO ls_eine INDEX 1.lv_minbm = ls_eine-minbm.ENDIF.IF lv_minbm > 1.IF lv_minbm > im_data_new-menge.lv_minbmc = lv_minbm / 1.lv_mengec = im_data_new-menge / 1.CONCATENATE '请注意,物料:' im_data_new-matnr '申请数量:' lv_mengec ' 小于 最小订购量:' lv_minbmc INTO lv_mess SEPARATED BY space.symsgv = lv_mess.CALL METHOD cl_message_mm=>createEXPORTINGim_msgid = 'ZMM'im_msgty = 'W'im_msgno = '000'im_msgv1 = symsgvim_force_collect = mmpur_yesEXCEPTIONSOTHERS = 0.ENDIF.ENDIF.ENDIF.ENDIF.ENDIF. ENDIF.">360账龄内的数量 > 0,长账龄 "库龄<360天 ,过去4个月无领料记录且最新入库日期>4个月 ,低周转 IF im_data_new-matnr <> '' AND im_data_new-werks <> '' AND im_data_old IS INITIAL.CLEAR:lv_kc,lw_sl,lv_frkrq,lv_lrkrq,lv_lckrq,lv_mess2.SELECT SUM( labst ) INTO lv_kc FROM mard WHERE matnr = im_data_new-matnr AND werks = im_data_new-werks.IF lv_kc > 0.REFRESH:it_mseg.SELECTmseg~matnrmseg~werksmseg~mblnrmseg~mjahrmseg~zeilemseg~bwartmseg~mengemseg~meinsmseg~ebelnmseg~ebelpmseg~aufnrmseg~budat_mkpf AS budatekpo~afnamINTO CORRESPONDING FIELDS OF TABLE it_msegFROM msegJOIN matdoc AS d ON d~mblnr EQ mseg~mblnr AND d~mjahr EQ mseg~gjahr AND d~zeile EQ mseg~zeileLEFT JOIN ekpo ON mseg~ebeln EQ ekpo~ebeln AND mseg~ebelp EQ ekpo~ebelpWHERE mseg~matnr EQ im_data_new-matnrAND mseg~werks EQ im_data_new-werksAND mseg~shkzg = 'S'AND mseg~bwart IN ( '101','105','561','531' )AND d~cancelled EQ '' .IF sy-subrc = 0.SORT it_mseg BY budat DESCENDING.lw_sl = lv_kc.LOOP AT it_mseg.IF sy-tabix = 1.lv_lrkrq = it_mseg-budat. "最后入库日期ENDIF.IF it_mseg-menge >= lw_sl.lv_frkrq = it_mseg-budat."最早入库日期lw_sl = 0.EXIT.ELSE.lw_sl = lw_sl - it_mseg-menge.lv_frkrq = it_mseg-budat."最早入库日期ENDIF.ENDLOOP.IF sy-datum - lv_frkrq > 360. "长账龄CONCATENATE '请注意,物料:' im_data_new-matnr ',当前为长账龄物料' INTO lv_mess2 SEPARATED BY space.symsgv = lv_mess.CALL METHOD cl_message_mm=>createEXPORTINGim_msgid = 'ZMM'im_msgty = 'W'im_msgno = '000'im_msgv1 = symsgvim_force_collect = mmpur_yesEXCEPTIONSOTHERS = 0.ELSE.IF sy-datum - lv_lrkrq > 120.REFRESH:it_mseg_h.SELECTmseg~matnrmseg~werksmseg~mblnrmseg~mjahrmseg~zeilemseg~bwartmseg~mengemseg~meinsmseg~ebelnmseg~ebelpmseg~aufnrmseg~budat_mkpf AS budatekpo~afnamINTO CORRESPONDING FIELDS OF TABLE it_mseg_hFROM msegJOIN matdoc AS d ON d~mblnr EQ mseg~mblnr AND d~mjahr EQ mseg~gjahr AND d~zeile EQ mseg~zeileLEFT JOIN ekpo ON mseg~ebeln EQ ekpo~ebeln AND mseg~ebelp EQ ekpo~ebelpWHERE mseg~matnr EQ im_data_new-matnrAND mseg~werks EQ im_data_new-werksAND mseg~shkzg = 'H'AND mseg~bwart IN ( '261','201','Z71','Z73','Z75','Z77','Z79','Z81','Z83' )AND d~cancelled EQ '' .IF sy-subrc = 0.SORT it_mseg_h BY budat DESCENDING.READ TABLE it_mseg_h INDEX 1.IF sy-datum - it_mseg_h-budat > 120.CONCATENATE '请注意,物料:' im_data_new-matnr ',当前为低周转物料' INTO lv_mess2 SEPARATED BY space.symsgv = lv_mess.CALL METHOD cl_message_mm=>createEXPORTINGim_msgid = 'ZMM'im_msgty = 'W'im_msgno = '000'im_msgv1 = symsgvim_force_collect = mmpur_yesEXCEPTIONSOTHERS = 0.ENDIF.ENDIF.ENDIF.ENDIF.ENDIF.ENDIF. ENDIF.
ENDIF.