1.创建 可批量
如果CO_XT_COMPONENT_ADD缺少需要的字段
可以拷贝出来,
在ZCO_XT_COMPONENT_ADD
添加字段例如:I_TEST 和 I_TESTX
或者memory id传值
在220行左右添加代码后调用BAPI即可
if i_testx is not initial.
ls_resbd_new-TEST = I_TEST.
endif.
也可以调用bapi后直接修改
(SAPLCOBC)RESB_BT[]
内的对应字段
data:is_order_key type coxt_ord_key,
i_material type coxt_material,
is_storage_location type coxt_s_storage_location,
is_storage_locationx type coxt_s_storage_locationx,
is_requ_quan type coxt_s_quantity,
i_operation type afvc-aplzl,
i_posno type cif_r3res-positionno,
ls_return type coxt_bapireturn,
lv_error type c.
data:
lv_matnr type mara-matnr,
lv_aufnr type afpo-aufnr,
lv_sortf type resb-sortf,
lv_sortfx type c,
lv_posnr type char4.
types: begin of ty_resb_bt.
include type resbb.
types: indold type syst_tabix.
types: no_req_upd type syst_datar.
types: end of ty_resb_bt.
types tt_resb_bt type table of ty_resb_bt.
field-symbols: <ft_resb_bt> type tt_resb_bt,
<fs_resb_bt> type ty_resb_bt.
data:begin of lt_aufnr occurs 0,
aufnr type afpo-aufnr,
end of lt_aufnr.
refresh lt_aufnr.
loop at gt_data1 assigning <fs_data1> where check eq 'X'
and cellcolor is initial
and icon ne icon_led_green.
lt_aufnr-aufnr = <fs_data1>-aufnr.
append lt_aufnr.
clear lt_aufnr.
endloop.
sort lt_aufnr.
delete adjacent duplicates from lt_aufnr.
loop at lt_aufnr.
loop at gt_data1 assigning <fs_data1> where aufnr eq lt_aufnr-aufnr.
clear:lv_matnr,lv_aufnr,lv_posnr,is_requ_quan,is_storage_location,is_storage_locationx,
ls_return,lv_error,lv_sortf,lv_sortfx.
unassign:<ft_resb_bt>,<fs_resb_bt>.
lv_aufnr = <fs_data1>-aufnr.
lv_matnr = <fs_data1>-matnr.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = lv_aufnr
importing
output = lv_aufnr.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = lv_matnr
importing
output = lv_matnr.
is_order_key = lv_aufnr.
i_material = lv_matnr.
is_requ_quan-quantity = <fs_data1>-menge.
is_storage_location-werks = <fs_data1>-werks.
is_storage_locationx-werks = 'X'.
if <fs_data1>-lgort is not initial.
is_storage_location-lgort = <fs_data1>-lgort.
is_storage_locationx-lgort = 'X'.
endif.
call function 'CO_XT_COMPONENT_ADD'
exporting
is_order_key = is_order_key
i_material = i_material
is_requ_quan = is_requ_quan
i_operation = i_operation
is_storage_location = is_storage_location
is_storage_locationx = is_storage_locationx
i_postp = 'L'
i_posno = i_posno
importing
es_bapireturn = ls_return
e_error_occurred = lv_error.
if lv_error is initial.
assign ('(SAPLCOBC)RESB_BT[]') to <ft_resb_bt>.
data(line) = lines( <ft_resb_bt> ).
loop at <ft_resb_bt> assigning <fs_resb_bt>.
"新增行数据处理
if sy-tabix = line.
if <fs_data1>-posnr is not initial.
<fs_resb_bt>-posnr = <fs_data1>-posnr.
else.
select single max( posnr )
into <fs_resb_bt>-posnr
from resb
where aufnr eq lv_aufnr.
<fs_resb_bt>-posnr = <fs_resb_bt>-posnr + 1.
lv_posnr = <fs_resb_bt>-posnr.
endif.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = <fs_resb_bt>-posnr
importing
output = <fs_resb_bt>-posnr.
if <fs_data1>-sortf is not initial.
<fs_resb_bt>-sortf = <fs_data1>-sortf.
endif.
if <fs_resb_bt>-xwaok is initial.
<fs_resb_bt>-xwaok = 'X'.
endif.
endif.
endloop.
call function 'CO_XT_ORDER_PREPARE_COMMIT'
importing
es_bapireturn = ls_return
e_error_occurred = lv_error.
if ( ls_return-type = 'S' or ls_return-type = 'W' or ls_return-type = 'I' ) or
ls_return is initial.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
call function 'CO_XT_ORDER_INITIALIZE'.
<fs_data1>-mseg = '新增成功'.
* <fs_data1>-color = 'C500'.
<fs_data1>-icon = icon_led_green.
perform save_history_add using <fs_data1> lv_posnr.
else.
call function 'BAPI_TRANSACTION_ROLLBACK'.
<fs_data1>-mseg = ls_return-message.
<fs_data1>-icon = icon_led_red.
endif.
else.
call function 'BAPI_TRANSACTION_ROLLBACK'.
<fs_data1>-mseg = ls_return-message.
<fs_data1>-icon = icon_led_red.
endif.
wait up to 1 seconds.
endloop.
endloop.
2.修改 单条
data:lt_resb like table of resb with header line.
data:lv_message type string,
lv_matny type mara-matnr.
data:ft_return type table of bapiret2 with header line.
data:lt_return type table of bapiret2 with header line.
data:ls_return type coxt_bapireturn,
ls_return2 type bapiret2,
error type c.
data:order type coxt_ord_key,
compkey type coxt_s_ord_comp_key,
ret type coxt_bapireturn,
bapiret type coxt_t_bapireturn.
data : is_order_key type coxt_ord_key,
is_order_component_key type coxt_s_ord_comp_key,
is_requirement_quantity type coxt_s_quantity,
is_requirement_quantityx type coxt_s_quantityx,
is_confirmed_quantity type coxt_s_quantity,
is_confirmed_quantityx type coxt_s_quantityx,
i_material type coxt_material,
i_materialx type coxt_materialx,
is_order_operation_key type coxt_s_ord_opr_key,
is_order_operation_keyx type coxt_s_ord_opr_keyx,
is_requirement_date type coxt_s_date,
is_requirement_datex type coxt_s_datex,
is_storage_location type coxt_s_storage_location,
is_storage_locationx type coxt_s_storage_locationx,
i_batch type coxt_batch,
i_batchx type coxt_batchx,
i_mi_configuration_object type coxt_config_object,
i_mi_configuration_objectx type coxt_config_objectx.
data :wa_resb type resb,
es_bapireturn type coxt_bapireturn,
e_error_occurred type c.
data:begin of lt_aufnr occurs 0,
aufnr type afpo-aufnr,
end of lt_aufnr.
refresh:lt_aufnr,lt_return.
loop at gt_data2 assigning <fs_data2> where check eq 'X'
and cellcolor is initial
and icon ne icon_led_green.
lt_aufnr-aufnr = <fs_data2>-aufnr.
append lt_aufnr.
clear lt_aufnr.
endloop.
sort lt_aufnr.
delete adjacent duplicates from lt_aufnr.
loop at lt_aufnr.
clear is_order_key.
is_order_key = lt_aufnr-aufnr.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = is_order_key
importing
output = is_order_key.
loop at gt_data2 assigning <fs_data2> where aufnr eq lt_aufnr-aufnr.
clear:lv_matny,ft_return[],ft_return,lv_message.
lv_matny = <fs_data2>-matny.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = lv_matny
importing
output = lv_matny.
if <fs_data2>-potx1 is initial and p_bf ne 'X'.
select *
into corresponding fields of table lt_resb
from resb
where aufnr eq is_order_key
and matnr eq lv_matny
and xloek ne 'X'.
else.
select *
into corresponding fields of table lt_resb
from resb
where aufnr eq is_order_key
and matnr eq lv_matny
and xloek ne 'X'
and potx1 eq <fs_data2>-potx1.
endif.
if lt_resb[] is initial.
<fs_data2>-mseg = '无该原物料可替换'.
<fs_data2>-icon = icon_led_red.
continue.
endif.
loop at lt_resb.
clear:ls_return,ls_return2,is_order_component_key,
is_requirement_quantity,is_requirement_quantityx,
is_storage_location,is_storage_locationx,i_material,i_materialx,
is_storage_location,is_storage_locationx,lv_message,error.
move-corresponding lt_resb to is_order_component_key.
if <fs_data2>-matnr is initial.
i_material = <fs_data2>-matny.
else.
i_material = <fs_data2>-matnr.
endif.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = i_material
importing
output = i_material.
i_materialx = 'X'.
is_storage_location-werks = lt_resb-werks.
is_storage_locationx-werks = 'X'.
if <fs_data2>-menge is not initial.
is_requirement_quantity-quantity = <fs_data2>-menge.
is_requirement_quantityx-quantity = 'X'.
endif.
if <fs_data2>-lgort is not initial.
is_storage_location-lgort = <fs_data2>-lgort.
is_storage_locationx-lgort = 'X'.
endif.
clear lv_zcomp.
if <fs_data2>-matnr is initial."新物料号为空 组件为原物料号
concatenate lt_resb-posnr lt_resb-matnr into lv_zcomp separated by '/'.
else."新物料号不为空 修改的是新物料号的 数量和库区
concatenate lt_resb-posnr <fs_data2>-matnr into lv_zcomp separated by '/'.
endif.
call function 'CO_XT_COMPONENT_CHANGE'
exporting
is_order_key = is_order_key
is_order_component_key = is_order_component_key
is_requirement_quantity = is_requirement_quantity
is_requirement_quantityx = is_requirement_quantityx
is_confirmed_quantity = is_confirmed_quantity
is_confirmed_quantityx = is_confirmed_quantityx
i_material = i_material
i_materialx = i_materialx
is_storage_location = is_storage_location
is_storage_locationx = is_storage_locationx
i_batch = i_batch
i_batchx = i_batchx
i_mi_configuration_object = i_mi_configuration_object
i_mi_configuration_objectx = i_mi_configuration_objectx
importing
es_bapireturn = ls_return
e_error_occurred = error.
if error is initial.
call function 'CO_XT_ORDER_PREPARE_COMMIT'
importing
e_order_key = is_order_key
es_bapireturn = ret
e_error_occurred = error.
if ( ret-type = 'S' or ret-type = 'W' or ret-type = 'I' ) or ret is initial.
data :lt_resb_get type table of resbdget,
lw_resb_get like line of lt_resb_get.
clear:lt_resb_get[],lw_resb_get.
call function 'CO_BC_RESBD_OF_ORDER_GET'
exporting
aufnr_act = is_order_key
* GET_OLD = ' '
* NO_MAKTX = 'X'
* NO_STATX = 'X'
* CHECK_DELETED = ' '
* NO_READ = ' '
* CHECK_VBKZ_DEL = 'X'
* I_ARCHIVE = ' '
tables
* ARESB_EXP =
resbd_get = lt_resb_get[].
loop at lt_resb_get into lw_resb_get where rsnum = lt_resb-rsnum
and rspos = lt_resb-rspos
and rsart = lt_resb-rsart..
if <fs_data2>-sortf is not initial.
lw_resb_get-sortf = <fs_data2>-sortf.
endif.
modify lt_resb_get from lw_resb_get index sy-tabix.
endloop.
call function 'CO_BC_UPDATE_CMP_OF_ORDERS'
* EXPORTING
* FLG_BANF_UPD = YX
* FLG_CALC_CHK = YX
* FLG_LVS_CHK = YX
* IMPORTING
* FLG_LVS =
tables
resbd_get = lt_resb_get[].
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
call function 'CO_XT_ORDER_INITIALIZE'.
endif.
else.
call function 'BAPI_TRANSACTION_ROLLBACK'.
endif.
wait up to 1 seconds.
endloop.
endloop.
endloop.
3.删除 可批量
data:lt_resb type table of resb with header line.
data:lt_return type coxt_t_bapireturn with header line.
data:ls_return type bapiret2.
data it_resb type coxt_t_resbdel with header line .
data:lv_matnr type mara-matnr,
lv_aufnr type afko-aufnr,
lv_message type string,
lv_error type c.
data:ft_return type table of bapiret2 with header line.
data:begin of lt_aufnr occurs 0,
aufnr type afpo-aufnr,
end of lt_aufnr.
refresh lt_aufnr.
loop at gt_data3 assigning <fs_data3> where check eq 'X'
and cellcolor is initial
and icon ne icon_led_green.
lt_aufnr-aufnr = <fs_data3>-aufnr.
append lt_aufnr.
clear lt_aufnr.
endloop.
sort lt_aufnr.
delete adjacent duplicates from lt_aufnr.
loop at lt_aufnr.
clear:lt_resb[],lt_resb,lv_message,ft_return[],ft_return,ls_return,lv_error,
lt_return[],lt_return,it_resb[],it_resb.
loop at gt_data3 assigning <fs_data3> where aufnr eq lt_aufnr-aufnr.
clear:lv_matnr,lv_aufnr.
lv_matnr = <fs_data3>-matnr.
lv_aufnr = <fs_data3>-aufnr.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = lv_matnr
importing
output = lv_matnr.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = lv_aufnr
importing
output = lv_aufnr.
if <fs_data3>-potx1 is initial and p_bf ne 'X'.
select rsnum rspos matnr posnr sortf aufnr
into corresponding fields of table lt_resb
from resb
where aufnr eq lv_aufnr
and matnr eq lv_matnr
and xloek ne 'X'.
else.
select rsnum rspos matnr posnr sortf aufnr
into corresponding fields of table lt_resb
from resb
where aufnr eq lv_aufnr
and matnr eq lv_matnr
and xloek ne 'X'
and potx1 eq <fs_data3>-potx1.
endif.
if lt_resb[] is initial.
<fs_data3>-mseg = '无该物料可删除'.
<fs_data3>-icon = icon_led_red.
continue.
endif.
endloop.
call function 'CO_XT_COMPONENTS_DELETE'
exporting
it_resbkeys_to_delete = it_resb[]
tables
ct_bapireturn = lt_return
exceptions
delete_failed = 1
others = 2.
if lt_return[] is initial.
*刷新变量
perform change_flag_set(saplcozv).
*数据更新到DB
call function 'CO_XT_ORDER_PREPARE_COMMIT'
importing
es_bapireturn = ls_return
e_error_occurred = lv_error.
if ( ls_return-type = 'S' or ls_return-type = 'W' or ls_return-type = 'I' )
or ls_return is initial.
*DB COMMMIT
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
*刷新变量
call function 'CO_XT_ORDER_INITIALIZE'.
loop at gt_data3 assigning <fs_data3> where aufnr eq lt_aufnr-aufnr.
<fs_data3>-mseg = '删除成功'.
<fs_data3>-icon = icon_led_green.
endloop.
else.
clear: lv_error,ls_return.
call function 'BAPI_TRANSACTION_ROLLBACK'.
endif.
else.
call function 'BAPI_TRANSACTION_ROLLBACK'.
loop at gt_data3 assigning <fs_data3> where aufnr eq lt_aufnr-aufnr.
<fs_data3>-mseg = lv_message.
<fs_data3>-icon = icon_led_red.
endloop.
clear lv_message.
endif.
endloop.