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

Introduction: This prog will help to send multiple attachment in XL format through e_mail

Error rendering macro 'code': Invalid value specified for parameter 'lang'
*----Report  zkc_mail
*----Programmer: Krishna Chauhan (Sparta Consulting)
*----Date: 04 Mar 2009
REPORT  ZKC_MAIL MESSAGE-ID ZP.
DATA: BEGIN OF IT_MARC1 OCCURS 0,
        MATNR LIKE MARC-MATNR,
        WERKS LIKE MARC-WERKS,
        PSTAT LIKE MARC-PSTAT,
        LVORM LIKE MARC-LVORM.
DATA: END OF IT_MARC1.
DATA: BEGIN OF IT_MARC2 OCCURS 0,
        MATNR LIKE MARC-MATNR,
        WERKS LIKE MARC-WERKS,
        PSTAT LIKE MARC-PSTAT,
        LVORM LIKE MARC-LVORM.
DATA: END OF IT_MARC2.
DATA: BEGIN OF IT_MARC3 OCCURS 0,
        MATNR LIKE MARC-MATNR,
        WERKS LIKE MARC-WERKS,
        PSTAT LIKE MARC-PSTAT,
        LVORM LIKE MARC-LVORM.
DATA: END OF IT_MARC3.
*&---------------------------------------------------------------------*
*&DATA DECLARATION
*&---------------------------------------------------------------------*
CLASS: CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.
DATA: DOCDATA LIKE SODOCCHGI1,
      OBJPACK LIKE SOPCKLSTI1 OCCURS 1 WITH HEADER LINE,      " internal tables declared for sending attachments to the mail
      OBJTXT 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: N TYPE I.
**********INITIALIZATION********************************************
INITIALIZATION.
*
*******At-selection-screens*****************************************
AT SELECTION-SCREEN.
*
***********************************************************************
* Start of selection event
************************************************************************
START-OF-SELECTION.
*---internal table for first attachment
  SELECT MATNR WERKS PSTAT LVORM FROM MARC
  INTO TABLE IT_MARC1 WHERE MATNR = '000000000001013225'
  AND WERKS = '4065'.
*---internal table for second attachment
  SELECT MATNR WERKS PSTAT LVORM FROM MARC
  INTO TABLE IT_MARC2 WHERE  MATNR = '000000000001013228'
  AND WERKS = '4065'.
*---internal table for third attachment
  SELECT MATNR WERKS PSTAT LVORM FROM MARC
  INTO TABLE IT_MARC3 WHERE  MATNR = '000000000001013232'
  AND WERKS = '4065'.
  PERFORM POPULATE_TABLES.
*&--------------------------------------------------------------------*
* subroutine created for processing and sending the attachments to mail id.
*---------------------------------------------------------------------*
  PERFORM PROCESS_EMAIL.
END-OF-SELECTION.
***********************************************************************
* End of selection event
************************************************************************
*&--------------------------------------------------------------------*
*&      Form  process_email
*&--------------------------------------------------------------------*
* subroutine created for processing and sending the attachments to mail id.
*---------------------------------------------------------------------*
FORM PROCESS_EMAIL.
***********************************************************************
*Body
***********************************************************************
  DOCDATA-OBJ_NAME = 'Mail_Excel_File'.
  DOCDATA-OBJ_DESCR = 'Employee data for Image Opting'.
  OBJTXT = 'Please the message to be displayed on the body of mail'.
  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
***********************************************************************
  N = 1.                                    "for sending 1st attachment
  DESCRIBE TABLE IT_MARC1 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 = 'Opt In Employees'.
  APPEND OBJPACK.
  N = N + TAB_LINES.                       "for sending 2nd attachment
  DESCRIBE TABLE IT_MARC2 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 = 'Opt Out Employees'.
  APPEND OBJPACK.
  N = N + TAB_LINES.                       "for sending 3rd attachment
  DESCRIBE TABLE IT_MARC3 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_Attachment3'.
  OBJPACK-OBJ_DESCR = 'Total Opt In/Out Employees'.
  APPEND OBJPACK.
***********************************************************************
*Create the list of recipients
***********************************************************************
  RECLIST-RECEIVER = 'abc@yahoo.com'.   "e_mail address
  RECLIST-REC_TYPE = 'U'.
  RECLIST-EXPRESS = 'X'.
  APPEND RECLIST.
***********************************************************************
*Send the e-mail by using this function module
***********************************************************************
  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.
  IF SY-SUBRC = 0.
    MESSAGE S000 WITH 'Email succesfully delivered'.
  ELSE.
    MESSAGE S000 WITH 'Error while sending email'.
  ENDIF.
ENDFORM.                    "process_email
*&---------------------------------------------------------------------*
*&      Form  POPULATE_TABLES
*&---------------------------------------------------------------------*
FORM POPULATE_TABLES .
  CLEAR: IT_MARC1, IT_MARC2, IT_MARC3.
*---inserting  header into internal tables
  IT_MARC1-MATNR  = 'Material No'.
  IT_MARC1-WERKS  = 'Plant'.
  IT_MARC1-PSTAT  = 'Pstat'.
  IT_MARC1-LVORM  = 'Lvorm'.
  INSERT IT_MARC1 INDEX 1.
  LOOP AT IT_MARC1.
    CONCATENATE IT_MARC1-MATNR IT_MARC1-WERKS IT_MARC1-PSTAT IT_MARC1-LVORM
    INTO OBJBIN_FINAL SEPARATED BY C_TAB.
    CONCATENATE C_RET OBJBIN_FINAL INTO OBJBIN_FINAL.
    APPEND OBJBIN_FINAL.
  ENDLOOP.
*---inserting  header into internal tables
  IT_MARC2-MATNR  = 'Material No'.
  IT_MARC2-WERKS  = 'Plant'.
  IT_MARC2-PSTAT  = 'Pstat'.
  IT_MARC2-LVORM  = 'Lvorm'.
  INSERT IT_MARC2 INDEX 1.
  LOOP AT IT_MARC2.
    CONCATENATE IT_MARC2-MATNR IT_MARC2-WERKS IT_MARC2-PSTAT IT_MARC2-LVORM
    INTO OBJBIN_FINAL SEPARATED BY C_TAB.
    CONCATENATE C_RET OBJBIN_FINAL INTO OBJBIN_FINAL.
    APPEND OBJBIN_FINAL.
  ENDLOOP.
*---inserting  header into internal tables
  IT_MARC3-MATNR  = 'Material No'.
  IT_MARC3-WERKS  = 'Plant'.
  IT_MARC3-PSTAT  = 'Pstat'.
  IT_MARC3-LVORM  = 'Lvorm'.
  INSERT IT_MARC3 INDEX 1.
  LOOP AT IT_MARC3.
    CONCATENATE IT_MARC3-MATNR IT_MARC3-WERKS IT_MARC3-PSTAT IT_MARC3-LVORM
    INTO OBJBIN_FINAL SEPARATED BY C_TAB.
    CONCATENATE C_RET OBJBIN_FINAL INTO OBJBIN_FINAL.
    APPEND OBJBIN_FINAL.
  ENDLOOP.
ENDFORM.                    " POPULATE_TABLES

1 Comment

  1. Guest

    i give syntax error which is the type cl_abap_char_utilities is unknown