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

mail sending program

Former Member
0 Likes
1,101

Hi Experts,

I am trying to send a mial with text attachement from the r/3. Everything is working fine except the data format in the text file.

I have filled the contetents table as shown below.


data:  word1(15) type c,
       word2(15) type c,
       tab_space(15) type c,
       idx type i.

word1 = 'firstword'.
word2 = 'secondword'.
tab_space = '      '.
idx = 1.
do 3 times.

concatenate word1   word2    into contents .
*insert wa_contents into table contents .

append contents.

*concatenate word1   word2    into contents .
*insert wa_contents into table contents .

append contents.

enddo.

and the packing list table as shown below


  DESCRIBE TABLE contents LINES count.
  REFRESH packing_list.
  packing_list-transf_bin = 'X'.
  packing_list-head_start = 1.
  packing_list-head_num = 1.
  packing_list-body_start = 1.
  packing_list-body_num = count.
  packing_list-doc_type = 'RAW'.

  APPEND packing_list.
  CLEAR packing_list.

* Create attachment notification
  packing_list-transf_bin = ''.
  packing_list-head_start = 1.
  packing_list-head_num   = 1.
  packing_list-body_start = 1.
  packing_list-body_num   = count.

  packing_list-doc_type   =  'TXT'.
  packing_list-obj_descr  =  'Material Infotype'.
  packing_list-obj_name   =  'Material Infotype'.
  packing_list-doc_size   =  count * 255.
  APPEND packing_list.

the mail sending code is shown below.


  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data                  = document_data
*   PUT_IN_OUTBOX                    = ' '
*   SENDER_ADDRESS                   = SY-UNAME
*   SENDER_ADDRESS_TYPE              = 'B'
*   COMMIT_WORK                      = ' '
* IMPORTING
*   SENT_TO_ALL                      =
*   NEW_OBJECT_ID                    =
*   SENDER_ID                        =
    TABLES
      packing_list                   = packing_list
*   OBJECT_HEADER                    =
    contents_bin                     = attachment
    contents_txt                     = contents
*   CONTENTS_HEX                     =
*   OBJECT_PARA                      =
*   OBJECT_PARB                      =
      receivers                      = real_recipients
* 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
            .

The problem is in the attachment file, the data is appearing as shown below:

firstwordsecondword

firstwordsecondword

firstwordsecondword

the second and third lines are not starting from the begining of new line. I do not understand why. Is that something problem with the packing parameters.

thanks

sankar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,065

Hi Sankar,

Change you concatnate statement like this.

concatenate word1

word2

CL_ABAP_CHAR_UTILITIES=>CR_LF

into contents .

Regards,

Vijay

8 REPLIES 8
Read only

former_member480923
Active Contributor
0 Likes
1,065

hi just modify your concatenate statement:


data: c_tab type char2 value '  '.  
do ...

concatenate word1   word2    into contents separated by c_tab .
append contents.
clear    contents.
enddo. 

Hope That Helps

Anirban M.

Read only

0 Likes
1,065

Hi Anirban

I have done the modifications. Now I get the o/p in the taxt file like this

firstword secondword

xxxxxxxxxxxxxxxxxxxxfirstword secondword

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXfirstword secondword

( X indicates the balnk space )

I wane the o/p in the text file like this

firstword secondword

firstword secondword

firstword secondword

all lines starting from the same point.

thanks

sankar

Message was edited by:

sankar rao

Message was edited by:

sankar rao

Read only

0 Likes
1,065

I have written something like the below and it works for me please check.


DATA: t_data TYPE STANDARD TABLE OF char50,
      w_data TYPE char50.

DATA:  word1(15) TYPE c,
       word2(15) TYPE c,
       tab_space(15) TYPE c,
       idx TYPE i.

word1 = 'firstword'.
word2 = 'secondword'.
tab_space = '      '.
idx = 1.

DO 3 TIMES.
  CONCATENATE word1   word2    INTO w_data SEPARATED BY tab_space.
  APPEND w_data TO t_data.
  CLEAR  w_data.
ENDDO.

LOOP AT t_data INTO w_data.
  WRITE:/ w_data.
ENDLOOP.

and here is my output:

firstword               secondword
firstword               secondword
firstword               secondword

Hope That Helps

Read only

0 Likes
1,065

Hi Ani,

When I disply the o/p in the report it is working fine, But in the text file attachment the text is appearing like this

firstword secondword

xxxxxxxxxxxxxxxxfirstword secondword

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXfirstword secondword.

X represents the blank space.

thanks

sankar

Read only

0 Likes
1,065

Try the following:

packing_list-doc_type   = 'RAW' " 'TXT'.
  packing_list-obj_descr  =  'Material Infotype'.
  packing_list-obj_name   =  'Material Infotype'.
  packing_list-doc_size   =  count * 255.
  APPEND packing_list.

Hope That Helps

Anirban M.

Read only

Former Member
0 Likes
1,065

Hi

check out below link,

http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm

Regards,

Raghavendra

Read only

Former Member
0 Likes
1,065

Hi,

try like this.

DATA: t_data TYPE STANDARD TABLE OF char50,

w_data TYPE char50.

DATA: word1(15) TYPE c,

word2(15) TYPE c,

tab_space(15) TYPE c,

idx TYPE i.

word1 = 'firstword'.

word2 = 'secondword'.

tab_space = ' '.

idx = 1.

DO 3 TIMES.

CONCATENATE word1 word2 INTO w_data SEPARATED BY tab_space.

APPEND w_data TO t_data.

CLEAR w_data.

ENDDO.

and change your pack list part like this .

t_objpack-transf_bin = 'X'.

t_objpack-head_start = 1.

t_objpack-head_num = 1.

t_objpack-body_start = 1.

t_objpack-body_num = count.

t_objpack-doc_type = 'TXT'.

t_objpack-obj_name = 'text1'.

t_objpack-obj_descr = 'Txt2'.

t_objpack-doc_size = count * 255.

t_objpack-mess_type = space.

APPEND t_objpack.

CLEAR t_objpack.

Read only

Former Member
0 Likes
1,066

Hi Sankar,

Change you concatnate statement like this.

concatenate word1

word2

CL_ABAP_CHAR_UTILITIES=>CR_LF

into contents .

Regards,

Vijay