Wednesday, August 31, 2011

Triggering a workflow from abap

Last week’s post was about creating a workflow on a custom object.

In a normal situation, when using standard objects in workflow, you subscribe your workflow on existing events on existing standard objects.

These events are raised in standard coding, at the right time.

When using custom objects, you should also raise the event in custom coding, so for instance after saving an instance of your custom object to the database, you should raise the CREATED event.

Raising an event on a BOR object can be easily done with the following simple ABAP code:

DATA it_cont TYPE TABLE OF swcont.
DATA it_event_id TYPE swedumevid-evtid.

    objtype = [your object type]
    objkey = [your instances key]
    event = [your event]
    event_id = it_event_id
    event_container = it_cont
    objtype_not_found = 1
                   OTHERS = 2.

IF it_event_id IS NOT INITIAL.

All workflows that start on that event will start.

If you are working with foreign custom objects (for instance custom objects in an ERP system), add the coding to a remote enabled function module, and call this from the remote system.