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

sending internal tables data through email.

Former Member
0 Likes
623

Hi ABAPers,

I want to send the data in my internal table to some mail-id's how can i do that.

I know that we can download the data in one excel sheet and attach that one to the mails. I want to know is there any other way to send the data. If not please any one can send me the code for this.

Thanks & Regards,

Ramana.

Hi ABAPers,

I want to send the data in my internal table to some mail-id's how can i do that.

I know that we can download the data in one excel sheet and attach that one to the mails. I want to know is there any other way to send the data. If not please any one can send me the code for this.

Thanks & Regards,

Ramana.

1 REPLY 1
Read only

Former Member
0 Likes
547

Use this code and execute your program in background. When you will execute your program in Background and you will display your internal table it will create a SPOOL. This spool will be used in below code.

&----


*& Form send_mail

&----


  • *** This subroutine will send the mail to the email recipient

  • *** specified and the report will be sent as a PDF attachement

----


  • --> P_EMAIL Email address of the recipient

  • <-- P_SPONO Spool number of the report

----


FORM send_mail

USING p_spono TYPE sy-spono

p_text TYPE matnr.

  • *** Internal Table Definition

DATA: lit_packlist TYPE STANDARD TABLE OF sopcklsti1,

lit_contents TYPE STANDARD TABLE OF solisti1,

lit_cont_bin TYPE STANDARD TABLE OF solisti1,

lit_content_out TYPE STANDARD TABLE OF solisti1.

  • *** Work Areas Definition

DATA: lwa_subject TYPE sodocchgi1

VALUE IS INITIAL,

lwa_packlist TYPE sopcklsti1

VALUE IS INITIAL,

lwa_cont_bin TYPE solisti1

VALUE IS INITIAL.

  • *** Variables Definition

DATA: lz_tab_lines TYPE i.

  • *** Constants

CONSTANTS: lkc_pdf TYPE sopcklsti1-doc_type

VALUE 'PDF',

lkc_attachment TYPE sopcklsti1-obj_name

VALUE 'ATTACHMENT',

lkc_raw TYPE sopcklsti1-doc_type

VALUE 'RAW'.

  • *** Initialiaing Work Areas and Internal tables

CLEAR: lwa_subject,

lit_packlist[],

lit_cont_bin[],

lit_contents[],

lit_content_out[].

CALL FUNCTION 'ABAP4_COMMIT_WORK'.

  • *** Body for the email

PERFORM fill_msg_body

CHANGING lit_contents[].

  • *** Subject for the email

PERFORM fill_subject

CHANGING lit_contents[]

lwa_subject

lz_tab_lines.

CLEAR lwa_packlist.

lwa_packlist-head_start = 1.

lwa_packlist-head_num = 0.

lwa_packlist-body_start = 1.

lwa_packlist-body_num = lz_tab_lines.

lwa_packlist-doc_type = lkc_raw.

APPEND lwa_packlist TO lit_packlist.

  • *** Fetching spool request and converting it to PDF

PERFORM fetch_spool_2pdf

USING p_spono

CHANGING lit_content_out

z_subrc.

  • *** Message Attachment

lwa_cont_bin = ' | '.

APPEND lwa_cont_bin TO lit_cont_bin.

DESCRIBE TABLE lit_cont_bin LINES lz_tab_lines.

lwa_packlist-transf_bin = 'X'.

lwa_packlist-head_start = lz_tab_lines + 1.

lwa_packlist-head_num = 0.

lwa_packlist-body_start = lz_tab_lines + 1.

APPEND LINES OF lit_content_out[] TO lit_cont_bin[].

DESCRIBE TABLE lit_content_out LINES lz_tab_lines.

lwa_packlist-doc_size = lz_tab_lines * 255.

lwa_packlist-body_num = lz_tab_lines.

lwa_packlist-doc_type = lkc_pdf.

lwa_packlist-obj_name = lkc_attachment.

lwa_packlist-obj_descr = p_text.

APPEND lwa_packlist TO lit_packlist.

CLEAR lwa_packlist.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = lwa_subject

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = lit_packlist

contents_bin = lit_cont_bin

contents_txt = lit_contents

receivers = it_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 NE 0.

WRITE: text-e07.

zn_cancel = 1.

EXIT.

ENDIF. "IF sy-subrc NE 0

  • *** Execute report rsconn01

PERFORM submit_mail.

ENDFORM. " send_mail

&----


*& Form fill_subject

&----


  • *** This subroutine will fill the work area with message, type

  • *** and size.

----


  • <--pit_contents table for message body *

  • <--pwa_subject Work area for subject *

  • <--p_tab_lines No. of lines in content *

----


FORM fill_subject

CHANGING pit_contents TYPE ty_it_solisti1

pwa_subject TYPE sodocchgi1

p_tab_lines TYPE i.

DATA: lwa_contents TYPE solisti1

VALUE IS INITIAL.

DATA: lz_date TYPE string,

lz_subject TYPE string,

lz_time TYPE tims,

lz_am_pm(2) TYPE c,

lz_var1 TYPE string,

lz_var2 TYPE string,

lz_var3 TYPE string.

CONSTANTS: lzc_mail_ali TYPE sodocchgi1-obj_name

VALUE 'MAIL_ALI',

lkc_hyphen TYPE char01 VALUE '-',

lkc_colon TYPE char01 VALUE ':',

lkc_type_time TYPE char01 VALUE 'A',

lkc_am_pm TYPE char03 VALUE 'AM'. .

CALL FUNCTION 'CONVERSION_EXIT_IDATE_OUTPUT'

EXPORTING

input = sy-datum

IMPORTING

output = lz_date.

lz_var1 = lz_date+0(2).

lz_var2 = lz_date+2(3).

lz_var3 = lz_date+5(4).

CLEAR lz_date.

CONCATENATE lz_var1

lkc_hyphen

lz_var2

lkc_hyphen

lz_var3

INTO lz_date.

CALL FUNCTION 'HRVE_CONVERT_TIME'

EXPORTING

type_time = lkc_type_time

input_time = sy-uzeit

input_am_pm = lkc_am_pm

IMPORTING

output_time = lz_time

output_am_pm = lz_am_pm

EXCEPTIONS

parameter_error = 1

OTHERS = 2.

IF sy-subrc NE 0.

MESSAGE e001(zzrefn01)

WITH text-006.

ENDIF. "if sy-subrc ne 0

CLEAR: lz_var1,

lz_var2.

lz_var1 = lz_time+0(2).

lz_var2 = lz_time+2(2).

CLEAR lz_time.

CONCATENATE lz_var1

lkc_colon

lz_var2

INTO lz_time.

CONCATENATE text-m05

lz_date

lz_time

lz_am_pm

INTO lz_subject

SEPARATED BY space.

pwa_subject-obj_name = lzc_mail_ali.

pwa_subject-obj_descr = lz_subject.

DESCRIBE TABLE pit_contents LINES p_tab_lines.

READ TABLE pit_contents

INTO lwa_contents

INDEX p_tab_lines.

IF sy-subrc EQ 0.

pwa_subject-doc_size = ( p_tab_lines - 1 )

  • 255 + STRLEN( lwa_contents ).

ENDIF. "IF sy-subrc EQ 0

ENDFORM. " fill_subject

&----


*& Form fill_msg_body

&----


  • *** This subroutine is used to fill the body of the email mesg

----


  • -->P_LIT_CONTENTS Internal table for message body

----


FORM fill_msg_body

CHANGING pit_contents TYPE ty_it_solisti1.

DATA: lwa_contents TYPE solisti1

VALUE IS INITIAL.

lwa_contents = space.

APPEND lwa_contents TO pit_contents.

CLEAR lwa_contents.

lwa_contents = text-m01.

APPEND lwa_contents TO pit_contents.

CLEAR lwa_contents.

lwa_contents = space.

APPEND lwa_contents TO pit_contents.

CLEAR lwa_contents.

lwa_contents = space.

APPEND lwa_contents TO pit_contents.

CLEAR lwa_contents.

lwa_contents = text-m02.

APPEND lwa_contents TO pit_contents.

CLEAR lwa_contents.

lwa_contents = text-m04.

APPEND lwa_contents TO pit_contents.

CLEAR lwa_contents.

lwa_contents = text-m03.

APPEND lwa_contents TO pit_contents.

CLEAR lwa_contents.

lwa_contents = space.

APPEND lwa_contents TO pit_contents.

CLEAR lwa_contents.

lwa_contents = space.

APPEND lwa_contents TO pit_contents.

CLEAR lwa_contents.

lwa_contents = space.

APPEND lwa_contents TO pit_contents.

CLEAR lwa_contents.

lwa_contents = text-m08.

APPEND lwa_contents TO pit_contents.

CLEAR lwa_contents.

lwa_contents = text-m09.

APPEND lwa_contents TO pit_contents.

ENDFORM. " fill_body

&----


*& Form fetch_spool_2pdf

&----


  • *** This subroutine fetches the spool requests and converts

  • *** it to PDF format and also adjusts the output length

----


  • -->P_LIT_CONTENT_OUT Attachement contents

  • -->P_P_SPONO Spool Request number

----


FORM fetch_spool_2pdf USING p_spono TYPE syspono

CHANGING pit_content_out TYPE ty_it_solisti1

p_subrc TYPE sysubrc.

DATA: lwa_tsp01 TYPE tsp01

VALUE IS INITIAL,

lit_pdfdata TYPE STANDARD TABLE OF tline.

CONSTANTS: lkc_dest TYPE char05 VALUE 'NC037'.

REFRESH pit_content_out.

  • *** Checking if the spool request exists or not

SELECT SINGLE *

FROM tsp01

INTO lwa_tsp01

WHERE rqident EQ p_spono.

IF sy-subrc NE 0.

WRITE: text-e01. "Spool Number does not exist

p_subrc = sy-subrc.

EXIT.

ENDIF. "IF sy-subrc NE 0

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = lwa_tsp01-rqident

no_dialog = ' '

pdf_destination = lkc_dest

TABLES

pdf = lit_pdfdata

EXCEPTIONS

err_no_abap_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_destdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11

OTHERS = 12.

CASE sy-subrc.

WHEN 0.

WHEN 1.

WRITE: text-e02. "No ABAP Spool Job

p_subrc = sy-subrc.

EXIT.

WHEN 2.

WRITE: text-e03. "Spool Number does not exist

p_subrc = sy-subrc.

EXIT.

WHEN 3.

WRITE: text-e04. "No permission for spool

p_subrc = sy-subrc.

EXIT.

WHEN OTHERS.

WRITE: text-e05. "Error in Function CONVERT_ABAPSPOOLJOB_2_PDF

p_subrc = sy-subrc.

EXIT.

ENDCASE. "CASE sy-subrc

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

EXPORTING

line_width_src = 134

line_width_dst = 255

TABLES

content_in = lit_pdfdata

content_out = pit_content_out

EXCEPTIONS

err_line_width_src_too_long = 1

err_line_width_dst_too_long = 2

err_conv_failed = 3

OTHERS = 4.

IF sy-subrc NE 0.

WRITE: text-e06.

p_subrc = sy-subrc.

EXIT.

ENDIF. "IF sy-subrc NE 0

ENDFORM. " fetch_spool_2pdf

&----


*& Form submit_mail

&----


  • *** This subroutine calls the report RSCONN01 which is used

  • *** to push all the mails in the queue to the mailbox of the

  • *** recipient

----


FORM submit_mail .

CONSTANTS: lzc_internet_mails TYPE sxaddrtype-addr_type

VALUE 'INT'.

  • *** Wait for 2 seconds to recieve the mail in the queue.

WAIT UP TO 2 SECONDS.

SUBMIT rsconn01 WITH mode = lzc_internet_mails

WITH output = ''

AND RETURN.

ENDFORM. " submit_mail