MATNR 1 类型 MATNR CHAR 40 0 0 物料编号
WERKS 1 类型 WERKS_D CHAR 4 0 0 工厂
STLAN 1 类型 STLAN CHAR 1 0 0 物料清单用途
STLAL 1 类型 STLAL CHAR 2 0 0 备选物料清单
AENNR 1 类型 AENNR CHAR 12 0 0 变更编号
DSPST 1 类型 DATUV DATS 8 0 0 有效起始日期
BMENG 1 类型 BMENG QUAN 13 3 0 确认的数量
MEINS 1 类型 MEINS UNIT 3 0 0 基本计量单位
STLST 1 类型 STLST NUMC 2 0 0 物料清单状态
STLNR 1 类型 STNUM CHAR 8 0 0 物料清单
STLAL 1 类型 STALT CHAR 2 0 0 备选物料清单
MATNR 1 类型 MATNR CHAR 40 0 0 物料编号
WERKS 1 类型 WERKS_D CHAR 4 0 0 工厂
STLAN 1 类型 STLAN CHAR 1 0 0 物料清单用途
ZBS 1 类型 CHAR 1 0 0 标识(I增、D删、C改)
SPOSN 1 类型 SPOSN CHAR 4 0 0 BOM 项目号
POSTP 1 类型 POSTP CHAR 1 0 0 项目类别(物料单)
IDNRK 1 类型 IDNRK CHAR 40 0 0 BOM 组件
MENGE 1 类型 MENGE_D QUAN 13 3 0 数量
MEINS 1 类型 MEINS UNIT 3 0 0 基本计量单位
LGORT 1 类型 LGORT_D CHAR 4 0 0 存储地点
TEXT1 1 类型 TEXT1 CHAR 50 0 0 文本
ZTEXT 1 类型 ZETEXT CHAR 2048 0 0 长文本
MATNR 1 类型 MATNR CHAR 40 0 0 物料编号
WERKS 1 类型 WERKS_D CHAR 4 0 0 工厂
STLAN 1 类型 STLAN CHAR 1 0 0 物料清单用途
STLAL 1 类型 STLAL CHAR 2 0 0 备选物料清单
AENNR 1 类型 AENNR CHAR 12 0 0 变更编号
SPOSN 1 类型 SPOSN CHAR 4 0 0 BOM 项目号
IDNRK 1 类型 IDNRK CHAR 40 0 0 BOM 组件
STATUS 1 类型 BAPI_MTYPE CHAR 1 0 0 消息类型: S 成功,E 错误,W 警告,I 信息,A 中断
MESSAGE 1 类型 BAPI_MSG CHAR 220 0 0 消息文本
FUNCTION zfm_plm_bom_change_tosap.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(INPUT) TYPE ZSPP_PLM_BOM_CHANGE_INPUT OPTIONAL
*" EXPORTING
*" VALUE(OUTPUT) TYPE ZSMM_PLM_BOM_OUT
*"----------------------------------------------------------------------
DATA: lv_comp_qty TYPE p LENGTH 15 DECIMALS 3,
lv_menge TYPE p LENGTH 15 DECIMALS 3,
lv_ausss TYPE p LENGTH 5 DECIMALS 2,
lv_tabix TYPE sy-tabix.
DATA:
lv_warning TYPE capiflag-flwarning, "出错标识
ls_mbom TYPE csap_mbom, "BOM key信息
ls_stko_i TYPE stko_api01, "BOM头部信息-输入
ls_stko_o TYPE stko_api02. "BOM头部信息-输出
DATA:
lv_datuv TYPE csap_mbom-datuv,
lv_aennr TYPE csap_mbom-aennr.
DATA:
lv_datum TYPE csap_mbom-datuv,
lv_base_quan TYPE p DECIMALS 3,
lv_bmeng TYPE p DECIMALS 3,
lt_stpo_read TYPE TABLE OF stpo_api02,
ls_stpo_read TYPE stpo_api02,
lt_stko_read TYPE TABLE OF stko_api02,
ls_stko_read TYPE stko_api02.
DATA: lt_stpo TYPE TABLE OF stpo_api03,
ls_stpo TYPE stpo_api03.
DATA:lv_material TYPE csap_mbom-matnr,
lv_plant TYPE csap_mbom-werks,
lv_bom_usage TYPE csap_mbom-stlan, "BOM用途
lv_valid_from TYPE csap_mbom-datuv, "有效起始日期
lv_alternative TYPE csap_mbom-stlal. "备选物料清单
DATA:lt_texts TYPE TABLE OF csltx_line.
DATA:lt_lines LIKE TABLE OF tline.
DATA:lv_uuid TYPE sysuuid_c32,
lv_status TYPE bapi_mtype,
lv_message TYPE bapi_msg.
DATA: ls_ifsort TYPE zsall_iflog_zfield.
DATA:lv_type TYPE c.
DATA:ls_return TYPE zsmm_bom_change_zhead.
CLEAR ls_return.
*-----------------------------------------------------------------------
* 启用接口日志
/log/start. output-uuid = /log/data-uuid.
*-----------------------------------------------------------------------
* "校验表头数据
IF input-head-matnr IS INITIAL .
ls_return-status = 'E'.
ls_return-message = |{ ls_return-message }物料编码必须填写;|.
ENDIF.
IF input-head-werks IS INITIAL .
ls_return-status = 'E'.
ls_return-message = |{ ls_return-message }工厂必须填写;|.
ENDIF.
IF input-head-stlan IS INITIAL .
ls_return-status = 'E'.
ls_return-message = |{ ls_return-message }BOM用途必须填写;|.
ENDIF.
IF input-head-stlal IS INITIAL .
ls_return-status = 'E'.
ls_return-message = |{ ls_return-message }BOM版本必须填写;|.
ENDIF.
* IF input-head-aennr IS INITIAL .
* ls_return-status = 'E'.
* ls_return-message = |{ ls_return-message }ECN变更号必须填写;|.
* ENDIF.
IF input-head-dspst IS INITIAL .
ls_return-status = 'E'.
ls_return-message = |{ ls_return-message }有效日期起必须填写;|.
ENDIF.
IF input-head-bmeng IS INITIAL .
ls_return-status = 'E'.
ls_return-message = |{ ls_return-message }父件基本数量必须填写;|.
ENDIF.
IF input-head-stlst IS INITIAL .
ls_return-status = 'E'.
ls_return-message = |{ ls_return-message }BOM状态必须填写;|.
ENDIF.
IF ls_return-status = 'E'.
ls_return-matnr = input-head-matnr.
ls_return-werks = input-head-werks.
ls_return-stlan = input-head-stlan.
ls_return-stlal = input-head-stlal.
ls_return-aennr = input-head-aennr.
lv_type = 'E'.
APPEND ls_return TO output-data.
ENDIF.
IF lv_type <> 'E'.
LOOP AT input-item INTO DATA(ls_item).
CLEAR ls_return.
CLEAR lv_message.
IF ls_item-stlnr IS INITIAL .
ls_return-status = 'E'.
lv_message = |{ lv_message }物料单必须填写;|.
ENDIF.
IF ls_item-stlal IS INITIAL .
ls_return-status = 'E'.
lv_message = |{ lv_message }备料物料清单必须填写;|.
ENDIF.
IF ls_item-matnr IS INITIAL .
ls_return-status = 'E'.
lv_message = |{ lv_message }物料编号必须填写;|.
ENDIF.
IF ls_item-werks IS INITIAL .
ls_return-status = 'E'.
lv_message = |{ lv_message }工厂必须填写;|.
ENDIF.
IF ls_item-stlan IS INITIAL .
ls_return-status = 'E'.
lv_message = |{ lv_message }BOM用途必须填写;|.
ENDIF.
IF ls_item-zbs IS INITIAL .
ls_return-status = 'E'.
lv_message = |{ lv_message }标识必须填写;|.
ENDIF.
IF ls_item-idnrk IS INITIAL .
ls_return-status = 'E'.
lv_message = |{ lv_message }BOM组件物料必须填写;|.
ENDIF.
IF ls_item-sposn IS INITIAL .
ls_return-status = 'E'.
lv_message = |{ lv_message }BOM项目号必须填写;|.
ENDIF.
IF ls_item-postp IS INITIAL .
ls_return-status = 'E'.
lv_message = |{ lv_message }项目类别必须填写;|.
ENDIF.
IF ls_return-status = 'E'.
ls_return-matnr = ls_item-matnr.
ls_return-werks = ls_item-werks.
ls_return-stlan = ls_item-stlan.
ls_return-stlal = ls_item-stlal.
ls_return-idnrk = ls_item-idnrk.
ls_return-sposn = ls_item-sposn.
ls_return-message = lv_message.
APPEND ls_return TO output-data.
lv_type = 'E'.
ENDIF.
ENDLOOP.
ELSE.
output-status = 'E'.
output-message = '修改失败!'.
*-----------------------------------------------------------------------
* 记录调用第三方接口的实际请求参数与响应参数
/log/return output-status output-message ls_ifsort.
*-----------------------------------------------------------------------
ENDIF.
IF lv_type <> 'E'.
CLEAR: lv_datum.
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = input-head-dspst
IMPORTING
date_external = lv_datum
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.
CLEAR:lt_stpo_read.
input-head-matnr = |{ input-head-matnr ALPHA = IN }|.
input-head-stlal = |{ input-head-stlal ALPHA = IN }|.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
material = input-head-matnr
plant = input-head-werks
bom_usage = input-head-stlan
alternative = input-head-stlal
valid_from = lv_datum
valid_to = lv_datum
* IMPORTING
* FL_WARNING =
TABLES
t_stpo = lt_stpo_read
t_stko = lt_stko_read
EXCEPTIONS
error = 1
OTHERS = 2.
READ TABLE lt_stko_read INTO ls_stko_read INDEX 1.
CLEAR :lv_base_quan,lv_bmeng.
PERFORM frm_units_string_convert USING ls_stko_read-base_quan CHANGING lv_base_quan .
PERFORM frm_units_string_convert USING input-head-bmeng CHANGING lv_bmeng .
IF lv_base_quan <> lv_bmeng OR ls_stko_read-base_unit <> input-head-meins .
ls_stko_i-base_quan = input-head-bmeng. "父项基本数量
ls_stko_i-base_unit = input-head-meins. "基本单位
ENDIF.
CLEAR:lv_datuv,lv_aennr.
lv_aennr = input-head-aennr.
IF input-head-dspst IS NOT INITIAL.
lv_datuv = input-head-dspst.
ENDIF.
CLEAR ls_stko_i.
"抬头数据
lv_material = input-head-matnr."父项物料
lv_plant = input-head-werks."工厂
lv_bom_usage = input-head-stlan."BOM用途
lv_valid_from = input-head-dspst."有效起始日期
lv_alternative = input-head-stlal."备选物料清单
lv_aennr = input-head-aennr. "ECN变更号
IF input-head-stlan = '2'.
ls_stko_i-bom_status = '02'.
ELSE.
ls_stko_i-bom_status = input-head-stlst .
ENDIF.
IF input-head-stlan = '3'.
lv_alternative = lv_alternative + 1.
ENDIF.
MOVE-CORRESPONDING ls_stko_read TO ls_stko_i.
ls_stko_i-base_quan = input-head-bmeng .
ls_stko_i-base_unit = input-head-meins .
DATA:lv_index TYPE i.
CLEAR ls_item.
LOOP AT input-item INTO ls_item.
lv_index = lv_index + 1.
"检查行项目是否需要变更
READ TABLE lt_stpo_read INTO ls_stpo_read WITH KEY item_no = ls_item-sposn
component = ls_item-idnrk.
IF sy-subrc = 0.
MOVE-CORRESPONDING ls_stpo_read TO ls_stpo.
ENDIF.
ls_item-idnrk = |{ ls_item-idnrk ALPHA = IN }|.
ls_item-sposn = |{ ls_item-sposn ALPHA = IN }|.
"新项目
ls_stpo-item_no = ls_item-sposn. "BOM 项目号
ls_stpo-item_categ = ls_item-postp. "项目类别
ls_stpo-component = ls_item-idnrk. "组件物料号
ls_stpo-comp_qty = ls_item-menge. "数量
ls_stpo-comp_unit = ls_item-meins. "单位
ls_stpo-issue_loc = ls_item-lgort. "仓储地点
ls_stpo-rel_cost = 'X'. "标识:与成本核算相关的项目
ls_stpo-rel_prod = 'X'. "标识:与生产相关项目
ls_stpo-rel_sales = 'X'. "标识:与销售相关项目
ls_item-stlnr = |{ ls_item-stlnr ALPHA = IN }|.
ls_item-stlal = |{ ls_item-stlal ALPHA = IN }|.
ls_stpo-bom_no = ls_item-stlnr. "物料单
ls_stpo-bom_alt = lv_alternative.
IF ls_item-zbs = 'D'.
ls_stpo-fldelete = 'X'.
ENDIF.
IF ls_stpo-usage_prob = '0'."在更改模式中,如果usage_prob等于0,则不会更新
CLEAR:ls_stpo-usage_prob.
ENDIF.
ls_stpo-identifier = 'ITEM' && lv_index.
IF ls_item-ztext IS INITIAL.
ls_item-ztext = ls_item-text1.
ENDIF.
* IF ls_stpo-item_categ = 'T'.
* CLEAR:ls_stpo-id_comp,
* ls_stpo-component.
* ls_stpo-item_text1 = ls_item-idnrk.
* ELSE.
* ls_stpo-component = ls_item-idnrk.
* ls_stpo-item_text1 = ls_item-ztext.
* ENDIF.
* DATA(lv_len) = strlen( ls_item-ztext ).
* IF lv_len > 40 .
* ls_stpo-item_text2 = ls_item-ztext+40(*).
* ENDIF.
* CLEAR:lt_lines.
* CALL FUNCTION 'C14W_STRING_TO_TLINE'
* EXPORTING
* i_string = ls_item-ztext
* TABLES
* e_tline_tab = lt_lines.
* LOOP AT lt_lines INTO DATA(wa_text_line).
* lt_texts = VALUE #( BASE lt_texts
* ( object_id = '2'
* identifier = ls_stpo-identifier
* bom_no = ls_stko_read-bom_no
* item_node = ls_stpo-item_node
* item_count = ls_stpo-item_count
* tdformat = wa_text_line-tdformat
* tdline = wa_text_line-tdline ) ).
* ENDLOOP.
DATA: l_pos TYPE i.
DATA: l_string TYPE zetext.
DATA: l_string1 TYPE zetext.
DATA: l_string2 TYPE zetext.
DATA: l_subrc TYPE i.
DATA: l_tdformat TYPE tdformat.
l_string = ls_item-ztext.
DO.
CLEAR:l_string2.
CALL FUNCTION 'STRING_SPLIT_AT_POSITION'
EXPORTING
string = l_string
pos = 40
IMPORTING
string1 = l_string1
string2 = l_string
pos_new = l_pos
EXCEPTIONS
string1_too_small = 1
string2_too_small = 2
pos_not_valid = 3
OTHERS = 4.
l_subrc = sy-subrc.
IF l_subrc = 0.
l_string2 = l_string1.
ELSEIF l_subrc = 3.
l_string2 = l_string.
ENDIF.
IF sy-index = 1.
l_tdformat = '/'.
ELSE.
l_tdformat = '='.
ENDIF.
IF sy-index = 1.
ls_stpo-item_text1 = l_string2.
ELSEIF sy-index = 2.
ls_stpo-item_text2 = l_string2.
ENDIF.
lt_texts = VALUE #( BASE lt_texts
( object_id = '2'
identifier = ls_stpo-identifier
bom_no = ls_stko_read-bom_no
item_node = ls_stpo-item_node
item_count = ls_stpo-item_count
tdformat = l_tdformat
tdline = l_string2 ) ).
IF l_subrc <> 0.
EXIT .
ENDIF.
ENDDO.
IF ls_stpo-item_categ = 'T'.
CLEAR:ls_stpo-id_comp,ls_stpo-component.
ls_stpo-item_text1 = ls_item-idnrk.
ENDIF.
"新增关联关系,更新ITEM 的Change No.
ls_stpo-valid_from = lv_datuv. "有效期开始日
ls_stpo-change_no = lv_aennr. "变更编号
ls_stpo-id_itm_ctg = ls_item-postp. "项目类别
ls_stpo-id_item_no = ls_item-sposn. "BOM 项目号
ls_stpo-id_comp = ls_item-idnrk. "组件物料号
APPEND ls_stpo TO lt_stpo.
CLEAR: ls_stpo.
ENDLOOP.
CLEAR ls_return.
"调用BAPI创建BOM
CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'
EXPORTING
material = lv_material
plant = lv_plant
bom_usage = lv_bom_usage
alternative = lv_alternative
valid_from = lv_datuv
change_no = lv_aennr
i_stko = ls_stko_i
fl_commit_and_wait = 'X'
fl_bom_create = 'X'
fl_new_item = 'X'
fl_complete = 'X'
IMPORTING
fl_warning = lv_warning
o_stko = ls_stko_o
TABLES
t_stpo = lt_stpo
t_ltx_line = lt_texts
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
output-status = 'E'.
output-message = '修改失败!'.
ls_return-status = 'E'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = sy-msgid
msgnr = sy-msgno
msgv1 = sy-msgv1
msgv2 = sy-msgv2
msgv3 = sy-msgv3
msgv4 = sy-msgv4
IMPORTING
message_text_output = ls_return-message.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
ls_return-status = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
IF input-head-stlan = '2'.
ls_stko_i-bom_status = '01'.
lv_alternative = lv_alternative + 1.
CLEAR ls_return.
"调用BAPI创建BOM
CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'
EXPORTING
material = lv_material
plant = lv_plant
bom_usage = lv_bom_usage
alternative = lv_alternative
valid_from = lv_datuv
change_no = lv_aennr
i_stko = ls_stko_i
fl_commit_and_wait = 'X'
fl_bom_create = 'X'
fl_new_item = 'X'
fl_complete = 'X'
IMPORTING
fl_warning = lv_warning
o_stko = ls_stko_o
TABLES
t_stpo = lt_stpo
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
output-status = 'E'.
output-message = '修改失败!'.
ls_return-status = 'E'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = sy-msgid
msgnr = sy-msgno
msgv1 = sy-msgv1
msgv2 = sy-msgv2
msgv3 = sy-msgv3
msgv4 = sy-msgv4
IMPORTING
message_text_output = ls_return-message.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
ls_return-status = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ls_return-message = 'BOM修改成功'.
output-status = 'S'.
output-message = ls_return-message.
ENDIF.
ELSE.
ls_return-message = 'BOM修改成功'.
output-status = 'S'.
output-message = ls_return-message.
ENDIF.
ENDIF.
ls_return-matnr = lv_material.
ls_return-werks = lv_plant.
ls_return-stlan = lv_bom_usage.
ls_return-stlal = lv_alternative.
ls_return-aennr = lv_aennr.
APPEND ls_return TO output-data.
ELSE.
output-status = 'E'.
output-message = '修改失败!'.
*-----------------------------------------------------------------------
* 记录调用第三方接口的实际请求参数与响应参数
/log/return output-status output-message ls_ifsort.
*-----------------------------------------------------------------------
ENDIF.
*-----------------------------------------------------------------------
* 结束接口日志 &1状态码 &2消息 &3搜索项 &4反写UUID
/log/end output-status output-message ls_ifsort.
*-----------------------------------------------------------------------
ENDFUNCTION.
FORM frm_units_string_convert USING pv_quan1
CHANGING pv_quan2.
DATA: lv_clabs TYPE p DECIMALS 3,
lv_dcpfm LIKE usr01-dcpfm.
SELECT SINGLE dcpfm INTO lv_dcpfm
FROM usr01
WHERE bname = sy-uname.
CLEAR lv_clabs.
CALL FUNCTION 'UNITS_STRING_CONVERT'
EXPORTING
units_string = pv_quan1
dcpfm = lv_dcpfm "此时为X
* MLLN = 'M'
* TSND = 'T'
IMPORTING
units = lv_clabs
EXCEPTIONS
invalid_type = 1
OTHERS = 2.
IF sy-subrc = 0.
pv_quan2 = lv_clabs.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM frm_log_ZFM_PLM_BOM_CREATE
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*FORM frm_log_zfm_plm_bom_create TABLES it_items STRUCTURE zsmm_bom_create_line
* USING is_header TYPE zsmm_bom_create_head
* es_return TYPE zsmm_bom_create_zhead.
*
* DATA: ls_log TYPE ztlog.
*
* TYPES: BEGIN OF ty_data,
* is_header TYPE zsmm_bom_create_head,
* it_items TYPE TABLE OF zsmm_bom_create_line WITH NON-UNIQUE KEY matnr,
* es_return TYPE zsmm_bom_create_zhead,
* END OF ty_data.
* DATA: ls_data TYPE ty_data.
*
* MOVE-CORRESPONDING is_header TO ls_data-is_header.
*
* ls_data-it_items = it_items[].
*
* MOVE-CORRESPONDING es_return TO ls_data-es_return.
*
* CLEAR ls_log.
* ls_log-zifname = 'ZFM_PLM_BOM_CREATE'.
* ls_log-zifdesc = 'PLM->SAP 创建BOM主数据'.
* ls_log-ziftype = 'CPI'.
* ls_log-zdirection = 'PLM->SAP'.
* ls_log-formatstr = 'JSON'.
* ls_log-status = es_return-status.
* ls_log-message = es_return-message.
* "TODO 后面完善
** CALL FUNCTION 'ZFMLOG'
** EXPORTING
*** iv_string = lv_xmlinput
** is_log = ls_log
** is_data = ls_data.
*
*ENDFORM.
*FORM frm_add_tdline TABLES it_tdline STRUCTURE tline
* USING text TYPE char2048.
*
** CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
** EXPORTING
** text = text
*** IMPORTING
*** length = 100
** TABLES
** ftext_tab = it_tdline.
*
* CALL FUNCTION 'C14W_STRING_TO_TLINE'
* EXPORTING
* i_string = text
* TABLES
* e_tline_tab = it_tdline.
*
*
*ENDFORM.