cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Need help with Material Workflow

jimminy1
Participant
0 Likes
659

I inherited a workflow that was created by a consultant using a custom business object ZBS1001006 which is delegated to BUS1001006. The workflow is started by the BUS1001006.CREATED event. There is no entry in SWEC for MATERIAL for this business object. There is, however, an entry in SWED for MATERIAL on the MARA table for change and create. I am trying to find the underlying logic that causes this event to fire. I don't entirely understand the SWED entries and can only wonder if this is how the CREATED event is accomplished. I've already looked through any possible enhancement spots for the event creation and I only find logic for VIEWCREATED. Hopefully I've supplied enough information for this to make sense what I am asking. The reason I need to know is my company is now asking for the same workflow to fire when a material is extended. I added the VIEWCREATED event to the same workflow under Start Event and now the workflow is firing multiple times for the VIEWCREATED event and one time for the CREATED event. I tried using a function module to check the instance for existence before it fires VIEWCREATED but it did not work. In SWEL, VIEWCREATED is being fired first so at this point an instance does not exist. I do not want to create another custom workflow to fire the VIEWCREATED event because they want to use the same steps as the workflow for when a material is first created. I would like to use the same workflow for both events. So my questions are:

1. How can I find out where the logic is that causes the CREATED event to fire or is it possible that the SWED entry does that?

2. How can I use one workflow for both events without having it fire multiple times? Please forgive if I have not supplied enough information. If you need me to clarify anything please ask. I am still new to this.

Thank you,

D.

Accepted Solutions (1)

Accepted Solutions (1)

pokrakam
Active Contributor
0 Likes

Hi,

SWED defines events based on change documents, there is no underlying logic. If an activity occurs in the table that matches the SWEC/SWED entries an event is raised, it's that simple. Thus an entry for table MARA, activity CREATE means each time a record is added to MARA it will trigger. SWED can contain additional functionality to do further stuff - look out for any entries under function module or key manipulation.

I have slightly bad news in that what you are doing can get messy. Which event do you want to suppress? Look at implementing a check function in your event linkage to suppress views you don't want to trigger WFs. Someone can create a material and 5 views, another time a material can be created with one view and another 7 views be added one by one. What if a workflow is already in progress, should another one start? In my experience, material workflows have been some of the most complex ones out there. I've built ones that took a few days and others that have taken months.

Regards,

Mike

jimminy1
Participant
0 Likes

Mike,

From my understanding an entry in SWEC linking the business object is required along with the SWED entry. My system only has a SWED entry for MARA on create and change. There is no SWEC entry for BUS1001006 to MATERIAL. I would think this would need to be there in order to raise an event based on the change document. Does that mean that change documents are not being used to create the event for BUS1001006 on my system?

Former Member
0 Likes

Hi D,

If the requirement is to trigger the same workflow on material extension, do not add any event in config to trigger it. Create a custom event in the custom BO and find a spot an exit to raise that event for material extension. Also call FM 'SWE_EVENT_CREATE' with key and event details and the BO type.

Now before calling this FM always check FM 'SAP_WAPI_WORKITEMS_TO_OBJECT' for any existing workflow instances.

So the CREATED event trigger does not changes.

You add a custom event to trigger the workflow for material extension.

When you create a view and or any changes pertaining to the material extension should go through the same trigger and and would be by passed by the instance check logic.

Let me know if you need more details.

Regards,

Sandip

jimminy1
Participant
0 Likes

Sandip,

Thanks for your response. I am thinking this might work but the problem is finding a spot to add this logic. I need help with how to do that. First of all, I cannot find the logic that raises the CREATE event. Maybe I don't need to know that in order to do this but it would be helpful to know where/how it is raised.

Can you give me some direction on how best to find an enhancement spot?

Thanks,

D.

jimminy1
Participant
0 Likes

I was trying to avoid creating any custom events/logic and just use what SAP provided but I was unable to get it to work for my particular scenario. So, I added a custom event to my business object and implemented an enhancement spot in the MGA package and called SAP_WAPI_CREATE_EVENT to fire the event since it is newer logic instead of SWE_CREATE_EVENT. It works perfectly when I need it to. I knew this would be a possible solution before I posted but I have marked yours as the solution because it did resolve my issue, Sandip. Thanks so much to all of your for your input.


Answers (2)

Answers (2)

former_member16044
Active Participant
0 Likes

Hi D,

Once cross-check there are not multiple entries(Business object and event) across the MATERIAL 'On Change' event.

Regards,

Rahul Kulkarni

I042439
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi D

Since both events are getting fired in the same LUW, if you use a FM (check FM) to look for a running instance, you will not find one because check FM gets executed in the same LUW......you can even try that by putting an endless loop in the check FM!

Once the workflow starts, it's in a separate LUW! So the triggering of the two events happen in ONE LUW, but their workflows are then started in separate LUW's.

As a first step in the workflow, you can check for a running instance and if found, terminate the self (the instance checking for a running workflow)... this way you will not have to worry for more than 2 running instance....each checks for a running instance , self terminates and the LAST instance to check is the lucky one to continue further.

However, this is hypothetical, please try to check this with every permutation and combination of steps which the user may perform while creating / changing the material.

Regards,

Modak