Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

sending email using ABAP

Former Member
0 Likes
1,864

i have this program which functions in sending XLS attachment email to external address.

but it somehow doesn't send the content messages out.

e.g. i've attached converted data in XLS format and email content appeared as in: "Attached herewith the data requested by user".

The email received but without the content message; the XLS file is attached neatly.

Any idea?

p.s. the FM i'm using is SO_NEW_DOCUMENT_ATT_SEND_API1.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,393

Hi florinda voo ,

Welcome to SDN.

Hope this site helps you a lot.

Here the sample program which can send a mail to the specified members.

REPORT ZSSO_DOCUMENT_SEND_API1.

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

  • Creating the document to be sent

DOC_CHNG-OBJ_NAME = 'OFFER'.

DOC_CHNG-OBJ_DESCR = 'Auction of a Picasso jr'.

OBJTXT = 'Reserve price : $250000'.

APPEND OBJTXT.

OBJTXT = 'Tets mail'.

APPEND OBJTXT.

OBJTXT = 'Tets mail'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creating the entry for the compressed document

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.

  • Creating the document attachment

  • (Assume the data in OBJBIN are given in BMP format)

OBJBIN = ' \O/ '. APPEND OBJBIN.

OBJBIN = ' '. APPEND OBJBIN.

OBJBIN = ' / \ '. APPEND OBJBIN.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

OBJHEAD = 'picasso.bmp'. APPEND OBJHEAD.

  • Creating the entry for the compressed attachment

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'BMP'.

OBJPACK-OBJ_NAME = 'ATTACHMENT'.

OBJPACK-OBJ_DESCR = 'PTets mail'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK..

  • Entering names in the distribution list

*RECLIST-RECEIVER = '[email protected]'.

RECLIST-RECEIVER = '[email protected]'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = '[email protected]'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = 'DLI-NEUREICH'.

RECLIST-REC_TYPE = 'P'.

APPEND RECLIST.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

CASE SY-SUBRC.

WHEN 0.

WRITE: / 'Result of the send process:'.

LOOP AT RECLIST.

WRITE: / RECLIST-RECEIVER(48), ':'.

IF RECLIST-RETRN_CODE = 0.

WRITE 'sent successfully'.

ELSE.

WRITE 'not sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE:

/ 'no authorization to send to the specified number recipients!'.

WHEN 2.

WRITE: / 'document could not be sent to any of the recipient'.

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.

After executing this do the following:

G0 to the transaction : sost

Select the reciver name to whome who want to send the mail.

Then go to : Utilities-->start send/Recieve.

<b>Reward points if it helps you.</b>

Regds,

Rama.Pammi

i have this program which functions in sending XLS attachment email to external address.

but it somehow doesn't send the content messages out.

e.g. i've attached converted data in XLS format and email content appeared as in: "Attached herewith the data requested by user".

The email received but without the content message; the XLS file is attached neatly.

Any idea?

p.s. the FM i'm using is SO_NEW_DOCUMENT_ATT_SEND_API1.

8 REPLIES 8
Read only

Former Member
0 Likes
1,393

Hi Florinda,

Can you paste your code.

Regards,

Atish

Read only

Former Member
0 Likes
1,394

Hi florinda voo ,

Welcome to SDN.

Hope this site helps you a lot.

Here the sample program which can send a mail to the specified members.

REPORT ZSSO_DOCUMENT_SEND_API1.

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

  • Creating the document to be sent

DOC_CHNG-OBJ_NAME = 'OFFER'.

DOC_CHNG-OBJ_DESCR = 'Auction of a Picasso jr'.

OBJTXT = 'Reserve price : $250000'.

APPEND OBJTXT.

OBJTXT = 'Tets mail'.

APPEND OBJTXT.

OBJTXT = 'Tets mail'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creating the entry for the compressed document

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.

  • Creating the document attachment

  • (Assume the data in OBJBIN are given in BMP format)

OBJBIN = ' \O/ '. APPEND OBJBIN.

OBJBIN = ' '. APPEND OBJBIN.

OBJBIN = ' / \ '. APPEND OBJBIN.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

OBJHEAD = 'picasso.bmp'. APPEND OBJHEAD.

  • Creating the entry for the compressed attachment

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'BMP'.

OBJPACK-OBJ_NAME = 'ATTACHMENT'.

OBJPACK-OBJ_DESCR = 'PTets mail'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK..

  • Entering names in the distribution list

*RECLIST-RECEIVER = '[email protected]'.

RECLIST-RECEIVER = '[email protected]'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = '[email protected]'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = 'DLI-NEUREICH'.

RECLIST-REC_TYPE = 'P'.

APPEND RECLIST.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

CASE SY-SUBRC.

WHEN 0.

WRITE: / 'Result of the send process:'.

LOOP AT RECLIST.

WRITE: / RECLIST-RECEIVER(48), ':'.

IF RECLIST-RETRN_CODE = 0.

WRITE 'sent successfully'.

ELSE.

WRITE 'not sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE:

/ 'no authorization to send to the specified number recipients!'.

WHEN 2.

WRITE: / 'document could not be sent to any of the recipient'.

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.

After executing this do the following:

G0 to the transaction : sost

Select the reciver name to whome who want to send the mail.

Then go to : Utilities-->start send/Recieve.

<b>Reward points if it helps you.</b>

Regds,

Rama.Pammi

Read only

Former Member
0 Likes
1,393

<b>Send external email from within ABAP program</b>

<b>please in this use find .xls you can see the logic of formatting in the xls file format of th attach file</b>

The code below demonstrates how to send an email to an external email address([email protected]),where the data is stored within a .xls attachment.

*& Report  ZEMAIL_ATTACH                                               *
*&                                                                     *
*&---------------------------------------------------------------------*
*& Example of sending external email via SAPCONNECT                    *
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT  ZEMAIL_ATTACH                   .
TABLES: ekko.

PARAMETERS: p_email   TYPE somlreci1-receiver
                                  DEFAULT '[email protected]'.

TYPES: BEGIN OF t_ekpo,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
 END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
      wa_ekpo TYPE t_ekpo.

TYPES: BEGIN OF t_charekpo,
  ebeln(10) TYPE c,
  ebelp(5)  TYPE c,
  aedat(8)  TYPE c,
  matnr(18) TYPE c,
 END OF t_charekpo.
DATA: wa_charekpo TYPE t_charekpo.

DATA:   it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                WITH HEADER LINE.
DATA:   it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                WITH HEADER LINE.

DATA:   t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
        t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
        t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
        t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
        t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
        w_cnt TYPE i,
        w_sent_all(1) TYPE c,
        w_doc_data LIKE sodocchgi1,
        gd_error    TYPE sy-subrc,
        gd_reciever TYPE sy-subrc.


************************************************************************
*START_OF_SELECTION
START-OF-SELECTION.
*   Retrieve sample data from table ekpo
  PERFORM data_retrieval.

*   Populate table with detaisl to be entered into .xls file
  PERFORM build_xls_data_table.


************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
* Populate message body text
  perform populate_email_message_body.

* Send file by email as .xls speadsheet
  PERFORM send_file_as_email_attachment
                               tables it_message
                                      it_attach
                                using p_email
                                      'Example .xls documnet attachment'
                                      'XLS'
                                      'filename'
                                      ' '
                                      ' '
                                      ' '
                             changing gd_error
                                      gd_reciever.

*   Instructs mail send program for SAPCONNECT to send email(rsconn01)
  PERFORM initiate_mail_execute_program.


*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
FORM data_retrieval.
  SELECT ebeln ebelp aedat matnr
   UP TO 10 ROWS
    FROM ekpo
    INTO TABLE it_ekpo.
ENDFORM.                    " DATA_RETRIEVAL


*&---------------------------------------------------------------------*
*&      Form  BUILD_XLS_DATA_TABLE
*&---------------------------------------------------------------------*
*       Build data table for .xls document
*----------------------------------------------------------------------*
FORM build_xls_data_table.
  CONSTANTS: con_cret TYPE x VALUE '0D',  "OK for non Unicode
             con_tab TYPE x VALUE '09'.   "OK for non Unicode

*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
*constants:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
*    con_cret type c value cl_abap_char_utilities=>CR_LF.


  CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
         INTO it_attach SEPARATED BY con_tab.
  CONCATENATE con_cret it_attach  INTO it_attach.
  APPEND  it_attach.

  LOOP AT it_ekpo INTO wa_charekpo.
    CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
                wa_charekpo-aedat wa_charekpo-matnr
           INTO it_attach SEPARATED BY con_tab.
    CONCATENATE con_cret it_attach  INTO it_attach.
    APPEND  it_attach.
  ENDLOOP.
ENDFORM.                    " BUILD_XLS_DATA_TABLE


*&---------------------------------------------------------------------*
*&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
*&---------------------------------------------------------------------*
*       Send email
*----------------------------------------------------------------------*
FORM send_file_as_email_attachment tables pit_message
                                          pit_attach
                                    using p_email
                                          p_mtitle
                                          p_format
                                          p_filename
                                          p_attdescription
                                          p_sender_address
                                          p_sender_addres_type
                                 changing p_error
                                          p_reciever.


  DATA: ld_error    TYPE sy-subrc,
        ld_reciever TYPE sy-subrc,
        ld_mtitle LIKE sodocchgi1-obj_descr,
        ld_email LIKE  somlreci1-receiver,
        ld_format TYPE  so_obj_tp ,
        ld_attdescription TYPE  so_obj_nam ,
        ld_attfilename TYPE  so_obj_des ,
        ld_sender_address LIKE  soextreci1-receiver,
        ld_sender_address_type LIKE  soextreci1-adr_typ,
        ld_receiver LIKE  sy-subrc.

  ld_email   = p_email.
  ld_mtitle = p_mtitle.
  ld_format              = p_format.
  ld_attdescription      = p_attdescription.
  ld_attfilename         = p_filename.
  ld_sender_address      = p_sender_address.
  ld_sender_address_type = p_sender_addres_type.


* Fill the document data.
  w_doc_data-doc_size = 1.

* Populate the subject/generic message attributes
  w_doc_data-obj_langu = sy-langu.
  w_doc_data-obj_name  = 'SAPRPT'.
  w_doc_data-obj_descr = ld_mtitle .
  w_doc_data-sensitivty = 'F'.

* Fill the document data and get size of attachment
  CLEAR w_doc_data.
  READ TABLE it_attach INDEX w_cnt.
  w_doc_data-doc_size =
     ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-obj_name   = 'SAPRPT'.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = 'F'.
  CLEAR t_attachment.
  REFRESH t_attachment.
  t_attachment[] = pit_attach[].

* Describe the body of the message
  CLEAR t_packing_list.
  REFRESH t_packing_list.
  t_packing_list-transf_bin = space.
  t_packing_list-head_start = 1.
  t_packing_list-head_num = 0.
  t_packing_list-body_start = 1.
  DESCRIBE TABLE it_message LINES t_packing_list-body_num.
  t_packing_list-doc_type = 'RAW'.
  APPEND t_packing_list.

* Create attachment notification
  t_packing_list-transf_bin = 'X'.
  t_packing_list-head_start = 1.
  t_packing_list-head_num   = 1.
  t_packing_list-body_start = 1.

  DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
  t_packing_list-doc_type   =  ld_format.
  t_packing_list-obj_descr  =  ld_attdescription.
  t_packing_list-obj_name   =  ld_attfilename.
  t_packing_list-doc_size   =  t_packing_list-body_num * 255.
  APPEND t_packing_list.

* Add the recipients email address
  CLEAR t_receivers.
  REFRESH t_receivers.
  t_receivers-receiver = ld_email.
  t_receivers-rec_type = 'U'.
  t_receivers-com_type = 'INT'.
  t_receivers-notif_del = 'X'.
  t_receivers-notif_ndel = 'X'.
  APPEND t_receivers.

  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
       EXPORTING
            document_data              = w_doc_data
            put_in_outbox              = 'X'
            sender_address             = ld_sender_address
            sender_address_type        = ld_sender_address_type
            commit_work                = 'X'
       IMPORTING
            sent_to_all                = w_sent_all
       TABLES
            packing_list               = t_packing_list
            contents_bin               = t_attachment
            contents_txt               = it_message
            receivers                  = t_receivers
       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.

* Populate zerror return code
  ld_error = sy-subrc.

* Populate zreceiver return code
  LOOP AT t_receivers.
    ld_receiver = t_receivers-retrn_code.
  ENDLOOP.
ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
*&---------------------------------------------------------------------*
*       Instructs mail send program for SAPCONNECT to send email.
*----------------------------------------------------------------------*
FORM initiate_mail_execute_program.
  WAIT UP TO 2 SECONDS.
  SUBMIT rsconn01 WITH mode = 'INT'
                WITH output = 'X'
                AND RETURN.
ENDFORM.                    " INITIATE_MAIL_EXECUTE_PROGRAM


*&---------------------------------------------------------------------*
*&      Form  POPULATE_EMAIL_MESSAGE_BODY
*&---------------------------------------------------------------------*
*        Populate message body text
*----------------------------------------------------------------------*
form populate_email_message_body.
  REFRESH it_message.
  it_message = 'Please find attached a list test ekpo records'.
  APPEND it_message.
endform.                    " POPULATE_EMAIL_MESSAGE_BODY

reward points if it is usefull ....

Girish

Read only

Former Member
0 Likes
1,393

Hai try this code to clear ur doubt.

Don't forget to reward if found helpfull.

Regards,

Rakesh.


  CLASS cl_abap_char_utilities DEFINITION LOAD.
  CONSTANTS:
  con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
  con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.


  TYPES: BEGIN OF typ_item,
         asno(10) TYPE c,
         matnr TYPE mseg-matnr,
         maktx TYPE makt-maktx,
         menge TYPE mseg-menge,
         meins TYPE mseg-meins,
         END OF typ_item.

  DATA: wrk_menge(17) TYPE c.
  DATA: sum_srno TYPE i VALUE 0.
  DATA: wrk_srno TYPE n.

*Internal tables
*----------------------------------------------------------------------*
  DATA: it_std_objhdr  TYPE TABLE OF solisti1.
  DATA: it_std_objcnt  TYPE TABLE OF solisti1.
  DATA: it_std_rcvlst  TYPE TABLE OF somlreci1.
  DATA: it_std_objtxt  TYPE TABLE OF solisti1..
  DATA: it_std_objpack TYPE TABLE OF sopcklsti1 .
  DATA: it_std_cntbin  TYPE TABLE OF solisti1.

  DATA: it_std_items TYPE TABLE OF typ_item.
  DATA: is_items LIKE LINE OF it_std_items.
*  DATA: it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE.
*  DATA: wa_attachment TYPE solisti1.

* Internal structures
*----------------------------------------------------------------------*
  DATA: is_docdata LIKE sodocchgi1.
  DATA: is_objhdr  LIKE LINE OF it_std_objhdr.
  DATA: is_objcnt  LIKE LINE OF it_std_objcnt.
  DATA: is_rcvlst  LIKE LINE OF it_std_rcvlst.
  DATA: is_objtxt  LIKE LINE OF it_std_objtxt.
  DATA: is_objpack LIKE LINE OF it_std_objpack.
  DATA: is_cntbin  LIKE LINE OF it_std_cntbin.


*Work variables
*----------------------------------------------------------------------*
  DATA: wrk_lines TYPE i.




  is_docdata-obj_descr = 'Movement of parts to processor'.



*Cover letter of the mail
  is_objtxt = 'Dear Sir,'.
  APPEND is_objtxt TO it_std_objtxt.

  is_objtxt = ' '.
  APPEND is_objtxt TO it_std_objtxt.


  is_objtxt = text-001.
  APPEND is_objtxt TO it_std_objtxt.


  is_objtxt = text-002.
  APPEND is_objtxt TO it_std_objtxt.

  is_objtxt = text-003.
  APPEND is_objtxt TO it_std_objtxt.

  is_objtxt = ' '.
  APPEND is_objtxt TO it_std_objtxt.

  is_objtxt = 'Thanks n Regards,'.
  APPEND is_objtxt TO it_std_objtxt.

  is_objtxt = ' '.
  APPEND is_objtxt TO it_std_objtxt.

  is_objtxt = 'EICHER MOTORS'.
  APPEND is_objtxt TO it_std_objtxt.


* Write Packing List (Main)

  DESCRIBE TABLE it_std_objtxt LINES wrk_lines.
  READ TABLE it_std_objtxt INTO is_objtxt INDEX wrk_lines.

  is_docdata-doc_size = ( wrk_lines - 1 ) * 255 + STRLEN( is_objtxt ).


  CLEAR is_objpack-transf_bin.

  is_objpack-head_start = 1.
  is_objpack-head_num   = 0.
  is_objpack-body_start = 1.
  is_objpack-body_num   = wrk_lines.
  is_objpack-doc_type   = 'RAW'.

  APPEND is_objpack TO it_std_objpack.

  BREAK-POINT.
*---------------------------------
*loop for selecting the data into contents bin//// Excel.
  CONCATENATE 'SRNO' 'ASN no:' 'PARTNO' 'PART DESCRIPTION'
              'QUANTITY' 'UNIT' INTO is_cntbin
  SEPARATED BY con_tab.

  CONCATENATE con_cret is_cntbin INTO is_cntbin.
  APPEND is_cntbin TO it_std_cntbin.

  LOOP AT it_std_items INTO is_items.

    sum_srno = sum_srno + 1.

    wrk_menge = is_items-menge.
    wrk_srno  = sum_srno.

    CONCATENATE wrk_srno is_items-asno is_items-matnr is_items-maktx
    wrk_menge is_items-meins
    INTO is_cntbin SEPARATED BY con_tab.

    CONCATENATE con_cret is_cntbin INTO is_cntbin.
    APPEND is_cntbin TO it_std_cntbin.
  ENDLOOP.



*--------------------------------







  DESCRIBE TABLE it_std_cntbin LINES wrk_lines.

  READ TABLE it_std_cntbin INTO is_cntbin INDEX wrk_lines.

  is_objpack-doc_size   = ( wrk_lines - 1 ) * 255 +
                           STRLEN( is_cntbin ).


  is_objpack-transf_bin = 'X'.
  is_objpack-head_start = 1.
  is_objpack-head_num   = 0.
  is_objpack-body_start = 1.
  is_objpack-body_num   = wrk_lines.
  is_objpack-doc_type   = 'XLS'.

  is_objpack-obj_name   = 'Document File'.
  is_objpack-obj_descr  = 'Document File'.

  APPEND is_objpack TO it_std_objpack.



*Start of testing code
  IF sy-uname = 'DEVELOPER'.

    is_rcvlst-receiver = sy-uname.
    is_rcvlst-rec_type = 'B'.
    is_rcvlst-express  = 'X'.

    APPEND is_rcvlst TO it_std_rcvlst.

    CLEAR is_rcvlst.

  ENDIF.
*End of testing code



*Creating the recepient list
  is_rcvlst-receiver = '[email protected]'.
  is_rcvlst-rec_type = 'U'.
  is_rcvlst-express  = 'X'.
  is_rcvlst-com_type = 'INT'.
  APPEND is_rcvlst TO it_std_rcvlst.


  is_rcvlst-receiver = '[email protected]'.
  is_rcvlst-copy     = 'X'.
  is_rcvlst-rec_type = 'U'.
  is_rcvlst-express  = 'X'.
  is_rcvlst-com_type = 'INT'.
  APPEND is_rcvlst TO it_std_rcvlst.






  BREAK-POINT.

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data                    = is_docdata
   put_in_outbox                    = 'X'
   commit_work                      = 'X'
* IMPORTING
*   SENT_TO_ALL                      =
*   NEW_OBJECT_ID                    =
    TABLES
      packing_list                     = it_std_objpack
*   OBJECT_HEADER                    =
   contents_bin                     = it_std_cntbin
   contents_txt                     = it_std_objtxt
*   CONTENTS_HEX                     =
*   OBJECT_PARA                      =
*   OBJECT_PARB                      =
      receivers                        = it_std_rcvlst
* 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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


  COMMIT WORK.

Message was edited by:

RAKESH S R

Message was edited by:

RAKESH S R

Read only

Former Member
0 Likes
1,393

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

  • Creating the document to be sent

DOC_CHNG-OBJ_NAME = 'OFFER'.

DOC_CHNG-OBJ_DESCR = 'Auction of a Picasso jr'.

OBJTXT = 'Reserve price : $250000'.

APPEND OBJTXT.

OBJTXT = 'A reproduction of the painting to be auctioned'.

APPEND OBJTXT.

OBJTXT = 'is enclosed as an attachment.'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creating the entry for the compressed document

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.

  • Creating the document attachment

  • (Assume the data in OBJBIN are given in BMP format)

OBJBIN = ' \O/ '. APPEND OBJBIN.

OBJBIN = ' '. APPEND OBJBIN.

OBJBIN = ' / \ '. APPEND OBJBIN.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

OBJHEAD = 'picasso.bmp'. APPEND OBJHEAD.

  • Creating the entry for the compressed attachment

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'BMP'.

OBJPACK-OBJ_NAME = 'ATTACHMENT'.

OBJPACK-OBJ_DESCR = 'Reproduction object 138'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK..

  • Entering names in the distribution list

RECLIST-RECEIVER = '[email protected]'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = 'DLI-NEUREICH'.

RECLIST-REC_TYPE = 'P'.

APPEND RECLIST.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

CASE SY-SUBRC.

WHEN 0.

WRITE: / 'Result of the send process:'.

LOOP AT RECLIST.

WRITE: / RECLIST-RECEIVER(48), ':'.

IF RECLIST-RETRN_CODE = 0.

WRITE 'sent successfully'.

ELSE.

WRITE 'not sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE:

/ 'no authorization to send to the specified number recipients!'.

WHEN 2.

WRITE: / 'document could not be sent to any of the recipient'.

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.

Why don't you type the content in the code itself and then send the mail. After executing the code, go to transaction SOST and then select the mail and press Ctrl+F7.

Regards,

Pavan P.

Read only

0 Likes
1,393

Dear Pavan...

thanks for the code..

i already implemented and try to sent to my office mail but this error is comes up..

what can i do to fix it? is there another configuration that i must done ?

thanks for ur help..

this is the message captured from SAP R/3 :

Cannot process message, no route from SH-SASMITO to [email protected]

Message no. XS826

Diagnosis

To continue processing, the system requires a valid route from sender SH-SASMITO to recipient [email protected] (type INT).

System response

The action was terminated.

Error occurred in R/3 in SAPconnect

Procedure

If this error was generated within R/3 by SAPconnect, you have the following options:

Create a route (i.e. assign a suitable address area, which covers the above address, to a node).

1. Check whether the route exists, but the node to which it is assigned is not in operation. If this is the case, change the route or put the node into operation.

2. Change the recipient address if it has been entered incorrectly.

If the error was detected outside of R/3, please read the operator's manual for your communication software or contact the manufacturer.

Read only

Former Member
0 Likes
1,393

Hi,

Here's the code:-

REPORT  Z_EMAIL_XLS5.

DATA: it_t001 LIKE t001 OCCURS 0 WITH HEADER LINE.
DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
DATA: doc_chng LIKE sodocchgi1.
DATA: tab_lines LIKE sy-tabix.

doc_chng-obj_name = 'SENDFILE'.
doc_chng-obj_descr = 'Company Details'.

select * from t001 into table it_t001.

LOOP AT it_t001.
  CONCATENATE it_t001-bukrs it_t001-butxt INTO objtxt.
  APPEND objtxt.
ENDLOOP.

DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
doc_chng-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 = 'XLS'.
APPEND objpack.

CLEAR reclist.
reclist-receiver = '[email protected]'.
reclist-rec_type = 'U'.
reclist-com_type = 'INT'.
reclist-copy = 'X'.
APPEND reclist.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
  document_data = doc_chng
  put_in_outbox = 'X'
TABLES
  packing_list = objpack
*  object_header = objhead
*  contents_bin = objtxt
  contents_txt = objtxt
  receivers = reclist
EXCEPTIONS
  too_many_receivers = 1
  document_not_sent = 2
  operation_no_authorization = 4
  OTHERS = 99.

CASE sy-subrc.
WHEN 0.
  WRITE: / 'Result of the send process:'.
*   LOOP AT reclist.
  IF reclist-retrn_code = 0.
    commit work.
    message s208(00) with 'Email has been sent.'.
  ELSE.
    message e208(00) with 'Email has not been sent.'.
  ENDIF.
*   ENDLOOP.
WHEN 1.
  message e208(00) with 'No authorization to send to that number of recipients.'.
WHEN 2.
  message e208(00) with 'Document could not be sent to any recipient.'.
WHEN 4.
  message e208(00) with 'No send authorization.'.
WHEN OTHERS.
  message e208(00) with 'Error occurred while sending.'.
ENDCASE.

Read only

0 Likes
1,393

Hi,

Just look at this piece of code from Rakesh

*----


*loop for selecting the data into contents bin//// Excel.

CONCATENATE 'SRNO' 'ASN no:' 'PARTNO' 'PART DESCRIPTION'

'QUANTITY' 'UNIT' INTO is_cntbin

SEPARATED BY con_tab.

CONCATENATE con_cret is_cntbin INTO is_cntbin.

APPEND is_cntbin TO it_std_cntbin.

LOOP AT it_std_items INTO is_items.

sum_srno = sum_srno + 1.

wrk_menge = is_items-menge.

wrk_srno = sum_srno.

CONCATENATE wrk_srno is_items-asno is_items-matnr is_items-maktx

wrk_menge is_items-meins

INTO is_cntbin SEPARATED BY con_tab.

CONCATENATE con_cret is_cntbin INTO is_cntbin.

APPEND is_cntbin TO it_std_cntbin.

ENDLOOP.

*----


Regards,

Atish