Skip to Content
author's profile photo
Former Member

Trigger workflow?

Hi experts,

pls explain me how to trigger a workflow from an abap program.Which function module is used? pls give me sample code for this

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

5 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on May 17, 2007 at 04:33 AM

    Hai,

    Check the following Code to trigger the Workflow from an ABAP Program.

    • 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.

    In TCode SWETYPV Create entry for Object type Event and Workflow ID.

    In my case Object type is ZBUS1001

    Event CreatePLMMaterial

    Rec type = <Workflow ID>

    Regards,

    Padmam.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on May 17, 2007 at 04:26 AM

    but its not working

    How do we pass objkey if it contain more than 1 field?

    Message was edited by:

    Naveena M

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on May 17, 2007 at 04:09 AM

    Hi,

    In order to trigger an event programmatically, we would use the function module SWE_EVENT_CREATE.

    <b>BUS1001006 ( Standard Material )</b>

    here is the sample code.

    DATA: key LIKE sweinstcou-objkey.

    key = '68." Material Number (hard-coded)

    CALL FUNCTION 'SWE_EVENT_CREATE'

    EXPORTING

    objtype = 'BUS1001006'

    objkey = key

    event = 'CREATED'

    • CREATOR = ' '

    • TAKE_WORKITEM_REQUESTER = ' '

    • START_WITH_DELAY = ' '

    • START_RECFB_SYNCHRON = ' '

    • NO_COMMIT_FOR_QUEUE = ' '

    • DEBUG_FLAG = ' '

    • NO_LOGGING = ' '

    • IDENT =

    • IMPORTING

    • EVENT_ID =

    • TABLES

    • 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.

    ELSE.

    WRITE 'Event Triggered'.

    ENDIF.

    COMMIT WORK.

    ************************************************************************

    In order to test whether the event is getting triggered or not, we can make use of Event Trace. Switch on the event trace using the transaction SWELS.

    Press ‘Switch On”.

    Now execute the program developed earlier. Now switch-off the event trace using the same transaction SWELS.

    Now go to transaction SWEL. Here you can list out the events triggered in the particular period of time. Here is the event-trace list:

    Reward Points if it is Useful.

    Thanks,

    Manjunath MS

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on May 17, 2007 at 04:16 AM

    Hi Naveena,

    Check this tread it will help you,

    https://forums.sdn.sap.com/click.jspa?searchID=2650853&messageID=3074200.

    Thanks.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on May 17, 2007 at 04:55 AM

    Thank you all

    My problem is solved

    Add comment
    10|10000 characters needed characters exceeded