ABAP-CS01BOM批导

  1 FUNCTION zfm_pp_0002.
  2 *"----------------------------------------------------------------------
  3 *"*"本地接口:
  4 *"  IMPORTING
  5 *"     VALUE(IV_TEST) TYPE  CHAR1 OPTIONAL
  6 *"  EXPORTING
  7 *"     VALUE(EV_TYPE) TYPE  CHAR1
  8 *"     VALUE(EV_MESSAGE) TYPE  CHAR255
  9 *"     VALUE(EV_BOMNO) TYPE  STNUM
 10 *"  TABLES
 11 *"      TI_INPUT STRUCTURE  ZSPP_0002 OPTIONAL
 12 *"----------------------------------------------------------------------
 13 
 14   DATA:lt_return   TYPE TABLE OF bapiret2,
 15        ls_return   TYPE bapiret2,
 16        lt_bomgroup TYPE TABLE OF bapi1080_bgr_c,
 17        ls_bomgroup TYPE bapi1080_bgr_c,
 18        lt_variants TYPE TABLE OF bapi1080_bom_c,
 19        ls_variants TYPE bapi1080_bom_c,
 20        lt_mare     TYPE TABLE OF bapi1080_mbm_c,
 21        ls_mare     TYPE bapi1080_mbm_c,
 22        lt_item     TYPE TABLE OF bapi1080_itm_c,
 23        ls_item     TYPE bapi1080_itm_c,
 24        lt_items    TYPE TABLE OF bapi1080_rel_itm_bom_c,
 25        ls_items    TYPE bapi1080_rel_itm_bom_c,
 26        ls_testrun  TYPE bapiflag.
 27 
 28   REFRESH lt_bomgroup .
 29   REFRESH lt_return .
 30   REFRESH lt_variants .
 31   REFRESH lt_mare .
 32   REFRESH lt_item .
 33   REFRESH lt_items .
 34 
 35   LOOP AT ti_input ASSIGNING FIELD-SYMBOL(<fs_input>) .
 36 
 37     AT FIRST .
 38 
 39       CLEAR ls_bomgroup .
 40       ls_bomgroup-bom_group_identification = 'BAPI_SMP_COL1'.
 41       ls_bomgroup-object_type = 'BGR'.
 42       ls_bomgroup-object_id = 'SIMPLE1'.
 43       ls_bomgroup-bom_usage = <fs_input>-stlan. "
 44       ls_bomgroup-created_in_plant = <fs_input>-werks .
 45       ls_bomgroup-ltxt_lang = sy-langu.
 46       ls_bomgroup-technical_type = ''."技术类型
 47       ls_bomgroup-bom_text  = ''."物料清单描述
 48       APPEND ls_bomgroup TO lt_bomgroup .
 49 
 50       CLEAR ls_variants .
 51       ls_variants-bom_group_identification = 'BAPI_SMP_COL1'.
 52       ls_variants-object_type = 'BOM'.
 53       ls_variants-object_id = 'SIMPLE1'.
 54       ls_variants-alternative_bom = <fs_input>-stlal .
 55       ls_variants-bom_status = <fs_input>-stlst .
 56       ls_variants-base_qty = <fs_input>-bmeng .
 57       ls_variants-valid_from_date = <fs_input>-datuv .
 58       ls_variants-alt_text = <fs_input>-stktx .
 59       ls_variants-base_unit = <fs_input>-bmein .
 60       ls_variants-change_no = <fs_input>-aennr .
 61       ls_variants-function = 'NEW'.
 62       APPEND ls_variants TO lt_variants .
 63 
 64       CLEAR ls_mare .
 65       ls_mare-bom_group_identification = 'BAPI_SMP_COL1'.
 66       ls_mare-material = <fs_input>-matnr .
 67       ls_mare-plant = <fs_input>-werks .
 68       ls_mare-bom_usage = <fs_input>-stlan .
 69       ls_mare-alternative_bom = <fs_input>-stlal .
 70       APPEND ls_mare TO lt_mare .
 71 
 72     ENDAT .
 73 
 74     CLEAR ls_item .
 75     SELECT SINGLE sanfe,
 76       sanko,
 77       sanka,
 78       sanin,
 79       erskz,
 80       rvrel
 81       INTO ( @ls_item-prod_rel ,
 82       @ls_item-eng_rel,
 83       @ls_item-cost_rel,
 84       @ls_item-pm_rel,
 85       @ls_item-spare_part,
 86       @ls_item-sales_rel )
 87       FROM t416v
 88       WHERE stlan = @<fs_input>-stlan .
 89     ls_item-bom_group_identification = 'BAPI_SMP_COL1'.
 90     ls_item-object_type = 'ITM'.
 91     ls_item-object_id = 'SIMPLE1'.
 92     ls_item-item_no = <fs_input>-posnr .
 93     ls_item-item_cat = <fs_input>-postp .
 94     ls_item-component = <fs_input>-idnrk .
 95     ls_item-comp_qty = <fs_input>-menge .
 96     ls_item-comp_unit = <fs_input>-meins .
 97     ls_item-comp_scrap = <fs_input>-ausch .
 98     ls_item-iss_st_loc = <fs_input>-lgort .
 99     ls_item-co_product = <fs_input>-kzkup .
100     ls_item-alt_item_group = <fs_input>-alpgr .
101     ls_item-alt_item_prio = <fs_input>-alprf .
102     ls_item-usage_prob = <fs_input>-ewahr .
103     ls_item-alt_item_strategy = <fs_input>-alpst .
104     ls_item-cost_rel = <fs_input>-sanka .
105     ls_item-bulk_mat = <fs_input>-schgt .
106     ls_item-sort_string = <fs_input>-sortf .
107     ls_item-valid_from_date = <fs_input>-datuv .
108     ls_item-fixed_qty = <fs_input>-fmeng .
109     ls_item-item_text1 = <fs_input>-potx1 .
110     ls_item-item_text2 = <fs_input>-potx2 .
111     ls_item-opr_scrap = <fs_input>-avoau .
112     ls_item-net_scrap_ind = <fs_input>-netau .
113     ls_item-change_no = <fs_input>-aennr .
114     ls_item-ltxt_lang = sy-langu.
115     APPEND ls_item TO lt_item .
116 
117     CLEAR lt_items.
118     ls_items-bom_group_identification = 'BAPI_SMP_COL1'.
119     ls_items-sub_object_type = 'ITM'.
120     ls_items-sub_object_id = 'SIMPLE1'.
121     ls_items-super_object_type = 'BOM'.
122     ls_items-super_object_id = 'SIMPLE1'.
123     ls_items-valid_from_date = <fs_input>-datuv .
124     ls_items-function = 'NEW'.
125     APPEND ls_items TO lt_items.
126 
127     AT LAST .
128 
129       ls_testrun-bapiflag = iv_test .
130       CALL FUNCTION 'BAPI_MATERIAL_BOM_GROUP_CREATE'
131         EXPORTING
132           testrun           = ls_testrun
133 *         ALL_ERROR         = 'X'
134         TABLES
135           bomgroup          = lt_bomgroup
136           variants          = lt_variants
137           items             = lt_item
138 *         SUBITEMS          =
139           materialrelations = lt_mare
140           itemassignments   = lt_items
141 *         SUBITEMASSIGNMENTS       =
142 *         TEXTS             =
143           return            = lt_return.
144 
145       IF line_exists( lt_return[ type = 'E' ] )
146         OR line_exists( lt_return[ type = 'A' ] )  .
147 
148         CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
149         ev_type = 'E' .
150 
151         LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A' .
152 
153           ev_message = ls_return-message && ';' && ev_message .
154 
155         ENDLOOP .
156 
157       ELSE .
158 
159         IF iv_test = 'X' .
160           CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
161         ELSE .
162           CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
163             EXPORTING
164               wait = 'X'.
165           READ TABLE lt_return INTO ls_return INDEX 1 .
166           IF sy-subrc = 0 .
167             ev_bomno = ls_return-message_v2+0(8) .
168           ENDIF .
169         ENDIF .
170         ev_type = 'S' .
171 
172       ENDIF .
173 
174     ENDAT .
175 
176   ENDLOOP .
177 
178 ENDFUNCTION.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值