Posted: Sun Oct 14, 2007 9:43 pm Post subject: Send List or OTF spool as an attachment to email using ABAP
Requirement:
This program shows how a spool ( SapScript/Smartform -OTF or ABAP List ) can be sent as an attachment to email using ABAP Program.
Processing:
This program takes spool id and email-id as input and converts the spool to pdf using FMs 'CONVERT_ABAPSPOOLJOB_2_PDF' or 'CONVERT_OTFSPOOLJOB_2_PDF'. Further, the program calls mail API FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' to send PDF file as an attachment. Mail Title and mail-body is prepared and the pdf internal table is adjusted first to 255 character inetrnal table suitable for mail API FM.
For real life scenarios, like sending purchase order as an attachment to email :
it can be achieved by modifying the print program of purchase order output type ( NEU ). Actually, SAP standard has configuration for sending PO as email, but the constraint is that you can't use mail body text for external mails. This is only possible for internal SAP Office mails. You can modify the print program ( copy of original ) for external send ( communication type '5' ) to get the spool number or OTF itab from the FORM_OPEN or smartform FM and then convert the spool to pdf and send it as an attachment with email body-text through your own coding in the print program.
Code:
*&---------------------------------------------------------------------*
* Written By : Ram Manohar Tiwari
* Presented By : www.rmtiwari.com
* Function : Send any spool ( OTF / LIST )as attachment to an e-mail
* using ABAP program.
*&---------------------------------------------------------------------*
REPORT Z_RMTIWARI_SEND_SPOOL_MAIL_ATT .
*----------------------------------------------------------------------*
PARAMETERS : P_SPOOL TYPE TSP01-RQIDENT OBLIGATORY .
PARAMETERS : P_MAIL TYPE char100 OBLIGATORY .
*----------------------------------------------------------------------*
TYPES : TY_LINE type string.
DATA: IT_ATTACHMENT TYPE soli OCCURS 0 WITH HEADER LINE.
DATA: IT_ATTACHMENT_LONG TYPE TY_LINE OCCURS 0 WITH HEADER LINE.
DATA: LV_PDF_SIZE type i.
DATA: LT_PDF type standard table of tline with header line.
DATA: LT_OBJPACK LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE,
LT_OBJHEAD LIKE solisti1 OCCURS 1 WITH HEADER LINE,
LT_OBJBIN LIKE solisti1 OCCURS 10 WITH HEADER LINE,
LT_OBJTXT LIKE solisti1 OCCURS 10 WITH HEADER LINE,
LT_RECLIST LIKE somlreci1 OCCURS 5 WITH HEADER LINE,
LV_DOCUMENT_DATA TYPE sodocchgi1.
* Read spool and get the pdf internal table and name of spool
PERFORM READ_SPOOL USING X_SPOOL_ID LV_SPOOL_DESC.
CHECK NOT ( LT_PDF[] IS INITIAL ).
* Convert pdf itab to 255 line itab.
data :LV_COUNTER type i.
data :LV_FROM type i.
loop at LT_PDF.
translate LT_PDF using ' ~' .
concatenate IT_ATTACHMENT_LONG LT_PDF into it_attachment_long.
endloop.
translate IT_ATTACHMENT_LONG using '~ ' .
append IT_ATTACHMENT_LONG.
clear : LV_COUNTER.
DO.
LV_COUNTER = strlen( IT_ATTACHMENT_LONG ).
if LV_COUNTER ge 255.
IT_ATTACHMENT = IT_ATTACHMENT_LONG(255).
append IT_ATTACHMENT.
SHIFT IT_ATTACHMENT_LONG by 255 places.
else.
IT_ATTACHMENT = IT_ATTACHMENT_LONG(lv_counter).
append IT_ATTACHMENT.
exit.
endif.
ENDDO.
* Body of email
MOVE 'Email sent to you from SAP' TO LT_OBJTXT.
APPEND LT_OBJTXT.
LV_DOCUMENT_DATA-obj_name = 'SpoolMail'.
* Title of the email as spool name
LV_DOCUMENT_DATA-obj_descr = LV_SPOOL_DESC.
LV_DOCUMENT_DATA-sensitivty = 'O'.
LV_DOCUMENT_DATA-expiry_dat = SY-datum + 15.
LV_DOCUMENT_DATA-doc_size = STRLEN( LT_OBJTXT ).
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.