RE:SX_TABLE_line_width_change
Hi,
How to use this function module SX_TABLE_line_width_change
According to the "where used" for this function module, it is called from function SO_OBJECT_CONVERT_TO_WI, and its purpose there is to convert an internal table OBJCONT that is 255 bytes wide into an internal table, CONTENT, that is as wide as CONTENT-LINES (1024 bytes):
* * convert object content in archive format
DESCRIBE FIELD CONTENT-LINES LENGTH ARCHIVE_LINE
in character mode.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
LINE_WIDTH_SRC = 255
LINE_WIDTH_DST = ARCHIVE_LINE
TABLES
CONTENT_IN = OBJCONT
CONTENT_OUT = CONTENT
EXCEPTIONS
ERR_CONV_FAILED = 1
OTHERS = 2.
Jonathan
Similar Messages
-
Email with text attachment with line width 1250
Dear all,
I want to send the email with text attachment whose line width in text file is 1250. Kindly let me know how to send email attachment with more than 255 line width.
Regards,
Manoj
Moderator Message: Frequently Asked Question. Please search for available information before posting.
Edited by: kishan P on Apr 29, 2011 2:48 PMHi,
What ever text you are sending in the email, create a standard text for it using tcode SO10. In the program use the FM READ_TEXT to get the data into internal table which will be of length 132 char. If you want line widht of 255 chars convert using FM SX_TABLE_LINE_WIDTH_CHANGE as below,
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_dst = '255'
TABLES
content_in = it_data
content_out = it_mess_att
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
Use FM SO_NEW_DOCUMENT_ATT_SEND_API1 to send email.
Hope this will help you.
regards,
Tulasi. -
Want to Send smartform as pdf attachment with a Email to some mail id
Hi ,
I want to send a smartform as a PDF attachment with a mail to a mail id. And I can send a mail with the PDF attachment.
But I am not able to open the PDF. It is throwing some error (Adobe reader could not open u2018fileu2019 because it is either not a supported file type or because the file has been damaged (for example , it was sent as an email attachment and was not correctly decoded)).
By debugging I come to know that the file which is generating is in some encoding format.
Please help me regard this. This is very urgent.
here is the code,
Main Program :
REPORT Ztest_report.
*--Top Include for Global Data Declarations.
INCLUDE ztest_report_top.
*--Form Include for Form Routines.
INCLUDE ztest_report_form.
START-OF-SELECTION.
START-OF-SELECTION.
*--Display data
Perform display_data.
END-OF-SELECTION.
Top declaration :
Internal table
DATA : i_otfdata TYPE tsfotf, " Smart Forms: Table OTF
i_tline TYPE TABLE OF tline WITH HEADER LINE,
i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
Objects to send mail.
i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
Work Area declarations
w_mailaddr TYPE ppfdmailad,
w_mailtype TYPE so_escape,
w_mailrecipient TYPE swotobjid,
w_control TYPE ssfctrlop,
w_compop TYPE ssfcompop,
w_return TYPE ssfcrescl,
wa_doc_chng TYPE sodocchgi1,
w_data TYPE sodocchgi1,
wa_buffer TYPE string, "To convert from 132 to 255
wa_objhead TYPE soli_tab,
Variables declarations
v_form_name TYPE rs38l_fnam,
v_len_in LIKE sood-objlen,
v_len_out LIKE sood-objlen,
v_len_outn TYPE i,
v_lines_txt TYPE i,
v_lines_bin TYPE i.
Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-009.
PARAMETER: p_bukrs TYPE bukrs OBLIGATORY, "Company Code
p_belnr TYPE belnr_d OBLIGATORY, "Document No
p_gjahr TYPE gjahr OBLIGATORY, "document type
p_mailid(50) TYPE c OBLIGATORY.
"Mail Id
SELECTION-SCREEN END OF BLOCK blk1.
Form Logic :
FORM display_data.
*Local Variable declaration
DATA: lc_fm TYPE rs38l_fnam, "local variable to store the
l_i_document_output_info TYPE ssfcrespd,
l_i_struc_job_output_info TYPE ssfcrescl,
l_i_struc_job_output_options TYPE ssfcrescl,
i_lines TYPE TABLE OF tline WITH HEADER LINE,
lv_job_output_info TYPE ssfcrescl,
lv_document_output_info TYPE ssfcrespd,
lv_job_output_options TYPE ssfcresop,
lv_bin_filesize LIKE sood-objlen.
Determine the smartform name
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZTEST_SMARTFORM'
IMPORTING
fm_name = lc_fm
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
w_control-getotf = 'X'.
w_control-no_dialog = 'X'.
w_control-preview = space.
w_control-device = 'MAIL'.
Call the smartform and pass the selection screen parameter
CALL FUNCTION lc_fm
EXPORTING
control_parameters = w_control
output_options = w_compop
user_settings = 'X'
t_bukrs = p_bukrs
t_belnr = p_belnr
t_gjahr = p_gjahr
IMPORTING
job_output_info = l_i_struc_job_output_info
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Moving the Smart Forms: Table OTF into an internal table
i_otfdata[] = l_i_struc_job_output_info-otfdata[].
CONVERT TO OTF TO PDF.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = lv_bin_filesize
TABLES
otf = i_otfdata
lines = i_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
IF sy-batch EQ l_c_no.
To directly view the print-preview in PDF format
CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
EXPORTING
i_otf = i_otfdata
EXCEPTIONS
convert_otf_to_pdf_error = 1
cntl_error = 2
OTHERS = 3.
For Sending the PDF file to a Mail ID.
LOOP AT i_lines.
TRANSLATE i_lines USING '~'.
CONCATENATE wa_buffer i_lines INTO wa_buffer.
ENDLOOP.
TRANSLATE wa_buffer USING '~'.
DO.
i_record = wa_buffer.
APPEND i_record.
SHIFT wa_buffer LEFT BY 255 PLACES.
IF wa_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
DATA: BEGIN OF zlines OCCURS 0,
tline TYPE char255,
END OF zlines.
*Change the PDF format from 132 to 255.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
transfer_bin = 'X'
TABLES
content_in = i_lines
content_out = zlines
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Attachment
REFRESH: i_reclist,
i_objtxt,
i_objbin,
i_objpack.
CLEAR wa_objhead.
i_objbin[] = zlines[].
Create Message Body Title and Description
i_objtxt = 'test with pdf-Attachment!'.
APPEND i_objtxt.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
READ TABLE i_objtxt INDEX v_lines_txt.
wa_doc_chng-obj_name = 'smartform'.
wa_doc_chng-expiry_dat = sy-datum + 10.
wa_doc_chng-obj_descr = 'smartform'.
wa_doc_chng-sensitivty = 'F'.
wa_doc_chng-doc_size = v_lines_txt * 255.
Main Text
CLEAR i_objpack-transf_bin.
i_objpack-head_start = 1.
i_objpack-head_num = 1.
i_objpack-body_start = 2.
i_objpack-body_num = v_lines_txt.
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
Attachment (pdf-Attachment)
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 1.
i_objpack-body_start = 2.
I_OBJPACK-DOC_TYPE = 'RAW'.
DESCRIBE TABLE i_objbin LINES v_lines_bin.
READ TABLE i_objbin INDEX v_lines_bin.
i_objpack-doc_size = v_lines_bin * 255 .
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'smart'.
i_objpack-obj_descr = 'test'.
APPEND i_objpack.
CLEAR i_reclist.
i_reclist-receiver = p_mailid.
i_reclist-rec_type = 'U'.
APPEND i_reclist.
Send new document with attachments via RFC
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = i_objpack
object_header = wa_objhead
contents_bin = i_objbin
contents_txt = i_objtxt
receivers = i_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.
WRITE:/ 'Error When Sending the File', sy-subrc.
ELSE.
WRITE:/ 'Mail sent'.
ENDIF.
ENDFORM. " display_datahi,
i wrote a programm.for me it is working.i think it will help for u.
DATA: t_otfdata TYPE ssfcrescl,
t_lines LIKE tline OCCURS 0 WITH HEADER LINE,
t_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
t_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
Objects to send mail.
DATA:T_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,
T_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
T_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
T_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE.
DATA: w_filesize TYPE i,
w_bin_filesize TYPE i,
wa_ctrlop TYPE ssfctrlop,
wa_outopt TYPE ssfcompop,
WA_BUFFER TYPE STRING, "To convert from 132 to 255
WA_OBJHEAD TYPE SOLI_TAB,
WA_DOC_CHNG TYPE SODOCCHGI1,
W_DATA TYPE SODOCCHGI1.
DATA: form_name TYPE rs38l_fnam,
V_LINES_TXT TYPE I,
V_LINES_BIN TYPE I,
nast-spras type sy-langu value 'DE'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = 'ZSR_DEMO1'
VARIANT = ' '
DIRECT_CALL = ' '
IMPORTING
FM_NAME = form_name
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
wa_ctrlop-LANGU = nast-spras.
wa_ctrlop-getotf = 'X'.
wa_ctrlop-no_dialog = 'X'.
wa_outopt-tdnoprev = 'X'.
CALL FUNCTION form_name
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
CONTROL_PARAMETERS = wa_ctrlop
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
OUTPUT_OPTIONS = wa_outopt
USER_SETTINGS = 'X'
IMPORTING
DOCUMENT_OUTPUT_INFO =
JOB_OUTPUT_INFO = t_otfdata
JOB_OUTPUT_OPTIONS =
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
t_otf[] = t_otfdata-otfdata[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
ARCHIVE_INDEX = ' '
COPYNUMBER = 0
ASCII_BIDI_VIS2LOG = ' '
PDF_DELETE_OTFTAB = ' '
IMPORTING
BIN_FILESIZE = w_bin_filesize
BIN_FILE =
TABLES
OTF = t_otf
LINES = t_lines
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
ERR_BAD_OTF = 4
OTHERS = 5
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at t_lines.
TRANSLATE t_lines USING '~'.
CONCATENATE WA_BUFFER T_LINES INTO WA_BUFFER.
ENDLOOP.
TRANSLATE WA_BUFFER USING '~'.
DO.
t_RECORD = WA_BUFFER.
APPEND t_RECORD.
SHIFT WA_BUFFER LEFT BY 255 PLACES.
IF WA_BUFFER IS INITIAL.
EXIT.
ENDIF.
ENDDO.
Attachment
REFRESH: T_RECLIST,
T_OBJTXT,
T_OBJBIN,
T_OBJPACK.
CLEAR WA_OBJHEAD.
T_OBJBIN[] = T_RECORD[].
Create Message Body Title and Description
T_OBJTXT = 'test with pdf-Attachment!'.
APPEND T_OBJTXT.
DESCRIBE TABLE T_OBJTXT LINES V_LINES_TXT.
READ TABLE T_OBJTXT INDEX V_LINES_TXT.
WA_DOC_CHNG-OBJ_NAME = 'smartform'.
WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.
WA_DOC_CHNG-OBJ_DESCR = 'smartform'.
WA_DOC_CHNG-SENSITIVTY = 'F'.
WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.
Main Text
CLEAR T_OBJPACK-TRANSF_BIN.
T_OBJPACK-HEAD_START = 1.
T_OBJPACK-HEAD_NUM = 0.
T_OBJPACK-BODY_START = 1.
T_OBJPACK-BODY_NUM = V_LINES_TXT.
T_OBJPACK-DOC_TYPE = 'RAW'.
APPEND T_OBJPACK.
Attachment (pdf-Attachment)
T_OBJPACK-TRANSF_BIN = 'X'.
T_OBJPACK-HEAD_START = 1.
T_OBJPACK-HEAD_NUM = 0.
T_OBJPACK-BODY_START = 1.
DESCRIBE TABLE T_OBJBIN LINES V_LINES_BIN.
READ TABLE T_OBJBIN INDEX V_LINES_BIN.
T_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .
T_OBJPACK-BODY_NUM = V_LINES_BIN.
T_OBJPACK-DOC_TYPE = 'PDF'.
T_OBJPACK-OBJ_NAME = 'smart'.
T_OBJPACK-OBJ_DESCR = 'test'.
APPEND T_OBJPACK.
CLEAR T_RECLIST.
T_RECLIST-RECEIVER = 'mail id'.
T_RECLIST-REC_TYPE = 'U'.
APPEND T_RECLIST.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = WA_DOC_CHNG
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = T_OBJPACK
OBJECT_HEADER = WA_OBJHEAD
CONTENTS_BIN = T_OBJBIN
CONTENTS_TXT = T_OBJTXT
RECEIVERS = T_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.
WRITE:/ 'Error When Sending the File', SY-SUBRC.
ELSE.
WRITE:/ 'Mail sent'.
ENDIF.
please reward me if helpful. -
Change width of fields displayed on PDF from ALV
Hello,
I have a requirement in which i have to print an alv report in a pdf , now in the report say there are 11 fields of which 5 are hidden , so when i print the report in pdf , in the pdf output the entire width of the page is not occupied but only the width of the displayed fields
for eg. The 6 fields being displayed will cover only a part of the page..however i want the fields to occupy the entire page depending on the fields that are displayed .. plz advice how i can achieve this..Hi,
<li>After converting to PDF, try to use SX_TABLE_LINE_WIDTH_CHANGE function module to change the width of the PDF.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = g_spool_no
no_dialog = ' '
IMPORTING
pdf_bytecount = l_no_of_bytes
pdf_spoolid = l_pdf_spoolid
btc_jobname = l_jobname
btc_jobcount = l_jobcount
TABLES
pdf = i_pdf
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.
MESSAGE s000(0k) WITH 'No ABAP Spool Job'.
EXIT.
WHEN 2.
MESSAGE s000(0k) WITH 'Spool Number does not exist'.
EXIT.
WHEN 3.
MESSAGE s000(0k) WITH 'No permission for spool'.
EXIT.
WHEN OTHERS.
MESSAGE s000(0k)
WITH 'Error in Function CONVERT_ABAPSPOOLJOB_2_PDF'.
EXIT.
ENDCASE.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_src = 134
line_width_dst = 255
TABLES
content_in = i_pdf
content_out = l_attachment
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.
MESSAGE s000(0k) WITH 'Conversion Failed'.
EXIT.
ENDIF.
Thanks
Venkat.O -
Smartform to OTF to PDF attached to an email ERROR
Hi everyone... I have this problem... I need to send a smartform attached to an email... I'm doing the following:
- Create the OTF using the smartform function importing job_output_info.
- Convert the OTF (job_output_info-otfdata) to PDF using CONVERT_OTF_2_PDF.
- Change the table line's width using SX_TABLE_LINE_WIDTH_CHANGE.
- Send the email using SO_NEW_DOCUMENT_ATT_SEND_API1.
Everything seems to be OK. But When I check the PDF file attached in the email and open it, everything there is a mess. The letters are superimposed over each other and the grills are not painted (instead it shows a black block).
Any ideas how to solve this???
Thanks a lot!!!Try this out..!
<removed by moderator>
To convert the script out put to PDF.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF' u201C FOR out put format
max_linewidth = 132 u201CFor ASCII format: Number of lines in LINES-TDLINE
IMPORTING
bin_filesize = gv_bin_filesize u201CFile size reference
TABLES
otf = gt_otf u201CInput table with OTF format
lines = gt_pdf_tab " Output table with target format
To mail Order in PDF format:
Data declaration part :
DATA: gt_reclist TYPE TABLE OF somlreci1, " SAPoffice: Structure of the API Recipient List
gt_pdf_tab TYPE TABLE OF tline, " SAPscript: Text Lines
gt_otf TYPE TABLE OF itcoo, " OTF Structure
gt_objbin TYPE TABLE OF solisti1, " SAPoffice: Single List with Column Length 255
gt_objpack TYPE TABLE OF sopcklsti1. " SAPoffice: Description of Imported Object Components
DATA: gv_form_name TYPE rs38l_fnam, " Used to store the function module generated by Smartform
gv_bin_filesize TYPE i, " Store the file size
gv_pos TYPE i,
gv_len TYPE i,
gv_tab_lines TYPE i.
DATA : gc_text(11) TYPE c VALUE 'Form Output',
gc_tst(3) TYPE c VALUE 'TST',
gc_testing(30) TYPE c VALUE 'Zellar Sales Document'.
1. Assigning the Description of the object sent in the mail
CLEAR gs_docdata.
gs_docdata-obj_name = gc_tst.
gs_docdata-obj_descr = gc_testing.
Assigning the email id to Structure of the API Recipient List table
CLEAR : gt_reclist, gs_reclist. u201C variables used
gs_reclist-receiver = mail address'. u201CTo whom this mail should go
GS_RECLIST-REC_TYPE = 'U'.
APPEND gs_reclist TO gt_reclist. u201C Internal table for storing mail address
2.Passing the Smart form text lines to SAP office: Single List with Column Length 255 table ,this logic is used to get all the data into PDF file while you send an attachment through mail..
CLEAR: gs_objbin, gs_pdf_tab.
LOOP AT gt_pdf_tab INTO gs_pdf_tab. u201CLoop the content of PDF table
gv_pos = 255 - gv_len.
IF gv_pos > 134. "length of pdf_table
gv_pos = 134.
ENDIF.
gs_objbin+gv_len = gs_pdf_tab(gv_pos).
gv_len = gv_len + gv_pos.
IF gv_len = 255. "length of out (contents_bin)
APPEND gs_objbin TO gt_objbin.
CLEAR: gs_objbin, gv_len.
IF gv_pos < 134.
gs_objbin = gs_pdf_tab+gv_pos.
gv_len = 134 - gv_pos.
ENDIF.
ENDIF.
ENDLOOP.
IF gv_len > 0.
APPEND gs_objbin TO gt_objbin. u201CTable contains Single List with Column Length 255 table
ENDIF.
3. Filling the details in SAPoffice: Description of Imported Object Components table
DESCRIBE TABLE gt_objbin LINES gv_tab_lines.
CLEAR gs_objbin.
READ TABLE gt_objbin INTO gs_objbin INDEX gv_tab_lines.
IF sy-subrc = 0.
gs_objpack-doc_size = ( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objbin ).
gs_objpack-transf_bin = 'X'.
gs_objpack-head_start = 1.
gs_objpack-head_num = 0.
gs_objpack-body_start = 1.
gs_objpack-body_num = gv_tab_lines.
gs_objpack-doc_type = 'PDF'.
gs_objpack-obj_name = 'ATTACHMENT'.
gs_objpack-obj_descr = 'test'.
APPEND gs_objpack TO gt_objpack.
ENDIF.
4. Sending the Form Output in the PDF format to email
data: WK_OBJHEAD TYPE SOLI_TAB.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' u201Cfunction module used for sending mail
EXPORTING
document_data = gs_docdata u201CAttributes of new document
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = gt_objpack u201CInformation about structure of data tables
OBJECT_HEADER = WK_OBJHEAD u201CHeader data for document (spec.header)
contents_bin = gt_objbin u201CData which is to be sent as pdf attachment
receivers = gt_reclist u201Cmailing list
EXCEPTIONS u201CException Handling
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 sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
WRITE 'Sent Successfully'.
ENDIF.
Edited by: Thomas Zloch on Jul 16, 2010 10:38 PM -
Smartform to convert as pdf attachment and sending mail.
Program to convert smartform as PDF and send PDF as an atachment to email id.
********Variable Declarations ****************************
DATA: gv_form_name TYPE rs38l_fnam, " Used to store the function module generated by Smartform
gv_bin_filesize TYPE i, " Store the file size
gv_pos TYPE i,
gv_len TYPE i,
gv_tab_lines TYPE i.
*******Constants ******************************************
DATA : gc_text(11) TYPE c VALUE 'Form Output',
gc_tst(3) TYPE c VALUE 'TST',
gc_testing(7) TYPE c VALUE 'Testing'.
CONSTANTS : c_formname TYPE tdsfname VALUE 'ZSMART_T'. "Zsmart_t is the smartform name.
********Work Area Declarations ****************************
DATA: gs_docdata TYPE sodocchgi1, " Data of an object which can be changed
gs_ctrlop TYPE ssfctrlop, " Smart Forms: Control structure
gs_outopt TYPE ssfcompop, " SAP Smart Forms: Smart Composer (transfer) options
gs_otfdata TYPE ssfcrescl, " Smart Forms: Return value at end of form printing
gs_reclist TYPE somlreci1, " SAPoffice: Structure of the API Recipient List
gs_pdf_tab TYPE tline, " Workarea for SAP Script Text Lines
gs_objbin TYPE solisti1, " SAPoffice: Single List with Column Length 255
gs_objpack TYPE sopcklsti1. " SAPoffice: Description of Imported Object Components
********Internal tables Declarations ****************************
DATA: gt_reclist TYPE TABLE OF somlreci1, " SAPoffice: Structure of the API Recipient List
gt_pdf_tab TYPE TABLE OF tline, " SAPscript: Text Lines
gt_otf TYPE TABLE OF itcoo, " OTF Structure
gt_objbin TYPE TABLE OF solisti1, " SAPoffice: Single List with Column Length 255
gt_objpack TYPE TABLE OF sopcklsti1. " SAPoffice: Description of Imported Object Components
DATA: customer TYPE scustom,
bookings TYPE ty_bookings,
connections TYPE ty_connections.
CLEAR : gv_form_name,
gs_ctrlop,
gs_outopt,
gs_otfdata,
gv_bin_filesize,
gv_pos,
gv_len,
gv_tab_lines.
START-OF-SELECTION.
Generate Function Module name
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = c_formname
IMPORTING
fm_name = gv_form_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Assigning values to Form Control Structure and Form Composer
gs_ctrlop-getotf = 'X'.
gs_ctrlop-device = 'PRINTER'.
gs_ctrlop-preview = ''.
gs_ctrlop-no_dialog = 'X'.
gs_outopt-tddest = 'LP01'. "or 'LOCL'.
Getting the OTFDATA
CALL FUNCTION gv_form_name
EXPORTING
control_parameters = gs_ctrlop
output_options = gs_outopt
user_settings = ' '
customer = customer
bookings = bookings
connections = connections
IMPORTING
job_output_info = gs_otfdata
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Assigning the OTFDATA to OTF Structure table
CLEAR gt_otf.
gt_otf[] = gs_otfdata-otfdata[].
Convert the OTF DATA to SAP Script Text lines
CLEAR gt_pdf_tab.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = gv_bin_filesize
TABLES
otf = gt_otf
lines = gt_pdf_tab
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Assigning the Description of the object sent in the mail
CLEAR gs_docdata.
gs_docdata-obj_name = gc_tst.
gs_docdata-obj_descr = gc_testing.
Assigning the email id to Structure of the API Recipient List table
CLEAR : gt_reclist, gs_reclist.
IF internal mail id
gs_reclist-receiver = sy-uname.
GS_RECLIST-REC_TYPE = 'B'.
if external mail id
gs_reclist-receiver = mailid.com'.
gs_reclist-rec_type = 'U'.
APPEND gs_reclist TO gt_reclist.
Passing the SAP Script text lines to SAPoffice: Single List with Column Length 255 table
CLEAR : gs_objbin, gs_pdf_tab.
LOOP AT gt_pdf_tab INTO gs_pdf_tab.
gv_pos = 255 - gv_len.
IF gv_pos > 134. "length of pdf_table
gv_pos = 134.
ENDIF.
gs_objbin+gv_len = gs_pdf_tab(gv_pos).
gv_len = gv_len + gv_pos.
IF gv_len = 255. "length of out (contents_bin)
APPEND gs_objbin TO gt_objbin.
CLEAR: gs_objbin, gv_len.
IF gv_pos < 134.
gs_objbin = gs_pdf_tab+gv_pos.
gv_len = 134 - gv_pos.
ENDIF.
ENDIF.
ENDLOOP.
IF gv_len > 0.
APPEND gs_objbin TO gt_objbin.
ENDIF.
Filling the details in SAPoffice: Description of Imported Object Components table
DESCRIBE TABLE gt_objbin LINES gv_tab_lines.
CLEAR gs_objbin.
READ TABLE gt_objbin INTO gs_objbin INDEX gv_tab_lines.
IF sy-subrc = 0.
gs_objpack-doc_size = ( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objbin ).
gs_objpack-transf_bin = 'X'.
gs_objpack-head_start = 1.
gs_objpack-head_num = 0.
gs_objpack-body_start = 1.
gs_objpack-body_num = gv_tab_lines.
gs_objpack-doc_type = 'PDF'.
gs_objpack-obj_name = 'ATTACHMENT'.
gs_objpack-obj_descr = 'test'.
APPEND gs_objpack TO gt_objpack.
ENDIF.
Sending the Form Output in the PDF format to email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gs_docdata
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = gt_objpack
contents_bin = gt_objbin
receivers = gt_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 sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
WRITE 'Sent Successfully'.
ENDIF.
SUBMIT rsconn01
WITH mode EQ 'INT'
AND RETURN.
END-OF-SELECTION.Hi
Use function modules
CALL FUNCTION 'CONVERT_OTF'
and CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE' to convert as a pdf document
for sending mail CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
Regards,
Gopi -
To download the print format and mail it on giving a range of customers
Hai
i have a smartform attached program to a report.
my selection screen contains only customer number (in range) and sales office code.
on executing the program will generate a printfile file for each customers.
i posted this question already and got the reply but the selection screen has only one parameter called p_mail(where u pass the address straight away).but i need the pdf format to get splitted for each and every customers and to mail them automatically.
where to write the coding for fetching the email addressess of the customers and how to loop it in order to send for all the customers automaticlly.
how to pass the parameters in the function module.
please explain to me clearly.i am in need of help.
this is the program i got for sending one mail.i get confused as how this will work for the range of customers.somebody please solve me this problem.kindly tell me where to do the changes
REPORT ztest_smartform.
DATA:it_nfal TYPE nfal OCCURS 0 WITH HEADER LINE.
DATA:fm_name TYPE rs38l_fnam.
DATA:ssfctrlop TYPE ssfctrlop.
DATA:ssfcompop TYPE ssfcompop.
DATA:it_otf_data TYPE ssfcrescl.
DATA:it_otf_final TYPE itcoo OCCURS 0 WITH HEADER LINE.
DATA:bin_filesize TYPE i.
DATA:it_pdfdata TYPE TABLE OF tline.
DATA:it_pdf TYPE TABLE OF solisti1.
" Mail related declarations
"Variables
DATA :
g_sent_to_all TYPE sonv-flag,
g_tab_lines TYPE i.
"Types
TYPES:
t_document_data TYPE sodocchgi1,
t_packing_list TYPE sopcklsti1,
t_attachment TYPE solisti1,
t_body_msg TYPE solisti1,
t_receivers TYPE somlreci1,
t_pdf TYPE tline.
"Workareas
DATA :
w_document_data TYPE t_document_data,
w_packing_list TYPE t_packing_list,
w_attachment TYPE t_attachment,
w_body_msg TYPE t_body_msg,
w_receivers TYPE t_receivers,
w_pdf TYPE t_pdf.
"Internal Tables
DATA :
i_document_data TYPE STANDARD TABLE OF t_document_data,
i_packing_list TYPE STANDARD TABLE OF t_packing_list,
i_attachment TYPE STANDARD TABLE OF t_attachment,
i_body_msg TYPE STANDARD TABLE OF t_body_msg,
i_receivers TYPE STANDARD TABLE OF t_receivers,
i_pdf TYPE STANDARD TABLE OF t_pdf.
PARAMETERS p_mail type char120.
*START-OF-SELECTION.
START-OF-SELECTION.
"select data
SELECT * FROM nfal INTO TABLE it_nfal UP TO 10 ROWS.
ssfctrlop-no_dialog = 'X'.
ssfctrlop-preview = 'X'.
ssfctrlop-getotf = 'X'.
ssfcompop-tddest = 'LP01'.
Continued
Venkat.O
Posts: 1,036
Registered: 12/2/05
Forum Points: 1,782
Re: to down load the print format to pdf and sent the data thru the mail
Posted: Jul 15, 2009 7:31 AM in response to: amalrose Reply
from above
"Get Function module name for given smartform
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZTEST_SMARTFORM'
IMPORTING
fm_name = fm_name.
"Call Smartform function module.
CALL FUNCTION fm_name
EXPORTING
control_parameters = ssfctrlop
output_options = ssfcompop
IMPORTING
job_output_info = it_otf_data
TABLES
it_nfal = it_nfal.
***********appending the otf data into the final table*********************
it_otf_final[] = it_otf_data-otfdata[].
converting OTF data into pdf data**************************
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = bin_filesize
bin_file =
TABLES
otf = it_otf_final
lines = it_pdfdata[]
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
To send data as email attachment, we need to have a table of SOLISTI1.
This table contains line size of 255 characters. Below function module
does the trick of changing the table from X character sized lines into
any given Y character sized lines.
REFRESH it_pdf[].
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_dst = '255'
TABLES
content_in = it_pdfdata[]
content_out = it_pdf[]
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
IF sy-subrc 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
Continued
Venkat.O
Posts: 1,036
Registered: 12/2/05
Forum Points: 1,782
Re: to down load the print format to pdf and sent the data thru the mail
Posted: Jul 15, 2009 7:32 AM in response to: amalrose Reply
from above
"Subject of the mail.
w_document_data-obj_name = 'MAIL_TO_HEAD'.
w_document_data-obj_descr = 'Regarding Mail Program by SAP ABAP'.
"Body of the mail
w_body_msg = 'This is body of mail msg.'.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
"Write Packing List for Body
DESCRIBE TABLE i_body_msg LINES g_tab_lines.
w_packing_list-head_start = 1.
w_packing_list-head_num = 0.
w_packing_list-body_start = 1.
w_packing_list-body_num = g_tab_lines.
w_packing_list-doc_type = 'RAW'.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Write Packing List for Attachment
w_packing_list-transf_bin = 'X'.
w_packing_list-head_start = 1.
w_packing_list-head_num = 1.
w_packing_list-body_start = 1.
DESCRIBE TABLE it_pdf LINES w_packing_list-body_num.
w_packing_list-doc_type = 'PDF'.
w_packing_list-obj_descr = 'PDF Attachment'.
w_packing_list-obj_name = 'PDF_ATTACHMENT'.
w_packing_list-doc_size = w_packing_list-body_num * 255.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Fill the document data and get size of attachment
w_document_data-obj_langu = sy-langu.
READ TABLE it_pdf INTO w_pdf INDEX g_tab_lines.
w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_attachment ).
"Receivers List.
w_receivers-rec_type = 'U'."Internet address
w_receivers-receiver = p_mail.
w_receivers-com_type = 'INT'.
w_receivers-notif_del = 'X'.
w_receivers-notif_ndel = 'X'.
APPEND w_receivers TO i_receivers .
CLEAR:w_receivers.
"Function module to send mail to Recipients
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_document_data
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = g_sent_to_all
TABLES
packing_list = i_packing_list
contents_bin = it_pdf
contents_txt = i_body_msg
receivers = i_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 .
MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.
ENDIF.
ENDIF.Here:
http://www.adobe.com/cfusion/tdrc/index.cfm?product=photoshop_elements&loc=en
Was it deactivated on the old computer? If not, you may need to contact Adobe support by clicking on "Chat"
Serial number and activation support -
E-mail of PDF issue TLINE structure but SOLISTI1 needed
Hi,
So far I have done the following. I have prepared a SMARTFORM and an ABAP. My ABAP calls the Smartform and gives the data to the function module CONVERT_OTF. This function creates a PDF file from the Smartform data. The output of "CONVERT_OTF" is a table with the format of structure TLINE. In a first step I save these data into a PDF file with the function module "GUI_DOWNLOAD".
Now the issue.
In the second step I am trying to send the output with the function SO_DOCUMENT_SEND_API1. The function is recommended by SAP for release 6.4 instead of the former function "SO_NEW_DOCUMENT_ATT_SEND_API1".
The attachment must be delivered either with the structure SOLISTI1 or SOLIX to be sent with the e-mail function SO_DOCUMENT_SEND_API1. I have tried to put my data with structure TLINE into the function. In these case I get short dumps. If I put the output of the function CONVERT_OTF in a table with the format SOLISTI1 instead of a table with structure TLINE a PDF file is still created and also send out with the e-mail function, but the file cant be opened anymore. Acrobat delivers an error message that the file is damaged.
I have tried to convert the file with structure TLINE in a hexadecimal file with structure SOLIX. For this purpose I used the function TABLE_COMPRESS. This worked fine. But the file which has been sent by the e-mail was still damaged. Even if I have downloaded the file I got the message that the file was damaged.
Are there any other suggestions how the attachment could be sent instead of using the function SO_DOCUMENT_SEND_API1? Is there a function available, which could be used to sent attachments with structure TLINE? Or are there any suggestions, how I can convert my smartform output in a SOLIX or SOLISTI1 structure?
Thank you and best regards
KarstenHi Arold,
<b>1</b>.
Have a look at this program.
This program is sending PDF file as attachment thru mail
<b>2</b>.
REPORT zvenkat_mail.
TABLES :
tsp01.
Itabs and variables .
*Tables
DATA:
BEGIN OF i_mard OCCURS 0,
matnr TYPE mard-matnr,
werks TYPE mard-werks,
lgort TYPE mard-lgort,
labst TYPE mard-labst,
umlme TYPE mard-umlme,
insme TYPE mard-insme,
einme TYPE mard-einme,
END OF i_mard.
DATA :
g_sy_spono LIKE sy-spono.
Mail related Variables and i tabs.
DATA:
w_subject LIKE sodocchgi1,
i_pack_list LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
i_objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
i_contents_text LIKE solisti1 OCCURS 10 WITH HEADER LINE,
i_cont_bin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
i_objhex LIKE solix OCCURS 10 WITH HEADER LINE,
i_receiver LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
i_listobject LIKE abaplist OCCURS 1 WITH HEADER LINE,
pdf LIKE tline OCCURS 100 WITH HEADER LINE,
content_out LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA:
tab_lines TYPE i,
doc_size TYPE i,
att_type LIKE soodk-objtp,
obj_desc LIKE w_subject-obj_descr,
sent_to_all LIKE sonv-flag,
client LIKE tst01-dclient,
name LIKE tst01-dname,
objtype LIKE rststype-type,
type LIKE rststype-type,
is_otf TYPE c ,
no_of_bytes TYPE i,
pdf_spoolid LIKE tsp01-rqident,
jobname LIKE tbtcjob-jobname,
jobcount LIKE tbtcjob-jobcount,
pn_begda LIKE sy-datum,
val(1) TYPE c,
pripar TYPE pri_params,
arcpar TYPE arc_params,
lay TYPE pri_params-paart,
lines TYPE pri_params-linct,
cols TYPE pri_params-linsz,
spool_name TYPE pri_params-plist.
*& START-OF-SELECTION.
START-OF-SELECTION.
PERFORM get_data_from_database.
PERFORM output_for_pdf.
*& END-OF-SELECTION.
END-OF-SELECTION.
PERFORM send_mail..
*& Form get_data_from_database
FORM get_data_from_database .
SELECT matnr
werks
lgort
labst
umlme
insme
einme
FROM mard
INTO TABLE i_mard
UP TO 20 ROWS.
ENDFORM. " get_data_from_database
*& Form output_for_pdf
FORM output_for_pdf .
PERFORM get_print_params.
LOOP AT i_mard.
WRITE:/ sy-vline, i_mard-matnr,
sy-vline, i_mard-werks,
sy-vline, i_mard-lgort,
sy-vline, i_mard-labst,
sy-vline, i_mard-umlme,
sy-vline, i_mard-insme,
sy-vline, i_mard-einme,
sy-vline.
ENDLOOP.
ULINE .
g_sy_spono = sy-spono.
NEW-PAGE PRINT OFF.
CALL FUNCTION 'ABAP4_COMMIT_WORK'.
ENDFORM. " output_for_pdf
*& Form send_mail
FORM send_mail .
PERFORM mail_without_attachment.
PERFORM mail_with_pdf_attachment.
PERFORM mail_with_exel_attachment.
PERFORM mail_with_text_attachment.
ENDFORM. " send_mail
*& Form mail_with_pdf_attachment
FORM mail_with_pdf_attachment .
CLEAR :w_subject,
sent_to_all,
i_pack_list[],
i_objhead[],
i_cont_bin[],
i_contents_text[],
i_receiver[].
i_cont_bin = ' | '.
APPEND i_cont_bin.
Subject of the mail.
obj_desc = 'Hello SDN Friends ' .
w_subject-obj_name = 'MAIL_ALI'.
w_subject-obj_descr = obj_desc.
Body of the mail
DATA :head_desc LIKE i_contents_text,
body_desc LIKE i_contents_text.
i_contents_text = space.
APPEND i_contents_text.
CLEAR i_contents_text.
CONCATENATE
'This mail has been generated for Test purpose.'
'Please dont hesitate to ask any type of question in the forum.'
INTO body_desc
SEPARATED BY space.
i_contents_text = body_desc.
APPEND i_contents_text.
CLEAR i_contents_text.
CLEAR body_desc.
i_contents_text = 'Thank You.'.
APPEND i_contents_text.
CLEAR i_contents_text.
i_contents_text = 'Fellow SDN member,'.
APPEND i_contents_text.
CLEAR i_contents_text.
i_contents_text = 'Venkat.O'.
APPEND i_contents_text.
CLEAR i_contents_text.
i_contents_text = space.
APPEND i_contents_text.
CLEAR i_contents_text.
CONCATENATE '(Note: This is system generated message, please'
'do not reply'
'to this Email.)'
INTO i_contents_text
SEPARATED BY space.
APPEND i_contents_text.
CLEAR i_contents_text.
Write Packing List (Body)
DESCRIBE TABLE i_contents_text LINES tab_lines.
READ TABLE i_contents_text INDEX tab_lines.
w_subject-doc_size = ( tab_lines - 1 ) * 255 + STRLEN(
i_contents_text ).
CLEAR i_pack_list-transf_bin.
i_pack_list-head_start = 1.
i_pack_list-head_num = 0.
i_pack_list-body_start = 1.
i_pack_list-body_num = tab_lines.
i_pack_list-doc_type = 'RAW'.
APPEND i_pack_list.
CLEAR i_pack_list.
Create receiver list
i_receiver-receiver = '[email protected]'..
i_receiver-rec_type = 'U'.
APPEND i_receiver.
CLEAR i_receiver.
Select query for Spool requests
REFRESH content_out.
IF sy-subrc = 0.
SELECT SINGLE *
FROM tsp01
WHERE rqident = g_sy_spono.
IF sy-subrc <> 0.
MESSAGE s000(0k) WITH 'Spool Number does not exist'.
EXIT.
ELSE.
client = tsp01-rqclient.
name = tsp01-rqo1name.
ENDIF.
ENDIF.
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'.
is_otf = 'X'.
ELSE.
is_otf = space.
ENDIF.
Convert Spool job to PDF
IF is_otf = 'X'.
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = tsp01-rqident "Spool req number
no_dialog = ' '
IMPORTING
pdf_bytecount = no_of_bytes
pdf_spoolid = pdf_spoolid
btc_jobname = jobname
btc_jobcount = jobcount
TABLES
pdf = pdf
EXCEPTIONS
err_no_otf_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_dstdevice = 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.
MESSAGE s000(0k) WITH 'No OTF Spool Job'.
EXIT.
WHEN 2.
MESSAGE s000(0k) WITH 'Spool Number does not exist'.
EXIT.
WHEN 3.
MESSAGE s000(0k) WITH 'No permission for spool'.
EXIT.
WHEN OTHERS.
MESSAGE s000(0k) WITH 'Error in Function CONVERT_OTFSPOOLJOB_2_PDF'.
EXIT.
ENDCASE.
ELSE.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = tsp01-rqident
no_dialog = ' '
IMPORTING
pdf_bytecount = no_of_bytes
pdf_spoolid = pdf_spoolid
btc_jobname = jobname
btc_jobcount = jobcount
TABLES
pdf = pdf
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.
MESSAGE s000(0k) WITH 'No ABAP Spool Job'.
EXIT.
WHEN 2.
MESSAGE s000(0k) WITH 'Spool Number does not exist'.
EXIT.
WHEN 3.
MESSAGE s000(0k) WITH 'No permission for spool'.
EXIT.
WHEN OTHERS.
MESSAGE s000(0k)
WITH 'Error in Function CONVERT_ABAPSPOOLJOB_2_PDF'.
EXIT.
ENDCASE.
ENDIF.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_src = 134
line_width_dst = 255
TABLES
content_in = pdf
content_out = 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 <> 0.
MESSAGE s000(0k) WITH 'Conversion Failed'.
EXIT.
ENDIF.
---------------------Create Message Attachment
DESCRIBE TABLE i_cont_bin LINES tab_lines.
i_pack_list-transf_bin = 'X'.
i_pack_list-head_start = tab_lines + 1.
i_pack_list-head_num = 0.
i_pack_list-body_start = tab_lines + 1.
APPEND LINES OF content_out[] TO i_cont_bin[].
DESCRIBE TABLE content_out LINES tab_lines.
i_pack_list-doc_size = tab_lines * 255.
i_pack_list-body_num = tab_lines.
i_pack_list-doc_type = 'PDF'.
i_pack_list-obj_name = 'ATTACHMENT'.
i_pack_list-obj_descr = 'Materials and their Quantities' .
APPEND i_pack_list.
CLEAR i_pack_list.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_subject
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = sent_to_all
TABLES
packing_list = i_pack_list
object_header = i_objhead
contents_bin = i_cont_bin
contents_txt = i_contents_text
receivers = i_receiver
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.
ENDIF.
ENDFORM. " mail_with_pdf_attachment
*& Form get_print_params
FORM get_print_params .
lay = 'X_65_132'.
lines = 65.
cols = 132.
CALL FUNCTION 'GET_PRINT_PARAMETERS'
EXPORTING
in_archive_parameters = arcpar
in_parameters = pripar
layout = lay
line_count = lines
line_size = cols
no_dialog = 'X'
IMPORTING
out_archive_parameters = arcpar
out_parameters = pripar
valid = val
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
OTHERS = 4.
IF val <> space AND sy-subrc = 0.
pripar-prrel = space.
pripar-primm = space.
NEW-PAGE PRINT ON
NEW-SECTION
PARAMETERS pripar
ARCHIVE PARAMETERS arcpar
NO DIALOG.
ENDIF.
ENDFORM. " get_print_params
I hope it helps u .
<b>Thanks,
Venkat.O</b> -
I am trying to email my smartform output to a specified email address, but I am getting an error messege as mail could not me send as in the function module 'SO_NEW_DOCUMENT_SEND_API1'
Below is the code. The smartform contains a logo only.
Pls see the code and tell me what isn that I am missing!
*& Report ZKHA_SMARTFORM
REPORT zkha_smartform.
TYPE-POOLS: slis,
abap.
DATA : BEGIN OF it_mara OCCURS 0,
matnr LIKE mara-matnr,
END OF it_mara.
DATA: wa_ctrlop TYPE ssfctrlop, "Smart Forms: Control structure
wa_outopt TYPE ssfcompop, " SAP Smart Forms: Smart Composer (transfer)
t_otfdata TYPE ssfcrescl, "Smart Forms: Return value at end of form Printing
t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE, "#EC *
t_otf TYPE itcoo OCCURS 100 WITH HEADER LINE,"#EC * "itcoo is OTF Struct
w_filesize TYPE i, "#EC *
w_bin_filesize TYPE i, "#EC NEEDED
fm_name TYPE rs38l_fnam.
DATA : fullpath TYPE string, "#EC *
filename TYPE string, "#EC *
path TYPE string, "#EC *
user_action TYPE i, "#EC *
encoding TYPE abap_encoding. "#EC *
PARAMETERS: p_file TYPE rlgrap-filename NO-DISPLAY.
DATA: numbytes TYPE i,
cancel.
*wa_outopt-tddest = ' '.
wa_ctrlop-getotf = 'X'.
wa_ctrlop-no_dialog = 'X'.
*wa_outopt-tdnoprev = 'X'.
*wa_outopt-tdnoprint = 'X'. " CHANGED HERE
*wa_ctrlop-device = 'MAIL'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'Z_KHATEST1'
VARIANT = ' '
DIRECT_CALL = ' '
IMPORTING
fm_name = fm_name
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION fm_name
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
control_parameters = wa_ctrlop " CHANGED HERE
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
output_options = wa_outopt " CHANGED HERE
user_settings = 'X'
IMPORTING
DOCUMENT_OUTPUT_INFO =
job_output_info = t_otfdata
JOB_OUTPUT_OPTIONS =
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*CASE sy-ucomm.
WHEN 'PRNT'. " ADDED HERE
t_otf[] = t_otfdata-otfdata[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
ARCHIVE_INDEX = ' '
COPYNUMBER = 0
ASCII_BIDI_VIS2LOG = ' '
PDF_DELETE_OTFTAB = ' '
IMPORTING
bin_filesize = w_bin_filesize
BIN_FILE =
TABLES
otf = t_otf
lines = t_pdf_tab
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Data: t_objbin type standard table of SOLISTI1 with header line.
Converted to length of 255 Char
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
LINE_WIDTH_SRC =
LINE_WIDTH_DST = '255'
TRANSFER_BIN = ' '
TABLES
content_in = t_pdf_tab
content_out = t_objbin
EXCEPTIONS
ERR_LINE_WIDTH_SRC_TOO_LONG = 1
ERR_LINE_WIDTH_DST_TOO_LONG = 2
ERR_CONV_FAILED = 3
OTHERS = 4
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
PERFORM download_w_ext(rstxpdft) TABLES t_pdf_tab
USING p_file
'.pdf'
'BIN'
numbytes
cancel. "#EC *
CLEAR: wa_outopt, wa_ctrlop.
*ENDCASE.
DATA:
t_tline TYPE TABLE OF tline,
t_reclist TYPE TABLE OF somlreci1,
wa_doc_chng TYPE sodocchgi1,
wa_reclist TYPE somlreci1,
wa_return TYPE ssfcrescl,
v_descr TYPE so_obj_des,
v_mailid TYPE ad_smtpadr,
v_adrnr TYPE ad_addrnum ,
v_len_in TYPE string.
wa_doc_chng-obj_name = 'SMARTFORM'.
wa_doc_chng-expiry_dat = sy-datum + 10.
wa_doc_chng-obj_descr = v_descr.
wa_doc_chng-sensitivty = 'F'.
wa_doc_chng-obj_langu = sy-langu.
wa_doc_chng-no_change = 'X' .
Selecting email address depending on
address no.from ADR6 Table
SELECT smtp_addr "E-Mail Address
FROM adr6 UP TO 1 ROWS
INTO v_mailid
WHERE addrnumber = v_adrnr.
ENDSELECT .
wa_reclist-receiver = v_mailid.
wa_reclist-receiver = '[email protected]'.
" I have hard coded the mail address. It is automatically populating the adr6 table, I donno why???
Pls give immediate resolution!!!!
wa_reclist-rec_type = 'U'.
APPEND wa_reclist TO t_reclist.
break-point.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = wa_doc_chng
DOCUMENT_TYPE = 'PDF'
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
tables
OBJECT_HEADER =
OBJECT_CONTENT = t_objbin
CONTENTS_HEX =
OBJECT_PARA =
OBJECT_PARB =
receivers = t_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 SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.Use the following steps for doing the same. These steps are tested succesfully.
1. Get the Function Module Name for the Smart form
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = c_fmname
VARIANT = ' '
DIRECT_CALL = ' '
IMPORTING
FM_NAME = w_fmname
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3
2. Set the values to be passed in the Function Module to get the output of the Smart form in OTF format.
Set the call for OTF format.
t_control_parameters-no_dialog = c_x.
t_control_parameters-getotf = c_x.
3. Call the function Module for the smartform.
CALL FUNCTION w_fmname
EXPORTING
ARCHIVE_INDEX = H_ARCHIVE_INDEX
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS = H_ARCHIVE_PARAMS
CONTROL_PARAMETERS = t_control_parameters
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
OUTPUT_OPTIONS =
USER_SETTINGS = 'X'
Variable = v_flag
IMPORTING
DOCUMENT_OUTPUT_INFO =
JOB_OUTPUT_INFO = w_job_output_info
JOB_OUTPUT_OPTIONS =
TABLES
I_table = t_itab
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5
4. Convert the OTF format to PDF format using the w_job_output_info-otfdata
DATA: l_filesize TYPE i,
t_lines LIKE tline OCCURS 0,
t_objbin TYPE ty_tab_objbin.
**/ Get the PDF version of the OTF
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = l_filesize
bin_file = bin_file
TABLES
otf = w_job_output_info-otfdata
lines = t_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
5. Convert the PDF format to format required for attachment.
**/ Convert the PDF format to the table type required for the attachment.
CALL FUNCTION 'QCE1_CONVERT'
TABLES
t_source_tab = t_lines
t_target_tab = t_objbin
EXCEPTIONS
convert_not_possible = 1
OTHERS = 2.
6. Create the document to be sent by e-mail
Creation of the document to be sent
File Name: Name of the file to be attached
w_doc_chng-obj_name = Flename.
Mail Subject
w_doc_chng-obj_descr = Test E-mail(em1).
Completing the recipient list
t_reclist-receiver = t_rec. e-mail id of the recipient
t_reclist-rec_type = 'U'.
APPEND t_reclist.
Mail Contents
t_objtxt = 'Line 1'(bd1).
APPEND t_objtxt.
CLEAR t_objtxt.
APPEND t_objtxt. " to put in a blank line
t_objtxt = 'Line 2'(bd2).
APPEND t_objtxt.
CLEAR t_objtxt.
t_objtxt = Line 3'(bd3).
APPEND t_objtxt.
CLEAR t_objtxt.
APPEND t_objtxt. " to put in a blank line
t_objtxt = Line 4(bd3).
APPEND t_objtxt.
Calculate email size in bytes
DESCRIBE TABLE t_objtxt LINES w_tab_lines.
READ TABLE t_objtxt INDEX w_tab_lines.
w_doc_chng-doc_size = ( w_tab_lines - 1 ) * 255 + STRLEN( t_objtxt ).
Creation of the entry for the compressed document
for the email text
CLEAR t_objpack-transf_bin.
t_objpack-head_start = 1.
t_objpack-head_num = 0.
t_objpack-body_start = 1.
t_objpack-body_num = w_tab_lines.
t_objpack-doc_type = 'RAW'.
APPEND t_objpack.
Creation of the document attachment
(Assume that the data in OBJBIN is in BMP format)
DESCRIBE TABLE p_objbin LINES w_tab_lines.
t_objhead = Fielname.PDF'(em5).
APPEND t_objhead.
CLEAR t_objpack.
**/ Creation of the entry for the compressed/attached document
t_objpack-transf_bin = c_x.
t_objpack-head_start = 1.
t_objpack-head_num = 1.
t_objpack-body_start = 1.
t_objpack-body_num = w_tab_lines.
t_objpack-doc_type = 'PDF'.
t_objpack-obj_name = 'Possibly hover name'.
t_objpack-obj_descr = Mail Description'(em6).
t_objpack-doc_size = w_tab_lines * 255.
APPEND t_objpack.
7. Send the document by e-mail
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_doc_chng
put_in_outbox = c_x
TABLES
packing_list = t_objpack
object_header = t_objhead
contents_bin = t_objbin
contents_txt = t_objtxt
receivers = t_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
IF sy-subrc <> 0.
WRITE: / text-014, sy-subrc.
ELSE.
WRITE: / text-015.
ENDIF.
8. Commit work: this step is important to send the email to transaction SOST.
Once the email has reached the transaction SOST then its the job of the basis to do the configuration to send it to the specified e-mail id by internet.
**commit work for the email to go into transaction SOST.
COMMIT WORK.
9. In transaction SOST the mail will appear. -
Error while sending by email a PDF from SMARTFORM
Hi all.
Wer'e upgrading to EP4 and I can send smartform PDF by email but get an error message while trying to open it.
*FORM convert_otf_2_pdf.
call function 'CONVERT_OTF_2_PDF'
importing
bin_filesize = lv_len_in
tables
otf = gs_return-otfdata[]
doctab_archive = it_docs[]
lines = lt_tline[]
exceptions
err_conv_not_possible = 1
err_otf_mc_noendmarker = 2
others = 3.
if sy-subrc ne 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
*then to send it as Email attachemnt we need to format the PDF data
call function 'SX_TABLE_LINE_WIDTH_CHANGE'
exporting
line_width_dst = '255'
tables
content_in = lt_tline
content_out = lt_objbin
exceptions
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
others = 4.
clear ls_solisti.
ls_solisti = 'Payment Notification'.
append ls_solisti to lt_objtxt.
DESCRIBE TABLE lt_objtxt LINES lv_lines.
READ TABLE lt_objtxt INDEX lv_lines.
ls_doc_chg-obj_name = 'Payment Notification'.
ls_doc_chg-expiry_dat = sy-datum + 10.
ls_doc_chg-obj_descr = 'Payment Notification'.
ls_doc_chg-sensitivty = 'F'.
ls_doc_chg-doc_size = 255.
ls_objpack-head_start = 1.
ls_objpack-head_num = 0.
ls_objpack-body_start = 1.
ls_objpack-body_num = 1. "lv_lines.
ls_objpack-doc_type = 'RAW'.
append ls_objpack to lt_objpack.
(pdf-Attachment)
ls_objpack-transf_bin = 'X'.
ls_objpack-head_start = 1.
ls_objpack-head_num = 0.
ls_objpack-body_start = 1.
describe table lt_objbin lines lv_lines.
"READ TABLE lt_objbin INDEX lv_lines.
ls_objpack-doc_size = lv_lines * 255 .
ls_objpack-body_num = lv_lines.
ls_objpack-doc_type = 'PDF'.
ls_objpack-obj_name = 'NOTIF'.
ls_objpack-obj_descr = 'Payment Notif.'.
append ls_objpack to lt_objpack.
clear lt_dli[].
lv_name = p_list.
call function 'SO_DLI_READ_API1'
exporting
dli_name = lv_name
dli_id = '000000000001'
shared_dli = 'X'
tables
dli_entries = lt_dli
exceptions
dli_not_exist = 1
operation_no_authorization = 2
parameter_error = 3
x_error = 4
others = 5.
if sy-subrc eq 0 and
lt_dli[] is not initial.
clear ls_reclist.
ls_reclist-receiver = p_list.
ls_reclist-rec_type = 'C'.
append ls_reclist to lt_reclist.
endif.
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = ls_doc_chg
put_in_outbox = ''
tables
packing_list = lt_objpack
object_header = ls_objhead
contents_bin = lt_objbin
contents_txt = lt_objtxt
receivers = lt_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.
What's wrong ??
Thanks all,
RebekaHello,
Try below code
LOOP AT gt_check_data INTO gw_inc_payment.
CLEAR wa_pa0105.
READ TABLE gt_pa0105 INTO wa_pa0105
WITH KEY pernr = gw_inc_payment-pernr.
IF sy-subrc = 0. ELSE. CONDENSE wa_pa0105-usrid_long NO-GAPS.
TRANSLATE wa_pa0105-usrid_long TO LOWER CASE.
ENDIF.
CALL FUNCTION 'ZHR_ITA_MAIL_PDF'
EXPORTING
im_incentive = gw_ita_inc
im_flag = 'X'
IMPORTING
ls_job_output_info = ls_op_info
EXCEPTIONS
cntl_error_ctrl = 1
cntl_error_cont = 2
cntl_error_load = 3
cntl_error_show = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE text-024 TYPE 'E'.
ELSE.
CLEAR gt_tline[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = g_pdfsize
TABLES
otf = ls_op_info-otfdata
lines = gt_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
IF sy-subrc <> 0.
IF gt_tline IS INITIAL.
MESSAGE text-023 TYPE 'E'.
ENDIF.
ELSE.
Data handling with required length
LOOP AT gt_tline INTO gw_tline.
lv_pos = 255 - lv_len.
IF lv_pos > 134. "length of pdf_table
lv_pos = 134.
ENDIF.
gw_objbin+lv_len = gw_tline(lv_pos).
lv_len = lv_len + lv_pos.
IF lv_len = 255. "length of out (contents_bin)
APPEND gw_objbin TO gt_objbin.
CLEAR: gw_objbin, lv_len.
IF lv_pos < 134.
gw_objbin = gw_tline+lv_pos.
lv_len = 134 - lv_pos.
ENDIF.
ENDIF.
ENDLOOP.
IF lv_len > 0.
APPEND gw_objbin TO gt_objbin.
ENDIF.
CLEAR gw_objbin.
Mail process with the PDF attachment
PERFORM mail_process_attach USING wa_pa0105-usrid_long.
ENDIF.
ENDIF.
ENDLOOP.
FORM mail_process_attach USING lv_receive TYPE comm_id_long.
**//--- For Sending eMail
DATA : it_packing_list TYPE TABLE OF sopcklsti1,
wa_packing_list TYPE sopcklsti1,
it_receivers TYPE TABLE OF somlreci1,
wa_receivers TYPE somlreci1,
it_message TYPE TABLE OF solisti1,
wa_message TYPE solisti1,
it_line TYPE STANDARD TABLE OF tline,
wa_line TYPE tline,
it_attachment TYPE TABLE OF solisti1,
wa_attachment TYPE solisti1,
wa_doc_data TYPE sodocchgi1,
lv_cnt TYPE i,
lv_tablines TYPE i,
lv_subject TYPE so_obj_des,
lv_incref TYPE string.
*--Populating Mail Recepients
wa_receivers-rec_type = 'U'.
wa_receivers-com_type = 'INT'.
wa_receivers-notif_del = 'X'.
wa_receivers-notif_ndel = 'X'.
wa_receivers-express = 'X'.
assgining a receiver's mail id
wa_receivers-receiver = lv_receive.
APPEND wa_receivers TO it_receivers.
CLEAR wa_receivers.
*--Populating the body
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = 'ST'
language = sy-langu
name = gc_so10_name
object = 'TEXT'
TABLES
lines = it_line
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc = 0.
LOOP AT it_line INTO wa_line.
wa_message-line = wa_line-tdline.
APPEND wa_message TO it_message.
CLEAR : wa_line, wa_message.
ENDLOOP.
ENDIF.
*//--- Populate the subject/generic message attributes
wa_doc_data-obj_langu = sy-langu.
READ TABLE it_attachment INTO wa_attachment INDEX lv_cnt.
wa_doc_data-doc_size = ( lv_cnt - 1 ) * 255 + STRLEN( wa_attachment ).
wa_doc_data-obj_name = 'SAPRPT'.
*//--- Subject Begin
CLEAR : lv_subject.
lv_subject = gw_inc_payment-pernr.
SHIFT lv_subject LEFT DELETING LEADING '0'.
CONCATENATE text-009 '(' lv_subject ')'
INTO wa_doc_data-obj_descr
SEPARATED BY space.
*//--- Subject End
wa_doc_data-sensitivty = 'F'.
*--Describe the body of the message
CLEAR : wa_packing_list, it_packing_list[].
wa_packing_list-transf_bin = space.
wa_packing_list-head_start = 1.
wa_packing_list-head_num = 0.
wa_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES wa_packing_list-body_num.
wa_packing_list-doc_type = 'RAW'.
APPEND wa_packing_list TO it_packing_list.
Filling the attachment table
DESCRIBE TABLE gt_objbin LINES lv_tablines.
wa_packing_list-transf_bin = 'X'.
wa_packing_list-head_start = 1.
wa_packing_list-head_num = 0.
wa_packing_list-body_start = 1.
wa_packing_list-body_num = lv_tablines.
wa_packing_list-doc_type = 'PDF'.
wa_packing_list-obj_name = 'ATTACHMENT'(a01).
*//--- Attachment File Name - Begin
CLEAR : lv_subject.
lv_subject = gw_inc_payment-pernr.
lv_incref = gw_inc_payment-incref.
SHIFT lv_subject LEFT DELETING LEADING '0'.
SHIFT lv_incref LEFT DELETING LEADING '0'.
CONCATENATE text-011
lv_subject
gw_inc_payment-itafy
lv_incref
INTO wa_packing_list-obj_descr
SEPARATED BY '_'.
*//--- Attachment File Name - End
wa_packing_list-doc_size = lv_tablines * 255.
APPEND wa_packing_list TO it_packing_list.
CLEAR wa_packing_list.
calling the function module to send the mail
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = wa_doc_data
put_in_outbox = 'X'
sender_address = gc_sender
sender_address_type = 'INT'
commit_work = 'X'
TABLES
packing_list = it_packing_list
contents_bin = gt_objbin[]
contents_txt = it_message
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 <> 0.
gw_inc_payment-zmail = '0'.
gw_inc_payment-mail_status = text-022.
gw_ita_inc-zmail = '0'.
MODIFY gt_inc_payment FROM gw_inc_payment
TRANSPORTING zmail WHERE incref = gw_inc_payment-incref
AND pernr = gw_inc_payment-pernr.
MODIFY zhr_ita_inc_payk FROM gw_ita_inc.
MESSAGE text-013 TYPE 'E'.
CLEAR gw_ita_inc.
ELSE.
gw_inc_payment-zmail = '1'.
gw_inc_payment-mail_status = text-021.
gw_ita_inc-zmail = '1'.
MODIFY gt_inc_payment FROM gw_inc_payment
TRANSPORTING zmail mail_status
WHERE incref = gw_inc_payment-incref AND
pernr = gw_inc_payment-pernr.
IF sy-subrc = 0.
MODIFY zhr_ita_inc_payk FROM gw_ita_inc.
IF sy-subrc = 0.
MESSAGE text-012 TYPE 'S'.
ENDIF.
ENDIF.
CLEAR gw_ita_inc.
ENDIF.
CLEAR : it_packing_list,
gt_objbin[],
it_message[],
it_receivers[],
wa_doc_data.
ENDFORM. " MAIL_PROCESS_ATTACH
regards -
Send smartform as pdf attachment through Email on ECC 5.0
I have been trying hard to do this, but am not able to send attachment. Below are the problems -
1. If sometimes the mail goes, the attachment is empty.
2. if i use COMMIT_WORK = 'X' in FM SO_NEW_DOCUMENT_ATT_SEND_API1 , it throws a dump - ' Invalid COMMIT WORK in an update function module.'
3. If i comment COMMIT_WORK = 'X', it gets executed successfully but, in the program i get a dump 'UC_OBJECTS_NOT_CHAR' exception.
Can someone suggest, what settings are required in SAP to send smartforms as PDF attachments. Also, please suggest how can i remove the dump. If anyone can give me a working program, it will be very very helpful.
here is the code,
REPORT zrsmfmail.
TYPE-POOLS: addi.
Tables defination.
TABLES : vbpa,vbak,nast, stxl, stxh.
Data Decleration .
DATA: lf_fm_name TYPE rs38l_fnam,
l_lines TYPE i.
DATA: output_options TYPE ssfcompop.
DATA: fcodem TYPE sy-ucomm.
DATA: i_id LIKE thead-tdid VALUE 'V002',
i_object LIKE thead-tdobject VALUE 'VBBK' ,
i_tdname LIKE thead-tdname ,
i_lang LIKE thead-tdspras VALUE 'E' .
Internal Table declration.
DATA: int_vbak LIKE vbak OCCURS 0 WITH HEADER LINE,
int_vbap LIKE vbap OCCURS 0 WITH HEADER LINE.
DATA : itline1 LIKE tline OCCURS 0 WITH HEADER LINE .
DATA: retcode LIKE sy-subrc. "Returncode
DATA: repeat(1) TYPE c.
DATA: xscreen(1) TYPE c. "Output on printer or screen
Internal Table declarations
DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
i_tline TYPE TABLE OF tline WITH HEADER LINE,
i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
Objects to send mail.
i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
lt_att_content_hex LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
Work Area declarations
wa_objhead TYPE soli_tab,
w_ctrlop TYPE ssfctrlop,
w_compop TYPE ssfcompop,
w_return TYPE ssfcrescl,
wa_doc_chng TYPE sodocchgi1,
w_data TYPE sodocchgi1,
wa_buffer TYPE string,
Variables declarations
v_form_name TYPE rs38l_fnam,
v_len_in LIKE sood-objlen,
v_len_out LIKE sood-objlen,
v_len_outn TYPE i,
v_lines_txt TYPE i,
v_lines_bin TYPE i.
DATA: BEGIN OF zlines2 OCCURS 0,
tline TYPE char255,
END OF zlines2,
size TYPE i,
zdata TYPE sodocchgi1.
*& Form entry
FORM entry USING return_code TYPE i
us_screen TYPE c.
CLEAR retcode.
xscreen = us_screen.
PERFORM processing.
IF retcode NE 0.
return_code = 1.
ELSE.
return_code = 0.
ENDIF.
ENDFORM. "ENTRY
*& Form PROCESSING
text
FORM processing.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE int_vbak
FROM vbak
WHERE vbeln = nast-objky.
LOOP AT int_vbak .
i_tdname = int_vbak-vbeln .
SELECT SINGLE * FROM stxh WHERE tdobject = i_object
AND tdname = i_tdname
AND tdid = i_id
AND tdspras = i_lang.
IF sy-subrc = 0 .
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = i_id
language = i_lang
name = i_tdname
object = i_object
TABLES
lines = itline1.
IF sy-subrc NE 0 .
APPEND itline1 .
ENDIF .
ENDIF .
DESCRIBE TABLE int_vbak LINES l_lines.
l_lines = l_lines .
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZORDER_QUOTE'
IMPORTING
fm_name = v_form_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
w_ctrlop-getotf = 'X'.
w_ctrlop-no_dialog = 'X'.
w_compop-tdnoprev = 'X'.
CALL FUNCTION v_form_name
EXPORTING
l_lines = l_lines
control_parameters = w_ctrlop
output_options = w_compop
user_settings = 'X'
IMPORTING
job_output_info = w_return
TABLES
int_vbak = int_vbak
int_vbap = int_vbap
itline1 = itline1
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
i_otf[] = w_return-otfdata[].
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = size
TABLES
otf = i_otf
lines = i_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
Fehlerhandling
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Change the PDF format from 132 to 255.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
transfer_bin = 'X'
TABLES
content_in = i_tline
content_out = zlines2
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
others = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Attachment
REFRESH:
i_reclist,
i_objtxt,
i_objbin,
i_objpack.
CLEAR wa_objhead.
i_objtxt = 'TEST PDF ATTACHMENT'.
APPEND i_objtxt.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
READ TABLE i_objtxt INDEX v_lines_txt.
wa_doc_chng-obj_name = 'SMARTFORM'.
wa_doc_chng-expiry_dat = sy-datum + 10.
wa_doc_chng-obj_descr = 'SMARTFORM'.
wa_doc_chng-sensitivty = 'F'.
wa_doc_chng-no_change = 'X'.
wa_doc_chng-obj_langu = sy-langu.
wa_doc_chng-doc_size = ( v_lines_txt - 1 ) * 255 + STRLEN( i_objtxt ).
CLEAR i_objpack-transf_bin.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_txt.
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
(pdf-Attachment)
i_objbin[] = zlines2[].
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 1.
i_objpack-body_start = 1.
Länge des Attachment ermitteln
DESCRIBE TABLE i_objbin LINES v_lines_bin.
READ TABLE i_objbin INDEX v_lines_bin.
i_objpack-doc_size = v_lines_bin * 255 .
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'SMARTFORM'.
i_objpack-obj_descr = 'TEST'.
APPEND i_objpack.
CLEAR i_reclist.
i_reclist-receiver = 'abc at aa.com'.
i_reclist-rec_type = 'F'.
i_reclist-express = 'X'.
APPEND i_reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = WA_DOC_CHNG
PUT_IN_OUTBOX = 'X'
commit_work = 'X'
TABLES
PACKING_LIST = I_OBJPACK
CONTENTS_BIN = I_OBJBIN
CONTENTS_TXT = I_OBJTXT
RECEIVERS = I_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.
CASE sy-subrc.
WHEN 0.
WHEN 1. RAISE too_many_receivers.
WHEN 2. RAISE document_not_sent .
WHEN 3. RAISE document_type_not_exist.
WHEN 4. RAISE operation_no_authorization.
WHEN 5. RAISE parameter_error.
WHEN 7. RAISE enqueue_error .
WHEN OTHERS. RAISE x_error.
ENDCASE.
COMMIT WORK.
ENDLOOP.
ENDFORM. "entry
Please suggest ASAP, it has come to a critical stage now, a fruitful help will be a great saviour.
Thanks !Hi Guys,
You can even try this 'CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = bin_filesize
bin_file = xstring
TABLES
otf = it_otf_final
lines = it_pdfdata[]
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = xstring
APPEND_TO_TABLE = ' '
IMPORTING
OUTPUT_LENGTH =
TABLES
binary_tab = it_pdf
Use Cl_BSC Class for easy way to send mail.
Either u can Distribution list Tcode so23.
This is the way i have implemted .. ! -
Dear Experts,
How to send pdf file as email atachment, can some one give me some codings or links.
Thanks and REgards,
Thirukumaran. RMailing is possible when i open the pdf file it's giving the decoding error
i here with attached the codings for ur ref.
FUNCTION Z_HRFM_SEND_OFFERLETTER_MAIL.
*"*"Local Interface:
*" IMPORTING
*" VALUE(IV_APPLID) TYPE PERSNO
*" VALUE(IV_REPMGR) TYPE PERSNO
*" VALUE(IV_CONTROLMGR) TYPE PERSNO
*" VALUE(IV_REPFMGR) TYPE PERSNO
*" VALUE(IV_ACTION) TYPE MASSN
*" VALUE(JOIN_1000) TYPE DATS
*" VALUE(POSITION_1000) TYPE STEXT
*" VALUE(PLACE_1000) TYPE ORT01
*" VALUE(LOC_1000) TYPE ORT01
*" VALUE(GROSS_1000) TYPE NUMC7
*" VALUE(BASIC_1000) TYPE NUMC5
*" VALUE(CONV_1000) TYPE NUMC5
*" VALUE(FOOD_1000) TYPE NUMC5
*" VALUE(VAR_1000) TYPE NUMC5
*" VALUE(PERNR1_1000) TYPE PERSNO
*" VALUE(COMP_ADD) TYPE CHAR200
*" EXCEPTIONS
*" APPLICANT_NOT_FOUND
*" REPFORM_MGR_NOT_FOUND
*" REPMGR_NOT_FOUND
*" CONTROLMGR_NOT_FOUND
*" NO_EMAILID_FOUND
*" SENT
*" NOT_SENT
*& CREATION INFORMATION *
*& AUTHOR : thiruKumaran
*& CREATION DATE : 29.07.2009 *
*& TRANSPORT REQUEST: *
*& FUNCTIONAL SPEC# : *
*& TECHNICAL SPEC# : *
*& PURPOSE :
* Local Variable Declaration
data : EV_APPLNAME TYPE EMNAM,
EV_REPMGR_NAME TYPE EMNAM,
EV_CONTROLMGR_NAME TYPE EMNAM,
EV_CONTROLMGR_GEN TYPE CHAR2,
EV_REPMGR_GEN TYPE CHAR2,
EV_APPL_GEN TYPE CHAR2,
EV_REPFORM_GEN TYPE CHAR2,
EV_REPFORM_NAME TYPE EMNAM,
EV_STRAS TYPE STRAS,
EV_ORT01 TYPE ORT01,
EV_ORT02 TYPE ORT02.
DATA : l_APPname TYPE emnam,
l_evaluation_date TYPE begda,
l_extension_date TYPE begda,
l_emailid TYPE comm_id_long,
tab_lines TYPE sy-tabix,
fm_name TYPE rs38l_fnam.
data:/1BCDWB/FORMOUTPUT type FPFORMOUTPUT ,
/1BCDWB/DOCPARAMS type SFPDOCPARAMS ,
ie_outputparams type SFPOUTPUTPARAMS .
DATA : CONTENTS_HEX TYPE SOLIX.
* Structure Declaration
DATA : s_job_info TYPE ssfcrescl,
s_control_param TYPE ssfctrlop,
s_composer_param TYPE ssfcompop,
s_doc_data TYPE sodocchgi1.
* Internal Table Declaration
DATA : i_otfdata TYPE TABLE OF itcoo,
i_pdf TYPE TABLE OF solisti1,
i_pdfdata TYPE TABLE OF tline,
i_receivers TYPE TABLE OF somlreci1,
i_packing_list TYPE TABLE OF sopcklsti1,
i_message TYPE TABLE OF solisti1.
*& Work area declaration.
DATA : w_receivers LIKE LINE OF i_receivers,
w_packing_list LIKE LINE OF i_packing_list,
w_message LIKE LINE OF i_message.
CALL FUNCTION 'Z_HRFM_GET_OFFERED_DATA'
EXPORTING
IV_APPLID = IV_APPLID
IV_REPMGR = IV_REPMGR
IV_CONTROLMGR = IV_CONTROLMGR
IV_REPFMGR = IV_REPFMGR
IV_ACTION = IV_ACTION
IMPORTING
EV_APPLNAME = EV_APPLNAME
EV_REPMGR_NAME = EV_REPMGR_NAME
EV_CONTROLMGR_NAME = EV_CONTROLMGR_NAME
EV_CONTROLMGR_GEN = EV_CONTROLMGR_GEN
EV_REPMGR_GEN = EV_REPMGR_GEN
EV_APPL_GEN = EV_APPL_GEN
EV_REPFORM_GEN = EV_REPFORM_GEN
EV_REPFORM_NAME = EV_REPFORM_NAME
EV_STRAS = EV_STRAS
EV_ORT01 = EV_ORT01
EV_ORT02 = EV_ORT02
EXCEPTIONS
APPLICANT_NOT_FOUND = 1
REPFORM_MGR_NOT_FOUND = 2
REPMGR_NOT_FOUND = 3
CONTROLMGR_NOT_FOUND = 4
OTHERS = 5.
IF sy-subrc = 1.
RAISE applicant_not_found.
ELSEIF sy-subrc = 2.
RAISE repform_mgr_not_found.
ELSEIF sy-subrc = 3.
raise REPMGR_NOT_FOUND.
ELSEIF sy-subrc = 4.
raise CONTROLMGR_NOT_FOUND .
ENDIF.
*finding email id of applicant
SELECT SINGLE usrid_long INTO l_emailid FROM pb0105
WHERE pernr = IV_APPLID AND subty = '0010' AND endda = '99991231'."#EC *
IF sy-subrc <> 0.
RAISE no_emailid_found.
ENDIF.
* s_control_param-no_dialog = 'X'.
* s_control_param-getotf = 'X'.
* s_composer_param-tddest = 'LP01'.
* s_composer_param-tdnoprev = 'X'.
* Sending PDF by mail
CALL FUNCTION '/1BCDWB/SM00000046' "'ZHR_OFFER_FORM'
*"'/1BCDWB/SM00000046'
EXPORTING
/1BCDWB/DOCPARAMS = /1BCDWB/DOCPARAMS
APPLICANT_NAME = EV_APPLNAME
POSITION = POSITION_1000
JOINING_DATE = join_1000
REPFORM = EV_REPFORM_NAME
REPMGR = EV_REPMGR_NAME
CONTROLMGR = EV_CONTROLMGR_NAME
PLACE = PLACE_1000
APPLICANT_GENDER = EV_APPL_GEN
BASE_PLACE = loc_1000
REPMGR_GENDER = EV_REPMGR_GEN
REPFORM_GENDER = EV_REPFORM_GEN
CONTROLMGR_GENDER = EV_CONTROLMGR_GEN
GROSSS = gross_1000
BASIC = basic_1000
CONVEYANCE = conv_1000
FOOD = food_1000
VARIABLE = var_1000
CITY = ev_ORT01
DISTRICT = ev_ORT02
ADDRESS = ev_stras
C_DATE = sy-datum
APPLICANTID = pernr1_1000
comp_address = comp_add
IMPORTING
/1BCDWB/FORMOUTPUT = /1BCDWB/FORMOUTPUT
EXCEPTIONS
USAGE_ERROR = 1
SYSTEM_ERROR = 2
INTERNAL_ERROR = 3
OTHERS = 4
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*data : binary_tab.
call function 'SCMS_XSTRING_TO_BINARY'
exporting
buffer = /1BCDWB/FORMOUTPUT-PDF
tables
binary_tab = I_PDFDATA.
REFRESH i_pdf[].
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_dst = '255'
TABLES
content_in = i_pdfdata
content_out = i_pdf.
DESCRIBE TABLE i_pdf LINES tab_lines.
****for mailing********
w_receivers-receiver = l_emailid.
w_receivers-rec_type = 'U'.
w_receivers-com_type = 'INT'.
APPEND w_receivers TO i_receivers .
s_doc_data-obj_name = text-001.
s_doc_data-obj_descr = text-001.
CLEAR w_packing_list-transf_bin.
w_packing_list-head_start = 1.
w_packing_list-head_num = 0.
w_packing_list-body_start = 1.
w_packing_list-doc_type = 'RAW'.
w_packing_list-body_num = tab_lines.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
w_packing_list-transf_bin = 'X'.
w_packing_list-head_start = 1.
w_packing_list-head_num = 1.
w_packing_list-body_start = 1.
w_packing_list-doc_type = 'PDF'.
w_packing_list-body_num = tab_lines.
w_packing_list-doc_size = tab_lines * 255.
w_packing_list-obj_descr = text-001.
w_packing_list-obj_name = text-001.
APPEND w_packing_list TO i_packing_list.
*& Writing mail message
concatenate 'Hi' EV_APPLNAME into l_APPname separated by space.
w_message = L_APPNAME.
APPEND w_message TO i_message.
w_message = text-009.
APPEND w_message TO i_message.
w_message = text-002.
APPEND w_message TO i_message.
w_message = text-990.
APPEND w_message TO i_message.
w_message = text-003.
APPEND w_message TO i_message.
w_message = text-990.
APPEND w_message TO i_message.
w_message = text-004.
APPEND w_message TO i_message.
w_message = text-005.
APPEND w_message TO i_message.
"Call the FM to post the message to SAPMAIL
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = s_doc_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = i_packing_list
contents_txt = i_message
* contents_bin = i_pdf
CONTENTS_HEX = I_PDF
receivers = i_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.
raise sent.
else.
raise not_sent.
endif.
* To send mail immediatly
IF sy-subrc = 0.
WAIT UP TO 2 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT'
AND RETURN.
ENDIF.
ENDFUNCTION.
can u give some suggestions,
Thanks and REgards,
Thirukumaran. R -
Error opening the PDF file while sending the PDF as an attachment
Hi All,
I am sending a PDF as an attachment in the mail. I am using the code pasted on 'Jul 28, 2006 8:59 AM' subject OTF Format of Purchase Order in email unreadable.
My problem is when I open the attachment in SOST or in the mail, I get the error message "Adobe could not open *.PDF because it is either not a supported file type or because the file type has been corrupted."
Please let me know if anybody has faced such an issue.
The code is found below.
FORM MAIL_OBJECT *
This routine receives OTF data. OTF data is converted to PDF
format and send to the Partner's email address
FORM mail_object TABLES otf_data STRUCTURE itcoo .
DATA: pdf_size TYPE i, " PDF Size
pdf_itab_size TYPE i, " Attachment size
mailtxt_size TYPE i, " Text in mail size
l_vbeln LIKE vbdka-vbeln. " Order Doc
DATA:
it_mailtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE, " Mail Text
it_pdf TYPE TABLE OF tline WITH HEADER LINE, " OTF output
it_mailpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, " Dist details
it_mailhead LIKE solisti1 OCCURS 1 WITH HEADER LINE," Header data
it_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE, " Rec List
it_pdfdata LIKE solix OCCURS 0 WITH HEADER LINE. " Attachment data
DATA: it_doc_att LIKE sodocchgi1. " Attri of new doc
DATA: BEGIN OF it_pdfout OCCURS 0, " PDF in 255 length
tline TYPE char255,
END OF it_pdfout.
Sales doc and Customer
DATA: BEGIN OF i_vbeln OCCURS 0,
vbeln LIKE vbpa-vbeln, " Sales Document
adrnr LIKE vbpa-adrnr, " Customer
END OF i_vbeln.
Sender Address no and SMTP address
DATA: BEGIN OF i_addrs OCCURS 0,
addrnumber LIKE adr6-smtp_addr,
smtp_addr LIKE adr6-smtp_addr,
END OF i_addrs.
Convert OTF to PDF
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = pdf_size
TABLES
otf = otf_data
lines = it_pdf.
Make each line 255 characters
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
TABLES
content_in = it_pdf
content_out = it_pdfout.
Create the PDF File
CLEAR it_pdfdata.
REFRESH it_pdfdata.
it_pdfdata[] = it_pdfout[].
LOOP AT it_pdfout.
MOVE it_pdfout-tline TO it_pdfdata-line.
APPEND it_pdfdata.
CLEAR it_pdfdata.
ENDLOOP.
DESCRIBE TABLE it_pdfdata LINES pdf_itab_size.
Text in the mail.
it_mailtxt-line = 'ORDER ACKNOWLEDGEMENT'.
APPEND it_mailtxt.
it_mailtxt-line = ' This is a test mail, Line Number--1'.
APPEND it_mailtxt.
it_mailtxt-line = ' This is a test mail, Line Number--2' &
' This is a test mail, Line Number--2'.
APPEND it_mailtxt.
it_mailtxt-line = ' This is a test mail, Line Number--3' &
' This is a test mail, Line Number--3' &
' This is a test mail, Line Number--3'.
APPEND it_mailtxt.
it_mailtxt-line = ' This is a test mail, Line Number--4' &
' This is a test mail, Line Number--4' &
' This is a test mail, Line Number--4' &
' This is a test mail, Line Number--4'.
APPEND it_mailtxt.
it_mailtxt-line = ' This is a test mail, Line Number--5' &
' This is a test mail, Line Number--5' &
' This is a test mail, Line Number--5' &
' This is a test mail, Line Number--5' &
' This is a test mail, Line Number--5'.
APPEND it_mailtxt.
DESCRIBE TABLE it_mailtxt LINES mailtxt_size.
Document Number for Output
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = vbdka-vbeln
IMPORTING
output = l_vbeln.
Attributes of new doc
CONCATENATE 'Order' space 'Acknowledgement' space l_vbeln
INTO it_doc_att-obj_descr SEPARATED BY space.
it_doc_att-sensitivty = 'F'.
it_doc_att-doc_size = mailtxt_size * 255.
Create Pack to text in mail body.
CLEAR it_mailpack-transf_bin.
it_mailpack-head_start = 1.
it_mailpack-head_num = 0.
it_mailpack-body_start = 1.
it_mailpack-body_num = mailtxt_size.
it_mailpack-doc_type = 'RAW'.
APPEND it_mailpack.
Create Pack to PDF Attach.
it_mailpack-transf_bin = 'X'.
it_mailpack-head_start = 1.
it_mailpack-head_num = 1.
it_mailpack-body_start = 1.
it_mailpack-body_num = pdf_itab_size.
it_mailpack-doc_type = 'PDF'.
CONCATENATE l_vbeln '.pdf' INTO it_mailpack-obj_name.
CONCATENATE 'Order Ack' space l_vbeln INTO it_mailpack-obj_descr.
it_mailpack-doc_size = pdf_itab_size * 255.
APPEND it_mailpack.
*Get email addresses based on Sales document.
SELECT vbeln adrnr INTO TABLE i_vbeln
FROM vbpa
WHERE vbeln = vbdka-vbeln AND
parvw = nast-parvw.
IF NOT i_vbeln[] IS INITIAL.
SELECT addrnumber smtp_addr INTO TABLE i_addrs
FROM adr6 FOR ALL ENTRIES IN i_vbeln
WHERE addrnumber = i_vbeln-adrnr AND
smtp_addr NE space.
ENDIF.
IF i_addrs[] IS NOT INITIAL.
LOOP AT i_addrs.
it_reclist-receiver = i_addrs-smtp_addr.
it_reclist-express = 'X'.
it_reclist-rec_type = 'U'.
it_reclist-notif_del = 'X'. " request delivery notification
it_reclist-notif_ndel = 'X'. " request not delivered notification
APPEND it_reclist.
CLEAR: i_addrs.
ENDLOOP.
ENDIF.
Call FM to send email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = it_doc_att
put_in_outbox = 'X'
TABLES
packing_list = it_mailpack
object_header = it_mailhead
contents_txt = it_mailtxt
contents_hex = it_pdfdata
receivers = it_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorizationfiltered= 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " MAIL_OBJECT
Regards,
AjithHi Ajith !!
Please refer this link :
http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
Here a spool output is converted into PDF and then sent as an email.
I think instead of using FM to change the width, try the logic mentioned in the link.
Also instead of FM CONVERT_TO_OTF use :
1. CONVERT_OTFSPOOLJOB_2_PDF
I hope this should solve the problem.
I had referred the same program from the link and it worked absolutely fine. Also check the adobe acrobat version, i guess old version doesnt support SAP, though not very sure.
Best regards,
Prashant -
PDF file format error - Smartform to e-mail attachment
Hi All,
I am trying to convert smartform output to PDF and send as an e-mail/fax attachment. Every thing works fine except when I try to open attachment in e-mail it says Not supported file type or File Damage > May be not correctly decoded. I have attached my code for reference, any hints much appreciated. Thanks in advance.
Regards,
Tim
data: t_otf type table of itcoo,
t_tline type table of tline,
g_filesize TYPE I.
Internal Table declarations
DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
i_tline TYPE TABLE OF tline WITH HEADER LINE,
i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
Objects to send mail.
i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_objbin LIKE SOLIX OCCURS 0 WITH HEADER LINE,
i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
Work Area declarations
w_objhead TYPE soli_tab,
w_ctrlop TYPE ssfctrlop,
w_compop TYPE ssfcompop,
w_return TYPE ssfcrescl,
w_doc_chng typE sodocchgi1,
w_data TYPE sodocchgi1,
w_buffer TYPE string,"To convert from 132 to 255
Variables declarations
v_form_name TYPE rs38l_fnam,
v_len_in LIKE sood-objlen,
v_len_out LIKE sood-objlen,
v_len_outn TYPE i,
v_lines_txt TYPE i,
v_lines_bin TYPE i.
<b> CALL FUNCTION FM_NAME</b>. .......
t_otf[] = wa_outinfo-otfdata[].
CALL FUNCTION <b>'CONVERT_OTF'</b>
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
ARCHIVE_INDEX = ' '
COPYNUMBER = 0
ASCII_BIDI_VIS2LOG = ' '
PDF_DELETE_OTFTAB = ' '
IMPORTING
BIN_FILESIZE = g_filesize
BIN_FILE = g_binfile
TABLES
OTF = t_otf
LINES = i_tline
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
ERR_BAD_OTF = 4
OTHERS = 5.
convert PDF 132 to 255
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Convert PDF from 132 to 255.
LOOP AT i_tline.
Replacing space by ~
TRANSLATE i_tline USING ' ~'.
CONCATENATE w_buffer i_tline INTO w_buffer.
ENDLOOP.
Replacing ~ by space
TRANSLATE w_buffer USING '~ '.
DO.
i_record = w_buffer.
Appending 255 characters as a record
APPEND i_record.
SHIFT w_buffer LEFT BY 255 PLACES.
IF w_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
Refresh: i_reclist,
i_objtxt,
i_objbin,
i_objpack.
clear w_objhead.
Object with PDF.
loop at i_record.
i_objbin-line = i_record-line.
append i_objbin.
endloop.
i_objbin[] = i_record[].
DESCRIBE TABLE i_objbin LINES v_lines_bin.
Object with main text of the mail.
i_objtxt = 'Find attached the output of the smart form.'.
APPEND i_objtxt.
i_objtxt = 'Regards,'.
APPEND i_objtxt.
i_objtxt = 'test'.
APPEND i_objtxt.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
Document information.
w_doc_chng-obj_name = 'Smartform'.
w_doc_chng-expiry_dat = sy-datum + 10.
w_doc_chng-obj_descr = 'Smart form output'.
w_doc_chng-sensitivty = 'F'. "Functional object
w_doc_chng-doc_size = v_lines_txt * 255.
Pack to main body as RAW.
Obj. to be transported not in binary form
CLEAR i_objpack-transf_bin.
*Start line of object header in transport packet
i_objpack-head_start = 1.
Number of lines of an object header in object packet
i_objpack-head_num = 0.
Start line of object contents in an object packet
i_objpack-body_start = 1.
Number of lines of the object contents in an object packet
i_objpack-body_num = v_lines_txt.
Code for document class
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.
Packing as PDF.
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 1.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'Smartform'.
CONCATENATE 'Smartform_output' '.pdf'
INTO i_objpack-obj_descr.
i_objpack-doc_size = v_lines_bin * 255.
APPEND i_objpack.
Document information.
CLEAR i_reclist.
e-mail receivers.
i_reclist-receiver = '[email protected]'.
i_reclist-express = 'X'.
i_reclist-rec_type = 'U'. "Internet address
APPEND i_reclist.
Sending mail.
CALL FUNCTION <b>'SO_NEW_DOCUMENT_ATT_SEND_API1'</b>
EXPORTING
document_data = w_doc_chng
put_in_outbox = 'X'
COMMIT_WORK = 'X'
TABLES
packing_list = i_objpack
object_header = w_objhead
contents_hex = i_objbin
contents_txt = i_objtxt
receivers = i_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 SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.Hi Tim,
I used this to send a smartform in pdf format by email.
Hope it helps
Cristian
REPORT y_cb_test_051 .
DATA DECLARATION
TYPE-POOLS: meein.
TABLES: toa_dara,
nast,
tnapr,
arc_params.
DATA: ent_retco TYPE sy-subrc,
ent_screen TYPE c,
l_xkomk LIKE TABLE OF komk WITH HEADER LINE,
xscreen. "Kz. Probeausgabe
DATA: i_texto_cuerpo LIKE solisti1 OCCURS 0 WITH HEADER LINE.
SELECT OPTIONS / PARAMETERS
PARAMETERS:
p_kappl LIKE nast-kappl OBLIGATORY DEFAULT 'EF',
p_objky LIKE nast-objky OBLIGATORY DEFAULT '0010001125',
p_kschl LIKE nast-kschl OBLIGATORY DEFAULT 'NEU',
p_spras LIKE nast-spras OBLIGATORY DEFAULT 'EN',
p_parnr LIKE nast-parnr OBLIGATORY DEFAULT '50009123',
p_parvw LIKE nast-parvw OBLIGATORY DEFAULT 'BA',
p_erdat LIKE nast-erdat OBLIGATORY DEFAULT '20050908',
p_eruhr LIKE nast-eruhr OBLIGATORY DEFAULT '130105',
p_aende LIKE nast-aende DEFAULT 'X',
p_nacha LIKE nast-nacha DEFAULT '1',
p_ndialo TYPE tdsfflag DEFAULT ' ',
p_telfx LIKE nast-telfx DEFAULT '1-720-220-4274',
p_tland LIKE nast-tland DEFAULT 'US',
p_sform TYPE tdsfname DEFAULT 'ZMMNABPR3PFMMPO_L3' OBLIGATORY.
*PDF TABLES
DATA: tb_pdf LIKE tline OCCURS 0.
DATA: tb_pdf255 TYPE so_text255 OCCURS 0.
MAIN PROCESSING SECTION
START-OF-SELECTION.
SELECT SINGLE *
INTO nast
FROM nast
WHERE kappl = p_kappl
AND objky = p_objky
AND kschl = p_kschl
AND spras = p_spras
AND parnr = p_parnr
AND parvw = p_parvw
AND erdat = p_erdat
AND eruhr = p_eruhr.
IF sy-subrc <> 0.
MESSAGE s000(00) WITH 'Record in NAST not found.'.
nast-kappl = p_kappl.
nast-objky = p_objky.
nast-kschl = p_kschl.
nast-spras = p_spras.
nast-parnr = p_parnr.
nast-parvw = p_parvw.
nast-erdat = p_erdat.
nast-eruhr = p_eruhr.
nast-nacha = p_nacha.
nast-telfx = p_telfx.
nast-tland = p_tland.
ENDIF.
nast-aende = p_aende.
tnapr-sform = p_sform.
PERFORM entry_neu
USING
ent_retco
ent_screen.
FORMS
*& Form entry_neu
text
-->ENT_RETCO text
-->ENT_SCREEN text
FORM entry_neu
USING
ent_retco
ent_screen.
DATA: l_druvo LIKE t166k-druvo,
l_nast LIKE nast,
l_from_memory,
l_doc TYPE meein_purchase_doc_print.
DATA: ls_print_data_to_read TYPE lbbil_print_data_to_read.
DATA: ls_bil_invoice TYPE lbbil_invoice.
DATA: lf_fm_name TYPE rs38l_fnam.
DATA: ls_control_param TYPE ssfctrlop.
DATA: ls_composer_param TYPE ssfcompop.
DATA: ls_recipient TYPE swotobjid.
DATA: ls_sender TYPE swotobjid.
DATA: lf_formname TYPE tdsfname.
DATA: ls_addr_key LIKE addr_key.
xscreen = ent_screen.
clear ent_retco.
IF nast-aende EQ space.
l_druvo = '1'.
ELSE.
l_druvo = '2'.
ENDIF.
CALL FUNCTION 'ME_READ_PO_FOR_PRINTING'
EXPORTING
ix_nast = nast
ix_screen = ent_screen
IMPORTING
ex_retco = ent_retco
ex_nast = l_nast
doc = l_doc
CHANGING
cx_druvo = l_druvo
cx_from_memory = l_from_memory.
CHECK ent_retco EQ 0.
IF nast-adrnr IS INITIAL.
PERFORM get_addr_key
CHANGING ls_addr_key.
ELSE.
ls_addr_key = nast-adrnr.
ENDIF.
*Set the print Parameters
PERFORM set_print_param USING ls_addr_key
CHANGING ls_control_param
ls_composer_param
ls_recipient
ls_sender
ent_retco.
*Get the Smart Form name.
IF NOT tnapr-sform IS INITIAL.
lf_formname = tnapr-sform.
ELSE.
lf_formname = tnapr-fonam.
ENDIF.
determine smartform function module for invoice
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lf_formname
IMPORTING
fm_name = lf_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
error handling
ent_retco = sy-subrc.
perform protocol_update_i.
ENDIF.
ls_control_param-getotf = 'X'.
DATA: l_document_output_info TYPE ssfcrespd,
l_job_output_info TYPE ssfcrescl,
l_job_output_options TYPE ssfcresop.
CALL FUNCTION lf_fm_name
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
user_settings = ' '
zxekko = l_doc-xekko
zxpekko = l_doc-xpekko
zxaend = l_doc-xaend
IMPORTING
document_output_info = l_document_output_info
job_output_info = l_job_output_info
job_output_options = l_job_output_options
TABLES
l_xekpo = l_doc-xekpo[]
l_xekpa = l_doc-xekpa[]
l_xpekpo = l_doc-xpekpo[]
l_xeket = l_doc-xeket[]
l_xtkomv = l_doc-xtkomv[]
l_xekkn = l_doc-xekkn[]
l_xekek = l_doc-xekek[]
l_xaend = l_doc-xaend[]
l_xkomk = l_xkomk
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno.
BREAK-POINT.
ENDIF.
Converts OTF to PDF
DATA: v_len_in TYPE i.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = v_len_in
TABLES
otf = l_job_output_info-otfdata
lines = tb_pdf
EXCEPTIONS
err_max_linewidth = 0
err_format = 1
err_conv_not_possible = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Change the PDF format from 132 to 255.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_src =
line_width_dst =
transfer_bin = 'X'
TABLES
content_in = tb_pdf
content_out = tb_pdf255
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DATA: lw_subject TYPE so_obj_des.
DATA: lwa_body TYPE solisti1.
DATA: ltb_body TYPE TABLE OF solisti1.
DATA: lw_filename TYPE char100.
DATA: ltb_recipients TYPE TABLE OF somlreci1.
DATA: lwa_recipients TYPE somlreci1.
lw_subject = 'This is the email subject'.
lwa_body-line = 'This is the email body - Line1'.
APPEND lwa_body TO ltb_body.
lwa_body-line = 'This is the email body - Line2'.
APPEND lwa_body TO ltb_body.
lwa_body-line = 'This is the email body - Line3'.
APPEND lwa_body TO ltb_body.
lwa_body-line = 'This is the email body - Line4'.
APPEND lwa_body TO ltb_body.
lw_filename = 'Contract'.
*RECIPIENTS
lwa_recipients-rec_type = 'U'.
lwa_recipients-express = 'X'.
lwa_recipients-receiver = sy-uname.
lwa_recipients-copy = ''.
APPEND lwa_recipients TO ltb_recipients.
RECIPIENTS
lwa_recipients-rec_type = 'U'.
lwa_recipients-express = 'X'.
lwa_recipients-receiver = '[email protected]'.
lwa_recipients-copy = ''.
APPEND lwa_recipients TO ltb_recipients.
RECIPIENTS
lwa_recipients-rec_type = 'U'.
lwa_recipients-express = 'X'.
lwa_recipients-receiver = '[email protected]'.
lwa_recipients-copy = ''.
APPEND lwa_recipients TO ltb_recipients.
Sends the PDF by email.
PERFORM f_send_pdf_by_email
TABLES
tb_pdf255
ltb_body
ltb_recipients
USING
lw_subject
lw_filename.
ENDFORM. "entry_neu
*& Form ZCA_MAIL_BIN
text
FORM f_send_pdf_by_email
TABLES
ptb_pdf255 STRUCTURE solisti1
ptb_body STRUCTURE solisti1
ptb_recipients STRUCTURE somlreci1
USING
pw_subject TYPE so_obj_des
pw_filename TYPE char100.
*-DATA DECLARATION----
Variables y tablas internas.
DATA: BEGIN OF ltb_objbin OCCURS 0.
INCLUDE STRUCTURE solisti1.
DATA: END OF ltb_objbin.
DATA: lwa_doc_chng LIKE sodocchgi1,
lw_tab_lines LIKE sy-tabix,
ltb_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
ltb_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
*-MAIN PROCESSING SECTION----
clear: ltb_objbin, ltb_objtxt, ltb_objpack, lwa_doc_chng.
refresh: ltb_objbin, ltb_objtxt, ltb_objpack.
Control Data
lwa_doc_chng-obj_name = 'URGENT'.
lwa_doc_chng-sensitivty = 'P'.
lwa_doc_chng-no_change = 'X'.
lwa_doc_chng-priority = '1'.
lwa_doc_chng-obj_prio = '1'.
lwa_doc_chng-obj_langu = sy-langu.
lwa_doc_chng-no_change = 'X'.
Email Subject
lwa_doc_chng-obj_descr = pw_subject.
Email Body
ltb_objtxt[] = ptb_body[].
CLEAR ltb_objtxt.
DESCRIBE TABLE ltb_objtxt LINES lw_tab_lines.
IF lw_tab_lines GT 0.
READ TABLE ltb_objtxt INDEX lw_tab_lines.
lwa_doc_chng-doc_size =
( lw_tab_lines - 1 ) * 255 + STRLEN( ltb_objtxt ).
CLEAR ltb_objpack-transf_bin.
ltb_objpack-body_start = 1.
ltb_objpack-body_num = lw_tab_lines.
ltb_objpack-doc_type = 'RAW'.
APPEND ltb_objpack.
ENDIF.
Attachment
Move the binary attachment to other internal table.
ltb_objbin[] = ptb_pdf255[].
ltb_objpack-transf_bin = 'X'.
ltb_objpack-body_start = 1.
Get the number of lines in the Attachment (PDF FILE)
DESCRIBE TABLE ltb_objbin LINES lw_tab_lines.
ltb_objpack-body_num = lw_tab_lines.
ltb_objpack-doc_type = 'PDF'.
ltb_objpack-obj_descr = pw_filename.
ltb_objpack-obj_name = pw_filename.
ltb_objpack-doc_size = lw_tab_lines * 255.
APPEND ltb_objpack.
Call the function to send the PDF file by email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lwa_doc_chng
put_in_outbox = 'X'
TABLES
packing_list = ltb_objpack
contents_bin = ltb_objbin
contents_txt = ltb_objtxt
receivers = ptb_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.
CASE sy-subrc.
WHEN 0.
WHEN 1. RAISE too_many_receivers.
WHEN 2. RAISE document_not_sent .
WHEN 3. RAISE document_type_not_exist.
WHEN 4. RAISE operation_no_authorization.
WHEN 5. RAISE parameter_error.
WHEN 7. RAISE enqueue_error .
WHEN OTHERS. RAISE x_error.
ENDCASE.
COMMIT WORK.
ENDFORM. "ZCA_MAIL_BIN
*& Form get_addr_key
text
-->P_CS_BIL_INVOICE_HD_ADR text
<--P_CS_ADDR_KEY text
FORM get_addr_key
CHANGING l_addr_key LIKE addr_key.
DATA: l_lfa1 LIKE lfa1.
SELECT SINGLE * FROM lfa1 INTO l_lfa1
WHERE lifnr = nast-parnr.
IF sy-subrc = 0.
MOVE l_lfa1-adrnr TO l_addr_key.
ENDIF.
ENDFORM. " get_addr_key
*& Form set_print_param
text
-->P_LS_ADDR_KEY text
<--P_LS_CONTROL_PARAM text
<--P_LS_COMPOSER_PARAM text
<--P_LS_RECIPIENT text
<--P_LS_SENDER text
<--P_CF_RETCODE text
FORM set_print_param USING is_addr_key LIKE addr_key
CHANGING cs_control_param TYPE ssfctrlop
cs_composer_param TYPE ssfcompop
cs_recipient TYPE swotobjid
cs_sender TYPE swotobjid
cf_retcode TYPE sy-subrc.
DATA: ls_itcpo TYPE itcpo.
DATA: lf_repid TYPE sy-repid.
DATA: lf_device TYPE tddevice.
DATA: ls_recipient TYPE swotobjid.
DATA: ls_sender TYPE swotobjid.
lf_repid = sy-repid.
CALL FUNCTION 'WFMC_PREPARE_SMART_FORM'
CALL FUNCTION 'Z_MMNA_WFMC_PREPARE_SMART_FORM'
EXPORTING
pi_nast = nast
pi_addr_key = is_addr_key
pi_repid = lf_repid
IMPORTING
pe_returncode = cf_retcode
pe_itcpo = ls_itcpo
pe_device = lf_device
pe_recipient = cs_recipient
pe_sender = cs_sender.
IF cf_retcode = 0.
MOVE-CORRESPONDING ls_itcpo TO cs_composer_param.
cs_composer_param-tdimmed = ' '.
cs_control_param-device = lf_device.
cs_control_param-no_dialog = 'X'.
cs_control_param-no_dialog = p_ndialo.
cs_control_param-preview = xscreen.
cs_control_param-getotf = ls_itcpo-tdgetotf.
cs_control_param-langu = nast-spras.
ENDIF.
ENDFORM. "set_print_param
Message was edited by: Cristian Berri -
How to send output by mail?
Hi Experts,
Current output type in our system:
Document: SD delivey note
Output type: LD00
Medium: 1
Form: Smartforms.
Now we are printing delivery note by LD00 and Medium 1.
In the future, we need to send ducument output to customer by mail, format still as original smartforms.
Would you please give me a guide line to do this?
Thank you.
Richard.Hi Richard,
you need to do following things to send output as an email.
The output type should have medium 5. thats to send an email. Along with this you need to check following two things.
if you are using a copy of a standard program it should have code to send an email. Then you just need to configure following output type with medium '5' to send an email.
If you dont have code to send it as an email you can use FM to send it as an email.
you can use following FM if its an adobe form.
CALL FUNCTION 'SD_PDF_SEND_DATA'
EXPORTING
iv_device = p_w_device
iv_email_subject = w_lv_subject
it_email_text = w_mail_text
is_main_data = p_wa_fp_formoutput
iv_language = w_langu
is_address = w_ls_address
IMPORTING
ev_send_to_all = w_lv_send_to_all
EXCEPTIONS
exc_document = 1
exc_send_request = 2
exc_address = 3
OTHERS = 4.
Else for smart form you need to convert it to PDF format first and send it as an email. Refer below code.
Call Smartform function module.
CALL FUNCTION fm_name
EXPORTING
control_parameters = ssfctrlop
output_options = ssfcompop
IMPORTING
job_output_info = it_otf_data
TABLES
it_nfal = it_nfal.
***********appending the otf data into the final table*********************
it_otf_final[] = it_otf_data-otfdata[].
converting OTF data into pdf data**************************
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = bin_filesize
bin_file =
TABLES
otf = it_otf_final
lines = it_pdfdata[]
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
To send data as email attachment, we need to have a table of SOLISTI1.
This table contains line size of 255 characters. Below function module
does the trick of changing the table from X character sized lines into
any given Y character sized lines.
REFRESH it_pdf[].
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_dst = '255'
TABLES
content_in = it_pdfdata[]
content_out = it_pdf[]
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
"Subject of the mail.
w_document_data-obj_name = 'MAIL_TO_HEAD'.
w_document_data-obj_descr = 'Regarding Mail Program by SAP ABAP'.
"Body of the mail
w_body_msg = 'This is body of mail msg.'.
APPEND w_body_msg TO i_body_msg.
CLEAR w_body_msg.
"Write Packing List for Body
DESCRIBE TABLE i_body_msg LINES g_tab_lines.
w_packing_list-head_start = 1.
w_packing_list-head_num = 0.
w_packing_list-body_start = 1.
w_packing_list-body_num = g_tab_lines.
w_packing_list-doc_type = 'RAW'.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Write Packing List for Attachment
w_packing_list-transf_bin = 'X'.
w_packing_list-head_start = 1.
w_packing_list-head_num = 1.
w_packing_list-body_start = 1.
DESCRIBE TABLE it_pdf LINES w_packing_list-body_num.
w_packing_list-doc_type = 'PDF'.
w_packing_list-obj_descr = 'PDF Attachment'.
w_packing_list-obj_name = 'PDF_ATTACHMENT'.
w_packing_list-doc_size = w_packing_list-body_num * 255.
APPEND w_packing_list TO i_packing_list.
CLEAR w_packing_list.
"Fill the document data and get size of attachment
w_document_data-obj_langu = sy-langu.
READ TABLE it_pdf INTO w_pdf INDEX g_tab_lines.
w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_attachment ).
"Receivers List.
w_receivers-rec_type = 'U'."Internet address
w_receivers-receiver = p_mail.
w_receivers-com_type = 'INT'.
w_receivers-notif_del = 'X'.
w_receivers-notif_ndel = 'X'.
APPEND w_receivers TO i_receivers .
CLEAR:w_receivers.
"Function module to send mail to Recipients
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_document_data
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = g_sent_to_all
TABLES
packing_list = i_packing_list
contents_bin = it_pdf
contents_txt = i_body_msg
receivers = i_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 .
MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.
ENDIF.
ENDIF.
Edited by: Sumit Naik on Oct 13, 2010 11:20 PM
Maybe you are looking for
-
Difference Between FABLB03 and FBL3N
Hi, I have the following scenario. When we generate Trial Balance S_ALR_87012301 we have balance for Some GL codes, But when we Generate FBL3N we are not getting the same balance. But when we Generate FAGLB03 we are able to Match with Trial Balance .
-
A tough one for EJB experts - Stateless session bean spec question
I am busy learning more about EJBs and came across something confusing regarding the legal operations in the various container callback methods for stateless session beans. Specifically, the EJB spec states that in the ejbCreate() method, the Session
-
My 9860 has stopped sending emails to my car system. Please advise steps to take to repair.
-
Reg:os_cluster_wnmcdds8 No Online faulted
hi i am getting this error. we can see that MFEP-RG is in faulted state.server in cluster . MFEP-RG wnmcdds8 No Online faulted wnmcdds6 No Offline please give me any solution for that.it is an urgent.
-
How to use EJB 3.0 in Visual Pack Web ?
Hello everybody ! is there someone who can explain me how to bind a TABLE component visually with a particular business method of an EJB.3.0 (in Netbeens 5.5 / Visual Web Pack) -Is there a way to do the same thing as we can do it in Sun Java Studio C