可以批导创建及修改信息记录的主数据。而且可以对条件中的时间段及其数量等级中的金额进行批导及修改。可以根据自己的实际需求进行修改。这就很棒,就很nice!!!
*********************代码功能************************************* *(1) 批量创建信息记录 *(2) 批量修改信息记录及创建信息记录的有效期间和数量等级 ********************************************************************** REPORT zmmr_me11_12 NO STANDARD PAGE HEADING. TYPE-POOLS:truxs,icon. TABLES:eina,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_peinh TYPE epein, "价格单位 eine_waers TYPE waers, "净价货币 eine_angnr TYPE angnr, "报价/目标价 * 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. DATA:gt_tab2 TYPE TABLE OF ty_tab1, wa_tab2 TYPE ty_tab1, temp_tab TYPE TABLE OF ty_tab1 WITH HEADER LINE. 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, "条件金额 rv13a_datab TYPE kodatab, "有效时间从 rv13a_datbi TYPE kodatbi, "有效时间到 END OF numb_levels. DATA:gt_nl TYPE TABLE OF numb_levels, wa_nl TYPE numb_levels, gt_nl2 TYPE TABLE OF numb_levels, wa_nl2 TYPE numb_levels. DATA: aplfzc(3) TYPE c, "计划交货天数 normbc(16) TYPE c , "标准数量 netprcx(14) TYPE c, "净价 GYP netprc TYPE iprei, "净价 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 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. PERFORM upload_file1. PERFORM process_file. IF NOT gt_tab1 IS INITIAL. PERFORM create_me11. ENDIF. IF NOT gt_tab2 IS INITIAL. PERFORM update_me12. ENDIF. END-OF-SELECTION. PERFORM result_message. "显示执行结果 *&---------------------------------------------------------------------* *& Form PROCESS_FILE1 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM process_file. LOOP AT gt_tab1 INTO wa_tab1 WHERE flag = 'X'. 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 eina~infnr INTO eina-infnr FROM eina INNER JOIN eine ON eina~infnr = eine~infnr WHERE eina~matnr = wa_tab1-eina_matnr AND eina~lifnr = wa_tab1-eina_lifnr AND eine~werks = wa_tab1-eine_werks AND eine~ekorg = wa_tab1-eine_ekorg. "判断该数据是否已近创建 IF sy-subrc <> 0. MOVE-CORRESPONDING wa_tab1 TO wa_nl. APPEND wa_nl TO gt_nl. ELSE. MOVE-CORRESPONDING wa_tab1 TO wa_nl2. APPEND wa_nl2 TO gt_nl2. ENDIF. ENDLOOP. MOVE gt_tab1 TO temp_tab[]. CLEAR:gt_tab1[],gt_tab1. LOOP AT gt_nl INTO wa_nl. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = wa_nl-eina_matnr IMPORTING output = wa_nl-eina_matnr. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = wa_nl-eina_lifnr IMPORTING output = wa_nl-eina_lifnr. LOOP AT temp_tab WHERE eina_matnr = wa_nl-eina_matnr AND eina_lifnr = wa_nl-eina_lifnr AND eine_werks = wa_nl-eine_werks AND eine_ekorg = wa_nl-eine_ekorg. MOVE-CORRESPONDING temp_tab TO wa_tab1. APPEND wa_tab1 TO gt_tab1. ENDLOOP. ENDLOOP. LOOP AT gt_nl2 INTO wa_nl2. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = wa_nl2-eina_matnr IMPORTING output = wa_nl2-eina_matnr. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = wa_nl2-eina_lifnr IMPORTING output = wa_nl2-eina_lifnr. LOOP AT temp_tab WHERE eina_matnr = wa_nl2-eina_matnr AND eina_lifnr = wa_nl2-eina_lifnr AND eine_werks = wa_nl2-eine_werks AND eine_ekorg = wa_nl2-eine_ekorg. MOVE-CORRESPONDING temp_tab TO wa_tab2. APPEND wa_tab2 TO gt_tab2. ENDLOOP. ENDLOOP. CLEAR:temp_tab[],temp_tab. ENDFORM. " PROCESS_FILE1 *&---------------------------------------------------------------------* *& Form create_me11 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM create_me11. LOOP AT gt_tab1 INTO wa_tab1 WHERE flag = 'X'. CLEAR: aplfzc,normbc,netprc,netprcx,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 netprcx NO-GAPS. "GYP 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 ) ). "增值税 netprcx = netprc. * netprc = netprc * ( 1 + ( p / 100 ) ). "增值税 GYP CONDENSE netprcx NO-GAPS. "gyp 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' netprcx. "净价 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' netprcx. "净价 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 'A' 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. CONCATENATE '物料' wa_tab1-eina_matnr ':' result_mesg INTO result_mesg. 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 = lt_tab-eine_netpr. "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--->设置等级数量 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = lt_tab-eina_matnr IMPORTING output = lt_tab-eina_matnr. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = lt_tab-eina_lifnr IMPORTING output = lt_tab-eina_lifnr. LOOP AT gt_tab1 INTO wa_tab1 WHERE konm_kbetr > 0 AND eina_lifnr = lt_tab-eina_lifnr AND eina_matnr = lt_tab-eina_matnr AND eine_ekorg = lt_tab-eine_ekorg AND eine_werks = lt_tab-eine_werks. "数量等级金额>0 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_tab1-konm_kstbm. "条件等级数量 ti_bapicondqs-cond_unit = lv_bprme. "条件单位 ti_bapicondqs-currency = wa_tab1-konm_kbetr. "BAPIs 的货币金额(带有 9 个小数位) ti_bapicondqs-condcurr = lt_tab-eine_waers. "比率单位(货币或百分数) APPEND ti_bapicondqs . CLEAR ti_bapicondqs . 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_tab1 INTO wa_tab1 WHERE konm_kbetr > 0 AND eina_lifnr = lt_tab-eina_lifnr AND eina_matnr = lt_tab-eina_matnr AND eine_ekorg = lt_tab-eine_ekorg AND eine_werks = lt_tab-eine_werks. "数量等级金额>0 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_tab1-konm_kstbm. "条件等级数量 ti_bapicondqs-cond_unit = lv_bprme. "条件单位 ti_bapicondqs-currency = wa_tab1-konm_kbetr. "BAPIs 的货币金额(带有 9 个小数位) ti_bapicondqs-condcurr = lt_tab-konp_konwa2. "比率单位(货币或百分数) APPEND ti_bapicondqs . CLEAR ti_bapicondqs . 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'. CONCATENATE lt_tab-eina_matnr '操作错误!' INTO result_mesg. APPEND result_mesg. CLEAR:gv_infnr,result_mesg. ENDIF. ENDFORM. " CONDITION *&---------------------------------------------------------------------* *& 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,netprcx,peinhc. peinhc = wa_tab2-eine_peinh. CONDENSE peinhc NO-GAPS. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = wa_tab2-eina_matnr IMPORTING output = wa_tab2-eina_matnr. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = wa_tab2-eina_lifnr IMPORTING output = wa_tab2-eina_lifnr. netprc = wa_tab2-eine_netpr. netprcx = netprc. CONDENSE netprcx NO-GAPS. "GYP 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-eina_lifnr. PERFORM bdc_field USING 'EINA-MATNR' wa_tab2-eina_matnr. PERFORM bdc_field USING 'EINE-EKORG' wa_tab2-eine_ekorg. PERFORM bdc_field USING 'EINE-WERKS' wa_tab2-eine_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_CURSOR' 'EINA-URZTP'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-URZTP' ''. PERFORM bdc_field USING 'EINA-URZTP' wa_tab2-eina_urztp. PERFORM bdc_dynpro USING 'SAPMM06I' '0102'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINE-MWSKZ'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINE-MWSKZ' wa_tab2-eine_mwskz. PERFORM bdc_dynpro USING 'SAPMM06I' '0105'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINE-ANGNR'. PERFORM bdc_field USING 'BDC_OKCODE' '=KO'. PERFORM bdc_field USING 'EINE-ANGNR' wa_tab2-eine_angnr. 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-rv13a_datab. PERFORM bdc_field USING 'RV13A-DATBI' wa_tab2-rv13a_datbi. PERFORM bdc_field USING 'KONP-KBETR(01)' netprcx. 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. CONCATENATE '物料' wa_tab2-eina_matnr ':' result_mesg INTO result_mesg. 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_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,num. DATA esokzc TYPE c. IF lt_tab-wx = 'X'. esokzc = '3'. ELSE. esokzc = '0'. ENDIF. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = lt_tab-eina_matnr IMPORTING output = lt_tab-eina_matnr. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = lt_tab-eina_lifnr IMPORTING output = lt_tab-eina_lifnr. SELECT SINGLE * INTO CORRESPONDING FIELDS OF ls_a017 FROM a017 WHERE kschl = 'PB00' "条件类型 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 datab = lt_tab-rv13a_datab "起始时间 AND datbi = lt_tab-rv13a_datbi "截止时间 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-rv13a_datab. "条件记录有效起始日 ti_bapicondct-valid_to = lt_tab-rv13a_datbi. "条件记录有效截止日期 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_datab. ti_bapicondhd-valid_to = lt_tab-rv13a_datbi. 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 = netprcx. "BAPIs 的货币金额(带有 9 个小数位)-净价 ti_bapicondit-condcurr = lt_tab-eine_waers. "比率单位(货币或百分数):CNY ti_bapicondit-cond_p_unt = peinhc. "条件定价单位(单位=1) ti_bapicondit-cond_unit = lv_bprme. "条件单位 ti_bapicondit-condcurren = lt_tab-eine_waers. ti_bapicondit-unitmeasur = lv_bprme. "条件等级计量单位 APPEND ti_bapicondit. CLEAR ti_bapicondit. *PB00--->设置等级数量 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = lt_tab-eina_matnr IMPORTING output = lt_tab-eina_matnr. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = lt_tab-eina_lifnr IMPORTING output = lt_tab-eina_lifnr. LOOP AT gt_tab2 INTO wa_tab2 WHERE konm_kbetr > 0 AND eina_lifnr = lt_tab-eina_lifnr AND eina_matnr = lt_tab-eina_matnr AND eine_ekorg = lt_tab-eine_ekorg AND eine_werks = lt_tab-eine_werks. "数量等级金额>0 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_tab2-konm_kstbm. "条件等级数量 ti_bapicondqs-cond_unit = lv_bprme. "条件单位 ti_bapicondqs-currency = wa_tab2-konm_kbetr. "BAPIs 的货币金额(带有 9 个小数位) ti_bapicondqs-condcurr = lt_tab-eine_waers. "比率单位(货币或百分数) APPEND ti_bapicondqs . CLEAR ti_bapicondqs . 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 = 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-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_tab2 INTO wa_tab2 WHERE konm_kbetr > 0 AND eina_lifnr = lt_tab-eina_lifnr AND eina_matnr = lt_tab-eina_matnr AND eine_ekorg = lt_tab-eine_ekorg AND eine_werks = lt_tab-eine_werks. "数量等级金额>0 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_tab2-konm_kstbm. "条件等级数量 ti_bapicondqs-cond_unit = lv_bprme. "条件单位 ti_bapicondqs-currency = wa_tab2-konm_kbetr. "BAPIs 的货币金额(带有 9 个小数位) ti_bapicondqs-condcurr = lt_tab-konp_konwa2. "比率单位(货币或百分数) APPEND ti_bapicondqs . CLEAR ti_bapicondqs . 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. 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. CONCATENATE '物料' lt_tab-eina_matnr ' 更改并创建有效期 ' lt_tab-rv13a_datab '-' lt_tab-rv13a_datbi INTO result_mesg. APPEND result_mesg. CLEAR result_mesg. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. CONCATENATE '物料' lt_tab-eina_matnr '操作错误!' INTO result_mesg. APPEND result_mesg. CLEAR result_mesg. ENDIF. ENDFORM. " CONDITION *&---------------------------------------------------------------------* *& 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,netprcx,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'. PERFORM download_template. "创建 ENDCASE. ENDFORM. " DOWNLOAD_TEMPLATE *&---------------------------------------------------------------------* *& Form DOWNLOAD_TEMPLATE1 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM download_template. 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 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函数还是没有很好的理解。