本文主要是介绍ZMM_BADI_005 采购订单价格控制,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
采购订单价格控制
METHOD if_ex_me_process_po_cust~check.
IF sy-uname EQ 'WXJ'.
EXIT.
ENDIF.
* d
DATA: lv_bname TYPE zmmt999-bname .
CLEAR lv_bname .
SELECT SINGLE bname INTO lv_bname
FROM zmmt999
WHERE bname = sy-uname
AND mark EQ 'X' .
IF lv_bname IS NOT INITIAL .
EXIT .
ENDIF .
DATA: BEGIN OF ls_s1,
knumh TYPE komv-knumh,
kopos TYPE komv-kopos,
pstyp TYPE ekpo-pstyp,
kwert TYPE komv-kwert,
END OF ls_s1.
DATA: lt_s1 LIKE TABLE OF ls_s1.
DATA: BEGIN OF ls_slhz,
matnr TYPE mara-matnr,
pstyp TYPE ekpo-pstyp,
menge TYPE mseg-menge,
END OF ls_slhz.
DATA: lt_slhz LIKE TABLE OF ls_slhz.
DATA: lt_data TYPE purchase_order_items,
ls_data TYPE purchase_order_item.
DATA: ls_item TYPE mepoitem.
DATA: lt_item TYPE mepoitem.
DATA: ls_head TYPE mepoheader.
DATA: lv_class TYPE REF TO if_purchase_order_item_mm.
DATA: lv_mtart TYPE mara-mtart.
DATA: lt_konp TYPE TABLE OF konp,
ls_konp TYPE konp.
DATA: lt_konm TYPE TABLE OF konm,
ls_konm TYPE konm.
DATA: ls_konm_b TYPE konm.
DATA: lt_mmpur_tkomv TYPE mmpur_tkomv,
ls_mmpur_tkomv LIKE LINE OF lt_mmpur_tkomv.
* DATA: lt_tkomv TYPE mmpur_tkomv,
* ls_tkomv LIKE LINE OF lt_mmpur_tkomv.
DATA: lt_prcd_elements TYPE TABLE OF prcd_elements,
ls_prcd_elements TYPE prcd_elements.
DATA: lv_kopos TYPE konp-kopos.
DATA: lv_tabix LIKE sy-tabix.
* DATA: lv_tabix_1 LIKE sy-tabix.
DATA: lv_kwert TYPE konv-kwert.
DATA: BEGIN OF ls_prcd,
knumh TYPE konp-knumh,
kopos TYPE konp-kopos,
END OF ls_prcd.
DATA: lt_prcd LIKE TABLE OF ls_prcd.
DATA: lv_msg TYPE string.
DATA: lv_flg.
DATA: ls_a017 TYPE a017.
DATA: lv_s1 TYPE prcd_elements-kwert.
DATA: lv_s2 TYPE konm-kstbm.
DATA: lv_bfb TYPE p DECIMALS 4.
DATA: lv_01 TYPE p DECIMALS 1.
DATA: lv_kstbm TYPE string.
DATA: lv_lines LIKE sy-tabix.
DATA: gv_c TYPE c .
DATA: gv_c2 TYPE c .
DATA: lv_menge TYPE ekbe-menge .
DATA: BEGIN OF gs_ekbe,
menge TYPE ekbe-menge,
bewtp TYPE ekbe-bewtp,
END OF gs_ekbe.
DATA: gt_ekbe LIKE TABLE OF gs_ekbe.
DATA: lv_netpr TYPE ekpo-netpr.
lv_01 = 10 / 100.
DATA: lv_count TYPE i.
CALL METHOD im_header->get_data
RECEIVING
re_data = ls_head.
IF ls_head-ebeln BETWEEN '0000800000' AND '0000899999'.
EXIT.
ENDIF.
IF ls_head-bsart EQ 'ZUB' ." OR ls_head-bsart EQ 'Z006' .
EXIT.
ENDIF .
* 2019-05-29 modify by lxf
* IMPORT p1 TO gv_c FROM MEMORY ID 'dd'.
* IF sy-subrc NE 0. " 传值失败
* EXPORT p1 FROM ls_head-frgke TO MEMORY ID 'dd' .
* EXPORT p2 FROM ls_head-frgke TO MEMORY ID 'ee' .
* ENDIF .
*
* IMPORT p2 TO gv_c2 FROM MEMORY ID 'ee' .
*
* IF gv_c2 EQ 'R' .
* EXIT.
* ENDIF .
IMPORT p1 TO gv_c FROM MEMORY ID 'dd'.
IF sy-subrc NE 0. " 传值失败
EXPORT p1 FROM ls_head-frgke TO MEMORY ID 'dd' .
EXPORT p2 FROM ls_head-frgke TO MEMORY ID 'ee' .
ELSE .
ENDIF .
IMPORT p2 TO gv_c2 FROM MEMORY ID 'ee' .
IF sy-tcode EQ 'ME29N' .
IF gv_c2 EQ 'R' AND gv_c IS INITIAL .
EXIT.
ELSE .
* IF ls_head-frgke EQ 'B'.
* EXIT.
* ENDIF .
ENDIF .
ENDIF .
* 2019-05-29 modify by lxf
CALL METHOD im_header->get_items
RECEIVING
re_items = lt_data.
SORT lt_konm BY kstbm.
LOOP AT lt_data INTO ls_data.
lv_class = ls_data-item.
CLEAR: ls_item.
CALL METHOD lv_class->get_data
RECEIVING
re_data = ls_item.
IF ls_item-umson EQ 'X'.
CONTINUE.
ENDIF.
" 已收货不允许修改价格
CLEAR gt_ekbe[].
IF ls_head-bsart EQ 'Z005' ." OR ls_head-bsart EQ 'Z006' .
SELECT menge bewtp INTO TABLE gt_ekbe
FROM ekbe
WHERE ebeln = ls_item-ebeln
AND ebelp = ls_item-ebelp.
CLEAR lv_menge .
LOOP AT gt_ekbe INTO gs_ekbe.
IF gs_ekbe-bewtp EQ 'S'.
lv_menge = lv_menge + gs_ekbe-menge .
ELSE .
lv_menge = lv_menge - gs_ekbe-menge .
ENDIF .
ENDLOOP .
IF lv_menge <> 0.
CLEAR lv_netpr .
SELECT SINGLE netpr INTO lv_netpr FROM ekpo
WHERE ebeln = ls_item-ebeln
AND ebelp = ls_item-ebelp .
* IF lv_netpr <> ls_item-netpr .
IF abs( lv_netpr - ls_item-netpr ) * 100 > 3 .
MESSAGE e000(zhele) WITH '行' ls_item-ebelp ':已收货,不允许修改价格'.
ENDIF .
ENDIF.
CONTINUE.
ENDIF .
* 退货跳过增强
"
IF ls_item-retpo EQ 'X'.
CONTINUE.
ENDIF.
IF ls_item-loekz IS NOT INITIAL.
CONTINUE.
ENDIF.
SELECT SINGLE mtart
INTO lv_mtart
FROM mara
WHERE matnr = ls_item-matnr.
IF ( lv_mtart BETWEEN 'Z001' AND 'Z010' ) OR ( lv_mtart EQ 'Z020' ) .
IF ls_item-infnr IS INITIAL.
MESSAGE e004(zhele) WITH ls_head-lifnr ls_item-matnr.
ENDIF.
ELSE.
CONTINUE..
ENDIF.
"退货采购订单交货价格不能更改
CLEAR: lt_mmpur_tkomv.
CALL METHOD lv_class->get_conditions
IMPORTING
ex_conditions = lt_mmpur_tkomv.
* READ TABLE lt_mmpur_tkomv INTO ls_mmpur_tkomv INDEX 1.
* READ TABLE lt_s1 WITH KEY knumh = ls_mmpur_tkomv-knumh kopos = ls_mmpur_tkomv-kopos pstyp = ls_item-pstyp
* TRANSPORTING NO FIELDS.
* IF sy-subrc <> 0.
LOOP AT lt_mmpur_tkomv INTO ls_mmpur_tkomv.
IF ls_mmpur_tkomv-kschl <> 'PB00' AND ls_mmpur_tkomv-kschl <> 'PBXX'.
CONTINUE.
ENDIF.
ls_s1-knumh = ls_mmpur_tkomv-knumh.
ls_s1-kopos = ls_mmpur_tkomv-kopos.
ls_s1-pstyp = ls_item-pstyp.
ls_s1-kwert = ls_mmpur_tkomv-kwert.
COLLECT ls_s1 INTO lt_s1.
ENDLOOP.
* ENDIF.
ls_slhz-matnr = ls_item-matnr.
ls_slhz-pstyp = ls_item-pstyp.
ls_slhz-menge = ls_item-menge.
COLLECT ls_slhz INTO lt_slhz.
CLEAR: ls_slhz.
ENDLOOP.
CLEAR: lt_mmpur_tkomv.
LOOP AT lt_data INTO ls_data.
lv_class = ls_data-item.
CLEAR: ls_item.
CALL METHOD lv_class->get_data
RECEIVING
re_data = ls_item.
IF ls_item-umson EQ 'X'.
CONTINUE.
ENDIF.
IF ls_item-retpo EQ 'X'.
CONTINUE.
ENDIF.
IF ls_item-loekz IS NOT INITIAL.
CONTINUE.
ENDIF.
SELECT SINGLE mtart
INTO lv_mtart
FROM mara
WHERE matnr = ls_item-matnr.
IF ( lv_mtart BETWEEN 'Z001' AND 'Z010') OR ( lv_mtart EQ 'Z020' ) .
IF ls_item-infnr IS INITIAL.
MESSAGE e004(zhele) WITH ls_head-lifnr ls_item-matnr.
ENDIF.
ELSE.
CONTINUE..
ENDIF.
READ TABLE lt_slhz INTO ls_slhz WITH KEY matnr = ls_item-matnr pstyp = ls_item-pstyp.
CALL METHOD lv_class->get_conditions
IMPORTING
ex_conditions = lt_mmpur_tkomv.
*第一步
LOOP AT lt_mmpur_tkomv INTO ls_mmpur_tkomv.
IF ls_mmpur_tkomv-kschl <> 'PB00' AND ls_mmpur_tkomv-kschl <> 'PBXX'.
CONTINUE.
ENDIF.
IF ls_mmpur_tkomv-knumh IS INITIAL.
*1.2.1 当PRCD_ELEMENTS-KNUMH=空白,则报错“物料XXXXX的价格跟采购信息记录不一致”
MESSAGE e000(zhele) WITH '物料' ls_item-matnr '的价格跟采购信息记录不一致'.
ELSE.
SELECT COUNT(*)
FROM konp
WHERE knumh = ls_mmpur_tkomv-knumh
AND kopos = ls_mmpur_tkomv-kopos
AND loevm_ko = 'X'.
IF sy-subrc EQ 0.
MESSAGE e000(zhele) WITH '物料' ls_item-matnr '采购信息记录有修改,请检查!'.
ENDIF.
IF ls_mmpur_tkomv-kschl = 'PB00'.
SELECT SINGLE *
INTO ls_a017
FROM a017
WHERE kappl = 'M'
AND kschl = ls_mmpur_tkomv-kschl
AND lifnr = ls_head-lifnr
AND matnr = ls_item-matnr
AND ekorg = ls_head-ekorg
AND werks = ls_item-werks
AND esokz = ls_item-pstyp
AND knumh = ls_mmpur_tkomv-knumh
AND datbi >= ls_head-bedat."失效日期
IF ls_a017-datbi >= ls_head-bedat AND ls_a017-datab <= ls_head-bedat.
IF ls_a017-knumh <> ls_mmpur_tkomv-knumh.
MESSAGE e000(zhele) WITH '物料' ls_item-matnr '采购信息记录有修改,请检查!'.
ENDIF.
ELSE.
MESSAGE e000(zhele) WITH '物料' ls_item-matnr '采购信息记录有修改,请检查!'.
ENDIF.
ENDIF.
IF ls_mmpur_tkomv-kstbs EQ 0.
SELECT SINGLE *
INTO ls_konp
FROM konp
WHERE knumh = ls_mmpur_tkomv-knumh
AND kopos = ls_mmpur_tkomv-kopos.
IF ls_konp-kbetr <> ls_mmpur_tkomv-kbetr OR
ls_konp-konwa <> ls_mmpur_tkomv-waers OR
ls_konp-kpein <> ls_mmpur_tkomv-kpein OR
ls_konp-kmein <> ls_mmpur_tkomv-kmein OR
sy-subrc <> 0.
*1.2.2.1.1如果有不相等的,则报错“物料XXXXX的价格跟采购信息记录不一致”。
MESSAGE e000(zhele) WITH '物料' ls_item-matnr '的价格跟采购信息记录不一致'.
ENDIF.
ELSE.
CLEAR: lv_s1,lv_s2,ls_s1.
READ TABLE lt_s1 INTO ls_s1 WITH KEY knumh = ls_mmpur_tkomv-knumh
kopos = ls_mmpur_tkomv-kopos
pstyp = ls_item-pstyp.
IF sy-subrc EQ 0.
lv_s1 = ls_s1-kwert.
ENDIF.
**第二步。
CLEAR: ls_konp.
SELECT SINGLE *
INTO ls_konp
FROM konp
WHERE knumh = ls_mmpur_tkomv-knumh
AND kopos = ls_mmpur_tkomv-kopos.
***1.2.2.2当PRCD_ELEMENTS-KSTBS≠0时
CLEAR: lt_konm[].
SELECT *
INTO TABLE lt_konm
FROM konm
WHERE knumh = ls_konp-knumh
AND kopos = ls_konp-kopos.
IF sy-subrc <> 0.
MESSAGE e000(zhele) WITH '物料' ls_item-matnr '的价格跟采购信息记录不一致'.
ENDIF.
SORT lt_konm BY kstbm.
LOOP AT lt_konm INTO ls_konm_b.
lv_tabix = sy-tabix.
IF ls_konm_b-kstbm >= ls_slhz-menge."ls_mmpur_tkomv-kstbs.
EXIT.
ENDIF.
ENDLOOP.
IF ls_konm_b-kstbm > ls_slhz-menge.
lv_tabix = lv_tabix - 1.
ENDIF.
* lv_tabix = lv_tabix - 1.
IF lv_tabix > 0.
READ TABLE lt_konm INTO ls_konm INDEX lv_tabix.
ELSE.
MESSAGE e000(zhele) WITH '物料' ls_item-matnr '的价格跟采购信息记录不一致'.
ENDIF.
IF ls_konm_b-kstbm = ls_slhz-menge.
DESCRIBE TABLE lt_konm LINES lv_lines.
IF lv_tabix = lv_lines.
lv_flg = 'X'.
ELSE.
lv_tabix = lv_tabix + 1.
READ TABLE lt_konm INTO ls_konm_b INDEX lv_tabix.
ENDIF.
ENDIF.
IF ls_konm_b-kstbm < ls_slhz-menge.
lv_flg = 'X'.
ENDIF.
IF ls_konm-kbetr <> ls_mmpur_tkomv-kbetr OR
ls_konp-konwa <> ls_mmpur_tkomv-waers OR
ls_konp-kpein <> ls_mmpur_tkomv-kpein OR
ls_konp-kmein <> ls_mmpur_tkomv-kmein.
*1.2.2.2.1如果有不相等的,则报错“物料XXXXX的价格跟采购信息记录不一致”。
MESSAGE e000(zhele) WITH '物料' ls_item-matnr '的价格跟采购信息记录不一致'.
ELSE.
IF lv_flg = 'X'.
CLEAR: lv_flg.
CONTINUE.
ENDIF.
CLEAR: lv_s2,lv_bfb.
IF ls_konp-kpein <> 0.
lv_s2 = ls_konm_b-kbetr / ls_konp-kpein * ls_konm_b-kstbm.
ENDIF.
IF lv_s1 >= lv_s2.
MESSAGE e005(zhele) WITH ls_item-matnr ls_konm_b-kstbm .
ELSE.
IF lv_s2 <> 0.
lv_bfb = ( lv_s2 - lv_s1 ) / lv_s2.
ENDIF.
IF lv_bfb <= lv_01.
lv_kstbm = ls_konm_b-kstbm .
CONCATENATE '物料' ls_item-matnr '采购数量' lv_kstbm '可能更划算!'
INTO lv_msg.
CALL FUNCTION 'Z_CALL_MSG'
EXPORTING
iv_msg = lv_msg.
* MESSAGE i005(zhele) WITH ls_item-matnr ls_konm_b-kstbm.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDMETHOD.
这篇关于ZMM_BADI_005 采购订单价格控制的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!