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

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_PROCESS_PO_CUST 实现采购订单行项目增强

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

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

    一.介绍发票校验是物料管理(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. Codeforces Round #243 (Div. 2) B(思维模拟题)

    http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...

  2. Windows Internals学习笔记(五)Synchronization

    参考资料: 1. <Windows Internals> 2. 自旋锁spinlock剖析与改进 3. Lock指令前缀 4. Lock指令前缀(二) 5. Kernel Dispatch ...

  3. javascript学习-原生javascript的小特效(原生javascript实现链式运动)

    以下代码就不详细解析了,在我之前的多个运动效果中已经解析好多次了,重复的地方这里就不说明了,有兴趣的童鞋可以去看看之前的文章<原生javascript的小特效> <!DOCTYPE ...

  4. Nginx基础知识之——配置文件信息(检查配置文件是否正确)

    一.检查配置文件是否正确: /usr/local/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf 检查结果: nginx: [emerg] ngin ...

  5. poj1971Parallelogram Counting

    链接 越来越感觉到了数学的重要性!.. 这题本来用以斜率和长度为key值进行hash不过感觉很麻烦还TLE了.. 最后知道中点一样的话就可以组成平行四边形,初中数学就可以了.. #include &l ...

  6. TCP/IP协议学习(一) LWIP实现网络远程IAP下载更新

    最近需要实现通过TCP/IP远程IAP在线更新功能,忙了2周终于在原有嵌入式服务器的基础上实现了该功能,这里就记录下实现的过程. IAP又称在应用编程,其实说简单点就是实现不需要jlink,仅通过芯片 ...

  7. html的空格和换行显示【摘自网络】

    一.HTML 代码中的所有连续的空格或空行(换行)都会被显示为一个空格,不管是内容还是标签之间. 二.当我们想让它们在同一行连续显示时,就让所有的代码之间没有空格,也不要换行. 三.当我们想要显示连续 ...

  8. 关于时区的时间的详解,比如UTC\GMT等

    UTC 和 GMT 及 北京时间的关系 UTC和GMT,这两者几乎是同一概念.它们都是指的格林尼治标准时间,只不过UTC的称呼更为正式一点.两者的区别在于前者是一个天文 上的概念,而 后者是基于一个原 ...

  9. JS 判断当前使用浏览器名及版本

    由于我的后台系统的上传图片不支持IE浏览器的,所以我需要判断公司人员在使用后台系统的时候,是否使用的浏览器是IE的. // 获取当前浏览器名 及 版本号 function appInfo(){ var ...

  10. SqlServer_事务

    事务处理是在数据处理时经常遇到的问题,经常用到的方法有以下三种总结整理如下:方法1:直接写入到sql 中在存储过程中使用 BEGIN TRANS, COMMIT TRANS, ROLLBACK TRA ...