Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata
Error rendering macro 'code': Invalid value specified for parameter 'lang'
*&---------------------------------------------------------------------*
*& Report  ZBC_ITAB_TO_EXCEL_NEW                                       *
*&                                                                     *
*&---------------------------------------------------------------------*
*&  This dummy code helps in sending 2 internal tables data as two separate attachments
*&   in a single mail id outside sap system
*&---------------------------------------------------------------------*
REPORT  ZBC_ITAB_TO_EXCEL_NEW                   .
CLASS: CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.
DATA: DOCDATA LIKE SODOCCHGI1,
      OBJPACK LIKE SOPCKLSTI1 OCCURS 1 WITH HEADER LINE,
      OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
      OBJBIN1 LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
      OBJBIN2 LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
      OBJBIN_FINAL LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
      RECLIST LIKE SOMLRECI1 OCCURS 1 WITH HEADER LINE,
      TAB_LINES TYPE SY-TABIX.
DATA: GD_SENDER_TYPE LIKE SOEXTRECI1-ADR_TYP.
DATA: C_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
      C_RET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.
DATA: C_DEV TYPE SY-SYSID.
DATA: BEGIN OF I_DATA OCCURS 0,
      A(20),
      B(20),
      END OF I_DATA.
DATA: BEGIN OF ST,
      F1(2) TYPE C,
      F2(2) TYPE N,
      END OF ST.
DATA: ITAB1 LIKE TABLE OF ST WITH HEADER LINE,
      ITAB2 LIKE TABLE OF ST WITH HEADER LINE.
DATA: N TYPE I.
PARAMETER: P_EMAIL1 LIKE SOMLRECI1-RECEIVER
                    DEFAULT 'mansiasnani@yahoo.com',
           P_SENDER LIKE SOMLRECI1-RECEIVER.
START-OF-SELECTION.
  ITAB1-F1 = 'AA'. ITAB1-F2 = '01'. APPEND ITAB1.
  ITAB1-F1 = 'BB'. ITAB1-F2 = '02'. APPEND ITAB1.
  ITAB1-F1 = 'CC'. ITAB1-F2 = '03'. APPEND ITAB1.
  ITAB2-F1 = 'ZZ'. ITAB2-F2 = '26'. APPEND ITAB2.
  ITAB2-F1 = 'YY'. ITAB2-F2 = '25'. APPEND ITAB2.
  LOOP AT ITAB1.
    CONCATENATE ITAB1-F1 ITAB1-F2 INTO OBJBIN1 SEPARATED BY C_TAB.
    CONCATENATE C_RET OBJBIN1 INTO OBJBIN1.
    APPEND OBJBIN1.
  ENDLOOP.
  LOOP AT ITAB2.
    CONCATENATE ITAB2-F1 ITAB2-F2 INTO OBJBIN2 SEPARATED BY C_TAB.
    CONCATENATE C_RET OBJBIN2 INTO OBJBIN2.
    APPEND OBJBIN2.
  ENDLOOP.
  LOOP AT OBJBIN1.
    MOVE OBJBIN1-LINE TO OBJBIN_FINAL-LINE.
    APPEND OBJBIN_FINAL.
  ENDLOOP.
  LOOP AT OBJBIN2.
    MOVE OBJBIN2-LINE TO OBJBIN_FINAL-LINE.
    APPEND OBJBIN_FINAL.
  ENDLOOP.
  PERFORM PROCESS_EMAIL.
  C_DEV = SY-SYSID.
  IF SY-SYSID = C_DEV.
    WAIT UP TO 5 SECONDS.
    SUBMIT RSCONN01 WITH MODE = 'INT'
    WITH OUTPUT = 'X'
    AND RETURN.
  ENDIF.
  IF SY-SUBRC = 0.
    WRITE: / 'Email succesfilly delivered'.
  ELSE.
    WRITE: / 'failure'.
  ENDIF.
*&--------------------------------------------------------------------*
*&      Form  process_email
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM PROCESS_EMAIL.
  IF P_SENDER EQ SPACE.
    GD_SENDER_TYPE = SPACE.
  ELSE.
    GD_SENDER_TYPE = 'INT'.
  ENDIF.
*Body
  DOCDATA-OBJ_NAME = 'Mail_Excel_File'.
  DOCDATA-OBJ_DESCR = 'Excel file attachment'.
  OBJTXT = 'Attached is the sample Excel file'.
  APPEND OBJTXT.
  DESCRIBE TABLE OBJTXT LINES TAB_LINES.
  READ TABLE OBJTXT INDEX TAB_LINES.
  DOCDATA-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
  CLEAR OBJPACK-TRANSF_BIN.
  OBJPACK-HEAD_START = 1.
  OBJPACK-HEAD_NUM = 0.
  OBJPACK-BODY_START = 1.
  OBJPACK-BODY_NUM = TAB_LINES.
  OBJPACK-DOC_TYPE = 'RAW'.
  APPEND OBJPACK.
*Attachment 1
  N = 1.
  DESCRIBE TABLE OBJBIN1 LINES TAB_LINES.
  OBJPACK-DOC_SIZE = TAB_LINES * 255.
  OBJPACK-TRANSF_BIN = 'X'.
  OBJPACK-HEAD_START = 1.
  OBJPACK-HEAD_NUM = 1.
  OBJPACK-BODY_START = N.
  OBJPACK-BODY_NUM = TAB_LINES.
  OBJPACK-DOC_TYPE = 'XLS'.
  DOCDATA-OBJ_NAME = 'Excel_File_Attachment1'.
  OBJPACK-OBJ_DESCR = 'Excel File Attachment1'.
  APPEND OBJPACK.
*Attachment 1
  N = N + TAB_LINES.
  DESCRIBE TABLE OBJBIN2 LINES TAB_LINES.
  OBJPACK-DOC_SIZE = TAB_LINES * 255.
  OBJPACK-TRANSF_BIN = 'X'.
  OBJPACK-HEAD_START = 1.
  OBJPACK-HEAD_NUM = 1.
  OBJPACK-BODY_START = N.
  OBJPACK-BODY_NUM = TAB_LINES.
  OBJPACK-DOC_TYPE = 'XLS'.
  DOCDATA-OBJ_NAME = 'Excel_File_Attachment2'.
  OBJPACK-OBJ_DESCR = 'Excel File Attachment2'.
  APPEND OBJPACK.
*Create the list of recipients
  RECLIST-RECEIVER = P_EMAIL1.
  RECLIST-REC_TYPE = 'U'.
  RECLIST-EXPRESS = 'X'.
  APPEND RECLIST.
*Send the e-mail
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      DOCUMENT_DATA              = DOCDATA
      PUT_IN_OUTBOX              = 'X'
      COMMIT_WORK                = 'X'
    TABLES
      PACKING_LIST               = OBJPACK
      CONTENTS_BIN               = OBJBIN_FINAL
      CONTENTS_TXT               = OBJTXT
      RECEIVERS                  = RECLIST
    EXCEPTIONS
      TOO_MANY_RECEIVERS         = 1
      DOCUMENT_NOT_SENT          = 2
      DOCUMENT_TYPE_NOT_EXIST    = 3
      OPERATION_NO_AUTHORIZATION = 4
      PARAMETER_ERROR            = 5
      X_ERROR                    = 6
      ENQUEUE_ERROR              = 7
      OTHERS                     = 8.
  COMMIT WORK.
ENDFORM.                    "process_email

 

Regrds

Mansi

  • No labels

1 Comment

  1. Former Member

    Very helpful.