Powered By

Free XML Skins for Blogger

Powered by Blogger

Saturday, October 18, 2008

SAP Workflow from Change Documents

Every time a change document is written, a workflow event for the change document object is triggered. This can be used to chain unconditionally an action from a transaction.

The most interesting chaining point for workflow events is the creation of the change document. Nearly every transaction writes change documents to the database. This document is committed to the database with the function module CHANGEDOCUMENT_CLOSE. This function will also trigger a workflow event.

The workflow handler triggered by an event which is fired from change documents is defined in table SWECDOBJ . For every change document type, a different event handler can be assigned.

This is usually a function module and the call for it is the following:

CALL FUNCTION swecdobj-objtypefb

EXPORTING

changedocument_header = changedocument_header
objecttype = swecdobj-objtype

IMPORTING

objecttype = swecdobj-objtype

TABLES

changedocument_position = changedocument_position.

Change pointers are created by calling FUNCTION CHANGEDOCUMENT_CLOSE which writes the usual change documents into table CDHDR and CDPOS. This function then calls the routine CHANGE_POINTERS_CREATE, which creates the change pointers.

CALL FUNCTION 'CHANGE_POINTERS_CREATE'

EXPORTING

change_document_header = cdhdr

TABLES

change_document_position = ins_cdpos.

Trigger a Workflow from Messaging :

The third common way to trigger a workflow is doing it from messaging.

When the R/3 messaging creates a message and processes it immediately, then it actually triggers a workflow. You can use this to set up conditional workflow triggers, by defining a message with the message finding and link the message to a
workflow.

You define the message the usual way for your application as you would do it for
defining a message for SAPscript etc. As a processing media you can assign either
the type W for workflow or 8 for special processing.

The media type W for workflow would require defining an object in the object repository. We will only show how you can trigger the workflow with a standard
ABAP using the media type 8.

You need to assign a program and a form routine to the message in table TNAPR.
The form routine you specify needs exactly two USING-parameters as in the
example below.


TABLES: NAST.

FORM ENTRY USING RETURN_CODE US_SCREEN.


na call your workflow action

RETURN_CODE = 0.
SY-MSGID = '38'.
SY-MSGNO = '000'.
SY-MSGNO = 'I'.

SY-MSGV1 = 'Workflow called via NAST'.

CALL FUNCTION 'NAST_PROTOCOL_UPDATE'

EXPORTING

MSG_ARBGB = SYST-MSGID
MSG_NR = SYST-MSGNO
MSG_TY = SYST-MSGTY
MSG_V1 = SYST-MSGV1
MSG_V2 = SYST-MSGV2
MSG_V3 = SYST-MSGV3
MSG_V4 = SYST-MSGV4

EXCEPTIONS

OTHERS = 1.

ENDFORM.

In addition, you need to declare the table NAST with a tables statement public in the
ABAP where the form routinely resides. When the form is called, the variable NAST
is filled with the values of the calling NAST message.

No comments:

Archives