可以批导创建及修改信息记录的主数据。而且可以对条件中的时间段及其数量等级中的金额进行批导及修改。可以根据自己的实际需求进行修改。这就很棒,就很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 * <-- 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
可以批导创建及修改信息记录的主数据。而且可以对条件中的时间段及其数量等级中的金额进行批导及修改。可以根据自己的实际需求进行修改。这就很棒,就很nice!!!