cancel
Showing results for 
Search instead for 
Did you mean: 

CRM_ORDER_MAINTAIN - Appointments

Former Member
0 Kudos

Hi all

A client is using the CRM interaction centre (trxn. CIC0). When a date is set in a transaction within CIC0, they want that date copied to all the follow up activities as well when the user saves.

We've already used BADI ORDER_SAVE and FM's CRM_ORDER_READ, CRM_ORDER_MAINTAIN, and CRM_ORDER_SAVE to achieve this for some customer fields that were added in on a customer screen within CIC0 but cannot seem to achieve the same thing for the standard dates (appointments). When testing, the dates don't get copied through and don't appear on the Bdoc's (getting them onto the Bdoc's is the main priority).

Any guidance from ABAP developer's experienced with this area of CRM would be greatly appreciated.

The relevant coding from within the BADI is below:- (for ease of reading I've removed the coding going through the document flow and building up the internal table of GUID's that need to have the date maintained)

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.

Accepted Solutions (0)

Answers (4)

Answers (4)

hammitou_jack
Explorer
0 Kudos

Hi expert,

I want to change the partner and the status of a contract involving closed.

status is updated but the partner is not updated.

I use function module crm_order_maintain

Thank you for your help.

Former Member
0 Kudos

Hi All,

I am currently trying to insert a date into DATE TYPE(APPT_TYPE) in Item Level. There are no errors in the code but the transaction is not updated. Can somebody help me out ? Thanx a lot...

MOVE: gw_service_item_guid_ubb TO gw_appointment-        
      ref_guid,          
      'B' TO gw_appointment ref_kind,                          
      'CONTDISMAN' TO gw_appointment-appt_type,                
      '20060901220000' TO gw_appointment-timestamp_from,
      '20060901220000' TO gw_appointment-timestamp_to,
      'CET' TO gw_appointment-timezone_from,
      'CET' TO gw_appointment-timezone_to,
      'B' TO gw_appointment-mode.
APPEND gw_appointment TO gt_appointment_ubb.

gw_fname-fieldname = 'APPT_TYPE'.
gw_fname-changeable = 'X'.
insert gw_fname into table gt_fname.
gw_fname-fieldname = 'TIMESTAMP_FROM'.
gw_fname-changeable = 'X'.
INSERT gw_fname INTO TABLE gt_fname.
gw_fname-fieldname = 'TIMESTAMP_TO'.
gw_fname-changeable = 'X'.
INSERT gw_fname INTO TABLE gt_fname.
gw_fname-fieldname = 'TIMEZONE_FROM'.
gw_fname-changeable = 'X'.
INSERT gw_fname INTO TABLE gt_fname.
gw_fname-fieldname = 'TIMEZONE_TO'.
gw_fname-changeable = 'X'.
INSERT gw_fname INTO TABLE gt_fname.

gw_input-ref_guid = gw_service_item_guid_ubb.
gw_input-ref_kind = 'B'.
gw_input-objectname = 'APPOINTMENT'.
gw_input-logical_key = '0000'.
gw_input-ref_handle = '0000000000'.
gw_input-field_names = gt_fname.
APPEND gw_input TO gt_input_fields.

gw_item-guid = gw_service_item_guid_ubb.
gw_item-header = '39CF8B702B8B334F90AF4B23CA991925'.
gw_item-ITM_TYPE = gw_orderadm_i_ubb-itm_type.
gw_item-mode = 'B'.
APPEND gw_item TO gt_item.

CALL FUNCTION 'DIALOG_SET_NO_DIALOG'.

CALL FUNCTION 'CRM_ORDER_INITIALIZE'
  EXPORTING
    iv_initialize_whole_buffer = true
  EXCEPTIONS
    OTHERS           = 2.

CALL FUNCTION 'CRM_ORDER_MAINTAIN'
  EXPORTING
    it_appointment                = gt_appointment_ubb
    it_status                     = gt_status_maint
  CHANGING
    CT_ORDERADM_I                 = gt_item
    ct_input_fields               = gt_input_fields
 EXCEPTIONS
   error_occurred                = 1
   document_locked               = 2
   no_change_allowed             = 3
   no_authority                  = 4
   OTHERS                        = 5.

CALL FUNCTION 'DIALOG_SET_WITH_DIALOG'.

CALL FUNCTION 'CRM_ORDER_SAVE'
  EXPORTING
    it_objects_to_save   = gt_obj_guids
  IMPORTING
    et_saved_objects     = gt_saved_objects
    et_objects_not_saved = gt_objects_not_saved
  EXCEPTIONS
    document_not_saved   = 1
    OTHERS               = 2.
IF sy-subrc EQ 0.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
COMMIT WORK.

Useful help will be awarded. : )

Former Member
0 Kudos

i have met the same question, i debug find the field in lt_input_fields , run the crm_order_maitain, the changable is not turn to u2018Xu2019, if this lead to the code not update the fields.

who have some ideas?

Former Member
0 Kudos

Hi,

If it is just the appointments you wish to change I would use function CRM_APPT_MAINTAIN_MULTI_OW as it is far easier to get it to work.

I tried using CRM_ORDER_MAINTAIN for item level dates and gave up in the end.

Cheers

Colin.

Former Member
0 Kudos

Hi Colin,

Here's the help on this that I got from a friend ...

"I think the best would be if you would debug this. First thing which you need to do is to call transaction CRMD_ORDER. Change then the appointment of the relevant order.

But before this, call transaction SE24 and go into detail of the class CL_CRM_1O_MAIN.

Go to method 'MAINTAIN_ORDER' and from there to method CALL METHOD me->maintain_1o.

If you jump into maintain_1o, then set a breakpoint at the function call CRM_ORDER_MAINTAIN.

If you change now the appointment of the order via transaction CRMD_ORDER, the program will stop there. You can then easily see, how the function module has to be filled (which fields in detail) in order to achieve what you mentioned (change of appointment)."

N this helped me.Hope it will help you too.

Regards

Priyanka

Former Member
0 Kudos

Hi Mark,

I think the field names you're introducing in lt_input_field_names are not correct. try the following:

1. Set a break point in FM 'CRM_ORDER_MAINTAIN'.

2. Change manually an appointment in a follow-up activity.

3. Click enter and check which values the standard program has populated in ct_input_fields-fieldnames.

Hope it helps,

David

Former Member
0 Kudos

David, hi

Thanks for the suggestion.

In the particular case we were having problems with, the solution was to populate a field called LOGICAL_KEY in the input fields parameter with the value for the date rule applicable for the relevant appointment.

Regards

Mark

Former Member
0 Kudos

Hi Mark,

I have been trying to update an appointment 'Shipping Date' in the CRM Orders ...but probably I am missing out some where. For my case I dont have any date rule on the date.

The relevant code is


gs_field_names-fieldname = 'APPT_TYPE'.
gs_field_names-changeable = 'X'.
INSERT gs_field_names INTO TABLE gs_input_fields-field_names.


gs_field_names-fieldname = 'TIMESTAMP_FROM'.
gs_field_names-changeable = 'X'.
INSERT gs_field_names INTO TABLE gs_input_fields-field_names.

gs_field_names-fieldname = 'LOGICAL_KEY'.
gs_field_names-changeable = 'X'.
INSERT gs_field_names INTO TABLE gs_input_fields-field_names.

gs_input_fields-ref_guid = lc_header_guid.
gs_input_fields-ref_kind = 'A'.
gs_input_fields-objectname = 'APPOINTMENT'.
INSERT gs_input_fields INTO TABLE gt_input_fields.

clear gs_appointment.
clear gt_appointment.
refresh gt_appointment.

gs_appointment-REF_GUID = lc_header_guid.
gs_appointment-ref_kind = 'A'.
gs_appointment-APPT_TYPE = 'ZESSHIP_DAT'.
gs_appointment-TIMESTAMP_FROM = gv_created_at.
gs_appointment-mode = 'U'.

insert gs_appointment into table gt_appointment.


CALL FUNCTION 'CRM_ORDER_MAINTAIN'
 EXPORTING
    IT_APPOINTMENT                = gt_appointment
 CHANGING
   ct_input_fields               = gt_input_fields
 EXCEPTIONS
   error_occurred                = 1
   document_locked               = 2
   no_change_allowed             = 3
   no_authority                  = 4
   OTHERS                        = 5
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ROLLBACK WORK.
ELSE.
  CALL FUNCTION 'CRM_STATUS_UPDATE_DIALOG'.

  CALL FUNCTION 'CRM_ORDER_SAVE'
    EXPORTING
      it_objects_to_save = gt_obj_guids
      iv_no_bdoc_send    = nobdoc
    IMPORTING
      et_saved_objects   = gt_saved_objects.

  COMMIT WORK.

ENDIF.

But I am not able to actually find out where the error is.

Can you please help.

Regards

Priyanka

Former Member
0 Kudos

Thanks...

This is solved now.

Regards

Priyanka