我们学过了物料主数据的创建/编辑修改,今天我们学习物料BOM组的创建,
BAPI函数为BAPI_MATERIAL_BOM_GROUP_CREATE,
如果不想创建BOM组,而是简单的只创建BOM,那么可以使用函数 CSAP_MAT_BOM_CREATE 哦。
表参数:
参数名称 | 关联类型 | 可选的 | 说明 |
BOMGROUP | BAPI1080_BGR_C | 必选 | 物料 BOM组 |
VARIANTS | BAPI1080_BOM_C | 必选 | BOM抬头 |
ITEMS | BAPI1080_ITM_C | 可选 | BOM组件物料 |
SUBITEMS | BAPI1080_SUI_C | 可选 | BOM子项目 |
MATERIALRELATIONS | BAPI1080_MBM_C | 必选 | BOM抬头数据,物料分配 |
ITEMASSIGNMENTS | BAPI1080_REL_ITM_BOM_C | 可选 | 用来确定组件物料与物料的链接关系 |
SUBITEMASSIGNMENTS | BAPI1080_REL_SUI_ITM_C | 可选 | 用来确定子项目与BOM组件行项目的对应关系 |
TEXTS | BAPI1080_TXT_C | 可选 | 长文本行 |
RETURN | BAPIRET2 | 必选 | 返回参数 |
备注:下列没有的字段,根据需求,去参数的关联类型对应的结构或表中查找
BOMGROUP常用输入字段:
字段名 | 类型 | 简短描述 |
BOM_GROUP_IDENTIFICATION | CS_BGR_ID | 标识物料单组 |
OBJECT_TYPE | CS_OBJECT_TYPE | BOM 组中的对象类型 |
OBJECT_ID | CS_OBJECT_ID | BOM 组中对象的标识 |
TECHNICAL_TYPE | TETYP_D | 技术类型 |
BOM_USAGE | STLAN | BOM 用途 |
CREATED_IN_PLANT | WRKAN | 生成 BOM 或可选/变式的工厂 |
LTXT_LANG | LTXSP | 语言:用此语言存储长文本 |
BOM_TEXT | CSTEXT | BOM 文本 |
VARIANTS常用输入字段:
字段名 | 类型 | 简短描述 |
BOM_GROUP_IDENTIFICATION | CS_BGR_ID | 标识物料单组 |
OBJECT_TYPE | CS_OBJECT_TYPE | BOM 组中的对象类型 |
OBJECT_ID | CS_OBJECT_ID | BOM 组中对象的标识 |
ALTERNATIVE_BOM | STALT | 可选的 BOM |
BOM_STATUS | STLST | BOM 状态 |
BASE_QTY | BASMN | 基本数量 |
BASE_UNIT | BASME | BOM 基本单位 |
ALT_TEXT | STKTX | 可选 BOM 文本 |
VALID_FROM_DATE | DATUV | 有效起始日期 |
FUNCTION | CS_FUNCTION | 功能 |
ITEMS常用输入字段:
字段名 | 类型 | 简短描述 |
BOM_GROUP_IDENTIFICATION | CS_BGR_ID | 标识物料单组 |
OBJECT_TYPE | CS_OBJECT_TYPE | BOM 组中的对象类型 |
OBJECT_ID | CS_OBJECT_ID | BOM 组中对象的标识 |
ITEM_NO | SPOSN | BOM 项目号 |
ITEM_CAT | POSTP | 项目类别(物料单) |
SORT_STRING | SORTP | 排序字符串 |
COMPONENT | IDNRK18 | 物料清单组件 |
LTXT_LANG | LTXSP | 语言:用此语言存储长文本 |
ITEM_TEXT1 | POTX1 | BOM 项目文本(行1) |
COMP_QTY | KMPMG | 组件数量 |
COMP_UNIT | KMPME | 组件计量单位 |
OPR_SCRAP | AVOAU | 工序报废 |
NET_SCRAP_IND | NETAU | 净废品标识 |
MAT_PROVISION | BEIKZ | 物料供应标识符 |
ISS_ST_LOC | CSLGO | 生产订单的发货地点 |
ALT_ITEM_STRATEGY | CS_ALPST | 替代项目:策略 |
ALT_ITEM_PRIO | CS_ALPRF | 替代项目:评比定单 |
ALT_ITEM_GROUP | CS_ALPGR | 替代项目:组 |
USAGE_PROB | EWAHR | 使用可能性按 % (可选项目) |
VALID_FROM_DATE | DATUV | 有效起始日期 |
SUBITEMS常用输入字段:
字段名 | 类型 | 简短描述 |
BOM_GROUP_IDENTIFICATION | CS_BGR_ID | 标识物料单组 |
OBJECT_TYPE | CS_OBJECT_TYPE | BOM 组中的对象类型 |
OBJECT_ID | CS_OBJECT_ID | BOM 组中对象的标识 |
SUBITEM_NO | UPOSZ | 子项目编号 |
SUBITEM_QTY | UPMNG | 子项目数量 |
INSTALLATION_POINT | EBORT | 子项目安装地点 |
SUBITEM_TEXT | UPTXT | BOM 子项目文本 |
MATERIALRELATIONS常用输入字段:
字段名 | 类型 | 简短描述 |
BOM_GROUP_IDENTIFICATION | CS_BGR_ID | 标识物料单组 |
MATERIAL | MATNR18 | 物料编号(18个字符) |
PLANT | WERKS_D | 工厂 |
BOM_USAGE | STLAN | BOM 用途 |
ALTERNATIVE_BOM | STALT | 可选的 BOM |
LOT_SIZE_FROM | LOSVN | 从批量 |
LOT_SIZE_TO | LOSBS | 到批量 |
ITEM ASSIGNMENTS常用输入字段:
字段名 | 类型 | 简短描述 |
BOM_GROUP_IDENTIFICATION | CS_BGR_ID | 标识物料单组 |
SUB_OBJECT_TYPE | CS_SUB_OBJECT_TYPE | 子对象物料单类型 |
SUB_OBJECT_ID | CS_SUB_OBJECT_ID | 对象标识子对象物料单 |
SUPER_OBJECT_TYPE | CS_SUPER_OBJECT_TYPE | 超级对象 BOM 类型 |
SUPER_OBJECT_ID | CS_SUPER_OBJECT_ID | 超级对象 BOM 的对象 ID |
VALID_FROM_DATE | DATUV | 有效起始日期 |
FUNCTION | CS_FUNCTION | 功能 |
SUB ITEM ASSIGNMENTS常用输入字段:
字段名 | 类型 | 简短描述 |
BOM_GROUP_IDENTIFICATION | CS_BGR_ID | 标识物料单组 |
SUPER_OBJECT_TYPE | CS_SUPER_OBJECT_TYPE | 超级对象 BOM 类型 |
SUPER_OBJECT_ID | CS_SUPER_OBJECT_ID | 超级对象 BOM 的对象 ID |
SUB_OBJECT_TYPE | CS_SUB_OBJECT_TYPE | 子对象物料单类型 |
SUB_OBJECT_ID | CS_SUB_OBJECT_ID | 对象标识子对象物料单 |
作者HOT583.com曾经也是SAP ABAP beginners ,到处去找Tutorial for Constant。
需要自学很久,没人给咱免费培训。
写个测试代码DEMO举例子。下面是代码。希望您喜欢~
SORT gt_out ASCENDING BY matnr werks stlan stlal.
lt_itab1[] = gt_out[].
LOOP AT lt_itab1 INTO gs_out.
CLEAR wa_out.
REFRESH lt_itab2.
wa_out = gs_out.
lt_itab2[] = lt_itab1[].
AT NEW stlal.
DELETE lt_itab2 WHERE matnr NE wa_out-matnr OR werks NE wa_out-werks OR stlan NE wa_out-stlan OR stlal NE wa_out-stlal.
REFRESH:lt_bomgroup,
lt_variants,
lt_materialr,
lt_items,
lt_subitems,
lt_itemassig,
lt_subitemas,
lt_return.
*前导加0
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
input = wa_out-stlal
IMPORTING
output = wa_out-stlal.
*单位转换语言
CALL FUNCTION ‘CONVERSION_EXIT_CUNIT_INPUT’
EXPORTING
input = wa_out-bmein
language = sy-langu
IMPORTING
output = wa_out-bmein
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CLEAR lt_bomgroup.
lt_bomgroup-bom_group_identification = ‘BAPI_SMP_COL1’.
lt_bomgroup-object_type = ‘BGR’.
lt_bomgroup-object_id = ‘SIMPLE1’.
lt_bomgroup-bom_usage = wa_out-stlan. “BOM用途
lt_bomgroup-ltxt_lang = sy-langu. “语言
lt_bomgroup-technical_type = ”.
lt_bomgroup-created_in_plant = wa_out-werks.
lt_bomgroup-bom_text = wa_out-ztext.
APPEND lt_bomgroup.
* Header Details of the different variants
CLEAR lt_variants.
lt_variants-bom_group_identification = ‘BAPI_SMP_COL1’.
lt_variants-object_type = ‘BOM’.
lt_variants-object_id = ‘SIMPLE1′.
lt_variants-alternative_bom = wa_out-stlal. “可选BOM
lt_variants-bom_status = ’02’. “BOM状态
lt_variants-base_qty = wa_out-bmeng. “数量
lt_variants-base_unit = wa_out-bmein. “单位
lt_variants-valid_from_date = wa_out-datuv. “有效期起始日期
lt_variants-alt_text = wa_out-stktx. “可选BOM文本
lt_variants-function = ‘NEW’.
APPEND lt_variants.
* 物料分配 CREATE-/CHANGE BAPI 物料 BOM
CLEAR lt_materialr.
lt_materialr-bom_group_identification = ‘BAPI_SMP_COL1’.
lt_materialr-material = wa_out-matnr. “物料编码
lt_materialr-plant = wa_out-werks. “工厂
lt_materialr-bom_usage = wa_out-stlan. “BOM用途
lt_materialr-alternative_bom = wa_out-stlal. “可选BOM
lt_materialr-lot_size_from = wa_out-losvn. “从批量
lt_materialr-lot_size_to = wa_out-losvn. “到批量
APPEND lt_materialr.
* Details of the items of the variants
LOOP AT lt_itab2.
CLEAR:l_tabix,
l_tabic,
l_object_id.
l_tabix = sy-tabix.
MOVE l_tabix TO l_tabic.
CONCATENATE ‘SIMPLE’ l_tabic INTO l_object_id.
CONDENSE l_object_id NO-GAPS.
CALL FUNCTION ‘CONVERSION_EXIT_CUNIT_INPUT’
EXPORTING
input = lt_itab2-meins
language = sy-langu
IMPORTING
output = lt_itab2-meins
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
* Material BoM Group Header Data
CLEAR lt_items.
lt_items-bom_group_identification = ‘BAPI_SMP_COL1’.
lt_items-object_type = ‘ITM’.
lt_items-object_id = l_object_id.
lt_items-item_no = lt_itab2-posnr. “行号
lt_items-item_cat = lt_itab2-postp. “类别
lt_items-sort_string = lt_itab2-sortf. “排序字符串
lt_items-component = lt_itab2-idnrk. “组件物料
lt_items-item_text1 = lt_itab2-potx1. “项目文本1
lt_items-item_text2 = lt_itab2-potx2. “项目文本2
lt_items-comp_qty = lt_itab2-menge. “组件数量 (BTCI)
lt_items-comp_unit = lt_itab2-meins. “组件计量单位
lt_items-ltxt_lang = sy-langu.
lt_items-valid_from_date = sy-datum. “有效起始日期
* lt_items-sales_rel = lt_itab2-rvrel. “与销售相关
* lt_items-cost_rel = lt_itab2-sanka. “与成本相关
lt_items-mat_provision = lt_itab2-beikz. “物料供应标识
* lt_items-bulk_mat = lt_itab2-schgt. “散装物料标识
lt_items-opr_scrap = lt_itab2-avoau. “工序废品
IF lt_itab2-avoau NE 0.
lt_items-net_scrap_ind = c_con1.
ENDIF.
lt_items-spproctype = lt_itab2-itsob. “特殊获取类
lt_items-iss_st_loc = lt_itab2-lgort. “库存地点
lt_items-alt_item_group = lt_itab2-alpgr. “替代组
lt_items-alt_item_strategy = lt_itab2-alpst. “替代策咯
lt_items-alt_item_prio = lt_itab2-alprf. “优先级
lt_items-usage_prob = lt_itab2-ewahr. “使用可能性
APPEND lt_items.
* linking items to the corresponding variants
CLEAR lt_itemassig.
lt_itemassig-bom_group_identification = ‘BAPI_SMP_COL1’.
lt_itemassig-sub_object_type = ‘ITM’.
lt_itemassig-sub_object_id = l_object_id.”‘SIMPLE1’.
lt_itemassig-super_object_type = ‘BOM’.
lt_itemassig-super_object_id = ‘SIMPLE1’.
lt_itemassig-valid_from_date = sy-datum.
lt_itemassig-function = ‘NEW’.
APPEND lt_itemassig.
* 子项目 CREATE-/CHANGE BAPI 物料 BOM,(子项目要对应起来,子项目的逻辑)
IF lt_itab2-upmng IS NOT INITIAL AND lt_itab2-ebort IS NOT INITIAL AND lt_itab2-uptxt IS NOT INITIAL.
CLEAR lt_subitems.
lt_subitems-bom_group_identification = ‘BAPI_SMP_COL1’.
lt_subitems-object_type = ‘SUI’.
lt_subitems-object_id = l_object_id.
lt_subitems-subitem_no = lt_itab2-posnr. “行号
lt_subitems-subitem_qty = lt_itab2-upmng. “子项目数量
lt_subitems-installation_point = lt_itab2-ebort. “安装地点
lt_subitems-subitem_text = lt_itab2-uptxt. “子项目文本.
APPEND lt_subitems.
*分配 CREATE-/CHANGE BAPI SUI/ITM 物料 BOM
CLEAR lt_subitemas.
lt_subitemas-bom_group_identification = ‘BAPI_SMP_COL1’.
lt_subitemas-sub_object_type = ‘SUI’.
lt_subitemas-sub_object_id = l_object_id.
lt_subitemas-super_object_type = ‘ITM’.
lt_subitemas-super_object_id = l_object_id.
APPEND lt_subitemas.
ENDIF.
ENDLOOP.
* 调用BAPI,创建BOM。
CALL FUNCTION ‘BAPI_MATERIAL_BOM_GROUP_CREATE’
EXPORTING
* TESTRUN = ‘ ‘
all_error = ‘X’
TABLES
bomgroup = lt_bomgroup
variants = lt_variants
items = lt_items
subitems = lt_subitems
materialrelations = lt_materialr
itemassignments = lt_itemassig
subitemassignments = lt_subitemas
* TEXTS =
return = lt_return.
CLEAR l_flag.
LOOP AT lt_return WHERE type = ‘E’ OR type = ‘A’..
l_flag = ‘E’.
ENDLOOP. .
* IF lv_msgty = ‘E’ OR lv_msgty = ‘A’.
* l_flag = ‘E’.
* ENDIF.
IF l_flag = ‘E’.
wa_out-zflag = ‘E’.
* MOVE l_message TO wa_out-zmess.
LOOP AT lt_return WHERE type = ‘E’ OR type = ‘A’.
CONCATENATE lt_return-message wa_out-zmess INTO wa_out-zmess SEPARATED BY ‘;’.
ENDLOOP.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.
ELSE.
l_bom_no = sy-msgv2+0(8).
wa_out-zflag = ‘S’.
wa_out-zmess = ‘Succeed’.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = ‘X’.
ENDIF.
本文链接 : http://www.hot583.com/2022/04/06/bapi_material_bom_group_create/
本文为作者原创,如果这篇文章对您有用,欢迎转载,
转载请务必注明来源《今日热点在看》http://www.hot583.com/
我的微信公众号【 hot583 】 或者在这个链接联系我
微信原文《全文完》