Quantcast
Channel: ABAP Development
Viewing all articles
Browse latest Browse all 948

Sending Email with PDF Attachment

$
0
0


Hi All,

This blog is with reference to one of the threads(question) in SCN (http://scn.sap.com/thread/3373098) wherein the requirement was to send email with PDF attachment.

As I have implemented the same for one similar requirement I replied to this question and wanted to share the steps/code if required.I have documented all the steps and code in a MS word document but as SCN does not allow to upload MS Word document ,I told to send one email to my personal email ID(mentioned in the reply) and I will send the MS word document.

 

Thereafter I kept on receiving a lot of email requests to share the word document.So thought of creating this blog with all those steps and code so that anyone needs those can get them here in SCN itself .And also they will not need to wait for my email reply instead they can get it immediately here in SCN itself.

 

I will maintain this blog link to that original thread/question.

 

Here are the steps and codes for the development of the class, method to send email with PDF attachment(content of internal table) and also one sample program to test the same.

 

Step1:  Go to tcode SE24-> Provide the class name

 

  class1.png

 

Properties:

 

2.png

 

Step2 : Declare the PDF Method: SEND_PDF_FILE

 

PDF: Parameters:

 

3.png

 

Parameters list to copy and paste:

 

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

IM_FILE_HEADER_TEXT        Importing    Type    STRING                 Header Text

IM_EMAIL_SUBJECT_LINE     Importing   Type    SO_OBJ_DES       Subject Line

IM_EMAIL_BODY_TEXT         Importing    Type    BCSY_TEXT          Body Text

IM_EMAIL_ADDRESS            Importing   Type    ZTP_SMTP_TAB    Email Address

IM_EMAIL_DIST_NAME          Importing   Type   SO_OBJ_NAM       Email Distribution Name

IM_EMAIL_DIST_ID                Importing   Type    SO_OBJ_ID           Email Distribution Id

IM_ATTACHMENT_NAME       Importing   Type    SOOD-OBJDES     Attachment Name

IM_FILE_DELIMETER             Importing   Type    C                          File Delimiter

IM_ITAB_1                             Importing   Type    ZTP_TEXT_TAB      Itab with data content

IM_ITAB_2                             Importing   Type    SOLI_TAB             Itab with column headers

EX_SEND_TO_ALL                Exporting   Type    OS_BOOLEAN      Send Email

IM_EMAIL_DO_NOT               Importing   Type    CHAR1                  Flag to determine whether mail needs to be sent or not

IM_LAYOUT                          Importing    Type    SYPAART             Layout mode Portrait or Landscape

EX_PDF_TABLE                    Exporting   Type    RCL_BAG_TLINE   Contains converted data in PDF format

 

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

 

Custom types are highlighted , please find them below:

 

Step3 : Custom types needs to be created which is used above:

Email Table Type :

4.png

 

Corresponding structure:

 

5.png

 

Data Content table type:

 

7.png

 

Corresponding structure:

 

8.png

 

Exceptions:

 

9.png

 

Step4 : Paste the below code in the method body.

 

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

Please find the code in the attached file , with file name : Source code _method.txt

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

 

 

Step5:Activate the method and class and write the below small executable test program to test it.Go to SE38 create the below program to test:

 

10.png

 

Code :

 

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

Please find the code in the attached file , with file name : Source code _program.txt

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

 

Step6: Activate the program and execute it.Please change the email ID to yours one to receive the email to Lotus Notes / Outlook /Other email configured.

 

Execute the program and test whether the email is sent successfully or not (Check in SOST tcode):

 

12.png

 

Open the PDF file attached in the email and make sure the content is correct:

 

13.png

 

Please let me know if anyone face any issue while developing or testing it.

 

Thanks & Regrads,

Hafizul Mollah,

SAP ABAP Consultant @Capgemini India Pvt. Ltd.


Viewing all articles
Browse latest Browse all 948

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>