Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
ATA: lt_text_table TYPE TABLE OF string,
w_attachment TYPE string. "Added explicit declaration as STRING type
"Variables
DATA:
G_SENT_TO_ALL TYPE SONV-FLAG,
G_TAB_LINES TYPE I,
G_ATTACHMENT_LINES TYPE I.
"Types
TYPES:
T_DOCUMENT_DATA TYPE SODOCCHGI1,
T_PACKING_LIST TYPE SOPCKLSTI1,
T_ATTACHMENT TYPE SOLISTI1,
T_BODY_MSG TYPE SOLISTI1,
T_RECEIVERS TYPE SOMLRECI1.
"Workareas
DATA:
W_DOCUMENT_DATA TYPE T_DOCUMENT_DATA,
W_PACKING_LIST TYPE T_PACKING_LIST,
W_BODY_MSG TYPE T_BODY_MSG,
W_RECEIVERS TYPE T_RECEIVERS.
"Internal Tables
DATA:
I_DOCUMENT_DATA TYPE STANDARD TABLE OF T_DOCUMENT_DATA,
I_PACKING_LIST TYPE STANDARD TABLE OF T_PACKING_LIST,
I_ATTACHMENT TYPE STANDARD TABLE OF T_ATTACHMENT,
I_BODY_MSG TYPE STANDARD TABLE OF T_BODY_MSG,
I_RECEIVERS TYPE STANDARD TABLE OF T_RECEIVERS.
PARAMETERS: P_MAIL(99) TYPE C OBLIGATORY.
START-OF-SELECTION.
" Initialize test data
APPEND 'Hi' TO lt_text_table.
APPEND 'This is line 2' TO lt_text_table.
APPEND 'This is line 3' TO lt_text_table.
" Get line break constant
CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.
CONSTANTS: CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>NEWLINE.
" Convert text table to attachment format
LOOP AT lt_text_table INTO DATA(lv_text).
" Remove any existing trailing spaces
lv_text = condense( lv_text ).
" Convert to attachment format
w_attachment = lv_text.
" Add line break after each line except the last one
IF sy-tabix < lines( lt_text_table ).
CONCATENATE w_attachment CON_CRET INTO w_attachment.
ENDIF.
APPEND w_attachment TO i_attachment.
CLEAR w_attachment.
ENDLOOP.
"Subject of the Mail
W_DOCUMENT_DATA-OBJ_NAME = 'Text File'.
W_DOCUMENT_DATA-OBJ_DESCR = 'Text File Attachment'.
"Body of the Mail
W_BODY_MSG = 'Hi,'.
APPEND W_BODY_MSG TO I_BODY_MSG.
CLEAR W_BODY_MSG.
W_BODY_MSG = 'Please find the attached text file.'.
APPEND W_BODY_MSG TO I_BODY_MSG.
CLEAR W_BODY_MSG.
"Write Packing List for Body
DESCRIBE TABLE I_BODY_MSG LINES G_TAB_LINES.
W_PACKING_LIST-HEAD_START = 1.
W_PACKING_LIST-HEAD_NUM = 1.
W_PACKING_LIST-BODY_START = 1.
W_PACKING_LIST-BODY_NUM = G_TAB_LINES.
W_PACKING_LIST-DOC_TYPE = 'RAW'.
APPEND W_PACKING_LIST TO I_PACKING_LIST.
CLEAR W_PACKING_LIST.
APPEND LINES OF I_ATTACHMENT TO I_BODY_MSG.
"Write Packing List for Attachment
W_PACKING_LIST-HEAD_START = 2.
W_PACKING_LIST-HEAD_NUM = 1.
W_PACKING_LIST-BODY_START = G_TAB_LINES + 1.
DATA: LINES TYPE I.
DESCRIBE TABLE I_ATTACHMENT LINES LINES.
W_PACKING_LIST-BODY_NUM = LINES.
W_PACKING_LIST-DOC_TYPE = 'TXT'.
W_PACKING_LIST-OBJ_DESCR = 'Text File'.
W_PACKING_LIST-OBJ_NAME = 'text_file.txt'.
W_PACKING_LIST-DOC_SIZE = W_PACKING_LIST-BODY_NUM * 255.
APPEND W_PACKING_LIST TO I_PACKING_LIST.
CLEAR W_PACKING_LIST.
"Fill the document data and get size of attachment
W_DOCUMENT_DATA-OBJ_LANGU = SY-LANGU.
READ TABLE I_BODY_MSG INTO W_BODY_MSG INDEX G_ATTACHMENT_LINES.
W_DOCUMENT_DATA-DOC_SIZE = ( G_ATTACHMENT_LINES - 1 ) * 255 + STRLEN( W_BODY_MSG ).
"Receivers List
W_RECEIVERS-REC_TYPE = 'U'. "Internet address
W_RECEIVERS-RECEIVER = P_MAIL.
W_RECEIVERS-COM_TYPE = 'INT'.
W_RECEIVERS-NOTIF_DEL = 'X'.
W_RECEIVERS-NOTIF_NDEL = 'X'.
APPEND W_RECEIVERS TO I_RECEIVERS.
CLEAR: W_RECEIVERS.
"Function module to send Mail to Recipients
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = W_DOCUMENT_DATA
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL = G_SENT_TO_ALL
TABLES
PACKING_LIST = I_PACKING_LIST
CONTENTS_TXT = I_BODY_MSG
RECEIVERS = I_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.
MESSAGE I303(ME) WITH 'Mail has been Successfully Sent.'.
ELSE.
WAIT UP TO 2 SECONDS.
"This program starts the SAPconnect send process
SUBMIT RSCONN01 WITH MODE = 'INT' WITH OUTPUT = 'X' AND RETURN.
ENDIF.
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team