Sap Abap Workflow
Sap Abap Workflow
Sap Abap Workflow
4. Copy Standard Task and Adding Description & Attachment to User Decision Task (PFTC_COP)
10. Creating Background Task /Methods (Update Approved Status at the End of All Approvals)(SWO1)
Tcode: ZBUDG01 -> Create Budget Request, ZBUDG03 -> Display Data .
Table: zbudg_req
First of all we are creating Business object (TCode: SWO1 - Object-Name: ZBUSBUDGR) for this
application's workflow, we will use this in the workflow event to trigger the workflow.
When creating BO: ZBUSBUDGR, Fill the required data as well as like,
1. First of all, we created Fields key (ReqID) using Dictionary Table like (ZBUDG_REQ).
2. Now we created Event ID like Created.
3. Now we need to change the status of BO, Event form Modeled to Implement or Released.
But here the difference between that Implement and Released is that, Implement object can be
edit/modify but Released object can't modify. so here we need to choose Implement until our BO do
not final.
To Implement BO , Select BO , Choose from Menu EDIT-> Change Release Status -> Object Type -> To
Implemented.
To Implement Methods/Events Select , Choose From Menu EDIT-> Change Release Status -> Object
Type Components -> To Implemented.
After that Press Button to generate the BO. Here no need to implement the key field. Just go back and
Display / Edit BO. The status of Key-Field from Modeled to Implemented automatically changed.
4. Now we creating Workflow (zwf_budgreqt) using (TCode: SWDD) with user Decision Task.
First of all, we assigned event (Created) which is used to trigger workflow. Menu -> Goto -> Basic Date
and then assign BO (ZBUSBUDGR) with event(Created) and Save it.
5. Now we created Workflow element same like BO(ZBUSBUDGR) to pass data from event to Workflow
and workflow to event. Means this element will have Import and export characterises. After that Bind
the Event Binding and active it.
5. Now we want to insert SAP Standard Screen for approvals, we need to use User Decision task. Right
Click on the blank place and select User Decision task.
Click Save and Activate it.
Triggering Workflow
Now we just need to trigger Workflow. So added the logic of code in Application code.
Save the entry from application and check the workflow is triggered or not. Enter TCode: SWIA and
check the desired result like this.
Also we can check the workflow log or workflow item container values etc. Enter TCode: SBWP and
check the workflow inbox. click workflow and select desired item and double click on it. after that we
can Approve or Reject etc.
Copy Standard Task and Adding Description & Attachment to User Decision Task
Now we need to change the description of User-Decision task. But we can't change the standard. So we
need to copy the Standard User Decision Task.
Copy the User Decision Task or workflow template, Use the TCode: PFTC_DIS => Display, PFTC_COP =>
Copy.
Enter the Standard Task number & Select the Standard Task from Task Type and press Copy Button.
After Copied we got Custom Task with Number Now we can change it according to our requirements.
Now changes from the copied task, Enter Tcode: PFTC_CHG. Click the Edit Button and
Click the Description Tab and press the EDIT and make the description as per your requirements like this.
Now need to add Attachment of Budget Request # to Task so here we created the BO Object only with
Import Parameter in the container of the Task.
Now Copied the Custom Task Number and replace standard task number with custom task number.
Here only need Task <=> Windows Binding elements, Select these Binding elements and unselect other
Binding elements.
Press OK button. After that Press the Task binding Button.
Press Ok button and activate the workflow. Now we have to go assign the Possible Agents to task.
Click on Agent Assignment Button from the Task Properties. Select the Task and Press Attribute Button,
Select General Task and Press Transfer. And go back to the task. Save and activate the Workflow.
Again Save new entry from the ZBUDG01. Workflow will automatically trigger at the Save Time.
Now we seen, Attachment is shown but only display the Field Key (Request Number).
Call Transaction with Key Field (Budget Request#) Attachment Number.
Enter Transaction: SWO1 and open the BO which is created for Workflow. Clicked on Display Method
and Press the Redefine Method. It will be while from red mean it is available for code. Press the Program
Button.
ID_REQID = OBJECT-KEY-REQID.
CALL TRANSACTION 'ZBUDG03' AND SKIP FIRST SCREEN. " Transaction to display data from
attachment
Add Module in PBO (ZBUDG03). and write the following code in this module to get the Key-Field Value
from Workflow Attachment.
Now created the Method, GetApprover to get the approver list. It is background task so uncheck the
Dialog and remain the synchronous checked. Select the GetApprover Method and Press the Parameters
Button.
Now Created the Parameters, one is for to get the agents list and 2nd for the counting for Agents. Both
are exported Parameters and Both are Created without the Reference of Dictionary.
After Creating these Parameters, Select Method GetApprover, then Select Program, then a pop-up
window will appear, "Create Program with Reference to Functional Etc., Click yes. and Paste the Below
code into the GetApprover Method. After that Implement the method and Generate the BO.
DATA:
get_approv LIKE swhactor OCCURS 0,
numb_appr TYPE swastdtyp-wfcounter,
wa_agent LIKE LINE OF get_approv.
wa_agent-otype = 'US'.
wa_agent-objid = lwa_mapper-approver.
APPEND wa_agent TO get_approv.
ENDLOOP.
When we have to go back, This pop-up screen will appear. Select ok same as it is.. After that save the
workflow and activate it.
Assigning Agent to User Decision Task
Now need to pass tab_agents (Approver List) to user Decision Task for Approvals. for this we have to
need implement Loop structure. So First Created Looping Variable (Loop_Inc) With INT1 with Default
Value 1 and 2nd we Created Rejected With CHAR1, Which will be use in the condition.
Now Right Click on User-Decision Task and Select Create , then Select , Press In-Loop
Button from Pop-up.
Add the condition according to your requirements like this , and Press Ok Button.
After Created Loop, Right Click on the Reject Condition, Right Click on the Create, and Select
and set the Condition like this and Press OK Button.
Again Click on the Loop Agents Node and Process the previous steps , Select and
Set the Conditions Like this and Press Ok Button.
Now Double Clicked on the User-Decision Task. and Add the Agents Table like this.
Click OK Button. Save the Workflow and Activate it. Save the Entry in Application. And Checks the
workflow. It will be Working fine.
Creating Background Task /Methods (Update Approved Status at the End of All
Approvals)
Now created the Method, UpdateStatusApproved to update the Status for Approval Like In-Process to
Approved. It is background task so uncheck the Dialog and remain the synchronous checked. There is no
need to Import and Export Parameters.
Now Click the Menthod, UpdateStatusApproved and Press the Program Button. This Window will Pop-
UP. Click the Yes.
Write the following Code into the Method Templalte like this.
IF SY-SUBRC EQ 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
ENDIF.
After that Change the status of method from modeled to Implement. Now here need to generate the
error in case of updating failed, we will do it using method exception.
Click on the Method, UpdateStatusApproved, then Pressed the Exceptions Button. Add the Exception
Like this and we will use it already in the above code. After that Generate BO.
Now Created Background Task at the End of Workflow, which will update the Approved/Rejected Status
at the end of final Approver action. Select the end of Loop, Press Right Click and Click Create and select
Button.
Press Ok Button. Now Select Approved and Press Click Right and Select and Create New
Background Task and set the method like this.
Click Ok Button and Save the Workflow and Activate It. After that we tested it. It's Working Fine.