cancel
Showing results for 
Search instead for 
Did you mean: 

PDF Script

Former Member
0 Kudos

Hi Friends,

I have a program and the Form Layout. Say Ex: i am fetching some Material details and printing them using the Form Layout.

For that in the program i am fetching them using selects and wrting them onto the form using OPEN,WRITE & CLOSE FORM function modules.

If i code in the above way, soon after we execute the form, we will get the form output. But i want in the following way.

1. In addition to the form display i have to convert the form to PDF and send that to a mailID which is given in the initial selection scree.

2. Instead of displaying the Form output , a mail has to send to the mail ID that is mentioned in teh selection screen.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI, catch the OTFDATA for the Close_form FM and then use the FM CONVERT_OTF_2_PDF to convert the OTF data to PDF format which can be added as mail attachment .

Reward points if useful.

Raj.

Former Member
0 Kudos

Can you help me in catching the OTF Data ?

prasanth_kasturi
Active Contributor
0 Kudos

hi

SAP have created a standard program RSTXPDFT4 to convert your Sapscripts spools into a PDF format.

Specify the spool number and you will be able to download the sapscripts spool into your local harddisk.

It look exactly like what you see during a spool display.

Please note that it is not restricted to sapsciprts spool only. Any reports in the spool can be converted using the program 'RSTXPDFT4'.

Just rough idea for downloading, apply the same for SAP scripts...

**Set printer parameters

control_param-no_dialog = 'X'.

control_param-preview = ''.

control_param-getotf = 'X'.

output_opt-tddest = 'LOCL'.

output_opt-tdimmed = ''.

output_opt-tdnewid = ''.

output_opt-tdnoprint = ''.

output_opt-tdnoprev = 'X'.

Get smartform name

call function 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = formname

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 smartform

call function fm_name

EXPORTING

control_parameters = control_param

output_options = output_opt

user_settings = ' '

wa_head = wa_head

IMPORTING

job_output_info = job_info

TABLES

int_detail = int_detail

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

others = 5.

Note pass the job info file you got from above function module

data: int_docs type standard table of docs,

int_line type standard table of tline.

call function 'CONVERT_OTF_2_PDF'

IMPORTING

bin_filesize = filesize

TABLES

otf = job_info-otfdata

doctab_archive = int_docs

lines = int_line

EXCEPTIONS

err_conv_not_possible = 1

err_otf_mc_noendmarker = 2

others = 3.

USE below function module

all method cl_gui_frontend_services=>gui_download

exporting

bin_filesize = filesize

filename = filename

filetype = 'BIN'

changing

data_tab = int_line

refer the links

http://www.sap-img.com/smartforms/conversion-of-smartform-output-to-pdf.htm

regards

prasanth

Former Member
0 Kudos

Hi,

In your print program, while calling OPEN_FORM, pass options-TDGETOTF = 'X'. This is used for returning print output in OTF format.

Then in CLOSE_FORM, get the table OTFDATA returned from the function module. for example

DATA: OTF_DATA LIKE ITCOO OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

RESULT = RESULT

TABLES

OTFDATA = OTF_DATA.

now you can convert this OTF data to PDF using function module CONVERT_OTF

Then send this data as attachment to a mail using function module SO_NEW_DOCUMENT_ATT_SEND_API1

Regards,

Raj

Answers (1)

Answers (1)

prasanth_kasturi
Active Contributor
0 Kudos

hi,

check tghis prog its suits your reuirement

DATA: itcpo LIKE itcpo,

tab_lines LIKE sy-tabix.

*Variables for EMAIL functionality

DATA: maildata LIKE sodocchgi1.

DATA: mailpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

DATA: mailhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.

DATA: mailbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: mailtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: mailrec LIKE somlrec90 OCCURS 0 WITH HEADER LINE.

DATA: solisti1 LIKE solisti1 OCCURS 0 WITH HEADER LINE.

PERFORM send_form_via_email.

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

*

*

*FORM SEND_FORM_VIA_EMAIL *

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

FORM send_form_via_email.

CLEAR: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.

REFRESH: mailtxt, mailbin, mailpack, mailhead, mailrec.

*Creation of the document to be sent File Name

maildata-obj_name = 'TEST'.

*Mail Subject

maildata-obj_descr = 'Subject'.

*Mail Contents

mailtxt-line = 'Here is your file'.

APPEND mailtxt.

*Prepare Packing List

PERFORM prepare_packing_list.

*Set recipient - email address here!!!

mailrec-receiver = 'RAVINDRANATH.K'.

mailrec-rec_type = 'U'.

APPEND mailrec.

*Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = maildata

put_in_outbox = ' '

TABLES

packing_list = mailpack

object_header = mailhead

contents_bin = mailbin

contents_txt = mailtxt

receivers = mailrec

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

ENDFORM.

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

*Form PREPARE_PACKING_LIST

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

FORM prepare_packing_list.

CLEAR: mailpack, mailbin, mailhead.

REFRESH: mailpack, mailbin, mailhead.

DESCRIBE TABLE mailtxt LINES tab_lines.

READ TABLE mailtxt INDEX tab_lines.

maildata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( mailtxt ).

*Creation of the entry for the compressed document

CLEAR mailpack-transf_bin.

mailpack-head_start = 1.

mailpack-head_num = 0.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'RAW'.

APPEND mailpack.

*

*Creation of the document attachment

*This form gets the OTF code from the SAPscript form.

*If you already have your OTF code, I believe that you may

*be able to skip this form. just do the following code, looping thru

*your SOLISTI1 and updating MAILBIN.

PERFORM get_otf_code.

LOOP AT solisti1.

MOVE-CORRESPONDING solisti1 TO mailbin.

APPEND mailbin.

ENDLOOP.

DESCRIBE TABLE mailbin LINES tab_lines.

mailhead = 'TEST.OTF'.

APPEND mailhead.

*Creation of the entry for the compressed attachment

mailpack-transf_bin = 'X'.

mailpack-head_start = 1.

mailpack-head_num = 1.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'OTF'.

mailpack-obj_name = 'TEST'.

mailpack-obj_descr = 'Subject'.

mailpack-doc_size = tab_lines * 255.

APPEND mailpack.

ENDFORM.

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

*

*Form GET_OTF_CODE

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

FORM get_otf_code.

DATA: BEGIN OF otf OCCURS 0.

INCLUDE STRUCTURE itcoo .

DATA: END OF otf.

DATA: itcpo LIKE itcpo.

DATA: itcpp LIKE itcpp.

CLEAR itcpo.

itcpo-tdgetotf = 'X'.

*Start writing OTF code

CALL FUNCTION 'OPEN_FORM'

EXPORTING

form = 'Z08V3_COLLI'

language = sy-langu

options = itcpo

dialog = ' '

EXCEPTIONS

OTHERS = 1.

CALL FUNCTION 'START_FORM'

EXCEPTIONS

error_message = 01

OTHERS = 02.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

window = 'MAIN'

EXCEPTIONS

error_message = 01

OTHERS = 02.

*Close up Form and get OTF code

CALL FUNCTION 'END_FORM'

EXCEPTIONS

error_message = 01

OTHERS = 02.

MOVE-CORRESPONDING itcpo TO itcpp.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

result = itcpp

TABLES

otfdata = otf

EXCEPTIONS

OTHERS = 1.

*Move OTF code to structure SOLI form email

CLEAR solisti1. REFRESH solisti1.

LOOP AT otf.

solisti1-line = otf.

APPEND solisti1.

ENDLOOP.

Endform.

regards

prasanth

Edited by: prasanth kasturi on Jun 11, 2008 8:23 AM