采購信息記錄批導bapi


可以批導創建及修改信息記錄的主數據。而且可以對條件中的時間段及其數量等級中的金額進行批導及修改。可以根據自己的實際需求進行修改。這就很棒,就很nice!!!

report zme11_12 no standard page HEADING.
type-POOLS:truxs,icon.
tables sscrfields.

data:begin of it_fname occurs 0,
  name type char255,
end of it_fname.

data:bdcdata like bdcdata    occurs 0 with header line.  "用來存儲屏幕字段參數值,傳遞錄屏參數
data:messtab like bdcmsgcoll occurs 0 with header line.  "記錄執行BDC過程中產生的消息
data:result_mesg type table of string with header line.  "結果信息

data: ti_bapicondct like standard table of bapicondct with header line ,
      ti_bapicondhd like standard table of bapicondhd with header line ,
      ti_bapicondit like standard table of bapicondit with header line ,
      ti_bapicondqs like standard table of bapicondqs with header line ,
      ti_bapicondvs like standard table of bapicondvs with header line,
      bapiret2 like standard table of bapiret2 with header line,
      to_bapiknumhs like standard table of bapiknumhs with header line,
      to_mem_initial like standard table of cnd_mem_initial with header line,
      ls_a017 type a017.

data text2 type text1_007s. "附加稅值名
data p type i.

types:begin of ty_tab1,
  flag type c,                "記錄標識
  wx type c,                  "是否外協
  eina_mahn1 type mahn1,      "CLX
  eina_urztp type urztp,      "價格執行方式
  eina_urzzt type urzzt,      "編號
  eine_norbm type norbm,      "標准數量
  eine_mwskz type mwskz,      "稅代碼
  eine_netpr type iprei,      "凈價
  eine_waers type waers,      "凈價貨幣
  eine_angnr type angnr,      "報價
  eine_peinh type epein,      "價格單位
*  rm06i_ltex1 TYPE ltext,     "記錄信息文本
  rv13a_datab type kodatab,   "有效時間從
  rv13a_datbi type kodatbi,   "有效時間到
*  konp_konwa TYPE konwa,      "PB00比率單位(貨幣或百分數)
  konp_kschl2 type kscha,                                   "條件類型2
  konm_kbetr2 type konp-kbetr,                              "條件金額2
  konp_konwa2 type konwa,        "ZVA1比率單位(貨幣或百分數)
  eina_lifnr type elifn,      "供應商
  eina_matnr  type matnr,     "材料
  eine_ekorg type ekorg,      "采購組織
  eine_werks type ewerk,      "工廠
  konm_kstbm type kstbm,                                   "條件等級數量
  konm_kbetr type konp-kbetr,                                "條件金額
end of ty_tab1.
data:gt_tab1 type table of ty_tab1,
      wa_tab1 type ty_tab1.

types:begin of numb_levels,
  flag type c,                "記錄標識
  eina_lifnr type elifn,      "供應商
  eina_matnr  type matnr,     "材料
  eine_ekorg type ekorg,      "采購組織
  eine_werks type ewerk,      "工廠
  konm_kstbm type kstbm,     "條件等級數量
  konm_kbetr type kbetr,     "條件金額
  lifab      type eina-lifab,   "起始時間
  lifbi      type eina-lifbi,   "截止時間
end of numb_levels.
data:gt_nl type table of numb_levels,
      wa_nl type numb_levels.


types:begin of ty_tab2,
  flag    type c,                "記錄標識
  wx      type c,                  "是否外協
  lifnr   type lfa1-lifnr,
  matnr   type mara-matnr,
  ekorg   type eine-ekorg,
  werks   type eine-werks,
  netpr   type iprei,                                       "PB00金額
  konp_konwa  type konwa,         "比率單位(貨幣或百分數)
  peinh       like eine-peinh,          "價格單位
  konp_kschl2 type kscha,                                   "條件類型2
  konp_kbetr2 type kbetr_kond,    "金額2
  konp_konwa2 type konwa,        "比率單位(貨幣或百分數)
  lifab       type eina-lifab,   "起始時間
  lifbi       type eina-lifbi,   "截止時間
  konm_kstbm  type kstbm,                                   "條件等級數量
  konm_kbetr  type kbetr,                                   "條件金額
end of ty_tab2.
data:gt_tab2 type table of  ty_tab2,
      wa_tab2 type ty_tab2.

data: aplfzc(3) type c,     "計划交貨天數
      normbc(16) type c ,   "標准數量
      netprc(13) type c,    "凈價
      peinhc(5) type c,     "條件定價單位
      lv_bprme type bprme.  "條件單位

SELECTION-screen begin of block blk_001 with frame title text-001 .
  parameters:p_file like rlgrap-filename.
SELECTION-screen end of block blk_001.
SELECTION-screen begin of block blk_002 with frame title text-002.  "創建或修改
  parameters:radio_1 radiobutton group radi,    "創建
  radio_2 radiobutton group radi.               "修改
SELECTION-screen end of block blk_002.

SELECTION-screen function key 1. "應用工具欄增加按鈕

initialization.
write icon_change_text as icon to sscrfields-functxt_01+0(4).
sscrfields-functxt_01+4(*) = '下載模板'."分配字符位置

at SELECTION-screen.
perform dl_template.   "模板下載


at SELECTION-screen on value-REQUEST for p_file  .
perform open.

START-of-SELECTION.
if radio_1 = 'X'.
  perform upload_file1.
  perform process_file1.
  perform create_me11.
else.
  perform upload_file2.
  perform process_file2.
  perform update_me12.
endif.

end-of-SELECTION.
perform result_message.   "顯示執行結果

*&---------------------------------------------------------------------*
*&      Form  create_me11
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form create_me11.
  loop at gt_tab1 into wa_tab1 where flag = 'X'.
    clear: aplfzc,normbc,netprc,peinhc.
    aplfzc = wa_tab1-eina_mahn1.
    normbc = wa_tab1-eine_norbm.
    netprc = wa_tab1-eine_netpr. "凈價
    peinhc = wa_tab1-eine_peinh.
    condense aplfzc no-GAPS.
    condense normbc no-GAPS.
    condense netprc no-GAPS.
    condense peinhc no-GAPS.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input  = wa_tab1-eina_matnr
    importing
      output = wa_tab1-eina_matnr.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input  = wa_tab1-eina_lifnr
    importing
      output = wa_tab1-eina_lifnr.

    select single waers from lfm1 into wa_tab1-eine_waers where lifnr = wa_tab1-eina_lifnr and ekorg = wa_tab1-eine_ekorg.

    if wa_tab1-eine_waers = 'USD'.
      wa_tab1-eine_mwskz = 'J0'.
  elseif wa_tab1-eine_waers = 'CNY'.
      wa_tab1-eine_mwskz = 'J6'.
    endif.

    select single t007s~text1 into text2 from t007s where t007s~mwskz = wa_tab1-eine_mwskz and t007s~spras = sy-langu and t007s~kalsm = 'TAXCN'.  "附加稅值名
    if text2+1(1) = '%'.
      p = text2+0(1).
    else.
      p = text2+0(2).
    endif.

    netprc = netprc * ( 1 + ( p / 100 ) ).  "增值稅
    condense netprc no-GAPS.

    clear: bdcdata,bdcdata[] .
    perform bdc_dynpro      using 'SAPMM06I'    '0100'.
    perform bdc_field       using 'BDC_CURSOR'  'EINE-WERKS'.
    perform bdc_field       using 'BDC_OKCODE'  '/00'.
    perform bdc_field       using 'EINA-LIFNR'  wa_tab1-eina_lifnr."供應商
    perform bdc_field       using 'EINA-MATNR'  wa_tab1-eina_matnr. "材料
    perform bdc_field       using 'EINE-EKORG'  wa_tab1-eine_ekorg. "采購組織
    perform bdc_field       using 'EINE-WERKS'  wa_tab1-eine_werks. "工廠
    if wa_tab1-wx = 'X'.
      perform bdc_field       using 'RM06I-LOHNB'            'X'.
    else.
      perform bdc_field       using 'RM06I-NORMB'            'X'.
    endif.

    perform bdc_dynpro      using 'SAPMM06I'    '0101'.
    perform bdc_field       using 'BDC_CURSOR'  'EINA-URZZT'.
    perform bdc_field       using 'BDC_OKCODE'  '/00'.
    perform bdc_field       using 'EINA-MAHN1'  aplfzc.    "CLX
    perform bdc_field       using 'EINA-URZTP'  wa_tab1-eina_urztp.    "價格執行方式
    perform bdc_field       using 'EINA-URZZT'  wa_tab1-eina_urzzt.    "編號

    perform bdc_dynpro      using 'SAPMM06I'      '0102'.
    perform bdc_field       using 'BDC_CURSOR'    'EINE-MWSKZ'.
    perform bdc_field       using 'BDC_OKCODE'    '=KO'.  "/00
    perform bdc_field       using 'EINE-NORBM'    normbc.  "標准數量
    perform bdc_field       using 'EINE-MWSKZ'    wa_tab1-eine_mwskz. "稅代碼
    perform bdc_field       using 'EINE-NETPR'    netprc.    "凈價
    perform bdc_field       using 'EINE-WAERS'    wa_tab1-eine_waers.    "凈價貨幣

    perform bdc_dynpro      using 'SAPMV13A'      '0201'.
    perform bdc_field       using 'BDC_CURSOR'    'RV13A-DATBI'.
    perform bdc_field       using 'BDC_OKCODE'    '=BACK'.
    perform bdc_field       using 'RV13A-DATAB'    wa_tab1-rv13a_datab. "開始時間
    perform bdc_field       using 'RV13A-DATBI'    wa_tab1-rv13a_datbi. "結束時間
    perform bdc_field       using 'KONP-KPEIN(01)' peinhc.             "單位


    perform bdc_dynpro      using 'SAPMM06I'      '0102'.
    perform bdc_field       using 'BDC_CURSOR'    'EINE-APLFZ'.
    perform bdc_field       using 'BDC_OKCODE'    '/00'.  "/00
    perform bdc_field       using 'EINE-NORBM'    normbc.  "標准數量
    perform bdc_field       using 'EINE-MWSKZ'    wa_tab1-eine_mwskz. "稅代碼
    perform bdc_field       using 'EINE-NETPR'    netprc.    "凈價

    perform bdc_dynpro      using 'SAPMM06I'        '0105'.
    perform bdc_field       using 'BDC_CURSOR'      'EINE-ANGNR'.
    perform bdc_field       using 'BDC_OKCODE'      '/00'.
    perform bdc_field       using 'EINE-ANGNR'       wa_tab1-eine_angnr.  "報價

    perform bdc_dynpro      using 'SAPMM06I'        '0103'.
    perform bdc_field       using 'BDC_CURSOR'      'RM06I-LTEX1(01)'.
    perform bdc_field       using 'BDC_OKCODE'      '=BU'.
*    PERFORM bdc_field       USING 'RM06I-LTEX1(01)' wa_tab1-rm06i_ltex1.  "記錄信息

    call transaction 'ME11' using bdcdata mode 'N' update 'S' MESSAGES into messtab.
    read table messtab with key msgtyp = 'E'.
    if sy-subrc = 0.
      loop at messtab where msgtyp = 'E'.
        call function 'MESSAGE_TEXT_BUILD'  "消息編號及變量使用函數轉換為消息內容輸出
        exporting
          msgid                    = messtab-msgid
          msgnr                    = messtab-msgnr
          msgv1                     = messtab-msgv1
          msgv2                     = messtab-msgv2
          msgv3                     = messtab-msgv3
          msgv4                     = messtab-msgv4
        importing
          message_text_output       = result_mesg.
      endloop.
      append result_mesg.
      clear result_mesg.
    else.
      perform condition using wa_tab1.
    endif.

  endloop.
endform.                    "create_me11


*&---------------------------------------------------------------------*
*&      Form  CONDITION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_wa_tab1  text
*----------------------------------------------------------------------*
form condition  using  value(lt_tab) type ty_tab1.
  data num type n LENGTH 4.   "數量等級行號
  clear:ti_bapicondct[],ti_bapicondct,ti_bapicondhd[],ti_bapicondhd,ti_bapicondit[],ti_bapicondit,ti_bapicondqs[],ti_bapicondqs,lv_bprme.
  data esokzc type c.
  if lt_tab-wx = 'X'.
    esokzc = '3'.
  else.
    esokzc = '0'.
  endif.
  select single * into CORRESPONDING fields of ls_a017
  from a017 where  kschl = 'PB00'   "條件類型             "kappl = 'M' "應用:M采購
  and lifnr = lt_tab-eina_lifnr     "供應商帳戶號
  and matnr = lt_tab-eina_matnr     "物料
  and ekorg = lt_tab-eine_ekorg     "采購組織
  and werks = lt_tab-eine_werks     "工廠
  and esokz = esokzc.                    "采購信息記錄分類-(0:標准   3:分包合同)
  clear esokzc.

  select single kmein into lv_bprme from konp where knumh = ls_a017-knumh.      "konp:條件(項目)      kmein:條件單位

  ti_bapicondct-operation = '004' . "004修改  _009創建
  ti_bapicondct-cond_usage = 'A'.   "條件表用途:定價
  ti_bapicondct-table_no = '017' .  "條件表
  ti_bapicondct-applicatio = 'M' .
  ti_bapicondct-cond_type = 'PB00' .
  ti_bapicondct-valid_to = lt_tab-rv13a_datbi.    "條件記錄有效截止日期
  ti_bapicondct-valid_from = lt_tab-rv13a_datab. "條件記錄有效起始日
  ti_bapicondct-cond_no = ls_a017-knumh . "條件記錄號
  append ti_bapicondct .
  clear ti_bapicondct .

*KONH的BAPI結構----條件( 抬頭 )
  ti_bapicondhd-operation = '004' .
  ti_bapicondhd-cond_no = ls_a017-knumh . "條件記錄號
  ti_bapicondhd-created_by = sy-uname.    "創建對象的人員名稱
  ti_bapicondhd-creat_date = sy-datum.    "記錄的創建日期
  ti_bapicondhd-cond_usage = 'A' .
  ti_bapicondhd-table_no = ' 017' .
  ti_bapicondhd-applicatio = 'M' .
  ti_bapicondhd-cond_type = ' PB00' .
  ti_bapicondhd-valid_from = lt_tab-rv13a_datbi.
  ti_bapicondhd-valid_to = lt_tab-rv13a_datab.
  append ti_bapicondhd.
  clear ti_bapicondhd.

*KONP的BAPI結構
  ti_bapicondit-operation = '004' .
  ti_bapicondit-cond_no = ls_a017-knumh.
  ti_bapicondit-cond_count = '01' .           "條件的序列號
  ti_bapicondit-applicatio = 'M' .
  ti_bapicondit-cond_type = 'PB00' .
  ti_bapicondit-scaletype = 'A' .
  ti_bapicondit-scalebasin = 'C' .            "等級基值指示符,數量規模
  ti_bapicondit-scale_qty = 1 .               "條件等級數量
  ti_bapicondit-calctypcon = 'C' .            "條件計算類型--- C:數量  A:百分比
  ti_bapicondit-cond_value = netprc.          "BAPIs 的貨幣金額(帶有 9 個小數位)-凈價
  ti_bapicondit-condcurr = lt_tab-eine_waers. "比率單位(貨幣或百分數):CNY
  ti_bapicondit-cond_p_unt = peinhc.          "條件定價單位(單位=1)
  ti_bapicondit-cond_unit = lv_bprme.         "條件單位(EA)
  ti_bapicondit-condcurren = lt_tab-eine_waers.
  ti_bapicondit-unitmeasur = lv_bprme.         "條件等級計量單位
  append ti_bapicondit.
  clear ti_bapicondit.

  call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
  exporting
    input  = lt_tab-eina_lifnr
  importing
    output = lt_tab-eina_lifnr.
  call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
  exporting
    input  = lt_tab-eina_matnr
  importing
    output = lt_tab-eina_matnr.
*PB00--->設置等級數量
  loop at gt_nl into wa_nl where  konm_kbetr > 0.           "數量等級金額>0
    if lt_tab-eina_lifnr = wa_nl-eina_lifnr and lt_tab-eina_matnr = wa_nl-eina_matnr and lt_tab-eine_ekorg = wa_nl-eine_ekorg and lt_tab-eine_werks = wa_nl-eine_werks.
      num = num + 1.
      ti_bapicondqs-operation = '004' .
      ti_bapicondqs-cond_no = ls_a017-knumh.
      ti_bapicondqs-cond_count = '01' .
      ti_bapicondqs-line_no = num.
      ti_bapicondqs-scale_qty = wa_nl-konm_kstbm.   "條件等級數量
      ti_bapicondqs-cond_unit = lv_bprme.           "條件單位
      ti_bapicondqs-currency = wa_nl-konm_kbetr.    "BAPIs 的貨幣金額(帶有 9 個小數位)
      ti_bapicondqs-condcurr = lt_tab-eine_waers.   "比率單位(貨幣或百分數)
      append ti_bapicondqs .
      clear ti_bapicondqs .
    endif.
  endloop.
  clear num.

  if lt_tab-eine_waers = 'CNY'.
*如果貨幣單位為CNY,添加ZVA1類型
    ti_bapicondit-operation = '004' .
    ti_bapicondit-cond_no = ls_a017-knumh.
    ti_bapicondit-cond_count = '02'.                        "條件的序列號
    ti_bapicondit-applicatio = 'M'.
    ti_bapicondit-cond_type = 'ZVA1'.                       "類型2:ZVA1
    ti_bapicondit-scaletype = 'A'.                          "A基礎等級
    ti_bapicondit-scalebasin = 'C' .                        "等級基值指示符,數量規模
    ti_bapicondit-scale_qty = '2'.                          "條件等級數量
    ti_bapicondit-calctypcon = 'A' .                        "條件計算類型--- C:數量  A:百分比
    if lt_tab-konm_kbetr2 <> 0 or lt_tab-konm_kbetr2 <> ''.
      ti_bapicondit-cond_value = lt_tab-konm_kbetr2.        "BAPIs 的貨幣金額(帶有 9 個小數位)-(-5%)konm_kbetr2
    endif.
    ti_bapicondit-condcurr = lt_tab-konp_konwa2.            "比率單位(貨幣或百分數):CNY
    ti_bapicondit-cond_unit = lt_tab-konp_konwa2.           "條件單位
    ti_bapicondit-cond_unit = lv_bprme.
    ti_bapicondit-unitmeasur = lv_bprme.                    "條件等級計量單位
    append ti_bapicondit.
    clear ti_bapicondit.
*ZVA1--->設置等級數量
    loop at gt_nl into wa_nl where  konm_kbetr < 0.         "數量等級金額>0
      if lt_tab-eina_lifnr = wa_nl-eina_lifnr and lt_tab-eina_matnr = wa_nl-eina_matnr and lt_tab-eine_ekorg = wa_nl-eine_ekorg and lt_tab-eine_werks = wa_nl-eine_werks.
        num = num + 1.
        ti_bapicondqs-operation = '004' .
        ti_bapicondqs-cond_no = ls_a017-knumh.
        ti_bapicondqs-cond_count = '02' .
        ti_bapicondqs-line_no = num.
        ti_bapicondqs-scale_qty = wa_nl-konm_kstbm. "條件等級數量
        ti_bapicondqs-cond_unit = lv_bprme.           "條件單位
        ti_bapicondqs-currency = wa_nl-konm_kbetr.  "BAPIs 的貨幣金額(帶有 9 個小數位)
        ti_bapicondqs-condcurr = lt_tab-konp_konwa2.   "比率單位(貨幣或百分數)
        append ti_bapicondqs .
        clear ti_bapicondqs .
      endif.
    endloop.
    clear num.
  endif.

  call function 'BAPI_PRICES_CONDITIONS'
  tables
    ti_bapicondct  = ti_bapicondct
    ti_bapicondhd  = ti_bapicondhd
    ti_bapicondit  = ti_bapicondit
    ti_bapicondqs  = ti_bapicondqs
    ti_bapicondvs  = ti_bapicondvs
    to_bapiret2    = bapiret2
    to_bapiknumhs  = to_bapiknumhs
    to_mem_initial = to_mem_initial
  exceptions
    update_error   = 1
    others         = 2.
  if sy-subrc = 0.
    data gv_infnr type infnr.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input         = lt_tab-eina_lifnr
    importing
      output        = lt_tab-eina_lifnr.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input         = lt_tab-eina_matnr
    importing
      output        = lt_tab-eina_matnr.
    select single infnr into gv_infnr from eina where matnr = lt_tab-eina_matnr and lifnr = lt_tab-eina_lifnr.
    concatenate gv_infnr ' 信息記錄已創建!' into result_mesg.
    append result_mesg.
    clear result_mesg.
    else.
    call function 'BAPI_TRANSACTION_ROLLBACK'.
    result_mesg = '操作錯誤!'.
    append result_mesg.
    clear:gv_infnr,result_mesg.
  endif.
endform.                    " CONDITION
*&---------------------------------------------------------------------*
*&      Form  UPLOAD_FILE2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form upload_file2 .
  data: it_raw_data type truxs_t_text_data.
  field-SYMBOLS <fs> type ty_tab2.
  field-SYMBOLS:<fw>.
  data: i_excel type table of alsmex_tabline,"表格結構。"
        w_excel type alsmex_tabline.
  data:num_col type i.
  refresh: gt_tab2.
  "調用此函數,將Excel中的內容以類似坐標的形式存儲到I_excel內表中。"
  call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  exporting
    filename                = p_file
    i_begin_col             = 1
    i_begin_row             = 1
    i_end_col               = 55       "控制傳入字段個數
    i_end_row               = 2500
  tables
    intern                  = i_excel
  exceptions
    inconsistent_parameters = 1
    upload_ole              = 2
    others                  = 3.
  delete i_excel where row = 1.        "刪除第一行文本抬頭。
  if i_excel is initial.
    call function 'POPUP_TO_CONFIRM_WITH_MESSAGE'
    exporting
*     DEFAULTOPTION        = 'Y'
      diagnosetext1        = '數據錯誤'
*     DIAGNOSETEXT2        = ' '
*     DIAGNOSETEXT3        = ' '
      textline1            =  'Excel表格中沒有內容!'
      titel                = '提示' .
    return.
  endif.
  sort i_excel by row col.

  loop at i_excel into w_excel.
    num_col = w_excel-col.
    assign component  num_col  of structure wa_tab2 to <fw>.
    <fw> = w_excel-value.
    at end of row.
      append wa_tab2 to gt_tab2.
      clear:wa_tab2.
    endat.
    clear:w_excel.
  endloop.
endform.                    " UPLOAD_FILE2
*&---------------------------------------------------------------------*
*&      Form  UPDATE_ME12
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form update_me12.
  loop at gt_tab2 into wa_tab2 where flag = 'X'.
    clear: aplfzc,normbc,netprc,peinhc.
*    aplfzc = wa_tab2-aplfz.
*    normbc = wa_tab2-eine_norbm."標准數量
*    netprc = wa_tab2-netpr.
    peinhc = wa_tab2-peinh.
*    CONDENSE aplfzc NO-GAPS.
**    Condense normbc No-GAPS.
*    CONDENSE netprc NO-GAPS.
    condense peinhc no-GAPS.

    call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input  = wa_tab2-matnr
    importing
      output = wa_tab2-matnr.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input  = wa_tab2-lifnr
    importing
      output = wa_tab2-lifnr.

    netprc = wa_tab2-netpr.
    condense netprc no-GAPS.

    clear bdcdata[].
    perform bdc_dynpro      using 'SAPMM06I' '0100'.
    perform bdc_field       using 'BDC_CURSOR'          'EINE-WERKS'.
    perform bdc_field       using 'BDC_OKCODE'          '/00'.
    perform bdc_field       using 'EINA-LIFNR'          wa_tab2-lifnr.
    perform bdc_field       using 'EINA-MATNR'          wa_tab2-matnr.
    perform bdc_field       using 'EINE-EKORG'          wa_tab2-ekorg.
    perform bdc_field       using 'EINE-WERKS'          wa_tab2-werks.
    if wa_tab2-wx = 'X'.
      perform bdc_field       using 'RM06I-LOHNB'            'X'.
    else.
      perform bdc_field       using 'RM06I-NORMB'            'X'.
    endif.

    perform bdc_dynpro      using 'SAPMM06I' '0101'.
    perform bdc_field       using 'BDC_OKCODE'          '=EINE'.

    perform bdc_dynpro      using 'SAPMM06I' '0102'.
    perform bdc_field       using 'BDC_CURSOR'          'EINE-MWSKZ'.
    perform bdc_field       using 'BDC_OKCODE'          '/00'.

    perform bdc_dynpro      using 'SAPMM06I' '0105'.
    perform bdc_field       using 'BDC_CURSOR'          'EINE-ANGNR'.
    perform bdc_field       using 'BDC_OKCODE'          '=KO'.

    perform bdc_dynpro      using 'SAPLV14A' '0102'.
    perform bdc_field       using 'BDC_CURSOR'          'VAKE-DATAB(01)'.
    perform bdc_field       using 'BDC_OKCODE'          '=NEWD'.

    perform bdc_dynpro      using 'SAPMV13A' '0201'.
    perform bdc_field       using 'BDC_CURSOR'          'KONP-KBETR(01)'.
    perform bdc_field       using 'BDC_OKCODE'          '=SICH'.
    perform bdc_field       using 'RV13A-DATAB'          wa_tab2-lifab.
    perform bdc_field       using 'RV13A-DATBI'          wa_tab2-lifbi.
    perform bdc_field       using 'KONP-KBETR(01)'       netprc.

    call transaction 'ME12' using bdcdata
          mode   'N'
          update 'S'
          MESSAGES into messtab.
    read table messtab with key msgtyp = 'E'.
    if sy-subrc = 0.
      loop at messtab where msgtyp = 'E'.
        call function 'MESSAGE_TEXT_BUILD'  "消息編號及變量使用函數轉換為消息內容輸出
        exporting
          msgid                    = messtab-msgid
          msgnr                    = messtab-msgnr
          msgv1                     = messtab-msgv1
          msgv2                     = messtab-msgv2
          msgv3                     = messtab-msgv3
          msgv4                     = messtab-msgv4
        importing
          message_text_output       = result_mesg.
      endloop.
      append result_mesg.
      clear result_mesg.
    else.
      perform condition2 using wa_tab2.  "更新數量等級
    endif.
  endloop.
endform.                    "UPDATE_ME12

*&---------------------------------------------------------------------*
*&      Form  condition2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->LT_TAB     text
*----------------------------------------------------------------------*
form condition2  using  value(lt_tab) type ty_tab2.
  data num type n LENGTH 4.   "數量等級行號
  clear:ti_bapicondct[],ti_bapicondct,ti_bapicondhd[],ti_bapicondhd,ti_bapicondit[],ti_bapicondit,ti_bapicondqs[],ti_bapicondqs,lv_bprme,num.
  data esokzc type c.
  if lt_tab-wx = 'X'.
    esokzc = '3'.
  else.
    esokzc = '0'.
  endif.
  select single * into CORRESPONDING fields of ls_a017
  from a017 where  kschl = 'PB00'   "條件類型
  and lifnr = lt_tab-lifnr     "供應商帳戶號
  and matnr = lt_tab-matnr     "物料
  and ekorg = lt_tab-ekorg     "采購組織
  and werks = lt_tab-werks     "工廠
  and datab = lt_tab-lifab     "起始時間
  and datbi = lt_tab-lifbi     "截止時間
  and esokz = esokzc.               "采購信息記錄分類-(0:標准   3:分包合同)
  clear esokzc.

  select single kmein into lv_bprme  from konp where knumh = ls_a017-knumh.      "konp:條件(項目)      kmein:

  ti_bapicondct-operation = '004' . "004修改  _009創建
  ti_bapicondct-cond_usage = 'A'.   "條件表用途:定價
  ti_bapicondct-table_no = '017' .  "條件表
  ti_bapicondct-applicatio = 'M' .
  ti_bapicondct-cond_type = 'PB00' .
  ti_bapicondct-valid_from = lt_tab-lifab. "條件記錄有效起始日
  ti_bapicondct-valid_to = lt_tab-lifbi.    "條件記錄有效截止日期
  ti_bapicondct-cond_no = ls_a017-knumh . "條件記錄號
  append ti_bapicondct .
  clear ti_bapicondct .

*KONH的BAPI結構----條件( 抬頭 )
  ti_bapicondhd-operation = '004' .
  ti_bapicondhd-cond_no = ls_a017-knumh . "條件記錄號
  ti_bapicondhd-created_by = sy-uname.    "創建對象的人員名稱
  ti_bapicondhd-creat_date = sy-datum.    "記錄的創建日期
  ti_bapicondhd-cond_usage = 'A' .
  ti_bapicondhd-table_no = ' 017' .
  ti_bapicondhd-applicatio = 'M' .
  ti_bapicondhd-cond_type = ' PB00' .
  ti_bapicondhd-valid_from = lt_tab-lifab.
  ti_bapicondhd-valid_to = lt_tab-lifbi.
  append ti_bapicondhd .
  clear ti_bapicondhd .

*KONP的BAPI結構
  ti_bapicondit-operation = '004' .
  ti_bapicondit-cond_no = ls_a017-knumh.
  ti_bapicondit-cond_count = '01' .           "條件的序列號
  ti_bapicondit-applicatio = 'M' .
  ti_bapicondit-cond_type = 'PB00' .
  ti_bapicondit-scaletype = 'A' .
  ti_bapicondit-scalebasin = 'C' .            "等級基值指示符,數量規模
  ti_bapicondit-scale_qty = 1 .               "條件等級數量
  ti_bapicondit-calctypcon = 'C' .            "條件計算類型--- C:數量  A:百分比
  ti_bapicondit-cond_value = netprc.          "BAPIs 的貨幣金額(帶有 9 個小數位)-凈價
  ti_bapicondit-condcurr = lt_tab-konp_konwa. "比率單位(貨幣或百分數):CNY
  ti_bapicondit-cond_p_unt = peinhc.          "條件定價單位(單位=1)
  ti_bapicondit-cond_unit = lv_bprme.         "條件單位
  ti_bapicondit-condcurren = lt_tab-konp_konwa.
  ti_bapicondit-unitmeasur = lv_bprme.         "條件等級計量單位
  append ti_bapicondit.
  clear ti_bapicondit.
*PB00--->設置等級數量
  loop at gt_nl into wa_nl where  konm_kbetr > 0.           "數量等級金額>0
    if lt_tab-lifab = wa_nl-lifab and lt_tab-lifbi = wa_nl-lifbi.
      num = num + 1.
      ti_bapicondqs-operation = '004' .
      ti_bapicondqs-cond_no = ls_a017-knumh.
      ti_bapicondqs-cond_count = '01' .
      ti_bapicondqs-line_no = num.
      ti_bapicondqs-scale_qty = wa_nl-konm_kstbm.   "條件等級數量
      ti_bapicondqs-cond_unit = lv_bprme.           "條件單位
      ti_bapicondqs-currency = wa_nl-konm_kbetr.    "BAPIs 的貨幣金額(帶有 9 個小數位)
      ti_bapicondqs-condcurr = lt_tab-konp_konwa.   "比率單位(貨幣或百分數)
      append ti_bapicondqs .
      clear ti_bapicondqs .
    endif.
  endloop.
  clear num.

  if lt_tab-konp_konwa = 'CNY'.
*如果貨幣單位為CNY,添加ZVA1類型
    ti_bapicondit-operation = '004' .
    ti_bapicondit-cond_no = ls_a017-knumh.
    ti_bapicondit-cond_count = '02'.                        "條件的序列號
    ti_bapicondit-applicatio = 'M'.
    ti_bapicondit-cond_type = lt_tab-konp_kschl2.           "進項稅扣除ZVA1
    ti_bapicondit-scaletype = 'A'.                          "A基礎等級
    ti_bapicondit-scalebasin = 'C' .                        "等級基值指示符,數量規模
    ti_bapicondit-scale_qty = '2'.                          "條件等級數量
    ti_bapicondit-calctypcon = 'A' .                        "條件計算類型--- C:數量  A:百分比
    if lt_tab-konp_kbetr2 <> 0 or lt_tab-konp_kbetr2 <> ''.
      ti_bapicondit-cond_value = lt_tab-konp_kbetr2.        "BAPIs 的貨幣金額(帶有 9 個小數位)-(-5%)konm_kbetr2
    endif.
    ti_bapicondit-condcurr = lt_tab-konp_konwa2.            "比率單位(貨幣或百分數):CNY
    ti_bapicondit-cond_unit = lt_tab-konp_konwa2.           "條件單位
    ti_bapicondit-cond_unit = lv_bprme.
    ti_bapicondit-unitmeasur = lv_bprme.                    "條件等級計量單位
    append ti_bapicondit.
    clear ti_bapicondit.
*ZVA1--->設置等級數量
    loop at gt_nl into wa_nl where  konm_kbetr < 0.         "數量等級金額>0
      if lt_tab-lifab = wa_nl-lifab and lt_tab-lifbi = wa_nl-lifbi.
        num = num + 1.
        ti_bapicondqs-operation = '004' .
        ti_bapicondqs-cond_no = ls_a017-knumh.
        ti_bapicondqs-cond_count = '02' .
        ti_bapicondqs-line_no = num.
        ti_bapicondqs-scale_qty = wa_nl-konm_kstbm.   "條件等級數量
        ti_bapicondqs-cond_unit = lv_bprme.           "條件單位
        ti_bapicondqs-currency = wa_nl-konm_kbetr.    "BAPIs 的貨幣金額(帶有 9 個小數位)
        ti_bapicondqs-condcurr = lt_tab-konp_konwa2.  "比率單位(貨幣或百分數)
        append ti_bapicondqs .
        clear ti_bapicondqs .
      endif.
    endloop.
    clear num.
  endif.
  call function 'BAPI_PRICES_CONDITIONS'
  tables
    ti_bapicondct  = ti_bapicondct
    ti_bapicondhd  = ti_bapicondhd
    ti_bapicondit  = ti_bapicondit
    ti_bapicondqs  = ti_bapicondqs
    ti_bapicondvs  = ti_bapicondvs
    to_bapiret2    = bapiret2
    to_bapiknumhs  = to_bapiknumhs
    to_mem_initial = to_mem_initial
  exceptions
    update_error   = 1
    others         = 2.
  if sy-subrc = 0.
    concatenate '物料' lt_tab-matnr ' 已創建有效期 ' lt_tab-lifab '-' lt_tab-lifbi   into result_mesg.
    append result_mesg.
    clear result_mesg.
  else.
    call function 'BAPI_TRANSACTION_ROLLBACK'.
    result_mesg = '操作錯誤!'.
    append result_mesg.
    clear result_mesg.
  endif.
endform.                    " CONDITION
*&---------------------------------------------------------------------*
*&      Form  PROCESS_FILE1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form process_file1 .
  loop at gt_tab1 into wa_tab1.
    wa_nl-flag = wa_tab1-flag.
    wa_nl-eina_lifnr = wa_tab1-eina_lifnr.      "供應商
    wa_nl-eina_matnr = wa_tab1-eina_matnr.     "材料
    wa_nl-eine_ekorg = wa_tab1-eine_ekorg.      "采購組織
    wa_nl-eine_werks = wa_tab1-eine_werks.     "工廠
    wa_nl-konm_kstbm = wa_tab1-konm_kstbm.
    wa_nl-konm_kbetr = wa_tab1-konm_kbetr.
    append wa_nl to gt_nl.
  endloop.
endform.                    " PROCESS_FILE1

*&---------------------------------------------------------------------*
*&      Form  process_file2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form process_file2 .
  loop at gt_tab2 into wa_tab2.
    wa_nl-flag = wa_tab1-flag.
    wa_nl-lifab = wa_tab2-lifab.   "起始時間
    wa_nl-lifbi = wa_tab2-lifbi.   "截止時間
    wa_nl-konm_kstbm = wa_tab2-konm_kstbm.
    wa_nl-konm_kbetr = wa_tab2-konm_kbetr.
    append wa_nl to gt_nl.
  endloop.
endform.                    "process_file2

*&---------------------------------------------------------------------*
*&      Form  bdc_dynpro
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->VALUE(PROGRAM)  text
*      -->VALUE(DYNPRO)   text
*----------------------------------------------------------------------*
form bdc_dynpro using value(program) value(dynpro).
  clear bdcdata.
  bdcdata-program  = program.
  bdcdata-dynpro   = dynpro.
  bdcdata-dynbegin = 'X'.
  append bdcdata.
endform.                    "BDC_DYNPRO

*&---------------------------------------------------------------------*
*&      Form  bdc_field
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->VALUE(FNAM)  text
*      -->VALUE(FVAL)  text
*----------------------------------------------------------------------*
form bdc_field using value(fnam) value(fval).
  clear bdcdata.
  bdcdata-fnam = fnam.
  bdcdata-fval = fval.
  append bdcdata.
endform.                    "bdc_field
*&---------------------------------------------------------------------*
*&      Form  OPEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form open .
  call function 'KD_GET_FILENAME_ON_F4'
  exporting
    program_name  = syst-repid
    dynpro_number = syst-dynnr
    mask          = '*.xlsx,*.xls'
    static        = 'X'
  changing
    file_name     = p_file.
endform.                    " OPEN

*&---------------------------------------------------------------------*
*&      Form  upload_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form upload_file1.
  data: it_raw_data type truxs_t_text_data.
  field-SYMBOLS <fs> type ty_tab1.
  field-SYMBOLS:<fw>.
  data: i_excel type table of zalsmex_tabline,"表格結構。"
        w_excel type zalsmex_tabline.
  data:num_col type i.
  refresh: gt_tab1.
  "調用此函數,將Excel中的內容以類似坐標的形式存儲到I_excel內表中。"
  call function 'ZZALSM_EXCEL_TO_INTERNAL_TABLE'
  exporting
    filename                = p_file
    i_begin_col             = 1
    i_begin_row             = 1
    i_end_col               = 30       "控制傳入字段個數
    i_end_row               = 5000
  tables
    intern                  = i_excel
  exceptions
    inconsistent_parameters = 1
    upload_ole              = 2
    others                  = 3.
  delete i_excel where row = 1.        "刪除第一行文本抬頭。
  if i_excel is initial.
    call function 'POPUP_TO_CONFIRM_WITH_MESSAGE'
    exporting
      diagnosetext1 = '數據錯誤'
      textline1     = 'Excel表格中沒有內容!'
      titel         = '提示'.
    return.
  endif.
  sort i_excel by row col.

  loop at i_excel into w_excel.
    num_col = w_excel-col.
    assign component  num_col  of structure wa_tab1 to <fw>.
    <fw> = w_excel-value.
    at end of row.
      append wa_tab1 to gt_tab1.
      clear:wa_tab1.
    endat.
    clear:w_excel.
  endloop.
endform.                    " UPLOAD_FILE

*&---------------------------------------------------------------------*
*&      Form  result_message
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form result_message.
  clear: aplfzc,normbc,netprc,peinhc.
  clear:ti_bapicondct[],ti_bapicondct,ti_bapicondhd[],ti_bapicondhd,ti_bapicondit[],ti_bapicondit,ti_bapicondqs[],ti_bapicondqs,lv_bprme.
  loop at result_mesg.
    write: / result_mesg.
  endloop.
endform.                    "sub_output_result
*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form dl_template.
  case sscrfields-ucomm.
  when 'FC01'.
    if radio_1 = 'X'.
      perform download_template1. "創建
    else.
      perform download_template2. "修改
    endif.
  endcase.
endform.                    " DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD_TEMPLATE1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form download_template1 .
  data lv_file like rlgrap-filename.
  data lv_string type string.

  call function 'KD_GET_FILENAME_ON_F4'
  exporting
*     PROGRAM_NAME        = SYST-REPID
*     DYNPRO_NUMBER       = SYST-DYNNR
*     field_name          = lv_string
    static              = 'X'
    mask                = ',EXCEL,*.xls.'
*     FILEOPERATION       = 'R'
*     PATH                =
  changing
    file_name           = lv_file.
  clear wa_tab1.
  wa_tab1-flag = 'X'.                 "記錄標識
  wa_tab1-wx = ''.                    "是否外協
  wa_tab1-eina_mahn1 = '20'.          "CLX
  wa_tab1-eina_urztp = '1'.           "價格執行方式
  wa_tab1-eina_urzzt = '111'.         "編號
  wa_tab1-eine_norbm = '10'.          "標准數量
  wa_tab1-eine_mwskz = 'J6'.          "稅代碼
  wa_tab1-eine_netpr = '10'.          "凈價
  wa_tab1-eine_waers = 'CNY'.         "凈價貨幣
  wa_tab1-eine_angnr = '10'.          "報價
  wa_tab1-eine_peinh = '1'.           "價格單位
*  wa_tab1-rm06i_ltex1 = '信息文本'.   "記錄信息文本
  wa_tab1-rv13a_datab = '20190901'.   "有效時間從
  wa_tab1-rv13a_datbi = '20190910'.   "有效時間到
*  wa_tab1-konp_konwa = 'CNY'.         "PB00比率單位(貨幣或百分數)
  wa_tab1-konp_kschl2 = 'ZVA1'.                             "條件類型2
  wa_tab1-konm_kbetr2 = '-5'.                               "條件金額2
  wa_tab1-konp_konwa2 = '%'.          "ZVA1比率單位(貨幣或百分數)
  wa_tab1-eina_lifnr = '101472'.      "供應商
  wa_tab1-eina_matnr  = 'YCL*'.       "材料
  wa_tab1-eine_ekorg = '1000'.        "采購組織
  wa_tab1-eine_werks = '7888'.        "工廠
  wa_tab1-konm_kstbm = '1000'.        "條件等級數量
  wa_tab1-konm_kbetr = '10'.          "條件金額
  append wa_tab1 to gt_tab1.
  clear wa_tab1.
  wa_tab1-eina_lifnr = '101472'.      "供應商
  wa_tab1-eina_matnr  = 'YCL*'.       "材料
  wa_tab1-eine_ekorg = '1000'.        "采購組織
  wa_tab1-eine_werks = '7888'.        "工廠
  wa_tab1-konm_kstbm = '2000'.        "條件等級數量
  wa_tab1-konm_kbetr = '9'.          "條件金額
  append wa_tab1 to gt_tab1.
  clear wa_tab1.
  wa_tab1-eina_lifnr = '101472'.      "供應商
  wa_tab1-eina_matnr  = 'YCL*'.       "材料
  wa_tab1-eine_ekorg = '1000'.        "采購組織
  wa_tab1-eine_werks = '7888'.        "工廠
  wa_tab1-konm_kstbm = '1000'.        "條件等級數量
  wa_tab1-konm_kbetr = '-5'.          "條件金額
  append wa_tab1 to gt_tab1.
  clear wa_tab1.
  wa_tab1-eina_lifnr = '101472'.      "供應商
  wa_tab1-eina_matnr  = 'YCL*'.       "材料
  wa_tab1-eine_ekorg = '1000'.        "采購組織
  wa_tab1-eine_werks = '7888'.        "工廠
  wa_tab1-konm_kstbm = '2000'.        "條件等級數量
  wa_tab1-konm_kbetr = '-4'.          "條件金額
  append wa_tab1 to gt_tab1.
  clear wa_tab1.

  if it_fname is initial.
    perform append_filename using:'新記錄標識',
          '是否外協',
          'CLX',
          '價格執行方式',
          '編號',
          '標准數量',
          '稅代碼',
          '凈價',
          '貨幣',
          '報價',
          '價格單位',
*          '記錄信息文本',
          '開始時間(8位數字)',
          '結束時間(8位數字)',
*          'PB00單位',
          '條件類型2',
          '金額2',
          '單位2',
          '供應商',
          '物料',
          '采購組織',
          '工廠',
          '條件等級數量',
          '條件金額'.
  endif.
  lv_string = lv_file.
  call function 'GUI_DOWNLOAD'
  exporting
*         BIN_FILESIZE                    =
    filename                        = lv_string
*    filetype                       = 'DBF'
    filetype                        = 'DAT'
    append                       = 'X'
    write_field_separator           = 'X'
*    codepage                        = '8400'   "指定寫文件時用的字符集
  tables
    data_tab                        = gt_tab1
    fieldnames                      = it_fname[].
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno into result_mesg
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    append result_mesg.
    clear result_mesg.
  endif.
  clear: wa_tab1,gt_tab1,it_fname[].
endform.                    " DOWNLOAD_TEMPLATE1
*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD_TEMPLATE2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form download_template2 .
  data lv_file like rlgrap-filename.
  data lv_string type string.

  call function 'KD_GET_FILENAME_ON_F4'
  exporting
*     PROGRAM_NAME        = SYST-REPID
*     DYNPRO_NUMBER       = SYST-DYNNR
*     field_name          = lv_string
    static              = 'X'
    mask                = ',EXCEL,*.xls.'
*     FILEOPERATION       = 'R'
*     PATH                =
  changing
    file_name           = lv_file.
  clear wa_tab2.
  wa_tab2-flag = 'X'.                 "記錄標識
  wa_tab2-wx = ''.                    "是否外協
  wa_tab2-lifnr = '101472'.      "供應商
  wa_tab2-matnr  = 'YCL*'.       "材料
  wa_tab2-ekorg = '1000'.        "采購組織
  wa_tab2-werks = '7888'.        "工廠
  wa_tab2-netpr = '20'.                                     "PB00金額
  wa_tab2-konp_konwa = 'CNY'.                               "PB00金額
  wa_tab2-peinh = '1'.           "價格單位
  wa_tab2-konp_kschl2 = 'ZVA1'.                             "條件類型2
  wa_tab2-konp_kbetr2 = '-5'.                               "條件金額2
  wa_tab2-konp_konwa2 = '%'.          "ZVA1比率單位(貨幣或百分數)
  wa_tab2-lifab = '20190901'.   "有效時間從
  wa_tab2-lifbi = '20190910'.   "有效時間到
  wa_tab2-konm_kstbm = '1000'.        "條件等級數量
  wa_tab2-konm_kbetr = '10'.          "條件金額
  append wa_tab2 to gt_tab2.
  clear wa_tab2.
  wa_tab2-lifab = '20190901'.   "有效時間從
  wa_tab2-lifbi = '20190910'.   "有效時間到
  wa_tab2-konm_kstbm = '2000'.        "條件等級數量
  wa_tab2-konm_kbetr = '9'.          "條件金額
  append wa_tab2 to gt_tab2.
  clear wa_tab2.
  wa_tab2-lifab = '20190901'.   "有效時間從
  wa_tab2-lifbi = '20190910'.   "有效時間到
  wa_tab2-konm_kstbm = '1000'.        "條件等級數量
  wa_tab2-konm_kbetr = '-5'.          "條件金額
  append wa_tab2 to gt_tab2.
  clear wa_tab2.
  wa_tab2-lifab = '20190901'.   "有效時間從
  wa_tab2-lifbi = '20190910'.   "有效時間到
  wa_tab2-konm_kstbm = '1000'.        "條件等級數量
  wa_tab2-konm_kbetr = '-4'.          "條件金額
  append wa_tab2 to gt_tab2.
  clear wa_tab2.

  if it_fname is initial.
    perform append_filename using:'新記錄標識',
          '是否外協',
          '供應商',
          '物料',
          '采購組織',
          '工廠',
          'PB00金額',
          '貨幣',
          '單位',
          '條件類型2',
          '百分比',
          '貨幣2',
          '開始時間(8位數字)',
          '結束時間(8位數字)',
          '條件等級數量',
          '條件金額'.
  endif.
  lv_string = lv_file.
  call function 'GUI_DOWNLOAD'
  exporting
*         BIN_FILESIZE                    =
    filename                        = lv_string
*    filetype                       = 'DBF'
    filetype                        = 'DAT'
    append                       = 'X'
    write_field_separator           = 'X'
*    codepage                        = '8400'   "指定寫文件時用的字符集
  tables
    data_tab                        = gt_tab2
    fieldnames                      = it_fname[].
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno into result_mesg
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    append result_mesg.
    clear result_mesg.
  endif.
  clear: wa_tab2,gt_tab2,it_fname[].

endform.                    " DOWNLOAD_TEMPLATE2

*&---------------------------------------------------------------------*
*&      Form  append_filename
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_NAME     text
*----------------------------------------------------------------------*
form append_filename using p_name .
  it_fname-name = p_name.
  append it_fname.
  clear it_fname.
endform.                    "append_filename

對於時間段及其數量等級的創建及修改也是在網上各種找資料,不過對於這個BAPI_PRICES_CONDITIONS函數還是沒有很好的理解。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM