Application Development and Automation 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: 
Read only

wrong format on text file using SO_NEW_DOCUMENT_ATT_SEND_API1 FM

Former Member
0 Likes
951

Hi All!!

I've been looking in the forum but couldn't find the solution...

I'm using this FM to send a text file by email.

I got the email and the file attached but the file is not right

I shoud get:

texttexttexttext blablabla texttexttexttext

texttexttexttext blablabla texttexttexttext

texttexttexttext blablabla texttexttexttext

texttexttexttext blablabla texttexttexttext

but I'm getting

texttexttexttext blablabla texttexttexttext

. ...................................... texttexttexttext blablabla texttexttexttext

. ....................................... ...................................... texttexttexttext blablabla texttexttexttext

. ....................................... ....................................... ...................................... texttexttexttext blablabla texttexttexttext

(dots are not being displayed)

I've tried concatenating '0A' or '09' at the end of each line but I'm still getting the wrong alinegment.

Any idea?

Thanks.

Edited by: Ina on Sep 15, 2009 1:01 PM

Edited by: Ina on Sep 15, 2009 1:02 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
802

***********Declarations *******************************

constants : c_cret(2) TYPE c VALUE cl_abap_char_utilities=>cr_lf,

c_tab(2) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

DATA : i_objtxt TYPE STANDARD TABLE OF solisti1, " Internal table to hold Mail details

i_objpack TYPE STANDARD TABLE OF sopcklsti1, " Internal table to hold Mail details

i_objhead TYPE STANDARD TABLE OF solisti1, " Internal table for the Mail data

i_objbin TYPE STANDARD TABLE OF solisti1, " Internal table to hold the Object text

i_rcvrs TYPE STANDARD TABLE OF somlreci1.

DATA : wa_objtxt LIKE LINE OF i_objtxt,

wa_objpack LIKE LINE OF i_objpack,

wa_objhead LIKE LINE OF i_objhead,

wa_objbin LIKE LINE OF i_objbin,

wa_rcvrs LIKE LINE OF i_rcvrs.

********Send Mail***************************************

DATA : l_lines TYPE i.

DATA : l_attlines TYPE i.

  • Mail Body text

wa_objtxt-line = title

APPEND wa_objtxt TO i_objtxt.

DESCRIBE TABLE i_objtxt LINES l_lines.

*Document Attributes

i_doc_chng-obj_name = 'TEST'. " input contains the attributes of the document to be sent

i_doc_chng-obj_descr = 'bla bla bla'

  • Mail details

CLEAR wa_objpack.

wa_objpack-head_start = c_1.

wa_objpack-head_num = c_0.

wa_objpack-body_start = c_1.

wa_objpack-body_num = l_lines.

wa_objpack-doc_type = 'RAW'.

APPEND wa_objpack TO i_objpack.

IF NOT i_output IS INITIAL.

LOOP AT i_output INTO wa_output.

CONCATENATE wa_output-matnr1 wa_output-text INTO wa_objbin SEPARATED BY c_tab. "first line

CONCATENATE c_cret wa_objbin INTO wa_objbin.

APPEND wa_objbin TO i_objbin.

ENDLOOP.

DESCRIBE TABLE i_objbin LINES l_attlines.

READ TABLE i_objbin INTO wa_objbin INDEX l_attlines.

CLEAR wa_objpack.

wa_objpack-transf_bin = 'X'.

wa_objpack-head_start = c_1.

wa_objpack-head_num = c_0.

wa_objpack-body_start = c_1.

wa_objpack-body_num = l_attlines.

wa_objpack-doc_type = 'TXT' .

wa_objpack-obj_name = text-201.

wa_objpack-obj_descr = text-201.

wa_objpack-doc_size = ( l_attlines - 1 ) * 255

+ STRLEN( wa_objbin ).

APPEND wa_objpack TO i_objpack.

MOVE p_list TO wa_rcvrs-receiver.

wa_rcvrs-rec_type = 'U' " Internet ID

wa_rcvrs-rec_date = ''.

PERFORM touppercase CHANGING wa_rcvrs.

APPEND wa_rcvrs TO i_rcvrs.

CLEAR wa_rcvrs.

wa_objhead-line = text-201.

APPEND wa_objhead TO i_objhead.

  • Call function to send the mail

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = i_doc_chng

put_in_outbox = c_x

commit_work = c_x

TABLES

packing_list = i_objpack

object_header = i_objhead

contents_bin = i_objbin

contents_txt = i_objtxt

receivers = i_rcvrs

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.

CASE sy-subrc.

WHEN '0'.

WAIT UP TO 2 SECONDS.

SUBMIT rsconn01 WITH mode = 'INT'

AND RETURN.

MESSAGE s010(ad) WITH 'Mail Sent Successfully'(i50).

ENSCASE.

Try this code with your data, this should work.

Edited By Tejaswini Khante

7 REPLIES 7
Read only

Former Member
0 Likes
802

Hi,

Can you post the code snippet for attaching the attachment and the FM for sending the E-mail?

Regards,

Vikranth

Read only

0 Likes
802

Here it is

FORM send_input_file_by_email .

IF gt_infile[] IS NOT INITIAL AND

sp_rece[] IS NOT INITIAL.

LOOP AT gt_infile INTO i_filetab.

CONCATENATE i_filetab cl_abap_char_utilities=>cr_lf(1) INTO i_filetab.

APPEND i_filetab.

CLEAR i_filetab.

ENDLOOP.

  • File name

v_doc_data-obj_name = 'SENDFILE'.

  • Mail subject

v_doc_data-obj_descr = 'bla bla bla'.

  • Mail contents - this appears as the lines within the email

i_cont_txt = 'bla bla bla'.

APPEND i_cont_txt.

DESCRIBE TABLE i_cont_txt LINES l_lines.

READ TABLE i_cont_txt INDEX l_lines.

v_doc_data-doc_size = ( l_lines - 1 ) * 255 + STRLEN( i_cont_txt ).

  • Creation of the entry for the compressed document

CLEAR i_packlist-transf_bin.

i_packlist-head_start = 1.

i_packlist-head_num = 1.

i_packlist-body_start = 1.

i_packlist-body_num = l_lines.

i_packlist-doc_type = 'RAW'.

APPEND i_packlist.

  • i_cont_hex contains the file data

APPEND LINES OF i_filetab TO i_cont_hex.

DESCRIBE TABLE i_cont_hex LINES l_lines.

i_objhead = sp_file. "name of the attachment

APPEND i_objhead.

    • Creation of the entry for the compressed attachment

i_packlist-transf_bin = 'X'.

i_packlist-head_start = 1.

i_packlist-head_num = 0.

i_packlist-body_start = 1.

i_packlist-body_num = l_lines.

i_packlist-doc_type = 'TXT'.

i_packlist-obj_name = sp_file.

i_packlist-obj_descr = sp_file.

i_packlist-doc_size = l_lines * 255.

APPEND i_packlist.

  • Completing the recipient list

  • target recipent

LOOP AT sp_rece.

CLEAR i_rec.

i_rec-receiver = sp_rece-low.

i_rec-rec_type = 'U'.

APPEND i_rec.

ENDLOOP.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = v_doc_data

commit_work = 'X'

TABLES

packing_list = i_packlist

object_header = i_objhead

contents_txt = i_cont_txt

contents_hex = i_cont_hex

receivers = i_rec

EXCEPTIONS

OTHERS = 8.

ENDIF.

ENDFORM.

Read only

0 Likes
802

I will suggest to use


CALL FUNCTION 'LIST_FROM_MEMORY'
       TABLES
            LISTOBJECT = IT_LIST
       EXCEPTIONS
            NOT_FOUND  = 1
            OTHERS     = 2.
 
  IF SY-SUBRC = 0.
    CALL FUNCTION 'LIST_TO_ASCI'
         TABLES
              LISTASCI           = IT_ASC
              LISTOBJECT         = IT_LIST
         EXCEPTIONS
              EMPTY_LIST         = 1
              LIST_INDEX_INVALID = 2
              OTHERS             = 3.
  ENDIF.

a®

Read only

0 Likes
802

Hi,

Use this code for formating attachment in the pdf.

  • Transfer the 132-long strings to 255-long strings

LOOP AT i_pdf_output.

TRANSLATE i_pdf_output USING ' ~'.

CONCATENATE lv_buffer i_pdf_output INTO lv_buffer.

ENDLOOP.

TRANSLATE lv_buffer USING '~ '.

DO.

i_mess_att = lv_buffer.

APPEND i_mess_att.

SHIFT lv_buffer LEFT BY 255 PLACES.

IF lv_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

  • Fill the document data and get size of attachment

CLEAR wa_doc_data.

READ TABLE i_mess_att INDEX wa_cnt.

wa_doc_data-doc_size = ( wa_cnt - 1 ) * 255 + STRLEN( i_mess_att ).

wa_doc_data-obj_langu = sy-langu.

wa_doc_data-obj_name = 'Price List'.

wa_doc_data-obj_descr = 'Customer Price List'.

wa_doc_data-sensitivty = 'F'.

Regards,

Vijay

Read only

0 Likes
802

Hi,

Try with the following code changes,


data:  t_objbin         like  solisti1    occurs 0 with header line,
          t_contents       like  solisti1    occurs 0 with header line.

FORM send_input_file_by_email .
IF gt_infile[] IS NOT INITIAL AND
sp_rece[] IS NOT INITIAL.

LOOP AT gt_infile INTO i_filetab.
CONCATENATE i_filetab cl_abap_char_utilities=>cr_lf(1) INTO i_filetab.
APPEND i_filetab.
CLEAR i_filetab.
ENDLOOP.

* File name
v_doc_data-obj_name = 'SENDFILE'.
* Mail subject
v_doc_data-obj_descr = 'bla bla bla'.

t_objbin = 'bla bla bla'.                            " Content of the body of the mail
APPEND t_objbin.

DESCRIBE TABLE i_cont_txt LINES l_lines.
READ TABLE i_cont_txt INDEX l_lines.
v_doc_data-doc_size = ( l_lines - 1 ) * 255 + STRLEN( i_cont_txt ).

* Creation of the entry for the compressed document
CLEAR i_packlist-transf_bin.
i_packlist-head_start = 1.
i_packlist-head_num = 1.
i_packlist-body_start = 1.
i_packlist-body_num = l_lines.
i_packlist-doc_type = 'RAW'.
APPEND i_packlist.

APPEND LINES OF i_filetab TO t_content.         "Content of the attachment

DESCRIBE TABLE i_cont_hex LINES l_lines.
i_objhead = sp_file. "name of the attachment
APPEND i_objhead.


** Creation of the entry for the compressed attachment
i_packlist-transf_bin = 'X'.
i_packlist-head_start = 1.
i_packlist-head_num = 0.
i_packlist-body_start = 1.
i_packlist-body_num = l_lines.
i_packlist-doc_type = 'TXT'.
i_packlist-obj_name = sp_file.
i_packlist-obj_descr = sp_file.
i_packlist-doc_size = l_lines * 255.
APPEND i_packlist.


* Completing the recipient list
* target recipent
LOOP AT sp_rece.
CLEAR i_rec.
i_rec-receiver = sp_rece-low.
i_rec-rec_type = 'U'.
APPEND i_rec.
ENDLOOP.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = v_doc_data
commit_work = 'X'
TABLES
packing_list = i_packlist
object_header = i_objhead
contents_bin  = t_objbin                  " Newly added which consists of the body of the mail
contents_txt = t_content                " Add the attachments here
receivers = i_rec
EXCEPTIONS
OTHERS = 8.
ENDIF.
ENDFORM.

Regards,

Vikranth

Read only

Former Member
0 Likes
803

***********Declarations *******************************

constants : c_cret(2) TYPE c VALUE cl_abap_char_utilities=>cr_lf,

c_tab(2) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

DATA : i_objtxt TYPE STANDARD TABLE OF solisti1, " Internal table to hold Mail details

i_objpack TYPE STANDARD TABLE OF sopcklsti1, " Internal table to hold Mail details

i_objhead TYPE STANDARD TABLE OF solisti1, " Internal table for the Mail data

i_objbin TYPE STANDARD TABLE OF solisti1, " Internal table to hold the Object text

i_rcvrs TYPE STANDARD TABLE OF somlreci1.

DATA : wa_objtxt LIKE LINE OF i_objtxt,

wa_objpack LIKE LINE OF i_objpack,

wa_objhead LIKE LINE OF i_objhead,

wa_objbin LIKE LINE OF i_objbin,

wa_rcvrs LIKE LINE OF i_rcvrs.

********Send Mail***************************************

DATA : l_lines TYPE i.

DATA : l_attlines TYPE i.

  • Mail Body text

wa_objtxt-line = title

APPEND wa_objtxt TO i_objtxt.

DESCRIBE TABLE i_objtxt LINES l_lines.

*Document Attributes

i_doc_chng-obj_name = 'TEST'. " input contains the attributes of the document to be sent

i_doc_chng-obj_descr = 'bla bla bla'

  • Mail details

CLEAR wa_objpack.

wa_objpack-head_start = c_1.

wa_objpack-head_num = c_0.

wa_objpack-body_start = c_1.

wa_objpack-body_num = l_lines.

wa_objpack-doc_type = 'RAW'.

APPEND wa_objpack TO i_objpack.

IF NOT i_output IS INITIAL.

LOOP AT i_output INTO wa_output.

CONCATENATE wa_output-matnr1 wa_output-text INTO wa_objbin SEPARATED BY c_tab. "first line

CONCATENATE c_cret wa_objbin INTO wa_objbin.

APPEND wa_objbin TO i_objbin.

ENDLOOP.

DESCRIBE TABLE i_objbin LINES l_attlines.

READ TABLE i_objbin INTO wa_objbin INDEX l_attlines.

CLEAR wa_objpack.

wa_objpack-transf_bin = 'X'.

wa_objpack-head_start = c_1.

wa_objpack-head_num = c_0.

wa_objpack-body_start = c_1.

wa_objpack-body_num = l_attlines.

wa_objpack-doc_type = 'TXT' .

wa_objpack-obj_name = text-201.

wa_objpack-obj_descr = text-201.

wa_objpack-doc_size = ( l_attlines - 1 ) * 255

+ STRLEN( wa_objbin ).

APPEND wa_objpack TO i_objpack.

MOVE p_list TO wa_rcvrs-receiver.

wa_rcvrs-rec_type = 'U' " Internet ID

wa_rcvrs-rec_date = ''.

PERFORM touppercase CHANGING wa_rcvrs.

APPEND wa_rcvrs TO i_rcvrs.

CLEAR wa_rcvrs.

wa_objhead-line = text-201.

APPEND wa_objhead TO i_objhead.

  • Call function to send the mail

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = i_doc_chng

put_in_outbox = c_x

commit_work = c_x

TABLES

packing_list = i_objpack

object_header = i_objhead

contents_bin = i_objbin

contents_txt = i_objtxt

receivers = i_rcvrs

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.

CASE sy-subrc.

WHEN '0'.

WAIT UP TO 2 SECONDS.

SUBMIT rsconn01 WITH mode = 'INT'

AND RETURN.

MESSAGE s010(ad) WITH 'Mail Sent Successfully'(i50).

ENSCASE.

Try this code with your data, this should work.

Edited By Tejaswini Khante

Read only

0 Likes
802

tHANKS Tejaswini Khante

I have to find the difference with my code but yours solved my problem.

Thanks a lot.