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

email

Former Member
0 Likes
1,006

hi Gurus

Please tell me How to pass text message to the bosy of the email using FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
967

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 = 'Error - Materail Master Administration'.

OBJTXT = 'Error 1'.

APPEND OBJTXT.

OBJTXT = 'Error 2'.

APPEND OBJTXT.

OBJTXT = 'Error 3'.

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 = 1.

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.txt'. 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 = 'RAW'.

*

*OBJPACK-OBJ_NAME = 'ATTACHMENT'.

*

*OBJPACK-OBJ_DESCR = 'ERORRS LIST'.

*

*OBJPACK-DOC_SIZE = TAB_LINES * 255.

*

*APPEND OBJPACK..

  • Entering names in the distribution list

RECLIST-RECEIVER = 'email@gmail.com'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = 'email@gmail.com'.

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 of recipients!'.

WHEN 2.

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

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.

8 REPLIES 8
Read only

Former Member
0 Likes
968

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 = 'Error - Materail Master Administration'.

OBJTXT = 'Error 1'.

APPEND OBJTXT.

OBJTXT = 'Error 2'.

APPEND OBJTXT.

OBJTXT = 'Error 3'.

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 = 1.

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.txt'. 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 = 'RAW'.

*

*OBJPACK-OBJ_NAME = 'ATTACHMENT'.

*

*OBJPACK-OBJ_DESCR = 'ERORRS LIST'.

*

*OBJPACK-DOC_SIZE = TAB_LINES * 255.

*

*APPEND OBJPACK..

  • Entering names in the distribution list

RECLIST-RECEIVER = 'email@gmail.com'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

RECLIST-RECEIVER = 'email@gmail.com'.

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 of recipients!'.

WHEN 2.

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

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.

Read only

0 Likes
967

hi

thank you.

but its comming as attachment , i don't want as attachment ,i want as text in the body of mail.

Read only

0 Likes
967

please comment for objpack in case u dont want attachement..:)

Please reward points its really help me to work on SDN

regards

Read only

0 Likes
967

CONCATENATE l_fld_status

' STATUS CHANGED FROM: ' l_var

' TO ' l_output

' FOR MATERIAL TYPE: ' l_mtart

' FOR MATERIAL NO: ' l_mat_num

INTO l_mail_body.

PERFORM f_create_email_body_text USING l_mail_body.

PERFORM f_create_email_pack_listing. "CREATING THE ENTRY FOR THE COMPRESSED DOCUMENT

PERFORM f_create_email_recipient. "GETTING RELEVANT EMAIL RECIPIENTS

PERFORM f_send_email. "SENDING EMAIL

FORM f_create_email_body_text USING l_body_text.

REFRESH:

t_text.

CLEAR:

wa_text.

"CREATING BODY TEXT.

MOVE l_body_text TO wa_text-line.

APPEND wa_text-line TO t_text.

ENDFORM.

FORM f_create_email_pack_listing .

DATA:

l_num_lines TYPE i.

REFRESH:

t_pack.

CLEAR:

l_num_lines,

wa_pack.

"CREATING THE ENTRY FOR THE COMPRESSED DOCUMENT

DESCRIBE TABLE t_text LINES l_num_lines.

READ TABLE t_text INDEX l_num_lines INTO wa_text.

wa_pack-doc_size = ( l_num_lines - 1 ) * 255 + STRLEN( wa_text-line ).

MOVE 1 TO wa_pack-head_start.

MOVE 1 TO wa_pack-head_num.

MOVE 1 TO wa_pack-body_start.

MOVE l_num_lines TO wa_pack-body_num.

MOVE 'RAW' TO wa_pack-doc_type.

APPEND wa_pack TO t_pack.

ENDFORM.

FORM f_create_email_recipient .

DATA:

l_num_rows TYPE i,

l_count TYPE i.

REFRESH:

t_recipient.

CLEAR:

wa_recipient,

l_num_rows,

l_count.

l_num_rows = 0.

l_count = 1.

"GETTING RELEVANT EMAIL RECIPIENTS

DESCRIBE TABLE t_st_mail LINES l_num_rows.

DO l_num_rows TIMES.

READ TABLE t_st_mail INDEX l_count INTO wa_st_mail.

MOVE wa_st_mail-mailto TO wa_recipient-receiver.

MOVE 'U' TO wa_recipient-rec_type.

APPEND wa_recipient TO t_recipient.

l_count = l_count + 1.

ENDDO.

ENDFORM.

FORM f_send_email .

"FM FOR SENDING EMAIL

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = wa_doc_data

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = t_pack

contents_txt = t_text

receivers = t_recipient

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.

ENDFORM.

This will solve your problem

reward more points:)

Read only

0 Likes
967

hi

i have attachmented a pdf file by using the you have sent ,but now i need to pass message in the body of email, not in pdf file.

i have passed subject of mail by

OBJPACK-OBJ_DESCR = 'Reproduction object 138'.

APPEND OBJPACK.

similarly i want body of email.

Read only

0 Likes
967

hi

when i comment objpack in the function module its giving dump.

can u please give me the solution

Read only

Former Member
0 Likes
967

Hi Sudheer,

The follwing code which it send the mails to the perticular members in the list which it should maintain in DISTRIBUTION LIST : TCODE = SO23.

Firts goto t-code SO23 crete one distribution list in that add the no.of mail receipts in one list which we can send mail either sap inbox or exteral mails.

other wise u can send the mails directly with out use if so23.

  • Internal tables used to send emails

DATA: tbl_packing_list TYPE sopcklsti1 OCCURS 0 WITH HEADER LINE,

tbl_object_header TYPE solisti1 OCCURS 0 WITH HEADER LINE,

tbl_contents_txt TYPE solisti1 OCCURS 0 WITH HEADER LINE,

tbl_receivers TYPE somlreci1 OCCURS 0 WITH HEADER LINE.

constant c_business(7) VALUE 'LISTMAIL'. " This is list name by SO23.

  • Send mail to operations support with the detailed error log

PERFORM send_mail USING <b>c_business</b>.

FORM send_mail USING receiver.

CLEAR: w_lines,tbl_packing_list,tbl_object_header,

tbl_contents_txt, tbl_receivers.

REFRESH:tbl_packing_list, tbl_object_header,

tbl_contents_txt,tbl_receivers.

SORT tbl_err BY type.

DELETE ADJACENT DUPLICATES FROM tbl_err COMPARING ALL FIELDS.

IF NOT tbl_err[] IS INITIAL.

PERFORM prepare_email.

ELSE.

EXIT.

ENDIF.

  • Get e-mail document data

PERFORM document_data.

  • Get packing list

PERFORM packing_list.

tbl_receivers-receiver = receiver. " this is the distribution list name is LISTMAIL.

tbl_receivers-rec_type = 'C'.

tbl_receivers-express = c_flag.

tbl_receivers-sap_body = c_flag.

APPEND tbl_receivers.

  • Call FM to send E-mails to receivers

CALL FUNCTION <b>'SO_NEW_DOCUMENT_ATT_SEND_API1'</b>

EXPORTING

document_data = w_document_data

put_in_outbox = c_x

TABLES

packing_list = tbl_packing_list

object_header = tbl_object_header

contents_txt = tbl_contents_txt

receivers = tbl_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.

IF sy-subrc <> 0.

ENDIF.

ENDFORM. " send_mail

FORM prepare_email.

" Subject of mail.

CONCATENATE text-028 w_docnum text-030

INTO tbl_contents_txt-line

SEPARATED BY space.

APPEND tbl_contents_txt.

CLEAR tbl_contents_txt.

  • E-mail attachment header

CONCATENATE text-024

text-025

text-026

text-029

text-027

text-031

c_comma

INTO tbl_contents_txt-line

SEPARATED BY c_comma.

APPEND tbl_contents_txt.

CLEAR tbl_contents_txt.

SORT tbl_err .

  • E-mail attachment content

LOOP AT tbl_err.

CONCATENATE c_dbqt w_docnum c_dbqt c_comma

c_dbqt tbl_err-shipmn_id_nbr c_dbqt c_comma

c_dbqt tbl_err-contract_nbr c_dbqt c_comma

c_dbqt tbl_err-contract_line c_dbqt c_comma

c_dbqt tbl_err-msg c_dbqt c_comma

c_dbqt tbl_err-type c_dbqt c_comma

INTO tbl_contents_txt-line.

CONCATENATE c_linefeed

tbl_contents_txt-line

c_comma

INTO tbl_contents_txt-line.

APPEND tbl_contents_txt.

CLEAR tbl_contents_txt.

ENDLOOP.

DESCRIBE TABLE tbl_err LINES w_lines.

ENDFORM. " prepare_email

"Attach name.

FORM document_data.

CLEAR w_line.

CONCATENATE text-028 sy-datum sy-uzeit INTO w_line

SEPARATED BY c_uscore.

w_document_data-obj_name = w_line.

w_document_data-obj_descr = w_line.

w_document_data-priority = 1.

w_document_data-obj_prio = 1.

ENDFORM. " document_data

FORM packing_list.

CLEAR w_lines.

DESCRIBE TABLE tbl_err LINES w_lines.

READ TABLE tbl_contents_txt INDEX w_lines.

tbl_packing_list-head_start = 1.

tbl_packing_list-head_num = 1.

tbl_packing_list-body_start = 1.

tbl_packing_list-body_num = 1.

tbl_packing_list-doc_type = 'RAW'.

APPEND tbl_packing_list.

tbl_packing_list-head_start = 1.

tbl_packing_list-head_num = 0.

tbl_packing_list-body_start = 2.

tbl_packing_list-body_num = w_lines + 1.

tbl_packing_list-doc_type = 'CSV'. " this is Excel file

tbl_packing_list-obj_name = text-027.

tbl_packing_list-doc_size = 255 * ( w_lines + 1 ).

APPEND tbl_packing_list.

ENDFORM. " packing_list

<b>Reward with points if helpful.</b>

Regards,

Vijay

Read only

0 Likes
967

hi

thanks for reply

I have attached a pdf file , its working fine.

now i need to send some message in the body of this email ( not as attachment) .

how this can be achived ????????