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: 

problem when sending an attachment in mail

Former Member
0 Kudos

Hi,

I'm using the function SO_NEW_DOCUMENT_ATT_SEND_API1 to send an attachment in a mail.

I have 2 questions.

1. When I look at example programs of this kind, people always use 255 characters in the attachment. My line in the txt attachment is 280 characters. Is that a problem? Does it have to be 255?

2. When I send the txt as an attachment and I open it later, the 3 lines of data are displayed in 1 line, one after another. They should be 3 lines though.

I paste my code, just in case.

THX!

FORM enviar_fichero.

  • Structures and internal tables for the send data

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

DATA: DOC_SIZE(12) TYPE N.

DATA: compressed_list LIKE SOLI OCCURS 0.

DATA G_DOC_TYPE LIKE SOODK-OBJTP VALUE 'TXT'.

DATA: l_nom_report LIKE rsvar-report.

DATA MyNumber TYPE I.

DATA: RECIPIENT_INT LIKE SADRUD.

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

  • Send the document by calling the SAPoffice API1 module *

  • for sending documents with attachments *

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

  • Data for the status output after sending

DATA: USER_ADDRESS LIKE SOUSRADRI1 OCCURS 1 WITH HEADER LINE.

DATA: SENT_TO_ALL LIKE SONV-FLAG.

  • move list to office table objbin

MOVE i_datos[] TO OBJBIN[].

  • G_DOC_TYPE = LC_TIPOFIC.

  • Fill the fields of the packing_list for the main document:

  • It is a text document

CLEAR OBJPACK-TRANSF_BIN.

  • The document needs no header (head_num = 0)

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

  • but it has a body

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

  • of type TXT

OBJPACK-DOC_TYPE = 'TXT'.

APPEND OBJPACK.

  • Create the attachment (the list itself)

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

  • Fill the fields of the packing_list for the attachment:

  • It is binary document

OBJPACK-TRANSF_BIN = 'X'.

  • we need no header

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

  • but a body

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

  • of type G_DOC_TYPE

OBJPACK-DOC_TYPE = G_DOC_TYPE.

OBJPACK-OBJ_NAME = 'Attachment'.

OBJPACK-OBJ_DESCR = 'fichero para NACEX REEMBOLSO'.

DOC_CHNG-OBJ_DESCR = 'fichero para NACEX REEMBOLSO'.

READ TABLE OBJBIN INDEX TAB_LINES.

DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJBIN ).

OBJPACK-DOC_SIZE = DOC_SIZE.

APPEND OBJPACK.

  • INT - Fill the mail recipient list

LOOP AT S_mail.

RECIPIENT_INT-ADDRESS = s_mail-low.

RECLIST-RECEIVER = RECIPIENT_INT.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

endloop.

  • Send the document by calling the SAPoffice API1 module

  • for sending documents with attachments

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

PUT_IN_OUTBOX = 'X'

IMPORTING

SENT_TO_ALL = SENT_TO_ALL

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

CASE SY-SUBRC.

WHEN 0.

  • WRITE: / 'Result of the sendprocess:'.

IF NOT SENT_TO_ALL IS INITIAL.

  • WRITE: / 'Successfully sent to all recipients.'.

ELSE.

LOOP AT RECLIST WHERE RETRN_CODE NE 0.

REFRESH USER_ADDRESS.

CLEAR USER_ADDRESS.

USER_ADDRESS-USERID = RECLIST-REC_ID.

APPEND USER_ADDRESS.

CALL FUNCTION 'SO_USER_ADDRESS_READ_API1'

TABLES

USER_ADDRESS = USER_ADDRESS

EXCEPTIONS

ENQUEUE_ERRROR = 1

PARAMETER_ERROR = 2

X_ERROR = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

USER_ADDRESS-LONG_NAME = RECLIST-REC_ID.

ENDIF.

WRITE: / 'Could not send to: '.

WRITE: USER_ADDRESS-LONG_NAME(48).

ENDLOOP.

LOOP AT RECLIST WHERE RETRN_CODE EQ 0.

ENDLOOP.

IF SY-SUBRC = 0.

WRITE: / 'Successfully sent to all other recipients.'.

ENDIF.

ENDIF.

WHEN 1.

WRITE: / 'No permission to sent to the specified ',

'amount of recipients !'.

WHEN 2.

WRITE: / 'Document could not be sent to any recipient !'.

WHEN 4.

WRITE: / 'No permission to send !'.

WHEN OTHERS.

WRITE: / 'Error while sending !'.

ENDCASE.

ENDFORM. " send

Edited by: christophe latinne on Apr 3, 2009 1:49 PM

Edited by: christophe latinne on Apr 3, 2009 1:53 PM

2 REPLIES 2

Former Member
0 Kudos

HI

if you wan to use more size you may go for creating one more work area of type sopcklsti1

and append it to the internal table

for eg:

ls_objpack TYPE sopcklsti1,

ls_objpack1 TYPE sopcklsti1,

lt_objpack TYPE TABLE OF sopcklsti1,

append ls_objpack to lt_objpack

append ls_objpack1 to lt_objpack

shiva

Former Member
0 Kudos

Yes, your internal table length of 255 characters.

Regards,

Anand.