Friday, August 16, 2019

SAP Workflow – my first workflow



Workflow


Workflow is a tool for the automation of the business process, consisting of sequence of steps, tasks or event.
One similar example to workflow is the automated lines in the manufacturing industry with station points or loading points.
You can arrange and manage the dependency of tasks. Users can be sent notification for the task waiting in the SAP inbox for approval or action. Users can be informed of milestones in the process.
By automating the process, you free the users from having to know what to do when. Work items are sent to the participants notifying them of what they have to do, and a single click on the notification calls the correct transaction and navigates to the relevant screen.
WebFlow is the internet functionality of SAP Business Workflow.

Components:


Organizational Plan:  to manage the hierarchy of reporting and message flow
Workflow Builder: To generate the Workflow. The Workflow Builder provides a graphical view of the workflow definition.
Events
Business Workplace: SAP Inbox
Role Resolution

Components
Organizational Plan
–  Organizational Unit (a functional unit in your enterprise)
–  Position (Represents a post)
–  Job (classifications of functions in an enterprise)
–  Staff Assignments/Assignment of User-id’s
Standard Task
–  Task (A description of an activity)
Workflow Builder
– Overview
– Step types
– Tasks
– Messages
Events
– Triggering Events
– Terminating Events

Example:

– The scenario starts when an employee fills out a request for leave.
– The filled-out form is then automatically sent to that employee’s supervisor.
– If the supervisor rejects the application, the employee is informed and asked to decide whether he/she wants to re-submit the application or withdraw it completely.
– If the employee decides to revise the application, the form is forwarded to his/her inbox for re-submit.
– If the supervisor approves the request, the employee is informed and the workflow can end.

Steps:

1. Define Organization Plan  (T-code PPOCE)
2. Create Workflow template: (T-code PFTC_INS) to create a basic template of workflow,
       (T-code SWDD) to build the workflow in the workflow builder
3. Define 1st task  (T-code PFTC_INS) (Create notification of 
         absence)                                                                                                                                                                                                                                          
4. Add activity > first task in the workflow
5. 1st Test in SAP Inbox (T-code SBWP)
6. Define 2nd task  (Check notification of absence)
7. Add activity > second task in workflow
8. 2nd Test
9. Integrate User Decision for Re-submit
10. 3rd Test
11. Define 3rd task  (Revise notification of absence)
12. Add activity > third task to the workflow
13. Add 4th Customer Task (Send Notification for approval of leave)

Steps:



Step1: Define Organization Plan or Orgn. Unit (Tcode PPOCE)

step 1_01.png

Step 2:a: Create Workflow Template (T-code PFTC_INS)

step 2_01.png

Using Tcode PFTC_INS you can create workflow template and tasks also. This take you to the Task: Maintain.
In the Task type field, choose the Workflow template for Workflow Template.
For Creating tasks: Choose Standard Task in the Task type field.

Step2:b: View the workflow in T-code SWDD (Workflow Builder)
step 2_02.png

In the middle we have overview graphic/flow-chart. And on the right side on the bottom we have various small buttons/icons called step types. This we can drag and drop and insert into our worflow. We will be using the first step type which is like the /wp-content/uploads/2012/11/step2_03_159675.pngplay button called activity for our Step 3: Create Notification of Absence.

Step3:   Define 1st task  (Create notification of absence)   
Go to the T-code PFTC_INS : Tasks: Maintain
Choose Standard Task in the Task type field.
Give the following values and Save the task. On saving it will give a code Id: like 99500654
Name: Form_created
Abbr: create_form
Work Item Text: vik_notif_absence-create
Object Type: FORMABSENC
Method:  CREATE
Checkbox Synchronous object method, Object method with dialog checked.

Step 4: Add activity > first task  in workflow                                                                                                                                                                                                                                       
Add the Step: Activity to your workflow. /wp-content/uploads/2012/11/step2_03_159675.png in place of undefined step.

step 4_01.png
We have created Task TS99500654 separately using PFTC_INS. 

step 4_02.png

Note the checkbox Advance with Immediate dialog. This means that the work item of the workflow is made available for processing immediately. The user who starts the workflow is also one of the recipients of this first work item. This is the case here because you entered the container element _WF_Initiator as the agent in the step definition.
Note the Binding button. The binding  _WI_ObjectId -> &ABSENCEFORM& has been automatically defined here by the system. This binding ensures that the reference to the notification of absence created is not only known in this task, but also in the workflow.
Now the Workflow Builder screen looks like

step 4_03.png

Step 5:   1st Test in SAP Inbox (T-code SBWP)
When the workflow runs it creates work items which are like e-mails in the SAP Inbox. When it is executed it calls the respective task or transaction screen with the correct data.
Execute your workflow:
The notification of absence form is displayed.

step 5_01.png

Do not make any entries and do Not Save. Instead, choose Cancel.
You have now started the workflow but canceled the processing of its first step.
step 5_02.png
Your workflow inbox now contains one work item for processing. This is the work item for creating a notification of absence, the processing of which you canceled previously. You have to select your work item with the subject as the work item text you have given.
Select the work item, and choose execute (F8).
You return to the Create notification of absence screen where the notification of absence form is displayed. Fill out the form and choose Save. The work item disappears from your workflow inbox.
step 5_03.png
Step 6:   Define 2nd Customer task  (Check notification of absence)
This form formabsenc-create you created before will now be sent to supervisor for approval using the object formabsenc-approve object.
Create another task using PFTC_INS:

step 6_01.png
Note the checkbox Confirm end of processing.

Step 7:   Add activity > second task in worflow
Include Task: Check Notification of Absence in the Workflow. We have Task code as TS99500545.
Check the binding properties

step 7_01.png

We need to create the Approver variable in the workflow container. (left side – bottom, you will see a menu option Workflow container– <double click to create>)
Make the following entries for object &Approver&: Element: Approver, Name: Approver, Description: Approver of the absence request, Reference table: WFSYST, Reference field: AGENT.
and use the object &absenceform& already there.
For Agents Choose Position. Select your position by the name you have created in the organization. You can note down the id of your position from your organization (Tcode – PPOCE) as S50001707. (Don’t provide S in the text field).
step 7_02.png

We can also implement deadline in activities using Latest end, Requested Start, Latest start, Requested end. For e.g. If the superior has not made the decision about the leave request, the requester should be notified. Once the deadline (for e.g. latest end) passes, a work item for missed deadlines appears in your Business Workplace notifying you of the missed deadline.

step 7_03.png
Now, You will see that two branches are now inserted in your workflow definition for the two marked outcomes Approved and Rejected.

Step 8:   2nd Test
Choose execute the workflow. You go to the screen Create Notification of Absence.
When the workflow is started, the work item for creating the notification of absence is provided to you directly for processing. This is because of advancing with immediate dialog. You were introduced to this in the first test. Fill out the form and choose Save.
You now go to the screen of Business Workplace > Inbox through the user-id of superior/supervisor (head).
The work items for you to process are displayed with their work item texts and certain other attributes.
Select your work item for checking the notification of absence and Choose execute.
Either reject or approve the request. Notice the two buttons Approve and Reject.

step 8_01.png

Step 9:   Integrate User Decision for Re-submit
You can see that check Notification has two branches – Approved, Rejected. We will be adding a user decision to the outcome Rejected. With the user decision, the requester can decide to revise and resubmit the leave request if the head of department/supervisor rejects it.
Add the step type : User decision to the workflow.  step 9_01.png

step 9_02.png

step 9_03.png
Now your workflow looks like
step  9_04.png

step 9_05.png
Step 10: Third Test

Again execute your workflow. Fill out the Form and Save it. The work item will disappear from your inbox.
As a superior: Reject the application.
If the request is not approved, the next step in the workflow definition is the user decision. The requester (&WF_INITIATOR&) was entered as the agent for the step. The decision is therefore offered to you again as the requester.
There will be two options: Revise request or Withdraw request.
If you choose Revise request, that should take you to the re-submit form. That is our next step.

Step 11: Define 3rd Customer task  (Revise notification of absence) and add to undefined step at outcome – Revise after the user decision.

step 11_01.png

Use FORMABSENC-UPDATE as object.
In the binding give
_WI_Object_ID  <= &ABSENCEFORM&
In the Agents > expression give  &_WF_INITIATOR& in the field.

Step 13: Add 4th Customer Task (Send Notification)
You have created a complete workflow template with which a notification of absence can be created,  approved and revised.
Now you will insert a step in the workflow definition that sends a notification to the requester after the request has been approved.
Choose Step “Send mail”. Drag it to the Undefined Step after the outcome approved of the step Check notification of absence.
Choose Recipient type – Organizational object,
Choose Agents > Expression Choose &_WF_INITIATOR&.
Enter the subject – < Leave Approved >.
Enter the mail text –  < Dear Colleague, your leave was approved. >
Choose Enter. You will be asked for the name and abbreviation of a task. Fill up the fields.
Other features that can be used in this example:
Integrate Step: Until loop to the workflow,
Adding Container Operations which sets the value of flag,
Modify Customer Tasks (Confirm end of processing),
Implement deadlines in activities.
Other types of step types which can be used in the workflow are Activity, Process Control, Condition, User decision, Document from template, Container operation, Event creator, Multiple condition, Fork,  Undefined step, Loop (Until), Wait step, Loop(While).

Pass values from program to workflow BUS2017 MIGO

This document explains how to get values from a program (BADI in our case), pass the values from the program to the workflow and then pass the values from the workflow to a program (BAPI in our case).


I am myself a beginner in workflow. With some help in SCN, we have been able to set up a workflow to meet the requirements.


1. Creation of a workflow to execute MIGO

This document explains how to get values from a program (BADI in our case), pass the values from the program to the workflow and then pass the values from the workflow to a program (BAPI in our case).

1.1 Requirement:

Once MIGO is done, the client wishes to do another MIGO. For him to know that the first MIGO has been done, he needs to get it in his SAP Inbox (Workflow). From there, he can just execute the workflow and he will do the second MIGO.

1.1 Steps


1.1.1 BAPI

Create a BAPI in SE37 to get the purchase order (we need it because we will open the second MIGO with the purchase order of the first MIGO). We will also call the transaction MIGO in the BAPI (For our requirement, it is ZMIGO, but very similar to MIGO, just some different customizing).
In the BAPI, use the function module BAPI_GOODSMVT_GETDETAIL to get the purchase order.
A BDC is also done in the BAPI to open ZMIGO with the purchase order.
Code:
FUNCTION zbapi_call_transaction.
*”———————————————————————-
*”*”Interface locale :
*”  IMPORTING
*”     VALUE(MATERIALDOCUMENT) TYPE  MBLNR
*”     VALUE(MATDOCUMENTYEAR) TYPE  MJAHR
*”  EXPORTING
*”     VALUE(RETURN) TYPE  BAPIRETURN
*”———————————————————————-
DATA: gt_items TYPE STANDARD TABLE OF bapi2017_gm_item_show,
gs_items
TYPE bapi2017_gm_item_show,
gt_return
TYPE STANDARD TABLE OF bapiret2,
gs_header
TYPE bapi2017_gm_head_02,
l_materialdocument 
TYPE  bapi2017_gm_head_02mat_doc,
l_matdocumentyear
TYPE  bapi2017_gm_head_02doc_year.
DATA: gs_bdcdata  TYPE bdcdata,
gt_bdcdata 
TYPE TABLE OF bdcdata,
l_opt
TYPE ctu_params.
l_materialdocument       = materialdocument.
l_matdocumentyear       
= matdocumentyear.
CALL FUNCTION ‘BAPI_GOODSMVT_GETDETAIL’
EXPORTING
materialdocument
= l_materialdocument
matdocumentyear 
= l_matdocumentyear
IMPORTING
goodsmvt_header 
= gs_header
TABLES
goodsmvt_items  
= gt_items
return           = gt_return.
READ TABLE gt_items INTO gs_items INDEX 1.
IF sysubrc EQ 0.
CLEAR gs_bdcdata.
gs_bdcdata
program  = ‘SAPLMIGO’.
gs_bdcdata
dynpro   = ‘0001’.
gs_bdcdata
dynbegin = ‘X’.
APPEND gs_bdcdata TO gt_bdcdata.
CLEAR gs_bdcdata.
gs_bdcdata
fnam = ‘BDC_CURSOR’.
gs_bdcdata
fval = ‘GODYNPRO-PO_NUMBER’.
APPEND gs_bdcdata TO gt_bdcdata.
CLEAR gs_bdcdata.
gs_bdcdata
fnam = ‘GODYNPRO-PO_NUMBER’.
gs_bdcdata
fval = gs_itemspo_number.
APPEND gs_bdcdata TO gt_bdcdata.
CLEAR gs_bdcdata.
gs_bdcdata
fnam = ‘BDC_CURSOR’.
gs_bdcdata
fval = ‘GODEFAULT_TV-BWART’.
APPEND gs_bdcdata TO gt_bdcdata.
CLEAR gs_bdcdata.
gs_bdcdata
fnam = ‘GODEFAULT_TV-BWART’.
gs_bdcdata
fval = ‘101’.
APPEND gs_bdcdata TO gt_bdcdata.
CLEAR gs_bdcdata.
gs_bdcdata
fnam = ‘BDC_CURSOR’.
gs_bdcdata
fval = ‘GODYNPRO-PO_NUMBER’.
APPEND gs_bdcdata TO gt_bdcdata.
CLEAR gs_bdcdata.
gs_bdcdata
fnam = ‘BDC_OKCODE’.
gs_bdcdata
fval = ‘=OK_GO’.
APPEND gs_bdcdata TO gt_bdcdata.
l_optdismode = ‘E’.
l_opt
defsize = ‘X’.
CALL TRANSACTION ‘ZMIGO’ USING gt_bdcdata OPTIONS FROM l_opt.
ENDIF.
ENDFUNCTION.
 

1.1.2 Business Object

Create a Business Object in SWO1.
It is a copy of BUS2017, we have added our BAPI and an event. We also modified the program.


/wp-content/uploads/2014/04/1_446669.png

Modify the program by clicking on Program above:

/wp-content/uploads/2014/04/2_446670.png

/wp-content/uploads/2014/04/3_446739.png


Add the parameters in the new method (BAPI)

/wp-content/uploads/2014/04/4_446740.png

/wp-content/uploads/2014/04/5_446747.png


Add the parameters in the new Event.

/wp-content/uploads/2014/04/6_446748.png



1.1.3 BADI


Implement the BADI in SE18 / SE19
BADI: MB_DOCUMENT_BADI –
Method: MB_DOCUMENT_BEFORE_UPDATE
Get the purchase order
Use the function module SAP_WAPI_CREATE_EVENT to pass values from program to workflow.
Code:
method IF_EX_MB_DOCUMENT_BADI~MB_DOCUMENT_BEFORE_UPDATE.
DATA : BEGIN OF key,
mblnr
TYPE mkpfmblnr,
mjahr
TYPE mkpfmjahr,
END OF key.
DATA : event_container TYPE TABLE OF swcont.
DATA : objkey TYPE sweinstcouobjkey.
DATA : s_xmkpf TYPE mkpf.
DATA: l_RETURN_CODE TYPE sysubrc,
l_event_id
TYPE SWR_STRUCTEVENT_ID,
lt_container
TYPE STANDARD TABLE OF SWR_CONT,
ls_container
TYPE SWR_CONT.
data :INPUT_CONTAINE type table of SWR_CONT ,
x_cont
type swr_cont.

” numéro commande d’achat
DATA ls_xmseg TYPE mseg.
CLEAR ls_xmseg.
READ TABLE xmseg INTO ls_xmseg INDEX 1.
x_contELEMENT = ‘MATERIALDOCUMENT’.
x_cont
VALUE = ls_xmsegmblnr.
APPEND x_cont to INPUT_CONTAINE.
x_contELEMENT = ‘MATERIALDOCYEAR’.
x_cont
VALUE = ls_xmsegmjahr.
APPEND x_cont to INPUT_CONTAINE.

CALL FUNCTION ‘SAP_WAPI_CREATE_EVENT’
EXPORTING
object_type            
= ‘ZYBI’
object_key             
= objkey
event                   = ‘EVENT2’
COMMIT_WORK            
= space
IMPORTING
RETURN_CODE            
= l_RETURN_CODE
EVENT_ID               
= l_event_id
TABLES
INPUT_CONTAINER        
= INPUT_CONTAINE.
endmethod.
 

1.1.4 Workflow

Create the workflow in SWDD
Add the Business Object in the container and tick Import.
/wp-content/uploads/2014/04/7_446749.png


Create a task with the following details.

/wp-content/uploads/2014/04/8_446750.png



Click on Binding in the above screen:

/wp-content/uploads/2014/04/9_446751.png

/wp-content/uploads/2014/04/10_446752.png


Create an Activity and attach the task to it.


/wp-content/uploads/2014/04/11_446753.png


/wp-content/uploads/2014/04/12_446754.png

Affect Agents

/wp-content/uploads/2014/04/13_446755.png


Add a starting event in Basic Data.

/wp-content/uploads/2014/04/14_446756.png

/wp-content/uploads/2014/04/15_446757.png

Add a Process Control to end the workflow.
/wp-content/uploads/2014/04/1_446669.png


Workflow Final should look like this:

/wp-content/uploads/2014/04/17_446758.jpg

1.2         Tests

MIGO:

/wp-content/uploads/2014/04/5_446747.png

/wp-content/uploads/2014/04/6_446748.png

Verify in SAP Inbox (Transaction SBWP)

/wp-content/uploads/2014/04/7_446749.png

Execute the workflow by double-clicking

/wp-content/uploads/2014/04/21_446760.png



Tick OK and Save.

/wp-content/uploads/2014/04/9_446751.png