您的位置:首页 > 其它

更改销售订单配置

2010-12-08 16:17 435 查看
这个事情,反映了自己做事情不够坚决,中间尝试了BAPI_SALESORDER_CHANGE,浪费了不少时间。

既然可以同步了已经存在的配置,有配置但没有维护过的,应该也可以维护,可自己没有再深入一步。多走了许多弯 路。

type-pools:ibco2.
data:it_config_old type ibco2_instance_tab2,
g_object type cuib_business_object,
g_cuobj type vbap-cuobj.

*& 检查配置的合法性,即当传入的特性,在系统里没有的直接报错
perform configuration_validity_check tables cfg_list
using it_config_old
salesdocument
ret_msg
g_object
g_cuobj.

*& update configuration.
check ret_msg is initial.
perform update_configuration using it_config_old
g_cuobj
g_object
ret_msg .

*& update status
check ret_msg is initial.
if not status is initial.
perform update_order_header_status using salesdocument
status
ret_msg.
endif.
*& create header text.
check ret_msg is initial.
if not text[] is initial.
perform create_order_header_text tables text
using salesdocument
ret_msg.

endif.

if ret_msg is initial.
ret_msg-type = 'S'.
ret_msg-message = '系统同步成功!'.

endif.

*&---------------------------------------------------------------------*
*& Form configuration_validity_check
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->T_CFG_LIST text
* -->CFG_OLD text
* -->P_VBELN text
* -->R_MSG text
* -->CUIB_BUSINESS_OBJECT text
*----------------------------------------------------------------------*
form configuration_validity_check tables t_cfg_list
using cfg_old type ibco2_instance_tab2
p_vbeln
r_msg type bapiret2
p_object type cuib_business_object
p_cuobj.

data:wa type ibvalue0,
wa_config type line of ibco2_instance_tab2 ,
wa_ibco2 type ibco2_value_rec,
g_object type cuib_business_object,
l_index like sy-tabix,
l_atinn_inner_format(10).
*& 注意应该修改,不 应该硬编码:特性不能指定内部形式
loop at t_cfg_list into wa.

if wa-atinn <> '0000002288' and
wa-atinn <> '0000002291' and
wa-atinn <> '0000002292' .
r_msg-type = 'E'.
r_msg-message = '修改的配置只能为备注,等待技术资料,评审上线时间,请核实!'.
exit.
endif.

if wa-atwrt = ''.
delete t_cfg_list .
endif.

endloop.

check r_msg is initial.

call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = p_vbeln
importing
output = p_vbeln.

select single cuobj
into p_cuobj
from vbap
where vbeln = p_vbeln.

if sy-subrc = 0.

call function 'CUCB_GET_CONFIGURATION'
exporting
instance = p_cuobj
* IS_BUSINESS_OBJECT =
* IV_MOMENT =
* IV_WITH_DB_INSTANCE =
importing
* IBASE =
configuration = cfg_old
* EO_CBASE_REF =
exceptions
invalid_input = 1
invalid_instance = 2
instance_is_a_classification = 3
others = 4
.
if sy-subrc <> 0.
r_msg-type = 'E'.
r_msg-message = '订单的配置读取出现异常,请联系系统管理员!'.
else.
*& 当传入的特性,在SAP内不存在时报错.
loop at t_cfg_list into wa.
* CALL FUNCTION 'CONVERSION_EXIT_ATINN_OUTPUT'
* EXPORTING
* input = wa-atinn
* IMPORTING
* output = l_atinn_inner_format.

check r_msg is initial.
read table cfg_old into wa_config index 1.
if sy-subrc = 0.
read table wa_config-values into wa_ibco2 with key atinn = wa-atinn.
if sy-subrc <> 0.
wa_ibco2-atwrt = wa-atwrt.
wa_ibco2-atinn = wa-atinn.
wa_ibco2-atcod = 1.
*& 当为日期时,后面的。ATFLV需赋值
append wa_ibco2 to wa_config-values.
wa_config-ind-indcha = 'X'.
p_object-object_type = wa_config-owner+0(10).
p_object-object_key = wa_config-owner+10(50).
modify cfg_old from wa_config index 1.
* r_msg-type = 'E'.
* r_msg-message = '传入的特性在SAP不存在,请联系系统管理员!'.
* EXIT.
else.
l_index = sy-tabix.
wa_ibco2-atwrt = wa-atwrt.
modify wa_config-values from wa_ibco2 index l_index.

wa_config-ind-indcha = 'X'.
p_object-object_type = wa_config-owner+0(10).
p_object-object_key = wa_config-owner+10(50).
modify cfg_old from wa_config index 1.
endif.
endif.
endloop.

endif.
else.
r_msg-type = 'E'.
r_msg-message = '订单的对象编号不存在,请核实!'.
endif.

endform. " CONFIGURATION_VALIDITY_CHECK
*&---------------------------------------------------------------------*
*& Form UPDATE_CONFIGURATION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form update_configuration using update_cfg
p_cuobj
p_object structure cuib_business_object
r_msg type bapiret2.

call function 'CUCB_SET_CONFIGURATION'
exporting
root_instance = p_cuobj
* IS_CBASE_HEADER =
changing
configuration = update_cfg
exceptions
invalid_input = 1
invalid_instance = 2
instance_is_a_classification = 3
others = 4.
if sy-subrc <> 0.
r_msg-type = 'E'.
case sy-subrc.
when 1.
concatenate 'invalid_input' '请核查!' into r_msg-message.
when 2.
concatenate 'invalid_instance' '请核查!' into r_msg-message.
when 3.
concatenate 'instance_is_a_classification' '请核查!' into r_msg-message.
when 4.
concatenate 'others_error' '请核查!' into r_msg-message.
endcase.

endif.

call function 'CUCB_CONFIGURATION_TO_DB'
exporting
root_instance = p_cuobj
root_object = p_object
* FORCE_NEW_INSTANCE =
* IV_WITHOUT_COMMIT_UPDATE = ' '
* IV_MATERIAL =
* IV_LOCATION =
* IV_TECHS =
* IMPORTING
* NEW_INSTANCE =
* TABLES
* EXP_NEW_NESTED_CUOBJS =
exceptions
invalid_instance = 1
invalid_root_instance = 2
no_changes = 3
already_registered_for_update = 4
instance_is_a_classification = 5
others = 6
.
if sy-subrc <> 0.

r_msg-type = 'E'.
case sy-subrc.
when 1.
concatenate 'INVALID_INSTANCE' '请核查!' into r_msg-message.
when 2.
concatenate 'INVALID_ROOT_INSTANCE' '请核查!' into r_msg-message.
when 3.
concatenate 'NO_CHANGES' '请核查!' into r_msg-message.
when 4.
concatenate 'ALREADY_REGISTERED_FOR_UPDATE' '请核查!' into r_msg-message.
when 5.
concatenate 'INSTANCE_IS_A_CLASSIFICATION' '请核查!' into r_msg-message.
when 6.
concatenate 'others_error' '请核查!' into r_msg-message.
endcase.
else.
call function 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.

endif.

endform. " UPDATE_CONFIGURATION
*&---------------------------------------------------------------------*
*& Form UPDATE_ORDER_HEADER_STATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form update_order_header_status using p_vbeln
p_status
r_msg type bapiret2.
data:l_objnr like vbak-objnr,
l_user_status like jest-stat,
l_stsma like jsto-stsma .

select single objnr
into l_objnr
from vbak
where vbeln = p_vbeln.

select single stsma
into l_stsma
from jsto
where objnr = l_objnr.

select single estat
into l_user_status
from tj30t
where stsma = l_stsma and
spras = sy-langu and
txt04 = p_status.

call function 'STATUS_CHANGE_EXTERN'
exporting
* CHECK_ONLY = ' '
* CLIENT = SY-MANDT
objnr = l_objnr
user_status = l_user_status
* SET_INACT = ' '
* SET_CHGKZ =
* NO_CHECK = ' '
* IMPORTING
* STONR =
exceptions
object_not_found = 1
status_inconsistent = 2
status_not_allowed = 3
others = 4
.
if sy-subrc <> 0.
r_msg-type = 'E'.
case sy-subrc.
when 1.
concatenate 'OBJECT_NOT_FOUND' '请核查!' into r_msg-message.
when 2.
concatenate 'STATUS_INCONSISTENT' '请核查!' into r_msg-message.
when 3.
concatenate 'STATUS_NOT_ALLOWED ' '请核查!' into r_msg-message.
when 4.
concatenate 'others_error' '请核查!' into r_msg-message.
endcase.
else.
call function 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.

endif.

endform. " UPDATE_ORDER_HEADER_STATUS

*&---------------------------------------------------------------------*
*& Form create_order_header_text
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->T_TEXT text
* -->P_VBELN text
* -->R_MSG text
*----------------------------------------------------------------------*
form create_order_header_text tables t_text
using p_vbeln
r_msg structure bapiret2.

data:l_fname like thead-tdname.
l_fname = p_vbeln.

call function 'CREATE_TEXT'
exporting
fid = '0002'
flanguage = sy-langu
fname = l_fname
fobject = 'VBBK'
tables
flines = t_text
exceptions
no_init = 1
no_save = 2
others = 3.
if sy-subrc <> 0.
r_msg-type = 'E'.
case sy-subrc.
when 1.
concatenate 'no_init' '请核查!' into r_msg-message.
when 2.
concatenate 'no_save' '请核查!' into r_msg-message.
when 4.
concatenate 'others_error' '请核查!' into r_msg-message.
endcase.
endif.

endform. " CREATE_ORDER_HEADER_TEXT
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: