Sybase MobileWorkflow

Embed Size (px)

Citation preview

  • 8/9/2019 Sybase MobileWorkflow

    1/56

    WHITE PAPER

    www.sybase.com

    Sybase® Mobile Workflow forSAP® Business Suite 1.2 

    Overview and Customization

  • 8/9/2019 Sybase MobileWorkflow

    2/56

    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

  • 8/9/2019 Sybase MobileWorkflow

    3/56

    1

    INTRODUCTION

    Sybase 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 Architecture

    The 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 Platform

    SAP

    Workflow

    & Inbox

    SAP Business Suite

    SUP Protocol JCO

    HTTP(s)

    MBO   RFC

    RFC

    RFC

    MBO

    MBO

    WF DCN qRFC

  • 8/9/2019 Sybase MobileWorkflow

    4/56

    2

    SAP BUSIN ESS SUITE CUSTOMIZATION

    Custom Repository Objects

    The 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, lengthvariable (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, lengthvariable (case-sensitive)

    Class Library/Classes

    PACKAGE NAME OBJECT TYPE OBJECT NAME DESCRIPTIONZSUP_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 Platformuser parameter creation

    ZSUP_MWF_PKG Function ZSUP_MWF_GEN_NOTIF_JSON

    Generates a Sybase MobileWorkflow notification inJSON

    ZSUP_MWF_PKG Function ZSUP_MWF_HTTP_POST Performs actualnotification by HTTP postto specified destination

    ZSUP_MWF_PKG Function ZSUP_MWF_PUSH_WORKITEM

    Collects all necessaryinformation and executespush to HTTP destination

    ZSUP_MWF_PKG Function ZSUP_MWF_WI_COMPLETE

    Allows update of workitem with user’s decision

    ZSUP_MWF_PKG Function ZSUP_MWF_GETDETAIL Retrieves work item detailsfor specified user

  • 8/9/2019 Sybase MobileWorkflow

    5/56

    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 UnwiredPlatform Mobile Workflow

    Task 1 . Create a Package

    Create 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.

  • 8/9/2019 Sybase MobileWorkflow

    6/56

    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 s teps for

    each domain.

    1. In SAP Object Navigator, right-click the ZSUP_MWF_PKG package you just created and select

    Create > Dictionary Object > Domain.

  • 8/9/2019 Sybase MobileWorkflow

    7/56

  • 8/9/2019 Sybase MobileWorkflow

    8/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    9/56

    7

    Task 3. Create Data Elements

    Create 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.

  • 8/9/2019 Sybase MobileWorkflow

    10/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    11/56

    9

    Task 4. Create a Structure

    Create 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.

  • 8/9/2019 Sybase MobileWorkflow

    12/56

    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 us er 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.

  • 8/9/2019 Sybase MobileWorkflow

    13/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    14/56

    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 Group

    1. 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.

  • 8/9/2019 Sybase MobileWorkflow

    15/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    16/56

    14

    Task 8. Create Function Modules

    Create 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.

  • 8/9/2019 Sybase MobileWorkflow

    17/56

    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:

  • 8/9/2019 Sybase MobileWorkflow

    18/56

    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

  • 8/9/2019 Sybase MobileWorkflow

    19/56

    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:

  • 8/9/2019 Sybase MobileWorkflow

    20/56

    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:

  • 8/9/2019 Sybase MobileWorkflow

    21/56

    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:

  • 8/9/2019 Sybase MobileWorkflow

    22/56

    20

    • Export tab:

    • Tables tab:

     

    Task 9. Create SET/GET Parameter ID

    1. 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.

  • 8/9/2019 Sybase MobileWorkflow

    23/56

    21

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

     

    Task 10. Activate the Objects

    In 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 Setting

    In 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.

  • 8/9/2019 Sybase MobileWorkflow

    24/56

    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 Setting

    Use 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:

     

  • 8/9/2019 Sybase MobileWorkflow

    25/56

    23

    Workflow Template Customization

    1. 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:

     

  • 8/9/2019 Sybase MobileWorkflow

    26/56

    24

    sup.mwf.destination

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

    sup.mwf.qname

    A 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.qcount 

    The 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.match

    Allows 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.security 

    The name of the security configuration in Unwired Platform that is used to authenticate incoming device usersagainst Unwired Platform (for example, “admin”).

    sup.mwf.sender 

    Contains the default sender address that appears in the Mobile Inbox for notifications originating from this

    decision task.

    sup.mwf.sender.l10n

    Allows 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.en

    The 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.priority 

    Specifies whether the notification on the mobile device is marked as high priority (a red exclamation mark) or with

    default priority.

    sup.mwf.markread 

    Specifies whether the notification is created on the mobile device as a read or unread notification.

  • 8/9/2019 Sybase MobileWorkflow

    27/56

    25

    End-to-End Communication Troubleshooting

    You 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 ‘’.

  • 8/9/2019 Sybase MobileWorkflow

    28/56

    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 = ‘’.

  • 8/9/2019 Sybase MobileWorkflow

    29/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    30/56

    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

  • 8/9/2019 Sybase MobileWorkflow

    31/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    32/56

    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 

  • 8/9/2019 Sybase MobileWorkflow

    33/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    34/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    35/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    36/56

    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 TYPE x.

      lv_str = username.

      lv_length = strlen( lv_str ).

      DO lv_length TIMES.

      lv_char1 = lv_str(1).

       ASSIGN lv_char1 TO  CASTING.

      MOVE  TO lv_int4.

      lv_sum = lv_sum + lv_int4.

      SHIFT lv_str.

      ENDDO.

  • 8/9/2019 Sybase MobileWorkflow

    37/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    38/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    39/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    40/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    41/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    42/56

    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

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

  • 8/9/2019 Sybase MobileWorkflow

    43/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    44/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    45/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    46/56

    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’

  • 8/9/2019 Sybase MobileWorkflow

    47/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    48/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    49/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    50/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    51/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    52/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    53/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    54/56

    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.

  • 8/9/2019 Sybase MobileWorkflow

    55/56

    53

    Mobile Application Diagram Overview

    The 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 MBO

    This 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 MBO

    The 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 MBO

    The 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.

  • 8/9/2019 Sybase MobileWorkflow

    56/56

    Workflow Template Overview

    The 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 us er 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.