Application Development 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: 

How Internal table data send to sap mail as a attachment?

Former Member
0 Kudos
373

Hi,

Can any one please let me know , how we will send internal table data to sap mail.

In my internal table my data output length is more than 255 characters.

Thanks in advance.

1 ACCEPTED SOLUTION

former_member598013
Active Contributor
0 Kudos
86

Hi

Try out the below code:


DATA: ld_mtitle LIKE sodocchgi1-obj_descr,
        ld_format TYPE  so_obj_tp ,
        ld_attdescription TYPE  so_obj_nam ,
        ld_attfilename TYPE  so_obj_des .
*        ld_receiver LIKE  sy-subrc.



  DATA:   it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
          it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
          w_cnt TYPE i,
          w_sent_all(1) TYPE c,                             "#EC NEEDED
          w_doc_data LIKE sodocchgi1.

  REFRESH it_receivers . CLEAR it_receivers .
  IF v_trip_send = 'X'.
    it_receivers-receiver = it_trip_dload-approver_email .
  ELSE .
    it_receivers-receiver = it_adv_dload-approver_email .
  ENDIF.
  it_receivers-rec_type = c_u .
  APPEND it_receivers. CLEAR it_receivers.

*  it_receivers-receiver =            '  <Email ID>               '              "Email address.
  IF v_trip_send = 'X' .
    it_receivers-receiver = it_trip_dload-requester_email .
  ELSE .
    it_receivers-receiver = it_adv_dload-requester_email .
  ENDIF .
  it_receivers-rec_type = c_u .
  it_receivers-copy     = 'X' .
  APPEND it_receivers. CLEAR it_receivers.


  ld_mtitle = p_mtitle.
  ld_format              = p_format.
  ld_attdescription      = p_attdescription.
  ld_attfilename         = p_filename.

* 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  = c_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   = c_saprpt.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = c_f.
  CLEAR it_attachment.
  REFRESH it_attachment.
  it_attachment[] = it_attach[].

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

* Create attachment notification
  it_packing_list-transf_bin = c_x.
  it_packing_list-head_start = 1.
  it_packing_list-head_num   = 1.
  it_packing_list-body_start = 1.

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


  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data = w_doc_data
      put_in_outbox = c_x
      commit_work   = c_x
    IMPORTING
      sent_to_all   = w_sent_all
    TABLES
      packing_list  = it_packing_list
      contents_bin  = it_attachment
      contents_txt  = it_message
      receivers     = it_receivers.


&*********<removed_by_moderator_together_with_6_unmentionables>************&

Edited by: Julius Bussche on Jun 23, 2008 11:04 PM

3 REPLIES 3

former_member598013
Active Contributor
0 Kudos
87

Hi

Try out the below code:


DATA: ld_mtitle LIKE sodocchgi1-obj_descr,
        ld_format TYPE  so_obj_tp ,
        ld_attdescription TYPE  so_obj_nam ,
        ld_attfilename TYPE  so_obj_des .
*        ld_receiver LIKE  sy-subrc.



  DATA:   it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
          it_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
          w_cnt TYPE i,
          w_sent_all(1) TYPE c,                             "#EC NEEDED
          w_doc_data LIKE sodocchgi1.

  REFRESH it_receivers . CLEAR it_receivers .
  IF v_trip_send = 'X'.
    it_receivers-receiver = it_trip_dload-approver_email .
  ELSE .
    it_receivers-receiver = it_adv_dload-approver_email .
  ENDIF.
  it_receivers-rec_type = c_u .
  APPEND it_receivers. CLEAR it_receivers.

*  it_receivers-receiver =            '  <Email ID>               '              "Email address.
  IF v_trip_send = 'X' .
    it_receivers-receiver = it_trip_dload-requester_email .
  ELSE .
    it_receivers-receiver = it_adv_dload-requester_email .
  ENDIF .
  it_receivers-rec_type = c_u .
  it_receivers-copy     = 'X' .
  APPEND it_receivers. CLEAR it_receivers.


  ld_mtitle = p_mtitle.
  ld_format              = p_format.
  ld_attdescription      = p_attdescription.
  ld_attfilename         = p_filename.

* 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  = c_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   = c_saprpt.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = c_f.
  CLEAR it_attachment.
  REFRESH it_attachment.
  it_attachment[] = it_attach[].

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

* Create attachment notification
  it_packing_list-transf_bin = c_x.
  it_packing_list-head_start = 1.
  it_packing_list-head_num   = 1.
  it_packing_list-body_start = 1.

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


  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data = w_doc_data
      put_in_outbox = c_x
      commit_work   = c_x
    IMPORTING
      sent_to_all   = w_sent_all
    TABLES
      packing_list  = it_packing_list
      contents_bin  = it_attachment
      contents_txt  = it_message
      receivers     = it_receivers.


&*********<removed_by_moderator_together_with_6_unmentionables>************&

Edited by: Julius Bussche on Jun 23, 2008 11:04 PM

Former Member
0 Kudos
86

Hi,

report zmail_0003.

data: itcpo like itcpo,
tab_lines like sy-tabix.

    * Variables for EMAIL functionality

data: maildata like sodocchgi1.
data: mailpack like sopcklsti1 occurs 2 with header line.
data: mailhead like solisti1 occurs 1 with header line.
data: mailbin like solisti1 occurs 10 with header line.
data: mailtxt like solisti1 occurs 10 with header line.
data: mailrec like somlrec90 occurs 0 with header line.
data: solisti1 like solisti1 occurs 0 with header line.

perform send_form_via_email.

************************************************************************

    * FORM SEND_FORM_VIA_EMAIL *

************************************************************************
form send_form_via_email.

clear: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.
refresh: mailtxt, mailbin, mailpack, mailhead, mailrec.

    * Creation of the document to be sent File Name

maildata-obj_name = 'TEST'.

    * Mail Subject

maildata-obj_descr = 'Subject'.

    * Mail Contents

mailtxt-line = 'Here is your file'.
append mailtxt.

    * Prepare Packing List

perform prepare_packing_list.

    * Set recipient - email address here!!!

mailrec-receiver = 'email address'.
mailrec-rec_type = 'U'.
append mailrec.

    * Sending the document

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = maildata
put_in_outbox = ' '
tables
packing_list = mailpack
object_header = mailhead
contents_bin = mailbin
contents_txt = mailtxt
receivers = mailrec
exceptions
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
others = 99.

endform.

************************************************************************

    * Form PREPARE_PACKING_LIST

************************************************************************
form prepare_packing_list.

clear: mailpack, mailbin, mailhead.
refresh: mailpack, mailbin, mailhead.

describe table mailtxt lines tab_lines.
read table mailtxt index tab_lines.
maildata-doc_size = ( tab_lines - 1 ) * 255 + strlen( mailtxt ).

    * Creation of the entry for the compressed document

clear mailpack-transf_bin.
mailpack-head_start = 1.
mailpack-head_num = 0.
mailpack-body_start = 1.
mailpack-body_num = tab_lines.
mailpack-doc_type = 'RAW'.
append mailpack.

mailhead = 'TEST.TXT'.
append mailhead.

    * File 1

mailbin = 'This is file 1'.
append mailbin.

describe table mailbin lines tab_lines.

mailpack-transf_bin = 'X'.
mailpack-head_start = 1.
mailpack-head_num = 1.
mailpack-body_start = 1.
mailpack-body_num = tab_lines.
mailpack-doc_type = 'TXT'.
mailpack-obj_name = 'TEST1'.
mailpack-obj_descr = 'Subject'.
mailpack-doc_size = tab_lines * 255.
append mailpack.

endform.

Thanks

Vikranth

Former Member
0 Kudos
86

Use this customed FM:

FUNCTION Z_SEND_MAIL_FOR_SPOOLLIST.

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(SPOOLNUMBER) LIKE SY-SPONO DEFAULT SY-SPONO

*" REFERENCE(MAILNAME) LIKE SOOD1-OBJNAM DEFAULT 'NOTE'

*" REFERENCE(SUBJECT) LIKE SOOD1-OBJDES

*" REFERENCE(RECEPIENT) LIKE SY-UNAME DEFAULT SY-UNAME

*" REFERENCE(DLI) LIKE SOOS1-DLINAM OPTIONAL

*" TABLES

*" TEXT STRUCTURE SOLI

*" EXCEPTIONS

*" ERROR

*"----


DATA: OBJECT_HD_CHANGE LIKE SOOD1 OCCURS 0 WITH HEADER LINE,

OBJPARA LIKE SELC OCCURS 0 WITH HEADER LINE,

RECEIVERS LIKE SOOS1 OCCURS 0 WITH HEADER LINE.

OBJECT_HD_CHANGE-OBJLA = SY-LANGU.

OBJECT_HD_CHANGE-OBJNAM = MAILNAME.

OBJECT_HD_CHANGE-OBJDES = SUBJECT.

OBJECT_HD_CHANGE-OBJSNS = 'F'.

OBJECT_HD_CHANGE-VMTYP = 'T'.

OBJECT_HD_CHANGE-SKIPS = 'X'.

OBJECT_HD_CHANGE-ACNAM = 'SP01'.

OBJECT_HD_CHANGE-OBJCP = 'X'.

OBJECT_HD_CHANGE-OBJPRI = '1'.

*OBJECT_HD_CHANGE-ACOUT = 'X'.

RECEIVERS-RCDAT = SY-DATUM.

RECEIVERS-RCTIM = SY-UZEIT.

IF DLI IS INITIAL.

RECEIVERS-RECNAM = RECEPIENT.

RECEIVERS-RTUNAM = RECEPIENT.

ELSE.

RECEIVERS-RECNAM = DLI.

RECEIVERS-ADR_NAME = DLI.

RECEIVERS-RECESC = 'C'.

ENDIF.

RECEIVERS-SNDEX = 'X'. " Express-Mail

*RECEIVERS-SNDPRI = 'X'.

move 'B' TO RECEIVERS-RECESC.

move '1' TO RECEIVERS-ACONE.

RECEIVERS-DELIVER = 'X'.

*RECEIVERS-NOT_DELI = 'X'.

RECEIVERS-READ = 'X'.

RECEIVERS-MAILSTATUS = 'E'.

APPEND RECEIVERS.

OBJPARA-NAME = 'SPI'.

OBJPARA-LOW = SPOOLNUMBER.

APPEND OBJPARA.

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

OBJECT_HD_CHANGE = OBJECT_HD_CHANGE

OBJECT_TYPE = 'RAW'

OWNER = SY-UNAME

TABLES

OBJCONT = TEXT

OBJPARA = OBJPARA

RECEIVERS = RECEIVERS

EXCEPTIONS

OTHERS = 01.

IF SY-SUBRC NE 0.

  • RAISE ERROR.

ENDIF.

COMMIT WORK.

CALL FUNCTION 'SO_DEQUEUE_UPDATE_LOCKS'.

ENDFUNCTION.