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: 

Bug sending email with Excel file (immediate reply would he helpfull)

Former Member
0 Kudos

Hi ,

Below is have pasted a sample code where it will sends a email along with an attachtment (xls) .where the email is working perfectly but the xls file attachtment has a blank space in the first line .

where iam facing the problem ,

ie there should not be any blank lines at the top .

Please run the code one i have pasted below .u can find the bug .

can any one help me on this .

please have ur mail id in ( reclist-receiver ) so that u can check for the output.

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

  • 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.

*CREATION OF INTERNAL TABLE

DATA : BEGIN OF itobjbin OCCURS 10 ,

vbeln type vbrp-vbeln,

matnr type vbrp-matnr,

werks type vbrp-werks,

fktyp like vbrk-fktyp,

END OF itobjbin .

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

*DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: objbin TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

DATA: wa_itobjbin LIKE itobjbin .

  • 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_chng LIKE sodocchgi1.

DATA: tab_lines LIKE sy-tabix.

DATA : V_FKTYP LIKE VBRK-FKTYP.

  • Creating the document to be sent

doc_chng-obj_name = 'OFFER'. " input contains the attributes of the document to be sent

doc_chng-obj_descr = 'EMAIL WITH EXCEL DOWNLOAD'. "input contains title/subject of the document

*BODY OF THE MAIL

OBJTXT = 'Hi'.

APPEND OBJTXT .

OBJTXT = 'Test for excel download'.

APPEND OBJTXT.

OBJTXT = 'Below is the attachment with Billing Document Details'.

APPEND OBJTXT.

OBJTXT = 'Regards'.

APPEND OBJTXT.

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

  • Creating the entry for the compressed document

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.

  • Creating the document attachment

  • (Assume the data in OBJBIN are given in BMP format)

select vbeln matnr werks

from vbrp into table itobjbin

up to 10 rows

where werks GE '1000'.

loop at itobjbin.

select single fktyp into v_fktyp from vbrk where vbeln = itobjbin-vbeln.

move v_fktyp to itobjbin-fktyp.

modify itobjbin.

endloop.

PERFORM build_xls_data_table .

DESCRIBE TABLE objbin LINES tab_lines.

objhead = 'ABC.XLS'. 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 = 'XLS'.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = 'XLS'.

objpack-doc_size = tab_lines * 255.

APPEND objpack..

  • Entering names in the distribution list

reclist-receiver = ''.

reclist-rec_type = 'U'.

APPEND reclist.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = 'X'

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 send process:'.

LOOP AT reclist.

WRITE: / reclist-receiver(48), ':'.

IF reclist-retrn_code = 0.

WRITE 'sent successfully'.

ELSE.

WRITE 'not sent'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'no authorization to send to the specified number of', 'recipients!'.

WHEN 2.

WRITE: / 'document could not be sent to any of the recipients!'.

WHEN 4.

WRITE: / 'no authorization to send !'.

WHEN OTHERS.

WRITE: / 'error occurred during sending !'.

ENDCASE.

&----


*& Form build_xls_data_table

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_xls_data_table .

CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode

con_tab TYPE x VALUE '09'. "OK for non Unicode

CONCATENATE 'Billing Document' 'Material Number' 'Plant' 'Billing category' ' ' INTO objbin SEPARATED BY con_tab.

CONCATENATE con_cret objbin INTO objbin.

APPEND objbin.

LOOP AT itobjbin .

CONCATENATE itobjbin-vbeln itobjbin-matnr itobjbin-werks itobjbin-fktyp' '

INTO objbin SEPARATED BY con_tab.

CONCATENATE con_cret objbin INTO objbin.

APPEND objbin.

ENDLOOP.

thanks in advance,

vinay .

8 REPLIES 8

former_member181962
Active Contributor
0 Kudos

Change this code as suggested :

FORM build_xls_data_table .

CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode

con_tab TYPE x VALUE '09'. "OK for non Unicode

CONCATENATE 'Billing Document' 'Material Number' 'Plant' 'Billing category' ' ' INTO objbin SEPARATED BY con_tab.

APPEND objbin.

LOOP AT itobjbin .

CONCATENATE itobjbin-vbeln itobjbin-matnr itobjbin-werks itobjbin-fktyp' '

INTO objbin SEPARATED BY con_tab.

CONCATENATE con_cret objbin INTO objbin.

APPEND objbin.

ENDLOOP.

Reward points for helpful posts.

REgards,

Ravi

0 Kudos

Hi Ravi ,

what u have suggested is the was perfect .the code one i have sent was a sample one which is working for it .

but the code one we are using faces the same problem again .

i found the place where the bug has occuring but i cant able to solve it .

i feel this is the place where the problem occurs .

CONSTANTS:

row TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

coloumn TYPE c VALUE cl_abap_char_utilities=>cr_lf.

**

LOOP AT attachment.

REPLACE ALL OCCURRENCES OF '#' IN attachment WITH row . "INTO objbin.

CONCATENATE coloumn attachment INTO objbin.

attachment = objbin.

APPEND objbin.

ENDLOOP.

please let me know how to resolve it .

Thanks ,

shankar.

0 Kudos

HI VInay,

Change the code as follows:

LOOP AT attachment.

REPLACE ALL OCCURRENCES OF '#' IN attachment WITH row . "INTO objbin.

<b>CONCATENATE attachment coloumn INTO objbin.</b>

attachment = objbin.

APPEND objbin.

ENDLOOP.

The probelm is that you are concatenating a newline indicator withh some string.

The newline is coming first and thats why i reversed the order of concatenation.

REgards,

Ravi

P.S: PLease reward points if found helpful.

REgards,

Ravi

0 Kudos

Hi ravi ,

Thanks ,for your help .now xls is working fine .

but now iam facing a problem with the same function module .for txt files .where all the records are formated in asingle line .

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

below is have attached the sample code .

Thanks,

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.

0 Kudos

Hi ravi,

Thanks , for your help ravi now iam getting a prefect out put for both XLS and TXT attachtments ,but a small problem iam facing on xls .

the formation of the fileds are correct but the entire last column is taking up 255 char .

solution on this would be helpfull .

Thanks ,

shankar.

I have attached the sample code too.

FUNCTION zemail_send_attachment.

*"----


""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' .

LOOP AT attach_file .

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

IF sy-tabix = 1.

MOVE attach_file TO objbin.

ELSE.

CONCATENATE con_tab attach_file INTO objbin.

ENDIF.

APPEND objbin.

ENDLOOP.

ELSEIF atype = 'TXT' .

  • Convert IT to Text format

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.

ENDIF.

****

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.

IF atype = 'XLS'.

objpack-doc_type = atype.

ELSEIF atype = 'TXT'.

objpack-doc_type = 'RAW'.

ENDIF.

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.

0 Kudos

Hi ravi

this problem is happening only if the field values of numeric ie(88282)

if it is a char or alphanumeric .

the problem is not there .

Thanks ,

shankar.

0 Kudos

Hi I am having a similar problem.

I am not sure what will be the value of 'row' and 'column' at runtime.

I am gettting '#' for both , when I define the constant as given below.

I am in ECC5 version. that has a check on Unicode at the program attribute level.

And also I am not getting any data into the excel attached in the mail .

CONSTANTS:

row TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

coloumn TYPE c VALUE cl_abap_char_utilities=>cr_lf.

**

appreciate your help

David

venkat_o
Active Contributor
0 Kudos

Hello Vinay,

Check these links ,

<b>1</b>.

<b>2</b>.

These can help u.

<b>Thanks,

Venkat.O</b>