Вы находитесь на странице: 1из 11

SDN Contribution

Combining Multiple Smartform Outputs Into One PDF


File

Applies to:
SAP R/3 4.6C – ABAP / SMARTFORMS

Summary
This program code would help those who want to combine multiple smartform outputs into a single OTF
output and then to download them as a single PDF file in your local PC.

Author: Sylendra Prasad M

Company: Wipro Technologies, SAP ABAP Consultant

Created on: 13th June 2006

© 2006 SAP AG 1
Table of Contents
Procedure ........................................................................................................................................................................ 2

Sample Code................................................................................................................................................................... 4

Screenshot of the output PDF file ............................................................................................................................. 9

Disclaimer and Liability Notice ................................................................................................................................ 10

Author Bio ..................................................................................................................................................................... 11

Procedure
The Function Module generated by the system when you activate the Smartform is obtained by the Function
Module SSF_FUNCTION_MODULE_NAME and the data to be passed to the smartform is sent by calling
this FM. In this FM, we’ll set the GETOTF field of the CONTROL_PARAMETERS parameter. This FM would
import the details of the Smartform into a parameter JOB_OUTPUT_INFO, which is of type SSFCRESCL.
SSFCRESCL contains a field OTFDATA, which is a table type of ITCOO containing the OTF equivalent of
the Smartform output. ITCOO has two fields TDPRINTCOM, which is the command ID and TDPRINTPAR,
which is the print parameter.

© 2006 SAP AG 2
A sample content of the OTF table is given below.

For every Smartform output in its OTF equivalent, TDPRINTCOM begins and ends with ‘//’. So the final OTF
table that should be sent as PDF output should contain only one pair of ‘//’ to mark the beginning and end of
the table. TDPRINTCOM value for end-of-page will be ‘EP’. So if you want to combine multiple Smartforms
into one OTF table, the beginning and end markers (‘//’) for subsequent smartforms should be removed and
appended after ‘EP’ command in the OTF table.

Here is the sample content of OTF table, which contains the output of two Smartforms.

© 2006 SAP AG 3
Similarly we can append multiple smartform outputs to one OTF table and then use the Function Module
CONVERT_OTF to convert the OTF data to PDF data and then you can use the Function Module
GUI_DOWNLOAD to download the PDF data to your local file.

Sample Code.

REPORT yshail_smartform1_new .

****************************DECLARATIONS********************************

TABLES: zshail_t1,sflight.

DATA: cparam TYPE ssfctrlop,


outop TYPE ssfcompop,
fm_name TYPE rs38l_fnam,
my_tabix TYPE sy-tabix,
file_size TYPE i,
bin_filesize TYPE i.

DATA: tab_otf_data TYPE ssfcrescl,


pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE,

© 2006 SAP AG 4
itab LIKE TABLE OF zshail_t1 WITH HEADER LINE,
otab TYPE TABLE OF sflight WITH HEADER LINE,
tab_otf_final TYPE itcoo OCCURS 0 WITH HEADER LINE.

start-of-selection.

***************** suppressing the dialog box****************************


outop-tddest = 'LP01'.
cparam-no_dialog = 'X'.
cparam-preview = space.
cparam-getotf = 'X'.

*****************for the first smartform********************************


CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZSHAIL_SMFORM2'
* 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.

SELECT my_id my_income my_name FROM zshail_t1 INTO TABLE itab.

CALL FUNCTION fm_name


EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
control_parameters = cparam
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
output_options = outop
user_settings = space
IMPORTING
* DOCUMENT_OUTPUT_INFO =
job_output_info = tab_otf_data
* JOB_OUTPUT_OPTIONS =
TABLES
it_tab = itab[]
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.

© 2006 SAP AG 5
ENDIF.

**********appending the otf data into the final table**********************


tab_otf_final[] = tab_otf_data-otfdata[].

**************for the second smartform*************************************

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'


EXPORTING
formname = 'ZSHAIL_SMTAB'
* 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.

SELECT carrid connid fldate price FROM sflight INTO CORRESPONDING FIELDS
OF TABLE otab.

CALL FUNCTION fm_name


EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
control_parameters = cparam
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
output_options = outop
user_settings = space
IMPORTING
* DOCUMENT_OUTPUT_INFO =
job_output_info = tab_otf_data
* JOB_OUTPUT_OPTIONS =
TABLES
itab = otab[]
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.

© 2006 SAP AG 6
***removing the initial and final markers from the OTF data**********
DELETE tab_otf_data-otfdata WHERE tdprintcom = '//'.

***************** searching for the end-of-page in OTF table************


READ TABLE tab_otf_final WITH KEY tdprintcom = 'EP'.
my_tabix = sy-tabix + 1.

************ appending the modified OTF table to the final OTF table****
INSERT LINES OF tab_otf_data-otfdata INTO tab_otf_final INDEX my_tabix.

************ converting OTF data into pdf data**************************


CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
* ARCHIVE_INDEX = ' '
* COPYNUMBER = 0
* ASCII_BIDI_VIS2LOG = ' '
IMPORTING
bin_filesize = bin_filesize
* BIN_FILE =
TABLES
otf = tab_otf_final
lines = 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.

*************downloading the converted PDF data to your local PC********

CALL FUNCTION 'GUI_DOWNLOAD'


EXPORTING
bin_filesize = bin_filesize
filename = 'D:\TEST.PDF'
filetype = 'BIN'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE

© 2006 SAP AG 7
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
IMPORTING
filelength = file_size
TABLES
data_tab = pdf_tab
* FIELDNAMES =
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22
.

© 2006 SAP AG 8
Screenshot of the output PDF file
First smartform output

© 2006 SAP AG 9
Second Smartform output

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces
and therefore is not supported by SAP. Changes made based on this information are not supported and can
be overwritten during an upgrade.

SAP will not be held liable for any damages caused by using or misusing the information, code or methods
suggested in this document, and anyone using these methods does so at his/her own risk.

SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of
this technical article or code sample, including any liability resulting from incompatibility between the content

© 2006 SAP AG 10
within this document and the materials and services offered by SAP. You agree that you will not hold, or
seek to hold, SAP responsible or liable with respect to the content of this document.

Author Bio

I am an SAP ABAP Consultant working for Wipro Technologies.

© 2006 SAP AG 11

Вам также может понравиться