on 2021 Jul 21 9:29 PM
Hello guys,
I am trying to add a condition value in a sales order at the header level, but it has not been possible.
I have dealt with both the CRM_ORDER_MAINTAIN function and the PRC_INT_HEAD_INPUT function. No error is generated, but the condition classes are not saved in the document either.
Could someone help me understand what I am missing?
Thanks in advance.
I am trying to add it to an existing sales order. The code I am using is the following:
* Fill input fields table
ls_input_fields-ref_guid = guida.
ls_input_fields-ref_kind = kind. "A/B
ls_input_fields-objectname = 'PRIDOC'.
* ls_input_fields_fn-fieldname = 'WAERS'.
* INSERT ls_input_fields_fn INTO TABLE ls_input_fields-field_names.
* ls_input_fields_fn-fieldname = 'KBETR'.
* INSERT ls_input_fields_fn INTO TABLE ls_input_fields-field_names.
INSERT ls_input_fields INTO TABLE lt_input_fields.
* Get pridoc GUID and handle
CALL FUNCTION 'CRM_PRIDOC_GET_HANDLE_OW'
EXPORTING
iv_header_guid = guida
IMPORTING
ev_pd_handle = lv_pd_handle
ev_pridoc_guid = lv_pridoc_guid
EXCEPTIONS
error_occurred = 1
handle_determination_error = 2
orgdata_error = 3
OTHERS = 4.
* Get head conditions
CALL FUNCTION 'PRC_PD_HEAD_SHOW'
EXPORTING
iv_pd_handle = lv_pd_handle
IMPORTING
et_komv_print = lt_komv_print
EXCEPTIONS
non_existing_handle = 1
ipc_error = 2
OTHERS = 3.
* Add new condition
MOVE-CORRESPONDING lt_komv_print TO ls_pridoc-cond_change.
CLEAR: ls_cond_chg.
ls_cond_chg-kbetr = rate.
ls_cond_chg-kwert = rate.
"ls_cond_chg-stunr = 110.
"ls_cond_chg-zaehk = 001.
ls_cond_chg-waers = currency.
INSERT ls_cond_chg INTO TABLE ls_pridoc-cond_change.
* Fill pridoc table header
CLEAR: ls_pridoc.
ls_pridoc-ref_guid = guida. "GUID de cabecera del documento
ls_pridoc-ref_kind = kind. "A/B
ls_pridoc-pricing_type = ptype. "A/G
INSERT ls_pridoc INTO TABLE lt_pridoc.
CALL FUNCTION 'CRM_ORDER_MAINTAIN'
EXPORTING
it_pridoc = lt_pridoc
IMPORTING
et_exception = lt_exception
CHANGING
ct_input_fields = lt_input_fields
EXCEPTIONS
error_ocurred = 1
document_locked = 2
no_change_allowed = 3
no_authority = 4
OTHERS = 5.
ls_objects_to_save = guida.
APPEND ls_objects_to_save TO lt_objects_to_save.
CALL FUNCTION 'CRM_ORDER_SAVE'
EXPORTING
it_objects_to_save = lt_objects_to_save
IMPORTING
et_saved_objects = lt_saved_objects
EXCEPTIONS
document_not_saved = 1
OTHERS = 2.
IF sy-subrc EQ 0.
CLEAR lv_lin.
DESCRIBE TABLE lt_saved_objects LINES lv_lin.
IF lv_lin = 1.
READ TABLE lt_saved_objects INTO ls_saved_objects INDEX 1.
lv_order_object_guid = ls_saved_objects-guid.
lv_order_object_id = ls_saved_objects-object_id.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
ENDIF.
Request clarification before answering.
Hello guys,
I have solved my problem with the following code:
DATA:
guida TYPE crmt_object_guid,
ls_pridoc TYPE crmt_pridoc_com,
lt_pridoc TYPE crmt_pridoc_comt,
ls_pridoc_add TYPE prct_cond_external_input,
ls_input_fields TYPE crmt_input_field,
lt_input_fields TYPE crmt_input_field_tab,
lt_exception TYPE crmt_exception_t,
ls_objects_to_save TYPE crmt_object_guid,
lt_objects_to_save TYPE crmt_object_guid_tab.
* fill pridoc header
ls_pridoc-ref_guid = guida."GUID Sales Document
ls_pridoc-ref_kind = 'A'.
ls_pridoc-pricing_type = 'G'.
* add new price condition
ls_pridoc_add-kschl = 'ZDMG'.
ls_pridoc_add-waers = '%'.
ls_pridoc_add-kbetr = -150.
INSERT ls_pridoc_add INTO TABLE ls_pridoc-cond_add.
INSERT ls_pridoc INTO TABLE lt_pridoc.
* fill input fields table
ls_input_fields-ref_guid = guida.
ls_input_fields-ref_kind = 'A'. "A/B
ls_input_fields-objectname = 'PRIDOC'.
INSERT ls_input_fields INTO TABLE lt_input_fields.
CALL FUNCTION 'CRM_ORDER_MAINTAIN'
EXPORTING
it_pridoc = lt_pridoc
IMPORTING
et_exception = lt_exception
CHANGING
ct_input_fields = lt_input_fields
EXCEPTIONS
error_ocurred = 1
document_locked = 2
no_change_allowed = 3
no_authority = 4
OTHERS = 5.
IF sy-subrc IS INITIAL.
ls_objects_to_save = guida.
APPEND ls_objects_to_save TO lt_objects_to_save.
CALL FUNCTION 'CRM_ORDER_SAVE'
EXPORTING
it_objects_to_save = lt_objects_to_save
EXCEPTIONS
document_not_saved = 1
OTHERS = 2.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
CALL FUNCTION 'CRM_ORDER_INITIALIZE'
EXPORTING
it_guids_to_init = lt_objects_to_save
iv_initialize_whole_buffer = abap_true
iv_init_frame_log = abap_true
iv_keep_lock = abap_false
EXCEPTIONS
error_occurred = 1
OTHERS = 2.
ENDIF.
I hope it helps!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.