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

Mailing in SAP



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces | Интерфейсы
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Mon Sep 10, 2007 8:20 pm    Post subject: Mailing in SAP Reply with quote

Z_IDOC_INPUT_ALEAUD Code

Code:
FUNCTION Z_IDOC_INPUT_ALEAUD.
*"----------------------------------------------------------------------
*"*"Local interface:
*"       IMPORTING
*"             VALUE(INPUT_METHOD) LIKE  BDWFAP_PAR-INPUTMETHD
*"             VALUE(MASS_PROCESSING) LIKE  BDWFAP_PAR-MASS_PROC
*"       EXPORTING
*"             VALUE(WORKFLOW_RESULT) LIKE  BDWF_PARAM-RESULT
*"             VALUE(APPLICATION_VARIABLE) LIKE  BDWF_PARAM-APPL_VAR
*"             VALUE(IN_UPDATE_TASK) LIKE  BDWFAP_PAR-UPDATETASK
*"             VALUE(CALL_TRANSACTION_DONE) LIKE  BDWFAP_PAR-CALLTRANS
*"       TABLES
*"              IDOC_CONTRL STRUCTURE  EDIDC
*"              IDOC_DATA STRUCTURE  EDIDD
*"              IDOC_STATUS STRUCTURE  BDIDOCSTAT
*"              RETURN_VARIABLES STRUCTURE  BDWFRETVAR
*"              SERIALIZATION_INFO STRUCTURE  BDI_SER
*"       EXCEPTIONS
*"              WRONG_FUNCTION_CALLED
*"----------------------------------------------------------------------

  DATA: T_IDOC_CONTROL LIKE EDIDC OCCURS 0 WITH HEADER LINE,
        T_IDOC_DATA LIKE EDIDD OCCURS 0 WITH HEADER LINE,
        T_ALE_ERR LIKE ALE_ERR_MESSAGE OCCURS 0 WITH HEADER LINE,
        X_OBJCONT LIKE SOLI OCCURS 0 WITH HEADER LINE,
        X_OBJHEAD LIKE SOLI OCCURS 0 WITH HEADER LINE,
        RAW_HEAD LIKE SORH OCCURS 0 WITH HEADER LINE,
        X_RECEIVERS LIKE SOOS1 OCCURS 0 WITH HEADER LINE.

  DATA: W_E1ADHDR LIKE E1ADHDR,
        W_E1STATE LIKE E1STATE,
        W_E1PRTOB LIKE E1PRTOB,
        X_OBJECT_HD_CHANGE LIKE SOOD1,
        RECEIVING_SYSTEM LIKE EDIDC-SNDPRN,
        SENDING_SYSTEM   LIKE EDIDC-RCVPRN,
        H_TEXT        LIKE SOOD1-OBJDES,
        FOLDER_NAME   LIKE SOS06-S_FOLNAM,
        SUBRC         LIKE SY-SUBRC,
        GLOBAL_SUBRC  LIKE SY-SUBRC,
        X_OBJECT_TYPE LIKE SOOD-OBJTP.

  T_IDOC_CONTROL[] = IDOC_CONTRL[].
  T_IDOC_DATA[] = IDOC_DATA[].

  READ TABLE T_IDOC_CONTROL INDEX 1.
  RECEIVING_SYSTEM = T_IDOC_CONTROL-SNDPRN.
  SENDING_SYSTEM = T_IDOC_CONTROL-RCVPRN.
  GLOBAL_SUBRC = 0.

  LOOP AT T_IDOC_DATA.
    CASE T_IDOC_DATA-SEGNAM.
      WHEN 'E1ADHDR'.
        IF ZTAUD-MESTYP <> SPACE AND NOT T_ALE_ERR[] IS INITIAL.
*         send SAP mail
          CLEAR SUBRC.
          PERFORM SEND_SAP_MAIL
                                TABLES T_ALE_ERR
                                 USING RECEIVING_SYSTEM
                                       SENDING_SYSTEM
                                       ZTAUD
                                       SUBRC.
          IF SUBRC <> 0.
            GLOBAL_SUBRC = SUBRC.
            IDOC_STATUS-DOCNUM = T_IDOC_CONTROL-DOCNUM.
            IDOC_STATUS-STATUS = '51'.
            IDOC_STATUS-MSGTY = 'E'.
            IDOC_STATUS-MSGID = 'B1'.
            IDOC_STATUS-MSGNO = '999'.
            IDOC_STATUS-MSGV1 = TEXT-013.
            IDOC_STATUS-MSGV2 = ZTAUD-MESTYP.
            IDOC_STATUS-MSGV3 = 'SO_OBJECT_SEND RC ='.
            IDOC_STATUS-MSGV4 = SUBRC.
            APPEND IDOC_STATUS.
          ENDIF.
          CLEAR T_ALE_ERR.
          REFRESH T_ALE_ERR.
        ENDIF.

        W_E1ADHDR = T_IDOC_DATA-SDATA.
        CLEAR ZTAUD.
        SELECT SINGLE * FROM ZTAUD WHERE MESTYP = W_E1ADHDR-MESTYP.

      WHEN 'E1STATE'.
        IF ZTAUD-MESTYP = SPACE.
          CONTINUE.
        ELSE.
          W_E1STATE = T_IDOC_DATA-SDATA.
          CLEAR T_ALE_ERR.
          IF    W_E1STATE-STATUS = '51'
             OR W_E1STATE-STATUS = '56'
             OR W_E1STATE-STATUS = '61'
             OR W_E1STATE-STATUS = '63'
             OR W_E1STATE-STATUS = '65'
             OR W_E1STATE-STATUS = '60'.
            T_ALE_ERR-STATUS = W_E1STATE-STATUS.
            T_ALE_ERR-DOCNUMSND = W_E1STATE-DOCNUM.
          ENDIF.
        ENDIF.

      WHEN 'E1PRTOB'.
        IF ZTAUD-MESTYP = SPACE.
          CONTINUE.
        ELSE.
          IF T_ALE_ERR-STATUS = SPACE.
            CONTINUE.
          ELSE.
            W_E1PRTOB = T_IDOC_DATA-SDATA.
            T_ALE_ERR-DOCNUMRCV = W_E1PRTOB-DOCNUM.
            APPEND T_ALE_ERR.
            CLEAR T_ALE_ERR.
          ENDIF.
        ENDIF.
    ENDCASE.
  ENDLOOP.

  IF ZTAUD-MESTYP <> SPACE AND NOT T_ALE_ERR[] IS INITIAL.
*   send SAP mail
    CLEAR SUBRC.
    PERFORM SEND_SAP_MAIL
                          TABLES T_ALE_ERR
                           USING RECEIVING_SYSTEM
                                 SENDING_SYSTEM
                                 ZTAUD
                                 SUBRC.
    IF SUBRC <> 0.
      GLOBAL_SUBRC = SUBRC.
      IDOC_STATUS-DOCNUM = T_IDOC_CONTROL-DOCNUM.
      IDOC_STATUS-STATUS = '51'.
      IDOC_STATUS-MSGTY = 'E'.
      IDOC_STATUS-MSGID = 'B1'.
      IDOC_STATUS-MSGNO = '999'.
      IDOC_STATUS-MSGV1 = TEXT-013.
      IDOC_STATUS-MSGV2 = ZTAUD-MESTYP.
      IDOC_STATUS-MSGV3 = 'SO_OBJECT_SEND RC ='.
      IDOC_STATUS-MSGV4 = SUBRC.
      APPEND IDOC_STATUS.
    ENDIF.
    CLEAR T_ALE_ERR.
    REFRESH T_ALE_ERR.
  ENDIF.

  IF GLOBAL_SUBRC <> 0.
    WORKFLOW_RESULT = 99999.
    RETURN_VARIABLES-DOC_NUMBER = T_IDOC_CONTROL-DOCNUM.
    RETURN_VARIABLES-WF_PARAM = 'Error_IDOCs'.
    APPEND RETURN_VARIABLES.
  ELSE.
    WORKFLOW_RESULT = 0.
    CLEAR IDOC_STATUS.
    IDOC_STATUS-DOCNUM = T_IDOC_CONTROL-DOCNUM.
    IDOC_STATUS-STATUS = '53'.
    IDOC_STATUS-MSGTY = 'E'.
    IDOC_STATUS-MSGID = 'B1'.
    IDOC_STATUS-MSGNO = '999'.
    IDOC_STATUS-MSGV1 = TEXT-014.
    APPEND IDOC_STATUS.
    CLEAR RETURN_VARIABLES.
    RETURN_VARIABLES-WF_PARAM = 'Processed_IDOCs'.
    RETURN_VARIABLES-DOC_NUMBER = T_IDOC_CONTROL-DOCNUM.
    APPEND RETURN_VARIABLES.
  ENDIF.
ENDFUNCTION.


Appendix II (LZALAF01 Code)
Code:

*-------------------------------------------------------------------
***INCLUDE LZALAF01 .
*-------------------------------------------------------------------
*&---------------------------------------------------------------------*
*&      Form  SEND_SAP_MAIL
*&---------------------------------------------------------------------*
FORM SEND_SAP_MAIL
                   TABLES T_ALE_ERR        STRUCTURE ALE_ERR_MESSAGE
                    USING RECEIVING_SYSTEM LIKE EDIDC-SNDPRN
                          SENDING_SYSTEM   LIKE EDIDC-RCVPRN
                          ZTAUD            STRUCTURE ZTAUD
                          SUBRC            LIKE SY-SUBRC.

  DATA: T_ALE_ERR_WA LIKE ALE_ERR_MESSAGE OCCURS 0 WITH HEADER LINE,
        X_OBJCONT LIKE SOLI OCCURS 0 WITH HEADER LINE,
*       x_objhead like soli occurs 0 with header line,
        X_RECEIVERS LIKE SOOS1 OCCURS 0 WITH HEADER LINE.

  DATA:
        X_OBJECT_HD_CHANGE LIKE SOOD1,
        H_TEXT        LIKE SOLI-LINE,
        H_STATUS      LIKE EDIDC-STATUS,
        X_OBJECT_TYPE LIKE SOOD-OBJTP.

  MOVE 'RAW' TO X_OBJECT_TYPE.
  H_TEXT = TEXT-002.
  REPLACE '&' WITH ZTAUD-MESTYP INTO H_TEXT.
  REPLACE '&' WITH RECEIVING_SYSTEM INTO H_TEXT.
  CONDENSE H_TEXT.
  MOVE: SY-LANGU      TO X_OBJECT_HD_CHANGE-OBJLA,
        TEXT-001      TO X_OBJECT_HD_CHANGE-OBJSRT,
        TEXT-001      TO X_OBJECT_HD_CHANGE-OBJNAM,
        H_TEXT        TO X_OBJECT_HD_CHANGE-OBJDES,
        'F'           TO X_OBJECT_HD_CHANGE-OBJSNS.     " Functional

* clear   x_objhead.
* refresh x_objhead.
* move 6 to raw_head-rawsiz.
* move raw_head to x_objhead.
* append x_objhead.
  REFRESH X_OBJCONT.

  CLEAR   X_OBJCONT.
  MOVE H_TEXT TO X_OBJCONT.
  APPEND X_OBJCONT.
  CLEAR   X_OBJCONT.
  APPEND X_OBJCONT.
  SORT T_ALE_ERR.

  LOOP AT T_ALE_ERR.
    IF H_STATUS <> T_ALE_ERR-STATUS.
      IF H_STATUS <> SPACE.
        PERFORM ERROR_REPORT
                             TABLES X_OBJCONT
                                    T_ALE_ERR_WA
                              USING H_STATUS
                                    RECEIVING_SYSTEM
                                    SENDING_SYSTEM.
        CLEAR T_ALE_ERR_WA.
        REFRESH T_ALE_ERR_WA.
      ENDIF.
      H_STATUS = T_ALE_ERR-STATUS.
    ENDIF.
    T_ALE_ERR_WA = T_ALE_ERR.
    APPEND T_ALE_ERR_WA.

  ENDLOOP.
  IF SY-SUBRC = 0.
    PERFORM ERROR_REPORT
                         TABLES X_OBJCONT
                                T_ALE_ERR_WA
                          USING H_STATUS
                                RECEIVING_SYSTEM
                                SENDING_SYSTEM.
    CLEAR T_ALE_ERR_WA.
    REFRESH T_ALE_ERR_WA.
  ENDIF.

  CLEAR   X_RECEIVERS.
  REFRESH X_RECEIVERS.
  MOVE ZTAUD-DLINAM TO X_RECEIVERS-RECNAM. " Distribution list
  MOVE 'X'       TO X_RECEIVERS-SNDEX.
  MOVE 'C'       TO X_RECEIVERS-RECESC.
  APPEND X_RECEIVERS.

  CLEAR: SY-MSGID.
  CALL FUNCTION 'SO_OBJECT_SEND'
       EXPORTING
            OBJECT_HD_CHANGE           =  X_OBJECT_HD_CHANGE
            OBJECT_TYPE                =  X_OBJECT_TYPE
       TABLES
            OBJCONT                    = X_OBJCONT
*           objhead                    = x_objhead
            RECEIVERS                  = X_RECEIVERS
       EXCEPTIONS
            ACTIVE_USER_NOT_EXIST      = 1
            COMMUNICATION_FAILURE      = 2
            COMPONENT_NOT_AVAILABLE    = 3
            FOLDER_NOT_EXIST           = 4
            FOLDER_NO_AUTHORIZATION    = 5
            FORWARDER_NOT_EXIST        = 6
            NOTE_NOT_EXIST             = 7
            OBJECT_NOT_EXIST           = 8
            OBJECT_NOT_SENT            = 9
            OBJECT_NO_AUTHORIZATION    = 10
            OBJECT_TYPE_NOT_EXIST      = 11
            OPERATION_NO_AUTHORIZATION = 12
            OWNER_NOT_EXIST            = 13
            PARAMETER_ERROR            = 14
            SUBSTITUTE_NOT_ACTIVE      = 15
            SUBSTITUTE_NOT_DEFINED     = 16
            SYSTEM_FAILURE             = 17
            TOO_MUCH_RECEIVERS         = 18
            USER_NOT_EXIST             = 19
            X_ERROR                    = 20
            OTHERS                     = 21.

  SUBRC = SY-SUBRC.


ENDFORM.                               " SEND_SAP_MAIL

*&---------------------------------------------------------------------*
*&      Form  ERROR_REPORT
*&---------------------------------------------------------------------*
FORM ERROR_REPORT
                 TABLES X_OBJCONT    STRUCTURE SOLI
                        T_ALE_ERR_WA STRUCTURE ALE_ERR_MESSAGE
                  USING H_STATUS     LIKE EDIDC-STATUS
                        RECEIVING_SYSTEM LIKE EDIDC-SNDPRN
                        SENDING_SYSTEM   LIKE EDIDC-RCVPRN.

  DATA: H_TEXT        LIKE SOLI-LINE,
        H_LINES(5)   TYPE C.

  CLEAR X_OBJCONT.
  APPEND X_OBJCONT.

  CLEAR H_TEXT.
  CASE H_STATUS.
    WHEN '51'.
      H_TEXT = TEXT-004.
    WHEN '56'.
      H_TEXT = TEXT-005.
    WHEN '61'.
      H_TEXT = TEXT-006.
    WHEN '63'.
      H_TEXT = TEXT-007.
    WHEN '65'.
      H_TEXT = TEXT-008.
    WHEN '60'.
      H_TEXT = TEXT-009.
    WHEN OTHERS.
      H_TEXT = H_STATUS.

  ENDCASE.
  CLEAR X_OBJCONT.
  X_OBJCONT = H_TEXT.
  APPEND X_OBJCONT.

  DESCRIBE TABLE T_ALE_ERR_WA LINES H_LINES.

  H_TEXT = TEXT-010.
  REPLACE '&' WITH H_LINES INTO H_TEXT.
  X_OBJCONT = H_TEXT.
  APPEND X_OBJCONT.

  H_TEXT = TEXT-011.
  REPLACE '&' WITH RECEIVING_SYSTEM INTO H_TEXT.
  REPLACE '&' WITH SENDING_SYSTEM INTO H_TEXT.
  X_OBJCONT = H_TEXT.
  APPEND X_OBJCONT.

  LOOP AT T_ALE_ERR_WA.
    H_TEXT = TEXT-012.
    REPLACE '&' WITH T_ALE_ERR_WA-DOCNUMRCV INTO H_TEXT.
    REPLACE '&' WITH T_ALE_ERR_WA-DOCNUMSND INTO H_TEXT.
    X_OBJCONT = H_TEXT.
    APPEND X_OBJCONT.
  ENDLOOP.

ENDFORM.                               " ERROR_REPORT
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 -> Interfaces | Интерфейсы 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.