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

Script pdf Mail

Former Member
0 Likes
494

Hi Gurus,

This is Sunil

I've created a Program which accepts a sales doc no. and displays the data using scripts, converts the data in pdf and sends a mail to the sold-to-party address.

Foll is my code which is able to display the data, convert it into pdf and also it displays the msg that mail have been sent but th mail is not received at the particular email address specified.

*"Work Variables.......................................................

DATA:

w_options TYPE itcpo, " Work Area of Type itcpo

w_kunnr LIKE vbpa-kunnr, " Variable to Store Customer Number

w_waerk LIKE vbap-waerk, " SD document currency

w_adrnr1 LIKE vbpa-adrnr, " Variable to Store Address Number

" for Bill to Party

w_adrnr2 LIKE vbpa-adrnr, " Variable to Store Address Number

" for Ship to Party

w_size TYPE i, " Size Variable

w_total LIKE vbap-netpr, " Variable to Store Total Price

w_trtext LIKE tvtyt-vtext, " Transport Type Description

w_termtext LIKE tvzbt-vtext, " Description of terms of payment

*"Work Area's..........................................................

wa_vbak TYPE type_s_vbak, " Work Area to hold Sales Header Data

wa_vbap TYPE type_s_vbap, " Work Area to hold Sales Item Data

wa_vbkd TYPE type_s_vbkd, " Work Area to hold Business Data

wa_adrc LIKE adrc, " Work Area to Hold Addresses

wa_tline TYPE tline, " Work Area of Type TLINE

"----


  • Internal table to hold Sales Item Data. *

"----


t_vbap LIKE

STANDARD TABLE

OF wa_vbap,

"----


  • Internal table to hold Sales Business Data. *

"----


t_vbkd LIKE

STANDARD TABLE

OF wa_vbkd,

"----


  • Internal table of Type OTF Structure. *

"----


t_otf TYPE

STANDARD TABLE

OF itcoo WITH HEADER LINE,

"----


  • Internal table to Store SAPscript: Text Lines. *

"----


t_pdf TYPE

STANDARD TABLE

OF tline WITH HEADER LINE.

"----


  • Variables Declared for Sending Mail. *

"----


*"Work Variables.......................................................

DATA:

lw_tablines TYPE i, " Variable to store Table Lines

*"Work Areas...........................................................

wa_doc_data TYPE sodocchgi1, " Work Area of Type SODOCCHGI1

wa_pack TYPE sopcklsti1, " Work Area of Type SOPCKLSTI1

*"Internal Tables......................................................

t_pack TYPE TABLE OF sopcklsti1,

t_mail TYPE solisti1 OCCURS 10 WITH HEADER LINE,

t_receivers LIKE somlrec90 OCCURS 0 WITH HEADER LINE,

t_solisti1 LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_mailbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,

t_mailhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.

----


  • Form convert_otf *

----


  • This Subroutine Converts the Output of the Script to OTF Format. *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM convert_otf.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

  • MAX_LINEWIDTH = 132

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

IMPORTING

bin_filesize = w_size

  • BIN_FILE =

TABLES

otf = t_otf[]

lines = t_pdf[]

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

err_bad_otf = 4

OTHERS = 5

.

IF sy-subrc <> 0.

WRITE: 'OTF : ', sy-subrc.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " convert_otf

----


  • Form convert_otf_to_pdf *

----


  • This Subroutine Converts the OTF Format to the PDF Format and *

  • Stores it in a PDF File. *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM convert_otf_to_pdf .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = w_size

filename = 'd:\terra.pdf'

filetype = 'BIN'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = t_pdf[]

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22

.

IF sy-subrc <> 0.

WRITE: 'OTF : ', sy-subrc.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " convert_otf_to_pdf

----


  • Form pdf_to_mail *

----


  • This Subroutine Converts the OTF Format to the PDF Format and *

  • Stores it in a PDF File. *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM pdf_to_mail.

"----


  • Document Data. *

"----


wa_doc_data-obj_descr = 'Terra Object created by Sunil Saini'.

wa_doc_data-obj_name = 'TEST'.

"----


  • Contents Text. *

"----


*Contents of the Mail.

t_mail-line = 'This Mail contains the Sales and Item Data for Specified Sales Order'.

APPEND t_mail.

"----


  • Preparing Packing List. *

"----


PERFORM prepare_packing_list.

t_receivers-receiver = ' '. " Hard code the Destination mail address

t_receivers-rec_type = 'U'.

*t_receivers-com_type = 'INT'.

*t_receivers-notif_del = 'X'.

*t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = wa_doc_data

put_in_outbox = 'X'

  • commit_work = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = t_pack

object_header = t_mailhead

contents_bin = t_mailbin

contents_txt = t_mail

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = t_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: 'Mail : ', sy-subrc.

  • MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

  • WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ELSE.

WRITE : 'Mail Sent to specified address'.

ENDIF.

ENDFORM. " pdf_to_mail

----


  • Form prepare_packing_list *

----


  • This Subroutine Converts the OTF Format to the PDF Format and *

  • Stores it in a PDF File. *

----


  • There are no interface parameters to be passed to this subroutine. *

----


FORM prepare_packing_list.

CLEAR t_solisti1.

REFRESH t_solisti1.

LOOP AT t_otf.

t_solisti1-line = t_otf.

APPEND t_solisti1.

ENDLOOP.

DESCRIBE TABLE t_mail LINES lw_tablines.

READ TABLE t_mail INDEX lw_tablines.

wa_doc_data-doc_size = ( lw_tablines - 1 ) * 255 + STRLEN( t_mail ).

*Description of Imported Object Components.

CLEAR wa_pack.

wa_pack-head_start = 1.

wa_pack-head_num = 0.

wa_pack-body_start = 1.

wa_pack-body_num = lw_tablines.

wa_pack-doc_type = 'RAW'.

  • wa_pack-doc_size = wa_pack-body_num * 255.

APPEND wa_pack TO t_pack.

LOOP AT t_solisti1.

MOVE-CORRESPONDING t_solisti1 TO t_mailbin.

APPEND t_mailbin.

ENDLOOP.

DESCRIBE TABLE t_mailbin LINES lw_tablines.

t_mailhead = 'TEST.OTF'.

APPEND t_mailhead.

wa_pack-transf_bin = 'X'.

wa_pack-head_start = 1.

wa_pack-head_num = 1.

wa_pack-body_start = 1.

wa_pack-body_num = lw_tablines.

wa_pack-doc_type = 'OTF'.

wa_pack-obj_name = 'TEST'.

wa_pack-obj_descr = 'Subject'.

wa_pack-doc_size = lw_tablines * 255.

APPEND wa_pack TO t_pack.

ENDFORM. " prepare_packing_list

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
466

Can you check in transaction SOST whether the mail is successfully generated and processed?

2 REPLIES 2
Read only

Former Member
0 Likes
467

Can you check in transaction SOST whether the mail is successfully generated and processed?

Read only

0 Likes
466

Thanks for ur Reply

I've checked it in SOST there was a mistake I've done I've Uncommented Commit = 'X'.

Now I've got the Mail but still the data is not getting attached to the Mail.