SAP中VK11中的bapi BAPI_PRICES_CONDITIONS

2023-01-16 11:33发布

https://www.sapcenter.cn/archive/post/358261590671429.html


*&---------------------------------------------------------------------*
*& Report  ZGRIR
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

解释:VK11用BAPI_PRICES_CONDITIONS可以,VK12修改截止日期不太好用。我选择了bdc.
REPORT  z0906.
TABLES:konh,a914 .
DATA: lt_bapicondct  TYPE  bapicondct OCCURS 0  ,  "
      wa_bapicondct  TYPE  bapicondct ,
      lt_bapicondhd  TYPE  bapicondhd OCCURS 0  ,  "
      wa_bapicondhd  TYPE  bapicondhd ,
      lt_bapicondit  TYPE  bapicondit OCCURS 0  ,
      wa_bapicondit  TYPE  bapicondit ,
      lt_bapicondqs  TYPE  bapicondqs OCCURS 0  ,
      wa_bapicondqs  TYPE  bapicondqs ,
      lt_bapicondvs  TYPE  bapicondvs OCCURS 0  ,
      wa_bapicondvs  TYPE  bapicondvs .
DATA: lt_bapiret2 TYPE bapiret2 OCCURS 0 .
DATA: ret    TYPE  bapiret2 .
DATA: lt_bapiknumhs TYPE bapiknumhs  OCCURS  0 .
DATA: lt_mem_initial TYPE  cnd_mem_initial OCCURS 0 .
DATA: h_varkey(100),
      h_cond_unit TYPE meins .

SELECTION-SCREEN BEGIN OF BLOCK  bk1 WITH FRAME TITLE text_001 .
PARAMETERS:  i_kschl  LIKE a914-kschl,              "条件类型
             i_matnr  LIKE mvke-matnr,
             i_vkorg  LIKE mvke-vkorg,
             i_vtweg  LIKE mvke-vtweg,
             i_kbetr  LIKE konp-kbetr.               "定价值
SELECT-OPTIONS:  i_qsdat  FOR konh-datab.             "定价的有效期范围
SELECTION-SCREEN END OF BLOCK bk1 .


CONCATENATE   i_vkorg  i_vtweg '10' i_matnr INTO  h_varkey .

SELECT  SINGLE meins FROM mara
       INTO h_cond_unit  WHERE matnr = i_matnr .

*condition table 已条件表A951为例
wa_bapicondct-operation = '009'.     "消息功能 : 003 DEL ; 004 MODIFY ;005 REPLACE 009 INITIAL
wa_bapicondct-cond_usage = 'A'.      "条件表用途 ‘A' 定价
wa_bapicondct-table_no = '914'.
wa_bapicondct-applicatio = 'V'.
wa_bapicondct-cond_type = 'ZPR0'.    "定价条件
wa_bapicondct-varkey = h_varkey.
wa_bapicondct-valid_from = i_qsdat-low."开始日期
wa_bapicondct-valid_to = i_qsdat-high."截止日期
wa_bapicondct-cond_no = '$000000001'.   "创建
*wa_bapicondct-cond_no = '0001691852'.    "更改

APPEND wa_bapicondct TO lt_bapicondct.

*KONH
wa_bapicondhd-operation = '009'.
wa_bapicondhd-cond_no = '$000000001'.
*wa_bapicondhd-cond_no = '0001691852'.
wa_bapicondhd-created_by = sy-uname.
wa_bapicondhd-creat_date = sy-datum.
wa_bapicondhd-cond_usage = 'A'.
wa_bapicondhd-table_no = '914'.
wa_bapicondhd-applicatio = 'V'.
wa_bapicondhd-cond_type = i_kschl.
wa_bapicondhd-varkey = h_varkey.
wa_bapicondhd-valid_from = i_qsdat-low.
wa_bapicondhd-valid_to = i_qsdat-high.

APPEND wa_bapicondhd TO  lt_bapicondhd .

*KONP
wa_bapicondit-operation = '009'.   "修改
wa_bapicondit-cond_no = '$000000001'.
*wa_bapicondit-cond_no = '0001691852'.
wa_bapicondit-cond_count = '01'.     "条件序列号
wa_bapicondit-applicatio = 'V'.
wa_bapicondit-cond_type =  i_kschl.       "条件类型
wa_bapicondit-scaletype = 'A'.       "STFKZ Staffelsoort
wa_bapicondit-scalebasin = ''.      "KZBZG Teken:rekeneenheid "  wa_bapicondit-scalebasin = 'C'. 存在数量等级
wa_bapicondit-scale_qty = '1'.       "KSTBM Conditiestaffelbasis hoeveelheid
wa_bapicondit-cond_p_unt = '1'.      "KPEIN prijseenheid
wa_bapicondit-cond_unit = h_cond_unit.      "KMEIN Conditie-hoeveelheidseenheid
wa_bapicondit-calctypcon = 'C'.      "KRECH Conditie-rekenregel
wa_bapicondit-cond_value = i_kbetr.
wa_bapicondit-condcurr = 'CNY'.

APPEND  wa_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.
IF sy-subrc <> 0.
ELSE.
ENDIF.
          .


赞赏支持