Skip to end of metadata
Go to start of metadata

The Report and the Function module below enclosed  can be used as sample to handle phased message processing within data pipeline from one or more SAP systems named SENDER (A), XI/PI system named FIRST RECEIVER (B)  and XI/PI system named SECOND RECEIVER (C).The solution allows to build a phased message processing into a landscape adopting Proxy or IDoc technology on sender side.

The function module  Z_IDOC_CONTROLM is part of sender side (A) and the report ZBRGP_TRIGGER_MSG is part of first PI receiver(B).

  • The remote-enabled function module Z_IDOC_CONTROLM only selects Idocs ready for Dispatch (status '30') then Dispatch these, and return the amount of successfully passed to the Port (status 03).
FUNCTION z_idoc_controlm.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(MESTYP) TYPE  EDI_MESTYP OPTIONAL
*"     VALUE(RCVPRN) TYPE  EDI_RCVPRN OPTIONAL
*"     VALUE(SNDPRN) TYPE  EDI_SNDPRN OPTIONAL
*"     VALUE(RCVPOR) TYPE  EDI_RCVPOR OPTIONAL
*"  EXPORTING
*"     VALUE(NUM_IDOCS) TYPE  ANZEDIDD
*"----------------------------------------------------------------------
  CLEAR: r_idocs, num_idocs.
  REFRESH r_idocs.
  r_idocs-sign = 'I'.
  r_idocs-option = 'EQ'.
* Select all IDoc numbers
  SELECT docnum
    INTO r_idocs-low
    FROM edidc
   WHERE status EQ '30'
     AND mestyp EQ mestyp
     AND rcvprn EQ rcvprn
     AND sndprn EQ sndprn
     AND rcvpor EQ rcvpor.
    APPEND r_idocs.
  ENDSELECT.
  CHECK sy-subrc EQ 0.
* Process selected IDocs
  SUBMIT rseout00 WITH docnum IN r_idocs
                  WITH p_show_w = space
                  AND RETURN.
  COMMIT WORK.
* Read the IDoc status  for success
  SELECT COUNT( * )
    INTO num_idocs
    FROM edidc
   WHERE status EQ '03'
     AND docnum IN r_idocs.

ENDFUNCTION.
  • The Report ZBRGP_TRIGGER_MSG  executes below mentioned step:
  1. Checks Input Parameters, and in case of missing mandatory fields, an alert is generated
  2. Checks sender and receiver destination using function RFC_WALK_THRU_TEST.
  3. Checks flow transmission on second receiver PI system (C) and eventually go on step 4. In case of errors an alert is raised and the program stops the execution.
  4. Calls Remote-enable function module Z_IDOC_CONTROLM (for IDoc processing) or TRFC_QIN_ACTIVATE (for Proxy processing) for starting transmission on sender side (A).
  5. Updates transmission results on second receiver PI system (C).

The function modules of Second receiver ( Z_CHECKOPEN_FLOW_DE, Z_XICNTM_MSG_IN_DE) called from report ZBRGP_TRIGGER_MSG are not part of this document and can be designed according to your requirements. Feel free to comment these or adjust ABAP code.

*&---------------------------------------------------------------------*
*& Report  ZBRGP_TRIGGER_MSG
*&
*&---------------------------------------------------------------------*
*&
*& Report for triggering message transmission
*& (Idoc and Proxy)
*&
*& Author:  Niki Scaglione
*& Company: Techedge
*&---------------------------------------------------------------------*
REPORT zbrgp_trigger_msg NO STANDARD PAGE HEADING.
SELECTION-SCREEN BEGIN OF BLOCK ext_cont WITH FRAME TITLE text-t04.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK syst_cont WITH FRAME TITLE text-t02.
PARAMETERS:
      p_rfcsnd TYPE rfcdes-rfcdest OBLIGATORY,
      p_obsyst TYPE ait_sndr OBLIGATORY,
      p_obname TYPE rm_oifname OBLIGATORY.
SELECTION-SCREEN SKIP.
PARAMETERS:
      p_rfcrcv TYPE rfcdes-rfcdest OBLIGATORY,
      p_ibsyst TYPE ait_rcvr OBLIGATORY,
      p_ibname TYPE rm_iifname OBLIGATORY.
SELECTION-SCREEN SKIP.
PARAMETERS:
      p_cm_end(60) TYPE c OBLIGATORY.
SELECTION-SCREEN SKIP.
PARAMETERS:
      p_ipcat TYPE salrtdcat OBLIGATORY.
SELECTION-SCREEN END OF BLOCK syst_cont.
SELECTION-SCREEN BEGIN OF BLOCK radio_cont WITH FRAME TITLE text-t05.
PARAMETERS: p_proxy  RADIOBUTTON GROUP t DEFAULT 'X' USER-COMMAND appl.
PARAMETERS: p_idoc   RADIOBUTTON GROUP t.
SELECTION-SCREEN END OF BLOCK radio_cont.
SELECTION-SCREEN BEGIN OF BLOCK proxy_cont WITH FRAME TITLE text-t01.
SELECTION-SCREEN SKIP.
PARAMETERS:
      p_qname TYPE trfcqin-qname MODIF ID prx,
      p_maxtme TYPE sy-index MODIF ID prx.
SELECTION-SCREEN END OF BLOCK proxy_cont.
SELECTION-SCREEN BEGIN OF BLOCK idoc_cont WITH FRAME TITLE text-t03.
PARAMETERS:
      p_mestyp  TYPE  edi_mestyp MODIF ID idc,
      p_rcvprn  TYPE  edi_rcvprn MODIF ID idc,
      p_sndprn  TYPE  edi_sndprn MODIF ID idc,
      p_rcvpor  TYPE  edi_rcvpor MODIF ID idc.
SELECTION-SCREEN END OF BLOCK idoc_cont.

SELECTION-SCREEN END OF BLOCK ext_cont.
DATA:
        lt_dest TYPE TABLE OF rfchosts,
        lt_log TYPE TABLE OF rfclog,
        lt_container TYPE TABLE OF swcont,
        lw_log TYPE rfclog,
        lw_dest TYPE rfchosts,
        lw_container TYPE swcont,
        l_exeluw  TYPE  sy-index,
        l_exeidoc TYPE anzedidd,
        l_nummsg TYPE char10,
        l_result TYPE char2,
        l_start_time TYPE syuzeit,
        l_alert_msg TYPE REF TO cx_ai_system_fault,
        l_err_txt TYPE string,
        l_check_flow,
        l_test_in TYPE rfctest,
        l_rfcsnd TYPE string,
        l_rfcrcv TYPE string,
        l_obname TYPE string,
        l_ibname TYPE string.
AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    CASE 'X'.
      WHEN p_proxy.
        IF screen-group1 = 'PRX'.
          screen-active = '1'.
          MODIFY SCREEN.
        ENDIF.
        IF screen-group1 = 'IDC'.
          screen-active = '0'.
          MODIFY SCREEN.
        ENDIF.
      WHEN p_idoc.
        IF screen-group1 = 'PRX'.
          screen-active = '0'.
          MODIFY SCREEN.
        ENDIF.
        IF screen-group1 = 'IDC'.
          screen-active = '1'.
          MODIFY SCREEN.
        ENDIF.
    ENDCASE.
  ENDLOOP.
START-OF-SELECTION.

  TRY.
*Check Input Parameters
      IF p_proxy EQ 'X'.
        IF p_qname IS INITIAL OR p_maxtme IS INITIAL.
          RAISE EXCEPTION TYPE  cx_ai_system_fault EXPORTING errortext = 'Wrong Input Parameters'.
        ENDIF.
      ELSEIF p_idoc EQ 'X'.
        IF p_mestyp IS INITIAL OR p_rcvprn IS INITIAL OR p_sndprn IS INITIAL OR p_rcvpor IS INITIAL.
          RAISE EXCEPTION TYPE  cx_ai_system_fault EXPORTING errortext = 'Wrong Input Parameters'.
        ENDIF.
      ENDIF.
      l_rfcsnd = p_rfcsnd.
      l_rfcrcv = p_rfcrcv.
      l_obname = p_obname.
      l_ibname = p_ibname.
*Verify Sender RFC Destination
      lw_dest-rfcdest = p_rfcsnd.
      APPEND lw_dest TO lt_dest.
      CALL FUNCTION 'RFC_WALK_THRU_TEST'
        EXPORTING
          test_in      = l_test_in
        TABLES
          destinations = lt_dest
          log          = lt_log.
      READ TABLE lt_log INDEX 1 INTO lw_log.
      IF lw_log-rfclog <> 'o.k.'.
        l_err_txt = lw_log-rfclog.
        RAISE EXCEPTION TYPE  cx_ai_system_fault EXPORTING errortext = l_err_txt.
      ENDIF.
      CLEAR: lw_dest, lw_log, lt_log, lt_dest.
*Verify Receiver RFC Destination
      lw_dest-rfcdest = p_rfcrcv.
      APPEND lw_dest TO lt_dest.
      CALL FUNCTION 'RFC_WALK_THRU_TEST'
        EXPORTING
          test_in      = l_test_in
        TABLES
          destinations = lt_dest
          log          = lt_log.
      READ TABLE lt_log INDEX 1 INTO lw_log.
      IF lw_log-rfclog <> 'o.k.'.
        l_err_txt = lw_log-rfclog.
        RAISE EXCEPTION TYPE  cx_ai_system_fault EXPORTING errortext = l_err_txt.
      ENDIF.
*
* The following Function Module must be implemented to check  
* if data related to flow are blocked or not yet verified
*
*Check if data processing was fine during last run
**      CALL FUNCTION 'Z_CHECKOPEN_FLOW_DE' DESTINATION p_rfcrcv
**        EXPORTING
**          ob_system = p_obsyst
**          ob_name   = p_obname
**          ib_system = p_ibsyst
**          ib_name   = p_ibname
**        IMPORTING
**          flow_open = l_check_flow.
**      IF l_check_flow NE 'N'.
**        RAISE EXCEPTION TYPE  cx_ai_system_fault EXPORTING errortext = 'Open Flow Error on target system'.
**      ENDIF.
*Set starting time
      l_start_time = sy-uzeit.
*PROXY processing
      IF p_proxy EQ 'X'.
* Activate queue p_qname on sender system
        CALL FUNCTION 'TRFC_QIN_ACTIVATE' DESTINATION p_rfcsnd
          EXPORTING
            qname                      = p_qname
*     MAXLUW                     = 0
*     MODE                       = ' '
*     STARTDATE                  = '00000000'
*     STARTTIME                  = '000000'
           maxtime                    = p_maxtme            
*     NO_EXCEPTION               = ' '
*     SCHEDULER                  = ' '
*     USERDEST                   = ' '
*     NRETRY                     = 30
*     TDELAY                     = 300
        IMPORTING
           exeluw                     = l_exeluw
*           astate                     = l_astate       
        EXCEPTIONS
             invalid_parameter          = 1
             system_failed              = 2
             communication_failed       = 3
             OTHERS                     = 4
                  .
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO l_err_txt.
          RAISE EXCEPTION TYPE  cx_ai_system_fault EXPORTING errortext = l_err_txt.
        ENDIF.
        l_nummsg = l_exeluw.
*IDOC Processing
      ELSEIF p_idoc EQ 'X'.
*Dispatch IDocs on sender system
        CALL FUNCTION 'Z_IDOC_CONTROLM' DESTINATION p_rfcsnd
          EXPORTING
            mestyp    = p_mestyp
            rcvprn    = p_rcvprn
            sndprn    = p_sndprn
            rcvpor    = p_rcvpor
          IMPORTING
            num_idocs = l_exeidoc.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO l_err_txt.
          RAISE EXCEPTION TYPE  cx_ai_system_fault EXPORTING errortext = l_err_txt.
        ENDIF.
        l_nummsg = l_exeidoc.
      ENDIF.
*Send number of messages sent to remote system
      IF l_nummsg > 0.
 
*
* The following Function Module must be implemented to
* update flow check for related flow  
*
**        CALL FUNCTION 'Z_XICNTM_MSG_IN_DE' DESTINATION p_rfcrcv
**          EXPORTING
**            ob_system  = p_obsyst
**            ob_name    = p_obname
**            date_start = sy-datum
**            time_start = l_start_time
**            nrmsg_in   = l_nummsg
**            ctrlm_end  = p_cm_end
**            ib_system  = p_ibsyst
**            ib_name    = p_ibname
**          IMPORTING
**            UPDATE     = l_result.
        IF l_result NE 'OK'.
          RAISE EXCEPTION TYPE  cx_ai_system_fault EXPORTING errortext = 'Update Flag Error on target system'.
        ENDIF.
        WRITE : / l_nummsg , 'Messages successfully sent from Business system', l_rfcsnd , 'with update status' , l_result.
      ELSE.
        WRITE : / 'No messages found on Business system', l_rfcsnd , 'inside the queue' , p_qname.
      ENDIF.
    CATCH cx_ai_system_fault INTO l_alert_msg.
      PERFORM raise_alert USING l_alert_msg->errortext.
  ENDTRY.
*&---------------------------------------------------------------------*
*&      Form  RAISE ALERT
*&---------------------------------------------------------------------*
*       Fill table for alert creation
*----------------------------------------------------------------------*
FORM raise_alert USING l_err_txt TYPE string.
  DATA: l_sxms_error_code TYPE char70.
*Change user to generate alert to PIISUSER_<sid>
  CONCATENATE 'PIRWBUSE_' sy-sysid INTO sy-uname.
  CONCATENATE '- Job failed on ' sy-datum ' at ' sy-uzeit ':' l_err_txt INTO l_sxms_error_code RESPECTING BLANKS.
  CONDENSE l_sxms_error_code.
  lw_container-element = 'SXMS_ERROR_CAT'.
  lw_container-value = 'JOB ERROR'.
  lw_container-elemlength = 20.
  lw_container-type ='C'.
  APPEND lw_container TO lt_container.
  lw_container-element = 'SXMS_ERROR_CODE'.
  lw_container-value = l_sxms_error_code.
  lw_container-elemlength = 70.
  lw_container-type ='C'.
  APPEND lw_container TO lt_container.
  lw_container-element = 'SXMS_FROM_SERVICE'.
  lw_container-value = l_rfcsnd.
  lw_container-elemlength = 60.
  lw_container-type ='C'.
  APPEND lw_container TO lt_container.
  lw_container-element = 'SXMS_TO_SERVICE'.
  lw_container-value = l_rfcrcv.
  lw_container-elemlength = 60.
  lw_container-type ='C'.
  APPEND lw_container TO lt_container.
  lw_container-element = 'SXMS_FROM_INTERFACE'.
  lw_container-value = l_obname.
  lw_container-elemlength = 120.
  lw_container-type ='C'.
  APPEND lw_container TO lt_container.
  lw_container-element = 'SXMS_TO_INTERFACE'.
  lw_container-value = l_ibname.
  lw_container-elemlength = 120.
  lw_container-type ='C'.
  APPEND lw_container TO lt_container.

  CALL FUNCTION 'SALERT_CREATE'
        EXPORTING
         ip_cat                       = p_ipcat
*       IP_ALIAS                     =
*       IP_APPLICATION_GUID          =
*       IP_XML_CONTAINER             =
*     IMPORTING
*       EP_ALERT_ID                  =
*       EP_EXT_ALERT_ID              =
        TABLES
          it_container                 = lt_container
        EXCEPTIONS
          alert_category_unknown       = 1
          alert_no_recipients          = 2
          alert_error_unknown          = 3
          OTHERS                       = 4
     .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO l_sxms_error_code.
  ENDIF.
*Generate message to log
  MESSAGE l_sxms_error_code TYPE 'E'.

ENDFORM.                    " FILL_CONTAINER