• No results found

Example, How to Create a Sample Workflow Handler

In document IDocBook (Page 103-108)

Let us show you a function module which is suitable to serve as a function module and define the linkage.

We want to create a very simple function module that will be triggered upon a workflow event. This function is called from within function SWE_EVENT_CREATE. The parameters must comply with the calling standard as shown below.

generic_rectype = typecou-rectype IMPORTING

rectype = typecou-rectype TABLES

event_container = event_container EXCEPTIONS

OTHERS = 1.

Listing 1: Call of the type coupled event in release 40B

Release 40B provides the function module WF_EQUI_CHANGE_AFTER_ASSET which could be used as a template for the interface. So we will copy it and put our coding in instead..

RECEIVERS-RECEIVER = SY-SUBRC.

APPEND RECEIVERS.

DOCUMENT_DATA-OBJ_DESCR = OBJ_KEY.

CONTENT = OBJ_KEY.

APPEND CONTENT.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING DOCUMENT_DATA = DOCUMENT_DATA TABLES OBJECT_CONTENT = CONTENT RECEIVERS = RECEIVERS.

ENDFUNCTION.

Listing 2: A workflow handler that sends an Sap Office mail

The function can be registered as a handler for an event. This is done with transaction SWLD.

If you do not know the object type that will trigger the event, you can use the event log. You have to activate it from SWLD and then execute the event firing transaction.

When the event has been fired, it will trace it in the event log.

Create a function module that will be triggered by a workflow event

Template for workflow handler

Link handler to caller

Event logging

Axel Angeli et.al. SAP R/3 Guide to EDI ISBN 3528157291

104

Figure 51: Transaction SWLD to define event linkage and see event log

All workflow handlers are called via RFC to a dummy destination WORKFLOW_LOCAL_000 where 000 is to be replaced by the client number.

Most errors are caused by following reasons:

• You forgot to set the RFC flag in the interface definition of your event handling function module.

• There is a syntax error in your function module (check with generate function group).

• You mistyped something when defining the coupling.

The internal workflow destination WORKFLOW_LOCAL_000 is not defined.

If you think your handler did not execute at all, you can check the list of pending background tasks with transaction SM58. If your event is not there, it has either never been triggered (so your tables SWETYPEENA and SSWETYPEOBJ may have the wrong entries) or your event handler executed indeed and probably may have done something other than you expected. Ergo: your mistake.

Your event handler function is called IN BACKGROUND TASK. You may want to read carefully the help on this topic in the SAP help. (help for “call function” from the editor command line)

Hit list of common errors

SM58 to display what happened to your event

Read carefully the help for CALL FUNCTION ..

IN BACKGROUND TASK

Axel Angeli et.al. SAP R/3 Guide to EDI ISBN 3528157291

• This example sends a mail to the calling user and tells

• about the circumstances when the event was fired.

• Just for fun, it also lists all current enqueue locks DATA: ENQ LIKE SEQG3 OCCURS 0 WITH HEADER LINE.

DATA: DOC_DATA LIKE SODOCCHGI1.

DATA: MAIL LIKE STANDARD TABLE OF SOLISTI1 WITH HEADER LINE.

DATA: RECLIST LIKE STANDARD TABLE OF SOMLRECI1 WITH HEADER LINE.

MAIL-LINE = ‚Event fired by user: &’.

REPLACE ‚&’ WITH SY-UNAME INTO MAIL-LINE.

APPEND MAIL.

*---*

MAIL-LINE = ‚Object Key: &’.

REPLACE ‚&’ WITH OBJKEY INTO MAIL-LINE.

APPEND MAIL.

*---*

MAIL-LINE = ‚Event Name: &’.

REPLACE ‚&’ WITH EVENT INTO MAIL-LINE.

APPEND MAIL.

*---*

MAIL-LINE = ‚Rectype: &’.

REPLACE ‚&’ WITH RECTYPE INTO MAIL-LINE.

APPEND MAIL.

*---*

MAIL-LINE = ‚Object Type: &’.

REPLACE ‚&’ WITH OBJTYPE INTO MAIL-LINE.

APPEND MAIL.

*---*

MAIL-LINE = ‚Container contents:’.

APPEND MAIL.

*---*

LOOP AT EVENT_CONTAINER.

CONCATENATE EVENT_CONTAINER-ELEMENT EVENT_CONTAINER-VALUE INTO MAIL-LINE SEPARATED BY SPACE.

APPEND MAIL.

ENDLOOP.

--- write the current enqueues into the message -(for demo)--- MAIL-LINE = ‚Active enqueue locks when event was triggered:’.

APPEND MAIL.

CALL FUNCTION ‚ENQUEUE_READ’ TABLES ENQ = ENQ.

LOOP AT ENQ.

CONCATENATE ENQ-GNAME ENQ-GARG ENQ-GMODE ENQ-GUSR ENQ-GUSRVB ENQ-GOBJ ENQ-GCLIENT ENQ-GUNAME ENQ-GTARG ENQ-GTCODE

RECLIST-RECEIVER = ‚USERXYZ’.

RECLIST-REC_TYPE = ‚B’.

RECLIST-EXPRESS = ‚ ‚.

• reclist-express = ‚X’. „will pop up a notification on receiver screen

Axel Angeli et.al. SAP R/3 Guide to EDI ISBN 3528157291

DOC_DATA-OBJ_DESCR = ‚Event triggered by workflow type coupling’.

DOC_DATA-OBJ_SORT = ‚WORKFLOW’.

CALL FUNCTION ‚SO_NEW_DOCUMENT_SEND_API1’

EXPORTING

Listing 3: Send an SAP office mail triggered by a workflow event (full example)

Axel Angeli et.al. SAP R/3 Guide to EDI ISBN 3528157291

107

14 ALE - Application Link Enabling

ALE is an R/3 technology for distribution of data between independent R/3 installations. ALE is an application which is built on top of the IDoc engine. It simply adds some structured way to give R/3 a methodical means to find sender, receiver, and triggering events for distribution data.

Make Use of ALE for Your Developments

Transfer master data for material, customer, supplier and more to a different client or system with BALE Copy your settings for the R/3 classification and variant configurator to another system, also in BALE Copy pricing conditions with ALE from the conditions overview screen (e.g. VV12 )

Axel Angeli et.al. SAP R/3 Guide to EDI ISBN 3528157291

108

In document IDocBook (Page 103-108)

Related documents