sybase® mobile workflow for sap® business suite 1.2 [2012]

56
WHITE PAPER www.sybase.com Sybase ® Mobile Workflow for SAP ® Business Suite 1.2 Overview and Customization

Upload: bangalore-techie

Post on 13-Feb-2017

226 views

Category:

Technology


6 download

TRANSCRIPT

Page 1: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

white paper

www.sybase.com

Sybase® Mobile Workflow for SAP® Business Suite 1.2 Overview and Customization

Page 2: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

table of Contents

1 Introduction

1 End-to-End Architecture

1 Process Flow for Receiving a New Work Item 1 Process Flow for Completing a New Work Item

2 SAP Business Suite Customization

2 Custom Repository Objects

3 Task 1. Create a Package

4 Task 2. Create Six Domains

7 Task 3. Create Data Elements

9 Task 4. Create a Structure

10 Task 5. Create a Class

12 Task 6. Create a Function Group

13 Task 7. Create an Include

14 Task 8. Create Function Modules

20 Task 9. Create SET/GET Parameter ID

21 Task 10. Activate the Objects

21 SAP Mobile User Setting

22 SAP Mobile Destination Setting

23 Workflow Template Customization

25 End-to-End Communication Troubleshooting

25 Appendix A: ABAP Source Code

25 ZCL_SUP_MWF .EVENT_RAISED Method

31 ZSUP_MWF_UTILS Include

35 ZSUP_MWF_ACTIVATE Function

37 ZSUP_MWF_GEN_NOTIF_JSON Function

38 ZSUP_MWF_HTTP_POST Function

40 ZSUP_MWF_PUSH_WORKITEM Function

45 ZSUP_MWF_COMPLETE Function

48 ZSUP_MWF_GETDETAIL Function

51 Appendix B: Sybase Unwired Platform Projects Overview

51 Import Sybase Mobile Workflow Development Project

53 Mobile Application Diagram Overview

54 Workflow Template Overview

Page 3: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

1

introduCtionSybase Mobile Workflow for SAP Business Suite 1.2 (Sybase Mobile Workflow) utilizes Sybase Unwired Platform

(Unwired Platform) technology, allowing SAP Workflow decision steps to be performed on any user mobile device. When a decision-step message is received in the SAP Workflow Inbox (SAP Inbox), a message is sent to the mobile device. The user can complete the decision step in the mobile device inbox (Mobile Inbox) or in the SAP Inbox.

See the Unwired Platform documentation set and the Sybase Mobile Workflow Installation Guide for information about installing and configuring Sybase Unwired Platform components.

End-to-End ArchitectureThe solution’s main components, as illustrated below, are:

• Your custom function modules (RFCs) in the SAP back end• The mobile business object (MBO) package that is deployed into the Unwired Platform runtime, which integrates

with the SAP function modules• The Workflow package, which is hosted in the Unwired Platform for all your mobile device clients.

Process Flow for Receiving a New Work Item 1. In the back-end system, a program exit component inside the SAP workflow system pushes out new work

items to Mobile Workflow users. The message push is performed through the WF-DCN channel in the Unwired Platform server.

2. When the Unwired Platform server receives the new work item ID, it triggers the Unwired Platform Workflow package and uses the ZSUP_MWF_WI_GETDETAIL function module (see ZSUP_MWF_GETDETAIL Function in Appendix A) to retrieve work item details.

3. The Unwired Platform server converts the work item to a Mobile Workflow message, based on the Unwired Platform definition.

4. The workflow message, pushed to the device by Unwired Platform server, appears in the Mobile Inbox.

Process Flow for Completing a Work Item 1. The device user opens the work item in the Mobile Inbox and selects a decision. The decision triggers an

asynchronous request to the Unwired Platform server. 2. The work item message in the Mobile Inbox is marked as processed and the mobile user cannot select a different

decision.3. Inside Unwired Platform, the WorkitemCompletion operation of the Workitem MBO is executed, and the mapped

back-end ZSUP_MWF_WI_COMPLETE function module (see ZSUP_MWF_WI COMPLETE Function) is called.4. The work item is completed and removed from the SAP Inbox. A delete message for the work item is pushed

from the back end to Unwired Platform via the WF-DCN channel. 5. When the delete message is received by the device, the message in the Mobile Inbox is removed.

SUP Workflow

Sybase Unwired PlatformSAP

Workflow& Inbox

SAP Business Suite

SUP Protocol JCO

HTTP(s)

MBO RFC

RFC

RFC

MBO

MBO

WF DCN qRFC

Page 4: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

2

sap business suite Customization

Custom Repository ObjectsThe following tables list the custom repository objects that must be created in your SAP system to allow Unwired

Platform to integrate with SAP.

Dictionary Objects

PACkAgE NAmE OBjECT TyPE OBjECT NAmE DESCRIPTION

ZSUP_MWF_PKG Structure ZSUP_MWF_PARAM Key/value pair structure

ZSUP_MWF_PKG Domain ZSUP_MWF_CHAR1 Single character

ZSUP_MWF_PKG Domain ZSUP_MWF_CHAR20 Character field, length 20

ZSUP_MWF_PKG Domain ZSUP_MWF_CHAR255CS Character field, length 255 (case-sensitive)

ZSUP_MWF_PKG Domain ZSUP_MWF_CHAR32 Character field, length 32

ZSUP_MWF_PKG Domain ZSUP_MWF_INT4 4-byte signed integer

ZSUP_MWF_PKG Domain ZSUP_MWF_STRINGCS Character string, length variable (case-sensitive)

ZSUP_MWF_PKG Data Element ZSUP_MWF_CHAR1 Single character

ZSUP_MWF_PKG Data Element ZSUP_MWF_CHAR20 Character field, length 20

ZSUP_MWF_PKG Data Element ZSUP_MWF_CHAR255CS Character field, length 255 (case-sensitive)

ZSUP_MWF_PKG Data Element ZSUP_MWF_CHAR32 Character field, length 32

ZSUP_MWF_PKG Data Element ZSUP_MWF_INT4 4-byte signed integer

ZSUP_MWF_PKG Data Element ZSUP_MWF_STRINGCS Character string, length variable (case-sensitive)

Class Library/Classes

PACkAgE NAmE OBjECT TyPE OBjECT NAmE DESCRIPTION

ZSUP_MWF_PKG Class ZCL_SUP_MWF SUP Mobile Workflow

Function groups/Function modules

PACkAgE NAmE OBjECT TyPE OBjECT NAmE DESCRIPTION

ZSUP_MWF_PKG Function Group ZSUP_MWF_INTERNAL SUP Mobile Workflow

ZSUP_MWF_PKG Function ZSUP_MWF_ACTIVATE Allows Unwired Platform user parameter creation

ZSUP_MWF_PKG Function ZSUP_MWF_GEN_NOTIF_JSON

Generates a Sybase Mobile Workflow notification in JSON

ZSUP_MWF_PKG Function ZSUP_MWF_HTTP_POST Performs actual notification by HTTP post to specified destination

ZSUP_MWF_PKG Function ZSUP_MWF_PUSH_WORKITEM

Collects all necessary information and executes push to HTTP destination

ZSUP_MWF_PKG Function ZSUP_MWF_WI_COMPLETE

Allows update of work item with user’s decision

ZSUP_MWF_PKG Function ZSUP_MWF_GETDETAIL Retrieves work item details for specified user

Page 5: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

3

Includes

PACkAgE NAmE OBjECT TyPE OBjECT NAmE DESCRIPTION

ZSUP_MWF_PKG Include ZSUP_MWF_UTILS Various utilities

SET/gET Parameters

PACkAgE NAmE OBjECT TyPE OBjECT NAmE DESCRIPTION

ZSUP_MWF_PKG SET/GET Parameter ZSUP_MWF_ENABLED Enabled for Unwired Platform Mobile Workflow

Task 1. Create a PackageCreate all function modules in a new package named ZSUP_MWF_PKG.

1. In the Object Navigator (Transaction SE80) – Repository Browser, select Package and enter the package name.

2. Click Enter.

3. Select Workbench request for the newly created package, then click the green check mark to confirm the request.

Page 6: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

4

Task 2. Create Six Domains Create the six domains shown below.

The steps to create a domain are detailed below, using ZSUP_MWF_CHAR1 as an example. Repeat the steps for each domain.

1. In SAP Object Navigator, right-click the ZSUP_mWF_Pkg package you just created and select Create > Dictionary Object > Domain.

Page 7: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

5

2. Right-click the Domains node and select Create.

3. Enter the name for the new domain, then click the green check mark. Shown below is the entry for the first domain, ZSUP_MWF_CHAR1.

4. In the Definition tab, enter information for the newly created domain.

Page 8: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

6

You need not modify any settings on the Value Range or Properties tabs.

For domain names that end with “CS,” you must select the Lower Case check box.

5. Save the domain definition. Next, create the Object Directory entry.

6. Select the local Workbench request and click the green check mark to proceed.

7. Repeat steps 1 – 6 to create all six domains.

Page 9: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

7

Task 3. Create Data ElementsCreate the data elements shown below.

The steps to create a data element are detailed below, using ZSUP_MWF_CHAR1 as an example. Repeat the steps for each data element.

1. Right-click the Dictionary Objects node and select Create > Data Element.

2. Enter the name for the new data element, then click the green check mark.

Page 10: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

8

3. Enter the appropriate information on the Data Type tab.

4. Enter the appropriate information on the Field Label tab.

5. Save the definition of the data element.6. Repeat steps 1 – 5 to create all six data elements.

Page 11: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

9

Task 4. Create a StructureCreate the ZSUP_MWF_PARAM structure.

1. Right-click the Dictionary Objects node and select Create > Structure.

2. Enter ZSUP_mWF_PARAm as the name for the new structure, then click the green check mark.

3. On the Components tab, enter the definitions for the structure fields shown below.

4. Save the definition of the structure.

Page 12: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

10

Task 5. Create a Class Create the ZCL_SUP_MWF class, which implements the IF_SWF_IFS_WORKITEM_EXT interface and the

EVENT_RAISED method.

This class is configured in the Program Exits tab. The EVENT_RAISED method is triggered when a user-decision task is triggered because a new work item is generated, an existing work item is selected, or an existing work item is completed. Inside this method, an asynchronous notification to the mobile user is generated, if necessary, according to the workflow event type and the user’s ZSUP_MWF_ENABLED status.

1. In SAP Object Navigator, right-click the ZSUP_mWF_Pkg node in the Object tree and select Create > Class Library > Class.

2. Enter ZCL_SUP_mWF as the name for the new class, then click the green check mark.

Page 13: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

11

3. Complete the Create Object Directory Entry dialog.

4. Click Save and select your Workbench request.

5. Add two attributes to this class, as shown below.

6. Add the IF_SWF_WORkITEm_EXIT interface to this class.

7. Add the EVENT_RAISED method of the added interface:

8. Save the definition of the structure.

Page 14: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

12

Refer to ZCL_SUP_MWF .EVENT_RAISED Method in Appendix A for the implementation source code of the EVENT_RAISED method.

Task 6. Create a Function Group1. In SAP Object Navigator, right-click the ZSUP_mWF_Pkg node in the Object tree and select

Create > Function group.

2. In the Function group field, enter ZSUP_mWF_INTERNAL as the name for the new group, then click the green check mark.

3. Create the Object Directory Entry and add the function group to your Workbench request.

Page 15: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

13

Task 7. Create an Include 1. In SAP Object Navigator, under the ZSUP_MWF_INTERNAL function group you just created, right-click the

Includes node and select Create.

2. In the Include field, enter ZSUP_mWF_UTILS, then click the green check mark.

3. Accept the warning by clicking the green check mark.

4. Create the Object Directory Entry, then add the function group to your Workbench request and confirm the information dialog.

5. Add the implementation source code. Refer to ZSUP_MWF_UTILS Include in Appendix A for the complete source code of the INCLUDE.

Page 16: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

14

Task 8. Create Function ModulesCreate the function modules listed below.

• ZSUP_MWF_ACTIVATE• ZSUP_MWF_GEN_NOTIF_JSON• ZSUP_MWF_HTTP_POST• ZSUP_MWF_PUSH_WORKITEM• ZSUP_MWF_WI_COMPLETE• ZSUP_MWF_GETDETAIL

Repeat these steps for each function, entering information specific to each function module.

1. In SAP Object Navigator, right-click the ZSUP_mWF_INTERNAL function group and select Create > Function module.

2. Enter the name for the new function module, then click the green check mark. The entry for ZSUP_MWF_ACTIVATE is shown below.

Page 17: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

15

3. Click the green check mark to accept the information dialog.

4. Enter the appropriate function-module-specific information.

Function module ZSUP_mWF_ACTIVATE• Overall description: This function activates an SAP user to receive mobile work item notifications.

• Attributes tab:

• Import tab:

• Export tab: No export parameter for this function.

• Tables tab:

Page 18: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

16

Function module ZSUP_mWF_gEN_NOTIF_jSON• Overall description: This function generates the notification message pushed to Unwired Platform.

• Attributes tab:

• Import tab, Export tab, Table tab:

• Export tab:

• Tables tab: Null

Page 19: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

17

Function module ZSUP_mWF_HTTP_POST• Overall description: This function handles the HTTP message transfer to the configured destination (SM59).

• Attributes tab:

• Import tab:

• Export tab: Null

• Tables tab: Null

Function module ZSUP_mWF_PUSH_WORkITEm• Overall description: This function implements the notification message content creation.

• Attributes tab:

Page 20: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

18

• Import tab:

• Export tab: Null

• Tables tab:

Function module ZSUP_mWF_WI_COmPLETE• Overall description: This function is triggered by the Unwired Platform MBO to complete the work item.

• Attributes tab:

Page 21: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

19

• Import tab:

• Export tab: Null

• Tables tab:

Function module ZSUP_mWF_WI_gETDETAIL• Overall description: This function is triggered by the Unwired Platform MBO to receive the detail work item based on the import parameter WI_ID.

• Attributes tab:

• Import tab:

Page 22: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

20

• Export tab:

• Tables tab:

Task 9. Create SET/GET Parameter ID1. In SAP Object Navigator, right-click the ZSUP_mWF_Pkg package and select

Create > Other (1) > SET/gET Parameter ID.

2. Enter ZSUP_mWF_ENABLED as the parameter name.

Page 23: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

21

3. Select Workbench request, then click the green check mark to confirm the Workbench request.

Task 10. Activate the ObjectsIn SAP Object Navigator, right-click each object you have created under the ZSUP_MWF_PKG package and select

Activate. The image below shows the first object, the ZSUP_mWF_PARAm structure.

SAP mobile User SettingIn the back-end system, an SAP user is enabled as a Sybase Mobile Workflow user by using the

ZSUP_MWF_ENABLED parameter in the Parameters tab of the SU01 transaction, as shown below.

This parameter is automatically set when a user completes the activation process from his or her mobile device for the assigned Sybase Mobile Workflow package.

Page 24: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

22

If a user no longer wants to receive e-mail messages from his or her mobile device, the administrator removes the “X” flag in the Parameter Value column to stop the back-end system from pushing any new work items to this user. At the same time, the administrator should also use Sybase Control Center to unassign the Sybase Mobile Workflow package from the users’ device.

SAP mobile Destination SettingUse transaction SM59 to set up the destination.

1. Create a destination to your Sybase Unwired Platform installation as “HTTP Connections to External Server” configured with the Unwired Platform server’s DCN port and host name.

Configure the connection to use the DCN servlet that supports HTTP BASIC authentication. If you test the connection, ignore the HTTP error code.

2. Specify the user name and password as defined by your Sybase Unwired Platform administrator:

Page 25: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

23

Workflow Template Customization1. In the SAP Workflow Builder (transaction SWDD), open the workflow definition for the workflow containing the

decision step to be mobilized.

Identify the user decision task to be pushed to your users’ Mobile Inbox.

2. Open the user decision step by double-clicking, or right-clicking and selecting Change, then click the Program Exits tab to add the class created for this purpose.

• Set up the ZCL_SUP_MWF class:

• On the next tab, Properties, configure the settings for the Mobile Workflow push:

Page 26: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

24

sup.mwf.destination The name of the destination to the Unwired Platform server (see SAP Mobile Destination Setting)

sup.mwf.qnameA name that is unique to the particular workflow. If the property is not declared, outgoing requests do not go

through a queue, and the notification might be lost if Unwired Platform is unavailable.

sup.mwf.qcountThe number of queues to which to distribute outgoing notifications. If the property is not declared, a single queue

is used to push notifications to Unwired Platform.

sup.mwf.matchAllows a specific Unwired Platform workflow package to be associated with a specific decision task by using the

workflow package matching rules in the Unwired Platform design or runtime configuration.

sup.mwf.securityThe name of the security configuration in Unwired Platform that is used to authenticate incoming device users

against Unwired Platform (for example, “admin”).

sup.mwf.senderContains the default sender address that appears in the Mobile Inbox for notifications originating from this

decision task.

sup.mwf.sender.l10nAllows you to specify alternative localized versions of the sender text as a comma-separated list (for example,

“en,es,fr”). Based on the agent’s default system language, a localized sender text is chosen during runtime.

sup.mwf.sender.enThe sender text for users with a default language set to English (EN). If more than one alternative is configured, you

can add more properties (for example, “sup.mwf.sender.es” and “sup.mwf.sender.fr”).

sup.mwf.prioritySpecifies whether the notification on the mobile device is marked as high priority (a red exclamation mark) or with

default priority.

sup.mwf.markreadSpecifies whether the notification is created on the mobile device as a read or unread notification.

Page 27: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

25

End-to-End Communication TroubleshootingYou can use Transaction SMQ1 to monitor a work item notification that is stuck in the system, which may be caused

by either a configuration error or a physical network problem.

To resolve such an error, manually restart the queue.

appendix a: abap sourCe Code

ZCL_SUP_mWF .EVENT_RAISED method

method IF_SWF_IFS_WORKITEM_EXIT~EVENT_RAISED.

DATA lv_trfcqnam TYPE trfcqnam VALUE IS INITIAL.

DATA lv_return_code TYPE SY-SUBRC VALUE IS INITIAL.

DATA ls_header TYPE swr_wihdr VALUE IS INITIAL.

DATA ls_statra TYPE sww_statra VALUE IS INITIAL.

DATA lt_recipients TYPE TABLE OF swragent.

DATA ls_recipient TYPE swragent.

DATA lv_skip_owner TYPE zsup_mwf_char1 VALUE ‘’.

DATA lv_action TYPE zsup_mwf_char1 VALUE ‘X’.

DATA lv_priority TYPE zsup_mwf_char1 VALUE ‘’.

DATA lv_markread TYPE zsup_mwf_char1 VALUE ‘’.

DATA lv_destination TYPE zsup_mwf_char20 VALUE ‘’.

DATA lv_qname TYPE zsup_mwf_char20 VALUE ‘’.

DATA lv_qcount TYPE zsup_mwf_int4 VALUE 0.

DATA lv_supmatch TYPE zsup_mwf_char20 VALUE ‘’.

DATA lv_body TYPE zsup_mwf_char255cs VALUE ‘’.

DATA lv_workitem TYPE zsup_mwf_char32 VALUE ‘’.

DATA lv_taskid TYPE zsup_mwf_char32 VALUE ‘’.

DATA lv_supsecurity TYPE zsup_mwf_char255cs VALUE ‘’.

Page 28: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

26

DATA lv_prop_key type string VALUE ‘’.

DATA lv_prop_value TYPE string VALUE ‘’.

DATA lv_prop_lang_option TYPE string VALUE ‘’.

DATA lt_lang_options TYPE TABLE OF string.

DATA lv_localized_sender TYPE zsup_mwf_param.

DATA lt_localized_senders TYPE TABLE OF zsup_mwf_param.

DATA ls_filtered_recipient TYPE zsup_mwf_param.

DATA lt_filtered_recipients TYPE TABLE OF zsup_mwf_param.

“* read work item header from context

ls_header = im_workitem_context->get_header( ).

“* return without doing anything

“* either unable to read work item from context or

“* work item type is not a “Dialog Work Item; Represents a Single-Step Task”

IF ls_header IS INITIAL OR

ls_header-wi_type <> ‘W’.

RETURN.

ENDIF.

“* determine the action that need to be taken,

“* push a delete or upsert notification

IF ( im_event_name = ‘CREATED’ ).

“* if the work item got just now created

“* push a upsert notification

lv_action = zcl_sup_mwf=>push_action_upsert.

ELSEIF ( im_event_name = ‘STATE_CHG’ ).

ls_statra = im_workitem_context->get_state_transition( ).

“* push delete notification to all recipients

“* only in case this is a state transition and

“* the target state is either COMPLETED

“* or CANCELLED, if the target state is SELECTED

“* skip the actual user that accepted the item

IF ls_statra IS INITIAL.

RETURN.

ENDIF.

CASE ls_statra-tar_stat.

WHEN ‘COMPLETED’ OR

‘CANCELLED’.

lv_action = zcl_sup_mwf=>push_action_delete.

lv_skip_owner = ‘’.

Page 29: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

27

WHEN ‘SELECTED’.

lv_action = zcl_sup_mwf=>push_action_delete.

lv_skip_owner = ‘X’.

WHEN OTHERS.

RETURN.

ENDCASE.

ELSE.

“* all other events are ignored

RETURN.

ENDIF.

“* determine all recipients of this workitem,

“* while for newly created items this step could

“* be performed outside of the actual event

“* context, for deletes we have to determine

“* the recipients in the context of the event

“* as they are “removed” from the workitem

“* after the workitem event is completed

CALL FUNCTION ‘SAP_WAPI_WORKITEM_RECIPIENTS’

EXPORTING

workitem_id = ls_header-wi_id

IMPORTING

return_code = lv_return_code

TABLES

recipients = lt_recipients.

“* if the workitem has no actual recipients,

“* ignore the event and return immediately

IF lv_return_code <> 0.

RETURN.

ENDIF.

“* we are only interested in the list of usernames

“* from the actual recipient list, loops over the full

“* list of recipients and creates a new list with a subset

“* of entries

LOOP AT lt_recipients INTO ls_recipient.

IF ls_recipient-otype = ‘US’.

IF lv_skip_owner = ‘X’ AND

ls_recipient-objid = ls_header-wi_aagent.

CONTINUE.

ENDIF.

ls_filtered_recipient-pkey = ‘US’.

MOVE ls_recipient-objid TO ls_filtered_recipient-pvalue.

APPEND ls_filtered_recipient TO lt_filtered_recipients.

ENDIF.

ENDLOOP.

Page 30: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

28

TRY.

“* read property from work item to determine the configured

“* destination (SM59) used to push workitem notification to

lv_prop_value = im_workitem_context->get_property( ‘sup.mwf.destination’ ).

IF lv_prop_value <> ‘’.

MOVE lv_prop_value TO lv_destination.

ENDIF.

CATCH CX_WAPI_DEF_PROPERTY_NOT_FOUND.

lv_destination = ‘’.

ENDTRY.

TRY.

“* read property from work item to determine the configured

“* queue used to execute the actual push of the workitem notification,

“* if no qname is configured the actual push is going through tRFC (SM58)

“* instead of qRFC (SMQ1)

lv_prop_value = im_workitem_context->get_property( ‘sup.mwf.qname’ ).

IF lv_prop_value <> ‘’.

MOVE lv_prop_value TO lv_qname.

ENDIF.

CATCH CX_WAPI_DEF_PROPERTY_NOT_FOUND.

lv_qname = ‘’.

ENDTRY.

TRY.

“* read property from work item to determine the configured

“* number of queues to be used for the actual push of the

“* workitem notification

lv_prop_value = im_workitem_context->get_property( ‘sup.mwf.qcount’ ).

IF lv_prop_value <> ‘’.

MOVE lv_prop_value TO lv_qcount.

ENDIF.

CATCH CX_WAPI_DEF_PROPERTY_NOT_FOUND.

lv_qcount = 0.

ENDTRY.

TRY.

“* read property from work item to determine the configured

“* SUP security profile for the actual push of the workitem

“* notification

lv_prop_value = im_workitem_context->get_property( ‘sup.mwf.security’ ).

IF lv_prop_value <> ‘’.

MOVE lv_prop_value TO lv_supsecurity.

ENDIF.

CATCH CX_WAPI_DEF_PROPERTY_NOT_FOUND.

lv_supsecurity = ‘’.

ENDTRY.

“* copy workitem id and task id into

“* function module arguments

Page 31: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

29

MOVE ls_header-wi_id TO lv_workitem.

MOVE ls_header-wi_rh_task TO lv_taskid.

“* if the current event is not a delete notification, read more

“* properties that configure the content of the actual upsert

“* push notification

IF NOT lv_action = zcl_sup_mwf=>push_action_delete.

TRY.

“* read property that contains the workitem notification

“* body hint to allow SUP to match against

lv_prop_value = im_workitem_context->get_property( ‘sup.mwf.match’ ).

IF lv_prop_value <> ‘’.

MOVE lv_prop_value TO lv_supmatch.

ELSE.

lv_supmatch = ‘’.

ENDIF.

CATCH CX_WAPI_DEF_PROPERTY_NOT_FOUND.

lv_supmatch = ‘’.

ENDTRY.

“* complete the fixed workitem notification body

“* used for matching and paramater value extract

“* in the SUP notification processing

CONCATENATE ‘MATCH:’ lv_supmatch ‘, TASKID:’ lv_taskid ‘, WIID:’ lv_workitem

INTO lv_body.

TRANSLATE lv_body TO UPPER CASE.

TRY.

“* read property that determines if the workitem notification

“* should be displayed with high priority in the users

“* mobile inbox (default: normal priority)

lv_prop_value = im_workitem_context->get_property( ‘sup.mwf.priority’ ).

IF lv_prop_value = ‘X’.

lv_priority = ‘X’.

ELSE.

lv_priority = ‘’.

ENDIF.

CATCH CX_WAPI_DEF_PROPERTY_NOT_FOUND.

lv_priority = ‘’.

ENDTRY.

TRY.

“* read property that determines if the workitem notification

“* should be displayed with status read (default: unread) in

“* the users mobile inbox

lv_prop_value = im_workitem_context->get_property( ‘sup.mwf.markread’ ).

IF lv_prop_value = ‘X’.

lv_markread = ‘X’.

ELSE.

lv_markread = ‘’.

ENDIF.

Page 32: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

30

CATCH CX_WAPI_DEF_PROPERTY_NOT_FOUND.

lv_markread = ‘’.

ENDTRY.

TRY.

“* read property that determines the content of the from field

“* for the notification in the users mobile inbox

“* sup.mwf.sender is the default value for this field in case a

“* recipients language version (l10n options) is not configured

lv_prop_value = im_workitem_context->get_property( ‘sup.mwf.sender’ ).

IF NOT lv_prop_value = ‘’.

lv_localized_sender-pkey = ‘’.

lv_localized_sender-pvalue = lv_prop_value.

INSERT lv_localized_sender INTO TABLE lt_localized_senders.

“* read property that determines what l10n versions of the sender

“* field are available and have to be read

“* sup.mwf.sender.l10n contains a comma separated list of language

“* keys according to iso (table T002 field LAISO)

lv_prop_lang_option = im_workitem_context->get_property

( ‘sup.mwf.sender.l10n’ ).

IF NOT lv_prop_lang_option = ‘’.

TRANSLATE lv_prop_lang_option TO LOWER CASE.

SPLIT lv_prop_lang_option AT ‘,’ INTO TABLE lt_lang_options.

“* iterate over list of configured l10n version for sender field

“* and read one after another into lt_localized_senders table with

“* iso language key as UPPER CASE key for the parameter table

LOOP AT lt_lang_options INTO lv_prop_lang_option.

CONCATENATE ‘sup.mwf.sender.’ lv_prop_lang_option INTO lv_prop_key.

lv_prop_value = im_workitem_context->get_property( lv_prop_key ).

TRANSLATE lv_prop_lang_option TO UPPER CASE.

lv_localized_sender-pkey = lv_prop_lang_option.

lv_localized_sender-pvalue = lv_prop_value.

INSERT lv_localized_sender INTO TABLE lt_localized_senders.

ENDLOOP.

ENDIF.

ENDIF.

CATCH CX_WAPI_DEF_PROPERTY_NOT_FOUND.

ENDTRY.

ENDIF.

“* execute push function module in the background as tRFC

CALL FUNCTION ‘ZSUP_MWF_PUSH_WORKITEM’ IN BACKGROUND TASK AS SEPARATE UNIT

EXPORTING

destination = lv_destination

qname = lv_qname

qcount = lv_qcount

supsecurity = lv_supsecurity

action = lv_action

workitem = lv_workitem

Page 33: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

31

complete = ‘’

priority = lv_priority

markread = lv_markread

body = lv_body

TABLES

sendertexts = lt_localized_senders

recipients = lt_filtered_recipients.

“* tRFC/qRFC requires explicit commit

im_workitem_context->do_commit_work( ).

endmethod.

ZSUP_mWF_UTILS Include

FORM check_message_struct

TABLES message_struct TYPE STANDARD TABLE.

DATA ls_swr_mstruc TYPE swr_mstruc.

LOOP AT message_struct INTO ls_swr_mstruc.

IF ls_swr_mstruc-msgty = ‘E’ OR

ls_swr_mstruc-msgty = ‘A’.

MESSAGE ID ls_swr_mstruc-msgid TYPE ls_swr_mstruc-msgty NUMBER

ls_swr_mstruc-msgno.

ENDIF.

ENDLOOP.

ENDFORM.

FORM check_bapiret2

TABLES return TYPE STANDARD TABLE.

DATA ls_bapiret2 TYPE bapiret2.

LOOP AT return INTO ls_bapiret2.

IF ls_bapiret2-type = ‘E’ OR

ls_bapiret2-type = ‘A’.

MESSAGE ID ls_bapiret2-id TYPE ls_bapiret2-type NUMBER ls_bapiret2-number.

ENDIF.

ENDLOOP.

ENDFORM.

Page 34: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

32

FORM append_bapiret2

TABLES tbapiret2 TYPE STANDARD TABLE

CHANGING return TYPE STANDARD TABLE

lv_stop_processing TYPE ANY.

DATA ls_bapiret2 TYPE bapiret2.

DATA check TYPE char1.

LOOP AT tbapiret2 INTO ls_bapiret2.

IF ls_bapiret2-type = ‘E’ OR

ls_bapiret2-type = ‘A’.

APPEND ls_bapiret2 TO return.

lv_stop_processing = ‘X’.

ENDIF.

ENDLOOP.

ENDFORM.

FORM append_messages

TABLES message_lines TYPE STANDARD TABLE

message_struct TYPE STANDARD TABLE

CHANGING return TYPE STANDARD TABLE

lv_stop_processing TYPE ANY.

DATA ls_swr_mstruc TYPE swr_mstruc.

DATA ls_bapiret2 TYPE bapiret2.

DATA ls_swr_messag TYPE swr_messag.

LOOP AT message_lines INTO ls_swr_messag.

IF ls_swr_messag-msg_type = ‘E’ OR

ls_swr_messag-msg_type = ‘A’.

ls_bapiret2-type = ls_swr_messag-msg_type.

ls_bapiret2-id = ‘’.

ls_bapiret2-number = ‘’.

ls_bapiret2-message = ls_swr_messag-line.

APPEND ls_bapiret2 TO return.

lv_stop_processing = ‘X’.

ENDIF.

ENDLOOP.

LOOP AT message_struct INTO ls_swr_mstruc.

IF ls_swr_mstruc-msgty = ‘E’ OR

ls_swr_mstruc-msgty = ‘A’.

ls_bapiret2-type = ls_swr_mstruc-msgty.

ls_bapiret2-id = ls_swr_mstruc-msgid.

ls_bapiret2-number = ls_swr_mstruc-msgno.

ls_bapiret2-message = ‘’.

APPEND ls_bapiret2 TO return.

lv_stop_processing = ‘X’.

ENDIF.

ENDLOOP.

ENDFORM.

Page 35: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

33

FORM write_datetime_to_json

USING field_name TYPE any

field_date TYPE any

field_time TYPE any

CHANGING json_content.

DATA date_str TYPE string.

DATA time_str TYPE string.

IF json_content <> ‘’.

CONCATENATE json_content ‘,”’ field_name ‘”’ INTO json_content.

ELSE.

CONCATENATE json_content ‘”’ field_name ‘”’ INTO json_content.

ENDIF.

CONCATENATE field_date(4) field_date+4(2) field_date+6(2) INTO date_str SEPARATED

BY ‘-’.

CONCATENATE field_time(2) field_time+2(2) field_time+4(2) INTO time_str SEPARATED

BY ‘:’.

CONCATENATE json_content ‘:”’ date_str ‘T’ time_str ‘”’ INTO json_content.

ENDFORM.

FORM write_boolean_to_json

USING field_name TYPE any

field_value TYPE any

CHANGING json_content.

IF json_content <> ‘’.

CONCATENATE json_content ‘,”’ field_name ‘”’ INTO json_content.

ELSE.

CONCATENATE json_content ‘”’ field_name ‘”’ INTO json_content.

ENDIF.

CONCATENATE json_content ‘:’ field_value INTO json_content.

ENDFORM.

FORM write_string_to_json

USING field_name TYPE any

field_value TYPE any

CHANGING json_content.

DATA str TYPE string.

DATA strout TYPE string.

DATA strtemp TYPE string.

DATA c1 TYPE c LENGTH 1.

DATA c2 TYPE c LENGTH 4.

DATA int4 TYPE i.

str = field_value.

strout = str.

Page 36: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

34

IF json_content <> ‘’.

CONCATENATE json_content ‘,”’ field_name ‘”’ INTO json_content.

ELSE.

CONCATENATE json_content ‘”’ field_name ‘”’ INTO json_content.

ENDIF.

REPLACE ALL OCCURRENCES OF ‘\’ IN str WITH ‘\\’.

REPLACE ALL OCCURRENCES OF ‘”’ IN str WITH ‘\”’.

int4 = strlen( str ).

DO int4 TIMES.

c1 = str(1).

c2 = cl_abap_conv_out_ce=>uccp( c1 ).

IF NOT c2(2) = ‘00’.

CONCATENATE ‘\u’ c2 INTO strtemp.

REPLACE ALL OCCURRENCES OF c1 IN strout WITH strtemp.

ENDIF.

SHIFT str.

ENDDO.

CONCATENATE json_content ‘:”’ strout ‘”’ INTO json_content.

ENDFORM.

FORM hash_user_to_queue

USING username TYPE xubname

qcount TYPE zsup_mwf_int4

CHANGING

qname TYPE zsup_mwf_char20.

DATA lv_str TYPE string.

DATA lv_length TYPE i.

DATA lv_int4 TYPE i.

DATA lv_sum TYPE i.

DATA lv_hash TYPE i.

DATA lv_char1 TYPE c LENGTH 1.

FIELD-SYMBOLS <fs_x> TYPE x.

lv_str = username.

lv_length = strlen( lv_str ).

DO lv_length TIMES.

lv_char1 = lv_str(1).

ASSIGN lv_char1 TO <fs_x> CASTING.

MOVE <fs_x> TO lv_int4.

lv_sum = lv_sum + lv_int4.

SHIFT lv_str.

ENDDO.

Page 37: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

35

lv_hash = ( lv_sum MOD qcount + 1 ).

MOVE lv_hash TO lv_str.

CONCATENATE qname ‘.’ lv_str INTO qname.

TRANSLATE qname TO UPPER CASE.

ENDFORM.

ZSUP_mWF_ACTIVATE Function

FUNCTION ZSUP_MWF_ACTIVATE.

*”----------------------------------------------------------------------

*”*”Local Interface:

*” IMPORTING

*” VALUE(USERNAME) TYPE ZSUP_MWF_CHAR20

*” TABLES

*” RETURN STRUCTURE BAPIRET2

*”----------------------------------------------------------------------

DATA lv_xubname TYPE xubname.

DATA ls_userdefault TYPE bapidefaul VALUE IS INITIAL.

DATA lt_user_parameter TYPE TABLE OF bapiparam.

DATA ls_user_parameter TYPE bapiparam VALUE IS INITIAL.

DATA ls_bapiparamx TYPE bapiparamx VALUE IS INITIAL.

DATA lt_bapiret2 TYPE TABLE OF bapiret2.

DATA lv_stop_processing TYPE zsup_mwf_char1 VALUE IS INITIAL.

TRANSLATE username TO UPPER CASE.

MOVE username TO lv_xubname.

“* read user defaults to determine

“* if the user really exists

MOVE username TO lv_xubname.

CALL FUNCTION ‘BAPI_USER_GET_DETAIL’

EXPORTING

username = lv_xubname

IMPORTING

defaults = ls_userdefault

TABLES

parameter = lt_user_parameter

return = lt_bapiret2.

PERFORM append_bapiret2

TABLES lt_bapiret2

CHANGING return[]

lv_stop_processing.

IF lv_stop_processing = ‘X’.

RETURN.

ENDIF.

Page 38: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

36

“* set output language to user default,

“* if not set, set temporarily to default

IF NOT ls_userdefault-langu IS INITIAL.

SET LANGUAGE ls_userdefault-langu.

ELSE.

ls_userdefault-langu = sy-langu.

ENDIF.

“* read user parameter to determine

“* if the user already is enabled

lv_stop_processing = ‘’.

LOOP AT lt_user_parameter INTO ls_user_parameter.

IF ls_user_parameter-parid = ‘ZSUP_MWF_ENABLED’.

IF ls_user_parameter-parva = ‘X’.

RETURN.

ENDIF.

ENDIF.

ENDLOOP.

“* the user is not enabled add the

“* new parameter and call

“* BAPI_USER_CHANGE to add parameter.

ls_bapiparamx-parid = ‘X’.

ls_bapiparamx-parva = ‘X’.

DELETE lt_user_parameter WHERE parid = ‘ZSUP_MWF_ENABLED’.

ls_user_parameter-parid = ‘ZSUP_MWF_ENABLED’.

ls_user_parameter-parva = ‘X’.

APPEND ls_user_parameter TO lt_user_parameter.

CALL FUNCTION ‘BAPI_USER_CHANGE’

EXPORTING

username = lv_xubname

parameterx = ls_bapiparamx

TABLES

parameter = lt_user_parameter

return = lt_bapiret2.

PERFORM append_bapiret2

TABLES lt_bapiret2

CHANGING return[]

lv_stop_processing.

IF lv_stop_processing = ‘X’.

RETURN.

ENDIF.

ENDFUNCTION.

Page 39: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

37

ZSUP_mWF_gEN_NOTIF_jSON Function

FUNCTION ZSUP_MWF_GEN_NOTIF_JSON.

*”----------------------------------------------------------------------

*”*”Local Interface:

*” IMPORTING

*” VALUE(NOTIF_ID) TYPE ZSUP_MWF_CHAR32

*” VALUE(DELETE) TYPE ZSUP_MWF_CHAR1 OPTIONAL

*” VALUE(MARKREAD) TYPE ZSUP_MWF_CHAR1 OPTIONAL

*” VALUE(PRIORITY) TYPE ZSUP_MWF_CHAR1 OPTIONAL

*” VALUE(TO) TYPE ZSUP_MWF_CHAR20

*” VALUE(FROM) TYPE ZSUP_MWF_CHAR255CS OPTIONAL

*” VALUE(SUBJECT) TYPE ZSUP_MWF_CHAR255CS OPTIONAL

*” VALUE(BODY) TYPE ZSUP_MWF_CHAR255CS OPTIONAL

*” EXPORTING

*” VALUE(JSON_OUT) TYPE ZSUP_MWF_STRINGCS

*”----------------------------------------------------------------------

DATA p_json_out TYPE STRING.

DATA json_content TYPE STRING.

DATA time_stamp TYPE TIMESTAMPL.

DATA tz TYPE TZONREF-TZONE.

DATA dat TYPE DATE.

DATA tim TYPE TIME.

IF delete = ‘D’.

PERFORM write_string_to_json USING ‘op’ ‘:delete’ CHANGING json_content.

ELSE.

PERFORM write_string_to_json USING ‘op’ ‘:upsert’ CHANGING json_content.

ENDIF.

PERFORM write_string_to_json USING ‘id’ notif_id CHANGING json_content.

PERFORM write_string_to_json USING ‘to’ to CHANGING json_content.

PERFORM write_string_to_json USING ‘from’ from CHANGING json_content.

PERFORM write_string_to_json USING ‘subject’ subject CHANGING json_content.

PERFORM write_string_to_json USING ‘body’ body CHANGING json_content.

GET TIME STAMP FIELD time_stamp.

CONVERT TIME STAMP time_stamp TIME ZONE tz

INTO DATE dat TIME tim.

PERFORM write_datetime_to_json USING ‘received’ dat tim CHANGING json_content.

IF markread EQ ‘X’.

PERFORM write_boolean_to_json USING ‘read’ ‘true’ CHANGING json_content.

ELSE.

PERFORM write_boolean_to_json USING ‘read’ ‘false’ CHANGING json_content.

ENDIF.

Page 40: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

38

IF priority EQ ‘X’.

PERFORM write_boolean_to_json USING ‘priority’ ‘true’ CHANGING json_content.

ELSE.

PERFORM write_boolean_to_json USING ‘priority’ ‘false’ CHANGING json_content.

ENDIF.

CONCATENATE ‘{‘ json_content ‘,”data”:[]}’ INTO p_json_out.

json_out = p_json_out.

ENDFUNCTION.

ZSUP_mWF_HTTP_POST Function

FUNCTION ZSUP_MWF_HTTP_POST.

*”----------------------------------------------------------------------

*”*”Local Interface:

*” IMPORTING

*” REFERENCE(DESTINATION) TYPE ZSUP_MWF_CHAR20

*” REFERENCE(SUPSECURITY) TYPE ZSUP_MWF_CHAR255CS

*” REFERENCE(MSG_BODY) TYPE ZSUP_MWF_STRINGCS

*”----------------------------------------------------------------------

DATA lo_http_client TYPE REF TO if_http_client.

DATA lv_int4 type i VALUE 0.

DATA lv_string type string VALUE ‘’.

CALL METHOD cl_http_client=>create_by_destination

EXPORTING

destination = destination

IMPORTING

client = lo_http_client

EXCEPTIONS

destination_not_found = 1

internal_error = 2

argument_not_found = 3

destination_no_authority = 4

plugin_not_active = 5

OTHERS = 6.

CASE sy-subrc.

WHEN 0.

WHEN 1.

MESSAGE e000(sr) WITH ‘destination_not_found’.

WHEN 2.

MESSAGE e000(sr) WITH ‘internal_error’.

WHEN 3.

MESSAGE e000(sr) WITH ‘argument_not_found’.

WHEN 4.

MESSAGE e000(sr) WITH ‘destination_no_authority’.

WHEN 5.

Page 41: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

39

MESSAGE e000(sr) WITH ‘plugin_not_active’.

WHEN OTHERS.

MESSAGE e000(sr) WITH ‘unknown_error’.

ENDCASE.

CALL METHOD lo_http_client->request->set_header_field

EXPORTING

name = ‘~request_method’

value = ‘POST’.

CALL METHOD lo_http_client->request->set_form_field

EXPORTING

name = ‘cmd’

value = ‘wf’.

lv_string = SUPSECURITY.

CALL METHOD lo_http_client->request->set_form_field

EXPORTING

name = ‘security’

value = lv_string.

lv_string = ‘’.

CALL METHOD lo_http_client->request->set_header_field

EXPORTING

name = ‘Content-Type’

value = ‘text/json; charset=utf-8’.

lv_int4 = strlen( MSG_BODY ).

CALL METHOD lo_http_client->request->append_cdata2

EXPORTING

data = MSG_BODY

encoding = IF_HTTP_ENTITY=>CO_ENCODING_RAW

offset = 0

length = lv_int4.

lv_int4 = 0.

CALL METHOD lo_http_client->send

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2

OTHERS = 3.

CASE sy-subrc.

WHEN 0.

WHEN 1.

MESSAGE e000(sr) WITH ‘http_communication_failure’.

WHEN 2.

MESSAGE e000(sr) WITH ‘http_invalid_state’.

WHEN OTHERS.

MESSAGE e000(sr) WITH ‘unknown_error’.

ENDCASE.

Page 42: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

40

CALL METHOD lo_http_client->receive

EXCEPTIONS

http_communication_failure = 1

http_invalid_state = 2

http_processing_failed = 3.

CASE sy-subrc.

WHEN 0.

WHEN 1.

MESSAGE e000(sr) WITH ‘http_communication_failure’.

WHEN 2.

MESSAGE e000(sr) WITH ‘http_invalid_state’.

WHEN OTHERS.

MESSAGE e000(sr) WITH ‘unknown_error’.

ENDCASE.

CALL METHOD lo_http_client->response->GET_STATUS

IMPORTING

code = lv_int4

reason = lv_string.

IF lv_int4 <> 200.

MESSAGE e000(sr) WITH lv_string.

ENDIF.

ENDFUNCTION.

ZSUP_mWF_PUSH_WORkITEm Function

FUNCTION ZSUP_MWF_PUSH_WORKITEM.

*”----------------------------------------------------------------------

*”*”Local Interface:

*” IMPORTING

*” VALUE(DESTINATION) TYPE ZSUP_MWF_CHAR20

*” VALUE(QNAME) TYPE ZSUP_MWF_CHAR20

*” VALUE(QCOUNT) TYPE ZSUP_MWF_INT4

*” VALUE(SUPSECURITY) TYPE ZSUP_MWF_CHAR255CS

*” VALUE(ACTION) TYPE ZSUP_MWF_CHAR1

*” VALUE(WORKITEM) TYPE ZSUP_MWF_CHAR32

*” VALUE(COMPLETE) TYPE ZSUP_MWF_CHAR1 OPTIONAL

*” VALUE(PRIORITY) TYPE ZSUP_MWF_CHAR1 OPTIONAL

*” VALUE(MARKREAD) TYPE ZSUP_MWF_CHAR1 OPTIONAL

*” VALUE(SENDER) TYPE ZSUP_MWF_CHAR255CS OPTIONAL

*” VALUE(RECIPIENT) TYPE ZSUP_MWF_CHAR20 OPTIONAL

*” VALUE(SUBJECT) TYPE ZSUP_MWF_CHAR255CS OPTIONAL

*” VALUE(BODY) TYPE ZSUP_MWF_CHAR255CS OPTIONAL

*” TABLES

*” SENDERTEXTS STRUCTURE ZSUP_MWF_PARAM OPTIONAL

*” RECIPIENTS STRUCTURE ZSUP_MWF_PARAM OPTIONAL

*”----------------------------------------------------------------------

Page 43: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

41

“* if complete indicator is set, we directly generate

“* json and execute the push to the http endpoint

IF complete = ‘X’.

DATA lv_json_notif TYPE zsup_mwf_stringcs.

“* generate a workitem notification body

CALL FUNCTION ‘ZSUP_MWF_GEN_NOTIF_JSON’

EXPORTING

notif_id = workitem

delete = action

markread = markread

priority = priority

to = recipient

from = sender

subject = subject

body = body

IMPORTING

json_out = lv_json_notif.

“* execute http push function module using specified destination

CALL FUNCTION ‘ZSUP_MWF_HTTP_POST’

EXPORTING

destination = destination

supsecurity = supsecurity

msg_body = lv_json_notif.

RETURN.

ENDIF.

DATA lv_trfcqnam TYPE trfcqnam VALUE IS INITIAL.

DATA lv_xubname TYPE xubname VALUE IS INITIAL.

DATA ls_userdefault TYPE bapidefaul VALUE IS INITIAL.

DATA lv_lang_iso TYPE t002-laiso VALUE IS INITIAL.

DATA lv_wiid TYPE sww_wiid VALUE IS INITIAL.

DATA lv_wi_text TYPE witext VALUE IS INITIAL.

DATA lv_return_code TYPE sysubrc VALUE IS INITIAL.

DATA lv_subject TYPE zsup_mwf_char255cs VALUE IS INITIAL.

DATA lv_body TYPE zsup_mwf_char255cs VALUE IS INITIAL.

DATA lv_sender TYPE zsup_mwf_char255cs VALUE IS INITIAL.

DATA lv_sendertext TYPE zsup_mwf_param VALUE IS INITIAL.

DATA ls_recipient TYPE zsup_mwf_param VALUE IS INITIAL.

DATA lv_recipient TYPE zsup_mwf_char20 VALUE IS INITIAL.

DATA lt_message_struct TYPE TABLE OF swr_mstruc.

DATA lt_alternatives TYPE TABLE OF swr_decialts.

DATA lt_user_parameter TYPE TABLE OF bapiparam.

DATA ls_user_parameter TYPE bapiparam VALUE IS INITIAL.

DATA lt_bapiret2 TYPE TABLE OF bapiret2.

Page 44: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

42

“* loop over all entries in the recipient list

“* and determine the user language, translate

“* the workitem text into the users language

“* and call the function module again with the

“* complete indicator set to push individual

“* notifications to configured destination

LOOP AT recipients INTO ls_recipient.

IF ls_recipient-pkey = ‘US’.

“* read user defaults to determine user

“* default language and if user is mobile

“* enabled

MOVE ls_recipient-pvalue TO lv_xubname.

CALL FUNCTION ‘BAPI_USER_GET_DETAIL’

EXPORTING

username = lv_xubname

IMPORTING

defaults = ls_userdefault

TABLES

parameter = lt_user_parameter

return = lt_bapiret2.

“* set output language to user default,

“* if not set, set temporarily to default

IF NOT ls_userdefault-langu IS INITIAL.

SET LANGUAGE ls_userdefault-langu.

ELSE.

ls_userdefault-langu = sy-langu.

ENDIF.

“* check returned BAPIRET2 table for any error

“* or abort entries, stops execution in case

“* an error or abort entry is found

PERFORM check_bapiret2 TABLES lt_bapiret2.

“* initialize recipient name to username

MOVE lv_xubname TO lv_recipient.

“* check if user is mobile enabled (ZSUP_ENABLED)

“* and set the recipient name to the mobile username

lv_return_code = 1.

LOOP AT lt_user_parameter INTO ls_user_parameter.

IF ls_user_parameter-parid = ‘ZSUP_MWF_ENABLED’ AND

ls_user_parameter-parva = ‘X’.

lv_return_code = 0.

ENDIF.

ENDLOOP.

Page 45: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

43

“* if the user is not mobile enabled

“* continue with the next entry in the

“* recipient list

IF lv_return_code <> 0.

CONTINUE.

ENDIF.

“* if the notification push is a delete skip the

“* determination of further content for the push such

“* as localized subject and sender, etc.

IF NOT action = ‘D’.

“* translate user language code to iso

CALL FUNCTION ‘LANGUAGE_CODE_SAP_TO_ISO’

EXPORTING

sap_code = ls_userdefault-langu

IMPORTING

iso_code = lv_lang_iso

EXCEPTIONS

not_found = 1

OTHERS = 2.

“* output MESSAGE to stop execution in case of

“* an error during language code conversion

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno.

ENDIF.

“* read decision in users configured default language

MOVE workitem TO lv_wiid.

CALL FUNCTION ‘SAP_WAPI_DECISION_READ’

EXPORTING

workitem_id = lv_wiid

language = ls_userdefault-langu

user = lv_xubname

IMPORTING

return_code = lv_return_code

decision_title = lv_wi_text

TABLES

alternatives = lt_alternatives

message_struct = lt_message_struct.

“* check returned MESSAGE_STRUCT table for any error

“* or abort entries, stops execution in case

“* an error or abort entry is found

IF lv_return_code <> 0.

PERFORM check_message_struct TABLES lt_message_struct.

ENDIF.

Page 46: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

44

“* copy localized version of the decision title

“* into local subject valiable

MOVE lv_wi_text TO lv_subject.

“* loop over all available configured l10n versions

“* of the sender field and determine the match

“* for the particular users default language or

“* use the configured default sender text

LOOP AT sendertexts INTO lv_sendertext.

IF lv_sendertext-pkey CS lv_lang_iso.

lv_sender = lv_sendertext-pvalue.

EXIT.

ELSEIF lv_sendertext-pkey = ‘’.

lv_sender = lv_sendertext-pvalue.

ENDIF.

ENDLOOP.

“* complete the fixed workitem notification body

“* used for matching and paramater value extract

“* in the SUP notification processing

CONCATENATE body ‘, USER:’ lv_xubname ‘*#END#*’ INTO lv_body.

TRANSLATE lv_body TO UPPER CASE.

ENDIF.

“* if qname was not set skip

“* and execute as tRFC

IF qname <> ‘’.

“* if qcount was specified hash username

“* into one of the possible queues before

“* setting the queue name for qRFC

IF qcount > 0.

PERFORM hash_user_to_queue USING lv_xubname qcount CHANGING qname.

ENDIF.

MOVE qname TO lv_trfcqnam.

CALL FUNCTION ‘TRFC_SET_QUEUE_NAME’

EXPORTING

QNAME = lv_trfcqnam.

ENDIF.

“* execute push function module in the background

“* with complete flag set

CALL FUNCTION ‘ZSUP_MWF_PUSH_WORKITEM’ IN BACKGROUND TASK AS SEPARATE UNIT

EXPORTING

destination = destination

qname = qname

qcount = qcount

supsecurity = supsecurity

action = action

workitem = workitem

complete = ‘X’

Page 47: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

45

priority = priority

markread = markread

sender = lv_sender

recipient = lv_recipient

subject = lv_subject

body = lv_body.

ENDIF.

ENDLOOP.

“* tRFC/qRFC requires explicit commit

COMMIT WORK.

ENDFUNCTION.

ZSUP_mWF_WI COmPLETE Function

FUNCTION ZSUP_MWF_WI_COMPLETE.

*”----------------------------------------------------------------------

*”*”Local Interface:

*” IMPORTING

*” VALUE(USERNAME) TYPE ZSUP_MWF_CHAR20

*” VALUE(WORKITEM) TYPE ZSUP_MWF_CHAR20

*” VALUE(DECISION) TYPE ZSUP_MWF_CHAR20

*” VALUE(COMMENT) TYPE ZSUP_MWF_CHAR255CS OPTIONAL

*” TABLES

*” RETURN STRUCTURE BAPIRET2

*”----------------------------------------------------------------------

DATA lv_xubname TYPE xubname VALUE IS INITIAL.

DATA ls_userdefault TYPE bapidefaul VALUE IS INITIAL.

DATA lt_user_parameter TYPE TABLE OF bapiparam.

DATA lv_wiid TYPE sww_wiid VALUE IS INITIAL.

DATA ls_wihdr TYPE swr_wihdr VALUE IS INITIAL.

DATA lv_decikey TYPE swr_decikey VALUE IS INITIAL.

DATA ls_att_header TYPE swr_att_header VALUE IS INITIAL.

DATA lv_att_txt TYPE string VALUE IS INITIAL.

DATA lt_bapiret2 TYPE TABLE OF bapiret2.

DATA lv_return_code TYPE sysubrc VALUE IS INITIAL.

DATA lt_message_struct TYPE TABLE OF swr_mstruc.

DATA lt_message_line TYPE TABLE OF swr_messag.

DATA lv_stop_processing TYPE zsup_mwf_char1 VALUE IS INITIAL.

Page 48: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

46

“* read user defaults to determine the default

“* language and if the user exists

MOVE username TO lv_xubname.

CALL FUNCTION ‘BAPI_USER_GET_DETAIL’

EXPORTING

username = lv_xubname

IMPORTING

defaults = ls_userdefault

TABLES

parameter = lt_user_parameter

return = lt_bapiret2.

PERFORM append_bapiret2

TABLES lt_bapiret2

CHANGING return[]

lv_stop_processing.

IF lv_stop_processing = ‘X’.

RETURN.

ENDIF.

“* set output language to user default,

“* if not set, set temporarily to default

IF NOT ls_userdefault-langu IS INITIAL.

SET LANGUAGE ls_userdefault-langu.

ELSE.

ls_userdefault-langu = sy-langu.

ENDIF.

“* read workitem to verify state and

“* its existence

MOVE workitem TO lv_wiid.

CALL FUNCTION ‘SAP_WAPI_GET_HEADER’

EXPORTING

workitem_id = lv_wiid

language = ls_userdefault-langu

user = lv_xubname

IMPORTING

workitem_attributes = ls_wihdr

return_code = lv_return_code

TABLES

message_lines = lt_message_line

message_struct = lt_message_struct.

IF lv_return_code <> 0.

PERFORM append_messages

TABLES lt_message_line

lt_message_struct

CHANGING return[]

lv_stop_processing.

ENDIF.

Page 49: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

47

IF lv_stop_processing = ‘X’.

RETURN.

ENDIF.

“* if state is not ready, means the item

“* was processed already. Ignore decision.

IF ls_wihdr-wi_stat <> ‘READY’.

RETURN.

ENDIF.

“* execute supplied decision

MOVE decision TO lv_decikey.

CALL FUNCTION ‘SAP_WAPI_DECISION_COMPLETE’

EXPORTING

workitem_id = lv_wiid

language = ls_userdefault-langu

user = lv_xubname

decision_key = lv_decikey

do_commit = ‘ ‘

IMPORTING

return_code = lv_return_code

TABLES

message_lines = lt_message_line

message_struct = lt_message_struct.

IF lv_return_code <> 0.

PERFORM append_messages

TABLES lt_message_line

lt_message_struct

CHANGING return[]

lv_stop_processing.

ENDIF.

IF lv_stop_processing = ‘X’.

ROLLBACK WORK.

RETURN.

ENDIF.

“* attach uploaded comment as attachment

“* to work item if available

IF comment <> ‘’.

ls_att_header-file_name = text-001.

ls_att_header-file_type = ‘T’.

ls_att_header-file_extension = ‘TXT’.

ls_att_header-language = ls_userdefault-langu.

MOVE comment TO lv_att_txt.

Page 50: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

48

CALL FUNCTION ‘SAP_WAPI_ATTACHMENT_ADD’

EXPORTING

workitem_id = lv_wiid

att_header = ls_att_header

att_txt = lv_att_txt

language = ls_userdefault-langu

do_commit = ‘ ‘

IMPORTING

return_code = lv_return_code

TABLES

message_lines = lt_message_line

message_struct = lt_message_struct.

IF lv_return_code <> 0.

PERFORM append_messages

TABLES lt_message_line

lt_message_struct

CHANGING return[]

lv_stop_processing.

ENDIF.

IF lv_stop_processing = ‘X’.

ROLLBACK WORK.

RETURN.

ENDIF.

ENDIF.

COMMIT WORK.

ENDFUNCTION.

ZSUP_mWF_gETDETAIL Function

FUNCTION ZSUP_MWF_WI_GETDETAIL.

*”----------------------------------------------------------------------

*”*”Local Interface:

*” IMPORTING

*” VALUE(USERNAME) TYPE ZSUP_MWF_CHAR20

*” VALUE(WORKITEM) TYPE ZSUP_MWF_CHAR20

*” EXPORTING

*” VALUE(DECISION) TYPE ZSUP_MWF_CHAR255CS

*” VALUE(DESCRIPTION) TYPE ZSUP_MWF_STRINGCS

*” TABLES

*” RETURN STRUCTURE BAPIRET2

*” ALTERNATIVES STRUCTURE ZSUP_MWF_PARAM

*”----------------------------------------------------------------------

DATA lv_xubname TYPE xubname VALUE IS INITIAL.

DATA ls_userdefault TYPE bapidefaul VALUE IS INITIAL.

DATA lt_user_parameter TYPE TABLE OF bapiparam.

Page 51: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

49

DATA lt_bapiret2 TYPE TABLE OF bapiret2.

DATA lv_return_code TYPE sysubrc VALUE IS INITIAL.

DATA lv_wiid TYPE sww_wiid VALUE IS INITIAL.

DATA lv_wi_text TYPE witext VALUE IS INITIAL.

DATA lt_message_struct TYPE TABLE OF swr_mstruc.

DATA lt_message_line TYPE TABLE OF swr_messag.

DATA lt_alternatives TYPE TABLE OF swr_decialts.

DATA ls_alternative TYPE swr_decialts VALUE IS INITIAL.

DATA lt_text_lines TYPE TABLE OF swr_txtlin.

DATA lv_text_line TYPE swr_txtlin VALUE IS INITIAL.

DATA lv_stop_processing TYPE zsup_mwf_char1 VALUE IS INITIAL.

MOVE username TO lv_xubname.

CALL FUNCTION ‘BAPI_USER_GET_DETAIL’

EXPORTING

username = lv_xubname

IMPORTING

defaults = ls_userdefault

TABLES

parameter = lt_user_parameter

return = lt_bapiret2.

PERFORM append_bapiret2 TABLES lt_bapiret2 CHANGING return[] lv_stop_processing.

IF lv_stop_processing = ‘X’.

RETURN.

ENDIF.

“* set output language to user default,

“* if not set, set temporarily to default

IF NOT ls_userdefault-langu IS INITIAL.

SET LANGUAGE ls_userdefault-langu.

ELSE.

ls_userdefault-langu = sy-langu.

ENDIF.

“* read decision in users configured default language

MOVE workitem TO lv_wiid.

CALL FUNCTION ‘SAP_WAPI_DECISION_READ’

EXPORTING

workitem_id = lv_wiid

language = ls_userdefault-langu

user = lv_xubname

IMPORTING

return_code = lv_return_code

decision_title = lv_wi_text

TABLES

alternatives = lt_alternatives

message_lines = lt_message_line

message_struct = lt_message_struct.

Page 52: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

50

IF lv_return_code <> 0.

PERFORM append_messages

TABLES lt_message_line

lt_message_struct

CHANGING return[]

lv_stop_processing.

ENDIF.

IF lv_stop_processing = ‘X’.

RETURN.

ENDIF.

MOVE lv_wi_text TO decision.

alternatives-pkey = ‘’.

alternatives-pvalue = ‘’.

APPEND alternatives TO alternatives[].

LOOP AT lt_alternatives INTO ls_alternative.

alternatives-pkey = ls_alternative-altkey.

alternatives-pvalue = ls_alternative-alttext.

APPEND alternatives TO alternatives[].

ENDLOOP.

“* read description in users configured default language

CALL FUNCTION ‘SAP_WAPI_WORKITEM_DESCRIPTION’

EXPORTING

workitem_id = lv_wiid

language = ls_userdefault-langu

user = lv_xubname

IMPORTING

return_code = lv_return_code

TABLES

text_lines = lt_text_lines

message_lines = lt_message_line

message_struct = lt_message_struct.

IF lv_return_code <> 0.

PERFORM append_messages

TABLES lt_message_line

lt_message_struct

CHANGING return[]

lv_stop_processing.

ENDIF.

IF lv_stop_processing = ‘X’.

RETURN.

ENDIF.

Page 53: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

51

LOOP AT lt_text_lines INTO lv_text_line.

IF description = ‘’.

description = lv_text_line.

ELSE.

CONCATENATE description ‘#CRLF#’ lv_text_line INTO description.

ENDIF.

ENDLOOP.

REPLACE ALL OCCURRENCES OF ‘#CRLF#’ IN description WITH

cl_abap_char_utilities=>cr_lf.

ENDFUNCTION.

appendix b: sybase unwired platform projeCts overview

Import Sybase mobile Workflow Development ProjectThe product installs into the $SUP_ROOT$\SMW for SAP Business Suite directory. You can apply the Unwired

Platform deployment packages directly into an Unwired Platform installation, and import the development project files into Unwired WorkSpace, the Unwired Platform integrated development environment. These files are installed:

• SmW-jCO.zip – development and design-time project files• SUP_mWF.jar – MBO deployment package• mobileWorkflow.zip – Sybase Mobile Workflow deployment package

To import the Sybase Mobile Workflow project into Sybase Unwired Workspace:

1. Unzip the SmW-jCO.zip file to a folder, such as C:\SMW-JCO\.2. Launch Sybase Unwired WorkSpace.3. Select File > Import to add the project to the open workspace.

Page 54: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

52

4. Navigate to where you unzipped the project, for example C:\SmW-jCO\, then click Next.5. Click Finish.

6. Import the SAP connection template into Enterprise Explorer.

7. In the Project folder, select SmW_SAP_Default_Endpoint.conn.

Page 55: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

53

mobile Application Diagram OverviewThe MBOs displayed in the diagram below are already mapped to the interfaces of the function modules created in

the previous sections. All the MBOs are located in the Cache Group “default,” which has uses the cache policy “Online.”

• Services mBOThis is a pure service MBO; it does not have any attributes itself. The operation “UserActivation” activates the Sybase Mobile Workflow user. The operation is mapped to the ZSUP_MWF_ACTIVATE function module interface definition.

• Workitem mBOThe definition of this MBO maps to the ZSUP_MWF_WI_GETDETAIL function module, which retrieves the work item details based on the WI_ID pushed via the WF-DCN channel.

The “WorkitemCompletion” operation is mapped to the ZSUP_MWF_WI_COMPLETE function module, which records a mobile user’s work item decision.

• Alternatives mBOThe definition of this MBO maps to the ALTERNATIVES table, which is returned from the ZSUP_MWF_WI_GETDETAIL function module. All the available decisions for the current work item are modeled in this MBO.

Page 56: Sybase® Mobile Workflow for SAP® Business Suite 1.2 [2012]

www.sybase.com

Sybase, Inc. Worldwide HeadquartersOne Sybase DriveDublin, CA 94568-7902U.S.A1 800 8 sybase

Copyright © 2011 Sybase, Inc. All rights reserved. Unpublished rights reserved under U.S. copyright laws. Sybase and the Sybase logo are trademarks of Sybase, Inc. or its subsidiaries. ® indicates registration in the United States of America. SAP and the SAP logo are the trademarks or registered trademarks of SAP AG in Germany and in several other countries. All other trademarks are the property of their respective owners. 01/11

Workflow Template OverviewThe workflow screens defined in the Mobile Workflow Forms Designer are shown below, as they appear in Sybase

Unwired WorkSpace.

There are four screen flows defined:

• Activate flow, which activates the mobile user when the Workflow is initially launched. • Credential flow (not shown here), which requests new user credentials if locally cached device credentials are

expired. • Client-initiated flow, which shows an introduction screen when a user clicks the Workflow icon after activation.

Use the client initiated screen, for example, for support hotline information.• Server-initiated flow, which:

1. Sets the notification start point to extract information from the message pushed over the WF-DCN channel. 2. Invokes the findByParameter object query generated onto the Workitem MBO.3. Defines the Work item detail screen on the device side and operation invoked for completion.