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: 

Mail A Report !

Former Member
0 Kudos

Dear all, consider the following situation.

I have generated an ALV report, now there is a requirement in which this report ( ALV report ) should be mailed to a certain group of people. Is there something such as a mailing service which can be used here ? Please guide me how to do that !!!

21 REPLIES 21

Former Member
0 Kudos

Hi,

you can use spool list recipient option when you schedule the job.

If you are running the report in foreground, then you will have to use normal mailing Function modules.

Hope it helps.

Regards,

Shashank

Former Member
0 Kudos

Use the following code which will solve ur problem.

try this code which sends the spool list to email or fax with attachement

z_send_email_fax

FUNCTION ZCBFS_SEND_MAIL.

*"----


""Interface local:

*" IMPORTING

*" REFERENCE(SRC_SPOOLID) LIKE TSP01-RQIDENT

*" REFERENCE(HEADER_MAIL) TYPE SO_OBJ_DES

*" TABLES

*" LIST_FAX_MAIL_NUMBER STRUCTURE SOLI

*" EXCEPTIONS

*" ERR_NO_ABAP_SPOOLJOB

*"----


DATA: vg_achou(1) TYPE n.

  • Fist part: Verify if the spool really exists

vg_achou = 1.

DO 60 TIMES.

SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.

IF sy-subrc IS INITIAL.

CLEAR vg_achou.

EXIT.

ELSE.

WAIT UP TO 1 SECONDS.

ENDIF.

ENDDO.

IF vg_achou = 1.

RAISE err_no_abap_spooljob. "doesn't exist

ENDIF.

client = tsp01-rqclient.

name = tsp01-rqo1name.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

authority = 'SP01'

client = client

name = name

part = 1

IMPORTING

type = type

objtype = objtype

EXCEPTIONS

fb_error = 1

fb_rsts_other = 2

no_object = 3

no_permission = 4

OTHERS = 5.

IF objtype(3) = 'OTF'.

desired_type = otf.

ELSE.

desired_type = ali.

ENDIF.

CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'

EXPORTING

rqident = src_spoolid

desired_type = desired_type

IMPORTING

real_type = real_type

TABLES

buffer = l_objcont

EXCEPTIONS

no_such_job = 14

type_no_match = 94

job_contains_no_data = 54

no_permission = 21

can_not_access = 21

read_error = 54.

IF sy-subrc EQ 0.

attach_type = real_type.

ENDIF.

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'

EXPORTING

owner = sy-uname

region = ou_fol

IMPORTING

folder_id = l_folder_id

EXCEPTIONS

OTHERS = 5.

  • fill out informations about the header of the email

CLEAR: g_document.

g_document-foltp = l_folder_id-foltp.

g_document-folyr = l_folder_id-folyr.

g_document-folno = l_folder_id-folno.

g_document-objtp = c_objtp.

g_document-objdes = header_mail.

g_document-file_ext = c_file_ext.

g_header_data-objdes = header_mail.

CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'

EXPORTING

method = 'SAVE'

office_user = sy-uname

IMPORTING

authority = g_authority

TABLES

attachments = lt_attachments

CHANGING

document = g_document

header_data = g_header_data

EXCEPTIONS

OTHERS = 1.

folder_id-objtp = l_folder_id-foltp.

folder_id-objyr = l_folder_id-folyr.

folder_id-objno = l_folder_id-folno.

object_id-objtp = c_objtp.

object_id-objyr = g_document-objyr.

object_id-objno = g_document-objno.

link_folder_id-objtp = l_folder_id-foltp.

link_folder_id-objyr = l_folder_id-folyr.

link_folder_id-objno = l_folder_id-folno.

REFRESH lt_rec_tab.

LOOP AT LIST_FAX_MAIL_NUMBER.

lt_rec_tab-recextnam = LIST_FAX_MAIL_NUMBER-LINE.

lt_rec_tab-recesc = 'U'.

lt_rec_tab-sndart = 'INT'.

lt_rec_tab-sndpri = 1.

APPEND lt_rec_tab.

ENDLOOP.

lt_files-file = c_file.

APPEND lt_files.

hd_dat-objdes = header_mail.

CALL FUNCTION 'SO_ATTACHMENT_INSERT'

EXPORTING

object_id = object_id

attach_type = attach_type

object_hd_change = hd_dat

owner = sy-uname

TABLES

objcont = l_objcont

objhead = l_objhead

EXCEPTIONS

active_user_not_exist = 35

communication_failure = 71

object_type_not_exist = 17

operation_no_authorization = 21

owner_not_exist = 22

parameter_error = 23

substitute_not_active = 31

substitute_not_defined = 32

system_failure = 72

x_error = 1000.

IF sy-subrc > 0.

ENDIF.

  • send email from SAPOFFICE

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

folder_id = folder_id

object_id = object_id

outbox_flag = outbox_flag

link_folder_id = link_folder_id

owner = sy-uname

TABLES

receivers = lt_rec_tab

note_text = lt_note_text

EXCEPTIONS

active_user_not_exist = 35

communication_failure = 71

component_not_available = 1

folder_no_authorization = 5

folder_not_exist = 6

forwarder_not_exist = 8

object_no_authorization = 13

object_not_exist = 14

object_not_sent = 15

operation_no_authorization = 21

owner_not_exist = 22

parameter_error = 23

substitute_not_active = 31

substitute_not_defined = 32

system_failure = 72

too_much_receivers = 73

user_not_exist = 35.

ENDFUNCTION.

Former Member
0 Kudos

In ALV list, by default there will be an icon in the application tool bar to send a mail...check that.

former_member188685
Active Contributor
0 Kudos

Hi,

there is Built in functionality which is there in ALV

use that option or CTRL+F7

and send it to the people whom you want.

Regards

vijay

0 Kudos

Hi all !

I think was not able to explain it properly ! -


The requirment goes like this ..........

The user will enter some parameters in the selection screen. Based on these parameters some selection will be carried out. Now, after all that a final internal table will be generated, this data has to be mailed to the respective people who will see the report in the alv - report format. The user after putting the input parameters in the selection-screen should not see the alv-report, instead the same should be mailed to the respective user group ( whosoever ).

Please help !!!!!!!!!

0 Kudos

Hi,

It is difficult to email an ALV report.

However, you can send the attachemnt using FM

SO_NEW_DOCUMENT_ATT_SEND_API1.

This Fm is very well documented.

The steps could be

1. Prepare your internal table according to selection.

2. Prepare the import parameters for the above FM and call it.

3.call transaction SCOT to actually send the mails.

Hope it helps.

Regards,

Shashank

0 Kudos

hi,

follow these steps:

1)define the selection screen for Email parameters:

*--this P_MODE is for mail mode.ie.,External/internal etc.

PARAMETERS : P_MODE TYPE SO_ESCAPE MODIF ID USL.

*--this S_EMAIL to enter/take mail ids from the user

SELECT-OPTIONS: S_EMAIL FOR ADR6-SMTP_ADDR

NO INTERVALS MODIF ID USL.

2) in the program check this field, whether user entered any email id or not.

IF NOT S_EMAIL[] IS INITIAL.

*--User given some mail ids in the selection screen

PERFORM F_SEND_MAIL.

ELSE.

*--DISPLAY OUTPUT ON THE SCREEN USING ALV.

ENDIF.

3)form F_SEND_MAIL will take the values from S_EMAIl for email recipients, P_MODE for mail option(i.e.,internet mail id/internal mail)

& your final internal table which you want to send it in mail.

FORM F_SEND_MAIL.

*--Populate Mail Id's

*--for external mail: this P_MODE = 'U', within SAP its 'B'

WA_RECLIST-REC_TYPE = P_MODE.

WA_RECLIST-EXPRESS = C_X.

LOOP AT S_EMAIL INTO X_EMAIL.

*--populate all the email ids entered in the selection screen into mail ids internal table.

WA_RECLIST-RECEIVER = X_EMAIL-LOW.

*--append receiver table

APPEND WA_RECLIST TO IT_RECLIST.

ENDLOOP.

CHECK IT_RECLIST[] IS NOT INITIAL.

*--the below code is common for all the mail sending functionalities.

*--just add it in ur program & check the output.

*--To check Mail ID's internal table should not be Empty.

*--populate document attributes

CLEAR: X_DOC_CHNG.

X_DOC_CHNG-OBJ_NAME = 'HEADING'.

*--Mail subject line(give your object related text here)

CONCATENATE 'Domestic Material Catalog Changes as of'(034)

SY-DATUM

INTO X_DOC_CHNG-OBJ_DESCR SEPARATED BY SPACE.

*--Mail body

*--(give your object related text here)

CONCATENATE 'Domestic Material Catalog Changes,'(035)

' is attached.'(036)

INTO WA_OBJTXT SEPARATED BY SPACE.

APPEND WA_OBJTXT TO IT_OBJTXT.

*---- Append Date and Time into Body of email.

MOVE 'File is generated on'(037)

TO V_INFO.

V_TIME = SY-UZEIT.

CONCATENATE V_TIME+0(2)

V_TIME+2(2)

V_TIME+4(2)

INTO

V_TIME2 SEPARATED BY ':'.

CONCATENATE SY-DATUM+4(2)

'/'

SY-DATUM+6(2)

'/'

SY-DATUM+0(4)

INTO V_DATE2.

CONCATENATE V_INFO

V_DATE2

'At'

V_TIME2

INTO V_INFO

SEPARATED BY SPACE.

WA_OBJTXT = V_INFO.

APPEND WA_OBJTXT TO IT_OBJTXT.

*-document size

CLEAR : V_TABLE_LINES.

DESCRIBE TABLE IT_OBJTXT LINES V_TABLE_LINES.

READ TABLE IT_OBJTXT INTO WA_OBJTXT INDEX V_TABLE_LINES .

X_DOC_CHNG-DOC_SIZE =

( V_TABLE_LINES - 1 ) * 255 + STRLEN( WA_OBJTXT ).

*-populate packing list for body text

WA_OBJPACK-HEAD_START = 1.

WA_OBJPACK-HEAD_NUM = 0.

WA_OBJPACK-BODY_START = 1.

WA_OBJPACK-BODY_NUM = V_TABLE_LINES.

WA_OBJPACK-DOC_TYPE = 'RAW'.

APPEND WA_OBJPACK TO IT_OBJPACK.

CLEAR WA_OBJPACK.

*--for attachment

*--Populate Column headings

*--this a column heading for ur attachment.

*--nothing but IT_FINAL record fields.

CONCATENATE TEXT-040 " Material Number

TEXT-041 " Material Description

TEXT-042 " Division

TEXT-043 " Total product life

TEXT-044 " Special handling cond

TEXT-045 " Freeze prot code

TEXT-046 " Action Code

INTO V_TEXT SEPARATED BY C_TAB.

CONCATENATE V_TEXT

C_CR_LF

INTO V_TEXT.

WA_OBJBIN = V_TEXT.

APPEND WA_OBJBIN TO IT_OBJBIN.

CLEAR WA_OBJBIN.

*--Populate Data to the attachment

*--assume IT_FINAL will have ur final data to be sent as mail.

LOOP AT IT_FINAL INTO X_FINAL.

CONCATENATE X_FINAL-MATNR

X_FINAL-MAKTX

X_FINAL-SPART

X_FINAL-PRODLIFE

X_FINAL-BEHVO

X_FINAL-TEMPB

X_FINAL-ACODE

INTO V_TEXT SEPARATED BY C_TAB.

*--Go to next line after this record.

CONCATENATE V_TEXT

C_CR_LF

INTO V_TEXT.

WA_OBJBIN = V_TEXT.

APPEND WA_OBJBIN TO IT_OBJBIN.

CLEAR WA_OBJBIN.

ENDLOOP.

*-get total no.of lines of Object table(attachment)

CLEAR : V_TABLE_LINES.

DESCRIBE TABLE IT_OBJBIN LINES V_TABLE_LINES.

*-populate object header(attachment name)

WA_OBJHEAD = 'Material change log'(038).

APPEND WA_OBJHEAD TO IT_OBJHEAD.

CLEAR WA_OBJHEAD.

*-packing list for attachment

WA_OBJPACK-TRANSF_BIN = C_X.

WA_OBJPACK-HEAD_START = 1.

WA_OBJPACK-HEAD_NUM = 1.

WA_OBJPACK-BODY_START = 1.

WA_OBJPACK-BODY_NUM = V_TABLE_LINES .

WA_OBJPACK-DOC_TYPE = 'RAW' .

WA_OBJPACK-OBJ_NAME = 'MATERIAL'.

WA_OBJPACK-OBJ_DESCR = 'attachment'.

WA_OBJPACK-DOC_SIZE = V_TABLE_LINES * 255.

APPEND WA_OBJPACK TO IT_OBJPACK.

CLEAR WA_OBJPACK.

*-Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = X_DOC_CHNG

PUT_IN_OUTBOX = C_X

COMMIT_WORK = C_X

TABLES

PACKING_LIST = IT_OBJPACK

OBJECT_HEADER = IT_OBJHEAD

CONTENTS_BIN = IT_OBJBIN

CONTENTS_TXT = IT_OBJTXT

RECEIVERS = IT_RECLIST

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.

MESSAGE E000 WITH 'Error occurred in sending mail'(039).

ELSE.

PERFORM F_DISPLAY_SENT_MAIL_STATUS.

ENDIF.

ENDFORM. " F_SEND_MAIL

revert, if you need any more clarificatios.

Thanks

Savitha.

ADDED comments to the code

Message was edited by: savitha m

Message was edited by: savitha m

0 Kudos

Hi Savitha,

I am facing problems in understanding the code snippet given by you, as it does not contains the structure of the internal tables and other data used, so I am not able to get, what data is used for what and how it is being used.

Please help !

Eagerly waiting for your reply !

0 Kudos

hey,

i forgot, to mention the structures for the Mail related Internal tables.

*--MAIL related Internal tables

DATA: X_DOC_CHNG TYPE SODOCCHGI1, " document attributes

IT_OBJPACK TYPE STANDARD TABLE OF SOPCKLSTI1 ,

" attachment table

IT_OBJHEAD TYPE STANDARD TABLE OF SOLISTI1 ,

" object header table

IT_OBJBIN TYPE STANDARD TABLE OF SOLISTI1 ,

" binary table

IT_OBJTXT TYPE STANDARD TABLE OF SOLISTI1 , "object text

IT_RECLIST TYPE STANDARD TABLE OF SOMLRECI1 . "mail recipients

regards

Savitha

0 Kudos

hi Anshul,

i have given commented to the code i posted earlier.go thru it. revert if you need any clarifications.

after executing the program,to check the mail sent status

you can use the tcode : SOST to know the mail status.

Thanks

Savitha.

0 Kudos

Hi Sumathi!

what to do in the following perform statment?

is there some special function to be called here ?

PERFORM f_display_sent_mail_status.

0 Kudos

see the sample program and how to use Fm

SO_NEW_DOCUMENT_ATT_SEND_API1 in Functional Documentation .

regards

Prabhu

0 Kudos

Hi Sumathi !

I think I would be able to achive what I was looking for with your help !!!!

I am still facing some problems ..........

what are the following used for ?

c_x

c_cr_lf

and also the function module

SO_NEW_DOCUMENT_ATT_SEND_API1

is returning a non-zero value for sy-subrc.

Regards

Anshul

0 Kudos

Dear Savitha !!!

I am sorry I misspelled your name as Sumathi!

regards

Anshul

0 Kudos

Hi,

C_X is a constant of value 'X'.

CONSTANTS : C_X(1) TYPE C VALUE 'X'.

c_cr_lf : is to give the linefeed after each record.

i mean, once we reach end of record, the next record to be appeared on the next line. to make that difference we use LINE FEED.

its value is :

*--Horizontal tab & line feed constants

CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.

CONSTANTS:

C_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,

C_CR_LF TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF .

this will resolve your issues.

what is the subrc value you are getting ??

some times it may not be configured to internet ,to send mail to external ids.in that case you will get subrc <> 0.

so check your subrc value ..

regards

Savitha.

0 Kudos

hi,

that form F_SEND_MAIL , is just a modularized code.

after populating your final internal table , check your email select option, if its having any records, just call this form to send mail to the given id's

even you can write total form-endform code in that if condition.

regards

Savitha.

0 Kudos

Hi Savitha,

I am getting sy-subrc = 2.

What does that mean ?

Regards

Anshul

0 Kudos

hi,

to which id's you are sending mail? if its for external mail ids, first confirm with basis people the configuration is done or not.

else try to give your SAP ID in RECEIVER field

& 'B' in REC_TYPE . & execute it. it will come to your SAP office mail box.

transaction code to check your SAP mail : SO01.

Regards

Savitha.

0 Kudos

Hi Savitha,

Right now I am working on the 'test server' in which this mailing facility is not configured - ( I came to know this after I contacted the concerned Basis guy !!!)- here this facility is only in the production server in whicb I cannot test the program.

I am sending you the code I have written -( which is just another version of the one given by you !!! ) - can you please check it ! ? -


I know I am asking too much !!! but ,

PLEASE HELP !

Regards

Anshul

                            • Start Of Report **********************

REPORT ytest_anshul5 NO STANDARD PAGE HEADING

LINE-SIZE 100 LINE-COUNT 30(3) MESSAGE-ID ym .

TABLES: adr6,mara.

TYPES: BEGIN OF type_mara,

matnr LIKE mara-matnr,

matkl LIKE mara-matkl,

END OF type_mara.

DATA: wa_final TYPE type_mara,

it_final TYPE STANDARD TABLE OF type_mara INITIAL SIZE 0.

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

DATA: x_doc_chng TYPE sodocchgi1. " document attributes

DATA: it_objpack TYPE STANDARD TABLE OF sopcklsti1, " attachment table

wa_objpack TYPE sopcklsti1.

DATA: it_objhead TYPE STANDARD TABLE OF solisti1, " object header table

wa_objhead TYPE solisti1.

DATA: it_objbin TYPE STANDARD TABLE OF solisti1, " binary table

wa_objbin TYPE solisti1.

DATA: it_objtxt TYPE STANDARD TABLE OF solisti1,

wa_objtxt TYPE solisti1 . "object text

DATA: it_reclist TYPE STANDARD TABLE OF somlreci1,

wa_reclist TYPE somlreci1 . "mail recipients

DATA :v_time TYPE sy-uzeit,

v_time2 TYPE sy-uzeit,

v_info(30) TYPE c,

v_date2 TYPE sy-datum,

v_table_lines TYPE i,

v_text(100) TYPE c.

CONSTANTS : c_x(1) TYPE c VALUE 'X'.

CLASS cl_abap_char_utilities DEFINITION LOAD.

CONSTANTS:

c_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

c_cr_lf TYPE c VALUE cl_abap_char_utilities=>cr_lf .

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

SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-001.

PARAMETERS : p_mode TYPE so_escape MODIF ID usl.

SELECT-OPTIONS: s_email FOR adr6-smtp_addr

NO INTERVALS MODIF ID usl.

DATA: x_email LIKE s_email.

SELECTION-SCREEN END OF BLOCK blk.

START-OF-SELECTION.

BREAK-POINT.

PERFORM sub_select_data.

*END-OF-SELECTION.

IF NOT s_email[] IS INITIAL.

PERFORM f_send_mail.

ENDIF.

&----


*& Form F_SEND_MAIL

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM f_send_mail .

*--Populate Mail Id's

wa_reclist-rec_type = p_mode.

wa_reclist-express = c_x.

LOOP AT s_email INTO x_email.

wa_reclist-receiver = x_email-low.

  • --append receiver table

APPEND wa_reclist TO it_reclist.

ENDLOOP.

CHECK it_reclist[] IS NOT INITIAL.

*--To check Mail ID's internal table should not be Empty.

*--populate document attributes

CLEAR: x_doc_chng.

x_doc_chng-obj_name = 'HEADING'.

*--Mail subject line(give your object related text here)

CONCATENATE 'Domestic Material Catalog Changes as of'(034)

sy-datum

INTO x_doc_chng-obj_descr SEPARATED BY space.

*--Mail body

*--(give your object related text here)

CONCATENATE 'Domestic Material Catalog Changes,'(035)

' is attached.'(036)

INTO wa_objtxt SEPARATED BY space.

APPEND wa_objtxt TO it_objtxt.

*---- Append Date and Time into Body of email.

MOVE 'File is generated on'(037)

TO v_info.

v_time = sy-uzeit.

CONCATENATE v_time+0(2)

v_time+2(2)

v_time+4(2)

INTO

v_time2 SEPARATED BY ':'.

CONCATENATE sy-datum+4(2)

'/'

sy-datum+6(2)

'/'

sy-datum+0(4)

INTO v_date2.

CONCATENATE v_info

v_date2

'At'

v_time2

INTO v_info

SEPARATED BY space.

wa_objtxt = v_info.

APPEND wa_objtxt TO it_objtxt.

*-document size

CLEAR : v_table_lines.

DESCRIBE TABLE it_objtxt LINES v_table_lines.

READ TABLE it_objtxt INTO wa_objtxt INDEX v_table_lines .

x_doc_chng-doc_size =

( v_table_lines - 1 ) * 255 + STRLEN( wa_objtxt ).

*-populate packing list for body text

wa_objpack-head_start = 1.

wa_objpack-head_num = 0.

wa_objpack-body_start = 1.

wa_objpack-body_num = v_table_lines.

wa_objpack-doc_type = 'RAW'.

APPEND wa_objpack TO it_objpack.

CLEAR wa_objpack.

*--for attachment

*--Populate Column headings

*--this a column heading for ur attachment.

*--nothing but IT_FINAL record fields.

CONCATENATE text-040 " Material Number

text-041 " Material Type

  • text-042 " Division

  • text-043 " Total product life

  • text-044 " Special handling cond

  • text-045 " Freeze prot code

  • text-046 " Action Code

  • INTO v_text SEPARATED BY c_tab.

INTO v_text SEPARATED BY space.

  • CONCATENATE v_text

  • c_cr_lf

  • INTO v_text.

wa_objbin = v_text.

APPEND wa_objbin TO it_objbin.

CLEAR wa_objbin.

*--Populate Data to the attachment

*--assume IT_FINAL will have ur final data to be sent as mail.

LOOP AT it_final INTO wa_final.

CONCATENATE wa_final-matnr

wa_final-matkl

  • x_final-spart

  • x_final-prodlife

  • x_final-behvo

  • x_final-tempb

  • x_final-acode

INTO v_text SEPARATED BY space.

*--Go to next line after this record.

CONCATENATE v_text

c_cr_lf

INTO v_text.

wa_objbin = v_text.

APPEND wa_objbin TO it_objbin.

CLEAR wa_objbin.

ENDLOOP.

*-get total no.of lines of Object table(attachment)

CLEAR : v_table_lines.

DESCRIBE TABLE it_objbin LINES v_table_lines.

*-populate object header(attachment name)

wa_objhead = 'Material change log'(038).

APPEND wa_objhead TO it_objhead.

CLEAR wa_objhead.

*-packing list for attachment

wa_objpack-transf_bin = c_x.

wa_objpack-head_start = 1.

wa_objpack-head_num = 1.

wa_objpack-body_start = 1.

wa_objpack-body_num = v_table_lines .

wa_objpack-doc_type = 'RAW' .

wa_objpack-obj_name = 'MATERIAL'.

wa_objpack-obj_descr = 'attachment'.

wa_objpack-doc_size = v_table_lines * 255.

APPEND wa_objpack TO it_objpack.

CLEAR wa_objpack.

*-Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = x_doc_chng

put_in_outbox = c_x

commit_work = c_x

TABLES

packing_list = it_objpack

object_header = it_objhead

contents_bin = it_objbin

contents_txt = it_objtxt

receivers = it_reclist

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.

MESSAGE e000 WITH 'Error occurred in sending mail'(039).

ELSE.

  • PERFORM f_display_sent_mail_status.

ENDIF.

ENDFORM. " F_SEND_MAIL

&----


*& Form sub_select_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sub_select_data .

CLEAR wa_final.

SELECT SINGLE matnr matkl INTO CORRESPONDING FIELDS OF

wa_final FROM mara.

APPEND wa_final TO it_final.

ENDFORM. " sub_select_data

                            • End Of Report ************************

0 Kudos

thats why i suggest in my recent post , to check with in sap.

give your SAP ID in RECEIVER field

& 'B' in REC_TYPE . & execute it. it will come to your SAP office mail box.

transaction code to check your SAP mail : SO01.

for example :

*--Populate Mail Id's

WA_RECLIST-REC_TYPE = 'B'. 'Within SAP,you will get mail to ur sap office .

WA_RECLIST-EXPRESS = C_X.

WA_RECLIST-RECEIVER = 'SAPID'.

*--Fill up ur SAP id here instead of SAPID value.

*--append receiver table

APPEND WA_RECLIST TO IT_RECLIST.

ENDLOOP.

this will come to ur office mail box.

you can check it in SO10.

Regards

Savitha.

Former Member
0 Kudos

sample program , dont copy and paste ( u will get some syntax error )


the sample program also in alv
*&---------------------------------------------------------------------*
*& Report  YEMAIL_TPW                                                  *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*
report  yemail_tpw.
tables : yemailid ,
         afru,
         yplnt.
*Data Declaration
data:   docdata    like sodocchgi1,
        objpack    like sopcklsti1 occurs  1 with header line,
        objhead    like solisti1   occurs  1 with header line,
        objtxt     like solisti1   occurs 10 with header line,
        objbin     like solisti1   occurs 10 with header line,
        objhex     like solix      occurs 10 with header line,
        reclist    like somlreci1  occurs  1 with header line,
        packing_list like objpack occurs 0 with header line,
        tab_lines  type i,
        doc_size   type i,
        att_type   like soodk-objtp,
        listobject like abaplist   occurs  1 with header line,
        ymail like yemailid occurs 0 with header line,
        yplant like yplnt occurs 0 with header line,
        lines like sy-index,
        msgtab like bdcmsgcoll occurs 0 with header line,
        send_to_all like sonv-flag value 'X'.
*Ranges for werks/budat.
ranges : s_werks for afru-werks,
         s_budat for afru-budat.

*start of selection.
start-of-selection.
*getting the plants list .
 perform get_plant.
 perform get_date.
*Report for all the plants.
 loop at yplant.
*Refreshing all internal tables
 perform refresh.
*Sending the Emails to listed users
 perform create_list_memory.
 endloop.
*Display Errors.
*&---------------------------------------------------------------------*
*&      Form  refresh
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form refresh.
*Clearing the memory contents
clear  : docdata,
         objpack,
         objhead,
         objtxt ,
         objbin ,
         objhex ,
         reclist,
         packing_list,
         tab_lines,
         doc_size,
         att_type,
         listobject,
         ymail ,
         lines .
refresh: objpack,
         objhead,
         objtxt ,
         objbin ,
         objhex ,
         reclist,
         packing_list,
         listobject,
         ymail .
endform.
*&---------------------------------------------------------------------*
*&      Form  get_plant
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_plant.
*selecting production plants only.
select pplnt
       from
       yplnt
       into corresponding fields of table yplant
       where pplnt ne ''.

sort yplant by pplnt.
delete adjacent duplicates from yplant comparing pplnt.
sort yplant by pplnt.
endform.
*&---------------------------------------------------------------------*
*&      Form  create_list_memory
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form create_list_memory.

* Create receiver list
select werks
       mailid
       from
       yemailid
       into corresponding fields of table ymail
       where werks eq yplant-pplnt.

loop at ymail.
reclist-receiver = ymail-mailid.
reclist-rec_type = 'U'.
append reclist.
endloop.
describe table reclist lines lines.
if lines gt 0.
objpack-head_start = 1.
objbin = '  |  '.
append objbin.
describe table objbin lines tab_lines.
objpack-head_start = 1.

*   create list in memory
 submit ysample using selection-set 'PRABHU'
                         with s_werks eq yplant-pplnt
                         with s_budat in s_budat
                         exporting list to memory and return.

*   and read list from memory into table
    call function 'LIST_FROM_MEMORY'
      tables
        listobject       = listobject
      exceptions
        others           = 1.

    if sy-subrc <> 0.
      message id '61' type 'E' number '731'
      with 'LIST_FROM_MEMORY'.
    endif.

    packing_list = objpack.

    call function 'TABLE_COMPRESS'

*     IMPORTING

*       COMPRESSED_SIZE       =

      tables

         in                    = listobject

         out                   = objbin

      exceptions

         others                = 1.

    if sy-subrc <> 0.

      message id '61' type 'E' number '731'

      with 'TABLE_COMPRESS'.

    endif.


* Create Message Body

*   Title and Description
    docdata-obj_name  = 'TEST_ALI'.
    concatenate sy-title 'for   ' yplant-pplnt into
    docdata-obj_descr separated by space .
*   Main Text
    concatenate sy-title 'for' yplant-pplnt into
    objtxt  separated by space.
    append objtxt.
    objtxt = 'Have a nice day.'.
    append objtxt.
*   Write Packing List (Main)

    describe table objtxt lines tab_lines.
    read     table objtxt index tab_lines.
    docdata-doc_size = ( tab_lines - 1 ) * 2560 + strlen( objtxt ).
    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.

* Create Message Attachment
*   Write Packing List (Attachment)
    att_type = 'ALI'.
    describe table objbin lines tab_lines.
    read     table objbin index tab_lines.
    objpack-doc_size = ( tab_lines - 1 ) * 2560 + strlen( objbin ).
    objpack-transf_bin = 'X'.
    objpack-head_start = 1.
    objpack-head_num   = 0.
    objpack-body_start = 1.
    objpack-body_num   = tab_lines.
    objpack-doc_type   = att_type.
    objpack-obj_name   = 'ATTACHMENT'.
    concatenate sy-title 'for' yplant-pplnt into
    objpack-obj_descr separated by space.
    append objpack.
* Send Message

  call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    exporting

      document_data                     = docdata

       put_in_outbox                     = 'X'

       commit_work                       = 'X'     "used from rel.6.10
   importing
      sent_to_all                       = send_to_all
*     NEW_OBJECT_ID                     =

    tables

      packing_list                      = objpack

      object_header                     = objhead

      contents_bin                      = objbin

      contents_txt                      = objtxt

*     CONTENTS_HEX                      = objhex

*     OBJECT_PARA                        =

*     OBJECT_PARB                        =

      receivers                         = reclist

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

    message id 'SO' type 'S' number '023'

            with docdata-obj_name.

  endif.

endif.
endform.
*&---------------------------------------------------------------------*
*&      Form  get_date
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_date.
s_budat-sign   = 'I'.
s_budat-option = 'BT'.
s_budat-low = sy-datum.
s_budat-low+6(2) = '01'.
s_budat-low+4(2) = sy-datum+4(2) - 1.
*Year Change
if s_budat-low+4(2) eq 0.
s_budat-low+0(4) = sy-datum+0(4) - 1.
s_budat-low+4(2) = '12'.
else.
s_budat-low+0(4) = sy-datum+0(4).
endif.
*last day of the last month.
call function 'RP_LAST_DAY_OF_MONTHS'
 exporting
    day_in                  = s_budat-low
 importing
   last_day_of_month        = s_budat-high
* EXCEPTIONS
*   DAY_IN_NO_DATE          = 1
*   OTHERS                  = 2
          .
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
else.
append s_budat.
clear  s_budat.
endif.

endform.

revert back if u have any probs or doubts 

regards

Prabhu

rao_peram@yahoo.com