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: 

Using the FM SO_NEW_DOCUMENT_ATT_SEND_API1

Former Member
0 Kudos

Hi Gurus,

I am using the FM SO_NEW_DOCUMENT_ATT_SEND_API1.

My requirement needs me to email an attachment.

Why is it that when I input

A

B

C

in my table, the value I am getting is

A B C

wherein I should get an attachment that should look like this one

A

B

C

My output file is a TXT file. I understand that this is using the CONTENT_BIN that uses the binary format.

What I need is an attachment that is using the ASCII format. But when I use the ASCII format, I am getting an error: "error occurred during sending !".

Do I need to make enhacements on the FM?

Thanks in advance.

Benedict

7 REPLIES 7

Former Member
0 Kudos

Hi Benedict,

Please refer to the below code.

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

  • Program: ZRAT Creation Date: 12.04.2007 *

  • Program Title : Retirement Age Trigger *

  • Program Author: Puneet Jhari *

  • Program Type : Executable *

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

  • Object ID : *

  • Technical Specification Version: *

  • Technical Specification Author: *

  • Code Quality Reviewer : *

  • Transport No. : SRDK906499 *

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

  • Program Description: *

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

  • Inputs *

  • Tables: *

  • Parameters *

  • External files: *

  • Outputs *

  • Reports: *

  • Tables: *

  • Databases: *

  • Screens: *

  • Parameters *

  • External files: *

  • Other objects: *

  • Return codes set by ABAP: *

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

  • Modification Informaion *

  • Program Version: *

  • Date : DD-MMM-YYYY *

  • Author : *

  • Description : *

  • Transport No.: *

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

REPORT zrat NO STANDARD PAGE HEADING.

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

*DATA DECLARATION

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

DATA : BEGIN OF wa_ccode,

bukrs TYPE t001-bukrs,

END OF wa_ccode.

DATA : itab_ccode LIKE TABLE OF wa_ccode.

DATA : BEGIN OF wa_emp,

pernr TYPE pa0001-pernr,

sachp TYPE pa0001-sachp,

sname TYPE pa0001-sname,

END OF wa_emp.

DATA : itab_emp LIKE TABLE OF wa_emp.

DATA : BEGIN OF wa_bdate,

nachn LIKE pa0002-nachn,

vorna LIKE pa0002-vorna,

pernr TYPE pa0002-pernr,

gbdat TYPE pa0002-gbdat,

END OF wa_bdate.

DATA : itab_bdate LIKE TABLE OF wa_bdate.

DATA : new_date LIKE sy-datum.

DATA : diff TYPE i.

DATA : years LIKE p0347-scryy,

months LIKE p0347-scrmm,

days LIKE p0347-scrdd.

DATA : sup_code LIKE pa0001-sachp,

itab_usrid LIKE t526-usrid,

sup_pernr LIKE pa0105-pernr.

DATA : BEGIN OF wa_email,

usrid_long LIKE pa0105-usrid_long,

END OF wa_email.

DATA : sup_email LIKE TABLE OF wa_email.

DATA : gwa_document_data LIKE sodocchgi1,

gc_name TYPE so_obj_nam VALUE 'RETIREMENT',

gc_senst TYPE so_obj_sns VALUE 'P',

gc_size TYPE so_doc_siz VALUE '510',

gi_obj_cnt LIKE TABLE OF solisti1 WITH HEADER LINE,

gi_recievers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

gwa_obj_cnt LIKE LINE OF gi_obj_cnt.

DATA : smtp_addr LIKE adr6-smtp_addr.

DATA : wa_date LIKE sy-datum,

entries LIKE sy-tabix,

name(15),

line1(18) TYPE c,

line2(20) TYPE c,

line3(20) TYPE c,

line4(23) TYPE c,

line5(10) TYPE c,

line6(45) type c,

date(2) TYPE c,

month(2) TYPE c,

year(4) TYPE c.

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

*START OF SELECTION

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

SELECT bukrs

FROM t001

INTO TABLE itab_ccode

WHERE land1 EQ 'GB'.

SORT itab_ccode.

DELETE ADJACENT DUPLICATES FROM itab_ccode.

SELECT pernr sachp sname

FROM pa0001

INTO TABLE itab_emp

FOR ALL ENTRIES IN itab_ccode

WHERE bukrs EQ itab_ccode-bukrs AND begda LE sy-datum AND

endda GE sy-datum and persg eq '1'.

SELECT nachn vorna pernr gbdat

FROM pa0002

INTO TABLE itab_bdate

FOR ALL ENTRIES IN itab_emp

WHERE pernr EQ itab_emp-pernr.

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

*TO CHECK EMPLOYEES WHOSE AGE IS NEAR 75 YEARS.

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

LOOP AT itab_bdate INTO wa_bdate.

new_date = wa_bdate-gbdat.

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

*TO CALCULATE THE AGE TILL DATE

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

CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

EXPORTING

date1 = sy-datum

date2 = new_date

output_format = '05'

IMPORTING

years = years

months = months

days = days

.

IF sy-subrc <> 0.

ENDIF.

IF years EQ 64 AND months EQ 4.

IF days GE 23 AND days LE 31.

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

*FETCH THE DATA IF THE AGE IS NEARING 75 YEARS

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

SELECT SINGLE sachp FROM pa0001 INTO sup_code WHERE pernr EQ

wa_bdate-pernr AND begda LE sy-datum AND endda GE sy-datum.

SELECT SINGLE usrid FROM t526 INTO itab_usrid WHERE sachx EQ

sup_code.

SELECT SINGLE pernr FROM pa0105 INTO sup_pernr WHERE usrid EQ

itab_usrid AND subty EQ '0001'.

clear sup_email[].

SELECT usrid_long FROM pa0105 INTO TABLE sup_email WHERE pernr EQ

sup_pernr AND subty EQ '0010'.

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

*EMAIL ADDRESS OF THE SUPERVISOR TO BE NOTIFIED

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

CLEAR gi_obj_cnt.

CLEAR gi_recievers.

CLEAR gwa_document_data.

Loop at sup_email into wa_email.

write sy-uline+0(5).

write sy-uline+10(5).

write sy-uline+20(5).

write sy-uline+30(5).

write sy-uline+40(5).

write sy-uline+50(5).

write sy-uline+60(5).

write sy-uline+70(5).

smtp_addr = wa_email-usrid_long.

gi_recievers-receiver = smtp_addr.

gi_recievers-rec_type = 'U'.

gi_recievers-com_type = 'INT'.

APPEND gi_recievers.

Endloop.

smtp_addr = 'Mairi.Davidson@subsea7.com'.

gi_recievers-receiver = smtp_addr.

gi_recievers-rec_type = 'U'.

gi_recievers-com_type = 'INT'.

APPEND gi_recievers.

gwa_document_data-obj_name = gc_name.

gwa_document_data-obj_descr = 'RETIRE'.

gwa_document_data-sensitivty = gc_senst.

gwa_document_data-obj_langu = sy-langu.

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

*CONTENT OF THE EMAIL TO BE SENT

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

line1 = 'Please note that '.

line2 = wa_bdate-vorna.

line3 = wa_bdate-nachn.

line4 = ' will be 65 years on '.

line50(4) = wa_bdate-gbdat4(4).

date = line5+2(2).

month = line5+0(2).

year = wa_bdate-gbdat+0(4) + 65.

CONCATENATE date month year INTO line5 SEPARATED BY '.'.

line6 = '.Please complete the Retirement Procedure.'.

CONCATENATE line1 line2 line3 line4 line5 line6 INTO gwa_obj_cnt

SEPARATED BY space.

APPEND gwa_obj_cnt TO gi_obj_cnt.

CLEAR gwa_obj_cnt.

DESCRIBE TABLE gi_obj_cnt LINES entries.

READ TABLE gi_obj_cnt INDEX entries.

gwa_document_data-doc_size = ( entries - 1 ) * 255 + STRLEN( gi_obj_cnt

).

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

*FUNCTION MODULE TO SEND THE EMAIL TO THE CONCERNED PERSONS

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

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = gwa_document_data

document_type = 'RAW'

commit_work = 'X'

TABLES

object_content = gi_obj_cnt

receivers = gi_recievers

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

.

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

*MESSAGE TO BE DISPLAYED AFTER THE EXECUTION

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

  • endif.

CASE sy-subrc.

WHEN 0.

LOOP AT gi_recievers.

IF gi_recievers-receiver = space.

name = gi_recievers-rec_id.

ELSE.

name = gi_recievers-receiver.

ENDIF.

IF gi_recievers-retrn_code = 0.

WRITE: / name, ': succesfully sent'.

ELSE.

WRITE: / name, ': error occured'.

ENDIF.

ENDLOOP.

WHEN 1.

WRITE: / 'Too many receivers specified !'.

WHEN 2.

WRITE: / 'No receiver got the document !'.

WHEN 4.

WRITE: / 'Missing send authority !'.

WHEN OTHERS.

WRITE: / 'Unexpected error occurred !'.

ENDCASE.

ENDIF.

ENDIF.

ENDLOOP.

In case you have any further clarifications,do let me know.

Regards,

Puneet Jhari.

0 Kudos

Hi Vijay and Puneet,

Before I proceed, I just want to ask if I can use an attachment with an ASCII format?

Thanks in advance.

Benedict

Former Member
0 Kudos

Hi,

See the following code

The follwing code which it send the mails to the perticular members in the list which it should maintain in DISTRIBUTION LIST : TCODE = SO23.

Firts goto t-code SO23 crete one distribution list in that add the no.of mail receipts in one list which we can send mail either sap inbox or exteral mails.

other wise u can send the mails directly with out use if so23.

  • Internal tables used to send emails

DATA: tbl_packing_list TYPE sopcklsti1 OCCURS 0 WITH HEADER LINE,

tbl_object_header TYPE solisti1 OCCURS 0 WITH HEADER LINE,

tbl_contents_txt TYPE solisti1 OCCURS 0 WITH HEADER LINE,

tbl_receivers TYPE somlreci1 OCCURS 0 WITH HEADER LINE.

constant c_business(7) VALUE 'LISTMAIL'. " This is list name by SO23.

  • Send mail to operations support with the detailed error log

PERFORM send_mail USING c_business.

FORM send_mail USING receiver.

CLEAR: w_lines,tbl_packing_list,tbl_object_header,

tbl_contents_txt, tbl_receivers.

REFRESH:tbl_packing_list, tbl_object_header,

tbl_contents_txt,tbl_receivers.

SORT tbl_err BY type.

DELETE ADJACENT DUPLICATES FROM tbl_err COMPARING ALL FIELDS.

IF NOT tbl_err[] IS INITIAL.

PERFORM prepare_email.

ELSE.

EXIT.

ENDIF.

  • Get e-mail document data

PERFORM document_data.

  • Get packing list

PERFORM packing_list.

tbl_receivers-receiver = receiver. " this is the distribution list name is LISTMAIL.

tbl_receivers-rec_type = 'C'.

tbl_receivers-express = c_flag.

tbl_receivers-sap_body = c_flag.

APPEND tbl_receivers.

  • Call FM to send E-mails to receivers

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_document_data

put_in_outbox = c_x

TABLES

packing_list = tbl_packing_list

object_header = tbl_object_header

contents_txt = tbl_contents_txt

receivers = tbl_receivers[]

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.

IF sy-subrc <> 0.

ENDIF.

ENDFORM. " send_mail

FORM prepare_email.

" Subject of mail.

CONCATENATE text-028 w_docnum text-030

INTO tbl_contents_txt-line

SEPARATED BY space.

APPEND tbl_contents_txt.

CLEAR tbl_contents_txt.

  • E-mail attachment header

CONCATENATE text-024

text-025

text-026

text-029

text-027

text-031

c_comma

INTO tbl_contents_txt-line

SEPARATED BY c_comma.

APPEND tbl_contents_txt.

CLEAR tbl_contents_txt.

SORT tbl_err .

  • E-mail attachment content

LOOP AT tbl_err.

CONCATENATE c_dbqt w_docnum c_dbqt c_comma

c_dbqt tbl_err-shipmn_id_nbr c_dbqt c_comma

c_dbqt tbl_err-contract_nbr c_dbqt c_comma

c_dbqt tbl_err-contract_line c_dbqt c_comma

c_dbqt tbl_err-msg c_dbqt c_comma

c_dbqt tbl_err-type c_dbqt c_comma

INTO tbl_contents_txt-line.

CONCATENATE c_linefeed

tbl_contents_txt-line

c_comma

INTO tbl_contents_txt-line.

APPEND tbl_contents_txt.

CLEAR tbl_contents_txt.

ENDLOOP.

DESCRIBE TABLE tbl_err LINES w_lines.

ENDFORM. " prepare_email

"Attach name.

FORM document_data.

CLEAR w_line.

CONCATENATE text-028 sy-datum sy-uzeit INTO w_line

SEPARATED BY c_uscore.

w_document_data-obj_name = w_line.

w_document_data-obj_descr = w_line.

w_document_data-priority = 1.

w_document_data-obj_prio = 1.

ENDFORM. " document_data

FORM packing_list.

CLEAR w_lines.

DESCRIBE TABLE tbl_err LINES w_lines.

READ TABLE tbl_contents_txt INDEX w_lines.

tbl_packing_list-head_start = 1.

tbl_packing_list-head_num = 1.

tbl_packing_list-body_start = 1.

tbl_packing_list-body_num = 1.

tbl_packing_list-doc_type = 'RAW'.

APPEND tbl_packing_list.

tbl_packing_list-head_start = 1.

tbl_packing_list-head_num = 0.

tbl_packing_list-body_start = 2.

tbl_packing_list-body_num = w_lines + 1.

tbl_packing_list-doc_type = 'CSV'. " this is Excel file

tbl_packing_list-obj_name = text-027.

tbl_packing_list-doc_size = 255 * ( w_lines + 1 ).

APPEND tbl_packing_list.

ENDFORM. " packing_list

Let me know for further details to vijaykrishna.c@capgemini.com

<b>Reward with points if helpful.</b>

Regards,

Vijay

Former Member
0 Kudos

wrong radio button selected

sreeramkumar_madisetty
Active Contributor
0 Kudos

Hi Benedict

Can I know which you are sending as an attachement?

Because if you are facing the problems with message type in the attachement,

Call Use the FM:

<b>**/ Convert the PDF format to the table type required for the

*attachment.

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = l_pdf

t_target_tab = l_objbin

EXCEPTIONS

convert_not_possible = 1

OTHERS = 2.

IF sy-subrc <> 0.

WRITE: / 'error', sy-subrc.

ENDIF.</b>

as above.

Regards,

Sree

0 Kudos

Hi Sree,

I should be sending a TXT file.

I can send it successfully but the data are not correct.

Example:

I should get

A

B

C

3 lines with only 1 character per line and as an attachment, but I am getting

A B C

1 line with many spaces between.

Is this because the format is in BIN format and not in ASCII format?

When I made it to text and not in attachment file, it is correct.

BTW, what is QCE1_CONVERT doing? Converting only in PDF format?

Thanks in advance.

Benedict

0 Kudos

Hi All,

Anyone knows the solution?

Also, I am getting the data with spaces between the per character.

Thanks in advance.

Benedict