采购信息记录批导BAPI
2021-01-28 12:12
标签:result efault 附加 export tab 日期 名称 select 开始 转自:https://www.cnblogs.com/freeandeasy/p/11810272.html 可以批导创建及修改信息记录的主数据。而且可以对条件中的时间段及其数量等级中的金额进行批导及修改。可以根据自己的实际需求进行修改。这就很棒,就很nice!!! 对于时间段及其数量等级的创建及修改也是在网上各种找资料,不过对于这个BAPI_PRICES_CONDITIONS函数还是没有很好的理解。
作者的话: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
*
*----------------------------------------------------------------------*
form upload_file2 .
data: it_raw_data type truxs_t_text_data.
field-SYMBOLS
上一篇:H5C3-JS