У меня есть требование к цене товара, чтобы обновить конечное значение / KWERT на уровне товара. В CRM_UI я могу успешно обновить конечное значение / KWERT, но в моем настраиваемом коде его нельзя обновить. Я также попытался обновить другое поле, которое является Цена / KBETR, и оно было успешно обновлено.
Есть ли другие способы обновить KWERT?
Это поле, которое я пытаюсь обновить:
REPORT ytest_test.
DATA: gt_header_guid TYPE crmt_object_guid_tab ##NEEDED,
gt_e_orderadm_h TYPE crmt_orderadm_h_wrkt ##NEEDED,
gt_e_orderadm_i TYPE crmt_orderadm_i_wrkt ##NEEDED,
gt_orderadm_h TYPE crmt_orderadm_h_comt ##NEEDED,
gt_save_guid TYPE crmt_object_guid_tab ##NEEDED,
gt_saved_objects TYPE crmt_return_objects ##NEEDED,
gt_orderadm_i TYPE crmt_orderadm_i_comt ##NEEDED,
gs_header_guid TYPE LINE OF crmt_object_guid_tab ##NEEDED,
lt_pricing TYPE crmt_pricing_wrkt ##NEEDED,
gt_e_pricing_i TYPE crmt_pricing_i_wrkt ##NEEDED,
gt_pricing_i_new TYPE crmt_pricing_i_comt ##NEEDED,
ls_input_fields TYPE crmt_input_field, "input fields
ls_field_name TYPE crmt_input_field_names, "input fields
lt_input_fields TYPE crmt_input_field_tab, "input fields
ls_cond_change TYPE PRCT_COND_EXTERNAL_CHANGE, "input fields
lt_cond_change TYPE PRCT_COND_EXTERNAL_CHANGE_T.
DATA: lt_pridoc TYPE crmt_pric_cond_t.
gt_header_guid = VALUE #( ( |0050569346451EEA9FB63B376B8F8827| ) ).
"Read order details maintained
CALL FUNCTION 'CRM_ORDER_READ'
EXPORTING
it_header_guid = gt_header_guid
IMPORTING
et_orderadm_h = gt_e_orderadm_h
et_orderadm_i = gt_e_orderadm_i
et_pridoc = lt_pridoc
EXCEPTIONS
document_not_found = 1
error_occurred = 2
document_locked = 3
no_change_authority = 4
no_display_authority = 5
no_change_allowed = 6
OTHERS = 7.
IF sy-subrc = 0 AND lt_pridoc IS NOT INITIAL.
DATA(lt_pric_cond) = VALUE prct_cond_du_tab( lt_pridoc[ 1 ]-pric_cond OPTIONAL ).
DELETE lt_pric_cond WHERE varcond <> 'FAP'.
ASSIGN lt_pric_cond[ varcond = 'FAP' ] TO FIELD-SYMBOL(<fs_pric_cond>).
IF <fs_pric_cond> IS ASSIGNED.
<fs_pric_cond>-kwert = 1672.
UNASSIGN: <fs_pric_cond>.
ENDIF.
data(lo_core) = cl_crm_bol_core=>get_instance( ).
data: lr_coll type ref to IF_BOL_ENTITY_COL.
lo_core->start_up( 'BT' ).
CHECK lo_core IS BOUND.
data(lo_entity2) = lo_core->get_root_entity( iv_object_name = 'BTOrder'
iv_object_guid = '0050569346451EEA9FB63B376B8F8827' ).
CHECK lo_entity2 IS BOUND.
lo_entity2 = lo_entity2->get_related_entity( 'BTOrderHeader' ). "Get Header entity
IF lo_entity2->lock( ) = abap_true.
lo_entity2 = lo_entity2->get_related_entity( 'BTHeaderItemsExt' ). "Get Static Item entity
LOOP AT gt_e_orderadm_i INTO data(ls_order_i).
READ TABLE lt_pric_cond INTO data(ls_cond) WITH KEY kposn = ls_order_i-guid
kschl = 'VASE'.
IF sy-subrc EQ 0.
IF sy-subrc EQ 0.
CHECK lo_entity2 IS BOUND.
TRY.
CALL METHOD lo_entity2->get_related_entities "Get All Item entities
EXPORTING
iv_relation_name = 'BTOrderItemAll'
RECEIVING
rv_result = lr_coll.
CATCH cx_crm_genil_model_error .
ENDTRY.
CHECK lr_coll IS BOUND.
data(lo_entity) = lr_coll->get_first( ).
WHILE lo_entity IS BOUND.
data: lv_product type string.
CALL METHOD lo_entity->if_bol_bo_property_access~get_property_as_value
EXPORTING
iv_attr_name = 'ORDERED_PROD'
IMPORTING
ev_result = lv_product.
IF lv_product EQ 'AP_NW_DEV'.
lo_entity = lo_entity->get_related_entity( 'BTItemConditionSet' ). "Get Static Item Pricing entity
IF lo_entity IS BOUND.
TRY.
data: lr_coll1 like lr_coll.
CALL METHOD lo_entity->get_related_entities
EXPORTING
iv_relation_name = 'BTCondICondLineAll' ""Get Item Pricing entity which is to be changed
RECEIVING
rv_result = lr_coll1.
CATCH cx_crm_genil_model_error .
ENDTRY.
IF lr_coll IS BOUND.
data(lo_entity1) = lr_coll1->get_first( ).
WHILE lo_entity1 IS BOUND.
data: lv_cond type string,
lv_item type string.
CALL METHOD lo_entity1->if_bol_bo_property_access~get_property_as_value
EXPORTING
iv_attr_name = 'KSCHL'
IMPORTING
ev_result = lv_cond.
CALL METHOD lo_entity1->if_bol_bo_property_access~get_property_as_value
EXPORTING
iv_attr_name = 'KPOSN'
IMPORTING
ev_result = lv_item.
IF lv_cond EQ 'VASE' AND lv_item EQ ls_order_i-guid.
"Below is the Logic of Updating PB00 Pricing value of Item entity
lo_entity->switch_to_change_mode( ).
CALL METHOD lo_entity1->if_bol_bo_property_access~set_property
EXPORTING
iv_attr_name = 'KBETR'
iv_value = 160.
CALL METHOD lo_entity1->if_bol_bo_property_access~set_property
EXPORTING
iv_attr_name = 'KWERT'
iv_value = 140.
data: lr_trnx type ref to IF_BOL_TRANSACTION_CONTEXT.
CALL METHOD lo_core->get_transaction
RECEIVING
rv_result = lr_trnx.
lo_core->modify( ).
ENDIF.
lo_entity1 = lr_coll1->get_next( ).
ENDWHILE.
ENDIF.
ENDIF.
ENDIF.
lo_entity = lr_coll->get_next( ).
ENDWHILE.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
clear: gs_header_guid,
gt_header_guid.
gs_header_guid = '0050569346451EEA9FB63B376B8F8827'.
APPEND gs_header_guid TO gt_header_guid.
data: gT_PRIDOC TYPE CRMT_PRIC_COND_T.
CALL FUNCTION 'CRM_ORDER_READ'
EXPORTING
it_header_guid = gt_header_guid
IMPORTING
et_pridoc = gt_pridoc
EXCEPTIONS
document_not_found = 1
error_occurred = 2
document_locked = 3
no_change_authority = 4
no_display_authority = 5
no_change_allowed = 6
OTHERS = 7.
"Save currency update contract
CALL FUNCTION 'CRM_ORDER_SAVE'
EXPORTING
it_objects_to_save = gt_header_guid
IMPORTING
et_saved_objects = gt_saved_objects
EXCEPTIONS
document_not_saved = 1
OTHERS = 2.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
ENDIF.