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

Send External email Problem

Former Member
0 Likes
1,104

Good morning,

I'm using FM SO_NEW_DOCUMENT_ATT_SEND_API1 to send an attachment file .txt to some email recipients.

The problem is that when i open the file in notepad, the content is all in one line. Otherwise, if i open the file in MSWord or other editors, the information is displayed correctly, following the pattern:

line1

line2

...

line i

I post the code, could you tell me if i'm coding something wrong?


REPORT  zmmc062d_2.

TABLES: lfa1.

DATA: BEGIN OF reg_sal OCCURS 10,
        cif(9),
        asterisco(1),
        codigo(10),
      END OF reg_sal.

DATA:
objpack       LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE,
doc_chng    LIKE sodocchgi1,
remitent      LIKE soextreci1-receiver,
objbin         LIKE  solisti1 OCCURS 10 WITH HEADER LINE,
objtxt         LIKE solisti1 OCCURS 10 WITH HEADER LINE,
tab_lines    LIKE sy-tabix,
objhead      LIKE solisti1 OCCURS 1 WITH HEADER LINE,
t_desti        TYPE TABLE OF zmaildest WITH HEADER LINE,
destinataris TYPE TABLE OF somlreci1 WITH HEADER LINE,
sistema      LIKE sy-sysid.

doc_chng-obj_name = 'SENDFILE'.
doc_chng-obj_descr = 'Proveedores de TMB'.
objtxt = 'Adjunto archivo con los códigos de Proveedores de TMB'.
APPEND objtxt.

DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

* Creation of 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.

SELECT * FROM lfa1 WHERE ktokk = 'NTMB' AND
                         loevm NE 'X'.

  CONCATENATE lfa1-stcd1 '*' lfa1-lifnr INTO objbin.
  APPEND objbin.

ENDSELECT.

DESCRIBE TABLE objbin LINES tab_lines.
objhead = 'PROVEEDORES.TXT'.
APPEND objhead.

objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 1.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'TXT'.
objpack-obj_name = 'PROVEEDORES'.
objpack-obj_descr = 'PROVEEDORES'.
objpack-doc_size = tab_lines * 255.
APPEND objpack.

* @
CLEAR destinataris.
destinataris-receiver = 'email_address'. " commented
destinataris-express = 'X'.
destinataris-rec_type = 'U'. "<------------------ URL
destinataris-copy = 'X'.
APPEND destinataris.

*   Envío del correo:
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                  = destinataris
  EXCEPTIONS
    too_many_receivers         = 1
    document_not_sent          = 2
    operation_no_authorization = 4
    OTHERS                     = 99.

IF sy-subrc <> 0.
*       MESSAGE W006(ZP) WITH 'Missatge no enviat.'.
ENDIF.

Lots of thanks,

Javi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,078

Hi javier,

1. One problem is that there is no NEW LINE character.

2. Even if we open a txt file in notepad, behind the scenes

there is a NEWLINE character, at the end of every line,

and hence it is interpreted and instead of displaying the

ascii character, the contents are displayed in the next line.

3.

change your code slightly like this:

CONCATENATE lfa1-stcd1 '*' lfa1-lifnr

CL_ABAP_CHAR_UTILITIES=>CR_LF

INTO objbin.

regards,

amit m.

9 REPLIES 9
Read only

Former Member
0 Likes
1,078

SELECT * FROM lfa1 WHERE ktokk = 'NTMB' AND

loevm NE 'X'.

CONCATENATE lfa1-stcd1 '*' lfa1-lifnr INTO objbin.

APPEND objbin.

clear objbin.

ENDSELECT.

I have written clear statement please try it.

Regards,

madan.

Read only

0 Likes
1,078

I'm still having the same problem. The output in notepad (.txt) is displayed in one line. If i copy and paste the results here, it is shown correctly, but opening the file, it follows the following patter:

XXXXXX XXXXXX XXXXXX

XXXXX XXXXXX XXXXXX

XXXX XXXXXX XXXXX

...

Any possibility?

Thanks.

Javier

Read only

0 Likes
1,078

Hi,

better u can convert this to pdf format and attach it. or use .doc

some time .txt format is giving problem when number of lines are more. please tick the word wrap while opening.

Read only

0 Likes
1,078

Yes, in ".doc" everything is correct, but i wanted to know why i can't reach the same output in ".txt".

I don't understand your last sentence Binu "please tick the word wrap while opening."

What does it means? Thanks for your quickly reply!

Read only

0 Likes
1,078

Open the notepad

goto>format> WordWrap ...

Read only

0 Likes
1,078

Hi Javier,

This might be problem with ur local PC settings. Try this option.

Open some notepad file and type something which is more than one line. Now in menu format->select word wrap.

Now download ur file from code and try to open the same and see.

Thanks,

Vinod.

Read only

0 Likes
1,078

OK, thanks Srinivas.

The format is still wrong, checking this option. And when i maximize the window it changes.

I think i'll finally decide to export it in MSWord... because i can't resolve this notepad problem.

Read only

0 Likes
1,078

I was posting when i read the following responses.

Finally my problem is solved!!!!

Writing:

CONCATENATE lfa1-stcd1 '*' lfa1-lifnr INTO objbin.

CONCATENATE objbin cl_abap_char_utilities=>cr_lf

INTO objbin.

APPEND objbin.

Lots of thanks to all of you, who help me!

Javier

Read only

Former Member
0 Likes
1,079

Hi javier,

1. One problem is that there is no NEW LINE character.

2. Even if we open a txt file in notepad, behind the scenes

there is a NEWLINE character, at the end of every line,

and hence it is interpreted and instead of displaying the

ascii character, the contents are displayed in the next line.

3.

change your code slightly like this:

CONCATENATE lfa1-stcd1 '*' lfa1-lifnr

CL_ABAP_CHAR_UTILITIES=>CR_LF

INTO objbin.

regards,

amit m.