DATA: lv_bol_core TYPE REF TO cl_crm_bol_core.
DATA: lv_root TYPE REF TO cl_crm_bol_entity.
DATA: lv_header TYPE REF TO cl_crm_bol_entity.
DATA: ls_header TYPE crmst_adminh_btil .
DATA: LV_SALE TYPE REF TO cl_crm_bol_entity .
DATA: LS_SALE TYPE ZATAB0000MD_BOL_ATTR.
DATA: LV_COST TYPE REF TO cl_crm_bol_entity.
DATA: LS_COST TYPE ZATAB0000MR_BOL_ATTR.
DATA: lc_SALE TYPE REF TO if_bol_bo_col.
DATA: lt_SALE TYPE REF TO if_bol_bo_col_iterator.
DATA: lv_guid TYPE crmt_object_guid.
DATA: le_check TYPE c .
DATA: wa_SALE TYPE ZSALE_STEP .
DATA: lv_save TYPE c .
DATA: lv_commit TYPE c .
DATA: ls_error TYPE crmt_genil_message .
***************************************************************************
e_message = 'E' .
CHECK IT_SALE IS NOT INITIAL .
LOOP AT It_SALE INTO wa_SALE.
LV_GUID = WA_SALE-RECORD_ID.
* SELECT SINGLE guid INTO lv_guid
* FROM crmd_orderadm_h
* WHERE GUID = is_order-object_id .
lv_bol_core = cl_crm_bol_core=>get_instance( ).
lv_bol_core->start_up( 'ONEORDER' ).
TRY.
CALL METHOD lv_bol_core->get_root_entity
EXPORTING
iv_object_name = 'BTOrder'
iv_object_guid = lv_guid
RECEIVING
rv_result = lv_root.
CATCH cx_crm_genil_model_error .
ENDTRY.
IF lv_root IS BOUND AND lv_root->lock( ) = abap_true.
************header
lv_header = lv_root->get_related_entity( iv_relation_name = 'BTOrderHeader' ).
IF lv_header IS NOT BOUND.
lv_header = lv_root->create_related_entity( iv_relation_name = 'BTOrderHeader' ).
ENDIF.
************SALE
FREE lv_SALE . CLEAR le_check .
lC_SALE = lv_header->get_related_entities( iv_relation_name = 'ZAEXT_BOL_RELAT000013' ).
IF lC_SALE IS BOUND.
lT_SALE = lc_SALE->get_iterator( ).
IF lt_SALE IS BOUND.
le_check = 'X' .
ENDIF.
ENDIF.
************************
* LOOP AT It_SALE INTO wa_SALE.
FREE lv_SALE .
IF le_check = 'X' .
lv_SALE ?= lt_SALE->find_by_property( iv_attr_name = 'RECORD_ID'
iv_value = wa_SALE-RECORD_ID ).
ENDIF.
IF lv_SALE IS NOT BOUND.
lv_SALE = lv_header->create_related_entity( iv_relation_name = 'ZAEXT_BOL_RELAT000013' ).
ENDIF.
CHECK lv_SALE IS BOUND .
CLEAR LS_SALE.
CALL METHOD lv_SALE->if_bol_bo_property_access~get_properties
IMPORTING
es_attributes = ls_SALE.
LS_SALE-RECORD_ID = WA_SALE-RECORD_ID.
LS_SALE-PARENT_ID = WA_SALE-PARENT_ID.
LS_SALE-OBJECT_ID = WA_SALE-OBJECT_ID.
LS_SALE-ZZAFLD000068 = WA_SALE-ZZAFLD000068.
LS_SALE-ZZAFLD000069 = WA_SALE-ZZAFLD000069.
LS_SALE-ZZAFLD00006A = WA_SALE-ZZAFLD00006A.
LS_SALE-ZZAFLD00006B = WA_SALE-ZZAFLD00006B.
LS_SALE-ZZAFLD00006C = WA_SALE-ZZAFLD00006C.
LS_SALE-ZZAFLD00006D = WA_SALE-ZZAFLD00006D.
CALL METHOD lv_SALE->if_bol_bo_property_access~set_properties
EXPORTING
is_attributes = ls_SALE.
CLEAR wa_SALE .
* ENDLOOP.
* 5. Submit child objects created
lv_bol_core->modify( ).
* 6. Save and commit changes using global transaction context
DATA: lv_transaction TYPE REF TO if_bol_transaction_context.
lv_transaction = lv_bol_core->get_transaction( ).
CLEAR: lv_save,lv_commit .
lv_save = lv_transaction->save( ).
IF lv_save = 'X' .
lv_commit = lv_transaction->commit( ).
CHECK lv_commit = 'X' .
* 1) use the message container manager
DATA: lv_mcm TYPE REF TO cl_crm_genil_mess_cont_manager.
lv_mcm = lv_bol_core->get_message_cont_manager( ).
* 2) ... to obtain the message container
DATA: lv_object_name TYPE crmt_ext_obj_name,
lv_object_id TYPE crmt_genil_object_id.
lv_object_name = lv_root->get_name( ).
lv_object_id = lv_root->get_key( ).
DATA: lv_mc TYPE REF TO if_genil_message_container.
lv_mc = lv_mcm->get_message_cont( iv_object_name = lv_object_name
iv_object_id = lv_object_id ).
* 3) Access messages
DATA: lv_number_of_errors TYPE int4,
lt_error_messages TYPE crmt_genil_message_tab.
lv_number_of_errors = lv_mc->get_number_of_messages( lv_mc->mt_error ).
IF lv_number_of_errors <> 0.
CALL METHOD lv_mc->get_messages
EXPORTING
iv_message_type = lv_mc->mt_error
iv_for_display = abap_false
IMPORTING
et_messages = lt_error_messages.
e_error = lt_error_messages.
ELSE .
e_message = 'S' .
ENDIF .
ELSE .
IF lv_guid IS NOT INITIAL.
CALL FUNCTION 'CRM_ORDER_DEQUEUE'
EXPORTING
iv_guid = lv_guid.
ENDIF.
ENDIF.
ELSE .
ls_error-type = 'E' .
* CONCATENATE '订单' -object_id '被锁定或者不存在!' INTO ls_error-message .
APPEND ls_error TO e_error. CLEAR ls_error .
ENDIF.
ENDLOOP.
阅读(1592) | 评论(0) | 转发(0) |