SAP CSO1创建BOM
1业务说明
此文档使用BAPI:BAPI_MATERIAL_BOM_GROUP_CREATE创建BOM
2前台实现
事务代码:CS01
输入行项目信息
保存即可
3代码实现
3.1调用BAPI
抬头
行项目
导入BAPI
3.2问题解决
3.2.1 成本核算标识置空
成本核算标识置空失败,因为业务配置默认打钩,传空置之后,系统默认使用默认配置打上勾。
后来查了资料,是因为当以下字段为空时,就默认使用T416V,也就是业务配置的默认值予以覆盖,
因此需要给其中一个字段传值,这样可以不适用默认值覆盖,这里我们选择的是生产相关字段。
之后就可以顺利置空了。
3.3源代码
"-----------------------------------------@斌将军-------------------------------------------- DATA:gt_bomgroup TYPE bapi1080_bgr_c OCCURS 0 WITH HEADER LINE, " gt_variants TYPE bapi1080_bom_c OCCURS 0 WITH HEADER LINE, " gt_items TYPE bapi1080_itm_c OCCURS 0 WITH HEADER LINE, " gt_subitems TYPE bapi1080_itm_c OCCURS 0 WITH HEADER LINE, gt_materialrelations TYPE bapi1080_mbm_c OCCURS 0 WITH HEADER LINE, gt_itemassignments TYPE bapi1080_rel_itm_bom_c OCCURS 0 WITH HEADER LINE, " gt_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE, gs_return TYPE bapiret2, * texts TYPE bapi1080_txt_c OCCURS 0 WITH HEADER LINE. gw_subitemas TYPE bapi1080_rel_sui_itm_c, gt_subitemas TYPE TABLE OF bapi1080_rel_sui_itm_c. DATA:item_no TYPE i, lv_check TYPE char1, lv_message type char200, lv_text TYPE char120 VALUE 'texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext'. "以父物料汇总 CLEAR gt_bomgroup. gt_bomgroup-bom_group_identification = 'BAPI_SMP_COL1'. "可以为空 gt_bomgroup-object_type = 'BGR'. gt_bomgroup-object_id = 'SIMPLE1'. gt_bomgroup-bom_usage = '1'. "用途 gt_bomgroup-ltxt_lang = sy-langu. gt_bomgroup-technical_type = ''. gt_bomgroup-bom_group = ''. "可以为空 gt_bomgroup-created_in_plant = '2010'."工厂 " gt_bomgroup-bom_text = lt_data-bom_text."BOM文本 APPEND gt_bomgroup. " HEADER DETAILS OF THE DIFFERENT gt_variants CLEAR gt_variants. gt_variants-bom_group_identification = 'BAPI_SMP_COL1'. gt_variants-object_type = 'BOM'. gt_variants-object_id = 'SIMPLE1'. gt_variants-alternative_bom = '09'."备选物料清单 此处要填两位数字,不够补零 gt_variants-bom_status = '01'. "BOM状态 gt_variants-base_qty = '10'."基本数量 " gt_variants-base_unit = lt_data-bmein."计量单位 gt_variants-valid_from_date = sy-datum."生效日期 " gt_variants-alt_text = lt_data-stktx."可选文本 gt_variants-ltxt_lang = sy-langu. gt_variants-langu_iso = sy-langu. gt_variants-function = 'NEW'. "NEW表示新建. APPEND gt_variants. CLEAR gt_materialrelations. gt_materialrelations-bom_group_identification = 'BAPI_SMP_COL1'. "可以为空 gt_materialrelations-material_long = '000000000005000021'. "物料号 gt_materialrelations-plant = '2010'."工厂 gt_materialrelations-bom_usage = '1'."BOM用途 gt_materialrelations-alternative_bom = '09'."可选的BOM 此处要填两位数字,不够补零 APPEND gt_materialrelations. " " CLEAR gt_itemassignments. " gt_itemassignments-bom_group_identification = ''. " 可以为空 " gt_itemassignments-sub_object_type = 'ITM'. " gt_itemassignments-sub_object_id = object_id. " gt_itemassignments-super_object_type = 'BOM'. " gt_itemassignments-super_object_id = 'BOM1'. " gt_itemassignments-valid_from_date = sy-datum. " gt_itemassignments-function = 'NEW'. " APPEND gt_itemassignments. " CLEAR gw_subitemas. " gw_subitemas-bom_group_identification = bom_group_identification. " gw_subitemas-sub_object_type = 'SUI'. " gw_subitemas-sub_object_id = 'SIM1'. " gw_subitemas-super_object_type = 'ITM'. " gw_subitemas-super_object_id = object_id. " APPEND gw_subitemas TO gt_subitemas. "取父物料的子件信息 item_no = item_no + 1. CLEAR gt_items. gt_items-bom_group_identification = 'BAPI_SMP_COL1'. "可以为空 gt_items-object_type = 'ITM'. gt_items-object_id = item_no. gt_items-item_no = '0010'."项目 gt_items-item_cat = 'L'."项目类别 gt_items-component_long = '000000000004000012'."组件编码 gt_items-comp_qty = '10'."组件数量 *gt_items-alt_item_group = gs_data-alpgr."项目替代组 gt_items-prod_rel = 'X'."标识:与生产相关项目 gt_items-cost_rel = ''."成本核算相关项的标识符 *IF gs_data-alpgr IS NOT INITIAL . * gt_items-alt_item_strategy = '2'."替代项目:策略 *ENDIF. *gt_items-alt_item_prio = gs_data-alprf."优先级 *gt_items-usage_prob = 100."以百分比表示的使用概率(备选项目) "gt_items-comp_unit = gs_data-meins."组件计量单位 gt_items-item_text1 = lv_text+0(40)."项目长文本 gt_items-item_text2 = lv_text+40(80). gt_items-ltxt_lang = sy-langu. "这个参数一定要填 APPEND gt_items. CLEAR gt_itemassignments. gt_itemassignments-bom_group_identification = 'BAPI_SMP_COL1'. " 可以为空 gt_itemassignments-sub_object_type = 'ITM'. gt_itemassignments-sub_object_id = item_no. gt_itemassignments-super_object_type = 'BOM'. gt_itemassignments-super_object_id = 'SIMPLE1'. gt_itemassignments-valid_from_date = sy-datum. gt_itemassignments-function = 'NEW'. APPEND gt_itemassignments. "BOM操作 CALL FUNCTION 'BAPI_MATERIAL_BOM_GROUP_CREATE' EXPORTING * TESTRUN = 'X' all_error = 'X' TABLES bomgroup = gt_bomgroup variants = gt_variants items = gt_items materialrelations = gt_materialrelations itemassignments = gt_itemassignments * subitemassignments = gt_subitemas return = gt_return. lv_check = 'S'. LOOP AT gt_return INTO gs_return WHERE type = 'A' OR type = 'E'. lv_message = lv_message && gs_return-message. lv_check = 'E'. ENDLOOP. IF lv_check = 'S'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. * WRITE:GV_NUMBER. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ENDIF. "-----------------------------------------@斌将军--------------------------------------------
定期更文,欢迎关注