物料主数据批导bapi

创建物料主数据,根据模板不同批导原材料,半成品,成品。可根据实际需求对字段进行增删。

   1 report zmmr_bapi_mm01 no standard page HEADING.
   2 type-POOLS:slis,truxs,icon.
   3 tables: sscrfields,lips,resb,marc,ckmlab02.
   4 data num type stprs_bapi.
   5 data flag type i.                 "标识符,如果不为1则不创建物料
   6 
   7 types:begin of ty_tab,
   8   head_material type matnr,       "物料号
   9   head_ind_sector type mbrsh,     "行业领域
  10   head_matl_type type mtart,      "物料类型
  11   marc_plant type werks_d,        "工厂
  12   mvke_sales_org type vkorg,      "销售组织
  13   mvke_distr_chan type vtweg,     "分销渠道
  14   t_makt_matl_desc type maktx,    "物料描述
  15   mara_base_uom type meins,       "基本计量单位
  16   mara_matl_group type matkl,     "物料组
  17   mara_extwg type extwg,          "客户
  18   mara_item_cat type mtpos_mara,  "普通项目组类别
  19   t_marm_unit_of_wt type gewei,   "重量单位
  20   mara_wrkst type wrkst,          "基本物料
  21   mara_ihivi type adge_ihivi,     "是否客供
  22   mara_zeinr type dzeinr,         "客户物料编码
  23   mvke_dwerk type maktx,          "交货工厂
  24   mvke_sktof type sktof,          "现金折扣
  25   t_mlan_taxclass1 type taxkm,    "税分类
  26   mvke_matl_stats type stgma,     "物料统计组
  27   mvke_acct_assgt type ktgrm,     "科目设置组
  28   mvke_item_cat type mtpos,       "项目类别组
  29   marc_availcheck type mtvfp,     "可用性检查
  30   mara_trans_grp type tragr,      "运输组
  31   marc_loadinggrp type ladgr,     "装载组
  32   marc_pur_group type ekgrp,      "采购组
  33   marc_batch_mgmt type xchpf,     "批次管理标示
  34   marc_auto_p_ord type kautb,     "自动采购订单标识
  35   marc_webaz type webaz,          "收货处理时间
  36   marc_insmk type insmk_mat,      "过账到检验库存
  37   marc_mrp_group type disgr,      "MRP组
  38   marc_maabc type maabc,          "ABC标识
  39   marc_mrp_type type dismm,       "MRP类型
  40   marc_mrp_ctrler type dispo,     "MRP控制者
  41   marc_lotsizekey type disls,     "批量
  42   marc_minlotsize type bstmi,     "最小批量
  43   marc_round_val type bstrf,      "舍入值
  44   marc_proc_type type beskz,      "采购类型
  45   marc_lgpro type lgpro,          "生产仓储地点
  46   marc_rgekz type rgekz,          "反冲
  47   marc_lgfsb type lgfsb,          "外部采购仓储地点
  48   marc_sm_key type fhori,         "计划边际码
  49   marc_plnd_delry type plifz,     "计划交货时间
  50   marc_sbdkz type sbdkz,          "集中/独立
  51 *  mpop_prmod TYPE mpop-prmod,     "预测模型
  52   mbew_val_class type bklas,      "评估级别
  53   mbew_ml_settle type ck_ml_abst, "价格确定
  54   mbew_std_price type ck_pvprs_1, "标准价格
  55   mbew_moving_pr type ck_pvprs_1, "移动平均价
  56   mbew_price_ctrl type vprsv,     "价格控制
  57   mbew_price_unit type peinh,     "价格单位
  58   mbew_hrkft type hrkft,          "原始组
  59   mbew_orig_mat type hkmat,       "物料来源
  60   marc_losgr type ck_losgr,       "成品核算批量
  61 end of ty_tab.
  62 
  63 types:begin of ty_tab2,
  64   head_material type matnr,       "物料号
  65   head_ind_sector type mbrsh,     "行业领域
  66   head_matl_type type mtart,      "物料类型
  67   marc_plant type werks_d,        "工厂
  68   mvke_sales_org type vkorg,      "销售组织
  69   mvke_distr_chan type vtweg,     "分销渠道
  70   t_makt_matl_desc type maktx,    "物料描述
  71   mara_base_uom type meins,       "基本计量单位
  72   mara_matl_group type matkl,     "物料组
  73   mara_extwg type extwg,          "客户
  74   mara_spart type spart,          "产品组
  75   mara_item_cat type mtpos_mara,  "普通项目组类别
  76   t_marm_unit_of_wt type gewei,   "重量单位
  77   mara_formt type formt,          "替代料标识
  78   mara_wrkst type wrkst,          "基本物料
  79   mara_zeinr type dzeinr,         "客户物料编码
  80   mvke_dwerk type maktx,          "交货工厂
  81   mvke_sktof type sktof,          "现金折扣
  82   t_mlan_taxclass1 type taxkm,    "税分类
  83   mvke_matl_stats type stgma,     "物料统计组
  84   mvke_acct_assgt type ktgrm,     "科目设置组
  85   mvke_item_cat type mtpos,       "项目类别组
  86   marc_availcheck type mtvfp,     "可用性检查
  87   mara_trans_grp type tragr,      "运输组
  88   marc_loadinggrp type ladgr,     "装载组
  89   marc_ekgrp type ekgrp,          "采购组
  90   marc_kautb type kautb,          "自动采购单
  91   marc_xchpf type xchpf,          "批次管理
  92   marc_webaz type webaz,          "收货处理时间
  93   marc_mrp_group type disgr,      "MRP组
  94   marc_mrp_type type dismm,       "MRP类型
  95   marc_mrp_ctrler type dispo,     "MRP控制者
  96   marc_lotsizekey type disls,     "批量大小
  97   marc_bstmi type bstmi,          "最小批量大小
  98   marc_bstrf type bstrf,          "舍入值
  99   marc_proc_type type beskz,      "采购类型
 100   marc_sobsl type sobsl,          "特殊采购类型
 101   marc_lgpro type lgpro,          "生产仓储地点
 102   marc_lgfsb type lgfsb,          "外部采购仓储地点
 103   marc_dzeit type dzeit,          "生产时间
 104   marc_plifz type plifz,          "计划交货时间
 105   marc_eisbe type eisbe,          "安全库存
 106   marc_sm_key type fhori,         "计划边际码
 107   marc_strgr type strgr,          "策略组
 108   marc_vrmod type vrmod,          "消耗模式
 109   marc_vint1 type vint1,          "逆向消耗期间
 110   marc_vint2 type vint2,          "向前消耗期间
 111   marc_altsl type altsl,          "选择方法
 112   marc_sbdkz type sbdkz,          "集中/独立
 113   mpop_prmod type mpop-prmod,     "预测模型
 114   mbew_val_class type bklas,      "评估级别
 115   mbew_ml_settle type ck_ml_abst, "价格确定
 116   mbew_std_price type ck_pvprs_1, "标准价格
 117   mbew_price_ctrl type vprsv,     "价格控制
 118   mbew_orig_mat type hkmat,       "物料来源
 119   marc_awsls type awsls,          "差异码
 120   marc_losgr type ck_losgr,       "成本核算批量
 121 end of ty_tab2.
 122 
 123 data:it_tab type table of  ty_tab ,   "原材料
 124       wa_tab type ty_tab.
 125 data:it_tab2 type table of  ty_tab2,  "成品
 126       wa_tab2 type ty_tab2.
 127 
 128 *输入参数
 129 data: headdata                type bapimathead,     "表头数据
 130       clientdata              type bapi_mara,       "基本数据
 131       clientdatax             type bapi_marax,
 132       plantdata like  bapi_marc,                    "工厂数据
 133       plantdatax  like  bapi_marcx,
 134       forecastparameters type  bapi_mpop,           "预测
 135       forecastparametersx type bapi_mpopx,
 136       planningdata type bapi_mpgd,                  "计划
 137       planningdatax type bapi_mpgdx,
 138       valuationdata type bapi_mbew,                 "评估数据
 139       valuationdatax type bapi_mbewx,
 140       warehousenumberdata type bapi_mlgn,           "仓库数据
 141       warehousenumberdatax type bapi_mlgnx,
 142       salesdata type bapi_mvke,                     "销售数据
 143       salesdatax type bapi_mvkex,
 144       storagetypedata type bapi_mlgt,               "存储类型数据
 145       storagetypedatax type bapi_mlgtx.
 146 
 147 *表参数
 148 data: materialdescription type table of bapi_makt with header line,   "描述
 149       unitsofmeasure type table of bapi_marm with header line,        "单位
 150       unitsofmeasurex type table of bapi_marmx with header line,
 151       taxclassifications type table of bapi_mlan with header line,    "税分类
 152       return like table of bapiret2 with header line.                 "错误信息
 153 
 154 data pr_unit type meins.  "基本单位
 155 data pr_unit2 type meins. "重量单位
 156 
 157 data: begin of gt_out occurs 0, "保存return信息
 158   text(255),
 159 end of gt_out.
 160 
 161 *TYPES:BEGIN OF ty_fieldnames ,
 162 *  name TYPE CHAR255,
 163 *END OF ty_fieldnames.
 164 *DATA it_fname TYPE TABLE OF ty_fieldnames WITH HEADER LINE.
 165 data:begin of it_fname occurs 0,
 166   name type char255,
 167 end of it_fname.
 168 
 169 
 170 SELECTION-screen begin of block blk_001 with frame title text-001 . "选择文件路径
 171   parameters:p_file like rlgrap-filename.
 172 SELECTION-screen end of block blk_001.
 173 SELECTION-screen: uline /1(82).
 174 SELECTION-screen: uline 83(83).
 175 SELECTION-screen begin of block blk_002 with frame title text-002.  "确定创建物料类型
 176   parameters:radio_1 radiobutton group radi,    "原材料
 177   radio_2 radiobutton group radi.               "半成品/成品
 178 SELECTION-screen end of block blk_002.
 179 
 180 
 181 SELECTION-screen function key 1. "应用工具栏增加按钮
 182 
 183 initialization.
 184 write icon_change_text as icon to sscrfields-functxt_01+0(4).
 185 sscrfields-functxt_01+4(*) = '下载模板'."分配字符位置
 186 
 187 at SELECTION-screen.
 188 perform selection_screeen.   "模板下载
 189 
 190 
 191 at SELECTION-screen on value-REQUEST for p_file  .
 192 perform open.
 193 
 194 START-of-SELECTION.
 195 if radio_1 = 'X'.
 196   perform upload_file.      "上传数据
 197   perform mm01_1.           "执行批导(原材料).
 198 else.
 199   perform upload_file2.     "上传数据
 200   perform mm01_2.           "执行批导(成品/半成品)
 201 endif.
 202 
 203 
 204 end-of-SELECTION.
 205 perform result_message.   "显示执行结果
 206 
 207 *&---------------------------------------------------------------------*
 208 *&      Form  MM01
 209 *&---------------------------------------------------------------------*
 210 *       text
 211 *----------------------------------------------------------------------*
 212 *  -->  p1        text
 213 *  <--  p2        text
 214 *----------------------------------------------------------------------*
 215 form mm01_1.
 216   loop at it_tab into wa_tab.
 217 *前导0
 218     call function 'CONVERSION_EXIT_ALPHA_INPUT'
 219     exporting
 220       input  = wa_tab-head_material
 221     importing
 222       output = wa_tab-head_material.
 223 
 224 *判断物料是否以存在
 225     select single * from marc where matnr = wa_tab-head_material and werks = wa_tab-marc_plant.
 226     if sy-subrc = 0.
 227       concatenate wa_tab-head_material ' 物料在' wa_tab-marc_plant ' 工厂已存在!' into gt_out-text.
 228       append gt_out.
 229       clear gt_out.
 230       continue.
 231     endif.
 232 
 233     if wa_tab-mbew_moving_pr = ''.
 234       concatenate wa_tab-head_material '->原材料的移动平均价格为空' into gt_out-text.
 235       append gt_out.
 236       clear gt_out.
 237       continue.
 238     endif.
 239 
 240     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "科目设置组
 241     exporting
 242       input        = wa_tab-mvke_acct_assgt
 243     importing
 244       output        = wa_tab-mvke_acct_assgt.
 245     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "可用性检查
 246     exporting
 247       input         = wa_tab-marc_availcheck
 248     importing
 249       output        = wa_tab-marc_availcheck.
 250     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "运输组
 251     exporting
 252       input         = wa_tab-mara_trans_grp
 253     importing
 254       output        = wa_tab-mara_trans_grp.
 255     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "装载组
 256     exporting
 257       input         = wa_tab-marc_loadinggrp
 258     importing
 259       output        = wa_tab-marc_loadinggrp.
 260     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "MRP组
 261     exporting
 262       input         = wa_tab-marc_mrp_group
 263     importing
 264       output        = wa_tab-marc_mrp_group.
 265     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "MRP控制者
 266     exporting
 267       input         = wa_tab-marc_mrp_ctrler
 268     importing
 269       output        = wa_tab-marc_mrp_ctrler.
 270     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "计划边际值
 271     exporting
 272       input         = wa_tab-marc_sm_key
 273     importing
 274       output        = wa_tab-marc_sm_key.
 275 
 276 *判断是否客供,提示价格信息
 277     if wa_tab-mara_ihivi <> 'X'.
 278       clear num.
 279       num = wa_tab-mbew_std_price / wa_tab-mbew_price_unit.
 280       case wa_tab-marc_maabc.   "ABC标识
 281       when 'A'.
 282         if num > 100.
 283           perform pop_confirm using wa_tab-marc_maabc wa_tab-head_material.
 284           if flag = 1.  "为否时执行下一物料
 285             clear flag.
 286             continue.
 287           endif.
 288         endif.
 289       when 'B'.
 290         if num > 5.
 291           perform pop_confirm using wa_tab-marc_maabc wa_tab-head_material.
 292           if flag = 1.
 293             clear flag.
 294             continue.
 295           endif.
 296         endif.
 297       when others.
 298         perform pop_confirm using wa_tab-marc_maabc wa_tab-head_material.
 299         if flag = 1.
 300           clear flag.
 301           continue.
 302         endif.
 303       endcase.
 304     endif.
 305 
 306     clear headdata.
 307     headdata-material = wa_tab-head_material.
 308     headdata-matl_type = wa_tab-head_matl_type.
 309     headdata-ind_sector = wa_tab-head_ind_sector.
 310     headdata-basic_view = 'X'.        "基本数据视图
 311     headdata-sales_view = 'X'.        "销售视图
 312     headdata-purchase_view = 'X'.     "采购视图
 313     headdata-mrp_view = 'X'.          "物料需求计划(MRP)视图
 314 *    headdata-forecast_view = 'X'.     "预测视图
 315     headdata-warehouse_view = 'X'.    "工作计划视图
 316     headdata-account_view = 'X'.      "会计视图
 317     headdata-cost_view = 'X'.         "成本视图
 318 
 319 *基本数据
 320     clear pr_unit.
 321     perform frm_unit using wa_tab-mara_base_uom changing pr_unit."基本单位
 322     clear: clientdata.
 323     clientdata-base_uom = pr_unit.                    "基本计量单位
 324     clientdata-matl_group = wa_tab-mara_matl_group.   "物料组
 325     clientdata-item_cat = wa_tab-mara_item_cat.       "普通项目类别组
 326     clientdata-trans_grp = wa_tab-mara_trans_grp.     "运输组
 327     clientdata-extmatlgrp = wa_tab-mara_extwg.        "客户
 328     clientdata-basic_matl = wa_tab-mara_wrkst.        "基本物料
 329     clientdata-high_visc = wa_tab-mara_ihivi.         "是否客供
 330     clientdata-document = wa_tab-mara_zeinr.          "客户物料编码
 331     clear clientdatax.
 332     clientdatax-base_uom = 'X'.   "基本计量单位
 333     clientdatax-matl_group = 'X'.
 334     clientdatax-item_cat = 'X'.
 335     clientdatax-net_weight = 'X'.
 336     clientdatax-trans_grp = 'X'.
 337     clientdatax-extmatlgrp = 'X'.
 338     clientdatax-basic_matl = 'X'.
 339     clientdatax-high_visc = 'X'.
 340     clientdatax-document = 'X'.
 341 
 342 *工厂级别数据
 343     clear:plantdata.
 344     plantdata-plant = wa_tab-marc_plant.   "工厂
 345     plantdata-availcheck = wa_tab-marc_availcheck.    "可用性检查
 346     plantdata-loadinggrp = wa_tab-marc_loadinggrp.    "装载组
 347     plantdata-pur_group = wa_tab-marc_pur_group.      "采购组
 348     plantdata-batch_mgmt = wa_tab-marc_batch_mgmt.    "批次管理标示
 349     plantdata-auto_p_ord = wa_tab-marc_auto_p_ord.    "自动采购订单标识
 350     plantdata-gr_pr_time = wa_tab-marc_webaz.         "自动采购订单标识
 351     plantdata-ind_post_to_insp_stock = wa_tab-marc_insmk.    "过账到检验库存
 352     plantdata-mrp_group = wa_tab-marc_mrp_group.      "MRP组
 353     plantdata-abc_id = wa_tab-marc_maabc.             "ABC标识
 354     plantdata-mrp_type = wa_tab-marc_mrp_type.        "MRP类型
 355     plantdata-mrp_ctrler = wa_tab-marc_mrp_ctrler.    "MRP控制者
 356     plantdata-lotsizekey = wa_tab-marc_lotsizekey.    "批量
 357     plantdata-minlotsize = wa_tab-marc_minlotsize.    "最小批量
 358     plantdata-round_val = wa_tab-marc_round_val.      "舍入值
 359     plantdata-proc_type = wa_tab-marc_proc_type.      "采购类型
 360     plantdata-iss_st_loc = wa_tab-marc_lgpro.         "生产仓储地点
 361     plantdata-backflush = wa_tab-marc_rgekz.          "反冲
 362     plantdata-sloc_exprc = wa_tab-marc_lgfsb.         "外部采购仓储地点
 363     plantdata-sm_key = wa_tab-marc_sm_key.            "计划边际码
 364     plantdata-plnd_delry = wa_tab-marc_plnd_delry.    "计划交货时间
 365     plantdata-dep_req_id = wa_tab-marc_sbdkz.         "集中/独立
 366     plantdata-lot_size = wa_tab-marc_losgr.           "批量产品核算
 367     clear plantdatax.
 368     plantdatax-plant = wa_tab-marc_plant.
 369     plantdatax-availcheck = 'X'.
 370     plantdatax-loadinggrp = 'X'.
 371     plantdatax-pur_group = 'X'.
 372     plantdatax-batch_mgmt = 'X'.
 373     plantdatax-auto_p_ord = 'X'.
 374     plantdatax-gr_pr_time = 'X'.
 375     plantdatax-ind_post_to_insp_stock = 'X'.
 376     plantdatax-mrp_group = 'X'.
 377     plantdatax-abc_id = 'X'.
 378     plantdatax-mrp_type = 'X'.
 379     plantdatax-mrp_ctrler = 'X'.
 380     plantdatax-lotsizekey = 'X'.
 381     plantdatax-minlotsize = 'X'.
 382     plantdatax-round_val = 'X'.
 383     plantdatax-proc_type = 'X'.
 384     plantdatax-iss_st_loc = 'X'.
 385     plantdatax-backflush = 'X'.
 386     plantdatax-sloc_exprc = 'X'.
 387     plantdatax-sm_key = 'X'.
 388     plantdatax-plnd_delry = 'X'.
 389     plantdatax-dep_req_id = 'X'.
 390     plantdatax-lot_size = 'X'.
 391 
 392 *销售数据
 393     clear salesdata.
 394     salesdata-sales_org = wa_tab-mvke_sales_org.      "销售组织
 395     salesdata-distr_chan = wa_tab-mvke_distr_chan.    "分销渠道
 396     salesdata-delyg_plnt = wa_tab-mvke_dwerk.         "交货工厂
 397     salesdata-cash_disc = wa_tab-mvke_sktof.          "现金折扣标志
 398     salesdata-matl_stats = wa_tab-mvke_matl_stats.    "物料统计组
 399     salesdata-acct_assgt = wa_tab-mvke_acct_assgt.    "科目设置组
 400     salesdata-item_cat = wa_tab-mvke_item_cat.        "项目类别组
 401     clear salesdatax.
 402     salesdatax-sales_org = wa_tab-mvke_sales_org.
 403     salesdatax-distr_chan = wa_tab-mvke_distr_chan.
 404     salesdatax-delyg_plnt = 'X'.
 405     salesdatax-cash_disc = 'X'.
 406     salesdatax-matl_stats = 'X'.
 407     salesdatax-acct_assgt = 'X'.
 408     salesdatax-item_cat = 'X'.
 409 
 410 **预测
 411 *    CLEAR:forecastparameters,forecastparametersx.
 412 *    forecastparameters-plant = wa_tab-marc_plant.         "工厂
 413 *    forecastparameters-fore_model = wa_tab-mpop_prmod.    "预测模型
 414 *    forecastparametersx-plant = wa_tab-marc_plant.
 415 *    forecastparametersx-fore_model = 'X'.
 416 
 417 *会计、成本
 418     clear valuationdata.
 419     valuationdata-val_area = wa_tab-marc_plant.
 420     valuationdata-val_class = wa_tab-mbew_val_class.      "评估级别
 421     valuationdata-ml_settle = wa_tab-mbew_ml_settle.      "价格确定
 422     valuationdata-std_price = wa_tab-mbew_std_price.      "标准价格
 423     valuationdata-moving_pr = wa_tab-mbew_moving_pr.      "移动平均价
 424     valuationdata-price_unit = wa_tab-mbew_price_unit.    "价格单位
 425     valuationdata-price_ctrl = wa_tab-mbew_price_ctrl.    "价格控制
 426     valuationdata-orig_group = wa_tab-mbew_hrkft.         "原始组
 427     valuationdata-orig_mat = wa_tab-mbew_orig_mat.        "物料来源
 428     clear valuationdatax.
 429     valuationdatax-val_area = wa_tab-marc_plant.
 430     valuationdatax-val_class = 'X'.
 431     valuationdatax-ml_settle = 'X'.
 432     valuationdatax-price_ctrl = 'X'.
 433     valuationdatax-price_unit = 'X'.
 434     valuationdatax-moving_pr = 'X'.
 435     valuationdatax-std_price = 'X'.
 436     valuationdatax-orig_group = 'X'.
 437     valuationdatax-orig_mat = 'X'.
 438 
 439 *物料描述
 440     clear materialdescription[].
 441     materialdescription-langu_iso = 'ZH'.
 442     materialdescription-matl_desc = wa_tab-t_makt_matl_desc.
 443     append materialdescription.
 444 
 445 *单位
 446     clear unitsofmeasure[].
 447     unitsofmeasure-alt_unit = pr_unit.
 448     unitsofmeasure-unit_of_wt = wa_tab-t_marm_unit_of_wt.
 449     append unitsofmeasure.
 450     clear unitsofmeasurex[].
 451     unitsofmeasurex-alt_unit = pr_unit.
 452     unitsofmeasurex-unit_of_wt = 'X'.
 453     append unitsofmeasurex.
 454 
 455 *税分类
 456     clear taxclassifications[].
 457     taxclassifications-depcountry = 'CN'.
 458     taxclassifications-tax_type_1 = 'MWST'.
 459     taxclassifications-taxclass_1 = wa_tab-t_mlan_taxclass1.  "税分类
 460     append taxclassifications.
 461 
 462     call function 'BAPI_MATERIAL_SAVEDATA'
 463     exporting
 464       headdata            = headdata
 465       clientdata          = clientdata
 466       clientdatax         = clientdatax
 467       plantdata           = plantdata
 468       plantdatax          = plantdatax
 469       forecastparameters  = forecastparameters
 470       forecastparametersx = forecastparametersx
 471       valuationdata       = valuationdata
 472       valuationdatax      = valuationdatax
 473       salesdata           = salesdata
 474       salesdatax          = salesdatax
 475     importing
 476       return              = return
 477     tables
 478       materialdescription = materialdescription[]
 479       unitsofmeasure      = unitsofmeasure[]
 480       unitsofmeasurex     = unitsofmeasurex
 481       taxclassifications  = taxclassifications[].
 482     if return-type = 'E' or return-type = 'A'.
 483       call function 'BAPI_TRANSACTION_ROLLBACK'.
 484       concatenate wa_tab-head_material ' 原材料—>' return-message into gt_out-text.
 485       append gt_out.
 486       clear gt_out.
 487     else.
 488       call function 'BAPI_TRANSACTION_COMMIT'
 489       exporting
 490         wait = 'X'.
 491       concatenate wa_tab-head_material ' 物料创建成功。' into gt_out-text.
 492       append gt_out.
 493       clear gt_out.
 494     endif.
 495   endloop.
 496 endform.                                                    "mm01
 497 
 498 *  PERFORM alv.
 499 *&---------------------------------------------------------------------*
 500 *&      Form  vq_fn
 501 *&---------------------------------------------------------------------*
 502 *       text
 503 *----------------------------------------------------------------------*
 504 form mm01_2.
 505   loop at it_tab2 into wa_tab2.
 506 
 507     call function 'CONVERSION_EXIT_ALPHA_INPUT'
 508     exporting
 509       input  = wa_tab2-head_material
 510     importing
 511       output = wa_tab2-head_material.
 512 
 513 *判断物料是否以存在
 514     select single * from marc where matnr = wa_tab2-head_material and werks = wa_tab2-marc_plant.
 515     if sy-subrc = 0.
 516       concatenate wa_tab2-head_material ' 物料在' wa_tab2-marc_plant ' 工厂已存在!' into gt_out-text.
 517       append gt_out.
 518       clear gt_out.
 519       continue.
 520     endif.
 521 
 522 *如果为移动平均,
 523     clear ckmlab02.
 524     if wa_tab2-mbew_price_ctrl = 'S'.
 525       select single * from ckmlab02 into ckmlab02 where bwkey = wa_tab2-marc_plant.  "Y3
 526       if ckmlab02 is initial.
 527         wa_tab2-mbew_ml_settle = '3'.       "价格确定
 528       else.
 529         wa_tab2-mbew_ml_settle = '2'.
 530       endif.
 531     endif.
 532 
 533     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "科目设置组
 534     exporting
 535       input        = wa_tab2-mvke_acct_assgt
 536     importing
 537       output        = wa_tab2-mvke_acct_assgt.
 538     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "可用性检查
 539     exporting
 540       input         = wa_tab2-marc_availcheck
 541     importing
 542       output        = wa_tab2-marc_availcheck.
 543     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "运输组
 544     exporting
 545       input         = wa_tab2-mara_trans_grp
 546     importing
 547       output        = wa_tab2-mara_trans_grp.
 548     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "装载组
 549     exporting
 550       input         = wa_tab2-marc_loadinggrp
 551     importing
 552       output        = wa_tab2-marc_loadinggrp.
 553     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "MRP控制者
 554     exporting
 555       input         = wa_tab2-marc_mrp_ctrler
 556     importing
 557       output        = wa_tab2-marc_mrp_ctrler.
 558     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "计划边际值
 559     exporting
 560       input         = wa_tab2-marc_sm_key
 561     importing
 562       output        = wa_tab2-marc_sm_key.
 563     call function 'CONVERSION_EXIT_ALPHA_INPUT'     "差异码
 564     exporting
 565       input         = wa_tab2-marc_awsls
 566     importing
 567       output        = wa_tab2-marc_awsls.
 568 
 569     clear headdata.
 570     headdata-material       = wa_tab2-head_material.
 571     headdata-matl_type      = wa_tab2-head_matl_type.
 572     headdata-ind_sector     = wa_tab2-head_ind_sector.
 573     headdata-basic_view     = 'X'.    "基本数据视图
 574     headdata-sales_view = 'X'.        "销售视图
 575     headdata-purchase_view = 'X'.     "采购视图
 576     headdata-mrp_view = 'X'.          "物料需求计划(MRP)视图
 577     headdata-forecast_view = 'X'.     "预测视图
 578     headdata-warehouse_view = 'X'.    "工作计划视图
 579     headdata-account_view = 'X'.      "会计视图
 580     headdata-cost_view = 'X'.         "成本视图
 581 
 582 *基本数据
 583     clear pr_unit.
 584     perform frm_unit using wa_tab2-mara_base_uom changing pr_unit."基本单位
 585     clear: clientdata.
 586     clientdata-base_uom = pr_unit.                     "基本计量单位
 587     clientdata-matl_group = wa_tab2-mara_matl_group.   "物料组
 588     clientdata-item_cat = wa_tab2-mara_item_cat.       "普通项目类别组
 589     clientdata-trans_grp = wa_tab2-mara_trans_grp.     "运输组
 590     clientdata-extmatlgrp = wa_tab2-mara_extwg.        "客户
 591     clientdata-division = wa_tab2-mara_spart.          "产品组
 592     clientdata-pageformat = wa_tab2-mara_formt.        "替代料标识
 593     clientdata-basic_matl = wa_tab2-mara_wrkst.        "基本物料
 594     clientdata-document = wa_tab2-mara_zeinr.          "客户物料编码
 595     clear clientdatax.
 596     clientdatax-base_uom = 'X'.   "基本计量单位
 597     clientdatax-matl_group = 'X'.
 598     clientdatax-item_cat = 'X'.
 599     clientdatax-trans_grp = 'X'.
 600     clientdatax-extmatlgrp = 'X'.
 601     clientdatax-division = 'X'.
 602     clientdatax-pageformat = 'X'.
 603     clientdatax-basic_matl = 'X'.        "基本物料
 604     clientdatax-document = 'X'.          "客户物料编码
 605 
 606 
 607 *工厂级别数据
 608     clear:plantdata.
 609     plantdata-plant = wa_tab2-marc_plant.   "工厂
 610     plantdata-availcheck = wa_tab2-marc_availcheck.    "可用性检查
 611     plantdata-loadinggrp = wa_tab2-marc_loadinggrp.    "装载组
 612     plantdata-pur_group = wa_tab2-marc_ekgrp.          "采购组
 613     plantdata-auto_p_ord = wa_tab2-marc_kautb.         "自动采购单
 614     plantdata-batch_mgmt = wa_tab2-marc_xchpf.         "批次管理
 615     plantdata-gr_pr_time = wa_tab2-marc_webaz.         "收货处理时间
 616     plantdata-mrp_group = wa_tab2-marc_mrp_group.      "MRP组
 617     plantdata-mrp_type = wa_tab2-marc_mrp_type.        "MRP类型
 618     plantdata-mrp_ctrler = wa_tab2-marc_mrp_ctrler.    "MRP控制者
 619     plantdata-lotsizekey = wa_tab2-marc_lotsizekey.    "批量大小
 620     plantdata-minlotsize = wa_tab2-marc_bstmi.         "最小批量大小
 621     plantdata-round_val = wa_tab2-marc_bstrf.         "舍入值
 622     plantdata-proc_type = wa_tab2-marc_proc_type.      "采购类型
 623     plantdata-spproctype = wa_tab2-marc_sobsl.         "特殊采购类型
 624     plantdata-iss_st_loc = wa_tab2-marc_lgpro.         "生产仓储地点
 625     plantdata-sloc_exprc = wa_tab2-marc_lgfsb.         "外部采购仓储地点
 626     plantdata-inhseprodt = wa_tab2-marc_dzeit.         "自制生产天数
 627     plantdata-plnd_delry = wa_tab2-marc_plifz.         "计划交货时间
 628     plantdata-safety_stk = wa_tab2-marc_eisbe.         "安全库存
 629     plantdata-plan_strgp = wa_tab2-marc_strgr.         "策略组
 630     plantdata-consummode = wa_tab2-marc_vrmod.         "消耗模式
 631     plantdata-bwd_cons = wa_tab2-marc_vint1.           "逆向消耗期间
 632     plantdata-fwd_cons = wa_tab2-marc_vint2.           "消耗时期-向前
 633     plantdata-alt_bom_id = wa_tab2-marc_altsl.         "选择方法(选择可替换物料单的方法)
 634     plantdata-sm_key = wa_tab2-marc_sm_key.            "计划边际码
 635     plantdata-dep_req_id = wa_tab2-marc_sbdkz.         "集中/独立
 636     plantdata-variance_key = wa_tab2-marc_awsls.       "差异码
 637     plantdata-lot_size = wa_tab2-marc_losgr.           "成本核算批量
 638     clear plantdatax.
 639     plantdatax-plant = wa_tab2-marc_plant.
 640     plantdatax-availcheck = 'X'.
 641     plantdatax-loadinggrp = 'X'.
 642     plantdatax-pur_group = 'X'.
 643     plantdatax-auto_p_ord = 'X'.
 644     plantdatax-batch_mgmt = 'X'.
 645     plantdatax-gr_pr_time = 'X'.
 646     plantdatax-mrp_group = 'X'.
 647     plantdatax-mrp_type = 'X'.
 648     plantdatax-mrp_ctrler = 'X'.
 649     plantdatax-lotsizekey = 'X'.
 650     plantdatax-minlotsize = 'X'.
 651     plantdatax-round_val = 'X'.
 652     plantdatax-proc_type = 'X'.
 653     plantdatax-spproctype = 'X'.
 654     plantdatax-iss_st_loc = 'X'.
 655     plantdatax-sloc_exprc = 'X'.
 656     plantdatax-inhseprodt = 'X'.
 657     plantdatax-plnd_delry = 'X'.
 658     plantdatax-safety_stk = 'X'.
 659     plantdatax-plan_strgp = 'X'.
 660     plantdatax-consummode = 'X'.
 661     plantdatax-bwd_cons = 'X'.
 662     plantdatax-fwd_cons = 'X'.
 663     plantdatax-alt_bom_id = 'X'.
 664     plantdatax-sm_key = 'X'.
 665     plantdatax-dep_req_id = 'X'.
 666     plantdatax-variance_key = 'X'.
 667     plantdatax-lot_size = 'X'.
 668 
 669 
 670 *销售数据
 671     clear salesdata.
 672     salesdata-sales_org = wa_tab2-mvke_sales_org.      "销售组织
 673     salesdata-distr_chan = wa_tab2-mvke_distr_chan.    "分销渠道
 674     salesdata-delyg_plnt = wa_tab2-mvke_dwerk.         "交货工厂
 675     salesdata-cash_disc = wa_tab2-mvke_sktof.          "现金折扣标志
 676     salesdata-matl_stats = wa_tab2-mvke_matl_stats.    "物料统计组
 677     salesdata-acct_assgt = wa_tab2-mvke_acct_assgt.    "科目设置组
 678     salesdata-item_cat = wa_tab2-mvke_item_cat.        "项目类别组
 679     clear salesdatax.
 680     salesdatax-sales_org = wa_tab2-mvke_sales_org.
 681     salesdatax-distr_chan = wa_tab2-mvke_distr_chan.
 682     salesdatax-delyg_plnt = 'X'.
 683     salesdatax-cash_disc = 'X'.
 684     salesdatax-matl_stats = 'X'.
 685     salesdatax-acct_assgt = 'X'.
 686     salesdatax-item_cat = 'X'.
 687 
 688 *预测
 689     clear:forecastparameters,forecastparametersx.
 690     forecastparameters-plant = wa_tab2-marc_plant.       "工厂
 691     forecastparameters-fore_model = wa_tab2-mpop_prmod.  "预测模型
 692     forecastparametersx-plant = wa_tab2-marc_plant.
 693     forecastparametersx-fore_model = 'X'.
 694 
 695 *会计、成本
 696     clear valuationdata.
 697     valuationdata-val_area = wa_tab2-marc_plant.
 698     valuationdata-val_class = wa_tab2-mbew_val_class.     "评估级别
 699     valuationdata-ml_settle = wa_tab2-mbew_ml_settle.     "价格确定
 700     valuationdata-std_price = wa_tab2-mbew_std_price.     "标准价格
 701     valuationdata-price_ctrl = wa_tab2-mbew_price_ctrl.   "价格控制
 702     valuationdata-orig_mat = wa_tab2-mbew_orig_mat.       "物料来源
 703     clear valuationdatax.
 704     valuationdatax-val_area = wa_tab2-marc_plant.
 705     valuationdatax-val_class = 'X'.
 706     valuationdatax-ml_settle = 'X'.
 707     valuationdatax-price_ctrl = 'X'.
 708     valuationdatax-std_price = 'X'.
 709     valuationdatax-orig_mat = 'X'.
 710 
 711 
 712 *物料描述
 713     clear materialdescription[].
 714     materialdescription-langu_iso = 'ZH'.
 715     materialdescription-matl_desc = wa_tab2-t_makt_matl_desc.
 716     append materialdescription.
 717 
 718 
 719 *单位
 720     clear unitsofmeasure[].
 721     unitsofmeasure-alt_unit = pr_unit.
 722     unitsofmeasure-unit_of_wt = wa_tab2-t_marm_unit_of_wt.
 723     append unitsofmeasure.
 724     clear unitsofmeasurex[].
 725     unitsofmeasurex-alt_unit = pr_unit.
 726     unitsofmeasurex-unit_of_wt = 'X'.
 727     append unitsofmeasurex.
 728 
 729 
 730 *税分类
 731     clear taxclassifications[].
 732     taxclassifications-depcountry = 'CN'.
 733     taxclassifications-tax_type_1 = 'MWST'.
 734     taxclassifications-taxclass_1 = wa_tab2-t_mlan_taxclass1.  "税分类
 735     append taxclassifications.
 736 
 737     call function 'BAPI_MATERIAL_SAVEDATA'
 738     exporting
 739       headdata            = headdata
 740       clientdata          = clientdata
 741       clientdatax         = clientdatax
 742       plantdata           = plantdata
 743       plantdatax          = plantdatax
 744       forecastparameters  = forecastparameters
 745       forecastparametersx = forecastparametersx
 746       valuationdata       = valuationdata
 747       valuationdatax      = valuationdatax
 748       salesdata           = salesdata
 749       salesdatax          = salesdatax
 750     importing
 751       return              = return
 752     tables
 753       materialdescription = materialdescription[]
 754       unitsofmeasure      = unitsofmeasure[]
 755       unitsofmeasurex     = unitsofmeasurex
 756       taxclassifications  = taxclassifications[].
 757     if return-type = 'E' or return-type = 'A'.
 758       call function 'BAPI_TRANSACTION_ROLLBACK'.
 759       concatenate wa_tab-head_material ' 原材料—>' return-message into gt_out-text.
 760       append gt_out.
 761       clear gt_out.
 762     else.
 763       call function 'BAPI_TRANSACTION_COMMIT'
 764       exporting
 765         wait = 'X'.
 766       concatenate wa_tab2-head_material ' 成品创建成功。' into gt_out-text.
 767       append gt_out.
 768       clear gt_out.
 769     endif.
 770   endloop.
 771 endform.                                                    "mm01
 772 
 773 *&---------------------------------------------------------------------*
 774 *&      Form  open
 775 *&---------------------------------------------------------------------*
 776 *       text
 777 *----------------------------------------------------------------------*
 778 form open .
 779 
 780   call function 'KD_GET_FILENAME_ON_F4'
 781   exporting
 782 *     PROGRAM_NAME        = SYST-REPID
 783 *     DYNPRO_NUMBER       = SYST-DYNNR
 784 *     FIELD_NAME          = ' '
 785 *mask    = '*.txt,*.txt'
 786     mask    = '*.xlsx,*.xls'
 787     static  = 'X'
 788 *     MASK                = ' '
 789 *     FILEOPERATION       = 'R'
 790 *     PATH                =
 791   changing
 792     file_name           = p_file
 793 *     LOCATION_FLAG       = 'P'
 794 *   EXCEPTIONS
 795 *     MASK_TOO_LONG       = 1
 796 *     OTHERS              = 2
 797     .
 798 endform.                    "vq_fn
 799 
 800 *&---------------------------------------------------------------------*
 801 *&      Form  vq_fn1
 802 *&---------------------------------------------------------------------*
 803 *       text
 804 *----------------------------------------------------------------------*
 805 "vq_fn
 806 
 807 *&---------------------------------------------------------------------*
 808 *&      Form  upload_file
 809 *&---------------------------------------------------------------------*
 810 *       text
 811 *----------------------------------------------------------------------*
 812 form upload_file .
 813   data: it_raw_data type truxs_t_text_data.
 814   field-SYMBOLS <fs> type ty_tab.
 815   field-SYMBOLS:<fw>.
 816   data: i_excel type table of alsmex_tabline,"表格结构。"
 817         w_excel type alsmex_tabline.
 818   data:num_col type i.
 819   refresh: it_tab.
 820   "调用此函数,将Excel中的内容以类似坐标的形式存储到I_excel内表中。"
 821   call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
 822   exporting
 823     filename                = p_file
 824     i_begin_col             = 1
 825     i_begin_row             = 1
 826     i_end_col               = 55       "控制传入字段个数
 827     i_end_row               = 2500
 828   tables
 829     intern                  = i_excel
 830   exceptions
 831     inconsistent_parameters = 1
 832     upload_ole              = 2
 833     others                  = 3.
 834   delete i_excel where row = 1.        "删除第一行文本抬头。
 835   if i_excel is initial.
 836     call function 'POPUP_TO_CONFIRM_WITH_MESSAGE'
 837     exporting
 838 *     DEFAULTOPTION        = 'Y'
 839       diagnosetext1        = '数据错误'
 840 *     DIAGNOSETEXT2        = ' '
 841 *     DIAGNOSETEXT3        = ' '
 842       textline1            =  'Excel表格中没有内容!'
 843       titel                = '提示' .
 844     return.
 845   endif.
 846   sort i_excel by row col.
 847 
 848   loop at i_excel into w_excel.
 849     num_col = w_excel-col.
 850     assign component  num_col  of structure wa_tab to <fw>.
 851     <fw> = w_excel-value.
 852     at end of row.
 853       append wa_tab to it_tab.
 854       clear:wa_tab.
 855     endat.
 856     clear:w_excel.
 857   endloop.
 858 endform.                    " UPLOAD_FILE
 859 
 860 *&---------------------------------------------------------------------*
 861 *&      Form  upload_file2
 862 *&---------------------------------------------------------------------*
 863 *       text
 864 *----------------------------------------------------------------------*
 865 form upload_file2.
 866   data: it_raw_data type truxs_t_text_data.
 867   field-SYMBOLS <fs> type ty_tab2.
 868   field-SYMBOLS:<fw>.
 869 
 870   data: i_excel type table of alsmex_tabline,"表格结构。"
 871         w_excel type alsmex_tabline.
 872   data:num_col type i.
 873   refresh: it_tab2.
 874   "调用此函数,将Excel中的内容以类似坐标的形式存储到I_excel内表中。"
 875   call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
 876   exporting
 877     filename                = p_file
 878     i_begin_col             = 1
 879     i_begin_row             = 1
 880     i_end_col               = 60       "控制传入字段个数
 881     i_end_row               = 2500
 882   tables
 883     intern                  = i_excel
 884   exceptions
 885     inconsistent_parameters = 1
 886     upload_ole              = 2
 887     others                  = 3.
 888   delete i_excel where row = 1.         "删除第一行文本抬头。
 889   if i_excel is initial.
 890     call function 'POPUP_TO_CONFIRM_WITH_MESSAGE'
 891     exporting
 892 *     DEFAULTOPTION        = 'Y'
 893       diagnosetext1        = '数据错误'
 894 *     DIAGNOSETEXT2        = ' '
 895 *     DIAGNOSETEXT3        = ' '
 896       textline1            =  'Excel表格中没有内容!'
 897       titel                = '提示' .
 898     return.
 899   endif.
 900   sort i_excel by row col.
 901 
 902   loop at i_excel into w_excel.
 903     num_col = w_excel-col.
 904     assign component  num_col  of structure wa_tab2 to <fw>.
 905     <fw> = w_excel-value.
 906     at end of row.
 907       append wa_tab2 to it_tab2.
 908       clear:wa_tab2.
 909     endat.
 910     clear:w_excel.
 911   endloop.
 912 endform.                    " UPLOAD_FILE
 913 
 914 *获取基本计量单位内码
 915 form frm_unit using unit1 changing unit2.
 916   call function 'CONVERSION_EXIT_CUNIT_INPUT'
 917   exporting
 918     input          = unit1
 919     language       = sy-langu
 920   importing
 921     output         = unit2
 922   exceptions
 923     unit_not_found = 1
 924     others         = 2.
 925   if sy-subrc <> 0.
 926 *   message id sy-msgid type sy-msgty number sy-msgno
 927 *           with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
 928   endif.
 929 endform.                    "frm_unit
 930 
 931 
 932 *&---------------------------------------------------------------------*
 933 *&      Form  result_message
 934 *&---------------------------------------------------------------------*
 935 *       text
 936 *----------------------------------------------------------------------*
 937 form result_message.
 938   loop at gt_out.
 939     write: / gt_out-text.
 940   endloop.
 941 endform.                    "sub_output_result
 942 
 943 
 944 *&---------------------------------------------------------------------*
 945 *&      Form  selection_screeen
 946 *&---------------------------------------------------------------------*
 947 *       text
 948 *----------------------------------------------------------------------*
 949 form selection_screeen .
 950   case sscrfields-ucomm.
 951   when 'FC01'.
 952     if radio_1 = 'X'.
 953       perform download_template.
 954     else.
 955       perform download_template2.
 956     endif.
 957   endcase.
 958 endform.                    "SELECTION_SCREEEN
 959 
 960 
 961 *&---------------------------------------------------------------------*
 962 *&      Form  download_template
 963 *&---------------------------------------------------------------------*
 964 *       text
 965 *----------------------------------------------------------------------*
 966 form download_template.
 967 
 968   data lv_file like rlgrap-filename.
 969   data lv_string type string.
 970 
 971   call function 'KD_GET_FILENAME_ON_F4'
 972   exporting
 973 *     PROGRAM_NAME        = SYST-REPID
 974 *     DYNPRO_NUMBER       = SYST-DYNNR
 975 *     field_name          = lv_string
 976     static              = 'X'
 977     mask                = ',EXCEL,*.xls.'
 978 *     FILEOPERATION       = 'R'
 979 *     PATH                =
 980   changing
 981     file_name           = lv_file.
 982   clear wa_tab.
 983   wa_tab-head_material = 'YCL07'.
 984   wa_tab-head_ind_sector = 'M'.
 985   wa_tab-head_matl_type = '8030'.
 986   wa_tab-marc_plant = '7888'.
 987   wa_tab-mvke_sales_org = '7888'.
 988   wa_tab-mvke_distr_chan = '10'.
 989   wa_tab-t_makt_matl_desc = 'YCL07原材料'.
 990   wa_tab-mara_base_uom = 'EA'.
 991   wa_tab-mara_matl_group = '00103'.
 992   wa_tab-mara_extwg = 'DW'.
 993   wa_tab-mara_item_cat = 'NORM'.
 994   wa_tab-t_marm_unit_of_wt = 'KG'.
 995   wa_tab-mara_wrkst = '基本数据2_基本物料'.
 996   wa_tab-mara_ihivi = 'X'.
 997   wa_tab-mara_zeinr = '基本数据2_客户物料编码'.
 998   wa_tab-mvke_dwerk = '7888'.
 999   wa_tab-mvke_sktof = 'X'.
1000   wa_tab-t_mlan_taxclass1 = '1'.
1001   wa_tab-mvke_matl_stats = '1'.
1002   wa_tab-mvke_acct_assgt = '03'.
1003   wa_tab-mvke_item_cat = 'NORM'.
1004   wa_tab-marc_availcheck = '02'.
1005   wa_tab-mara_trans_grp = '0001'.
1006   wa_tab-marc_loadinggrp = '0001'.
1007   wa_tab-marc_pur_group = '104'.
1008   wa_tab-marc_batch_mgmt = 'X'.
1009   wa_tab-marc_auto_p_ord = 'X'.
1010   wa_tab-marc_webaz = '5'.
1011   wa_tab-marc_insmk = 'X'.
1012   wa_tab-marc_mrp_group = '0007'.
1013   wa_tab-marc_maabc = 'A'.
1014   wa_tab-marc_mrp_type = 'PD'.
1015   wa_tab-marc_mrp_ctrler = '001'.
1016   wa_tab-marc_lotsizekey = 'EX'.
1017   wa_tab-marc_minlotsize = '105'.
1018   wa_tab-marc_round_val = '205'.
1019   wa_tab-marc_proc_type = 'F'.
1020   wa_tab-marc_lgpro = '1021'.
1021   wa_tab-marc_rgekz = '1'.
1022   wa_tab-marc_lgfsb = '1021'.
1023   wa_tab-marc_sm_key = '000'.
1024   wa_tab-marc_plnd_delry = '30'.
1025   wa_tab-marc_sbdkz = '1'.
1026   wa_tab-mbew_val_class = '3000'.
1027   wa_tab-mbew_ml_settle = '2'.
1028   wa_tab-mbew_std_price = '5'.
1029   wa_tab-mbew_moving_pr = '5'.
1030   wa_tab-mbew_price_ctrl = 'V'.
1031   wa_tab-mbew_price_unit = '1'.
1032   wa_tab-mbew_hrkft = 'Z10'.
1033   wa_tab-mbew_orig_mat = 'X'.
1034   wa_tab-marc_losgr = '10'.
1035   append wa_tab to it_tab.
1036   clear wa_tab.
1037 
1038   if it_fname is initial.
1039     perform append_filename using:'物料号',
1040           '行业领域',
1041           '物料类型',
1042           '工厂',
1043           '销售组织',
1044           '分销渠道',
1045           '物料描述',
1046           '基本计量单位',
1047           '物料组',
1048           '客户',
1049           '普通项目组类别',
1050           '重量单位',
1051           '基本物料',
1052           '是否客供',
1053           '客户物料编码',
1054           '交货工厂',
1055           '现金折扣',
1056           '税分类',
1057           '物料统计组',
1058           '科目设置组',
1059           '项目类别组',
1060           '可用性检查',
1061           '运输组',
1062           '装载组',
1063           '采购组',
1064           '批次管理标示',
1065           '自动采购订单标识',
1066           '收货处理时间',
1067           '过账至检验库存',
1068           'MRP组',
1069           'ABC标识',
1070           'MRP类型',
1071           'MRP控制者',
1072           '批量',
1073           '最小批量',
1074           '舍入值',
1075           '采购类型',
1076           '生产仓储地点',
1077           '反冲',
1078           '外部采购仓储地点',
1079           '计划边际码',
1080           '计划交货时间',
1081           '集中/独立',
1082           '评估级别',
1083           '价格确定',
1084           '标准价格',
1085           '移动平均价',
1086           '价格控制',
1087           '价格单位',
1088           '原始组',
1089           '物料来源',
1090           '成品核算PL'.
1091   endif.
1092   lv_string = lv_file.
1093   call function 'GUI_DOWNLOAD'
1094   exporting
1095 *         BIN_FILESIZE                    =
1096     filename                        = lv_string
1097     filetype                       = 'DBF'
1098 *      filetype                        = 'DAT'
1099     append                       = 'X'
1100     write_field_separator           = 'X'
1101     codepage                        = '8400'   "指定写文件时用的字符集
1102   tables
1103     data_tab                        = it_tab
1104     fieldnames                      = it_fname[].
1105   if sy-subrc <> 0.
1106 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
1107 *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
1108   endif.
1109   clear: it_tab,it_fname[],lv_string.
1110 endform.                    "download_templat
1111 
1112 
1113 *&---------------------------------------------------------------------*
1114 *&      Form  download_template2
1115 *&---------------------------------------------------------------------*
1116 *       text
1117 *----------------------------------------------------------------------*
1118 form download_template2.
1119 
1120   data lv_file like rlgrap-filename.
1121   data lv_string type string.
1122 
1123   call function 'KD_GET_FILENAME_ON_F4'
1124   exporting
1125 *     PROGRAM_NAME        = SYST-REPID
1126 *     DYNPRO_NUMBER       = SYST-DYNNR
1127 *     field_name          = lv_string
1128     static              = 'X'
1129     mask                = ',EXCEL,*.xls.'
1130 *     FILEOPERATION       = 'R'
1131 *     PATH                =
1132   changing
1133     file_name           = lv_file.
1134   clear wa_tab2.
1135   wa_tab2-head_material = 'CP01'.
1136   wa_tab2-head_ind_sector = 'M'.
1137   wa_tab2-head_matl_type = '8010'.
1138   wa_tab2-marc_plant = '7888'.
1139   wa_tab2-mvke_sales_org = '7888'.
1140   wa_tab2-mvke_distr_chan = '10'.
1141   wa_tab2-t_makt_matl_desc = 'CP01成品测试'.
1142   wa_tab2-mara_base_uom = 'EA'.
1143   wa_tab2-mara_matl_group = '00501030'.
1144   wa_tab2-mara_extwg = 'DW'.
1145   wa_tab2-mara_spart = '01'.
1146   wa_tab2-mara_item_cat = 'NORM'.
1147   wa_tab2-t_marm_unit_of_wt = 'KG'.
1148   wa_tab2-mara_formt = 'Y'.
1149   wa_tab2-mara_wrkst = '基本物料'.
1150   wa_tab2-mara_zeinr = '客户物料编码'.
1151   wa_tab2-mvke_dwerk = '7888'.
1152   wa_tab2-mvke_sktof = 'X'.
1153   wa_tab2-t_mlan_taxclass1 = '1'.
1154   wa_tab2-mvke_matl_stats = '1'.
1155   wa_tab2-mvke_acct_assgt = '01'.
1156   wa_tab2-mvke_item_cat = 'NORM'.
1157   wa_tab2-marc_availcheck = '02'.
1158   wa_tab2-mara_trans_grp = '0001'.
1159   wa_tab2-marc_loadinggrp = '0001'.
1160   wa_tab2-marc_ekgrp = '101'.
1161   wa_tab2-marc_kautb = 'X'.
1162   wa_tab2-marc_xchpf = 'X'.
1163   wa_tab2-marc_webaz = '1'.           "收货处理时间
1164   wa_tab2-marc_mrp_group = 'F001'.
1165   wa_tab2-marc_mrp_type = 'PD'.
1166   wa_tab2-marc_mrp_ctrler = '050'.
1167   wa_tab2-marc_lotsizekey = 'EX'.     "批量大小
1168   wa_tab2-marc_bstmi = '100'.         "最小批量大小
1169   wa_tab2-marc_bstrf = '100'.         "舍入值
1170   wa_tab2-marc_proc_type = 'X'.       "采购类型
1171   wa_tab2-marc_sobsl = '10'.          "特殊采购类型
1172   wa_tab2-marc_lgpro = '3002'.        "生产仓储地点
1173   wa_tab2-marc_lgfsb = '3002'.        "外部采购仓储地点
1174   wa_tab2-marc_dzeit = '3'.           "自制生产天数
1175   wa_tab2-marc_plifz = '1'.           "计划交货时间
1176   wa_tab2-marc_eisbe = '100'.         "安全库存
1177   wa_tab2-marc_sm_key = '000'.        "计划边际码
1178   wa_tab2-marc_strgr = '10'.          "策略组
1179   wa_tab2-marc_vrmod = '2'.           "消耗模式
1180   wa_tab2-marc_vint1 = '999'.         "逆向消耗期间
1181   wa_tab2-marc_vint2 = '999'.         "向前消耗期间
1182   wa_tab2-marc_altsl = '1'.           "选择方法
1183   wa_tab2-marc_sbdkz = '1'.           "集中/独立
1184   wa_tab2-mpop_prmod = 'D'.           "预测模型
1185   wa_tab2-mbew_val_class = '7920'.    "评估级别
1186   wa_tab2-mbew_ml_settle = '3'.       "价格确定
1187   wa_tab2-mbew_std_price = '5'.       "标准价格
1188   wa_tab2-mbew_price_ctrl = 'S'.      "价格控制
1189   wa_tab2-mbew_orig_mat = 'X'.        "物料来源
1190   wa_tab2-marc_awsls = '000001'.      "差异码
1191   wa_tab2-marc_losgr = '100'.         "成本核算批量
1192   append wa_tab2 to it_tab2.
1193   clear wa_tab2.
1194 
1195   if it_fname is initial.
1196     perform append_filename using:'物料号',
1197           '行业领域',
1198           '物料类型',
1199           '工厂',
1200           '销售组织',
1201           '分销渠道',
1202           '物料描述',
1203           '基本计量单位',
1204           '物料组',
1205           '客户',
1206           '产品组',
1207           '普通项目组类别',
1208           '重量单位',
1209           '替代料标识',
1210           '基本物料',
1211           '客户物料编码',
1212           '交货工厂',
1213           '现金折扣',
1214           '税分类',
1215           '物料统计组',
1216           '科目设置组',
1217           '项目类别组',
1218           '可用性检查',
1219           '运输组',
1220           '装载组',
1221           '采购组',
1222           '自动采购单',
1223           '批次管理',
1224           '收货处理时间',
1225           'MRP组',
1226           'MRP类型',
1227           'MRP控制者',
1228           '批量大小',
1229           '最小批量大小',
1230           '舍入值',
1231           '采购类型',
1232           '特殊采购类型',
1233           '生产仓储地点',
1234           '外部采购仓储地点',
1235           '生产时间',
1236           '计划交货时间',
1237           '安全库存',
1238           '计划边际码',
1239           '策略组',
1240           '消耗模式',
1241           '逆向消耗模式',
1242           '向前消耗模式',
1243           '选择方法',
1244           '集中/独立',
1245           '预测模型',
1246           '评估级别',
1247           '价格确定',
1248           '标准价格',
1249           '价格控制',
1250           '物料来源',
1251           '差异码',
1252           '成本核算批量'.
1253   endif.
1254   lv_string = lv_file.
1255   call function 'GUI_DOWNLOAD'
1256   exporting
1257 *         BIN_FILESIZE                    =
1258     filename                        = lv_string
1259     filetype                        = 'DBF'
1260 *         APPEND                          = ' '
1261     write_field_separator           = 'X'
1262     codepage                        = '8400'   "指定写文件时用的字符集
1263   tables
1264     data_tab                        = it_tab2
1265     fieldnames                      = it_fname[].
1266   if sy-subrc <> 0.
1267 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
1268 *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
1269   endif.
1270   clear:it_tab2,it_fname[],lv_string.
1271 endform.                    "download_templat
1272 
1273 *&---------------------------------------------------------------------*
1274 *&      Form  append_filename
1275 *&---------------------------------------------------------------------*
1276 *       text
1277 *----------------------------------------------------------------------*
1278 *      -->P_NAME     text
1279 *----------------------------------------------------------------------*
1280 form append_filename using p_name .
1281   it_fname-name = p_name.
1282   append it_fname.
1283   clear it_fname.
1284 endform.                    "append_filename
1285 *&---------------------------------------------------------------------*
1286 *&      Form  POP_CONFIRM
1287 *&---------------------------------------------------------------------*
1288 *      弹出确认对话框进行价格判断
1289 *----------------------------------------------------------------------*
1290 *  -->  p1        text
1291 *  <--  p2        text
1292 *----------------------------------------------------------------------*
1293 form pop_confirm using value(char_abc) value(material).
1294   data: resul type c,
1295         str   type char255.
1296   clear:resul,str.
1297   if char_abc = 'A'.
1298     concatenate material '原材料 ' char_abc '类价格大于100,继续导入?' into str.
1299 elseif char_abc = 'B'.
1300     concatenate material '原材料 ' char_abc '类价格大于5,继续导入?' into str.
1301   else.
1302     concatenate material '原材料 ' char_abc '类价格大于1,继续导入?' into str.
1303   endif.
1304   call function 'POPUP_TO_CONFIRM'
1305   exporting
1306     text_question         = str
1307     icon_button_1         = ''
1308     icon_button_2         = ''
1309     default_button        = '1'
1310     display_cancel_button = ''  "显示取消的按钮并可用
1311     start_column          = 40
1312     start_row             = 10
1313   importing
1314     answer                = resul.
1315   if resul = '1'.
1316   else.
1317     concatenate material ' 物料未创建!' into gt_out-text.
1318     append gt_out.
1319     clear gt_out.
1320     flag = 1.
1321     return.
1322   endif.
1323 endform.                    " POP_CONFIRM

在下载模板的时候使用的是 GUI_DOWNLOAD 这个函数,通过这个函数的 filetype = 'DBF',codepage = '8400' 可以保存带有前导零的数据,但是下载的模板抬头的中文的每列最多只能显示五个汉字。

如果 filetype = 'DAT',抬头的文本数据可以完整下载,但是主要数据则会去除数字的前导零。

如果有知道如何解决的话请在评论区留言,谢谢!!!

版权声明:程序员胖胖胖虎阿 发表于 2022年8月29日 下午3:49。
转载请注明:物料主数据批导bapi | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...