Changed Service Order Status Upon Service Confirmation 

Change Status of Preceding Document 

As of now we are updating the status of preceding doc by using ORDER_SAVE Badi.

or 

The Method SET_DOCUMENT_STATUS in processing type which could be use for doing same.

or

I had worked on scenario where we have changed service order status upon service confirmation status gets completed.

I have used a Zmethod to achieve this. Find the below code which I used. Hope it may be useful to you to create Zmethod.

method IF_EX_EXEC_METHODCALL_PPF~EXECUTE .

data: lv_guid_ref       type crmt_object_guid,
      lc_action_execute type ref to cl_action_execute,
      doc_info           type CRMT_DOC_FLOW_WRKT,
      doc_links          type line of CRMT_DOC_FLOW_WRKT,
      header_guid      type CRMT_OBJECT_GUID,
      object_no         type CRM_JSTO-OBJNR,
      order_items       type CRMT_ORDERADM_I_DU_TAB,
      order_item        type line of CRMT_ORDERADM_I_DU_TAB.

* get the object GUID for processing

  create object lc_action_execute.

  call method lc_action_execute->get_ref_object
    exporting
      io_appl_object = io_appl_object
      ip_action      = ip_action
      ii_container   = ii_container
    importing
      ev_guid_ref    = lv_guid_ref.

* If the GUID is not present then get the information from the object
* layer

  if lv_guid_ref is initial.
   CALL FUNCTION 'CRM_INTLAY_GET_HEADER_GUID'
     IMPORTING
       EV_HEADER_GUID       = lv_guid_ref
            .
  endif.

* check the GUID before processing

  check not lv_guid_ref is initial.

* Read the document flow to retrieve the service order number

  CALL FUNCTION 'CRM_DOC_FLOW_READ_OB'
    EXPORTING
      IV_HEADER_GUID        = lv_guid_ref
    IMPORTING
      ET_DOC_FLOW_WRK       = doc_info
            .
*  CALL FUNCTION 'CRM_DOC_FLOW_READ_DB'
*    EXPORTING
*      IV_HEADER_GUID       = lv_guid_ref
*    IMPORTING
*      ET_DOC_LINKS         = doc_info.

* determine if this service confirmation has a service order

  describe table doc_info lines sy-tabix.

  check sy-tabix gt 0.

  read table doc_info into doc_links with key objtype_a = 'BUS2000116'.

* set the user status to Complete upon save of the
* service confirmation

  move doc_links-objkey_a to header_guid.

*  call function 'CRM_STATUS_BUFFER_REFRESH'.

* Lock the service order

   call function 'CRM_ORDER_ENQUEUE'
   exporting
     iv_guid           = header_guid
   exceptions
     foreign_lock      = 1
     system_failure    = 2
     distributed_lock  = 3
     no_change_allowed = 4
     transferring      = 5
     others            = 6.

* Check if the service order is locked

  if sy-subrc = 1 or sy-subrc = 3.
* sent message to the user
  endif.

* Change the header status

   move header_guid to object_no.

   call function 'CRM_STATUS_CHANGE_EXTERN_OW'
   exporting
     objnr               = object_no
     user_status         = 'E0007'
     set_inact           = ' '
   exceptions
     object_not_found    = 1
     status_inconsistent = 2
     status_not_allowed  = 3
     others              = 4.

* Change the line item status

  CALL FUNCTION 'CRM_ORDERADM_I_READ_DB'
    EXPORTING
      IV_HEADER                 = header_guid
    IMPORTING
      ET_ORDERADM_I_DB          = order_items.

* read each item and change the status

loop at order_items into order_item where itm_type ne 'SRVS'.

   move order_item-guid to object_no.

   call function 'CRM_STATUS_CHANGE_EXTERN_OW'
   exporting
     objnr               = object_no
     user_status         = 'E0007'
     set_inact           = ' '
   exceptions
     object_not_found    = 1
     status_inconsistent = 2
     status_not_allowed  = 3
     others              = 4.
 endloop.

* Save the status

   if sy-subrc eq 0.
    call function 'CRM_STATUS_UPDATE_DIALOG'.
   endif.

* set the return processing status

if sy-subrc eq 0.
  rp_status = '1'.
else.
  rp_status = '2'.
endif.

endmethod. 

*--- End ---

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.