Skip to Content
0
Former Member
Jun 01, 2006 at 09:16 AM

Email attachtment as TXT

18 Views

Hi ,

Below i have attached a sample of code ,which will send email along with attachtment ,which is working fine for excel attachtment .

where as am facing a problem with for txt files .where all the records are formated in asingle line .

can any one provide a solution for this ,which would be very helpfull.

below is have attached the sample code .

Thanks in advance,

vinay.

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

FUNCTION Z_KAILASH_ATTACHMENT1.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(EMAILID)

*" VALUE(SUBJECT)

*" VALUE(ATYPE)

*" TABLES

*" ATTACH_FILE STRUCTURE SOLISTI1

*" BODY OPTIONAL

*"----


  • This table requires information about how the data in the

  • tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are

  • to be distributed to the documents and its attachments.

DATA OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

  • This table must contain the summarized data dependent on each object type.

  • SAPscript objects store information here about forms and styles,

  • for example. Excel list viewer objects store the number of rows and columns

  • amongst other things and PC objects store their original file name.

DATA OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

  • This table must contain the summarized content of the objects identified as binary objects.

DATA OBJBIN TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

  • This table must contain the summarized content of the objects identified as ASCII objects.

DATA OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

  • This table must contain the document recipients.

DATA RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE .

  • This structure must contain the attributes of the document to be sent.

DATA: DOC_CHING LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

  • Create the internal table for body , subject

DATA: IT_BODY LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

CONSTANTS: con_cret TYPE C VALUE cl_abap_char_utilities=>horizontal_tab,

con_tab TYPE C VALUE cl_abap_char_utilities=>cr_lf.

  • Move Body to Internal Table (body into it_body)

LOOP AT BODY .

MOVE BODY TO IT_BODY .

APPEND IT_BODY .

ENDLOOP.

DOC_CHING-OBJ_DESCR = SUBJECT. "Subject of the Email

  • Move the Subject and Body to OBJTXT

OBJTXT[] = IT_BODY[].

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

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

CLEAR OBJPACK-TRANSF_BIN.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'RAW'.

APPEND OBJPACK.

  • Convert IT to Excel format

IF ATYPE = 'XLS' .

*CONSTANTS: con_cret TYPE C VALUE cl_abap_char_utilities=>horizontal_tab,

  • con_tab TYPE C VALUE cl_abap_char_utilities=>cr_lf.

LOOP AT ATTACH_FILE .

REPLACE ALL OCCURRENCES OF '#' IN ATTACH_FILE WITH con_cret. " INTO objbin.

CONCATENATE ATTACH_FILE con_tab INTO objbin.

APPEND objbin.

ENDLOOP.

ELSEIF ATYPE = 'TXT' .

LOOP AT ATTACH_FILE .

REPLACE ALL OCCURRENCES OF '#' IN ATTACH_FILE WITH con_tab. " INTO objbin.

CONCATENATE ATTACH_FILE ' ' INTO OBJBIN .

APPEND OBJBIN .

ENDLOOP.

ENDIF.

****End-Code Excel Format .

DESCRIBE TABLE objbin LINES tab_lines.

objhead = subject. APPEND objhead.

  • Creating the entry for the compressed attachment

*

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = TAB_LINES.

objpack-doc_type = ATYPE.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = 'TEST'. "Attachment File Name

objpack-doc_size = TAB_LINES * 255.

APPEND objpack..

reclist-receiver = EMAILID.

reclist-rec_type = 'U'.

APPEND reclist.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHING

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

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 .

ENDFUNCTION.