I don’t see the attachment. Could you please post it again? on a side note, there will always be naysayers for anything you do. This is a step in right direction.
Thanks,
John
Like(0)
Reply
Alert Moderator
Hafizul Mollah Post author
April 20, 2017 at 12:31 pm
Hi John,
I think those attachments have been deleted by admin during the migration from SCN to “sap.com”. The sample codes have now been pasted directly in the blog.
Thanks & Regards,
Hafizul
Like(0)
Reply
Alert Moderator
Avish Mittal
June 29, 2017 at 10:33 am
Hi Hafizul,
Thanks for this wonderful blog. It is very helpful.
I am also working on same kind of requirement. I am calling a smartform and converting output into PDF (using FM “CONVERT_OTF”) and then sending as attachment in email. Now the issue is when I am running the report in foreground everything is working fine, but when running in background PDF in email is a corrupt file. Then I have debug the code and found when I am running the code in background FM “CONVERT_OTF” is giving SY-SUBRC = 4. I have also tried FM “CONVERT_OTF_2_PDF”, but no luck. Please help.
Thanks in advance.
Regards,
Avish
Like(0)
Reply
Alert Moderator
Harris Veziris
September 14, 2020 at 11:39 am
Hi Hafizul,
I was struggling to convert text lines with binary content to raw format of SOLIX type, but I used your code and worked fine.
LOOP AT it_pdf_table INTO wa_pdfline.
ASSIGN wa_pdfline TO <l_xline> CASTING.
CONCATENATE pdf_xstring <l_xline> INTO pdf_xstring IN BYTE MODE.
ENDLOOP.
* get PDF xstring and convert it to BCS format
lp_pdf_size = xstrlen( pdf_xstring ).
pdf_content = cl_document_bcs=>xstring_to_solix(
ip_xstring = pdf_xstring ).
Thanks a lot!
Harris
Like(0)
Reply
Alert Moderator
Send Emails with Attachments of any Format
Skip to end of metadata
Created by V S BHARGAV MYLAVARAPU, last modified by Former Member on Oct 24, 2013
Go to start of metadata
Hi All,
Happy SDN..!
Recently I got a chance to do some R&D in sending emails using ABAP. I searched all the SCN and other Technical forums to find a easy solution to perform this operation. But unsucessfull :( . We have several options given by SAP to send mails to several people with attachments. Everyone knows how to perform this operation. The new thing here which I want to explain to all via Wiki SDN is Sending those mails in a bulk format. For Example, I have kept 100 documents in a Folder on my desktop. The folder contains different types of documents like, PDF, EXCEL, WORD, JPEG, Etc... Now I need to send all those documents one by one via Email to a specific Mail ID with attachments. Since the folder can contain any type of document, The below program will solve this kind of requirement. Please find the below screen shots of the program for a easy go-thru of what exactly this program does. Now a Email will be generated to the given Mail ID as shown in the below screen shots. Similarly you will get different mails with each attachment in a seperate mail.
The explaination of the program is as follows.
Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT YSEND_BULK_DOCUMENTS_FROM_A_FOLDER.
PARAMETERS : P_ATTACH TYPE CHAR200 OBLIGATORY, " Select the Folder on the Desktop from F4 help
P_EMAIL TYPE CHAR50 OBLIGATORY, " Email ID
P_SUBJ TYPE CHAR50 OBLIGATORY. " Subject of the Email
DATA : T_HEXTAB TYPE TABLE OF STRING,
L_FILE TYPE STRING,
T_MAILHEX TYPE SOLIX_TAB,
LV_COUNT TYPE I,
GV_EMAIL TYPE ADR6-SMTP_ADDR,
T_BODY TYPE TABLE OF SOLISTI1,
GR_RECIPIENT TYPE REF TO IF_RECIPIENT_BCS,
TL_TEXTPOOL TYPE TABLE OF TEXTPOOL,
WA_TEXTPOOL LIKE LINE OF TL_TEXTPOOL,
IT_CONTENTS TYPE SOLI_TAB,
LV_ATTACH_NAME TYPE SOOD-OBJDES,
L_SUBJECT TYPE SO_OBJ_DES,
L_DOCUMENT TYPE REF TO CL_DOCUMENT_BCS,
W_DOCUMENT TYPE REF TO CL_BCS,
WA_CONTENTS LIKE LINE OF IT_CONTENTS,
LV_FILENAME TYPE STRING,
L_RESULT TYPE OS_BOOLEAN,
LV_STRING TYPE STRING.
DATA : FILE_TABLE LIKE TABLE OF SDOKPATH WITH HEADER LINE .
DATA : DIR_TABLE LIKE TABLE OF SDOKPATH WITH HEADER LINE .
DATA : FILE_COUNT TYPE I ,
DIRCOUNT TYPE I .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_ATTACH.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE
CHANGING
SELECTED_FOLDER = LV_STRING
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
P_ATTACH = LV_STRING.
ENDIF.
START-OF-SELECTION.
* CHECK IF THE FOLDER PATH IS INITIAL, IF INITIAL LEAVE THE PROGRAM, ELSE COPY THE SUBJECT. ---> IT ALL DEPENDS ON HOW YOU VALIDATE.
IF P_ATTACH IS INITIAL.
LEAVE LIST-PROCESSING.
ELSE.
L_SUBJECT = P_SUBJ.
ENDIF.
* GETS ALL THE FILES NAMES IN THE SELECTED FOLDER
CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
EXPORTING
DIRECTORY = P_ATTACH
IMPORTING
FILE_COUNT = FILE_COUNT
DIR_COUNT = DIRCOUNT
TABLES
FILE_TABLE = FILE_TABLE
DIR_TABLE = DIR_TABLE
EXCEPTIONS
CNTL_ERROR = 1
OTHERS = 2.
* TELL HOW MANY FIELDS EXISTS
WRITE:/ 'no of files in the floder is : '(005), FILE_COUNT.
SKIP 1.
WRITE:/ SY-ULINE.
WRITE:/ SY-ULINE.
* PROCESS THE DATA TO SEND MAIL WITH ATTACHMENT.
LOOP AT FILE_TABLE.
LV_COUNT = SY-TABIX.
CONCATENATE P_ATTACH '\' FILE_TABLE INTO LV_FILENAME.
MOVE LV_FILENAME TO L_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = L_FILE
FILETYPE = 'BIN'
TABLES
DATA_TAB = T_MAILHEX
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* YOU NEED TO MAINTAIN TEXT SYMBOLS AND WANT TO READ THEM IN THE PROGRAM
READ TEXTPOOL SY-REPID INTO TL_TEXTPOOL LANGUAGE SY-LANGU.
* MY TEXT SYMBOL IS " T04: You can Add your Body here"
READ TABLE TL_TEXTPOOL INTO WA_TEXTPOOL WITH KEY ID = 'I'
KEY = 'T04' BINARY SEARCH.
IF SY-SUBRC = 0.
WA_CONTENTS-LINE = WA_TEXTPOOL-ENTRY.
APPEND WA_CONTENTS TO IT_CONTENTS.
ENDIF.
* CREATE THE DOCUMENT WITH CONTENTS
CREATE OBJECT L_DOCUMENT.
L_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
I_TYPE = 'HTM'
I_SUBJECT = L_SUBJECT
I_LENGTH = '1000'
I_LANGUAGE = SY-LANGU
I_IMPORTANCE = '1'
I_TEXT = IT_CONTENTS ).
* ATTACH THE FILE, THE ATTACHMENT TYPE SHOULD BE BIN TO ACCEPT ANY KIND OF ATTACHMENT, INCLUDING VIDEOS, AUDIO FILES ETC...
LV_ATTACH_NAME = FILE_TABLE.
CALL METHOD L_DOCUMENT->ADD_ATTACHMENT
EXPORTING
I_ATTACHMENT_TYPE = 'BIN'
I_ATTACHMENT_SUBJECT = LV_ATTACH_NAME
I_ATT_CONTENT_HEX = T_MAILHEX.
* CREATING PERSISTENT OBJECT WILL ALLOW YOU TO SET THE DOCUMENT IN THE MAIL
W_DOCUMENT = CL_BCS=>CREATE_PERSISTENT( ).
CALL METHOD W_DOCUMENT->SET_DOCUMENT( L_DOCUMENT ).
* EMAIL AS GIVEN IN THE SELECTION SCREEN.
GV_EMAIL = P_EMAIL.
GR_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( GV_EMAIL ).
"Add recipient to send request
CALL METHOD W_DOCUMENT->ADD_RECIPIENT
EXPORTING
I_RECIPIENT = GR_RECIPIENT
I_EXPRESS = 'X'.
* SEND THE MAIL
CALL METHOD W_DOCUMENT->SEND(
EXPORTING
I_WITH_ERROR_SCREEN = 'X'
RECEIVING
RESULT = L_RESULT ).
* YOU CAN VERIFY THE STATUS IN THE LIST, YOU CAN ALSO SUBMIT THIS AS A BACKGROUND JOB.
IF L_RESULT = 'X'.
WRITE :/ , 1(9) LV_COUNT, 10(55) FILE_TABLE-PATHNAME.
WRITE : 56(1) '-', 58(20) 'Mail sent'(003).
COMMIT WORK.
ELSE.
WRITE :/ , 1(9) LV_COUNT, 10(55) FILE_TABLE-PATHNAME.
WRITE : 56(1) '-', 58(30) 'Error in sending Mail'(004).
ROLLBACK WORK.
ENDIF.
REFRESH IT_CONTENTS[].
ENDLOOP.
You can Verify the Status of the Mail in SOST and SCOT as shown below respectively. I Hope this WIKI would help many SAPians in sending mails with any type of attachment using ABAP. Thanks & Regards, Venkat Sesha
emails
sost
scot
attachments
attachment
formats
3 Comments
Former Member
Hi Venkat Sesha,
Thank you for the detailed explanation with screen shots. It is very helpful.
We tried using this and it worked perfectly. But , we had an issue with the sender email . By default this program is taking the SAP logon as the email id.
Is there a way we can specify the sender email id?
Thanks
Sujata Kolla
Aug 06, 2014
Former Member
Hi Venkat,
I really appreciate your effort. Wonder full..Keep it up..
Regards,
Abu Fazi
Feb 04, 2015
V S BHARGAV MYLAVARAPU
Thanks for your complements...
Dashboard
…
ABAP - Email
Skip to end of banner
Go to start of banner
Send Mail having Multiple Files as Attachment using object oriented technique
Skip to end of metadata
Created by Former Member on May 14, 2010
Go to start of metadata
Back to Sending Mails - Home Page
Author: Pratik Mallick Submitted: 3rd April 2009
Introduction
Send notification is becoming important from business point of view. It adds extra reliability to the process and enables business person to react quickly to customer's requirement. If any error occurred to a process some group of people in the top management will get a notification and react based on the details specified in the notification.
Business Requirements
In some situation we had to send a notification to a group people. Some cases we had to only send the text in the mail body and some cases we had to send the detail records as attachments. Suppose one user ran a program to update the material master and the top management wants to get the success records as one attachment and error records as another attachment in the email.
Methodology
Using the below object oriented technique it can easily obtained.
Create object
The standard class CL_BCS is used to send the notification along with attachment to a group of people. Method CREATE_PERSISTENT is used to create an send request object of the standard class CL_BCS.
Create body of the email
Method CREATE_DOCUMENT of standard class CL_DOCUMENT_BCS is used to create the text of the email body.
Create attachments of the email
Method ADD_ATTACHMENT of standard class CL_DOCUMENT_BCS is used to create attachment of the email. If we want to create the multiple attachment we have call this method multiple times. Method SET_DOCUMENT of the standard class CL_BCS is used to add the document (email body and attachments) to be send request object.
Create sender
Method CREATE of the standard class CL_SAPUSER_BCS is used to create the sender address. Method SET_SENDER of standard class CL_BCS is used add the sender address to the send request object.
Create recipient
Method CREATE_INTERNET_ADDRESS of standard class CL_CAM_ADDRESS_BCS is used to create recipient email address.
Method ADD_RECIPIENT of standard class CL_BCS is used to add the recipient email address to the send request object.
Send email
Method SEND of standard class CL_BCS is used to send the send request object to a group of people added in the recipient list. Sending is done in a queued way; immediate sending can be triggered for very urgent alerts.