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 of sending email with attachment by SO_NEW_DOCUMENT_ATT_SEND_API1

Former Member
0 Kudos

Hi experts,

When I sent email with FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' with TXT attachment, I found the there were no new line after each row of the content of TXT file attachment . All the rows in the internal table are concatenated into a string without any new line mark. It damaged the format of my attachment.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

You need to concatenate your text with l_c_cr_lf (For enter button or new line) after every 255 char to get new line. Below is the code. Let me know in case of ny clarifications.

CONSTANTS: l_c_cr_lf TYPE abap_cr_lf VALUE cl_abap_char_utilities=>cr_lf,

l_c_255 TYPE char3 VALUE '255'.

DATA: l_v_cr_lf TYPE abap_cr_lf,

l_v_n TYPE i,

l_v_dif TYPE i,

l_v_strlen TYPE i.

l_v_cr_lf = l_c_cr_lf.

l_v_n = 0.

LOOP AT fp_i_mail_out INTO wa_mail_out.

l_v_strlen = STRLEN( wa_mail_out ).

CLEAR l_v_n.

DO.

l_v_dif = l_v_strlen - l_v_n.

IF l_v_dif < l_c_255.

EXIT.

ELSE.

l_wa_attachment = wa_mail_out+l_v_n(255).

APPEND l_wa_attachment TO l_i_attachment.

CLEAR l_wa_attachment.

l_v_n = l_v_n + 255.

ENDIF.

ENDDO.

IF l_v_strlen > l_v_n.

l_v_dif = l_v_strlen - l_v_n.

l_wa_attachment = wa_mail_out+l_v_n(l_v_dif).

APPEND l_wa_attachment TO l_i_attachment.

CLEAR l_wa_attachment.

ENDIF.

DESCRIBE TABLE l_i_attachment LINES l_v_lines.

LOOP AT l_i_attachment ASSIGNING <l_fs_attach>.

IF sy-tabix = l_v_lines.

CONCATENATE <l_fs_attach>-line l_v_cr_lf INTO <l_fs_attach>-line.

ENDIF.

ENDLOOP.

ENDLOOP.

8 REPLIES 8

Former Member
0 Kudos

You need to concatenate your text with l_c_cr_lf (For enter button or new line) after every 255 char to get new line. Below is the code. Let me know in case of ny clarifications.

CONSTANTS: l_c_cr_lf TYPE abap_cr_lf VALUE cl_abap_char_utilities=>cr_lf,

l_c_255 TYPE char3 VALUE '255'.

DATA: l_v_cr_lf TYPE abap_cr_lf,

l_v_n TYPE i,

l_v_dif TYPE i,

l_v_strlen TYPE i.

l_v_cr_lf = l_c_cr_lf.

l_v_n = 0.

LOOP AT fp_i_mail_out INTO wa_mail_out.

l_v_strlen = STRLEN( wa_mail_out ).

CLEAR l_v_n.

DO.

l_v_dif = l_v_strlen - l_v_n.

IF l_v_dif < l_c_255.

EXIT.

ELSE.

l_wa_attachment = wa_mail_out+l_v_n(255).

APPEND l_wa_attachment TO l_i_attachment.

CLEAR l_wa_attachment.

l_v_n = l_v_n + 255.

ENDIF.

ENDDO.

IF l_v_strlen > l_v_n.

l_v_dif = l_v_strlen - l_v_n.

l_wa_attachment = wa_mail_out+l_v_n(l_v_dif).

APPEND l_wa_attachment TO l_i_attachment.

CLEAR l_wa_attachment.

ENDIF.

DESCRIBE TABLE l_i_attachment LINES l_v_lines.

LOOP AT l_i_attachment ASSIGNING <l_fs_attach>.

IF sy-tabix = l_v_lines.

CONCATENATE <l_fs_attach>-line l_v_cr_lf INTO <l_fs_attach>-line.

ENDIF.

ENDLOOP.

ENDLOOP.

0 Kudos

thx very much , shraddha verma .

l_c_cr_lf is worked when it is assigned at the last two characters in each line. Can I get a carriage return and new line and the end of the content of each line instead of the whole 255 characters?

Another little question, what is the difference between new line and CR_LF when they are used in the character line? Does the cr_lf means a carriage return + new line?

P561888
Active Contributor
0 Kudos

HI ,

Are working on 4.7 Version , use this FM , and where as ECC 6 we need to use the OOPS concept examlpe program are BCS_EXAMPLE_1.

Regards,

Bharani

Former Member
0 Kudos

Hi shraddha verma , thank you very much for the quick replay.

hi Bharani ,

As you said, I used to use it in 4.x and it works fine. But now I want to realize it in ECC 6, the problem occurs. What I want to check is we can not use it in ECC6? It means shraddha verma's way maybe can not solve the problem? Because it is weekend, I can not connect to the R3, so I can not test it.

0 Kudos

Hi YICHAO ,

Please make sure SCOT are maintained for the mailing server along with the Ports from the basis side .

and by using: FM :SO_NEW_DOCUMENT_SEND_API1 you can send the attachement with mail .

Regards

Swapnil

0 Kudos

Hi YICHAO,

Declare it.

DATA HORI_TAB TYPE STRING VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

and pass hori_tab to the CONTENTS_BIN before endloop.

(Ex : LOOP AT IT_STATUSLOG INTO WA_STATUSLOG.

WA_OBJBIN-LINE+0(05) = WA_STATUSLOG-ERROR_CODE.

WA_OBJBIN-LINE+5(65) = WA_STATUSLOG-MESSAG.

WA_OBJBIN-LINE+70(10) = WA_STATUSLOG-BKTXT.

WA_OBJBIN-LINE+85(1) = HORIZONTAL_TAB.

APPEND WA_OBJBIN TO IT_OBJBIN.

ENDLOOP.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

TABLES

CONTENTS_BIN = IT_OBJBIN)

Regards,

Sri

0 Kudos

hi srikanthn , I just want a line break at the end of each line. Does the CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB manage it? Semantically, it adds a TAB in the line, doesn't it?

Former Member
0 Kudos

cl_abap_char_utilities=>cr_lf works. I close this question. But it is still a tiny problem ,is it necessary to put CR_LF at the end of the content line?