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

Launching an error Workflow



 
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: 1639

PostPosted: Mon Sep 10, 2007 8:12 pm    Post subject: Launching an error Workflow Reply with quote

Code:
* include for workflow programming
INCLUDE <CNTN01>.

       PERFORM analyzing_event_create
                TABLES
                   t_couple_to_process
                USING
                   l_commit_counter
                   inbsync.
        if sy-subrc is initial.

          MESS-MSGID = 'ZS7'.
          MESS-MSGTY = 'E'.
          MESS-MSGNO = i_msgno.
          MESS-MSGV1 = i_msgv1.
          MESS-MSGV2 = i_msgv2.
          CALL FUNCTION 'IDOC_ERROR_WORKFLOW_START'
            EXPORTING
              DOCNUM                        = 0
              EVENTCODE                     = 'EDIM'
              MESS                          = mess
              STATUSMESS                    = mess
            EXCEPTIONS
              NO_ENTRY_IN_TEDE5             = 1
              ERROR_IN_START_WORKFLOW       = 2
              OTHERS                        = 3.

          COMMIT WORK.
        endif.  "link created

FORM analyzing_event_create
                TABLES
                   t_couple_to_process_in  STRUCTURE ediinbound
                USING
                   commit_counter_in       LIKE      ediglodata-comcount
                   start_recfb_synchron_in LIKE      ediglodata-inbsync.
* local variables
  DATA:
* instance that is created
    l_object               TYPE swc_object,
* object key, e.g IDoc number
    l_object_key           LIKE swotobjid-objkey,
* id of wf event
    l_event_id             LIKE swedumevid-evtid,
* status record for case of error
    l_status_record        TYPE tidoc_status_record_ext,
* flag indicating whether subscribed task is started synchronously
    l_start_recfb_synchron LIKE sweflags-syncflag VALUE ' ',
* idoc number (needed because of type checking)
    l_idoc_number          LIKE edidc-docnum.
* local constants
  CONSTANTS:
* object type 'IDOC'
    c_object_type          LIKE swetypecou-objtype VALUE 'IDOCINVOIC',
* name of event to be created
    c_idc_evt     LIKE swetypecou-event VALUE 'INPUTERROROCCURREDMM'
.

 if t_couple_to_process_in[] is initial.
    COMMIT WORK.
    CALL FUNCTION 'DEQUEUE_ALL'.
    CLEAR commit_counter_in.
    exit.
  endif.

* cast
  l_start_recfb_synchron = start_recfb_synchron_in.
* declaration of container
  swc_container       l_t_ev_container.
* initialize container
  swc_clear_container l_t_ev_container.

* dequeue all idocs at the same time
  LOOP AT t_couple_to_process_in.
* cast
    l_idoc_number = t_couple_to_process_in(16).
    CALL FUNCTION 'EDI_DOCUMENT_DEQUEUE_LATER'
         EXPORTING
              docnum = l_idoc_number
         EXCEPTIONS
              OTHERS = 0.
  ENDLOOP.

* get first idoc number in table in order to create an object
  READ TABLE t_couple_to_process_in INDEX 1.
* set object key in variable of correct type (casting)
  l_object_key = t_couple_to_process_in(16).

* create an object, i.e. an IDoc
  swc_create_object l_object c_object_type l_object_key.

* fill container: work item object id (idoc)
  swc_set_element l_t_ev_container     "EC *
                  c_element_wi_obj_id  "EC *
                  l_object.            "EC *
* fill container:  NumberPlusEventcode (table of couples)
  swc_set_table l_t_ev_container
                c_element_no_plus_info
                t_couple_to_process_in.

* fire event that will trigger the idoc inbound processing
  CALL FUNCTION 'SWE_EVENT_CREATE'
       EXPORTING
            objtype              = c_object_type
            objkey               = l_object_key
            event                = c_idc_evt
*           CREATOR              = ' '
*           START_WITH_DELAY     = ' '
            start_recfb_synchron = l_start_recfb_synchron
       IMPORTING
            event_id             = l_event_id
       TABLES
            event_container      = l_t_ev_container
       EXCEPTIONS
            objtype_not_found    = 1
            OTHERS               = 2.

  IF   ( sy-subrc <> 0 )
* event was not created => error handling for this idoc (EDIM)
    OR ( l_event_id = 0 ).
* stop processing, no commit
    MESSAGE ID      'E0'
            TYPE    'A'
            NUMBER  '374'
            WITH    l_status_record-docnum
                    c_idc_evt
            RAISING event_create_failed.
  ELSE.
* do commit and reset counter
* the commit will get the idocs to the database and at the same time
* activate the event that was created
    COMMIT WORK.
* dequeue all unprocessed IDocs to avoid log-overflow
    CALL FUNCTION 'DEQUEUE_ALL'.
    CLEAR commit_counter_in.
* reset table of idocs that need to be processed
    CLEAR   t_couple_to_process_in.
    REFRESH t_couple_to_process_in.
  ENDIF.

ENDFORM.                               " ANALYZING_EVENT_CREATE
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.