采购订单限价(包含阶梯价)ME_PROCESS_PO_CUST

时间:2022-09-09 20:35:02

为了能管控到钱财的每个环节,公司要求采购订单需要使用物料限价,当有报价低于先前的价格时,在采购订单保存时,更新最低限价

BADI:ME_PROCESS_PO_CUST

process~item里做限价检查

post里更新限价

  METHOD IF_EX_ME_PROCESS_PO_CUST~PROCESS_ITEM.

    INCLUDE MM_MESSAGES_MAC.
DATA : LW_ITEM TYPE MEPOITEM.
DATA : LT_KONV TYPE TABLE OF KOMV .
DATA : LW_KONV TYPE KOMV .
DATA : LV_KNUMH TYPE A118-KNUMH .
DATA : LT_KONP TYPE TABLE OF KONP .
DATA : LW_KONP TYPE KONP .
DATA : LV_MARKS() TYPE C .
DATA:LT_KONM TYPE TABLE OF KONM,
LW_KONM TYPE KONM. DATA : LO_HEADER TYPE REF TO IF_PURCHASE_ORDER_MM .
DATA : LW_HEADER TYPE MEPOHEADER . CLEAR:LT_KONM[],LW_KONM. IF SY-TCODE = 'ME21N' OR SY-TCODE = 'ME22N' OR SY-TCODE = 'ME29N'
OR SY-TCODE = 'ME23N' .
LO_HEADER = IM_ITEM->GET_HEADER( ).
LW_HEADER = LO_HEADER->GET_DATA( ). IF LW_HEADER-BSART = '' OR LW_HEADER-BSART = ''
OR LW_HEADER-BSART = '' OR LW_HEADER-BSART = '' .
ELSE . LW_ITEM = IM_ITEM->GET_DATA( ). CHECK LW_ITEM-UMSON = '' ."免费货物不检查
CHECK LW_ITEM-LOEKZ = '' ."删除货物不检查
CHECK LW_ITEM-MATNR <> '' ."无物料号不检查 CALL METHOD IM_ITEM->GET_CONDITIONS
IMPORTING
EX_CONDITIONS = LT_KONV[]. CLEAR LV_MARKS .
CLEAR LW_KONV .
READ TABLE LT_KONV INTO LW_KONV
WITH KEY KPOSN = LW_ITEM-EBELP
KSCHL = 'PB00' .
IF SY-SUBRC <> .
CLEAR LW_KONV .
READ TABLE LT_KONV INTO LW_KONV
WITH KEY KPOSN = LW_ITEM-EBELP
KSCHL = 'PBXX' .
IF SY-SUBRC <> .
LV_MARKS = 'X' .
ENDIF .
ENDIF . CHECK LV_MARKS = '' . SELECT SINGLE KNUMH
INTO LV_KNUMH
FROM A901
WHERE KSCHL = 'PB00'
AND MATNR = LW_ITEM-MATNR
AND ZONWA = LW_HEADER-WAERS
AND DATBI >= SY-DATUM
AND DATAB <= SY-DATUM .
IF SY-SUBRC = .
CLEAR LT_KONP[] .
SELECT *
INTO TABLE LT_KONP
FROM KONP
WHERE KNUMH = LV_KNUMH
AND KONWA = LW_HEADER-WAERS .
IF SY-SUBRC = .
SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_KONM
FROM KONM
FOR ALL ENTRIES IN LT_KONP WHERE KNUMH = LT_KONP-KNUMH AND KOPOS = LT_KONP-KOPOS." AND KSTBM <= LW_ITEM-MENGE.
CLEAR LW_KONP .
READ TABLE LT_KONP INTO LW_KONP INDEX . SORT LT_KONM BY KNUMH KOPOS KSTBM DESCENDING."按数量倒序
READ TABLE LT_KONM INTO LW_KONM INDEX ."取最近最大的值对应的价格 IF LT_KONM[] IS NOT INITIAL."如果存在,将阶梯价复制过来
LOOP AT LT_KONM INTO LW_KONM WHERE KSTBM >= LW_ITEM-MENGE..
LW_KONP-KBETR = LW_KONM-KBETR.
ENDLOOP.
ENDIF.
IF LW_HEADER-WAERS <> LW_KONV-WAERS .
CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
DATE = SY-DATUM
FOREIGN_CURRENCY = LW_HEADER-WAERS
LOCAL_AMOUNT = LW_KONV-KBETR
LOCAL_CURRENCY = LW_KONV-WAERS
IMPORTING
FOREIGN_AMOUNT = LW_KONV-KBETR
EXCEPTIONS
NO_RATE_FOUND =
OVERFLOW =
NO_FACTORS_FOUND =
NO_SPREAD_FOUND =
DERIVED_2_TIMES =
OTHERS = .
ENDIF . IF LW_KONP-KMEIN <> LW_KONV-KMEIN ."数量单位转换
DATA : LV_MENGE TYPE EKPO-MENGE .
LV_MENGE = LW_KONP-KPEIN .
CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
EXPORTING
I_MATNR = LW_ITEM-MATNR
I_IN_ME = LW_KONP-KMEIN
I_OUT_ME = LW_KONV-KMEIN
I_MENGE = LV_MENGE
IMPORTING
E_MENGE = LV_MENGE
EXCEPTIONS
ERROR_IN_APPLICATION =
ERROR =
OTHERS = .
IF LV_MENGE <> .
LW_KONP-KBETR = LW_KONP-KBETR / LV_MENGE * LW_KONV-KPEIN .
ELSE .
MMPUR_MESSAGE 'E' 'ZMM' '' '行项目' LW_ITEM-EBELP '限价转换单位太小,程序无法判断' ''.
ENDIF .
ELSE .
LW_KONP-KBETR = LW_KONP-KBETR / LW_KONP-KPEIN * LW_KONV-KPEIN .
ENDIF . IF LW_KONV-KBETR > LW_KONP-KBETR .
MMPUR_MESSAGE 'E' 'ZMM' '' '行项目' LW_ITEM-EBELP '采购价格超出物料最高限价!' ''.
ENDIF .
ELSE .
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
INPUT = LW_ITEM-MATNR
IMPORTING
OUTPUT = LW_ITEM-MATNR.
MMPUR_MESSAGE 'E' 'ZMM' '' '行项目' LW_ITEM-EBELP '的最高限价货币记录为空!' ''.
ENDIF .
ELSE ." SELECT SINGLE KNUMH
INTO LV_KNUMH
FROM A901
WHERE KSCHL = 'PB00'
AND MATNR = LW_ITEM-MATNR
AND DATBI >= SY-DATUM
AND DATAB <= SY-DATUM .
IF SY-SUBRC = .
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
INPUT = LW_ITEM-MATNR
IMPORTING
OUTPUT = LW_ITEM-MATNR.
MMPUR_MESSAGE 'E' 'ZMM' '' '行项目' LW_ITEM-EBELP '的最高限价货币记录为空!' ''.
ELSE .
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
INPUT = LW_ITEM-MATNR
IMPORTING
OUTPUT = LW_ITEM-MATNR.
MMPUR_MESSAGE 'W' 'ZMM' '' '行项目' LW_ITEM-EBELP '的最高限价记录为空,将自动维护' ''.
ENDIF .
ENDIF . ENDIF .
ENDIF . ENDMETHOD.
  METHOD IF_EX_ME_PROCESS_PO_CUST~POST.
TYPES : BEGIN OF LS_EKPO ,"物料对应
MATNR TYPE EKPO-MATNR,
MENGE TYPE EKPO-MENGE,
KBETR TYPE KONV-KBETR, "P DECIMALS 6 ,
WAERS TYPE KONV-WAERS,
KMEIN TYPE KONV-KMEIN,
KBET2 TYPE KONV-KBETR,
KPEIN TYPE KONV-KPEIN,
MARKX() TYPE C,
END OF LS_EKPO . DATA : LW_EKPO TYPE LS_EKPO .
DATA : LT_EKPO TYPE TABLE OF LS_EKPO .
DATA : LW_ITEM TYPE MEPOITEM.
DATA : LW_HEAD TYPE MEPOHEADER.
DATA : LT_ITEM TYPE TABLE OF MEPOITEM.
DATA : LT_KONV TYPE TABLE OF KOMV .
DATA : LT_KONV_01 TYPE TABLE OF KOMV .
DATA : LW_KONV TYPE KOMV .
DATA : LV_KNUMH TYPE A118-KNUMH .
DATA : LT_KONP TYPE TABLE OF KONP .
DATA : LW_KONP TYPE KONP .
DATA: LT_ITEMS TYPE PURCHASE_ORDER_ITEMS,
LW_ITEMS TYPE PURCHASE_ORDER_ITEM.
DATA : LM_KONV TYPE REF TO IF_PURCHASE_ORDER_ITEM_MM .
DATA:LT_KONM TYPE TABLE OF KONM,
LW_KONM TYPE KONM.
DATA:LV_FLAG TYPE C. ***************************************************
*************************************************** DATA: LT_BAPICONDCT TYPE TABLE OF BAPICONDCT , "
LW_BAPICONDCT TYPE BAPICONDCT,
LT_BAPICONDHD TYPE TABLE OF BAPICONDHD , "
LW_BAPICONDHD TYPE BAPICONDHD,
LT_BAPICONDIT TYPE TABLE OF BAPICONDIT,
LW_BAPICONDIT TYPE BAPICONDIT,
LT_BAPICONDQS TYPE TABLE OF BAPICONDQS,
LW_BAPICONDQS TYPE BAPICONDQS,
LT_BAPICONDVS TYPE TABLE OF BAPICONDVS,
LW_BAPICONDVS TYPE BAPICONDVS. DATA: LT_BAPIRET2 TYPE TABLE OF BAPIRET2 .
DATA: LW_BAPIRET2 TYPE BAPIRET2 .
DATA: LT_BAPIKNUMHS TYPE TABLE OF BAPIKNUMHS .
DATA: LT_MEM_INITIAL TYPE TABLE OF CND_MEM_INITIAL.
DATA : LV_MARKX() TYPE C ."需要扩大标识
DATA: H_VARKEY(),
H_COND_UNIT TYPE MEINS .
***************************************************
*************************************************** CLEAR : LT_EKPO[] .
CLEAR : LT_ITEM[] .
CLEAR : LT_KONV[] .
CLEAR : LT_KONP[] .
IF SY-TCODE = 'ME21N' OR SY-TCODE = 'ME22N' OR SY-TCODE = 'ME23N'
OR SY-TCODE = 'ME29N' .
LT_ITEMS = IM_HEADER->GET_ITEMS( ).
LW_HEAD = IM_HEADER->GET_DATA( ).
IF LW_HEAD-BSART = '' OR LW_HEAD-BSART = ''
OR LW_HEAD-BSART = '' OR LW_HEAD-BSART = '' .
ELSE .
CLEAR LW_ITEMS .
LOOP AT LT_ITEMS INTO LW_ITEMS . CLEAR LW_ITEM .
LW_ITEM = LW_ITEMS-ITEM->GET_DATA( ).
APPEND LW_ITEM TO LT_ITEM . CLEAR LT_KONV_01[] .
CALL METHOD LW_ITEMS-ITEM->GET_CONDITIONS
IMPORTING
EX_CONDITIONS = LT_KONV_01[].
APPEND LINES OF LT_KONV_01 TO LT_KONV . ENDLOOP. CLEAR LW_ITEM .
LOOP AT LT_ITEM INTO LW_ITEM .
CHECK LW_ITEM-UMSON = '' ."免费货物不检查
CHECK LW_ITEM-LOEKZ = '' ."删除货物不检查
CHECK LW_ITEM-MATNR <> '' ."无物料号不检查
CLEAR LW_KONV .
READ TABLE LT_KONV INTO LW_KONV
WITH KEY KPOSN = LW_ITEM-EBELP
KSCHL = 'PB00' .
IF SY-SUBRC = . CLEAR LW_EKPO .
LW_EKPO-KBETR = LW_KONV-KBETR .
LW_EKPO-MENGE = LW_ITEM-MENGE .
LW_EKPO-MATNR = LW_ITEM-MATNR .
LW_EKPO-WAERS = LW_KONV-WAERS .
LW_EKPO-KMEIN = LW_KONV-KMEIN .
LW_EKPO-KBET2 = LW_KONV-KBETR .
LW_EKPO-KPEIN = LW_KONV-KPEIN .
APPEND LW_EKPO TO LT_EKPO .
ELSE .
CLEAR LW_KONV .
READ TABLE LT_KONV INTO LW_KONV
WITH KEY KPOSN = LW_ITEM-EBELP
KSCHL = 'PBXX' .
IF SY-SUBRC = .
CLEAR LW_EKPO .
LW_EKPO-MENGE = LW_ITEM-MENGE .
LW_EKPO-KBETR = LW_KONV-KBETR .
LW_EKPO-MATNR = LW_ITEM-MATNR .
LW_EKPO-WAERS = LW_KONV-WAERS .
LW_EKPO-KMEIN = LW_KONV-KMEIN .
LW_EKPO-KBET2 = LW_KONV-KBETR .
LW_EKPO-KPEIN = LW_KONV-KPEIN .
APPEND LW_EKPO TO LT_EKPO .
ENDIF .
ENDIF .
CLEAR LW_ITEM .
ENDLOOP . "取到唯一的最小值
SORT LT_EKPO BY MATNR KBETR ASCENDING .
DELETE ADJACENT DUPLICATES FROM LT_EKPO
COMPARING MATNR . IF LT_EKPO[] IS NOT INITIAL . CLEAR LW_EKPO .
LOOP AT LT_EKPO INTO LW_EKPO .
CLEAR : LT_BAPICONDCT[] ,
LT_BAPICONDHD[] ,
LT_BAPICONDIT[] ,
LT_BAPICONDQS[] ,
LT_BAPICONDVS[] ,
LT_BAPIRET2[] ,
LT_BAPIKNUMHS[] ,
LT_MEM_INITIAL[] . LW_EKPO-KBETR = LW_EKPO-KBET2 .
SELECT SINGLE KNUMH
INTO LV_KNUMH
FROM A901
WHERE KSCHL = 'PB00'
AND MATNR = LW_EKPO-MATNR
AND ZONWA = LW_EKPO-WAERS
AND DATBI >= SY-DATUM
AND DATAB <= SY-DATUM .
IF SY-SUBRC = .
CLEAR: LT_KONP[],LT_KONM .
SELECT *
INTO TABLE LT_KONP
FROM KONP
WHERE KNUMH = LV_KNUMH .
IF SY-SUBRC = .
SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_KONM FROM KONM
FOR ALL ENTRIES IN LT_KONP WHERE KNUMH = LT_KONP-KNUMH AND KOPOS = LT_KONP-KOPOS." AND KSTBM <= LW_EKPO-MENGE.
ENDIF.
CLEAR LW_KONP .
READ TABLE LT_KONP INTO LW_KONP INDEX . SORT LT_KONM BY KNUMH KOPOS KSTBM DESCENDING."先取最大的,然后倒序,小于等于当前数量 赋值
READ TABLE LT_KONM INTO LW_KONM INDEX .
IF LT_KONM[] IS NOT INITIAL.
LW_KONP-KBETR = LW_KONM-KBETR.
LOOP AT LT_KONM INTO LW_KONM WHERE KSTBM >= LW_EKPO-MENGE.
LW_KONP-KBETR = LW_KONM-KBETR.
ENDLOOP.
ENDIF. IF LW_EKPO-WAERS <> LW_KONP-KONWA .
CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
DATE = SY-DATUM
FOREIGN_CURRENCY = LW_KONP-KONWA
LOCAL_AMOUNT = LW_EKPO-KBETR
LOCAL_CURRENCY = LW_EKPO-WAERS
IMPORTING
FOREIGN_AMOUNT = LW_EKPO-KBETR
EXCEPTIONS
NO_RATE_FOUND =
OVERFLOW =
NO_FACTORS_FOUND =
NO_SPREAD_FOUND =
DERIVED_2_TIMES =
OTHERS = .
ENDIF . IF LW_EKPO-KMEIN <> LW_KONP-KMEIN ."数量单位转换
DATA : LV_MENGE TYPE EKPO-MENGE .
LV_MENGE = LW_KONP-KPEIN .
CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
EXPORTING
I_MATNR = LW_ITEM-MATNR
I_IN_ME = LW_KONP-KMEIN
I_OUT_ME = LW_EKPO-KMEIN
I_MENGE = LV_MENGE
IMPORTING
E_MENGE = LV_MENGE
EXCEPTIONS
ERROR_IN_APPLICATION =
ERROR =
OTHERS = . LW_KONP-KBETR = LW_KONP-KBETR / LV_MENGE * LW_EKPO-KPEIN .
ELSE .
LW_KONP-KBETR = LW_KONP-KBETR / LW_KONP-KPEIN * LW_EKPO-KPEIN .
ENDIF . IF LW_EKPO-KBETR < LW_KONP-KBETR . " LW_KONP-KBETR = LW_EKPO-KBETR * LW_KONP-KPEIN .
LW_KONP-KBETR = LW_EKPO-KBET2 .
********************************************************
********************************************************
CHECK LW_KONP-KBETR <> .
H_VARKEY = LW_ITEM-MATNR .
LW_BAPICONDCT-OPERATION = ''. "更改
LW_BAPICONDCT-COND_USAGE = 'A'. "条件表用途 ‘A' 定价
LW_BAPICONDCT-TABLE_NO = ''.
LW_BAPICONDCT-APPLICATIO = LW_KONP-KAPPL.
LW_BAPICONDCT-COND_TYPE = LW_KONP-KSCHL. "定价条件
LW_BAPICONDCT-VARKEY = H_VARKEY.
LW_BAPICONDCT-VALID_TO = ''.
LW_BAPICONDCT-VALID_FROM = SY-DATUM.
LW_BAPICONDCT-COND_NO = LV_KNUMH. "更改
APPEND LW_BAPICONDCT TO LT_BAPICONDCT. LW_BAPICONDHD-OPERATION = ''.
LW_BAPICONDHD-COND_NO = LV_KNUMH.
LW_BAPICONDHD-COND_USAGE = 'A'.
LW_BAPICONDHD-TABLE_NO = ''.
LW_BAPICONDHD-APPLICATIO = LW_KONP-KAPPL.
LW_BAPICONDHD-COND_TYPE = LW_KONP-KSCHL.
LW_BAPICONDHD-VALID_FROM = SY-DATUM.
LW_BAPICONDHD-VALID_TO = ''.
APPEND LW_BAPICONDHD TO LT_BAPICONDHD . IF LT_KONM[] IS NOT INITIAL.
CLEAR:LV_FLAG.
LOOP AT LT_KONM INTO LW_KONM. AT LAST.
IF LV_FLAG <> 'E'.
LV_FLAG = 'S'.
ENDIF.
ENDAT. IF LW_KONM-KSTBM > LW_EKPO-MENGE." AND LV_FLAG <> 'E'."小于等于订单数量的第一个
IF LV_FLAG = 'S'.
LV_FLAG = 'X'.
ENDIF.
ELSEIF LW_KONM-KSTBM = LW_EKPO-MENGE.
LV_FLAG = 'X'.
ELSEIF LW_KONM-KSTBM < LW_EKPO-MENGE.
IF LV_FLAG = ''.
LV_FLAG = 'X'.
ENDIF.
ENDIF.
IF LV_FLAG = 'X'.
LW_BAPICONDQS-CURRENCY = LW_KONP-KBETR.
LV_FLAG = 'E'.
ELSE.
LW_BAPICONDQS-CURRENCY = LW_KONM-KBETR.
ENDIF.
LW_BAPICONDQS-OPERATION = ''.
LW_BAPICONDQS-COND_NO = LW_KONM-KNUMH.
LW_BAPICONDQS-COND_COUNT = LW_KONM-KOPOS.
LW_BAPICONDQS-LINE_NO = LW_KONM-KLFN1.
LW_BAPICONDQS-SCALE_QTY = LW_KONM-KSTBM.
LW_BAPICONDQS-COND_UNIT = LW_EKPO-KMEIN.
LW_BAPICONDQS-CONDCURR = LW_KONP-KONWA.
APPEND LW_BAPICONDQS TO LT_BAPICONDQS.
ENDLOOP.
LW_BAPICONDIT-UNITMEASUR = LW_EKPO-KMEIN.
ENDIF. LW_BAPICONDIT-OPERATION = ''. "修改
LW_BAPICONDIT-COND_NO = LV_KNUMH.
LW_BAPICONDIT-COND_COUNT = ''. "条件序列号
LW_BAPICONDIT-APPLICATIO = LW_KONP-KAPPL.
LW_BAPICONDIT-COND_TYPE = LW_KONP-KSCHL. "条件类型
LW_BAPICONDIT-SCALETYPE = 'A'. "STFKZ Staffelsoort
LW_BAPICONDIT-SCALEBASIN = LW_KONP-STFKZ. "KZBZG Teken:rekeneenheid " LW_bapicondit-scalebasin = 'C'. 存在数量等级
LW_BAPICONDIT-SCALE_QTY = LW_KONP-KSTBM. "KSTBM Conditiestaffelbasis hoeveelheid
LW_BAPICONDIT-COND_P_UNT = LW_EKPO-KPEIN . "KPEIN prijseenheid
LW_BAPICONDIT-COND_UNIT = LW_EKPO-KMEIN. "KMEIN Conditie-hoeveelheidseenheid
LW_BAPICONDIT-CALCTYPCON = LW_KONP-KRECH. "KRECH Conditie-rekenregel
LW_BAPICONDIT-COND_VALUE = LW_KONP-KBETR.
LW_BAPICONDIT-CONDCURR = LW_KONP-KONWA.
APPEND LW_BAPICONDIT TO LT_BAPICONDIT . CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
TABLES
TI_BAPICONDCT = LT_BAPICONDCT
TI_BAPICONDHD = LT_BAPICONDHD
TI_BAPICONDIT = LT_BAPICONDIT
TI_BAPICONDQS = LT_BAPICONDQS
TI_BAPICONDVS = LT_BAPICONDVS
TO_BAPIRET2 = LT_BAPIRET2
TO_BAPIKNUMHS = LT_BAPIKNUMHS
TO_MEM_INITIAL = LT_MEM_INITIAL
EXCEPTIONS
UPDATE_ERROR =
OTHERS = .
CLEAR LW_BAPIRET2 .
READ TABLE LT_BAPIRET2 INTO LW_BAPIRET2 WITH KEY TYPE = 'E' .
IF SY-SUBRC <> .
COMMIT WORK AND WAIT .
ELSE .
ROLLBACK WORK .
CALL FUNCTION 'ZMMFM001'
EXPORTING
EBELN = LW_HEAD-EBELN
MATNR = LW_EKPO-MATNR
KBETR = LW_KONP-KBETR
TABLES
BAPIRET2 = LT_BAPIRET2. ENDIF .
********************************************************
********************************************************
ENDIF . ELSE . SELECT SINGLE KNUMH
INTO LV_KNUMH
FROM A901
WHERE KSCHL = 'PB00'
AND MATNR = LW_EKPO-MATNR
AND DATBI >= SY-DATUM
AND DATAB <= SY-DATUM .
IF SY-SUBRC <> . ********************************************************
********************************************************
* CHECK LW_KONP-KBETR <> 0 .
LW_KONP-KAPPL = 'M' .
LW_KONP-KSCHL = 'PB00' .
LW_KONP-STFKZ = 'A' .
LW_KONP-KSTBM = .
LW_KONP-KPEIN = LW_EKPO-KPEIN .
LW_KONP-KMEIN = LW_EKPO-KMEIN .
LW_KONP-KRECH = 'C' .
LW_KONP-KBETR = LW_EKPO-KBET2 .
LW_KONP-KONWA = LW_EKPO-WAERS .
LV_KNUMH = '$000000001' . CONCATENATE LW_EKPO-MATNR LW_KONP-KONWA INTO H_VARKEY .
LW_BAPICONDCT-OPERATION = ''. "更改
LW_BAPICONDCT-COND_USAGE = 'A'. "条件表用途 ‘A' 定价
LW_BAPICONDCT-TABLE_NO = ''.
LW_BAPICONDCT-APPLICATIO = LW_KONP-KAPPL.
LW_BAPICONDCT-COND_TYPE = LW_KONP-KSCHL. "定价条件
LW_BAPICONDCT-VARKEY = H_VARKEY.
LW_BAPICONDCT-VALID_TO = ''.
LW_BAPICONDCT-VALID_FROM = SY-DATUM.
LW_BAPICONDCT-COND_NO = LV_KNUMH. "更改
APPEND LW_BAPICONDCT TO LT_BAPICONDCT. LW_BAPICONDHD-OPERATION = ''.
LW_BAPICONDHD-COND_NO = LV_KNUMH.
LW_BAPICONDHD-COND_USAGE = 'A'.
LW_BAPICONDHD-TABLE_NO = ''.
LW_BAPICONDHD-APPLICATIO = LW_KONP-KAPPL.
LW_BAPICONDHD-COND_TYPE = LW_KONP-KSCHL.
LW_BAPICONDHD-VARKEY = H_VARKEY.
LW_BAPICONDHD-VALID_FROM = SY-DATUM.
LW_BAPICONDHD-VALID_TO = ''.
APPEND LW_BAPICONDHD TO LT_BAPICONDHD . LW_BAPICONDIT-OPERATION = ''. "修改
LW_BAPICONDIT-COND_NO = LV_KNUMH.
LW_BAPICONDIT-COND_COUNT = ''. "条件序列号
LW_BAPICONDIT-APPLICATIO = LW_KONP-KAPPL.
"LW_BAPICONDIT-MATLSETTL = LW_EKPO-MATNR.
LW_BAPICONDIT-COND_TYPE = LW_KONP-KSCHL. "条件类型
LW_BAPICONDIT-SCALETYPE = 'A'. "STFKZ Staffelsoort
LW_BAPICONDIT-SCALEBASIN = LW_KONP-STFKZ. "KZBZG Teken:rekeneenheid " LW_bapicondit-scalebasin = 'C'. 存在数量等级
LW_BAPICONDIT-SCALE_QTY = LW_KONP-KSTBM. "KSTBM Conditiestaffelbasis hoeveelheid
LW_BAPICONDIT-COND_P_UNT = LW_KONP-KPEIN . "KPEIN prijseenheid
LW_BAPICONDIT-COND_UNIT = LW_KONP-KMEIN. "KMEIN Conditie-hoeveelheidseenheid
LW_BAPICONDIT-CALCTYPCON = LW_KONP-KRECH. "KRECH Conditie-rekenregel
LW_BAPICONDIT-COND_VALUE = LW_KONP-KBETR.
LW_BAPICONDIT-CONDCURR = LW_KONP-KONWA.
APPEND LW_BAPICONDIT TO LT_BAPICONDIT . CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
TABLES
TI_BAPICONDCT = LT_BAPICONDCT
TI_BAPICONDHD = LT_BAPICONDHD
TI_BAPICONDIT = LT_BAPICONDIT
TI_BAPICONDQS = LT_BAPICONDQS
TI_BAPICONDVS = LT_BAPICONDVS
TO_BAPIRET2 = LT_BAPIRET2
TO_BAPIKNUMHS = LT_BAPIKNUMHS
TO_MEM_INITIAL = LT_MEM_INITIAL
EXCEPTIONS
UPDATE_ERROR =
OTHERS = .
CLEAR LW_BAPIRET2 .
READ TABLE LT_BAPIRET2 INTO LW_BAPIRET2 WITH KEY TYPE = 'E' .
IF SY-SUBRC <> .
COMMIT WORK AND WAIT .
ELSE .
ROLLBACK WORK .
CALL FUNCTION 'ZMMFM001'
EXPORTING
EBELN = LW_HEAD-EBELN
MATNR = LW_EKPO-MATNR
KBETR = LW_KONP-KBETR
TABLES
BAPIRET2 = LT_BAPIRET2.
ENDIF . ENDIF . ENDIF .
ENDLOOP .
ENDIF . ENDIF .
ENDIF .
ENDMETHOD.

METHOD IF_EX_ME_PROCESS_PO_CUST~POST.
    TYPES : BEGIN OF LS_EKPO ,"物料对应
              MATNR    TYPE EKPO-MATNR,
              MENGE    TYPE EKPO-MENGE,
              KBETR    TYPE KONV-KBETR, "P DECIMALS 6 ,
              WAERS    TYPE KONV-WAERS,
              KMEIN    TYPE KONV-KMEIN,
              KBET2    TYPE KONV-KBETR,
              KPEIN    TYPE KONV-KPEIN,
              MARKX(1) TYPE C,
            END OF LS_EKPO .

DATA : LW_EKPO TYPE LS_EKPO .
    DATA : LT_EKPO TYPE TABLE OF LS_EKPO .

DATA : LW_ITEM TYPE MEPOITEM.
    DATA : LW_HEAD TYPE MEPOHEADER.
    DATA : LT_ITEM TYPE TABLE OF MEPOITEM.
    DATA : LT_KONV TYPE TABLE OF KOMV .
    DATA : LT_KONV_01 TYPE TABLE OF KOMV .
    DATA : LW_KONV TYPE KOMV .
    DATA : LV_KNUMH TYPE A118-KNUMH .
    DATA : LT_KONP TYPE TABLE OF KONP .
    DATA : LW_KONP TYPE KONP .
    DATA: LT_ITEMS TYPE PURCHASE_ORDER_ITEMS,
          LW_ITEMS TYPE PURCHASE_ORDER_ITEM.
    DATA : LM_KONV TYPE REF TO IF_PURCHASE_ORDER_ITEM_MM .
    DATA:LT_KONM TYPE TABLE OF  KONM,
         LW_KONM TYPE  KONM.
    DATA:LV_FLAG TYPE C.

***************************************************
***************************************************

DATA: LT_BAPICONDCT TYPE TABLE OF  BAPICONDCT   ,  "
          LW_BAPICONDCT TYPE  BAPICONDCT,

LT_BAPICONDHD TYPE TABLE OF BAPICONDHD ,  "
          LW_BAPICONDHD TYPE  BAPICONDHD,

LT_BAPICONDIT TYPE TABLE OF BAPICONDIT,
          LW_BAPICONDIT TYPE  BAPICONDIT,

LT_BAPICONDQS TYPE TABLE OF BAPICONDQS,
          LW_BAPICONDQS TYPE  BAPICONDQS,

LT_BAPICONDVS TYPE TABLE OF BAPICONDVS,
          LW_BAPICONDVS TYPE  BAPICONDVS.

DATA: LT_BAPIRET2 TYPE TABLE OF BAPIRET2 .
    DATA: LW_BAPIRET2 TYPE BAPIRET2 .

DATA: LT_BAPIKNUMHS TYPE TABLE OF BAPIKNUMHS  .
    DATA: LT_MEM_INITIAL TYPE  TABLE OF CND_MEM_INITIAL.

DATA : LV_MARKX(1) TYPE C ."需要扩大标识

DATA: H_VARKEY(100),
          H_COND_UNIT TYPE MEINS .
***************************************************
***************************************************

CLEAR : LT_EKPO[] .
    CLEAR : LT_ITEM[] .
    CLEAR : LT_KONV[] .
    CLEAR : LT_KONP[] .
    IF SY-TCODE = 'ME21N' OR SY-TCODE = 'ME22N' OR SY-TCODE = 'ME23N'
      OR SY-TCODE = 'ME29N' .
      LT_ITEMS = IM_HEADER->GET_ITEMS( ).
      LW_HEAD = IM_HEADER->GET_DATA( ).
      IF LW_HEAD-BSART = '913' OR  LW_HEAD-BSART = '914'
        OR  LW_HEAD-BSART = '915' OR  LW_HEAD-BSART = '916' .
      ELSE .
        CLEAR LW_ITEMS .
        LOOP AT LT_ITEMS INTO LW_ITEMS .

CLEAR LW_ITEM .
          LW_ITEM = LW_ITEMS-ITEM->GET_DATA( ).
          APPEND LW_ITEM TO LT_ITEM .

CLEAR LT_KONV_01[] .
          CALL METHOD LW_ITEMS-ITEM->GET_CONDITIONS
            IMPORTING
              EX_CONDITIONS = LT_KONV_01[].
          APPEND LINES OF LT_KONV_01 TO LT_KONV .

ENDLOOP.

*    CALL METHOD IM_HEADER->GET_CONDITIONS
*      IMPORTING
*        EX_CONDITIONS = LT_KONV[].

CLEAR LW_ITEM  .
        LOOP AT LT_ITEM INTO LW_ITEM .
          CHECK LW_ITEM-UMSON = '' ."免费货物不检查
          CHECK LW_ITEM-LOEKZ = '' ."删除货物不检查
          CHECK LW_ITEM-MATNR <> '' ."无物料号不检查
          CLEAR LW_KONV .
          READ TABLE LT_KONV INTO LW_KONV
                  WITH KEY KPOSN = LW_ITEM-EBELP
                          KSCHL = 'PB00' .
          IF SY-SUBRC = 0 .

CLEAR LW_EKPO .
*            IF LW_KONV-KBETR  / LW_KONV-KPEIN >= 1000 .
*              LW_EKPO-KBETR = LW_KONV-KBETR  / LW_KONV-KPEIN ."扩大100倍方便小数位对比
*            ELSE .
*              LW_EKPO-KBETR = LW_KONV-KBETR  / LW_KONV-KPEIN * 1000."扩大100倍方便小数位对比
*              LW_EKPO-MARKX = 'X' .
*            ENDIF .
            LW_EKPO-KBETR = LW_KONV-KBETR  .
            LW_EKPO-MENGE = LW_ITEM-MENGE  .
            LW_EKPO-MATNR = LW_ITEM-MATNR .
            LW_EKPO-WAERS = LW_KONV-WAERS .
            LW_EKPO-KMEIN = LW_KONV-KMEIN .
            LW_EKPO-KBET2 = LW_KONV-KBETR .
            LW_EKPO-KPEIN = LW_KONV-KPEIN .
            APPEND LW_EKPO TO LT_EKPO .
          ELSE .
            CLEAR LW_KONV .
            READ TABLE LT_KONV INTO LW_KONV
                    WITH KEY KPOSN = LW_ITEM-EBELP
                            KSCHL = 'PBXX' .
            IF SY-SUBRC = 0 .
              CLEAR LW_EKPO .
*              IF LW_KONV-KBETR  / LW_KONV-KPEIN >= 1000 .
*                LW_EKPO-KBETR = LW_KONV-KBETR  / LW_KONV-KPEIN ."扩大1000倍方便小数位对比
*              ELSE .
*                LW_EKPO-KBETR = LW_KONV-KBETR  / LW_KONV-KPEIN * 1000."扩大1000倍方便小数位对比
*                LW_EKPO-MARKX = 'X' .
*              ENDIF .
              LW_EKPO-MENGE = LW_ITEM-MENGE  .
              LW_EKPO-KBETR = LW_KONV-KBETR  .
              LW_EKPO-MATNR = LW_ITEM-MATNR .
              LW_EKPO-WAERS = LW_KONV-WAERS .
              LW_EKPO-KMEIN = LW_KONV-KMEIN .
              LW_EKPO-KBET2 = LW_KONV-KBETR .
              LW_EKPO-KPEIN = LW_KONV-KPEIN .
              APPEND LW_EKPO TO LT_EKPO .
            ENDIF .
          ENDIF .
          CLEAR LW_ITEM  .
        ENDLOOP .

"取到唯一的最小值
        SORT LT_EKPO BY MATNR KBETR ASCENDING .
        DELETE ADJACENT DUPLICATES FROM LT_EKPO
                COMPARING MATNR .

IF LT_EKPO[] IS NOT INITIAL .

CLEAR LW_EKPO .
          LOOP AT LT_EKPO INTO LW_EKPO .
            CLEAR : LT_BAPICONDCT[]  ,
                    LT_BAPICONDHD[]  ,
                    LT_BAPICONDIT[]  ,
                    LT_BAPICONDQS[]  ,
                    LT_BAPICONDVS[]  ,
                    LT_BAPIRET2[]    ,
                    LT_BAPIKNUMHS[]  ,
                    LT_MEM_INITIAL[] .

LW_EKPO-KBETR = LW_EKPO-KBET2 .
            SELECT SINGLE KNUMH
                INTO LV_KNUMH
                FROM A901
                WHERE KSCHL = 'PB00'
                  AND MATNR = LW_EKPO-MATNR
                  AND ZONWA = LW_EKPO-WAERS
                  AND DATBI >= SY-DATUM
                  AND DATAB <= SY-DATUM .
            IF SY-SUBRC = 0 .
              CLEAR: LT_KONP[],LT_KONM .
              SELECT *
                INTO TABLE LT_KONP
                FROM KONP
                WHERE KNUMH = LV_KNUMH  .
              IF SY-SUBRC = 0.
                SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_KONM FROM KONM
                  FOR ALL ENTRIES IN LT_KONP WHERE KNUMH = LT_KONP-KNUMH AND KOPOS = LT_KONP-KOPOS." AND KSTBM <= LW_EKPO-MENGE.
              ENDIF.
              CLEAR LW_KONP .
              READ TABLE LT_KONP INTO LW_KONP INDEX 1 .

SORT LT_KONM BY KNUMH KOPOS KSTBM DESCENDING."先取最大的,然后倒序,小于等于当前数量 赋值
              READ TABLE LT_KONM INTO LW_KONM INDEX 1.
              IF LT_KONM[] IS NOT INITIAL.
                LW_KONP-KBETR = LW_KONM-KBETR.
                LOOP AT LT_KONM INTO LW_KONM WHERE KSTBM >= LW_EKPO-MENGE.
                  LW_KONP-KBETR = LW_KONM-KBETR.
                ENDLOOP.

*                CLEAR:LT_KONM[].
*                SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_KONM FROM KONM
*                  FOR ALL ENTRIES IN LT_KONP WHERE KNUMH = LT_KONP-KNUMH AND KOPOS = LT_KONP-KOPOS.
*                  SORT LT_KONM BY KNUMH KOPOS KSTBM DESCENDING.
              ENDIF.

IF LW_EKPO-WAERS <> LW_KONP-KONWA .
                CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
                  EXPORTING
                    DATE             = SY-DATUM
                    FOREIGN_CURRENCY = LW_KONP-KONWA
                    LOCAL_AMOUNT     = LW_EKPO-KBETR
                    LOCAL_CURRENCY   = LW_EKPO-WAERS
                  IMPORTING
                    FOREIGN_AMOUNT   = LW_EKPO-KBETR
                  EXCEPTIONS
                    NO_RATE_FOUND    = 1
                    OVERFLOW         = 2
                    NO_FACTORS_FOUND = 3
                    NO_SPREAD_FOUND  = 4
                    DERIVED_2_TIMES  = 5
                    OTHERS           = 6.
              ENDIF .

*              IF LW_EKPO-KMEIN <> LW_KONV-KMEIN ."数量单位转换
*                DATA : LV_MENGE TYPE EKPO-MENGE .
*                LV_MENGE = 1 .
*                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*                  EXPORTING
*                    I_MATNR              = LW_ITEM-MATNR
*                    I_IN_ME              = LW_EKPO-KMEIN
*                    I_OUT_ME             = LW_KONP-KMEIN
*                    I_MENGE              = LV_MENGE
*                  IMPORTING
*                    E_MENGE              = LV_MENGE
*                  EXCEPTIONS
*                    ERROR_IN_APPLICATION = 1
*                    ERROR                = 2
*                    OTHERS               = 3.
*                LW_EKPO-KBETR =  LW_EKPO-KBETR * LV_MENGE.
*              ENDIF .
*              LW_KONP-KBETR = LW_KONP-KBETR  / LW_KONP-KPEIN .
              IF LW_EKPO-KMEIN <> LW_KONP-KMEIN ."数量单位转换
                DATA : LV_MENGE TYPE EKPO-MENGE .
                LV_MENGE = LW_KONP-KPEIN .
                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
                  EXPORTING
                    I_MATNR              = LW_ITEM-MATNR
                    I_IN_ME              = LW_KONP-KMEIN
                    I_OUT_ME             = LW_EKPO-KMEIN
                    I_MENGE              = LV_MENGE
                  IMPORTING
                    E_MENGE              = LV_MENGE
                  EXCEPTIONS
                    ERROR_IN_APPLICATION = 1
                    ERROR                = 2
                    OTHERS               = 3.

LW_KONP-KBETR = LW_KONP-KBETR  / LV_MENGE * LW_EKPO-KPEIN .
              ELSE .
                LW_KONP-KBETR = LW_KONP-KBETR  / LW_KONP-KPEIN * LW_EKPO-KPEIN .
              ENDIF .
*              IF LW_EKPO-MARKX = 'X' .
*                LW_KONP-KBETR = LW_KONP-KBETR  / LW_KONP-KPEIN * LW_EKPO-KPEIN * 1000 .
*              ELSE .
*                LW_KONP-KBETR = LW_KONP-KBETR  / LW_KONP-KPEIN * LW_EKPO-KPEIN .
*              ENDIF .

IF LW_EKPO-KBETR < LW_KONP-KBETR .

"   LW_KONP-KBETR = LW_EKPO-KBETR * LW_KONP-KPEIN  .
                LW_KONP-KBETR = LW_EKPO-KBET2 .
********************************************************
********************************************************
                CHECK LW_KONP-KBETR <> 0 .
                H_VARKEY  = LW_ITEM-MATNR  .
                LW_BAPICONDCT-OPERATION = '004'.         "更改
                LW_BAPICONDCT-COND_USAGE = 'A'.      "条件表用途 ‘A' 定价
                LW_BAPICONDCT-TABLE_NO = '901'.
                LW_BAPICONDCT-APPLICATIO = LW_KONP-KAPPL.
                LW_BAPICONDCT-COND_TYPE = LW_KONP-KSCHL.    "定价条件
                LW_BAPICONDCT-VARKEY = H_VARKEY.
                LW_BAPICONDCT-VALID_TO = '99991231'.
                LW_BAPICONDCT-VALID_FROM = SY-DATUM.
                LW_BAPICONDCT-COND_NO = LV_KNUMH.    "更改
                APPEND LW_BAPICONDCT TO LT_BAPICONDCT.

LW_BAPICONDHD-OPERATION = '004'.
                LW_BAPICONDHD-COND_NO = LV_KNUMH.
                LW_BAPICONDHD-COND_USAGE = 'A'.
                LW_BAPICONDHD-TABLE_NO = '901'.
                LW_BAPICONDHD-APPLICATIO = LW_KONP-KAPPL.
                LW_BAPICONDHD-COND_TYPE = LW_KONP-KSCHL.
                LW_BAPICONDHD-VALID_FROM = SY-DATUM.
                LW_BAPICONDHD-VALID_TO = '99991231'.
                APPEND LW_BAPICONDHD TO  LT_BAPICONDHD .

IF LT_KONM[] IS NOT INITIAL.
                  CLEAR:LV_FLAG.
                  LOOP AT LT_KONM INTO LW_KONM.

AT LAST.
                      IF LV_FLAG <> 'E'.
                        LV_FLAG = 'S'.
                      ENDIF.
                    ENDAT.

IF LW_KONM-KSTBM > LW_EKPO-MENGE." AND LV_FLAG <> 'E'."小于等于订单数量的第一个
                      IF LV_FLAG = 'S'.
                        LV_FLAG = 'X'.
                      ENDIF.
                    ELSEIF LW_KONM-KSTBM = LW_EKPO-MENGE.
                      LV_FLAG = 'X'.
                    ELSEIF LW_KONM-KSTBM < LW_EKPO-MENGE.
                      IF LV_FLAG = ''.
                        LV_FLAG = 'X'.
                      ENDIF.
                    ENDIF.
                    IF LV_FLAG = 'X'.
                      LW_BAPICONDQS-CURRENCY = LW_KONP-KBETR.
                      LV_FLAG = 'E'.
                    ELSE.
                      LW_BAPICONDQS-CURRENCY = LW_KONM-KBETR.
                    ENDIF.
                    LW_BAPICONDQS-OPERATION  = '004'.
                    LW_BAPICONDQS-COND_NO    = LW_KONM-KNUMH.
                    LW_BAPICONDQS-COND_COUNT = LW_KONM-KOPOS.
                    LW_BAPICONDQS-LINE_NO    = LW_KONM-KLFN1.
                    LW_BAPICONDQS-SCALE_QTY  = LW_KONM-KSTBM.
                    LW_BAPICONDQS-COND_UNIT  = LW_EKPO-KMEIN.
                    LW_BAPICONDQS-CONDCURR   = LW_KONP-KONWA.
                    APPEND LW_BAPICONDQS TO LT_BAPICONDQS.
                  ENDLOOP.
                  LW_BAPICONDIT-UNITMEASUR = LW_EKPO-KMEIN.
                ENDIF.

LW_BAPICONDIT-OPERATION = '004'.   "修改
                LW_BAPICONDIT-COND_NO = LV_KNUMH.
                LW_BAPICONDIT-COND_COUNT = '01'.     "条件序列号
                LW_BAPICONDIT-APPLICATIO = LW_KONP-KAPPL.
                LW_BAPICONDIT-COND_TYPE =  LW_KONP-KSCHL.       "条件类型
                LW_BAPICONDIT-SCALETYPE = 'A'.       "STFKZ Staffelsoort
                LW_BAPICONDIT-SCALEBASIN = LW_KONP-STFKZ.      "KZBZG Teken:rekeneenheid "  LW_bapicondit-scalebasin = 'C'. 存在数量等级
                LW_BAPICONDIT-SCALE_QTY = LW_KONP-KSTBM.       "KSTBM Conditiestaffelbasis hoeveelheid
                LW_BAPICONDIT-COND_P_UNT = LW_EKPO-KPEIN .      "KPEIN prijseenheid
                LW_BAPICONDIT-COND_UNIT = LW_EKPO-KMEIN.      "KMEIN Conditie-hoeveelheidseenheid
                LW_BAPICONDIT-CALCTYPCON = LW_KONP-KRECH.      "KRECH Conditie-rekenregel
                LW_BAPICONDIT-COND_VALUE = LW_KONP-KBETR.
                LW_BAPICONDIT-CONDCURR = LW_KONP-KONWA.
                APPEND  LW_BAPICONDIT  TO LT_BAPICONDIT  .

CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
                  TABLES
                    TI_BAPICONDCT  = LT_BAPICONDCT
                    TI_BAPICONDHD  = LT_BAPICONDHD
                    TI_BAPICONDIT  = LT_BAPICONDIT
                    TI_BAPICONDQS  = LT_BAPICONDQS
                    TI_BAPICONDVS  = LT_BAPICONDVS
                    TO_BAPIRET2    = LT_BAPIRET2
                    TO_BAPIKNUMHS  = LT_BAPIKNUMHS
                    TO_MEM_INITIAL = LT_MEM_INITIAL
                  EXCEPTIONS
                    UPDATE_ERROR   = 1
                    OTHERS         = 2.
                CLEAR LW_BAPIRET2 .
                READ TABLE LT_BAPIRET2 INTO LW_BAPIRET2 WITH KEY TYPE = 'E' .
                IF SY-SUBRC <> 0 .
                  COMMIT WORK AND WAIT .
                ELSE .
                  ROLLBACK WORK .
                  CALL FUNCTION 'ZMMFM001'
                    EXPORTING
                      EBELN    = LW_HEAD-EBELN
                      MATNR    = LW_EKPO-MATNR
                      KBETR    = LW_KONP-KBETR
                    TABLES
                      BAPIRET2 = LT_BAPIRET2.

ENDIF .
********************************************************
********************************************************
              ENDIF .

ELSE .

SELECT SINGLE KNUMH
                 INTO LV_KNUMH
                 FROM A901
                 WHERE KSCHL = 'PB00'
                   AND MATNR = LW_EKPO-MATNR
                   AND DATBI >= SY-DATUM
                   AND DATAB <= SY-DATUM .
              IF SY-SUBRC <> 0 .

********************************************************
********************************************************
*               CHECK LW_KONP-KBETR <> 0 .
                LW_KONP-KAPPL = 'M' .
                LW_KONP-KSCHL = 'PB00' .
                LW_KONP-STFKZ = 'A' .
                LW_KONP-KSTBM = 0 .
                LW_KONP-KPEIN = LW_EKPO-KPEIN .
                LW_KONP-KMEIN = LW_EKPO-KMEIN .
                LW_KONP-KRECH = 'C' .
                LW_KONP-KBETR = LW_EKPO-KBET2 .
                LW_KONP-KONWA = LW_EKPO-WAERS .
                LV_KNUMH = '$000000001'  .

CONCATENATE  LW_EKPO-MATNR LW_KONP-KONWA INTO H_VARKEY   .
                LW_BAPICONDCT-OPERATION = '009'.         "更改
                LW_BAPICONDCT-COND_USAGE = 'A'.      "条件表用途 ‘A' 定价
                LW_BAPICONDCT-TABLE_NO = '901'.
                LW_BAPICONDCT-APPLICATIO = LW_KONP-KAPPL.
                LW_BAPICONDCT-COND_TYPE = LW_KONP-KSCHL.    "定价条件
                LW_BAPICONDCT-VARKEY = H_VARKEY.
                LW_BAPICONDCT-VALID_TO = '99991231'.
                LW_BAPICONDCT-VALID_FROM = SY-DATUM.
                LW_BAPICONDCT-COND_NO = LV_KNUMH.    "更改
                APPEND LW_BAPICONDCT TO LT_BAPICONDCT.

LW_BAPICONDHD-OPERATION = '009'.
                LW_BAPICONDHD-COND_NO = LV_KNUMH.
                LW_BAPICONDHD-COND_USAGE = 'A'.
                LW_BAPICONDHD-TABLE_NO = '901'.
                LW_BAPICONDHD-APPLICATIO = LW_KONP-KAPPL.
                LW_BAPICONDHD-COND_TYPE = LW_KONP-KSCHL.
                LW_BAPICONDHD-VARKEY = H_VARKEY.
                LW_BAPICONDHD-VALID_FROM = SY-DATUM.
                LW_BAPICONDHD-VALID_TO = '99991231'.
                APPEND LW_BAPICONDHD TO  LT_BAPICONDHD .

LW_BAPICONDIT-OPERATION = '009'.   "修改
                LW_BAPICONDIT-COND_NO = LV_KNUMH.
                LW_BAPICONDIT-COND_COUNT = '01'.     "条件序列号
                LW_BAPICONDIT-APPLICATIO = LW_KONP-KAPPL.
                "LW_BAPICONDIT-MATLSETTL = LW_EKPO-MATNR.
                LW_BAPICONDIT-COND_TYPE =  LW_KONP-KSCHL.       "条件类型
                LW_BAPICONDIT-SCALETYPE = 'A'.       "STFKZ Staffelsoort
                LW_BAPICONDIT-SCALEBASIN = LW_KONP-STFKZ.      "KZBZG Teken:rekeneenheid "  LW_bapicondit-scalebasin = 'C'. 存在数量等级
                LW_BAPICONDIT-SCALE_QTY = LW_KONP-KSTBM.       "KSTBM Conditiestaffelbasis hoeveelheid
                LW_BAPICONDIT-COND_P_UNT = LW_KONP-KPEIN .      "KPEIN prijseenheid
                LW_BAPICONDIT-COND_UNIT = LW_KONP-KMEIN.      "KMEIN Conditie-hoeveelheidseenheid
                LW_BAPICONDIT-CALCTYPCON = LW_KONP-KRECH.      "KRECH Conditie-rekenregel
                LW_BAPICONDIT-COND_VALUE = LW_KONP-KBETR.
                LW_BAPICONDIT-CONDCURR = LW_KONP-KONWA.
                APPEND  LW_BAPICONDIT  TO LT_BAPICONDIT  .

CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
                  TABLES
                    TI_BAPICONDCT  = LT_BAPICONDCT
                    TI_BAPICONDHD  = LT_BAPICONDHD
                    TI_BAPICONDIT  = LT_BAPICONDIT
                    TI_BAPICONDQS  = LT_BAPICONDQS
                    TI_BAPICONDVS  = LT_BAPICONDVS
                    TO_BAPIRET2    = LT_BAPIRET2
                    TO_BAPIKNUMHS  = LT_BAPIKNUMHS
                    TO_MEM_INITIAL = LT_MEM_INITIAL
                  EXCEPTIONS
                    UPDATE_ERROR   = 1
                    OTHERS         = 2.
                CLEAR LW_BAPIRET2 .
                READ TABLE LT_BAPIRET2 INTO LW_BAPIRET2 WITH KEY TYPE = 'E' .
                IF SY-SUBRC <> 0 .
                  COMMIT WORK AND WAIT .
                ELSE .
                  ROLLBACK WORK .
                  CALL FUNCTION 'ZMMFM001'
                    EXPORTING
                      EBELN    = LW_HEAD-EBELN
                      MATNR    = LW_EKPO-MATNR
                      KBETR    = LW_KONP-KBETR
                    TABLES
                      BAPIRET2 = LT_BAPIRET2.
                ENDIF .

ENDIF .

ENDIF .
          ENDLOOP .
        ENDIF .

ENDIF .
    ENDIF .
  ENDMETHOD.

采购订单限价(包含阶梯价)ME_PROCESS_PO_CUST的更多相关文章

  1. ME&lowbar;PROCESS&lowbar;PO&lowbar;CUST 实现采购订单行项目增强

    用户希望创建采购订单时,输入行项目时,能根据采购订单类型,自动带出科目分类类别. 业务顾问看了一下配置,不能实现这个功能,所以用增强实现. 采购订单BADI增强:ME_PROCESS_PO_CUST. ...

  2. MM--发票校验 及基于采购订单的MIRO发票校验过程&lpar;

    一.介绍发票校验是物料管理(MM)系统的一部分.它提供物料管理部分和财务会计, 成本控制和资产管理部分的连接.物料管理模块的发票校验为以下目的服务:它完成物料采购的全过程 - 物料采购从采购申请开始, ...

  3. SAP采购订单屏幕增强

    转自<http://blog.csdn.net/heng0757/article/details/8073875> 为采购订单增加一个页标签,在其中放入客户自定义字段, 1. CMOD 增 ...

  4. 采购订单打印并预览PDF

    *&---------------------------------------------------------------------* *& Report Z01MMF019 ...

  5. 采购订单审批与撤销审批BAPI

    *"---------------------------------------------------------------------- *"*"本地接口: *& ...

  6. SAP采购订单入库后不允许修改单价增强

    需求:在根据采购订单做了入库凭证之后,如果用户反审批采购订单去修改单价,系统提示‘已收货,不允许修改单价’. 判断流程:是否有入库凭证 如果采购订单条件按采购信息记录定价,这个价格本来就不能修改,只能 ...

  7. U8采购订单联查采购入库单

    1.表头rdrecord01,字段ipurorderid(采购订单ID), cOrderCode(采购订单号)要与采购订单表头主键和单号对应 表体rdrecords01,字段cPOID(采购订单号), ...

  8. SAP采购订单历史明细报表源代码(自己收藏)

    SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF } ...

  9. SAP公司间采购订单关联交货单报表源代码(自己收藏)

    SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF } ...

随机推荐

  1. 前端学PHP之运算符

    × 目录 [1]总括 [2]算术运算符 [3]赋值运算符[4]位运算符[5]比较运算符[6]错误控制[7]逻辑运算符[8]字符串连接[9]数组运算符 前面的话 运算符是可以通过给出的一或多个表达式来产 ...

  2. &lbrack;New Portal&rsqb;Windows Azure Virtual Machine &lpar;23&rpar; 使用Storage Space&comma;提高Virtual Machine磁盘的IOPS

    <Windows Azure Platform 系列文章目录> 注意:如果使用Azure Virtual Machine,虚拟机所在的存储账号建议使用Local Redundant.不建议 ...

  3. 把Java生成的RSA公钥、私钥转换成&period;NET使用的XML格式

    import java.security.KeyFactory; import java.security.interfaces.RSAPrivateCrtKey; import java.secur ...

  4. C&num;开发MySQL数据库程序时需要注意的几点

    一:引用MySQL使用基于Parameter方式代码,总是提示:“Column '列名'cannot be null”解决 MySQL使用基于Parameter方式代码,总是提示:“Column '列 ...

  5. 转!论if else与switch的效率高低问题

    转 下面来详细描述switch与ifelse的区别. switch...case与if...else的根本区别在于,switch...case会生成一个跳转表来指示实际的case分支的地址,而这个跳转 ...

  6. Objective-C内存管理教程和原理剖析&lpar;三&rpar;

    初学Objective-C的朋友都有一个困惑,总觉得对Objective-C的内存管理机制琢磨不透,程 序经常内存泄漏或莫名其妙的崩溃.我在这里总结了自己对Objective-C内存管理机制的研究成果 ...

  7. &bsol;r&comma;&bsol;n&comma;&bsol;r&bsol;n的区别和用法

    https://blog.csdn.net/xiaofei2010/article/details/8458605

  8. 【洛谷】SAC E&num;1 Factorial

    别人可以眼杀我却研究了一个小时看了题解才懂的数学题 输入: n, k 输出: n!在k进制下后缀0的个数 n,k <= 10^12 将 n! 表示成 x×2y5z 的形式,其中 x mod 2 ...

  9. mysql导入excel表格

    https://jingyan.baidu.com/album/fc07f9891cb56412ffe5199a.html?picindex=1

  10. 搭建前端监控系统(二)JS错误监控篇

    ===================================================================== 前端性能监控系统: DEMO地址    GIT代码仓库地址 ...