Skip to content

SWE_EVENT_CREATE

Raise a SAP Business Workflow event from ABAP to start or continue a workflow.

Purpose

SWE_EVENT_CREATE fires a business object event (e.g. CREATED, CHANGED, DELETED) for a given business object type (BOR object). Active event linkages in the workflow system then start or advance workflows that are waiting on that event.

Use this when your ABAP code needs to trigger a workflow — for example, after saving a custom document, approving a request, or completing a batch job.

Signature (key parameters)

Parameter Direction Type Description
OBJTYPE Importing SWETYPECOU-OBJTYPE Business object type (from BOR, e.g. 'BUS2012')
OBJKEY Importing SWEINSTCOU-OBJKEY Key of the object instance (e.g. PO number)
EVENT Importing SWETYPECOU-EVENT Event name (e.g. 'CREATED', 'CHANGED')
START_WITH_DELAY Importing SWEFLAGS-DELAYFLAG 'X' = process event asynchronously via queue
START_RECFB_SYNCHRON Importing SWEFLAGS-SYNCFLAG 'X' = process synchronously in same LUW
NO_LOGGING Importing SWEFLAGS-LOGFLAG 'X' = suppress event log entry
EVENT_ID Exporting SWEDUMEVID-EVTID ID assigned to the raised event
RECEIVER_COUNT Exporting SWE_EVTID Number of workflow receivers triggered
EVENT_CONTAINER Tables SWCONT Optional event container parameters

Example — raise CREATED event for a purchase order

REPORT z_swe_event_po.

START-OF-SELECTION.

  DATA: lv_objtype TYPE swetypecou-objtype VALUE 'BUS2012',
        lv_objkey  TYPE sweinstcou-objkey,
        lv_event   TYPE swetypecou-event   VALUE 'CREATED'.

  " Object key must match the BOR key definition — for BUS2012: 10-char PO number
  lv_objkey = '4500012345'.

  CALL FUNCTION 'SWE_EVENT_CREATE'
    EXPORTING
      objtype           = lv_objtype
      objkey            = lv_objkey
      event             = lv_event
    EXCEPTIONS
      objtype_not_found = 1
      OTHERS            = 2.

  IF sy-subrc = 0.
    WRITE: / 'Event raised:', lv_event, 'for', lv_objtype, lv_objkey.
  ELSE.
    WRITE: / 'Event creation failed, sy-subrc:', sy-subrc.
  ENDIF.

Example — raise custom event with container parameters

REPORT z_swe_event_custom.

START-OF-SELECTION.

  DATA lt_container TYPE STANDARD TABLE OF swcont.

  " Pass extra context to the workflow via event container
  " SWCONT fields: element (name), value, type, len, low, high
  APPEND VALUE #( element = 'AMOUNT'   value = '10000' ) TO lt_container.
  APPEND VALUE #( element = 'CURRENCY' value = 'EUR'   ) TO lt_container.

  DATA lv_objkey TYPE sweinstcou-objkey VALUE 'REQ0000042'.

  CALL FUNCTION 'SWE_EVENT_CREATE'
    EXPORTING
      objtype  = 'ZBUSREQUEST'
      objkey   = lv_objkey
      event    = 'APPROVED'
    TABLES
      event_container = lt_container
    EXCEPTIONS
      OTHERS = 1.

  IF sy-subrc = 0.
    WRITE: / 'Event APPROVED raised for ZBUSREQUEST', lv_objkey.
  ELSE.
    WRITE: / 'Event creation failed, sy-subrc:', sy-subrc.
  ENDIF.

Asynchronous vs synchronous raising

By default SWE_EVENT_CREATE raises the event asynchronously — the event is committed and the workflow server picks it up in the next processing cycle. Workflows do not start immediately within the same transaction.

To raise synchronously (workflow starts within the same LUW), pass START_RECFB_SYNCHRON = 'X' — but a COMMIT WORK must occur before calling the FM so the triggering object is visible to the workflow.

Common pitfalls

Event linkage must be active

If no active event linkage exists in the workflow system for this object type + event combination, the event is silently ignored. Check linkages in SWETYPV.

OBJKEY format must match the BOR key exactly

The key format is defined in the Business Object Repository (transaction SWO1). For BUS2012 (purchase order) it is the 10-character PO number. Wrong format → no workflow instance is found or started.

  • COMMIT WORK timing: The event is only processed after a database commit. If the FM is called inside a long transaction, the workflow may not start until the commit.
  • Custom business objects: Define Z-business objects in SWO1 with key fields and events. Register event linkages in SWETYPV.
  • Monitoring: Check event trace in SWELS (event log) and workflow instance status in SWI1.

See also

  • Transaction SWO1 — Business Object Repository (define BOR objects and events)
  • Transaction SWETYPV — event type linkages (which events trigger which workflows)
  • Transaction SWI1 — workflow instance monitor
  • Transaction SWELS — event log (trace raised events)

Comments