Vous êtes sur la page 1sur 40

SAP Mobility

SAP Fiori Approve Requests

Adding a custom workflow scenario to


the SAP Fiori Approve Requests in 6 steps
A Branded Service provided by SAP Customer Experience Group

Applicable Releases:
SAP Fiori Approve Requests 1.0
SAP NetWeaver Gateway 2.0 SP 07
SAP Fiori Launchpad

Version 3.1
June 2014

All other produc t and s er vic e names mentioned ar e the trademar ks of their res pecti ve c ompani es. Data c ontai ned i n this document s er ves i nfor mati onal pur poses onl y. National pr oduct specific ati ons may var y.
The infor mation i n this document is pr oprietar y to SAP. N o part of this doc ument may be reproduc ed, c opi ed, or trans mitted i n any form or for any purpose without the expres s prior written per mission of SAP AG.
This doc ument is a preli minar y versi on and not subj ect to your lic ens e agreement or any other agreement with SAP. T his doc ument c ontai ns onl y intended s trategies , developments, and func tionalities of the SAP pr oduc t and is n ot i ntended to be bi ndi ng upon SAP to any parti cular course of busi ness, pr oduct str ateg y, and/or development. Pleas e note th at this doc ument is s ubjec t to c hang e and may be c hanged by SAP at any time without notice.
SAP ass umes no r esponsibility for err ors or omissi ons in this doc ument. SAP does not warrant the ac cur ac y or c ompl eteness of the infor mation, text, graphics , links, or other items contained within thi s materi al. T his document is provi ded without a warranty of any kind, either ex press or i mplie d, i ncl udi ng but not li mited to the i mpli ed warr anties of merc hantability, fitnes s for a partic ular purpos e, or non-infri ngement.
SAP s hall have no li ability for damages of any ki nd including without li mitation direc t, s pecial, indirec t, or c onsequenti al damages that may res ult from the us e of thes e materi als. T his li mitati on shall not appl y i n c as es of i ntent or gross negligenc e.
The statutor y liability for personal inj ur y and defec ti ve pr oduc ts is not affec ted. SAP has no c ontrol over the infor mation th at you may acc ess thr oug h the use of hot links c ontai ned i n these materi als and does not endors e your us e of thir d-party Web pages nor provi de any warranty whatsoever rel ating to third-party Web pages.

Copyright 2013 SAP AG. All rights reserved.


No part of this public ation may be reproduc ed or trans mitted in any for m or for any purpos e without the expr ess permis sion of SAP AG. T he infor mation c ontai ned herei n may be changed without pri or notic e.
Some s oftwar e produc ts mar keted by SAP AG and its dis tributors contai n pr oprietar y s oftware c omponents of other s oftwar e vendors.
Microsoft, Wi ndows , Excel , Outl ook, and Power Poi nt are registered tr ademar ks of Micr os oft Cor por ation.
IBM, D B2, D B2 Uni vers al D atabas e, System i, System i5, System p, Sys tem p5, Sys tem x, System z, System z 10, Sys tem z9, z 10, z 9, i Seri es, pSeri es, xSeries, zSeries, eSer ver, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterpris e Ser ver, PowerVM , Power Ar c hitecture, POWER6+, POWER 6, POWER 5+, POWER5, POWER , OpenPower, Power PC, Batc hPi pes, BladeC enter, System Storage, GPF S, H ACMP, R ETA IN, D B2 Connect, R ACF, Redbooks , OS/2, Parall el Syspl ex, M VS/ESA, AIX,
Intelligent Miner, WebSphere, N etfi nity, Ti voli and Informi x ar e tr ademar ks or registered trademar ks of IBM Cor por ati on.
Linux is the r egister ed tr ademar k of Linus T or val ds i n the U.S. and other c ountries.
Adobe, the Adobe l ogo, Acr obat, PostScript, and Reader are either tr ademar ks or registered tr ademar ks of Ado be Sys tems Inc orporated in the United States and/or other c ountries.
Oracl e is a r egister ed trademar k of Or acle C or por ation.
UNIX, X/Open, OSF/1, and M otif ar e r egister ed trademar ks of the Open Group.
Citrix, IC A, Program N eighbor hood, M etaFrame, Wi nFrame, Vi deoFr ame, and M ultiWi n are trademar ks or r egister ed trademar ks of Citri x Systems, Inc.
HTML, XML, XHTML and W3C ar e tr ademar ks or registered tr ademar ks of W3C, World Wide Web Cons ortium, Massac hus etts Institute of Tec hnol og y.
Java is a r egister ed trademar k of Sun Micros ystems, Inc .
JavaScri pt is a registered tr ademar k of Sun Micros ystems, Inc., used under licens e for tec hnol ogy invented and i mpl emented by N etsc ape.
SAP, R /3, SAP N etWeaver, D uet, PartnerEdge, ByDesig n, SAP BusinessObj ects Explor er, StreamWor k, and other SAP pr oducts and s er vic es mentioned herein as well as their r espec ti ve l ogos ar e tr ademar ks or regist ered trademar ks of SAP AG in Germany and other c ountries.

SAP How-to Guides are intended to simplify the product implementation.


While specific product features and procedures typically are explained in a

Business Objects and the Business Objects logo, BusinessObjects, Crystal

practical business context, it is not implied that those features and

Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business

procedures are the only approach in solving a specific business problem

Objects products and services mentioned herein as well as their respective

using SAP NetWeaver. Should you wish to receive additional information,

logos are trademarks or registered trademarks of Business Objects

clarification or support, please refer to SAP Consulting.

Software Ltd. Business Objects is an SAP company.

Any software coding and/or code lines / strings (Code) included in this

Sybas e and Adapti ve Ser ver, i Anywhere, Sybas e 365, SQL Anywher e, and other Sybase pr oduc ts and s er vic es mentioned herei n as well as their r es pec ti ve logos ar e trademar ks or registered trademar ks of Sybase, Inc. Sybas e is an SAP c ompany.

documentation are only examples and are not intended to be used in a


productive system environment. The Code is only intended better explain
and visualize the syntax and phrasing rules of certain coding. SAP does not
warrant the correctness and completeness of the Code given herein, and
SAP shall not be liable for errors or damages caused by the usage of the
Code, except if such damages were caused by SAP intentionally or grossly
negligent.
Disclaimer
Some components of this product are based on Java. Any code change
in these components may cause unpredictable and severe malfunctions
and is therefore expressively prohibited, as is any decompilation of these
components.
Any Java Source Code delivered with this product is only to be used by
SAPs Support Services and may not be modified or altered in any way.

Document History
Document Version

Description

The first release version.


With Gateway 2.0 SP06 and Approve Request SP01.

With Gateway 2.0 SP07 and Approve Request SP03.

Simplified. Removed check steps.

3.1

Step 6 ABAP code is updated with escaping value

Typographic Conventions

Icons

Type Style

Description

Icon

Example Text

Words or characters quoted


from the screen. These
include field names, screen
titles, pushbuttons labels,
menu names, menu paths,
and menu options.
Cross-references to other
documentation

Example text

Emphasized words or
phrases in body text, graphic
titles, and table titles

Example text

File and directory names and


their paths, messages,
names of variables and
parameters, source text, and
names of installation,
upgrade and database tools.

Example text

User entry texts. These are


words or characters that you
enter in the system exactly as
they appear in the
documentation.

<Example text>

Variable user entry. Angle


brackets indicate that you
replace these words and
characters with appropriate
entries to make entries in the
system.

EXAMPLE TEXT

Keys on the keyboard, for


example, F2 or ENTER.

Description
Caution
Note or Important
Example
Recommendation or Tip

Table of Contents
Business scenario ...........................................................................................................................1
Sample scenario .......................................................................................................................... 1
Prerequisites ................................................................................................................................ 1
1.

2.

3.

4.

5.

6.

Step 1 . Get workflow template information [ERP] ........................................................... 2


1.1

Find the workflow template ID .......................................................................................... 2

1.2

Find the approval step ID and step type .......................................................................... 4

1.3

Find the task ID ................................................................................................................. 6

1.4

Find the Business Object and method for Activity step type .......................................... 6

1.5

Find the outcomes from the step...................................................................................... 7

Step 2. Define workflow scenarios [Gateway] .................................................................. 9


2.1

Define scenario.................................................................................................................. 9

2.2

Assign consumer type ..................................................................................................... 10

2.3

Assign role ....................................................................................................................... 10

2.4

Assign task ...................................................................................................................... 10

Step 3. Add a tile to the Launchpad [Gateway] .............................................................. 12


3.1

Start the launchpad designer (system admin action). ...................................................12

3.2

Check the Target Mapping tile Click on the target mapping tile and make sure the
data matches the list below .............................................................................................13

3.3

Add a new App Launcher Dynamic tile .....................................................................13

3.4

Add app to Launchpad (End user action). ......................................................................15

Step 4. Configure the task decision [ERP] ...................................................................... 18


4.1

Define workflow template and the step .......................................................................... 18

4.2

Assign the step keys ....................................................................................................... 18

Step 5. Implement BADI for decision outcomes [ERP].................................................. 20


5.1

Create BAdI Configuration and Class for Decision Handling ....................................... 20

5.2

Implement BAdI Class for Decision Handling ............................................................... 26

Step 6. Display application data [Gateway] ....................................................................30


6.1

7.

Including business data by BADI (Optional but Recommended)[Gateway]................ 30

Test the scenario ............................................................................................................... 34


7.1

Approve from SAP Fiori Approve Requests .................................................................. 34

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

Business scenario
With SAP Fiori Approve Requests, you can add workflow tasks to the Approve Requests. SAP delivers
several standard approval scenarios but standard scenarios are not enough for your business. Now
you are going to add additional custom workflow scenarios to SAP Fiori Approve Requests.
If making an approval/reject decision is simple, you can go live with the generic contents of Approve
Requests. It is an easy and quick solution without big development effort.
If additional functions and UI screens are required, you can enhance the app or develop a custom app.

Sample scenario
In this exercise we will show you how to add Notification of Absence workflow scenario which is the
demo workflow of SAP Business Workflow. It is available in all AS ABAP systems. This workflow is an
Absence Approval scenario. It has an Activity step type which is bound to a BOR object/method. Your
job will be to expose this to SAP Fiori Approve Requests app.
Implementation steps are 6 steps.
1.
2.
3.
4.
5.
6.

Get workflow template information


Define workflow scenarios
Add a tile to the Launchpad
Configure the task decision
Implement the BADI for task outcomes
Display application data

Prerequisites
SAP Fiori Approve Requests is used for illustration throughout this exercise.

The workflow scenario is up and running in the SAP Business Suite system.

SAP NetWeaver Gateway 2.0 SP07 or higher system and basic settings are configured.

SAP Notes for SAP Business Workflow have been applied. The notes are listed in the SAP Fiori
Installation and Configuration guide.

One of the standard SAP Fiori approval apps are configured and running.

Jun 2014

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

1. Step 1 . Get workflow template information [ERP]


Before configuring the scenario, you should know the workflow template information.
Note: If you are in an SAP Education course, different workflow template ID and task ID are assigned
to each user. Please get your assigned workflow template ID and task ID from your instructor and
replace the WSXXXXXXXX and TSXXXXXXXX by your assigned ID.
Table: Workflow Information.
No

Information

Your scenario

Workflow template ID

WSXXXXXXXX

Approval step ID

48

Step type

Activity

Task ID

TSXXXXXXXX

Business Object

FORMABSENC

Approval Method

APPROVE

Outcomes

Container or Event

FORMABSENC sample in
this doc

Container value

Approve

Reject

Others

1.1

Find the workflow template ID

You are already using workflow scenarios in the production system. Find the workflow template ID that
you are going to integrate with SAP Fiori Approve Requests.
Note: This step will show you where to go to obtain the required information however no activity will be
performed here.

List workflow template last 365 days


1. Launch the SAP GUI (Start -> SAP Logon for Windows -> ZME System -> enter assigned
credentials)
2. If youre already in the GUI enter/N to return to the home screen in the ZME system then
enter Transaction: SWI2_FREQ and choose enter from your keyboard

Jun 2014

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

3. Select Last 365 days, uncheck Dialog and check (Sub-) Workflow then choose Execute

4. Select the Task Header and Sort in descending order

5. Workflow Templates are prefixed with WS, reference the workflow number for Z00 user
(WS97100480).
Remember this step is to show you where to find workflow templates and how to filter.
NOTE: The WS30000015 Process Notification of absence is the sample workflow in this
Exercise.

Jun 2014

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

1.2

Find the approval step ID and step type

Display the workflow template


6. Enter Transaction: /NPFTC

7. Choose Workflow template in the task type drop down and manually enter your
assigned task number (only the number as shown in the image below) in the task field. Then
choose the glasses button to display

8. Choose Workflow Builder

Jun 2014

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

9. Notice the approval step is 48. Choose this step by double clicking on it.

10. Check the step type (At the top of the screen above the tabs)

Explanation of Step types (for our exercise we want Activity step type)
Icon

Step type
Activity

Function Module or Transaction will be called. Most of


approval tasks are activity type.

User Decision

User will select decision options manually

Web activity

Web application integration

Form

From integration

If the approval step type is Web activity or Form type, you need to adjust workflow template.
Please contact workflow consultants to adjust.

Jun 2014

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

1.3

Find the task ID

1. Note your approval task ID (it should match the task number that was assigned to you) and
double click it

1.4

Find the Business Object and method for Activity step type
(Most of approval steps are activity type which calls Business Object method.)

2. Notice the Business Object is FORMABSENC


Method is APPROVE

Jun 2014

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

1.5

Find the outcomes from the step

1. Select F3 from your keyboard to return to the previous Workflow Builder Display screen
2. Choose the Outcomes tab
Notice Approved and Rejected are listed as possible outcomes for the approve step.

3. Select the outcome Approved and Rejected by double clicking them and see the result value.
The result value of Approved is A.
The result value of Rejected is R.

4. Now you have all required workflow information.


Table: Workflow Information.
No

Information

Workflow template ID

WS30000015

Approval step ID

48

Jun 2014

Your scenario

FORMABSENC
sample in this doc

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

Step type

Activity

Task ID

TS30000016

Business Object

FORMABSENC

Approval Method

APPROVE

Outcomes

Container or Event

Container value

Approve

Reject

Others

Jun 2014

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

2.

Step 2. Define workflow scenarios [Gateway]

2.1

Define scenario

Set the workflow scenarios in the task gateway customizing in the SAP NetWeaver Gateway.
1. Enter Transaction: /NSPRO -> SAP Reference IMG
SAP NetWeaver -> Gateway Service Enablement -> Content -> Task Gateway Service ->
Scenario Definition

2. Search for your entry if it is not there enter the following information

Field

value

Comments

Scenario Identifier

Z##_ABSENCE

Technical ID

Scenario Display
Name

Z## Absence Form

Task group in SAP Fiori


Approve Requests

Scenario order

blank

blank

Technical Service
Name

/IWPGW/TASKPROCESSING

Technical Name for generic


Inbox service. Select by F4
help.

Version

Version of Technical service


name.

Entity Set External


Name

Task

Property External
Name

TaskDefinitionID

Default Sort by
Property

CreatedOn

Mass Action

blank

Jun 2014

Sort property

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

Class for Scenario


Count

blank

In the Class for Scenario Count


field, enter the name of the class
that implements the
/IWWRK/IF_TGW_SCENARIO
interface in the SAP system.

Quick Action

Quick Approval by left slide on


mobile device.

Select your Scenario by choosing the block next to the name

2.2

Assign consumer type

With your scenario highlighted choose Assign consumer Type to Scenario by double clicking it and
notice the 3 available types

2.3

Assign role

If you want to enable the scenarios and consumer type to specific user groups, you can assign roles.
The users who have assigned role get task box in the SAP Fiori Approve Requests. If there is no role
assigned, all users will get the task box. This is an optional setting.

2.4

Assign task

You can assign multiple tasks to the Scenario. Choose Task Definition for Scenario by double
clicking it.

Jun 2014

10

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

NOTE: In all of these steps we just looked and didnt make any changes. The point is to show you
the different task assignments and how to assign them

Jun 2014

11

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

3.

Step 3. Add a tile to the Launchpad [Gateway]

3.1

Start the launchpad designer (system admin action).


Launch Google Chrome and choose quick Link LPD Designer CUST

If you receive a security warning choose proceed anyway and if prompted enter your login
credentials and choose Log In

Select the SAP FND Transactional Applications (SAP_FND_TC_T_X1) catalog

Jun 2014

12

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

3.2

Check the Target Mapping tile


Click on the target mapping tile and make sure the data matches the list below

Semantic Object: WorkflowTask.


Action: approveRequests
Launchpad Role: UIX01CA1
Launchpad Instance: TRANSACTIONAL
Application Alias: ApproveRequests

Once confirmed choose the back arrow

Add a new App Launcher Dynamic tile

3.3

Choose the blank tile

Jun 2014

13

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

Choose App Launcher Dynamic

Choose this new tile and enter the information below:

Title: Enter the name of your workflow scenario, for example, Approve Absence Requests.
Icon: Choose whatever you like
Service URL:
o Go to Start -> Documents -> SAPX03_95
o

Open the file named Unit 4_Lesson10_Workflow_01.txt and locate the URL

Copy the URL

/sap/opu/odata/IWPGW/TASKPROCESSING;mo/ScenarioCollection?$filter=key%20eq%
20'ZXX_ABSENCE
NOTE: Change Z00 to match your number ZXX
Paste the URL into the Link to Application space as shown below

Semantic Object: Enter WorkflowTask.


Action: Enter approveRequests.
Parameters: Enter scenarioId=<your scenario identifier> (Example:
scenarioId=Z00_ABSENCE)
Choose Save

Jun 2014

14

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

On the Confirmation Popup choose OK

3.4

Add app to Launchpad (End user action).


Make sure your user has the role SAP_FND_TCR_T_X1.
Open a new Google Chrome tab and choose the Launchpad quick link

Jun 2014

15

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

Click on Open Catalog. Select the Approve Absence Requests app by clicking on the + sign.

Choose the back arrow to return to the application. The application will show.

Jun 2014

16

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

Jun 2014

17

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

4.

Step 4. Configure the task decision [ERP]

4.1

Define workflow template and the step

To expose the possible decision options of an Activity task type assigned to a BOR method with a
Dialog we need to configure the decisions options.
1. Go to IMG and enter Transaction: SPRO (enter /NSPRO if youre not on the homepage of the
GUI)
Choose SAP Reference IMG
Content Navigate to SAP NetWeaver -> Gateway Service Enablement -> Content -> Workflow
Settings and choose the execute button next to Maintain Task Names and Decision Options

2. In the list of workflows look for your Workflow ID. If it is not listed choose New Entries and enter
the information as described in the table below. If it is listed choose it by selecting the gray box
next to the Workflow ID.

Field

value

comments

Workflow ID

WS30000015

Workflow template ID

Step ID

48

Step ID

Icon MIME Repository

blank

Step Description

Approve absence

4.2

Task name in UI

Assign the step keys

The key order should be exactly the same as task definition outcomes. Choose Decision Keys by
double clicking it.

Jun 2014

18

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

Note: If the step type is User Decision type, you can skip this step 2. The first option is assigned to
POSITIVE and the second option is assigned to NEGATIVE. We are just looking at the entries and
there is nothing further to accomplish in this step.

Jun 2014

19

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

5.

Step 5. Implement BADI for decision outcomes [ERP]

5.1

Create BAdI Configuration and Class for Decision Handling

To handle a decision that is made on the task we need to configure and implement a BAdI that will
contain the logic for doing this. The BAdI class will need to contain the same logic for completing the
task that is done in the assigned BOR object dialog method. These dialog methods are all slightly
different so you need to take it on a case by case basis when implementing the decision BAdI. So
understanding how the step works in the workflow and how the dialog method is implemented is key in
this process.
1. Enter transaction /NSE18 and choose enter from your keyboard
2. The Enhancement Spot for getting Business Context data is
/IWWRK/ES_WF_WI_BEFORE_UPD_IB. Enter that into the Enhancement Spot input field then
choose the Display button

3. You should now see the following:

4. Drill into the BAdI Definition by choosing the dropdown arrow so you see the following:

5. Right click on the Implementations node and select Create BAdI Implementation in the context
menu:

Jun 2014

20

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

6. In the popup window click the create icon in the bottom right hand corner:

7. In the Create Enhancement Implementation enter the details as shown below then choose the
green check mark.

8. If you receive the Create Object Directory Entry enter $TMP in the package then choose the
Save button

Jun 2014

21

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

9. You will be navigated back to the Select or Create Enhancement Implementation popup window.
Make sure your newly created Enhancement Implementation is selected as shown below and
choose the green check mark.

10. The Create BAdI Implementation popup window will now be displayed:
Enter in the details as shown below being sure to replace the XX with your assigned number
then choose the green check mark
BAdI Implementation:
Description:
Implementing Class

ZXX_BADI_ABSENCE_FORM
ZXX BADI Implementation Absence Form
ZXX_IC_ABSENCE_FORM

11. On the Create Object Directory Entry popup choose the save button

Jun 2014

22

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

12. You should now see the following:

13. Go into Change mode by click the Display/Change button.

Jun 2014

23

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

14. Drill into the BAdI implementation you just created by choosing the dropdown arrow and double
clicking the Filter Val.

15. Choose the change mode button again and on the right hand side you will see the filter details
view displayed then choose the Create Combination button

16. In the popup window select both WORKFLOW_ID and STEP_ID by holding down Shift and
choosing the gray box next to each and choose the green check box.

17. You should now see the following:

Jun 2014

24

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

18. Double click on the ???? in the Value 1 column for the STEP_ID row. You should see the
following popup window:

19. Enter 48 into the Value 1 input field (48 is the step ID for Approve absence notification), and set
Comparator 1 to =. The filter should now look like so. Choose the green check mark.

20. Now set the WORKFLOW_ID filter choose the ???? Value 1 setting and enter WSXXXXXXXX
(where the Xs are replaced with your assigned number) and Comparator 1 to =. Then choose
the green check mark.
21. Your filters should now be set as shown below:

22. Activate your BAdI by clicking the Activate button.

Jun 2014

25

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

23. In the Inactive Objects for FIORI-XX user choose the green check box

24. Note: you might see a warning telling you that the method that holds the actual implementation
code has not been implementedthis will be done in the following section.
Congrats! You have created a BAdI that can be called to access that business context data of the
Absence approval notification step.

5.2

Implement BAdI Class for Decision Handling

The BAdI class implementation for decision handling is going to be dependent on the workflow, the
task, and the BOR Object Dialog method that the task is bound to. You will need to examine all of
those elements to determine the necessary implementation. In any case you will be making use of the
SAP_WAPI* Business Workflow functions.
1. In your Enhancement Implementation switch to the Enh. Implementation Elements tab and
double click Implementing Class node.

Jun 2014

26

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

2. You will be displayed the following on the right hand side of the screen. Double click the method.

3. In the Create Method Implementation popup choose Yes.

4. Switch to change mode and add the follow code between the method and endmethod lines.

Go to Start -> Documents -> SAPX03_95

Open the file named Unit 4_Lesson09_Workflow_01.txt and locate the code

Copy the code (displayed below)

Paste in between Method and end method lines

Please read the code and understand it!:

DATA ls_object TYPE swr_obj_2.


DATA lv_objtype TYPE swr_struct-object_typ.
DATA lv_objkey TYPE SWR_STRUCT-OBJECT_KEY.
DATA lv_retcode TYPE sy-subrc.
DATA lt_container TYPE TABLE OF swr_cont.
DATA ls_container_line TYPE swr_cont.
DATA FORMNUMBER TYPE SWXFORMABS-FORMNUMBER.
DATA ls_formabs TYPE swxformabs.
"Access the workflow data
CALL FUNCTION 'SAP_WAPI_GET_OBJECTS'
EXPORTING
workitem_id

= is_wi_details-wi_id

IMPORTING

Jun 2014

27

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

leading_object_2 = ls_object.
"Get the formnumber which is the key to the absence table
MOVE ls_object-instid TO formnumber.
"Select the details of the absence from the table SWXFORMABS
select single * from swxformabs
into ls_formabs
where formnumber = formnumber.
"Read the workflow's container data
CALL FUNCTION 'SAP_WAPI_READ_CONTAINER'
EXPORTING
workitem_id

= is_wi_details-wi_id

IMPORTING
return_code

= lv_retcode

TABLES
simple_container

= lt_container.

" Check which decision was selected and set the data
" values appropriately
CASE iv_decision_key.
WHEN 0001. "Approved
ls_container_line-value = 'A'.
ls_formabs-procstate = 'A'.
WHEN 0002. "Rejected
ls_container_line-value = 'R'.
ls_formabs-procstate = 'R'.
ENDCASE.
"_WI_RESULT is what the workflow keys off to determine
"which path to follow - Approve or Reject path
ls_container_line-element = '_WI_RESULT'.
"Modify the workflow's container data - we are updating the row that
"holds _WI_RESULT which will be in the second row of the table
MODIFY lt_container INDEX 2 FROM ls_container_line TRANSPORTING value.
"Write the updated container back to the workflow engine
CALL FUNCTION 'SAP_WAPI_WRITE_CONTAINER'
EXPORTING
WORKITEM_ID
DO_COMMIT

= is_wi_details-wi_id
= 'X'

IMPORTING
RETURN_CODE

= lv_retcode

TABLES
SIMPLE_CONTAINER

= lt_container.

IF lv_retcode NE 0.
"Handle error
ENDIF.

Jun 2014

28

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

"Update the Absence table with the updated data


ls_formabs-approvdate = sy-datum.
ls_formabs-approvby = sy-uname.
update swxformabs from ls_formabs.
"Complete the task
CALL FUNCTION 'SAP_WAPI_WORKITEM_COMPLETE'
EXPORTING
WORKITEM_ID

= is_wi_details-wi_id.

"This task requires a confirm to be fully completed


"and start the next step in the workflow
CALL FUNCTION 'SAP_WAPI_WORKITEM_CONFIRM'
EXPORTING
WORKITEM_ID

= is_wi_details-wi_id.

5. Save and Activate your changes.

6. On the Inactive Objects for Fiori-XX popup choose the green check mark

Jun 2014

29

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

6.

Step 6. Display application data [Gateway]

6.1

Including business data by BADI (Optional but


Recommended)[Gateway]

You can enhance the workitem description by implementing BADI. HTML format is supported in
workitem description area.

The Enhancement spot name is /IWPGW/ES_TGW_TASK_DATA.


Please refer the section 5 for details steps of BADI implementation.

Please make sure you maintain the filter.


PROVIDER_ID = BWF
TASK_DEF_ID = your task ID. TS########

Method is MODIFY_TASK_DESCRIPTION.
o Go to Start -> Documents -> SAPX03_95
o Open the file named Unit 4_Lesson09_Workflow_02.txt and locate the code
o Copy the parameters (one at a time)
o Paste the code
Jun 2014

30

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

. Please read the code and understand it!:


The value should be escaped to avoid cross side script attacks.
Please look at help document.
http://help.sap.com/saphelp_nw70ehp2/helpdata/en/a6/87890ae991441b89bf418d0198ddcc/content.h
tm

val_escaped = escape( val = val format = cl_abap_format=>e_xss_ml ).

method /IWPGW/IF_TGW_TASK_DATA~MODIFY_TASK_DESCRIPTION.
*constants
constants: lc_element type swr_cont-element value '_WI_OBJECT_ID',
lc_backend type string value 'IDECLNT800'.
*itabs
data: num(12) type n value '000000000000',
str type string,
lv_returncode type sy-subrc,
lt_simple_container type standard table of swr_cont with nonunique key element,
lt_subcontainer_bor_objects type standard table of swr_cont,
lt_subcontainer_all_objects type standard table of swr_cont wi
th non-unique key element,
lv_formnumber type SWXFORMABS-FORMNUMBER,
ls_formdata type SWXFORMABS,
wa_subcontainer_all_objects type swr_cont,
val_escaped type string.
str = is_task_header-inst_id.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = str
IMPORTING
output = num.

*
*

*
*

*
*

CALL FUNCTION 'SAP_WAPI_READ_CONTAINER' destination lc_backend


EXPORTING
WORKITEM_ID
= num
LANGUAGE
= SY-LANGU
USER
= SY-UNAME
BUFFERED_ACCESS
= 'X'
IMPORTING
RETURN_CODE
= lv_returncode
IFS_XML_CONTAINER
=
IFS_XML_CONTAINER_SCHEMA =
TABLES
SIMPLE_CONTAINER
= lt_simple_container
MESSAGE_LINES
= lt_message_lines
MESSAGE_STRUCT
= lt_message_struct

Jun 2014

31

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

SUBCONTAINER_BOR_OBJECTS = lt_subcontainer_bor_objects
SUBCONTAINER_ALL_OBJECTS = lt_subcontainer_all_objects.
if lv_returncode = 0.

*retrieve only the ojbect key line


read table lt_subcontainer_all_objects with table key element = lc
_element
into wa_subcontainer_all_objects.
if sy-subrc = 0.
lv_formnumber = wa_subcontainer_all_objects-value.
CALL FUNCTION 'SWX_FORMABS_READ' destination lc_backend
EXPORTING
FORMNUMBER = lv_formnumber
IMPORTING
FORMDATA
= ls_formdata
RETURNCODE = lv_returncode.
if lv_returncode = 0.
CONCATENATE CV_DESCRIPTION '<div><p>You can display business d
ata in HTML view by BADI.</p>' into CV_DESCRIPTION.
CONCATENATE CV_DESCRIPTION '<table border = "1">' into CV_DESC
RIPTION.
val_escaped = escape( val = ls_formdataformnumber format = cl_abap_format=>e_xss_ml ).
CONCATENATE CV_DESCRIPTION '<tr><td>Form Number</td><td>' val_
escaped '</td></tr>' into CV_DESCRIPTION.
val_escaped = escape( val = ls_formdatacreatedate format = cl_abap_format=>e_xss_ml ).
CONCATENATE CV_DESCRIPTION '<tr><td>Created</td><td>' val_esca
ped '</td></tr>' into CV_DESCRIPTION.
val_escaped = escape( val = ls_formdataname format = cl_abap_format=>e_xss_ml ).
CONCATENATE CV_DESCRIPTION '<tr><td>Name</td><td>' val_escaped
'</td></tr>' into CV_DESCRIPTION.
val_escaped = escape( val = ls_formdatadepartment format = cl_abap_format=>e_xss_ml ).
CONCATENATE CV_DESCRIPTION '<tr><td>Department</td><td>' val_e
scaped '</td></tr>' into CV_DESCRIPTION.
val_escaped = escape( val = ls_formdatapernr format = cl_abap_format=>e_xss_ml ).
CONCATENATE CV_DESCRIPTION '<tr><td>Personel No.</td><td>' val
_escaped '</td></tr>' into CV_DESCRIPTION.
val_escaped = escape( val = ls_formdatacostcenter format = cl_abap_format=>e_xss_ml ).
CONCATENATE CV_DESCRIPTION '<tr><td>Cost center</td><td>' val_
escaped '</td></tr>' into CV_DESCRIPTION.
val_escaped = escape( val = ls_formdatafirstday1 format = cl_abap_format=>e_xss_ml ).
CONCATENATE CV_DESCRIPTION '<tr><td>From</td><td>' val_escaped

Jun 2014

32

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

'</td></tr>' into CV_DESCRIPTION.


val_escaped = escape( val = ls_formdatalastday1 format = cl_abap_format=>e_xss_ml ).
CONCATENATE CV_DESCRIPTION '<tr><td>To</td><td>' val_escaped '
</td></tr>' into CV_DESCRIPTION.
val_escaped = escape( val = ls_formdataholidaytp1 format = cl_abap_format=>e_xss_ml ).
CONCATENATE CV_DESCRIPTION '<tr><td>Leave Type</td><td>' val_e
scaped '</td></tr>' into CV_DESCRIPTION.
val_escaped = escape( val = ls_formdatareason format = cl_abap_format=>e_xss_ml ).
CONCATENATE CV_DESCRIPTION '<tr><td>Reason</td><td>' val_escap
ed '</td></tr>' into CV_DESCRIPTION.
val_escaped = escape( val = ls_formdatacontact format = cl_abap_format=>e_xss_ml ).
CONCATENATE CV_DESCRIPTION '<tr><td>Contact at</td><td>' val_e
scaped '</td></tr>' into CV_DESCRIPTION.
CONCATENATE CV_DESCRIPTION '</table>' into CV_DESCRIPTION.
endif.
endif.
endif.
endmethod.

Jun 2014

33

Adding a custom workflow scenario to the SAP Fiori Approve Requests in 6 steps

7.

Test the scenario

7.1

Approve from SAP Fiori Approve Requests

1. Launch the Fiori Launchpad by going to Google Chrome and choosing the Launchpad quick link.
If prompted enter your logon credentials.

2. Select the Approve Absence Requests form tile we created in an earlier step

3. Select the approve icon.

4. Make a comment and choose Submit


5. You should receive a successful message and the workflow item is removed from the list.

Jun 2014

34

www.sap.com/contactsap
www.sdn.sap.com/irj/sdn/howtoguides