‎2006 Jan 09 3:17 PM
Hello everybody,
Actually I'm working in a CRM 4.0 development project and I'm totally new in ABAP Programming (until now three years in functional roles).
My question is the following:
I have to develop an action method which delete several partner functions from partner tab in a sales order (for all included items and always the same partner functions, ZO1, ZO2 and ZO3 for example).
Which is the best way to do it? Maybe using CRM_ORDER_MAINTAIN function?
Could anybody help me posting some example code or any guideline?
Thank you very much.
I won't forget reward your answers.
‎2006 Jan 20 3:31 PM
here is the example code:
look at this,
METHOD if_ex_order_save~prepare .
TYPES: BEGIN OF t_guids,
guid TYPE crmt_doc_flow_wrk-objkey_a,
END OF t_guids.
Header GUID's.
DATA: lt_header_guid TYPE crmt_object_guid_tab,
ls_header_guid TYPE crmt_object_guid,
Read appointments.
lt_appointment_wrk TYPE crmt_appointment_wrkt,
ls_appointment_wrk TYPE crmt_appointment_wrk,
Update appointments.
lt_appointment_com TYPE crmt_appointment_comt,
ls_appointment_com TYPE crmt_appointment_com,
GUID's
lt_guids TYPE TABLE OF t_guids,
ls_guids TYPE t_guids,
Update fields.
ls_input_fields TYPE crmt_input_field,
lt_input_fields TYPE crmt_input_field_tab,
ls_input_field_names TYPE crmt_input_field_names,
lt_input_field_names TYPE crmt_input_field_names_tab,
Order header data.
lt_orderadm_h TYPE crmt_orderadm_h_comt,
Objects to be updated.
lt_objects_to_save TYPE crmt_object_guid_tab,
Exceptions.
lt_exception TYPE crmt_exception_t,
Updated documents.
lt_saved_objects TYPE crmt_return_objects,
lt_objects_not_saved TYPE crmt_object_guid_tab,
Local update task.
lv_update_task_local TYPE boolean.
Use a global variable to ensure this method is only called once per user save.
IF gv_first IS INITIAL.
gv_first = 'X'.
Get the dates for the current activity.
ls_header_guid = iv_guid.
INSERT ls_header_guid INTO TABLE lt_header_guid.
CALL FUNCTION 'CRM_ORDER_READ'
EXPORTING
it_header_guid = lt_header_guid
IMPORTING
et_appointment = lt_appointment_wrk
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.
EXIT.
ENDIF.
DELETE lt_appointment_wrk WHERE appt_type <> 'ZLSC00003'
OR timestamp_from IS INITIAL.
Check if the conclusion date has been set (appointment type ZLSC00003).
READ TABLE lt_appointment_wrk
INTO ls_appointment_wrk
WITH KEY appt_type = 'ZLSC00003'.
IF sy-subrc = 0.
.......
Coding removed here, build up the follow up GUID's from the document flow.
lt_header_guid now contains the parent GUID and the follow up activty GUID's
*........
Get all of the date details for all of the documents.
CALL FUNCTION 'CRM_ORDER_READ'
EXPORTING
it_header_guid = lt_header_guid
IMPORTING
et_appointment = lt_appointment_wrk
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.
EXIT.
ENDIF.
Get rid of date entries which aren't conclusion dates or aren't the same conclusion date.
DELETE lt_appointment_wrk WHERE appt_type <> 'ZLSC00003'
OR timestamp_from <> ls_appointment_wrk-timestamp_from.
Process each of the documents and, if they don't have a conclusion date with the same value,
set up the internal tables to update the document.
LOOP AT lt_header_guid INTO ls_header_guid.
Check if it has a conclusion date with the correct value already.
READ TABLE lt_appointment_wrk
WITH KEY ref_guid = ls_header_guid
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
DELETE lt_header_guid.
CONTINUE.
ENDIF.
Set up the fields to be updated.
CLEAR lt_input_field_names.
ls_input_field_names-fieldname = 'REF_KIND'.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.
ls_input_field_names-fieldname = 'APPT_TYPE'.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.
ls_input_field_names-fieldname = 'TIMESTAMP_FROM'.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.
ls_input_field_names-fieldname = 'TIMEZONE_FROM'.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.
ls_input_field_names-fieldname = 'TIMESTAMP_TO'.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.
ls_input_field_names-fieldname = 'TIMEZONE_TO'.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.
ls_input_field_names-fieldname = 'TIME_UNIT'.
INSERT ls_input_field_names INTO TABLE lt_input_field_names.
ls_input_fields-ref_handle = '0000000000'.
ls_input_fields-ref_guid = ls_header_guid.
ls_input_fields-objectname = 'APPOINTMENT'.
ls_input_fields-field_names = lt_input_field_names.
INSERT ls_input_fields INTO TABLE lt_input_fields.
Set up the values for the fields to be updated.
ls_appointment_com-ref_handle = '0000000000'.
ls_appointment_com-ref_guid = ls_header_guid.
ls_appointment_com-ref_kind = 'A'.
ls_appointment_com-appt_type = 'ZLSC00003'.
ls_appointment_com-timestamp_from = ls_appointment_wrk-timestamp_from.
ls_appointment_com-timezone_from = ls_appointment_wrk-timezone_from.
ls_appointment_com-timestamp_to = ls_appointment_wrk-timestamp_to.
ls_appointment_com-timezone_to = ls_appointment_wrk-timezone_to.
ls_appointment_com-time_unit = ls_appointment_wrk-time_unit.
INSERT ls_appointment_com INTO TABLE lt_appointment_com.
Create an entry in the internal table used to determine which documents will be updated.
INSERT ls_header_guid INTO TABLE lt_objects_to_save.
ENDLOOP.
Change the values in the documents
IF NOT lt_appointment_com IS INITIAL.
CALL FUNCTION 'CRM_ORDER_MAINTAIN'
EXPORTING
it_appointment = lt_appointment_com
IMPORTING
et_exception = lt_exception
CHANGING
ct_orderadm_h = lt_orderadm_h
ct_input_fields = lt_input_fields
EXCEPTIONS
error_occurred = 1
document_locked = 2
no_change_allowed = 3
no_authority = 4
OTHERS = 5.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDIF.
Save the changed date values.
IF NOT lt_objects_to_save IS INITIAL.
CALL FUNCTION 'CRM_ORDER_SAVE'
EXPORTING
it_objects_to_save = lt_objects_to_save
iv_update_task_local = lv_update_task_local
IMPORTING
et_saved_objects = lt_saved_objects
et_exception = lt_exception
et_objects_not_saved = lt_objects_not_saved
EXCEPTIONS
document_not_saved = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDIF.
ENDIF.
CLEAR gv_first.
ENDIF.
ENDMETHOD.