|
Example code of 1 way of launching an error workflow for an IDoc.
* 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
Related Items:
|