Skip to Content
avatar image
Former Member

'Contract end date' updation for service contract.

Hi Guys,

I used a FM: 'CRM_APPT_MAINTAIN_SINGLE_OW' to update the 'contract end date' value in my BADI. But at the final stage i don't see the value got updated, but the sy-subrc is coming '0'. Can any one explain what is the mistake i did.

Can i use the above FM for this kind of updation.

Please find my code here:

LOOP at i_guid into i_wa_guid.

v_guid = i_wa_guid-guid.

i_wa_appointment-REF_GUID = v_guid.

i_wa_appointment-REF_KIND = 'A'.

i_wa_appointment-APPT_TYPE = 'CONTEND'.

v_end_date = i_wa_guid-end_date.

  • Convert Date to Timestamp

CALL FUNCTION 'ADDR_CONVERT_DATE_TO_TIMESTAMP'

EXPORTING

IV_DATE = v_end_date

IMPORTING

EV_TIMESTAMP = v_timestamp.

i_wa_appointment-TIMESTAMP_TO = v_timestamp.

i_wa_appointment-TIMEZONE_TO = 'CET'.

i_wa_appointment-mode = 'B'.

CLEAR: i_wa_field_names,

i_field_names.

i_wa_field_names-fieldname = 'TIMESTAMP_TO'.

i_wa_field_names-CHANGEABLE = ' '.

APPEND i_wa_field_names TO i_field_names.

CLEAR: i_wa_input_fields,

i_input_fields.

i_wa_input_fields-ref_guid = i_wa_guid-guid.

i_wa_input_fields-ref_kind = 'A'.

i_wa_input_fields-logical_key = 'CONTEND'.

i_wa_input_fields-objectname = 'APPOINTMENT'.

i_wa_input_fields-field_names = i_field_names.

APPEND i_wa_input_fields TO i_input_fields.

  • Call FM: CRM_APPT_MAINTAIN_SINGLE_OW to update the Date

CALL FUNCTION 'CRM_APPT_MAINTAIN_SINGLE_OW'

EXPORTING

IS_APPOINTMENT_COM = i_wa_appointment

CHANGING

CT_INPUT_FIELDS = i_input_fields.

CLEAR: i_wa_appointment,

i_wa_guid,

v_guid,

v_end_date,

i_wa_field_names,

v_end_date,

v_timestamp.

Refresh: i_input_fields.

ENDLOOP.

Regards.

Sunil

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 02, 2008 at 09:46 AM

    Do you do a CRM_ORDER_SAVE and a BAPI_COMMIT_WORK in your BAPI implementation afterwards? If not, you are most probably only updating the memory structures without passing the updated values down into the save interface.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Sunil,

      If the update of the date using FM CRM_APPT_MAINTAIN_SINGLE_OW is executed through a BADI CRM_ORDER_SAVE would have triggered. You can check this by setting a break point in CRM_ORDER_SAVE and executing the program. Another point could be that your date is being replaced by other call back functions. I am guessing the parameters send into CRM_APPT_MAINTAIN_SINGLE_OW is not correct. You can use a where used list and copy the same parameters to be send into the FM. Hope this helps.

      Thanks.

      Anand

  • May 23, 2014 at 12:31 PM

    Hi Sunil ,

    I'm facing the same problem .Can you share how you implemented that fun. Modules ..

    Regards

    Krishna Acharya

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Here is the code for updating Contract end date:

      *Update the Contract End Appointment Type

      READ TABLE i_appointment_i INTO i_wa_appointment_i

      WITH KEY ref_guid = i_wa_guid-guid

      ref_kind = c_refkind "Header

      appt_type = c_appty_cend. "Contract End App.Type

      IF sy-subrc EQ 0.

      CLEAR i_wa_appointment.

      MOVE-CORRESPONDING i_wa_appointment_i TO i_wa_appointment.

      i_wa_appointment-timestamp_from = i_wa_guid-end_date.

      i_wa_appointment-timestamp_to = i_wa_guid-end_date.

      APPEND i_wa_appointment TO i_appointment_t.

      CLEAR: i_wa_field_names,i_field_names.

      i_wa_field_names-fieldname = 'TIMESTAMP_FROM'.

      i_wa_field_names-changeable = c_space.

      APPEND i_wa_field_names TO i_field_names.

      CLEAR i_wa_field_names.

      i_wa_field_names-fieldname = 'TIMESTAMP_TO'.

      i_wa_field_names-changeable = c_space.

      APPEND i_wa_field_names TO i_field_names.

      CLEAR: i_wa_input_fields.

      i_wa_input_fields-ref_guid = i_wa_guid-guid.

      i_wa_input_fields-ref_kind = c_refkind.

      i_wa_input_fields-logical_key = c_appty_cend.

      i_wa_input_fields-objectname = c_objname.

      i_wa_input_fields-field_names = i_field_names.

      APPEND i_wa_input_fields TO i_input_fields.

      ENDIF.

      CLEAR: i_wa_appointment,

      i_wa_guid,

      i_wa_field_names.

      ENDLOOP.

      *Update the Contracts with the new End dates

      IF NOT i_appointment_t IS INITIAL AND

      NOT i_input_fields IS INITIAL.

      CALL FUNCTION 'CRM_ORDER_MAINTAIN'

      EXPORTING

      it_appointment = i_appointment_t

      CHANGING

      ct_input_fields = i_input_fields

      EXCEPTIONS

      error_occurred = 1

      document_locked = 2

      no_change_allowed = 3

      no_authority = 4

      OTHERS = 5.

      IF sy-subrc = 0.

      *To save the document in the database

      CALL FUNCTION 'CRM_ORDER_SAVE'

      EXPORTING

      it_objects_to_save = i_guid_header

      iv_update_task_local = c_check

      IMPORTING

      et_saved_objects = i_saved_objects

      et_exception = i_exception

      et_objects_not_saved = i_not_saved

      EXCEPTIONS

      document_not_saved = 1

      OTHERS = 2.

      IF sy-subrc <> 0.

      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

      ENDIF.

      *Database commit

      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

      ENDIF.

      ENDIF.

      ENDIF.