Skip to Content
Author's profile photo Konstantin Anikeev

Create a Workflow forecast for shopping cart

Sometimes one needs to create Workflow forecast for the case if workflow must be restarted.

Want to share a solution, I found.

First you need to have a shopping cart header guid.


DATA lo_process     TYPE REF TO /sapsrm/if_wf_process.
lo_process = /sapsrm/cl_wf_process_manager=>get_process_by_document( header_guid ).

So you get a worflow process instance. Then you need to reinitialize process (simulate restart)


/sapsrm/cl_wf_process_manager=>reinitialize_process( lo_process ).

This call returns true, if re-initialization was successful.

So, it’s better to pack it in IF operator


IF abap_true = /sapsrm/cl_wf_process_manager=>reinitialize_process( lo_process ).
........
ENDIF.

Now you are ready to simulate workflow


DATA ls_process_forecast TYPE /SAPSRM/S_WF_PROCESS.
/sapsrm/cl_wf_apv_facade=>create_process_forecast(
  EXPORTING
    iv_document_guid       = header_guid
    iv_document_type       = /sapsrm/if_pdo_obj_types_c=>gc_pdo_shop
    iv_agent_id            = sc_header_created_by
    iv_language            = sc_header_language
  IMPORTING
    es_process             = ls_process_forecast ).

So, in ls_process_forecast you will get a workflow simulation for the restart case.

After processing of simulation you may need to rollback the work or clear workflow simulation cache.


/sapsrm/cl_wf_process_manager=>delete_runtime_config_cache( ).

Regards

Konstantin

P.S.:  English language is not my native language, and any person is not insured from mistakes and typing errors. If you have found an error in the text, please let me know – I’ll correct the post.

P.P.S.: If you have some ideas, how to correct/improve this post – please don’t hesitate to leave a comment.

Assigned tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi..

      In which scenario this is used? Can u elaborate little detail ?

      Where you written the code..

      Thanks for understanding..

      Author's profile photo Konstantin Anikeev
      Konstantin Anikeev
      Blog Post Author

      Hi, Tamil,

      it was processed controlled workflow for shopping cart.

      Code was written in custom report for workflow restart

      Regards

      Konstantin

      Author's profile photo karuna reddy
      karuna reddy

      Hi Konstantin,

      I have a requirement to restart a Shopping Cart workflow when it is resubmitted by requestor after rejection. Here I created a thread which will give more idea about the issue.

      http://scn.sap.com/thread/3707675

      Can I use your logic inside class /SAPSRM/CL_WF_PROCESS_MANAGER and method DETERMINE_PROCESS_RESTART to restart the SC workflow. will it work? Please advise.

      Thanks,

      Karuna

      Author's profile photo Konstantin Anikeev
      Konstantin Anikeev
      Blog Post Author

      Hi Karuna,

      please use BADI /SAPSRM/BD_WF_PROCESS_RESTART for that

      Regards

      Konstantin

      Author's profile photo karuna reddy
      karuna reddy

      Sorry...I meant for same Badi which called under the method DETERMINE_PROCESS_RESTART.

      Thanks for correcting me.