Introduction to SAP Event Management

...Previous

How to make EM work for our requirements:-  

Here, we have assumed ECC to be application system and delivery process as our business scenario. We would need to do few configuration steps in SPRO in ECC as well as EM system. By writing logic in extractor function module in ECC, we can extract required field values from ECC and make it flow to the EM system. Like, if we need some related field values of delivery from LIKP, then we need to write logic in extractor FM and append to expected event structure.  

Below screenshot shows business object extractor, where coding needs to be done for data extraction from ECC side. So, we would need to create a copy of this standard FM while customizing as we are not supposed to modify standard code.

We had a requirement where in we were required to trigger PGI POD activities from EM system to ECC for completing corresponding activities for delivery document. EM system would receive signals from external systems like FF (freight forwarder), CD (Cross Dock) & DOF ( Direct order fulfillment) which would be posted in EM in the form of event message through idoc. Idoc of message type EVMSTA, idoc type EVMSTA02 can be used to post expected event in EM system. Expected event code can be populated in IDoc segment so that corresponding FM maintained in SPRO gets triggered.  

In reaction to above posted event, we would need to define a reaction which will call an activity function module where logic for PGI would be handled. This reaction can be defined in rule set in SPRO setting. An activity EM needs to be created in EM system where we would need to use OOPs concept to write code logic for extracting parameters values from event message.  

To trigger PGI activity in ECC, we have written logic in FM in EM which will receive event message details as import parameter. We can extract values from these parameters as written in source code below. Then we would place RFC call to RFC enabled function module in ECC which will create an inbound idoc directly in ECC to trigger PGI in delivery document.  

 Source code:-  

FUNCTION ZPGITRIGGER.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*"     REFERENCE (I_EAI) TYPE  /SAPTRX/EM_ACTIVITY_INTERFACE
*" EXPORTING
*"     REFERENCE (E_RETURN_CODE) TYPE  SY-SUBRC
*"----------------------------------------------------------------------
  tables : SAPTRX/EH_CNTRL,/saptrx/eh_info, /saptrx/eh_hdr.
  DATA:
*   Parameters
    lv_param         TYPE /saptrx/function_param,
    lv_arg_1         TYPE /saptrx/msg_var,
    lv_arg_2         TYPE /saptrx/msg_var,
    lv_arg_3         TYPE /saptrx/msg_var,
*    lv_arg_4         TYPE /saptrx/msg_var,
    lv_len           TYPE i,
    lv_param_name    TYPE /saptrx/paramname, "parameter for the control record
    lv_param_name1   TYPE /saptrx/paramname, " paramter for Info record
    ls_cntrl         TYPE /saptrx/eh_cntrl_dyn,
    lt_cntrl         TYPE /saptrx/eh_cntrl_tab,
    ls_info          TYPE /saptrx/eh_info_dyn,
    ls_info_pos      TYPE /saptrx/eh_info_dyn,
    ls_info_mat      TYPE /saptrx/eh_info_dyn,
    ls_info_quan     TYPE /saptrx/eh_info_dyn,
    lt_info_pos      TYPE /saptrx/eh_info_tab,
    lt_info_mat      TYPE /saptrx/eh_info_tab,
    lt_info_quan     TYPE /saptrx/eh_info_tab,
    lv_eh_hdr_dyn    TYPE /SAPTRX/EH_HDR_DYN,
    lv_gi_date       TYPE /SAPTRX/EV_EVTDAT,
    lv_vbeln         TYPE vbeln,
    lv_date          TYPE DATS,
    lv_return        type i.
  DATA:
*   Event Handler event msg process model
    ls_model       TYPE REF TO /saptrx/cl_eh_event_msg_model,
*   Structure of the whole set of Event Message DB tables
    ls_evm_data    TYPE /saptrx/evm_tables,
*   Event Message: Globally Unique ID
    lv_evt_guid    TYPE /saptrx/ev_guid,
*   Structure to table /SAPTRX/EVM_HDR
    ls_header      TYPE /saptrx/evm_hdr_str,
*   Event Handler data structures
    ls_eh_data       TYPE /saptrx/eh_data.
*--------------------------------------------------------------------*
* Structure for the Control data .
*--------------------------------------------------------------------*
* data : lt_cntrl_tab type /saptrx/eh_cntrl_tab.
  data : lt_cntrl_tab type STANDARD TABLE OF /SAPTRX/EH_CNTRL.
  data : ls_cntrl_tab type /SAPTRX/EH_CNTRL.
  data : lt_info_tab type STANDARD TABLE OF  /saptrx/eh_info.
  data : ls_info_tab type /saptrx/eh_info.
  data : lt_eh_tab type STANDARD TABLE OF  /saptrx/eh_hdr.
  data : ls_eh_tab type /saptrx/eh_hdr.
  e_return_code = 4.
* First Parameter: Delivery number
  lv_param = i_eai-task-param_1.
  check lv_param is not initial.
  lv_arg_1 = i_eai-eh_model->get_activity_meta_data(
                              i_eai = i_eai
                              i_meta_data = lv_param ).    " stored delivery number in lv_arg_1
  lv_eh_hdr_dyn = i_eai-eh_model->GET_EH_HDR( ).
*--------------------------------------------------------------------*
** Second Parameter: Position Number of Delivery Item(s)
* Parsing the control info
*--------------------------------------------------------------------*
  lv_param = i_eai-task-param_2.
  CHECK lv_param IS NOT INITIAL.
  lv_arg_2 = i_eai-eh_model->get_activity_meta_data(
                              i_eai = i_eai
                              i_meta_data = lv_param ).
  IF lv_param(1) = '<'.
    TRANSLATE lv_param TO UPPER CASE.                     "#EC SYNTCHAR
*   - Control Parameter: <CNTRL-PARAM_NAME>
    IF lv_param+1(5) = 'CNTRL'.
      lv_len = strlen( lv_param ) - 8.
      MOVE lv_param+7(lv_len) TO lv_param_name.
    endif .
    lt_cntrl = i_eai-eh_model->get_ctrl_parameter( lv_param_name ).
    Loop at lt_cntrl into ls_cntrl.
      MOVE-CORRESPONDING ls_cntrl TO ls_info.               "#EC ENHOK
      APPEND ls_info TO lt_info_pos.
    endloop .
  ELSEIF lv_param+1(4) = 'INFO'.
    lv_len = strlen( lv_param ) - 7.
    MOVE lv_param+6(lv_len) TO lv_param_name.
*     Get Info Parameter
    lt_info_pos = i_eai-eh_model->get_info_parameter( lv_param_name ).
* Fixed Value
  ELSE.
    ls_info-param_index = 1.
    ls_info-param_value = lv_param.
    APPEND ls_info TO lt_info_pos.
  endif .
  clear:  ls_info,
          ls_cntrl.
  refresh lt_cntrl.
* Third parameter: Material
  lv_param = i_eai-task-param_3.
  CHECK lv_param IS NOT INITIAL.
  lv_arg_3 = i_eai-eh_model->get_activity_meta_data(
                       i_eai = i_eai
                       i_meta_data = lv_param ).
* Dynamic Value from Control or Info Paramters
  IF lv_param(1) = '<'.
    TRANSLATE lv_param TO UPPER CASE.                     "#EC SYNTCHAR
*   - Control Parameter: <CNTRL-PARAM_NAME>
    IF lv_param+1(5) = 'CNTRL'.
      lv_len = strlen( lv_param ) - 8.
      MOVE lv_param+7(lv_len) TO lv_param_name1.
*     Get Control Parameter
      lt_cntrl = i_eai-eh_model->get_ctrl_parameter( lv_param_name ).
      LOOP AT lt_cntrl INTO ls_cntrl.
        MOVE-CORRESPONDING ls_cntrl TO ls_info.             "#EC ENHOK
        APPEND ls_info TO lt_info_mat.
      ENDLOOP.
*   Info Paramter: <INFO-PARAM_NAME>
    ELSEIF lv_param+1(4) = 'INFO'.
      lv_len = strlen( lv_param ) - 7.
      MOVE lv_param+6(lv_len) TO lv_param_name1.
*     Get Info Parameter
      lt_info_mat = i_eai-eh_model->get_info_parameter( lv_param_name ).
    ENDIF.
* Fixed Value
  ELSE.
    ls_info-param_index = 1.
    ls_info-param_value = lv_param.
    APPEND ls_info TO lt_info_mat.
  ENDIF.
  clear:  ls_info,
          ls_cntrl.
  refresh lt_cntrl.
  e_return_code = 2.
* Get Event Message data
  ls_model ?= i_eai-eh_model.
  CALL METHOD ls_model->evm_data
    IMPORTING
      e_evm_data = ls_evm_data.
* Retrieve Reason Code if deviation quantity is not initial.
  IF ( ls_evm_data IS NOT INITIAL ).
*   Get the current Event Guid
    lv_evt_guid = i_eai-event_msg-hdr-evt_guid.
    READ TABLE ls_evm_data-header INTO ls_header
      WITH KEY evt_guid = lv_evt_guid.
    IF sy-subrc is initial.
      lv_gi_date = ls_header-evtdat.      " event message posting date
    ENDIF.
  ENDIF.
* Create IDoc Structure.
* For Segment E1EDL20
* - Set delivery number
  lv_vbeln = lv_arg_1.
  lv_date = lv_gi_date.
We have passed delivery number & GI date from EM to ECC to trigger PGI in ECC delivery document. For POD activity, there is standard functionality in EM which can be used easily. We need to configure standard FM /SAPTRX/SEND_POD in rule set of SPRO for required expected event.
ECC code
FUNCTION Z_TRIGGERPGI.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(GV_DELVRY) TYPE  VBELN
*"     VALUE(GV_GI_DATE) TYPE  DATS
*"  EXPORTING
*"     VALUE(RETURN) TYPE  I
*"----------------------------------------------------------------------
*Data declaration
  TABLES : EDIDD,EDIDC,EDIDS,e1vpdlh.
  DATA : it_edidd type standard table of EDI_DD40,   "EDIDD,
         it_edidc type standard table of EDI_DC40,   "EDIDC,
         it_edids type standard table of EDIDS,
         it_tede2 type standard table of tede2,
         ls_edids type edids,
         ws_edidd type EDI_DD40,  "edidd,
         ws_edidc type EDI_DC40,  "edidc,
         lv_docnum type edidc-docnum,
         lv_proc type sy-subrc,
         check_idocpost type i VALUE '0',
         lv_logsys type LOGSYS,
         lv_port type EDI_RCVPOR.
* initialize tables/workareas and predefine parameters
*  PERFORM Z_INITIALIZE_DATA.
  clear : ws_edidd,
         ws_edidc.
* prepare control_record_out
*  PERFORM Z_PREPARE_CONTROL_RECORD.
  SELECT single logsys from T000
                       into lv_logsys
                       where mandt eq sy-mandt.
  ws_edidc-mandt = sy-mandt.
  ws_edidc-docnum = ' '.
  ws_edidc-docrel = ' '.
  ws_edidc-status = ' '.
  ws_edidc-direct = 2.
  CONCATENATE 'SAP' sy-sysid into lv_port.
  ws_edidc-rcvpor = lv_port.
  ws_edidc-rcvprt = 'LS'.
  ws_edidc-rcvprn = lv_logsys.
  ws_edidc-mescod = ' '.
  ws_edidc-mesfct = ' '.
  ws_edidc-sndpor = 'A000000015'.
  ws_edidc-sndprt = 'LS'.
  ws_edidc-sndprn = lv_logsys.
  ws_edidc-credat = sy-datum.
  ws_edidc-cretim = sy-uzeit.
  ws_edidc-std    = 'E'.
  ws_edidc-IDOCTYP = 'SDPIID01'.
  ws_edidc-MESTYP = 'SDPICK'.
  APPEND ws_edidc to it_edidc.
* fill data in idoc table
*  PERFORM Z_FILL_IDOC_TAB_DELIVERY.
  ws_edidd-segnam = 'E1VPDLH'.
  e1vpdlh-vbeln_vl = gv_delvry.
  e1vpdlh-vbeln    = gv_delvry.
  e1vpdlh-komue    = '2'.
  e1vpdlh-wabuc    = 'X'.
  e1vpdlh-wadat_ist = gv_gi_date.
  MOVE e1vpdlh TO ws_edidd-sdata.
  APPEND ws_edidd to it_edidd.
  CALL FUNCTION 'IDOC_INBOUND_ASYNCHRONOUS'
    TABLES
      IDOC_CONTROL_REC_40 = IT_EDIDC
      IDOC_DATA_REC_40    = IT_EDIDD.
  IF SY-SUBRC <> 0.
    check_idocpost = 4.
  ENDIF.
  RETURN = check_idocpost.
ENDFUNCTION.  

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image