Skip to Content

<p>If you need to develop an SCEM scenario in which you need to create or update events with IDOC’s then hopefully this will help you. </p><p> </p><p>Consider a scenario in which you are creating or updating the events using BAPI calls on SCEM server (Please read Kevin’s blog for the same). Currently the events are being created or updated by BAPI calls. Now consider a scenario in which the BAPI call fails due to one or the other reason and the event does not get created or updated. This may lead to inconsistencies. To handle these cases we can use the option of creating or updating the event using IDOC’s. The IDOC details are as below.</p><p> </p><p>IDOC Type: EHPOST1</p><p>Message Type: EHPSTA</p><p>Process Code: /SAPTRX/EHPOST</p><p> </p><p>After completing the basic ALE settings, you can add the code for the processing the IDOC.</p><p> </p><p>* Sample Code </p><p> </p><p>  CALL FUNCTION ‘/SAPTRX/BAPI_EH_ADDEVENTMSG_02′</p><p>    DESTINATION v_target_logsys</p><p>    EXPORTING</p><p>      blockonerrorin  = c_x</p><p>      synchronous     = c_x</p><p>    IMPORTING</p><p>      erroroccurred   = v_error</p><p>    TABLES</p><p>      trackingheader  = t_trackingheader</p><p>      trackparameters = t_trackparameters</p><p>      return          = t_bapireturn.</p><p> </p><p>  LOOP AT t_bapireturn ASSIGNING <f_bapiret> WHERE type = c_e.</p><p>  ENDLOOP.</p><p> </p><p>  IF NOT v_error IS INITIAL OR sy-subrc IS INITIAL.</p><p> </p><p>* Close RFC connection</p><p>  CALL FUNCTION ‘RFC_CONNECTION_CLOSE'</p><p>    EXPORTING</p><p>      destination                          = v_target_logsys</p><p>    EXCEPTIONS</p><p>      destination_not_open           = 1</p><p>      OTHERS                             = 2.</p><p> </p><p>* Send the Idoc</p><p>    CALL FUNCTION ‘Z_IDOC_OUTPUT_EVMSTA'</p><p>      TABLES</p><p>        tb_trackingheader  = t_trackingheader</p><p>        tb_trackparameters = t_trackparameters.</p><p>  ENDIF.</p><p> </p><p> </p><p>* Function Module Code</p><p>FUNCTION Z_IDOC_OUTPUT_EVMSTA.</p><p>“—-


</p><p>
“Local Interface:</p><p>”  TABLES

”      TB_TRACKINGHEADER STRUCTURE /SAPTRX/BAPI_EVM_HEADER</p><p>”      TB_TRACKPARAMETERS STRUCTURE /SAPTRX/BAPI_EVM_PARAMETERS

“—-


</p><p> </p><p>  DATA: t_edidd TYPE STANDARD TABLE OF edidd.</p><p>  DATA: t_edidc TYPE STANDARD TABLE OF edidc.</p><p> </p><p>
Build up Idoc data

  PERFORM build_idoc_data TABLES tb_trackingheader

                                 tb_trackparameters

                                 t_edidd.

 

* Build Control records

  PERFORM build_control_record TABLES t_edidc.

 

* Send Idoc

  PERFORM send_idoc TABLES t_edidc

                           t_edidd.

 

ENDFUNCTION.

 

&—-


&      Form  build_idoc_data</p><p>&–


</p><p>  Build idoc data</p><p>*—


</p><p>      –>rt_trackingheader   EH track

*      –>rt_trackparameters  Tracking Paarmeters

*      >rt_edidd            Idoc data</p><p>*


</p><p>FORM build_idoc_data  TABLES   rt_trackingheader STRUCTURE /saptrx/bapi_evm_header</p><p>                               rt_trackparameters STRUCTURE /saptrx/bapi_evm_parameters</p><p>                               rt_edidd STRUCTURE edidd.    </p><p> </p><p>  DATA: s_trackingheader TYPE /saptrx/bapi_evm_header.</p><p>  DATA: s_trackparameters TYPE /saptrx/bapi_evm_parameters.</p><p>  DATA: s_e1evmhdr02 TYPE e1evmhdr02.</p><p>  DATA: s_e1evmtid TYPE e1evmtid.</p><p>  DATA: s_e1evmpar TYPE e1evmpar.</p><p>  DATA: s_edidd TYPE edidd.</p><p> </p><p>  LOOP AT rt_trackingheader INTO s_trackingheader.</p><p>    s_edidd-segnam  = c_e1evmhdr02.</p><p>    MOVE-CORRESPONDING s_trackingheader TO s_e1evmhdr02.</p><p>    s_edidd-sdata = s_e1evmhdr02.</p><p>    APPEND s_edidd TO rt_edidd.</p><p>    CLEAR s_edidd.</p><p>    MOVE-CORRESPONDING s_trackingheader TO s_e1evmtid.</p><p>    s_edidd-segnam  = c_e1evmtid.</p><p>    s_edidd-sdata   = s_e1evmtid.</p><p>    APPEND s_edidd TO rt_edidd.</p><p>    CLEAR s_edidd.</p><p>    LOOP AT rt_trackparameters INTO s_trackparameters WHERE evtcnt = s_trackingheader-evtcnt.</p><p>      MOVE-CORRESPONDING s_trackparameters TO s_e1evmpar.</p><p>      s_edidd-segnam  = c_e1evmpar.</p><p>      s_edidd-sdata   = s_e1evmpar.</p><p>      APPEND s_edidd TO rt_edidd.</p><p>      CLEAR s_edidd.</p><p>    ENDLOOP.</p><p>  ENDLOOP.</p><p>ENDFORM.                    ” build_idoc_data</p><p> </p><p>&


</p><p>&      Form  build_control_record</p><p>*&


</p><p>Build idoc control table</p><p>*      <
rt_edidc  Idoc control data

—-


FORM build_control_record  TABLES rt_edidc STRUCTURE edidc.

 

  DATA: s_edidc TYPE edidc.

 

* Get receiver information from partner profile

  SELECT rcvprn rcvpor rcvprt mestyp mestyp idoctyp

      INTO (s_edidc-rcvprn,

          s_edidc-rcvpor,

          s_edidc-rcvprt,

          s_edidc-mestyp,

          s_edidc-stdmes,

          s_edidc-doctyp)

    FROM edp13

    WHERE rcvprt = c_rcvprt_out

     AND mestyp  = c_evmsta     

     AND test    = space.

    APPEND s_edidc TO rt_edidc.

    CLEAR s_edidc.

  ENDSELECT.

 

* Get sender information

  SELECT SINGLE logsys

      INTO s_edidc-sndprn

      FROM t000

     WHERE mandt = sy-mandt.

  s_edidc-sndprt = c_rcvprt_out.

  MODIFY rt_edidc FROM s_edidc TRANSPORTING sndprn sndprt WHERE sndprn IS INITIAL.

 

ENDFORM.                    ” build_control_record

 

&—-


&      Form  send_idoc</p><p>&—-


</p><p>      –>rt_edidc  Idoc control data

*      >rt_edidd  Idoc data</p><p>*


*

FORM send_idoc  TABLES   rt_edidc STRUCTURE edidc          

                         rt_edidd STRUCTURE edidd.         

 

  DATA: s_edidc TYPE edidc.

  DATA: t_edidc TYPE STANDARD TABLE OF edidc.

 

  LOOP AT rt_edidc INTO s_edidc.

    CALL FUNCTION ‘MASTER_IDOC_DISTRIBUTE’

      EXPORTING

        master_idoc_control            = s_edidc

      TABLES

        communication_idoc_control     = t_edidc

        master_idoc_data               = rt_edidd

      EXCEPTIONS

        error_in_idoc_control          = 1

        error_writing_idoc_status      = 2

        error_in_idoc_data             = 3

        sending_logical_system_unknown = 4

        OTHERS                         = 5.

    IF sy-subrc <> 0.

      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

 

  ENDLOOP.

ENDFORM.                    ” send_idoc

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply