Application Development 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: 

E-mail multiple PDF attachments

Former Member
0 Kudos
2,936

Hi Experts,

My requirement is to send two PDFs as attachments in a single mail. I am able to see the two attachments. But, the first attachment is not opening and the second one is only openeing.

Here, i am giving the code which i have written. Can any body help me where the error is? If any extra ABAP statements required, please suggest me.

Thanks in advance for your help.

  • Read SRQ document from Application Server

DATA: BEGIN OF INT_SRQ OCCURS 0,

FIELD(256),

END OF INT_SRQ.

DATA: WS_FILE1(100) VALUE '/tmp/safety_questionaire.pdf'.

OPEN DATASET WS_FILE1 FOR INPUT IN BINARY MODE.

DO.

READ DATASET WS_FILE1 INTO INT_SRQ-FIELD.

IF SY-SUBRC EQ 0.

APPEND INT_SRQ.

ELSE.

EXIT.

ENDIF.

ENDDO.

  • Read Insurance document from Application Server

DATA: BEGIN OF INT_INSURANCE OCCURS 0,

FIELD(256),

END OF INT_INSURANCE.

DATA: WS_FILE2(100) VALUE '/tmp/insurance.pdf'.

OPEN DATASET WS_FILE2 FOR INPUT IN BINARY MODE.

DO.

READ DATASET WS_FILE2 INTO INT_INSURANCE-FIELD.

IF SY-SUBRC EQ 0.

APPEND INT_INSURANCE.

ELSE.

EXIT.

ENDIF.

ENDDO.

*****************************************************************

data: itcpo like itcpo,

tab_lines like sy-tabix.

  • Variables for EMAIL functionality

data: maildata like sodocchgi1.

data: mailpack like sopcklsti1 occurs 2 with header line.

data: mailhead like solisti1 occurs 1 with header line.

data: mailbin like solisti1 occurs 10 with header line.

data: mailtxt like solisti1 occurs 10 with header line.

data: mailrec like somlrec90 occurs 0 with header line.

data: solisti1 like solisti1 occurs 0 with header line.

perform send_form_via_email.

if sy-subrc eq 0.

message i000(0) with 'e-mail sent successfully'.

endif.

************************************************************************

  • FORM SEND_FORM_VIA_EMAIL *

************************************************************************

form send_form_via_email.

clear: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.

refresh: mailtxt, mailbin, mailpack, mailhead, mailrec.

  • Creation of the document to be sent File Name

maildata-obj_name = 'SRQ '.

  • Mail Subject

maildata-obj_descr = Questionnaires.

  • Mail Contents

mailtxt-line = 'Questionnaires'.

append mailtxt.

  • Prepare Packing List

perform prepare_packing_list.

  • Set recipient - email address here!!!

mailrec-receiver = 'vamseekrishna_k@yahoo.co.in'.

mailrec-rec_type = 'U'.

append mailrec.

  • Sending the document

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = maildata

put_in_outbox = 'x'

tables

packing_list = mailpack

object_header = mailhead

contents_bin = mailbin

contents_txt = mailtxt

receivers = mailrec

exceptions

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

others = 99.

endform.

************************************************************************

  • Form PREPARE_PACKING_LIST

************************************************************************

form prepare_packing_list.

clear: mailpack, mailbin, mailhead.

refresh: mailpack, mailbin, mailhead.

describe table mailtxt lines tab_lines.

read table mailtxt index tab_lines.

maildata-doc_size = ( tab_lines - 1 ) * 255 + strlen( mailtxt ).

  • Creation of the entry for the compressed document

clear mailpack-transf_bin.

mailpack-head_start = 1.

mailpack-head_num = 0.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'RAW'.

append mailpack.

mailhead = 'TEST.pdf'.

append mailhead.

  • File 1

CALL FUNCTION 'QCE1_CONVERT'

TABLES

T_SOURCE_TAB = INT_SRQ

T_TARGET_TAB = mailbin.

append mailbin.

*CLEAR:TAB_LINES.

describe table mailbin lines tab_lines.

READ TABLE MAILBIN INDEX TAB_LINES.

mailpack-transf_bin = 'X'.

mailpack-head_start = 1.

mailpack-head_num = 0.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'PDF'.

mailpack-obj_name = 'TEST1'.

mailpack-obj_descr = 'attach1'.

mailpack-doc_size = tab_lines * 255.

append mailpack.

IF SY-SUBRC EQ 0.

MESSAGE I000(2) WITH 'FILE1 READ IS OKAY'.

ENDIF.

**File 2

CALL FUNCTION 'QCE1_CONVERT'

TABLES

T_SOURCE_TAB = INT_INSURANCE

T_TARGET_TAB = mailbin.

*

append mailbin.

data:TAB_LINES2 type i.

DESCRIBE TABLE MAILBIN LINES TAB_LINES2.

READ TABLE MAILBIN INDEX TAB_LINES2.

*

data: start type i.

data: end type i.

end = TAB_LINES2.

start = tab_lines + 1.

*

  • describe table mailbin lines end.

*

mailpack-transf_bin = 'X'.

mailpack-head_start = 1.

mailpack-head_num = 0.

mailpack-body_start = start.

mailpack-body_num = end.

mailpack-doc_type = 'PDF'.

mailpack-obj_name = 'TEST2'.

mailpack-obj_descr = 'attach2'.

mailpack-doc_size = ( tab_lines2 - 1 ) * 255 + strlen( mailBIN ).

append mailpack.

**

if sy-subrc eq 0.

message i000(1) with 'file 2 read ok'.

endif.

endform.

8 REPLIES 8

Former Member
0 Kudos
348

hi vamsi gimme ur mail id i will send the code to u.

0 Kudos
348

Hi Prasad,

Thanks for your help.

My E-mail is k.vamsee@boci.co.in

Can you please send me the code?

0 Kudos
348

Hi Prasad,

I rectified my error and now i can view both the attachments.

Thanks.

0 Kudos
348

hi,

how u solved it. pls explain..will helpful for others..

rgds

Anver

0 Kudos
348

Hi Vamsee,

I have similar requirement. I tried your code by making some corrections, but I am getting error as 'File is damaged' when I tried to open files.

It would be helpful if you paste your code here.

Thanks in advance.

regards,

Ram.

0 Kudos
348

Hi.

I have the same issue and my code is almost identical to sample code. I can view the first PDF in my email but not the 2nd PDF. Can you help me?

V

Former Member
0 Kudos
348

Hi,

Check for logic in the standard FM 'FI_SEND_PDF', if this FM is not available see sap note 976306.

Regards,

Bhaskar

raisaansari
Explorer
0 Kudos
348

CLEAR DDATA.
DDATA-OBJ_NAME = 'NAME-1'.
DDATA-OBJ_SORT = 'NAME-1' .

DDATA-OBJ_EXPDAT = SY-DATUM.
DDATA-SENSITIVTY = 'P'.
DDATA-NO_CHANGE = 'X'.
DDATA-PRIORITY = '1'.
DDATA-OBJ_PRIO = '1'.
DDATA-OBJ_LANGU = SY-LANGU.
DDATA-NO_CHANGE = 'X'.

REFRESH TXT.
CLEAR TXT.

TXT-LINE = 'EMAIL SUBJECT'.
APPEND TXT.

DESCRIBE TABLE TXT LINES TAB_LINES.
READ TABLE TXT INDEX TAB_LINES.
DDATA-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( TXT ).

CLEAR HEADER.
REFRESH HEADER.
HEADER-LINE = 'PDF'

APPEND HEADER.

REFRESH BIN.
CLEAR: BIN, PDF_LINES, PDF_STRING, PDF_SIZE, PDF_LINES2, PDF_STRING2, PDF_SIZE2..

LOOP AT PDF_FILE.
TRANSLATE PDF_FILE USING ' ~'.
CONCATENATE PDF_STRING PDF_FILE INTO PDF_STRING.
ENDLOOP.

LOOP AT PDF_FILE2.
TRANSLATE PDF_FILE2 USING ' ~'.
CONCATENATE PDF_STRING2 PDF_FILE2 INTO PDF_STRING2.
ENDLOOP.

TRANSLATE PDF_STRING USING '~ '.
TRANSLATE PDF_STRING2 USING '~ '.

DO.
TEXT255 = PDF_STRING.
APPEND TEXT255 TO BIN.
CLEAR TEXT255 .

SHIFT PDF_STRING LEFT BY 255 PLACES.
IF PDF_STRING IS INITIAL.
EXIT.
ENDIF.
ENDDO.

DO.
TEXT255 = PDF_STRING2.
APPEND TEXT255 TO BIN2.
CLEAR TEXT255 .

SHIFT PDF_STRING2 LEFT BY 255 PLACES.
IF PDF_STRING2 IS INITIAL.
EXIT.
ENDIF.
ENDDO.

DESCRIBE TABLE BIN LINES PDF_LINES.
DESCRIBE TABLE BIN2 LINES PDF_LINES2.
READ TABLE BIN INDEX PDF_LINES.
PDF_SIZE = ( PDF_LINES - 1 ) * 255 + STRLEN( BIN ).

READ TABLE BIN2 INDEX PDF_LINES2.
PDF_SIZE2 = ( PDF_LINES2 - 1 ) * 255 + STRLEN( BIN2 ).

APPEND LINES OF BIN2 TO BIN.

REFRESH: PLIST.
CLEAR: PLIST.

PLIST-TRANSF_BIN = SPACE.
PLIST-HEAD_START = 1.
PLIST-HEAD_NUM = 0.
PLIST-BODY_START = 1.
PLIST-BODY_NUM = TAB_LINES.
PLIST-DOC_TYPE = 'RAW'.
APPEND PLIST.

PLIST-TRANSF_BIN = 'X'.
PLIST-HEAD_START = 1.
PLIST-HEAD_NUM = 1.
PLIST-BODY_START = 1.
PLIST-BODY_NUM = PDF_LINES.
PLIST-DOC_TYPE = 'PDF'.
PLIST-OBJ_NAME = 'ATTACHMENT'.
PLIST-OBJ_DESCR = 'FILE-1'.
PLIST-DOC_SIZE = PDF_SIZE.
APPEND PLIST.

PLIST-TRANSF_BIN = 'X'.
PLIST-HEAD_START = 1.
PLIST-HEAD_NUM = 1.
PLIST-BODY_START = PDF_LINES + 1.
PLIST-BODY_NUM = PDF_LINES2.
PLIST-DOC_TYPE = 'PDF'.
PLIST-OBJ_NAME = 'ATTACHMENT'.
PLIST-OBJ_DESCR = 'FILE-2'.
PLIST-DOC_SIZE = PDF_SIZE2.
APPEND PLIST.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DDATA
PUT_IN_OUTBOX = SPACE
COMMIT_WORK = 'X'
SENDER_ADDRESS = 'WF-BATCH'
SENDER_ADDRESS_TYPE = 'B'
TABLES
OBJECT_HEADER = HEADER
PACKING_LIST = PLIST
CONTENTS_BIN = BIN
RECEIVERS = RECV
CONTENTS_TXT = TXT
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.
EMAIL_COUNT = EMAIL_COUNT + 1.
ENDIF.