Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Convert Smartform to PDF

Former Member
0 Likes
2,111

Hi,

Someone can help me to convert a smartform to a pdf and then send it by email.

Thanks a lot!! because I have a lot of problems with this

Message was edited by: Laura Portal

Message was edited by: Laura Portal

1 ACCEPTED SOLUTION
Read only

christian_wohlfahrt
Active Contributor
0 Likes
1,998

Hi Laura,

there is a nice report posted by Thomas Jung which should help you:

(Topic: Sendin Spool reports to an e-mail address. [In case link is not working])

In general:

Create normal output by smartform (which can be send by email in 4.7 already in job-planning).

Plan second report, which fetches first output, converts into PDF and sends result by email.

Regards,

Christian

Hi,

Someone can help me to convert a smartform to a pdf and then send it by email.

Thanks a lot!! because I have a lot of problems with this

Message was edited by: Laura Portal

Message was edited by: Laura Portal

10 REPLIES 10
Read only

christian_wohlfahrt
Active Contributor
0 Likes
1,999

Hi Laura,

there is a nice report posted by Thomas Jung which should help you:

(Topic: Sendin Spool reports to an e-mail address. [In case link is not working])

In general:

Create normal output by smartform (which can be send by email in 4.7 already in job-planning).

Plan second report, which fetches first output, converts into PDF and sends result by email.

Regards,

Christian

Read only

0 Likes
1,998

Tks Christian, it was helpful but I have some problems to convert to pdf. Ii can generate the file but without data, I don't know why.

I hope someone can give me some examples to do that

🐵

Read only

0 Likes
1,998

Hi Laura,

Can you share the flow of your program and the call to the PDF conversion module?

May be that will help the forum to pinpoint the problem.

Srinivas

Read only

0 Likes
1,998

Hi,

This is my program. And the error message is the following:

Sapfewin

C:perforce as620_CORsrc es ewsapfewinguifunctionality.xml contiene una ruta no valida

I don't know what is the problem. I hope someone can help me

🐵

****************************************************¨***

control_parameters-langu = sy-langu.

control_parameters-no_dialog = 'X'.

control_parameters-getotf = 'X'.

** THIS IS THE SMARTFORM

CALL FUNCTION '/1BCDWB/SF00000003'

EXPORTING

  • ARCHIVE_INDEX =

  • ARCHIVE_INDEX_TAB =

  • ARCHIVE_PARAMETERS =

CONTROL_PARAMETERS = control_parameters

  • MAIL_APPL_OBJ =

  • MAIL_RECIPIENT =

  • MAIL_SENDER =

  • OUTPUT_OPTIONS =

  • USER_SETTINGS = 'X'

p_vbeln = d_vbeln

IMPORTING

  • DOCUMENT_OUTPUT_INFO =

JOB_OUTPUT_INFO = output_data

  • JOB_OUTPUT_OPTIONS =

  • EXCEPTIONS

  • FORMATTING_ERROR = 1

  • INTERNAL_ERROR = 2

  • SEND_ERROR = 3

  • USER_CANCELED = 4

  • OTHERS = 5

.

IF sy-subrc <> 0.

MESSAGE i208(00) WITH 'Error al imprimir la factura'.

ENDIF.

PERFORM pdf.

PERFORM email.

ENDFORM. "entry

**&----

-


*

**& Form PDF

**&----

-


*

    • text

**----

-


*

    • --> p1 text

    • <-- p2 text

**----

-


*

FORM pdf .

****CONVERT TO PDF

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

  • MAX_LINEWIDTH = 132

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

IMPORTING

BIN_FILESIZE = L_PDF_LEN

BIN_FILE = L_PDF_XSTRING

TABLES

OTF = OUTPUT_DATA-OTFDATA

LINES = LT_LINES

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

ERR_BAD_OTF = 4

OTHERS = 5

.

IF SY-SUBRC <> 0.

  • error handling

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

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

ENDIF.

PERFORM get_path USING 'PDF_FILE'.

*--

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

filename = filename

filetype = 'PDF'

bin_filesize = L_PDF_LEN

TABLES

data_tab = itab2

EXCEPTIONS

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_table_width = 4

invalid_type = 5

no_batch = 6

unknown_error = 7

OTHERS = 8.

*

ENDFORM. " PDF

*&----

-


*& Form GET_PATH

*&----

-


FORM get_path USING p_filename.

CLEAR: h_path, file_name.

file_name = p_filename.

CALL FUNCTION 'WS_QUERY'

EXPORTING

query = 'CD' "// Current Directory

IMPORTING

return = h_path.

CONCATENATE file_name '.pdf' INTO file_name.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_filename = file_name

def_path = h_path

mask = h_mask

mode = 'O'

IMPORTING

filename = filename "dbname

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

ENDFORM. " GET_PATH

**&----

-


*

**& Form EMAIL

**&----

-


*

    • text

**----

-


*

    • --> p1 text

    • <-- p2 text

**----

-


*

FORM email .

SELECT * FROM vbrk

INTO w_vbrk

WHERE vbeln = d_vbeln.

ENDSELECT.

SELECT * FROM kna1

INTO w_kna1

WHERE kunnr = w_vbrk-kunrg.

ENDSELECT.

CALL FUNCTION 'ADDR_GET_REMOTE'

EXPORTING

ADDRNUMBER = w_kna1-adrnr

  • ADDRHANDLE =

TABLES

  • ADDR1 =

  • ADTEL =

  • ADFAX =

  • ADTTX =

  • ADTLX =

ADSMTP = v_email

  • ADRML =

  • ADX400 =

  • ADRFC =

  • ADPRT =

  • ADSSF =

  • ADURI =

  • ADPAG =

  • ADDR_REM =

  • ADCOMREM =

EXCEPTIONS

PARAMETER_ERROR = 1

ADDRESS_NOT_EXIST = 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.

MOVE v_email-smtp_addr TO dest.

              • TO SEND BY EMAIL</b>

submit SHOWCOLO exporting list to memory and return.

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = listobject

EXCEPTIONS

OTHERS = 1

.

IF sy-subrc <> 0.

message ID '61' TYPE 'E' NUMBER '731'

with 'LIST_FROM_MEMORY'.

ENDIF.

CALL FUNCTION 'TABLE_COMPRESS'

  • IMPORTING

  • COMPRESSED_SIZE =

TABLES

IN = listobject

OUT = objbin

EXCEPTIONS

OTHERS = 1

.

if sy-subrc <> 0.

message ID '61' TYPE 'E' NUMBER '731'

with 'TABLE_COMPRESS'.

endif.

  • Title and Description

docdata-obj_name = filename.

docdata-obj_descr = 'Factura con attachment'.

  • Main Text

objtxt = 'Factura:'.

append objtxt.

objtxt = d_vbeln.

append objtxt.

.

  • Write Packing List (Main)

describe table objtxt lines tab_lines.

read table objtxt index tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).

clear objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'RAW'.

append objpack.

  • Create Message Attachment

  • Write Packing List (Attachment)

att_type = 'ALI'.

describe table objbin lines tab_lines.

read table objbin index tab_lines.

objpack-doc_size = L_PDF_LEN + ( tab_lines - 1 ) * 255 + strlen(

objbin ).

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = att_type.

objpack-obj_name = filename.

objpack-obj_descr = 'Factura'.

append objpack.

  • Create receiver list

reclist-receiver = dest.

reclist-rec_type = 'U'.

append reclist.

  • reclist-receiver = sy-uname.

*

  • reclist-rec_type = 'B'.

*

  • append reclist.

  • Send Message

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X' "used from rel.6.10

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

tables

packing_list = objpack

OBJECT_HEADER = objhead

CONTENTS_BIN = objbin

CONTENTS_TXT = objtxt

  • CONTENTS_HEX = objhex

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = reclist

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

DOCUMENT_TYPE_NOT_EXIST = 3

OPERATION_NO_AUTHORIZATION = 4

PARAMETER_ERROR = 5

X_ERROR = 6

ENQUEUE_ERROR = 7

OTHERS = 8.

IF sy-subrc <> 0.

message ID 'SO' TYPE 'S' NUMBER '023'

with docdata-obj_name.

ENDIF.

ENDFORM. " EMAIL

Read only

Casey
Product and Topic Expert
Product and Topic Expert
0 Likes
1,998

Hi Laura,

As referred to your error message

Sapfewin

C:\perforce\bas\620_COR\src\fes\few\sapfewin\guifunctionality.xml contiene una ruta no valida

In order to resolve this issue, please intall the SAP Gui 620 final release with patch level 38 or higher as suggested in SAP Note No. 684576.

Hope this help.

Cheers, KokChuan

Read only

christian_wohlfahrt
Active Contributor
0 Likes
1,998

Hi Laura!

Spanish? I guess, message is something like 'Path not valid / found'.

Functions WS_DOWNLOAD, WS_... need GUI / user-input. So try to run this online.

Otherwise: translate!

Regards,

Christian

Read only

0 Likes
1,998

Hi,

Yes the message in english is

Sapfewin

C:\perforce\bas\620_COR\src\fes\few\sapfewin\guifunctionality.xml Path not valid.

I run it online and appears this message. Then I click OK and appears another window where I have to put the name of the file and it suppose to save it but it doesn't work.

Message was edited by: Laura Portal

Read only

christian_wohlfahrt
Active Contributor
0 Likes
1,998

Hi Laura,

to go on and have some success:

deactivate form get path and use fixed filename:

  • PERFORM get_path USING 'PDF_FILE'.

*--

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

*filename = filename

filename = 'C:\temp.xml' "maybe 'C:/temp.xml' here is not MS

Later you should have a look at transaction FILE, define something for PDF_FILE (like variable in get_path), have a look at documentation of WS_DOWNLOAD; replace this part by function GUI_DOWNLOAD...

Regards,

Christian

Read only

0 Likes
1,998

Hi Chrsitian,

I tried that and nothing happen. Get a message : Output could not be issued. And the attach in the email is a table with colors. I don't know if the pdf is ok or in the attach of the email I am sending another thing.

Tks

Read only

0 Likes
1,998

Laura,

I am on SAP R/3 4.7 Enterprise. If you have a look at program LF150U37 this handles the Dunning Smartforms output. The Smartform is called using function call

CALL FUNCTION fm_name

Below this is the code to convert the Smartform to PDF using function module CONVERT_OTF and then send the PDF by email using function module SO_OBJECT_SEND. Have a look at this code and see if you can figure out how to implement it in your own program.

Incidentally, I'd recommend using function module SSF_FUNCTION_MODULE_NAME to retrieve the name of your Smartforms function module rather than hard-coding it. The reason is that the function module name may change when you transport the Smartform through the system landscape.

Let me know how you go on.

Regards,

JB