bapi sap 创建物料_bapi 物料主数据创建 ‘BAPI_MATERIAL_SAVEDATA’「建议收藏」

2022-09-15 11:07:34 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

CALL FUNCTION ‘BAPI_MATERIAL_SAVEDATA’

2.物料信息的获取bapi : BAPI_MATERIAL_GET_DETAIL

Report ZMMPL001

*&

*&———————————————————————*

*&

*&

*&———————————————————————*

REPORT ZMMPL001.

DATA: pr_unit TYPE meins,”基本计量单位

bapi_exe_result(1) TYPE c.”bapi执行结果标识

*原材料

DATA: BEGIN OF wa_y_material,

marc_plant TYPE werks_d, “工厂

mard_stge_loc TYPE lgort_d,”库存地点

mvke_sales_org TYPE vkorg,”销售组织

mvke_distr_chan TYPE vtweg,”分销渠道

head_material TYPE matnr,”物料号

head_ind_sector TYPE mbrsh,”行业领域

head_matl_type TYPE mtart,”物料类型

t_makt_matl_desc TYPE maktx,”物料描述

mara_base_uom TYPE meins,”基本计量单位

mara_matl_group TYPE matkl,”物料组

mara_extmatlgrp TYPE extwg,”外部物料组

mara_item_cat TYPE mtpos_mara,”普通项目组类别

t_marm_gross_wt TYPE brgew,”毛重

t_marm_unit_of_wt TYPE gewei,”重量单位

mara_net_weight TYPE ntgew,”净重

t_marm_volume TYPE volum,”标准箱

t_marm_volumeunit TYPE voleh,”体积单位

mvke_sales_unit TYPE vrkme,”销售单位

t_mlan_taxclass1 TYPE taxkm, “税分类1

t_mlan_taxclass2 TYPE taxkm, “税分类2

mvke_matl_stats TYPE stgma,”物料统计组

mvke_acct_assgt TYPE ktgrm,”科目设置组

mvke_item_cat TYPE mtpos,”来自物料主文件的项目主类别

marc_availcheck TYPE mtvfp,”可用性检查

mara_trans_grp TYPE tragr,”运输组

marc_loadinggrp TYPE ladgr,”装载组

marc_pur_group TYPE ekgrp,”采购组

marc_batch_mgmt TYPE xchpf,”批次管理标示

marc_auto_p_ord TYPE kautb,”自动采购订单

marc_ind_post_to_insp_stock TYPE insmk_mat,”过账到检验库存

marc_quotausage TYPE usequ,”配额安排

marc_sourcelist TYPE kordb,”源清单

marc_mrp_group TYPE disgr,”MRP组

marc_mrp_type TYPE dismm,””MRP类型

marc_mrp_ctrler TYPE dispo,”MRP控制者

marc_lotsizekey TYPE disls,”批量

marc_minlotsize TYPE bstmi,”最小批量

marc_maxlotsize TYPE bstma,”最大批量

marc_round_val TYPE bstrf,”舍入值

marc_proc_type TYPE beskz,”采购类型

marc_backflush TYPE rgekm,”反冲

marc_plnd_delry TYPE plifz,”计划交货时间

marc_gr_pr_time TYPE webaz,”收货处理时间

marc_safety_stk TYPE eisbe,”安全库存

marc_sm_key TYPE fhori,” 计划边际码

marc_plan_strgp TYPE strgp,”策略组

marc_alt_bom_id TYPE altsl,”选择方法

stge_loc TYPE lgort_d,”库存地点,占位,不用取出赋值,同上边库存地点

mbew_val_class TYPE bklas,”评估类

mbew_price_ctrl TYPE vprsv,”价格控制

mbew_price_unit TYPE peinh,”价格单位

mbew_moving_pr TYPE verpr_bapi,”移动平均价

mbew_std_price TYPE stprs_bapi,”标准价格

mbew_qty_struct TYPE ck_ekalrel,”用QS的成本估算

mbew_orig_mat TYPE hkmat,”物料来源

END OF wa_y_material.

DATA: it_y_material LIKE TABLE OF wa_y_material.

DATA: BEGIN OF wa_message,

material TYPE matnr,

description TYPE maktx,

message(97) TYPE c,

END OF wa_message.

DATA: it_message LIKE TABLE OF wa_message.

*输入参数

DATA: headdata TYPE bapimathead, “表头数据

clientdata TYPE bapi_mara, “基本数据

clientdatax TYPE bapi_marax,

plantdata TYPE bapi_marc, “工厂级别数据

plantdatax TYPE bapi_marcx,

forecastparameters TYPE bapi_mpop, “预测

forecastparametersx TYPE bapi_mpopx,

planningdata TYPE bapi_mpgd, “计划

planningdatax TYPE bapi_mpgdx,

storagelocationdata TYPE bapi_mard, “存储位置

storagelocationdatax TYPE bapi_mardx,

valuationdata TYPE bapi_mbew, “评估数据

valuationdatax TYPE bapi_mbewx,

warehousenumberdata TYPE bapi_mlgn, “仓库数据

warehousenumberdatax TYPE bapi_mlgnx,

salesdata TYPE bapi_mvke, “销售数据

salesdatax TYPE bapi_mvkex,

storagetypedata TYPE bapi_mlgt, “存储类型数据

storagetypedatax TYPE bapi_mlgtx.

*Table参数

DATA: materialdescription TYPE TABLE OF bapi_makt WITH HEADER LINE,”描述

unitsofmeasure TYPE TABLE OF bapi_marm WITH HEADER LINE,”单位

unitsofmeasurex TYPE TABLE OF bapi_marmx WITH HEADER LINE,

taxclassifications TYPE TABLE OF bapi_mlan WITH HEADER LINE.”税分类

*Return

DATA return TYPE bapiret2.

*以上都是准备的参数,it_y_material 存放的就是物料信息内表,具体数据怎么来的省略(一般就是上传文本)

*往往调用一个bapi的时候不知道哪里赋值,怎么赋值,赋什么值,下边是参数赋值、调用示例

FORM create_y_matnr_data.

DATA: total TYPE i,

num type i.

num = 0.

DESCRIBE TABLE it_y_material LINES total.

CLEAR it_message.

LOOP AT it_y_material INTO wa_y_material.

num = num 1.

CLEAR headdata.

headdata-material = wa_y_material-head_material.

headdata-matl_type = wa_y_material-head_matl_type.

headdata-ind_sector = wa_y_material-head_ind_sector.

headdata-basic_view = ‘X’.

headdata-sales_view = ‘X’.

headdata-purchase_view = ‘X’.

headdata-mrp_view = ‘X’.

* headdata-forecast_view = ‘X’.

headdata-warehouse_view = ‘X’.

headdata-account_view = ‘X’.

headdata-cost_view = ‘X’.

“基本数据

CLEAR clientdata.

clientdata-matl_group = wa_y_material-mara_matl_group.

PERFORM get_pr_unit USING wa_y_material-mara_base_uom CHANGING pr_unit.

clientdata-base_uom = pr_unit.

clientdata-extmatlgrp = wa_y_material-mara_extmatlgrp.

clientdata-item_cat = wa_y_material-mara_item_cat.

clientdata-net_weight = wa_y_material-mara_net_weight.

clientdata-trans_grp = wa_y_material-mara_trans_grp.

CLEAR clientdatax.

clientdatax-matl_group = ‘X’.

clientdatax-base_uom = ‘X’.

clientdatax-extmatlgrp = ‘X’.

clientdatax-item_cat = ‘X’.

clientdatax-net_weight = ‘X’.

clientdatax-trans_grp = ‘X’.

“工厂级别数据

CLEAR plantdata.

plantdata-plant = wa_y_material-marc_plant.

plantdata-availcheck = wa_y_material-marc_availcheck.

plantdata-loadinggrp = wa_y_material-marc_loadinggrp.

plantdata-pur_group = wa_y_material-marc_pur_group.

plantdata-batch_mgmt = wa_y_material-marc_batch_mgmt.

plantdata-auto_p_ord = wa_y_material-marc_auto_p_ord.

plantdata-ind_post_to_insp_stock = wa_y_material-marc_ind_post_to_insp_stock.

plantdata-quotausage = wa_y_material-marc_quotausage.

plantdata-sourcelist = wa_y_material-marc_sourcelist.

plantdata-mrp_group = wa_y_material-marc_mrp_group.

plantdata-mrp_type = wa_y_material-marc_mrp_type.

plantdata-mrp_ctrler = wa_y_material-marc_mrp_ctrler.

plantdata-lotsizekey = wa_y_material-marc_lotsizekey.

plantdata-minlotsize = wa_y_material-marc_minlotsize.

plantdata-maxlotsize = wa_y_material-marc_maxlotsize.

plantdata-round_val = wa_y_material-marc_round_val.

plantdata-proc_type = wa_y_material-marc_proc_type.

plantdata-backflush = wa_y_material-marc_backflush.

plantdata-plnd_delry = wa_y_material-marc_plnd_delry.

plantdata-gr_pr_time = wa_y_material-marc_gr_pr_time.

plantdata-safety_stk = wa_y_material-marc_safety_stk.

plantdata-sm_key = wa_y_material-marc_sm_key.

plantdata-plan_strgp = wa_y_material-marc_plan_strgp.

plantdata-alt_bom_id = wa_y_material-marc_alt_bom_id.

CLEAR plantdatax.

plantdatax-plant = wa_y_material-marc_plant.

plantdatax-availcheck = ‘X’.

plantdatax-loadinggrp = ‘X’.

plantdatax-pur_group = ‘X’.

plantdatax-batch_mgmt = ‘X’.

plantdatax-auto_p_ord = ‘X’.

plantdatax-ind_post_to_insp_stock = ‘X’.

plantdatax-quotausage = ‘X’.

plantdatax-sourcelist = ‘X’.

plantdatax-mrp_group = ‘X’.

plantdatax-mrp_type = ‘X’.

plantdatax-mrp_ctrler = ‘X’.

plantdatax-lotsizekey = ‘X’.

plantdatax-minlotsize = ‘X’.

plantdatax-maxlotsize = ‘X’.

plantdatax-round_val = ‘X’.

plantdatax-proc_type = ‘X’.

plantdatax-backflush = ‘X’.

plantdatax-plnd_delry = ‘X’.

plantdatax-gr_pr_time = ‘X’.

plantdatax-safety_stk = ‘X’.

plantdatax-sm_key = ‘X’.

plantdatax-plan_strgp = ‘X’.

plantdatax-alt_bom_id = ‘X’.

“仓库存储数据

CLEAR storagelocationdata.

storagelocationdata-plant = wa_y_material-marc_plant.

storagelocationdata-stge_loc = wa_y_material-mard_stge_loc.

CLEAR storagelocationdatax.

storagelocationdatax-plant = wa_y_material-marc_plant.

storagelocationdatax-stge_loc = wa_y_material-mard_stge_loc.

“销售数据

CLEAR salesdata.

salesdata-sales_org = wa_y_material-mvke_sales_org.

salesdata-distr_chan = wa_y_material-mvke_distr_chan.

salesdata-sales_unit = wa_y_material-mvke_sales_unit.

salesdata-matl_stats = wa_y_material-mvke_matl_stats.

salesdata-acct_assgt = wa_y_material-mvke_acct_assgt.

salesdata-item_cat = wa_y_material-mvke_item_cat.

CLEAR salesdatax.

salesdatax-sales_org = wa_y_material-mvke_sales_org.

salesdatax-distr_chan = wa_y_material-mvke_distr_chan.

salesdatax-sales_unit = ‘X’.

salesdatax-matl_stats = ‘X’.

salesdatax-acct_assgt = ‘X’.

salesdatax-item_cat = ‘X’.

“会计、成本

CLEAR valuationdata.

valuationdata-val_area = wa_y_material-marc_plant.

valuationdata-val_class = wa_y_material-mbew_val_class.

valuationdata-price_ctrl = wa_y_material-mbew_price_ctrl.

valuationdata-price_unit = wa_y_material-mbew_price_unit.

valuationdata-moving_pr = wa_y_material-mbew_moving_pr.

valuationdata-std_price = wa_y_material-mbew_std_price.

valuationdata-qty_struct = wa_y_material-mbew_qty_struct.

valuationdata-orig_mat = wa_y_material-mbew_orig_mat.

CLEAR valuationdatax.

valuationdatax-val_area = wa_y_material-marc_plant.

valuationdatax-val_class = ‘X’.

valuationdatax-price_ctrl = ‘X’.

valuationdatax-price_unit = ‘X’.

valuationdatax-moving_pr = ‘X’.

valuationdatax-std_price = ‘X’.

valuationdatax-qty_struct = ‘X’.

valuationdatax-orig_mat = ‘X’.

“物料描述

CLEAR materialdescription[].

materialdescription-langu_iso = ‘ZH’.

materialdescription-matl_desc = wa_y_material-t_makt_matl_desc.

APPEND materialdescription.

“单位

CLEAR unitsofmeasure[]. unitsofmeasure-alt_unit = pr_unit.

unitsofmeasure-gross_wt = wa_y_material-t_marm_gross_wt.

unitsofmeasure-unit_of_wt = wa_y_material-t_marm_unit_of_wt.

unitsofmeasure-volume = wa_y_material-t_marm_volume.

unitsofmeasure-volumeunit = wa_y_material-t_marm_volumeunit.

APPEND unitsofmeasure.

CLEAR unitsofmeasurex[].

unitsofmeasurex-alt_unit = pr_unit.

unitsofmeasurex-gross_wt = ‘X’.

unitsofmeasurex-unit_of_wt = ‘X’.

unitsofmeasurex-volume = ‘X’.

unitsofmeasurex-volumeunit = ‘X’.

APPEND unitsofmeasurex.

“税分类

CLEAR taxclassifications[].

taxclassifications-depcountry = ‘CN’.

taxclassifications-tax_type_1 = ‘MWST’.

taxclassifications-taxclass_1 = wa_y_material-t_mlan_taxclass1.

taxclassifications-taxclass_2 = wa_y_material-t_mlan_taxclass2.

APPEND taxclassifications.

PERFORM savedata USING num total.

CLEAR wa_message.

wa_message-material = wa_y_material-head_material.

wa_message-description = wa_y_material-t_makt_matl_desc.

wa_message-message = return-message.

APPEND wa_message TO it_message.

ENDLOOP.

ENDFORM. “fill_matnr_data

*保存数据,调用BAPI_MATERIAL_SAVEDATA

FORM savedata USING num total.

CALL FUNCTION ‘BAPI_MATERIAL_SAVEDATA’

EXPORTING

headdata = headdata

clientdata = clientdata

clientdatax = clientdatax

plantdata = plantdata

plantdatax = plantdatax

* forecastparameters = forecastparameters

* forecastparametersx = forecastparametersx

* planningdata = planningdata

* planningdatax = planningdatax

storagelocationdata = storagelocationdata

storagelocationdatax = storagelocationdatax

valuationdata = valuationdata

valuationdatax = valuationdatax

* warehousenumberdata = warehousenumberdata

* warehousenumberdatax = warehousenumberdatax

salesdata = salesdata

salesdatax = salesdatax

* storagetypedata = storagetypedata

* storagetypedatax = storagetypedatax

* flag_online = ‘ ‘

* flag_cad_call = ‘ ‘

* no_dequeue = ‘ ‘

IMPORTING

return = return

TABLES

materialdescription = materialdescription[]

unitsofmeasure = unitsofmeasure[]

unitsofmeasurex = unitsofmeasurex

* INTERNATIONALARTNOS =

* MATERIALLONGTEXT =

taxclassifications = taxclassifications[]

* RETURNMESSAGES =

* PRTDATA =

* PRTDATAX =

* EXTENSIONIN =

* EXTENSIONINX =

.

IF sy-subrc = 0.

CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’

EXPORTING

wait = ‘X’

* IMPORTING

* RETURN =

.

bapi_exe_result = ‘X’.

ELSE.

bapi_exe_result = ”.

ENDIF.

WAIT UP TO 1 SECONDS.

DATA: per TYPE f,

txt TYPE string.

per = ( num / total ) * 100.

DATA: str1 TYPE string,

str2 TYPE string.

str1 = num.

str2 = total.

CONCATENATE ‘正在批量创建物料…已完成:(‘ str1 ‘/’ str2 ‘)’ INTO txt.

CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR’

EXPORTING

percentage = per

text = txt.

ENDFORM. “SAVEDATA

*获取基本计量单位内码

FORM get_pr_unit USING unit1 CHANGING unit2.

SELECT SINGLE msehi INTO unit2 FROM t006a WHERE spras = 1 AND mseh3 = unit1.

IF sy-subrc <> 0.

unit2 = unit1.

ENDIF.

ENDFORM.

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/163919.html原文链接:https://javaforall.cn

0 人点赞