SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Workflow Event Create



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SAP Business Workflow
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sun Dec 16, 2007 12:37 am    Post subject: Workflow Event Create Reply with quote

Write a Report/Function Module That Generates an Event

You may be asked to develop a program that generates an event in order to trigger a workflow, e.g the event CREATE for Accounting document line item BSEG. Before programming any event, you must familiarize yourself with the structure of the object type to which it belongs. Transaction SWO1 may be used to display the components of all standard and custom object types existing in the SAP system. (See figure 1.)


Figure 1. Viewing the Components of an Object Type via transaction SWO1.

The events are only defined in the Business Object Repository (BOR). In order to utilize them for workflows, they should be fired from programs. The function module SWE_EVENT_CREATE or any of its variant forms may be used to generate events.

An excerpt from a program that employs this function module is shown below.
......
Code:
  DATA : OBJKEY LIKE.
  DATA : BEGIN OF KEY,
                  BUKRS LIKE BSEG-BELNR,
                  BELNR LIKE BSEG-BELNR,
                  GJAHR LIKE BSEG-GJAHR,
                  BUZEI LIKE BSEG-BUZEI, 
              END OF KEY.
 KEY-BUKRS = ‘ZABC’.
 KEY-BELNR = ‘1900001220’.
 KEY-GJAHR = ‘2003’.
 KEY-BUZEI =  ‘001’.
 OBJKEY = KEY.
  CALL FUNCTION  'SWE_EVENT_CREATE'
     EXPORTING
          OBJTYPE                      = ‘BSEG’
          OBJKEY                        = OBJKEY
          EVENT                          = ‘CREATED’
            TABLES
          EVENT_CONTAINER               = CONTAINER
       EXCEPTIONS
          OBJTYPE_NOT_FOUND      = 1
          OTHERS                 = 2
              .
     IF SY-SUBRC <> 0.
       " MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
       "         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4
       "         RAISING OBJTYPE_NOT_FOUND.
     ENDIF.
   COMMIT WORK.


The above code fragment calls the function module SWE_EVENT_CREATE and passes values to its parameters. Let us go through each of them.

OBJTYPE: The name of the object type whose event is to be generated. This object type must exist in the Business Object Repository (BOR) and must be viewable via the transaction SWO1.

OBJKEY: A set of values that uniquely identifies the instance of the object type in question. For example, in the case of a document line item, the fields Company code document number, Fiscal Year and line item together form the key data for an object of type BSEG.

EVENT: The name of the event, in our case – CREATED.

EVENT_CONTAINER: The internal table that represents the event container. Any additional information that is essential to the correct working of the workflow may be passed from the event generation program to the workflow via containers. You may utilize the macros of container programming within the calling program. SWC_SET_ELEMENT and SWC_SET_OBJECT_KEY are a few such macros. However, the INCLUDE <CNTAIN> is necessary in the main program before using the macros since the macro definitions reside in this include.

As with all function modules, be careful when selecting the type of the passing parameters. Selecting incorrect types may lead to short dumps. If the function module executes without any error, SY-SUBRC returns zero, or any other value, otherwise. Upon successful execution of the function, the fired event may be interpreted as
Accounting Document '1900001220'
line item '001'
of Company code 'ZABC'
in fiscal year '2003'
has been created. This event is made available to the entire SAP system so that any of the linked receiver programs may be invoked.

A subsequent COMMIT WORK statement, however, is very important in order to trigger the event's receiver program(s). Suppose your event triggers the sending of a work item to a user, the work item will not be sent to the respective agent until a COMMIT WORK is executed. The COMMIT WORK triggers a separate tRFC for each receiver found for the respective generated event.

Code:
REPORT ZRGEVTCR.

INCLUDE <CNTN01>.

DATA: OBJKEY  LIKE SWEINSTCOU-OBJKEY,
      EVENTID LIKE SWEDUMEVID-EVTID.
DATA: BEGIN OF EVENT_CONTAINER OCCURS 0.
        INCLUDE STRUCTURE SWCONT.
DATA: END OF EVENT_CONTAINER.

PARAMETERS:
  OBJTYPE  LIKE SWETYPECOU-OBJTYPE DEFAULT 'ZRGMARA',
  MATERIAL LIKE MARA-MATNR,
  EVENT    LIKE SWETYPECOU-EVENT   DEFAULT 'CREATED',
  VOLEH    LIKE MARA-VOLEH,
  LED      LIKE SY-DATUM           DEFAULT '19971231'.


OBJKEY = MATERIAL.
CLEAR EVENT_CONTAINER. REFRESH EVENT_CONTAINER.

* set input parameters for CREATED event.
* remark: to be more general, we had to use fm SWO_QUERY_PARAMETERS
IF EVENT EQ 'CREATED'.
  SWC_SET_ELEMENT EVENT_CONTAINER 'LatestChangeDate' LED.
  SWC_SET_ELEMENT EVENT_CONTAINER 'VolumeUnit' VOLEH.
ENDIF.

CALL FUNCTION 'SWE_EVENT_CREATE'
     EXPORTING
          OBJTYPE           = OBJTYPE
          OBJKEY            = OBJKEY
          EVENT             = EVENT
     IMPORTING
          EVENT_ID          = EVENTID
     TABLES
          EVENT_CONTAINER   = EVENT_CONTAINER
     EXCEPTIONS
          OBJTYPE_NOT_FOUND = 1.

IF SY-SUBRC NE 0.
  WRITE : / 'Object type', OBJTYPE, 'not found in object repository'.
ELSE.
  IF EVENTID NE 0.
    WRITE : / 'At least one receiver was found'.
    COMMIT WORK.
  ELSE.
    WRITE : / 'No receivers found'.
  ENDIF.
ENDIF.


In the BADI implementation of the action call FM SWE_EVENT_CREATE to trigger the workflow.

This is the piece of code that you can write in the BADI implementation.

Code:

* Data for workflow trigger
DATA: objtype LIKE swetypecou-objtype,
objkey LIKE sweinstcou-objkey,
event LIKE swetypecou-event,
event_container LIKE swcont OCCURS 0 WITH HEADER LINE.
 
objtype = 'ZBUS1001'. "Material [sub object of BUS1001]
MOVE v_wfmatnr TO objkey. "V_WFMATNR is material number
event = 'CreatePLMMaterial'."Custom Event defined in
* ZBUS1001 [Tcode SWO1]
REFRESH event_container.
*Following are the Event parameters required in the *Workflow
swc_set_element event_container 'Attachment' v_wfattachment.
swc_set_element event_container 'Material' v_wfmatnr.
swc_set_element event_container 'TisGroup' v_wftisgroup.
swc_set_element event_container 'SchDate' v_schdate.
 
CALL FUNCTION 'SWE_EVENT_CREATE'
EXPORTING
objtype = objtype
objkey = objkey
event = event
TABLES
event_container = event_container
EXCEPTIONS
objtype_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
COMMIT WORK.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SAP Business Workflow All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.