1.用于创建与更改物料主数据的核心代码,算是比较全了。
*****创建物料主数据使用
DATA gw_headdata LIKE bapimathead. "声明带有控制信息的表头段
DATA gw_clientdata LIKE bapi_mara. "声明客户端层次物料数据
DATA gw_bapi_te_marax LIKE bapi_te_marax. "声明客户端层次物料数据
DATA gw_bapi_te_mara LIKE bapi_te_mara. "声明客户端层次物料数据
DATA gw_clientdatax LIKE bapi_marax. "声明BAPI_MARA 的复选框结构
DATA gw_plantdata LIKE bapi_marc. "声明工厂级别的物料数据
DATA gw_plantdatax LIKE bapi_marcx. "声明BAPI_MARC 的复选框结构
DATA gw_bapi_mard LIKE bapi_mard. "存储位置级别的物料数据
DATA gw_bapi_mardx LIKE bapi_mardx. "BAPI_MARD 的复选框结构
DATA gw_valuationdata LIKE bapi_mbew. "声明评估数据
DATA gw_valuationdatax LIKE bapi_mbewx. "BAPI_MBEW 的复选框结构
DATA gw_return LIKE bapiret2. "声明RETURN
DATA lt_extensionin LIKE TABLE OF bapiparex.
DATA lw_extensionin LIKE bapiparex.
DATA lt_extensioninx LIKE TABLE OF bapiparexx.
DATA lw_extensioninx LIKE bapiparexx.
DATA gw_mvkex LIKE bapi_mvkex.
DATA gw_mvke LIKE bapi_mvke.
DATA gt_mater LIKE bapi_makt OCCURS 10 WITH HEADER LINE.
DATA gt_mlan LIKE bapi_mlan OCCURS 10 WITH HEADER LINE.
DATA gt_unit LIKE bapi_marm OCCURS 10 WITH HEADER LINE.
DATA gt_unitx LIKE bapi_marmx OCCURS 10 WITH HEADER LINE.
DATA gt_qmat LIKE bapi1001004_qmat OCCURS 0 WITH HEADER LINE.
DATA gt_return LIKE bapi_matreturn2 OCCURS 0 WITH HEADER LINE.
DATA gw_mlgndata LIKE bapi_mlgn. "仓库号数据
DATA gw_mlgndatax LIKE bapi_mlgnx. "仓库号数据的复选框结构
DATA gw_mlgtdata LIKE bapi_mlgt. "仓储类型数据
DATA gw_mlgtdatax LIKE bapi_mlgtx. "仓储类型数据复选框结构
*全局临时变量
DATA: gv_create TYPE c."是否为创建物料 X 为创建新物料
DATA: lt_save_log TYPE TABLE OF ztmdm_007_log.
"产生guid 作为日志表的唯一主键。 并且作为接口平台的关键数据
DATA:lv_guid TYPE sysuuid_c32.
TRY.
CALL METHOD cl_system_uuid=>if_system_uuid_static~create_uuid_c32
RECEIVING
uuid = lv_guid.
CATCH cx_uuid_error .
ENDTRY.
"gt_alv 就是物料+工厂的数据
LOOP AT gt_alv INTO ls_alv.
"给物料填充前导零,全局变量赋值--接口或者excel导入都能使用到
PERFORM f_input CHANGING ls_alv
gv_create.
*---扩充那几个视图
PERFORM f_headdata USING ls_alv
CHANGING gw_headdata . "填充抬头HEADDATA
*---基本视图
PERFORM f_clientdata TABLES lt_extensionin "填充CLIENTDATA
lt_extensioninx
USING ls_alv
gv_create
CHANGING gw_clientdatax
gw_clientdata
gw_bapi_te_marax
gw_bapi_te_mara
.
*---工厂级别的物料数据
PERFORM f_plantdata USING ls_alv
CHANGING gw_plantdata
gw_plantdatax .
*---物料描述语言
PERFORM f_mater TABLES gt_mater
USING ls_alv .
*---评估数据
PERFORM f_valuationdata USING ls_alv
gv_create
CHANGING gw_valuationdatax
gw_valuationdata.
*---销售数据
IF gw_headdata-sales_view = 'X'. "销售视图为X
PERFORM f_mvke USING ls_alv
CHANGING gw_mvke
gw_mvkex .
ENDIF.
*---税收数据
PERFORM f_mlan TABLES gt_mlan
USING ls_alv.
*---计量单位维护
PERFORM f_unit TABLES gt_unitx "
gt_unit
USING ls_alv.
*----质量视图
IF gw_headdata-quality_view = 'X'. "质量管理视图为X
PERFORM f_qmat TABLES gt_qmat
USING ls_alv.
ENDIF.
*--仓储视图
IF gw_headdata-warehouse_view = 'X'. "仓库管理视图为X
PERFORM frm_set_mlgn_data USING ls_alv
CHANGING gw_mlgndata
gw_mlgndatax
gw_mlgtdata
gw_mlgtdatax.
ENDIF.
*----存储视图为X
IF gw_headdata-storage_view = 'X'.
PERFORM frm_set_MARD_data USING ls_alv
CHANGING gw_bapi_mard
gw_bapi_mardx.
ENDIF.
*调取BAPI
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = gw_headdata
clientdata = gw_clientdata
clientdatax = gw_clientdatax
plantdata = gw_plantdata
plantdatax = gw_plantdatax
salesdata = gw_mvke
salesdatax = gw_mvkex
valuationdata = gw_valuationdata
valuationdatax = gw_valuationdatax
warehousenumberdata = gw_mlgndata
warehousenumberdatax = gw_mlgndatax
storagelocationdata = gw_bapi_mard
storagelocationdatax = gw_bapi_mardX
storagetypedata = gw_mlgtdata
storagetypedatax = gw_mlgtdatax
IMPORTING
return = gw_return
TABLES
materialdescription = gt_mater[]
unitsofmeasure = gt_unit[]
unitsofmeasurex = gt_unitx[]
taxclassifications = gt_mlan[]
returnmessages = gt_return[]
extensionin = lt_extensionin
extensioninx = lt_extensioninx.
IF gw_return-type EQ 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
"在接口的时候返回一个表
"gs_detil_msg-matnr = ls_alv-matnr.
"gs_detil_msg-werks = ls_alv-werks.
"gs_detil_msg-ztype = 'E'.
"gs_detil_msg-zmessge = gw_return-message.
"APPEND gs_detil_msg TO gs_return-message_table .
"如果是alv导入程序,就直接更改当前行的消息内容。
PERFORM save_to_ztmdm_007_log USING ls_alv gw_return-message
gs_detil_msg-ztype
lv_guid .
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
"SAP物料主数据创建质量管理视图后添加检验类型
CLEAR gt_return[].
CALL FUNCTION 'BAPI_MATINSPCTRL_SAVEREPLICA'
TABLES
return = gt_return[]
inspectionctrl = gt_qmat[].
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = ''.
"存结果物料加工厂,最新结果表--
"ztmdm_007 是自建表以物料、工厂为主键
PERFORM save_to_ztmdm_007 USING ls_alv
gv_create ."保存到底表
"存到日志表,接口使用的日志记录表,主键为guiid32。excel导入就不要使用这个了
PERFORM save_to_ztmdm_007_log USING ls_alv gw_return-message
gs_detil_msg-ztype
lv_guid .
ENDIF.
*清空表和工作区
CLEAR:gw_headdata ,
gw_clientdata ,
gw_bapi_te_marax ,
gw_bapi_te_mara ,
gw_clientdatax ,
gw_plantdata ,
gw_plantdatax ,
gw_bapi_mard ,
gw_bapi_mardx ,
gw_valuationdata ,
gw_valuationdatax ,
gw_return ,
lt_extensionin ,
lw_extensionin ,
lt_extensioninx ,
lw_extensioninx ,
gw_mvkex ,
gw_mvke ,
gt_mater ,
gt_mlan ,
gt_unit ,
gt_unitx ,
gt_qmat ,
gt_return ,
gw_mlgndata ,
gw_mlgndatax ,
gw_mlgtdata ,
gw_mlgtdatax ,
gs_detil_msg .
REFRESH:lt_extensionin[],lt_extensioninx[],gt_mater[],gt_mlan[],gt_unit[],gt_unitx[],gt_qmat[],gt_return[].
ENDLOOP.
*-----------以下都是 PERFORM 详细逻辑
FORM f_headdata USING gs_alv TYPE zsmdm_matnr_detail
CHANGING gw_headdata TYPE bapimathead .
DATA material_number LIKE bapimatinr OCCURS 0 WITH HEADER LINE.
CLEAR gw_headdata .
DATA l_len TYPE i.
gw_headdata-material = gs_alv-matnr.
l_len = 0.
l_len = strlen( gs_alv-matnr ).
IF l_len > 18.
gw_headdata-material_long = gs_alv-matnr. "物料号
ENDIF.
gw_headdata-ind_sector = 'M'. "行业领域
gw_headdata-matl_type = gs_alv-mtart. "物料类型
gw_headdata-basic_view = 'X'. "基本数据视图为X
IF gs_alv-vkorg IS NOT INITIAL.
gw_headdata-sales_view = 'X'. "销售视图为X
ENDIF.
IF gs_alv-ekgrp IS NOT INITIAL.
gw_headdata-purchase_view = 'X'. "采购视图为X
ENDIF.
IF gs_alv-disgr IS NOT INITIAL.
gw_headdata-mrp_view = 'X'. "物料需求计划(MRP)视图为X
ENDIF.
* GW_HEADDATA-FORECAST_VIEW = 'X'. "预测视图为X
IF gs_alv-mtart = 'Z100' OR gs_alv-mtart = 'Z200' OR gs_alv-mtart = 'Z300'
OR gs_alv-mtart = 'Z460' OR gs_alv-mtart = 'Z470' OR gs_alv-mtart = 'ZR00'.
gw_headdata-work_sched_view = 'X'. "工作计划视图为X
ENDIF.
* GW_HEADDATA-PRT_VIEW = 'X'. "生产资源/工具(PRT)视图为X
IF gs_alv-lgtyp IS NOT INITIAL.
gw_headdata-warehouse_view = 'X'. "仓库管理视图为X
ENDIF.
IF gs_alv-prctr IS NOT INITIAL."利润中心不为空,开启视图
gw_headdata-storage_view = 'X'. "存储视图为X
ENDIF.
IF gs_alv-art IS NOT INITIAL.
gw_headdata-quality_view = 'X'. "质量管理视图为X
ENDIF.
IF gs_alv-bklas IS NOT INITIAL.
gw_headdata-account_view = 'X'. "会计视图为X
gw_headdata-cost_view = 'X'. "成本视图为X
* ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_INPUT
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& --> P1 TEXT
*& <-- P2 TEXT
*&---------------------------------------------------------------------*
FORM f_input CHANGING gs_alv TYPE zsmdm_matnr_detail
lv_create TYPE c.
"物料
CALL FUNCTION 'CONVERSION_EXIT_MATN5_INPUT'
EXPORTING
input = gs_alv-matnr
IMPORTING
output = gs_alv-matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
ENDIF.
"LV_CREATE 是否为创建物料。
CLEAR:lv_create.
SELECT SINGLE matnr FROM marc
WHERE matnr = @gs_alv-matnr
AND werks = @gs_alv-werks
INTO @DATA(lv_matnr).
IF sy-subrc NE 0.
lv_create = 'X'.
ENDIF.
"单位转换------------------------------------
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = gs_alv-meins
language = sy-langu
IMPORTING
output = gs_alv-meins
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = gs_alv-vrkme
language = sy-langu
IMPORTING
output = gs_alv-vrkme
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = gs_alv-bstme
language = sy-langu
IMPORTING
output = gs_alv-bstme
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
"生产订单转换
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = gs_alv-frtme
language = sy-langu
IMPORTING
output = gs_alv-frtme
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
*----选中字段赋值为X---接口传过来是1 SAP 转化为 X--------------
IF gs_alv-xchpf = '1'.
gs_alv-xchpf = 'X'.
ELSE.
gs_alv-xchpf = ''.
ENDIF.
IF gs_alv-apa = '1'.
gs_alv-apa = 'X'.
ELSE.
gs_alv-apa = ''.
ENDIF.
IF gs_alv-aktiv = '1'.
gs_alv-aktiv = 'X'.
ELSE.
gs_alv-aktiv = ''.
ENDIF.
IF gs_alv-mlmaa = '1'.
gs_alv-mlmaa = 'X'.
ELSE.
gs_alv-mlmaa = ''.
ENDIF.
IF gs_alv-ekalr = '1'.
gs_alv-ekalr = 'X'.
ELSE.
gs_alv-ekalr = ''.
ENDIF.
IF gs_alv-hkmat = '1'.
gs_alv-hkmat = 'X'.
ELSE.
gs_alv-hkmat = ''.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_CLIENTDATA
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& <-- GW_CLIENTDATAX
*& <-- GW_CLIENTDATA
*&---------------------------------------------------------------------*
FORM f_clientdata TABLES lt_extensionin STRUCTURE bapiparex
lt_extensioninx STRUCTURE bapiparexx
USING gs_alv TYPE zsmdm_matnr_detail
lv_create TYPE c
CHANGING gw_clientdatax TYPE bapi_marax
gw_clientdata TYPE bapi_mara
gw_bapi_te_marax TYPE bapi_te_marax "声明客户端层次物料数据
gw_bapi_te_mara TYPE bapi_te_mara . "声明客户端层次物料数据
DATA: lw_extensionin TYPE bapiparex,
lw_extensioninx TYPE bapiparexx.
CLEAR gw_clientdatax.
CLEAR gw_clientdata.
gw_clientdata-base_uom = gs_alv-meins.
gw_clientdatax-base_uom = 'X'.
gw_clientdata-base_uom_iso = gs_alv-meins. "基本计量单位
gw_clientdatax-base_uom_iso = 'X'.
" GW_CLIENTDATA-OLD_MAT_NO = GS_ALV-BISMT. "旧物料号
" GW_CLIENTDATAX-OLD_MAT_NO = 'X'.
gw_clientdata-matl_group = gs_alv-matkl. "物料组
gw_clientdatax-matl_group = 'X'.
" GW_CLIENTDATA-EXTMATLGRP = GS_ALV-EXTWG. "外部物料组
" GW_CLIENTDATAX-EXTMATLGRP = 'X'.
gw_clientdata-division = gs_alv-spart. "产品组
gw_clientdatax-division = 'X'.
gw_clientdata-prod_hier = gs_alv-prdha."产品层次
gw_clientdatax-prod_hier = 'X'.
gw_clientdata-size_dim = gs_alv-groes. "大小/纲领
gw_clientdatax-size_dim = 'X'.
gw_clientdata-net_weight = gs_alv-ntgew. "净重
gw_clientdatax-net_weight = 'X'.
IF gs_alv-gewei = '' AND gs_alv-ntgew = 0.
gs_alv-gewei = 'KG' .
ENDIF.
gw_clientdata-unit_of_wt = gs_alv-gewei. "重量单位
IF NOT gw_clientdata-unit_of_wt IS INITIAL .
gw_clientdatax-unit_of_wt = 'X'.
ENDIF.
gw_clientdata-unit_of_wt_iso = gs_alv-gewei. "重量单位
IF NOT gw_clientdata-unit_of_wt_iso IS INITIAL .
gw_clientdatax-unit_of_wt_iso = 'X'.
ENDIF.
gw_clientdata-allwd_vol = gs_alv-volum. "体积
IF gw_clientdata-allwd_vol <> 0 .
gw_clientdatax-allwd_vol = 'X'.
ENDIF.
gw_clientdata-pack_vo_un = gs_alv-voleh. "体积单位
gw_clientdatax-pack_vo_un = 'X'.
SELECT SINGLE matnr
FROM mara
WHERE matnr = @gs_alv-matnr
INTO @DATA(lv_c).
IF sy-subrc NE 0."新创建物料
gw_clientdata-batch_mgmt = gs_alv-xchpf. "批次管理
gw_clientdatax-batch_mgmt = 'X'.
gw_clientdata-pur_status = gs_alv-mstae. "跨工厂物料状态
gw_clientdatax-pur_status = 'X'.
ELSE."更改物料
IF gs_alv-mstae NE '06'."状态不是06,SAP进行接受更改
gw_clientdata-pur_status = gs_alv-mstae. "跨工厂物料状态
gw_clientdatax-pur_status = 'X'.
ENDIF.
ENDIF.
CLEAR:lv_c.
*
gw_clientdata-basic_matl = gs_alv-wrkst. "K3物料号
gw_clientdatax-basic_matl = 'X'.
gw_clientdata-po_unit = gs_alv-bstme. "采购单位
gw_clientdatax-po_unit = 'X'.
gw_clientdata-minremlife = gs_alv-mhdrz. "最小剩余货架寿命
gw_clientdatax-minremlife = 'X'.
gw_clientdata-shelf_life = gs_alv-mhdhb. "总货架寿命
gw_clientdatax-shelf_life = 'X'.
* GW_CLIENTDATA-PERIOD_IND_EXPIRATION_DATE = GS_ALV-IPRKZ. "SLED的期间标识
* GW_CLIENTDATAX-PERIOD_IND_EXPIRATION_DATE = 'X'.
* GW_CLIENTDATA-TEMP_CONDS = GS_ALV-TEMPB. "温度条件
* GW_CLIENTDATA-STOR_CONDS = GS_ALV-RAUBE. "存储条件
* GW_CLIENTDATA-QM_PROCMNT = GS_ALV-QMPUR. "存储条件
* GW_CLIENTDATAX-QM_PROCMNT = 'X'.
gw_clientdata-trans_grp = '0001'. "存储条件
gw_clientdatax-trans_grp = 'X'.
* GW_CLIENTDATA-DSN_OFFICE = GS_ALV-LABOR.
* GW_CLIENTDATAX-DSN_OFFICE = 'X'.
* GW_CLIENTDATA-PROD_MEMO = GS_ALV-FERTH.
* GW_CLIENTDATAX-PROD_MEMO = 'X'.
gw_clientdata-serialization_level = gs_alv-serlv.
gw_clientdatax-serialization_level = 'X'.
gw_clientdata-doc_vers = gs_alv-zeivr. "版本
gw_clientdatax-doc_vers = 'X'.
gw_clientdata-document = gs_alv-zeinr."凭证(图号)
gw_clientdatax-document = 'X'.
"客户特殊扩展字段
CLEAR gw_bapi_te_mara .
CLEAR gw_bapi_te_marax .
CLEAR lw_extensionin .
CLEAR lw_extensioninx .
REFRESH lt_extensioninx .
REFRESH lt_extensionin .
gw_bapi_te_mara-material = gs_alv-matnr .
gw_bapi_te_marax-material = gs_alv-matnr .
gw_bapi_te_mara-zprojc = gs_alv-zprojc .
IF NOT gw_bapi_te_mara-zprojc IS INITIAL .
gw_bapi_te_marax-zprojc = 'X' .
ENDIF.
gw_bapi_te_mara-zmlqc = gs_alv-zmlqc .
IF NOT gw_bapi_te_mara-zmlqc IS INITIAL .
gw_bapi_te_marax-zmlqc = 'X' .
ENDIF.
* GW_BAPI_TE_MARA-ZMLSZ = GS_ALV-ZMLSZ .
* IF NOT GW_BAPI_TE_MARA-ZMLSZ IS INITIAL .
* GW_BAPI_TE_MARAX-ZMLSZ = 'X' .
* ENDIF.
gw_bapi_te_mara-zspec = gs_alv-zspec .
gw_bapi_te_marax-zspec = 'X' .
IF gw_bapi_te_mara IS NOT INITIAL .
gw_bapi_te_mara-material = gs_alv-matnr .
gw_bapi_te_marax-material = gs_alv-matnr .
lw_extensionin-structure = 'BAPI_TE_MARA'.
lw_extensionin+30 = gw_bapi_te_mara.
APPEND lw_extensionin TO lt_extensionin.
lw_extensioninx-structure = 'BAPI_TE_MARAX'.
lw_extensioninx+30 = gw_bapi_te_marax.
APPEND lw_extensioninx TO lt_extensioninx.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_PLANTDATA
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& --> LS_ALV
*& <-- GW_PLANTDATA
*& <-- GW_PLANTDATAX
*&---------------------------------------------------------------------*
FORM f_plantdata USING gs_alv TYPE zsmdm_matnr_detail
CHANGING gw_plantdata TYPE bapi_marc "
gw_plantdatax TYPE bapi_marcx."
CLEAR gw_plantdata.
CLEAR gw_plantdatax.
gw_plantdata-plant = gs_alv-werks. "获取工厂号
gw_plantdatax-plant = gw_plantdata-plant. "
gw_plantdata-pur_group = gs_alv-ekgrp. "采购组
gw_plantdatax-pur_group = 'X'. "
gw_plantdata-mrp_type = gs_alv-dismm. "MRP类型规则
gw_plantdatax-mrp_type = 'X'. "
gw_plantdata-insp_int = gs_alv-prfrq. "MRP类型规则
gw_plantdatax-insp_int = 'X'. "
"工厂批次管理
SELECT SINGLE xchpf
FROM mara
WHERE matnr = @gs_alv-matnr
INTO @DATA(lv_xchpf).
IF sy-subrc = 0.
gw_plantdatax-batch_mgmt = 'X'.
gw_plantdata-batch_mgmt = lv_xchpf ." gs_alv-xchpf. "MRP类型规则
ELSE.
gw_plantdatax-batch_mgmt = 'X'.
gw_plantdata-batch_mgmt = gs_alv-xchpf. "MRP类型规则
ENDIF.
CLEAR:lv_xchpf.
* GW_PLANTDATA-QUOTAUSAGE = GS_ALV-USEQU. "配额安排
* GW_PLANTDATAX-QUOTAUSAGE = 'X'. "
IF gs_alv-kordb = '1'.
gw_plantdata-sourcelist = 'X'."gs_alv-kordb. "标识: 源清单要求
gw_plantdatax-sourcelist = 'X'. "
ENDIF.
* GW_PLANTDATA-CRIT_PART = GS_ALV-KZKRI. "标志:关键部件
* GW_PLANTDATAX-CRIT_PART = 'X'. "
gw_plantdata-mrp_ctrler = gs_alv-dispo. "MRP控制者
gw_plantdatax-mrp_ctrler = 'X'. "
gw_plantdata-pur_status = gs_alv-mmsta. "工厂状态
gw_plantdatax-pur_status = 'X'. "
gw_plantdata-reorder_pt = gs_alv-minbe. "再订货点
gw_plantdatax-reorder_pt = 'X'. "
gw_plantdata-safety_stk = gs_alv-eisbe. "安全库存
gw_plantdatax-safety_stk = 'X'. "
gw_plantdata-lotsizekey = gs_alv-disls. "批量大小
gw_plantdatax-lotsizekey = 'X'. "
gw_plantdata-fixed_lot = gs_alv-bstfe. "固定批量
gw_plantdatax-fixed_lot = 'X'. "
gw_plantdata-minlotsize = gs_alv-bstmi. "最小批量
gw_plantdatax-minlotsize = 'X'. "
gw_plantdata-round_val = gs_alv-bstrf. "舍入值
gw_plantdatax-round_val = 'X'. "
gw_plantdata-proc_type = gs_alv-beskz. "采购类型
gw_plantdatax-proc_type = 'X'. "
gw_plantdata-spproctype = gs_alv-sobsl. "特殊采购类
gw_plantdatax-spproctype = 'X'. "
IF gs_alv-schgt = '1'.
gw_plantdata-bulk_mat = 'X'. "散装物料
ENDIF.
gw_plantdatax-bulk_mat = 'X'. "
gw_plantdata-backflush = gs_alv-rgekz. "反冲
gw_plantdatax-backflush = 'X'. "
gw_plantdata-iss_st_loc = gs_alv-lgpro. "生产仓储地点
gw_plantdatax-iss_st_loc = 'X'. "
gw_plantdata-inhseprodt = gs_alv-dzeit. "自制生产
gw_plantdatax-inhseprodt = 'X'. "
gw_plantdata-plnd_delry = gs_alv-plifz. "计划交货时间
gw_plantdatax-plnd_delry = 'X'. "
gw_plantdata-gr_pr_time = gs_alv-webaz. "收货处理时间
gw_plantdatax-gr_pr_time = 'X'. "
gw_plantdata-sm_key = gs_alv-fhori. "计划边际码
gw_plantdatax-sm_key = 'X'. "
gw_plantdata-plan_strgp = gs_alv-strgr. "计划策略组
gw_plantdatax-plan_strgp = 'X'. "
gw_plantdata-mixed_mrp = gs_alv-miskz. "综合MRP标识
gw_plantdatax-mixed_mrp = 'X'. "
gw_plantdata-consummode = gs_alv-vrmod. "消耗模式
gw_plantdatax-consummode = 'X'. "
gw_plantdata-bwd_cons = gs_alv-vint1. "消耗期间:逆向
gw_plantdatax-bwd_cons = 'X'. "
gw_plantdata-fwd_cons = gs_alv-vint2. "消耗时期-顺向
gw_plantdatax-fwd_cons = 'X'. "
gw_plantdata-availcheck = gs_alv-mtvfp. "可用性检查
gw_plantdata-availcheck = '02'.
IF gw_plantdata-availcheck IS NOT INITIAL.
gw_plantdatax-availcheck = 'X'. "
ENDIF.
gw_plantdata-dep_req_id = gs_alv-sbdkz. "独立/集中
gw_plantdatax-dep_req_id = 'X'. "
* GW_PLANTDATA-ALT_BOM_ID = GS_ALV-ALTSL. "BOM选择方法
* GW_PLANTDATAX-ALT_BOM_ID = 'X'. "
gw_plantdata-no_costing = gs_alv-ncost. "存储条件
gw_plantdatax-no_costing = 'X'. "
* GW_PLANTDATA-VARIANCE_KEY = GS_ALV-AWSLS."差异码
* GW_PLANTDATAX-VARIANCE_KEY = 'X'. "
* GW_PLANTDATA-CO_PRODUCT = GS_ALV-KZKUP."联产品
* GW_PLANTDATAX-CO_PRODUCT = 'X'. "
IF gs_alv-prctr IS NOT INITIAL.
gw_plantdata-profit_ctr = gs_alv-prctr."利润中心
gw_plantdatax-profit_ctr = 'X'.
ENDIF. "
* GW_PLANTDATA-LOT_SIZE = GS_ALV-LOSGR."成本核算批量
* GW_PLANTDATAX-LOT_SIZE = 'X'. "
* GW_PLANTDATA-CTRL_KEY = GS_ALV-SSQSS. "QM控制码
* GW_PLANTDATAX-CTRL_KEY = 'X'. "
* GW_PLANTDATA-STGEPERIOD = GS_ALV-MAXLZ. "QM控制码
* GW_PLANTDATAX-STGEPERIOD = 'X'. "
* GW_PLANTDATA-STGE_PD_UN = GS_ALV-LZEIH.
* GW_PLANTDATAX-STGE_PD_UN = 'X'. "
gw_plantdata-serno_prof = gs_alv-sernp.
gw_plantdatax-serno_prof = 'X'. "
* GW_PLANTDATA-HANDLG_GRP = GS_ALV-LOGGR.
* GW_PLANTDATAX-HANDLG_GRP = 'X'. "
* GW_PLANTDATA-ALTERNATIVE_BOM = GS_ALV-STLAL.
* GW_PLANTDATAX-ALTERNATIVE_BOM = 'X'. "
* GW_PLANTDATA-BOM_USAGE = GS_ALV-STLAN.
* GW_PLANTDATAX-BOM_USAGE = 'X'. "
"ADDED BY IBMQJK 20200711
* GW_PLANTDATA-ISSUE_UNIT = GS_ALV-AUSME.
* GW_PLANTDATAX-ISSUE_UNIT = 'X'. "
gw_plantdata-mrp_group = gs_alv-disgr.
gw_plantdatax-mrp_group = 'X'. "
gw_plantdata-abc_id = gs_alv-maabc.
gw_plantdatax-abc_id = 'X'. "
gw_plantdata-maxlotsize = gs_alv-bstma.
gw_plantdatax-maxlotsize = 'X'. "
gw_plantdata-max_stock = gs_alv-mabst.
gw_plantdatax-max_stock = 'X'. "
gw_plantdata-round_prof = gs_alv-rdprf.
gw_plantdatax-round_prof = 'X'. "
gw_plantdata-sloc_exprc = gs_alv-lgfsb.
gw_plantdatax-sloc_exprc = 'X'. "
gw_plantdata-comp_scrap = gs_alv-kausf.
gw_plantdatax-comp_scrap = 'X'. "
gw_plantdata-discontinu = gs_alv-kzaus.
gw_plantdatax-discontinu = 'X'. "
gw_plantdata-eff_o_day = gs_alv-ausdt.
gw_plantdatax-eff_o_day = 'X'. "
gw_plantdata-follow_up = gs_alv-nfmat.
gw_plantdatax-follow_up = 'X'. "
gw_plantdata-production_scheduler = gs_alv-fevor.
gw_plantdatax-production_scheduler = 'X'.
gw_plantdata-prod_unit = gs_alv-frtme.
gw_plantdatax-prod_unit = 'X'. "
gw_plantdata-prodprof = gs_alv-sfcpf.
gw_plantdatax-prodprof = 'X'. "
gw_plantdata-under_tol = gs_alv-uneto.
gw_plantdatax-under_tol = 'X'. "
gw_plantdata-over_tol = gs_alv-ueeto.
gw_plantdatax-over_tol = 'X'.
"
gw_plantdata-loadinggrp = '0001'.
gw_plantdatax-loadinggrp = 'X'. "
gw_plantdata-unlimited = gs_alv-ueetk.
gw_plantdatax-unlimited = 'X'. "
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_MATER
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& --> GT_MATER
*& --> LS_ALV
*&---------------------------------------------------------------------*
FORM f_mater TABLES gt_mater STRUCTURE bapi_makt
USING gs_alv TYPE zsmdm_matnr_detail .
REFRESH gt_mater.
IF gs_alv-maktx <> ''.
CLEAR gt_mater.
gt_mater-matl_desc = gs_alv-maktx. "物料描述
gt_mater-langu_iso = 'ZH'. "使用ZH语言
APPEND gt_mater.
ENDIF.
* IF GS_ALV-MAKTX1 <> ''.
* CLEAR GT_MATER.
* GT_MATER-MATL_DESC = GS_ALV-MAKTX1. "物料描述
* GT_MATER-LANGU_ISO = 'EN'. "使用ZH语言
* APPEND GT_MATER.
* ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_VALUATIONDATA
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& --> LS_ALV
*& <-- GW_VALUATIONDATAX
*& <-- GW_VALUATIONDATA
*&---------------------------------------------------------------------*
FORM f_valuationdata USING gs_alv TYPE zsmdm_matnr_detail
gv_create TYPE c
CHANGING gw_valuationdatax LIKE bapi_mbewx
gw_valuationdata LIKE bapi_mbew ."声明评估数据
CLEAR gw_valuationdatax.
CLEAR gw_valuationdata.
gw_valuationdata-val_area = gs_alv-werks . "评估类
IF gw_valuationdata-val_area IS NOT INITIAL.
gw_valuationdatax-val_area = gs_alv-werks ."
ENDIF.
"当物料对应的物料组matkl为“2905003( 商业软件类)“时,评估类 "bklas" 字段值替换为"5010" -from liangfl
IF gs_alv-matkl = '2905003'.
gw_valuationdata-val_class = '5010'.
ELSE.
gw_valuationdata-val_class = gs_alv-bklas .
ENDIF.
IF gw_valuationdata-val_class IS NOT INITIAL.
gw_valuationdatax-val_class = gw_valuationdata-val_class . "评估类
ENDIF.
gw_valuationdata-vm_so_stk = ''." GS_ALV-EKLAS. "VC:销售订单库存
IF gw_valuationdata-vm_so_stk IS NOT INITIAL.
gw_valuationdatax-vm_so_stk = 'X'. "VC:销售订单库存
ENDIF.
gw_valuationdata-ml_settle = gs_alv-mlast. "价格确定
IF gw_valuationdata-ml_settle IS NOT INITIAL.
gw_valuationdatax-ml_settle = 'X'. "VC:销售订单库存
ENDIF.
gw_valuationdata-ml_active = gs_alv-mlmaa. "ML作业
IF gw_valuationdata-ml_active IS NOT INITIAL.
gw_valuationdatax-ml_active = 'X'. "VC:销售订单库存
ENDIF.
* GW_VALUATIONDATA-PRICE_CTRL = ''." GS_ALV-VPRSV."价格控制
* IF GW_VALUATIONDATA-PRICE_CTRL IS NOT INITIAL.
* GW_VALUATIONDATAX-PRICE_CTRL = 'X'. "VC:销售订单库存
* ENDIF.
* GW_VALUATIONDATA-PRICE_UNIT = ''." GS_ALV-PEINH."价格单位
* IF GW_VALUATIONDATA-PRICE_UNIT IS NOT INITIAL.
* GW_VALUATIONDATAX-PRICE_UNIT = 'X'. "VC:销售订单库存
* ENDIF.
* GW_VALUATIONDATA-MOVING_PR = ''." GS_ALV-VERPR."移动平均价
* IF GW_VALUATIONDATA-MOVING_PR IS NOT INITIAL.
* GW_VALUATIONDATAX-MOVING_PR = 'X'. "VC:销售订单库存
* ENDIF.
* GW_VALUATIONDATA-STD_PRICE = ''." GS_ALV-STPRS."标准价格
* IF GW_VALUATIONDATA-STD_PRICE IS NOT INITIAL.
* GW_VALUATIONDATAX-STD_PRICE = 'X'. "VC:销售订单库存
* ENDIF.
gw_valuationdata-qty_struct = gs_alv-ekalr."用QS的成本估算
IF gw_valuationdata-qty_struct IS NOT INITIAL.
gw_valuationdatax-qty_struct = 'X'. "VC:销售订单库存
ENDIF.
gw_valuationdata-orig_mat = gs_alv-hkmat."物料来源
IF gw_valuationdata-orig_mat IS NOT INITIAL.
gw_valuationdatax-orig_mat = 'X'. "VC:销售订单库存
ENDIF.
gw_valuationdata-orig_group = gs_alv-hrkft."原始组
IF gw_valuationdata-orig_group IS NOT INITIAL.
gw_valuationdatax-orig_group = 'X'. "VC:销售订单库存
ENDIF.
gw_valuationdata-plndprice1 = gs_alv-zplp1."计划价格1
IF gw_valuationdata-plndprice1 IS NOT INITIAL.
gw_valuationdatax-plndprice1 = 'X'. "VC:销售订单库存
ENDIF.
gw_valuationdata-plndprdate1 = gs_alv-zpld1."计划价格日期1
IF gw_valuationdata-plndprdate1 IS NOT INITIAL.
gw_valuationdatax-plndprdate1 = 'X'. "VC:销售订单库存
ENDIF.
IF gv_create = 'X'.
gw_valuationdata-pr_ctrl_py = 'S'.
gw_valuationdatax-pr_ctrl_py = 'X'.
gw_valuationdata-pr_ctrl_pp = 'S'.
gw_valuationdatax-pr_ctrl_pp = 'X'.
gw_valuationdata-price_ctrl = 'S'. "价格控制指示符 S标准价 V 移动平均价
gw_valuationdatax-price_ctrl = 'X'.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_MVKE
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& --> LS_ALV
*& <-- GW_MVKE
*& <-- GW_MVKEX
*&---------------------------------------------------------------------*
FORM f_mvke USING gs_alv TYPE zsmdm_matnr_detail
CHANGING gw_mvke LIKE bapi_mvke
gw_mvkex LIKE bapi_mvkex.
CLEAR gw_mvke.
CLEAR gw_mvkex.
gw_mvke-sales_org = gs_alv-vkorg. "销售组织
IF gw_mvke-sales_org IS NOT INITIAL.
gw_mvkex-sales_org = gs_alv-vkorg. "销售组织
ENDIF.
gw_mvke-distr_chan = gs_alv-vtweg. "分销渠道
IF gw_mvke-distr_chan IS NOT INITIAL.
gw_mvkex-distr_chan = gs_alv-vtweg. "销售组织
ENDIF.
gw_mvke-matl_stats = gs_alv-taxkm. "销项税
IF gw_mvke-matl_stats IS NOT INITIAL.
gw_mvkex-matl_stats = 'X'. "销项税
ENDIF.
* GW_MVKE-ITEM_CAT = GS_ALV-MTPOS. "项目类别组
* IF GW_MVKEX-ITEM_CAT IS NOT INITIAL.
* GW_MVKEX-ITEM_CAT = 'X'. "销项税
* ENDIF.
gw_mvke-acct_assgt = gs_alv-ktgrm. "科目设置组
IF gw_mvke-acct_assgt IS NOT INITIAL.
gw_mvkex-acct_assgt = 'X'. "销项税
ENDIF.
gw_mvke-mat_pr_grp = gs_alv-kondm. "物料价格组
IF gw_mvke-mat_pr_grp IS NOT INITIAL.
gw_mvkex-mat_pr_grp = 'X'. "销项税
ENDIF.
gw_mvke-delyg_plnt = gs_alv-dwerk. "交货工厂
IF gw_mvkex-matl_stats IS NOT INITIAL.
gw_mvkex-delyg_plnt = 'X'. "
ENDIF.
gw_mvke-item_cat = gs_alv-mtpos."项目类别组
gw_mvkex-item_cat = 'X'.
gw_mvke-matl_grp_1 = gs_alv-mvgr1."物料组1
gw_mvkex-matl_grp_1 = 'X'.
gw_mvke-sales_unit = gs_alv-vrkme. "销售单位
IF gw_mvke-sales_unit IS NOT INITIAL.
gw_mvkex-sales_unit = 'X'. "
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_MLAN
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& --> GT_MLAN
*& --> LS_ALV
*&---------------------------------------------------------------------*
FORM f_mlan TABLES gt_mlan STRUCTURE bapi_mlan
USING gs_alv TYPE zsmdm_matnr_detail.
REFRESH gt_mlan.
IF gs_alv-taxkm IS NOT INITIAL .
gt_mlan-depcountry = 'CN' ." GS_ALV-ALAND .
gt_mlan-tax_type_1 = 'MWST' .
gt_mlan-taxclass_1 = gs_alv-taxkm.
APPEND gt_mlan.
CLEAR gt_mlan .
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_UNIT
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& --> GT_UNITX
*& --> GT_UNIT
*& --> LS_ALV
*&---------------------------------------------------------------------*
FORM f_unit TABLES gt_unitx STRUCTURE bapi_marmx
gt_unit STRUCTURE bapi_marm
USING gs_alv TYPE zsmdm_matnr_detail.
REFRESH gt_unitx.
REFRESH gt_unit.
gt_unitx-alt_unit = gs_alv-meins.
gt_unitx-gross_wt = 'X'. "毛重
gt_unitx-unit_of_wt = 'X'.
gt_unitx-unit_of_wt_iso = 'X'.
gt_unitx-volume = 'X'.
gt_unitx-volumeunit = 'X'.
APPEND gt_unitx.
IF gs_alv-meins IS NOT INITIAL .
gt_unit-alt_unit = gs_alv-meins.
" GT_UNIT-GROSS_WT = GS_ALV-BRGEW. "毛重
gt_unit-unit_of_wt = gs_alv-gewei. "重量单位
gt_unit-unit_of_wt_iso = gs_alv-gewei. "重量单位
gt_unit-volume = gs_alv-volum.
gt_unit-volumeunit = gs_alv-voleh.
APPEND gt_unit.
"ADDED BY IBMQJK 2020.07.11 物料主数据批量导入
IF gs_alv-bstme IS NOT INITIAL.
gt_unit-alt_unit = gs_alv-bstme.
gt_unit-numerator = gs_alv-umrez.
gt_unit-denominatr = gs_alv-umren.
APPEND gt_unit.
gt_unitx-alt_unit = gs_alv-bstme.
gt_unitx-numerator = 'X'.
gt_unitx-denominatr = 'X'.
APPEND gt_unitx.
ENDIF.
IF gs_alv-frtme IS NOT INITIAL.
gt_unitx-alt_unit = gs_alv-frtme.
gt_unitx-numerator = 'X'.
gt_unitx-denominatr = 'X'.
APPEND gt_unitx.
gt_unit-alt_unit = gs_alv-frtme.
gt_unit-numerator = gs_alv-umrez_P.
gt_unit-denominatr = gs_alv-umren_P.
APPEND gt_unit.
ENDIF.
"销售单位和比例
IF gs_alv-vrkme IS NOT INITIAL.
gt_unitx-alt_unit = gs_alv-vrkme.
gt_unitx-numerator = 'X'.
gt_unitx-denominatr = 'X'.
APPEND gt_unitx.
gt_unit-alt_unit = gs_alv-vrkme.
gt_unit-numerator = gs_alv-umrez_V.
gt_unit-denominatr = gs_alv-umren_V.
APPEND gt_unit.
ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_QMAT
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& --> GT_QMAT
*& --> LS_ALV
*&---------------------------------------------------------------------*
FORM f_qmat TABLES gt_qmat STRUCTURE bapi1001004_qmat
USING gs_alv TYPE zsmdm_matnr_detail.
REFRESH gt_qmat.
DATA:lw_art TYPE qpart,
lw_art2 TYPE qpart.
SEARCH gs_alv-art FOR ','.
IF sy-subrc = 0.
SPLIT gs_alv-art AT ',' INTO lw_art lw_art2 .
CLEAR gt_qmat .
gt_qmat-material = gs_alv-matnr.
gt_qmat-insptype = lw_art. "检验类型
gt_qmat-preferred_insptype = 'X'."gs_alv-apa. "首选项
gt_qmat-ind_post_to_insp_stock = 'X'. "过帐到检验库存
gt_qmat-ind_insptype_mat_active = 'X'. "活动的
gt_qmat-ave_insp_duration = gs_alv-mpdau. "平均持续时间
gt_qmat-ind_insp_with_tsk_list = 'X'. "有任务清单的检验
gt_qmat-ind_single_units_possible = 'X'. "可能的序列号管理
gt_qmat-qual_score_procedure = '06'. "计算质量记分的程序
gt_qmat-contr_insp_lot_create = ''. "控制检验批
gt_qmat-ind_skips_allowed = 'X'. "允许略过
gt_qmat-ind_auto_assign = 'X'. "自动分配
gt_qmat-ind_insp_by_charac = 'X'. "检验特征
* GT_QMAT-IND_AUTOMATIC_UD = 'X'. "自动使用决策
IF lw_art = 'Z130' .
gt_qmat-preferred_insptype = ''. "首选项
gt_qmat-ind_post_to_insp_stock = ''. "过帐到检验库存
ENDIF.
IF lw_art = 'Z3' .
gt_qmat-ind_post_to_insp_stock = ''. "过帐到检验库存
gt_qmat-ind_insp_by_charac = 'X'. "检验特征
ENDIF.
gt_qmat-plant = gs_alv-werks.
APPEND gt_qmat.
CLEAR gt_qmat .
gt_qmat-material = gs_alv-matnr.
gt_qmat-insptype = lw_art2. "检验类型
gt_qmat-preferred_insptype = 'X'."gs_alv-apa. "首选项
gt_qmat-ind_post_to_insp_stock = 'X'. "过帐到检验库存
gt_qmat-ind_insptype_mat_active = 'X'. "活动的
gt_qmat-ave_insp_duration = gs_alv-mpdau. "平均持续时间
gt_qmat-ind_insp_with_tsk_list = 'X'. "有任务清单的检验
gt_qmat-ind_single_units_possible = 'X'. "可能的序列号管理
gt_qmat-qual_score_procedure = '06'. "计算质量记分的程序
gt_qmat-contr_insp_lot_create = ''. "控制检验批
gt_qmat-ind_skips_allowed = 'X'. "允许略过
gt_qmat-ind_auto_assign = 'X'. "自动分配
gt_qmat-ind_insp_by_charac = 'X'. "检验特征
* GT_QMAT-IND_AUTOMATIC_UD = 'X'. "自动使用决策
IF lw_art2 = 'Z130' .
gt_qmat-preferred_insptype = ''. "首选项
gt_qmat-ind_post_to_insp_stock = ''. "过帐到检验库存
ENDIF.
IF lw_art2 = 'Z3' .
gt_qmat-ind_post_to_insp_stock = ''. "过帐到检验库存
gt_qmat-ind_insp_by_charac = 'X'. "检验特征
ENDIF.
gt_qmat-plant = gs_alv-werks.
APPEND gt_qmat.
ELSE.
CLEAR gt_qmat .
gt_qmat-material = gs_alv-matnr.
gt_qmat-insptype = gs_alv-art. "检验类型
gt_qmat-preferred_insptype = 'X'."gs_alv-apa. "首选项
gt_qmat-ind_post_to_insp_stock = 'X'. "过帐到检验库存
gt_qmat-ind_insptype_mat_active = 'X'. "活动的
gt_qmat-ave_insp_duration = gs_alv-mpdau. "平均持续时间
gt_qmat-ind_single_units_possible = 'X'. "可能的序列号管理
gt_qmat-qual_score_procedure = '06'. "计算质量记分的程序
gt_qmat-contr_insp_lot_create = ''. "控制检验批
gt_qmat-ind_skips_allowed = 'X'. "允许略过
IF gs_alv-mtart = 'Z460'."物料类型为Z460时,这三个勾选置空
gt_qmat-ind_insp_with_tsk_list = ''. "有任务清单的检验
gt_qmat-ind_auto_assign = ''. "自动分配
gt_qmat-ind_insp_by_charac = ''. "检验特征
ELSE.
gt_qmat-ind_insp_with_tsk_list = 'X'. "有任务清单的检验
gt_qmat-ind_auto_assign = 'X'. "自动分配
gt_qmat-ind_insp_by_charac = 'X'. "检验特征
ENDIF.
* GT_QMAT-IND_AUTOMATIC_UD = 'X'. "自动使用决策
IF gs_alv-art = 'Z130' .
gt_qmat-preferred_insptype = ''. "首选项
gt_qmat-ind_post_to_insp_stock = ''. "过帐到检验库存
ENDIF.
IF gs_alv-art = 'Z3' .
gt_qmat-ind_post_to_insp_stock = ''. "过帐到检验库存
gt_qmat-ind_insp_by_charac = 'X'. "检验特征
ENDIF.
gt_qmat-plant = gs_alv-werks.
APPEND gt_qmat.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM FRM_SET_MLGN_DATA
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& --> LS_ALV
*& <-- GW_MLGNDATA
*& <-- GW_MLGNDATAX
*& <-- GW_MLGTDATA
*& <-- GW_MLGTDATAX
*&---------------------------------------------------------------------*
FORM frm_set_mlgn_data USING gs_alv TYPE zsmdm_matnr_detail
CHANGING gw_mlgndata LIKE bapi_mlgn
gw_mlgndatax LIKE bapi_mlgnx
gw_mlgtdata LIKE bapi_mlgt
gw_mlgtdatax LIKE bapi_mlgtx.
CLEAR gw_mlgndata.
CLEAR gw_mlgndatax.
gw_mlgndata-whse_no = 'Z01'.
gw_mlgndata-withdrawal = gs_alv-ltkza .
gw_mlgndata-placement = gs_alv-ltkze .
gw_mlgndata-stgesector = gs_alv-lgbkz .
gw_mlgndatax-whse_no = 'Z01'.
gw_mlgndatax-withdrawal = 'X' .
gw_mlgndatax-placement = 'X' .
gw_mlgndatax-stgesector = 'X' .
CLEAR gw_mlgtdata.
CLEAR gw_mlgtdatax.
gw_mlgtdata-whse_no = 'Z01'.
gw_mlgtdata-stge_type = gs_alv-lgtyp .
gw_mlgtdatax-whse_no = 'Z01'.
gw_mlgtdatax-stge_type = gs_alv-lgtyp .
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM SAVE_TO_ZTMDM_007
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& --> LS_ALV
*&---------------------------------------------------------------------*
FORM save_to_ztmdm_007 USING gs_alv TYPE zsmdm_matnr_detail
gv_create TYPE c.
DATA:ls_save TYPE ztmdm_007.
MOVE-CORRESPONDING gs_alv TO ls_save.
ls_save-zmatnr = gs_alv-matnr.
ls_save-zwerks = gs_alv-werks.
"创建日期时间人记录
IF gv_create = 'X'.
ls_save-erdat = sy-datum.
ls_save-erdim = sy-uzeit.
ls_save-ernam = sy-uname.
ELSE."修改记录
"创建人,日,时不变。
SELECT SINGLE erdat , erdim , ernam
FROM ztmdm_007
WHERE zmatnr = @gs_alv-matnr
AND zwerks = @gs_alv-werks
INTO @DATA(ls_mdm) .
ls_save-erdat = ls_mdm-erdat.
ls_save-erdim = ls_mdm-erdim.
ls_save-ernam = ls_mdm-ernam.
"更新时间。
ls_save-aedat = sy-datum.
ls_save-aetim = sy-uzeit.
ls_save-aenam = sy-uname.
ENDIF.
MODIFY ztmdm_007 FROM ls_save.
CLEAR:ls_save.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM SAVE_TO_ZTMDM_007_LOG
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& --> LS_ALV
*& --> GV_CREATE
*&---------------------------------------------------------------------*
FORM save_to_ztmdm_007_log USING gs_alv TYPE zsmdm_matnr_detail
bapi_msg TYPE bapi_msg
ztype TYPE c
lv_guid TYPE sysuuid_c32.
DATA:ls_save_log TYPE ztmdm_007_log.
MOVE-CORRESPONDING gs_alv TO ls_save_log.
ls_save_log-guid32 = lv_guid.
ls_save_log-zmatnr = gs_alv-matnr.
ls_save_log-zwerks = gs_alv-werks.
ls_save_log-jkzzt = ztype.
ls_save_log-jkmessage = bapi_msg.
ls_save_log-erdat = sy-datum.
ls_save_log-erdim = sy-uzeit.
ls_save_log-ernam = sy-uname.
MODIFY ztmdm_007_log FROM ls_save_log.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_set_MARD_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> LS_ALV
*& <-- GW_BAPI_MARD
*& <-- GW_BAPI_MARDX
*&---------------------------------------------------------------------*
FORM frm_set_MARD_data USING gs_alv TYPE zsmdm_matnr_detail
CHANGING gw_bapi_mard LIKE bapi_mard
gw_bapi_mardx LIKE bapi_mardx.
IF gs_alv-lgpro NE ''.
gw_bapi_mard-plant = gs_alv-werks.
gw_bapi_mardx-plant = gs_alv-werks.
gw_bapi_mard-stge_loc = gs_alv-lgpro.
gw_bapi_mardx-stge_loc = gs_alv-lgpro.
ENDIF.
ENDFORM.
二、使用此代码的注意点
1.这个代码使用在接口,或者excel导入,点按钮的loop循环逻辑之后的逻辑。
2.ls_alv与gs_alv都是自定义的结构。就是你要导入什么字段就收集哪些。如图1
图2
图3
图4
图5 这里大部分是用于接口的自定义字段,根据各自情况进行添加
附加:使用此BAPI,遇到的问题。
1.对于财务会计1视图的价格控制字段,我赋值S,是可以成功创建物料,但是在BAP中赋值了V,返回报错:你不能修改价格控制标识。
问题原因:要修改价格控制这个字段,需要连同价格确定一起更改。